如果我正在使用终端并输入一行命令文本,是否有热键或任何方式清除/删除该行?
例如,如果我当前的行/命令非常像:
> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now>
是否有热键或命令从上面开始:
>
通常我会按↓键,如果我的当前行是历史上的全新行,那将清除它。但是,如果我通过↑键浏览我的命令历史记录并开始编辑或使用这些命令,↓只会将提示更改为历史记录中的下一个最新命令,所以除非我多次按↓,否则它不起作用。
答案 0 :(得分:1227)
您可以使用 Ctrl + U 来清除开头。
您可以使用 Ctrl + W 删除一个单词。
您也可以使用 Ctrl + C 取消。
如果您想保留历史记录,可以使用 Alt + Shift + #对其进行评论。
答案 1 :(得分:497)
总结所有答案:
答案 2 :(得分:129)
我有完整的快捷键列表:
答案 3 :(得分:22)
Ctrl + A , Ctrl + K 擦除终端中的当前行。然后,如果需要,可以使用 Ctrl + Y 调用它。
答案 4 :(得分:15)
或者如果你使用vi模式,点击 Esc 后跟 cc
取回刚刚删除的内容, Esc 然后 p :)
答案 5 :(得分:10)
替代 Ctrl + A , Ctrl + K 是 Ctrl + E , Ctrl + U 。
答案 6 :(得分:9)
我不确定你是否喜欢它,但我使用 Ctrl + A (开始行)和 Ctrl + < kbd> K (删除行)我熟悉emacs中的这些命令,并意外地弄清楚了这些命令。
答案 7 :(得分:6)
Ctrl + w :移动字符和从光标留下的(多个)字到环形缓冲区
Ctrl + y :从环形缓冲区插入最后一个条目然后你可以使用 Alt + y < / kbd>通过环形缓冲区旋转。按多次以继续环形缓冲区中的“上一个”条目。
答案 8 :(得分:3)
CTRL + R 并开始输入以搜索历史记录中的先前命令。将显示全线。
CTRL + R 再次循环。
答案 9 :(得分:2)
Ctrl + W 将清除左侧的单词。
答案 10 :(得分:2)
要删除整行,无论光标在哪里,都可以使用kill-whole-line
命令,但默认情况下它是未绑定的。例如,它可以通过插入
"\e\C-k": kill-whole-line
进入您的Readline初始文件(通常为~/.inputrc
)。
各种评论:
为避免意外重新分配已用于其他内容的键序列,您可以使用bind -P
检查所有绑定。使用
bind -P | grep '\\e\\C-k'
INPUTRC
。如果未设置,则默认值为~/.inputrc
,或者(如果不存在)/etc/inputrc
。请注意,如果您有~/.inputrc
,则会忽略/etc/inputrc
。答案 11 :(得分:2)
为了清洁整条线(两种不同方式):
答案 12 :(得分:1)
另一个不错的完整列表:
TERINAL 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
答案 13 :(得分:0)
Alt + #注释掉当前行。如果需要,它将在历史记录中可用。