我一直在尝试学习macOS上Shell的键盘快捷键,但是当我尝试使用ALT+时B,它不起作用。
您如何在外壳中发现,配置和使用键绑定?任何备忘单都会有所帮助。
我一直在尝试学习macOS上Shell的键盘快捷键,但是当我尝试使用ALT+时B,它不起作用。
您如何在外壳中发现,配置和使用键绑定?任何备忘单都会有所帮助。
Answers:
处理在OS X终端上不起作用的“元”键序列的一种方法是将特定的字符序列分配给特定的按键。对于使用非美式键盘的我们来说,这通常是比其他答案的注释中提到的“将选项用作元数据”设置更好的解决方案。(许多国际Mac键盘在没有Option / alt键的情况下基本上无法用于开发工作,因为否则某些关键字符将不可用。#例如,在英国Mac键盘上则没有。)
为了使bash的单词左右对齐,我使用了终端中“设置”的“键盘”部分。您可以告诉它在进行特定的按键操作时生成特定的代码序列。我已经配置好了,以便alt+ ◀生成\033b
(实际上是两个字符:Esc,然后是小写b)和alt+ ▶生成\033f
(即Esc f
)。这使您可以使用箭头键并同时按住Option键来获得单词的左右行为。
我还没有解决的是如何获得Esc工作的钥匙-从理论上讲,您应该可以将其用于“元”序列,但似乎不起作用。(因此,只需输入Esc+ b即可返回一个单词。)
如果您使用的是美国键盘布局,或者Apple认为可以提供您实际需要的所有键的某些其他键盘,那么正如其他人所建议的那样,“将选项用作元键”(也位于“终端”设置的“键盘”部分)可能是一个更好的选择,因为您将能够使用任何元键组合。启用该功能后,Alt+会b按预期工作。
Mac OS X的终端是BASH,这是一些BASH快捷方式:
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor
Alt + F Move cursor forward one word on the current line
Alt + B Move cursor backward one word on the current line
Tab Auto-complete files and folder names
您要寻找的是Ctrl+ H。(这与按退格键相同)
如果您正在寻找一个转义字符以返回一个字符,那么您正在寻找\b
。如:
$ echo -e "one two\b\b\b\b three" # Will echo "one three"
尝试SS64。该网站非常适合命令行参考。
从此SS64页面获取的OS X CLI键盘快捷键。
Bash Keyboard Shortcuts
Moving the cursor:
Ctrl + a Go to the beginning of the line (Home)
Ctrl + e Go to the End of the line (End)
Ctrl + p Previous command (Up arrow)
Ctrl + n Next command (Down arrow)
Alt + b Back (left) one word
Alt + f Forward (right) one word
Ctrl + f Forward one character
Ctrl + b Backward one character
Ctrl + xx Toggle between the start of line and current cursor position
Editing:
Ctrl + L Clear the Screen, similar to the clear command
Ctrl + u Cut/delete the line before the cursor position.
Alt + Del Delete the Word before the cursor.
Alt + d Delete the Word after the cursor.
Ctrl + d Delete character under the cursor
Ctrl + h Delete character before the cursor (backspace)
Ctrl + w Cut the Word before the cursor to the clipboard.
Ctrl + k Cut the Line after the cursor to the clipboard.
Alt + t Swap current word with previous
Ctrl + t Swap the last two characters before the cursor (typo).
Esc + t Swap the last two words before the cursor.
Ctrl + y Paste the last thing to be cut (yank)
Alt + u UPPER capitalize every character from the cursor to the end of the current word.
Alt + l Lower the case of every character from the cursor to the end of the current word.
Alt + c Capitalize the character under the cursor and move to the end of the word.
Alt + r Cancel the changes and put back the line as it was in the history (revert).
Ctrl + _ Undo
TAB Tab completion for file/directory names
For example, to move to a directory 'sample1'; Type cd sam ; then press TAB and ENTER.
type just enough characters to uniquely identify the directory you wish to open.
History:
Ctrl + r Recall the last command including the specified character(s)
searches the command history as you type.
Equivalent to : vim ~/.bash_history.
Ctrl + p Previous command in history (i.e. walk back through the command history)
Ctrl + n Next command in history (i.e. walk forward through the command history)
Alt + . Use the last word of the previous command
Ctrl + s Go back to the next most recent command.
(beware to not execute it from a terminal because this will also launch its XOFF).
Ctrl + o Execute the command found via Ctrl+r or Ctrl+s
Ctrl + g Escape from history searching mode
Process control:
Ctrl + C Interrupt/Kill whatever you are running (SIGINT)
Ctrl + l Clear the screen
Ctrl + s Stop output to the screen (for long running verbose commands)
Ctrl + q Allow output to the screen (if previously stopped using command above)
Ctrl + D Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
Ctrl + Z Send the signal SIGTSTP to the current task, which suspends it.
To return to it later enter fg 'process name' (foreground).
Emacs mode vs Vi Mode
All the above assume that bash is running in the default Emacs setting, if you prefer this can be switched to Vi shortcuts instead.
Set Vi Mode in bash:
$ set -o vi
Set Emacs Mode in bash:
$ set -o emacs
注意:要使用Alt键快捷方式>>打开终端首选项>>设置选项卡>>键盘>>勾选“将选项用作元键”
您需要手册页的READLINE部分bash(1)
:
man 1 bash
/^READLINE
您可能对我的个人资料感兴趣:https : //github.com/lingtalfi/mac-terminal-shortcuts
它提供了以下(直观的)快捷方式:
ALT-left: move one word backward
ALT-right: move one word forward
CTRL-left: move to the beginning of the line
CTRL-right: move to the end of the line
ALT-backspace: kill one word backward
ALT-del: kill one word forward
ALT-up: set word after cursor to uppercase
ALT-down: set word after cursor to lowercase
CTRL-backspace: Same as ALT-backspace
CTRL-del: Same as ALT-del
home: move to the beginning of the line
end: move to the end of the line