Bash 如何清除/删除终端中的当前行?
如果我使用终端并键入一行命令文本,是否有热键或清除/删除该行的方法 例如,如果我的当前行/命令非常长,如:Bash 如何清除/删除终端中的当前行?,bash,terminal,Bash,Terminal,如果我使用终端并键入一行命令文本,是否有热键或清除/删除该行的方法 例如,如果我的当前行/命令非常长,如: > git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now> ? 通常我会按按钮↓ 关键,如果我现在的路线是历史上的一条全新路线,那将清除它。但是如果我通过↑ 键并开始编辑或使用这些命令,↓ 只会将提示更改为历史上的下一个最新命令,因此除非我
> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now>
?
通常我会按按钮↓ 关键,如果我现在的路线是历史上的一条全新路线,那将清除它。但是如果我通过↑ 键并开始编辑或使用这些命令,↓ 只会将提示更改为历史上的下一个最新命令,因此除非我按↓ 多次。我不确定您是否喜欢它,但我使用Ctrl+A(开始行)和Ctrl+K(删除行)。我熟悉emacs中的这些命令,并意外地发现了它们 Ctrl+A、Ctrl+K以擦除终端中的当前行。然后,如果需要,您可以使用Ctrl+Y来调用它。您可以使用Ctrl+U清除到开头 您可以使用Ctrl+W仅删除一个单词 也可以使用Ctrl+C来取消 如果要保留历史记录,可以使用Alt+Shift+#对其进行注释
Ctrl+A、Ctrl+K的替代方法是Ctrl+E、Ctrl+U。或者如果您使用的是vi模式,请按Esc键,然后按cc键
要恢复刚才删除的内容,请按Esc键,然后按p:)来总结所有答案:
- 清理直线:可以使用Ctrl+U清除直线的开头
- 清理行:Ctrl+E Ctrl+U以擦除终端中的当前行
- 清理行:Ctrl+A Ctrl+K以擦除终端中的当前行
- 取消当前命令/行:Ctrl+C
- 调用已删除的命令:Ctrl+Y(然后Alt+Y)
- 转到行首:Ctrl+A
- 转到行尾:Ctrl+E
- 例如,如果您在命令中间,请删除前进单词:Ctrl+K
- 删除左侧的字符,直到单词的开头:Ctrl+W
- 清除整个命令提示:Ctrl+L
- 在行首和当前光标位置之间切换:Ctrl+XX
按CTRL+R再次循环。
- Ctrl+u:将移动到行首的环形缓冲区
- Ctrl+k:将移动到行尾的环形缓冲区
- Ctrl+w:将字符和(多个)单词从光标左移到环形缓冲区中
- Ctrl+y:插入环形缓冲区中的最后一个条目,然后可以使用Alt+y在环形缓冲区中旋转。按多次可继续到环形缓冲区中的“上一个”条目
kill thill line
命令,但默认情况下,该命令处于解除绑定状态。例如,可以通过插入将其绑定到Ctrl+Alt+K
"\e\C-k": kill-whole-line
进入您的Readline init文件(通常是~/.inputrc
)
各种意见:
- 为了避免意外地重新分配已用于其他用途的键序列,可以使用
检查所有绑定。检查建议使用的绑定bind-p
bind -P | grep '\\e\\C-k'
- Readline init文件名取自shell变量
。如果未设置,默认值为INPUTRC
,或者(如果不存在)~/.inputrc
。请注意,如果您有/etc/inputrc
,~/.inputrc
将被忽略/etc/inputrc
- 要重新加载Readline init文件,可以使用Ctrl+X Ctrl+R
- 相关手册章节的链接:
在Bash中有效,但在Fish中不起作用。为了清洁整条管线(两种不同的方式):
- 主页,Ctrl+K
- 结束,按Ctrl+U组合键
Alt+#注释掉当前行。如果需要,它将在历史记录中提供。另一个很好的完整列表:
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
Ctrl-U删除的行也可以用Ctrl-Y重新调用。怎么了?太酷了谢谢keks和kev,⌃+U是删除光标之前的所有内容,⌃+K是在游标之后删除所有,⌃+A是到行的开头。所以技术上⌃+C是问题的最佳解决方案Alt Shift-#不起作用?我想其他人会的。Alt Shift-#在终端
U
/a
上打印>字符,而Y
更像是剪切粘贴。多次尝试执行Ctrl
+Y
。@LưuVĩnhPhúcESC
是bash中自己的修改键。它用于取消历史导航(CT
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