如果我正在使用终端并为命令输入一行文本,是否有热键或任何方式来清除/删除该行?
例如,如果我当前的行/命令非常像:
> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now>
Run Code Online (Sandbox Code Playgroud)
是否有热键或命令从上面到:
>
Run Code Online (Sandbox Code Playgroud)
?
通常我会按下↓键,如果我的当前行是历史上的全新行,那将清除它.但是如果我通过↑键查看命令历史记录并开始编辑或使用这些命令,↓则只会将提示更改为历史记录中的下一个最新命令,因此除非我按↓多次,否则它不起作用.
kev*_*kev 1346
您可以使用Ctrl+ U来清除开头.
您可以使用Ctrl+ W删除一个单词.
您也可以使用Ctrl+ C取消.
如果要保留历史记录,可以使用Alt+ Shift+ #将其作为注释.
J4c*_*4cK 537
只是总结一下所有的答案:
tha*_*mar 142
我有完整的快捷方式列表:
小智 16
或者如果你使用vi模式,点击Esc后跟cc
找回你刚刚删除的东西,Esc然后p:)
另一个不错的完整列表:
TERMINAL Shortcuts Lists:
Left Move back one character
Right Move forward one character
Ctrl+b Move back one character
Ctrl+f Move forward one character
Alt+Left Move back one word
Alt+Right Move forward one word
Alt+b Move back one word
Alt+f Move forward one word
Cmd+Left Move cursor to start of line
Cmd+Right Move cursor to end of line
Ctrl+a Move cursor to start of line
Ctrl+e Move cursor to end of line
Ctrl+d Delete character after cursor
Backspace Delete character before cursor
Alt+Backspace Delete word before cursor
Ctrl+w Delete word before cursor
Alt+w Delete word before the cursor
Alt+d Delete word after the cursor
Cmd+Backspace Delete everything before the cursor
Ctrl+u Delete everything before the cursor
Ctrl+k Delete everything after the cursor
Ctrl+l Clear the terminal
Ctrl+c Cancel the command
Ctrl+y Paste the last deleted command
Ctrl+_ Undo
Ctrl+r Search command in history - type the search term
Ctrl+j End the search at current history entry and run command
Ctrl+g Cancel the search and restore original line
Up previous command from the History
Down Next command from the History
Ctrl+n Next command from the History
Ctrl+p previous command from the History
Ctrl+xx Toggle between first and current position
Run Code Online (Sandbox Code Playgroud)
无论光标在哪里都可以删除整行,可以使用该kill-whole-line命令,但默认是未绑定的。例如,可以通过插入将其绑定到Ctrl++AltK
"\e\C-k": kill-whole-line
Run Code Online (Sandbox Code Playgroud)
进入你的 Readline 初始化文件(通常~/.inputrc)。
各种备注:
为了避免意外地重新分配已用于其他用途的按键序列,您可以使用 来检查所有绑定bind -P。检查建议的绑定
"\e\C-k": kill-whole-line
Run Code Online (Sandbox Code Playgroud)
Readline 初始化文件名取自 shell 变量INPUTRC。如果未设置,则默认值为~/.inputrc, 或(如果不存在)/etc/inputrc。请注意,如果有~/.inputrc,/etc/inputrc将被忽略。您可以使用该$include指令来重用后者:
$include /etc/inputrc
Run Code Online (Sandbox Code Playgroud)
要重新加载 Readline 初始化文件,您可以使用Ctrl+ X Ctrl+ R。
相关手册部分的链接:
Ctrl+ w:将光标中剩余的字符和(多个)字移动到环形缓冲区
Ctrl+ y:从环形缓冲区插入最后一个条目,然后可以使用Alt+ y在环形缓冲区中旋转.按多次以继续环形缓冲区中的"上一个"条目.