如果我使用终端并输入一行文本命令,是否有热键或任何方法来清除/删除该行?

例如,如果我当前的行/命令非常长,比如:

> 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+#使其成为注释。


Bash Emacs编辑模式备忘单


Ctrl+A, Ctrl+K的替代方案是Ctrl+E, Ctrl+U。


或者如果你使用vi模式,按Esc然后cc

返回刚才擦除的内容,按Esc键,然后按p:)


总结一下所有的答案:

Clean up the line: You can use Ctrl+U to clear up to the beginning. Clean up the line: Ctrl+E Ctrl+U to wipe the current line in the terminal Clean up the line: Ctrl+A Ctrl+K to wipe the current line in the terminal Cancel the current command/line: Ctrl+C. Recall the deleted command: Ctrl+Y (then Alt+Y) Go to beginning of the line: Ctrl+A Go to end of the line: Ctrl+E Remove the forward words for example, if you are middle of the command: Ctrl+K Remove characters on the left, until the beginning of the word: Ctrl+W To clear your entire command prompt: Ctrl + L Toggle between the start of line and current cursor position: Ctrl + XX


Ctrl+W将清除左边的单词。


CTRL+R,开始键入搜索历史中以前的命令。将显示整行。 再次按CTRL+R循环。


Ctrl+u:移动到你的行开始到一个环形缓冲区 Ctrl+k:移动到你的行的末尾到一个环形缓冲区 Ctrl+w:移动字符和(多个)字左从你的光标到一个环形缓冲区 Ctrl+y:插入环缓冲区中的最后一项,然后使用Alt+y旋转环缓冲区。按多次以继续“上一个”进入环缓冲区。


如果需要删除整行,且不考虑光标所在位置,可以使用kill-whole-line命令,但缺省情况下该命令是去绑定的。例如,可以通过插入将其绑定到Ctrl+Alt+K

"\e\C-k": kill-whole-line

进入Readline初始化文件(通常是~/.inputrc)。

各种各样的备注:

To avoid accidentally re-assigning a key sequence that is already in use for something else, you can check all your bindings with bind -P. Check for the suggested binding with bind -P | grep '\\e\\C-k' The Readline init file name is is taken from the shell variable INPUTRC. If it is unset, the default is ~/.inputrc, or (if that doesn't exist) /etc/inputrc. Notice that if you have ~/.inputrc, /etc/inputrc will be ignored. To reload your Readline init file, you can use Ctrl+X Ctrl+R. Links to relevant manual sections: Readline Init File Readline killing and yanking commands The bind builtin


我有完整的快捷方式列表:

Ctrl+a Move cursor to start of line Ctrl+e Move cursor to end of line Ctrl+b Move back one character Alt+b Move back one word Ctrl+f Move forward one character Alt+f Move forward one word Ctrl+d Delete current character Ctrl+w Cut the last word Ctrl+k Cut everything after the cursor Alt+d Cut word after the cursor Alt+w Cut word before the cursor Ctrl+y Paste the last deleted command Ctrl+_ Undo Ctrl+u Cut everything before the cursor Ctrl+xx Toggle between first and current position Ctrl+l Clear the terminal Ctrl+c Cancel the command Ctrl+r Search command in history - type the search term Ctrl+j End the search at current history entry Ctrl+g Cancel the search and restore original line Ctrl+n Next command from the History Ctrl+p previous command from the History


在列表中添加:

在Emacs模式下,按Esc,然后按R,将删除整行。

我不知道为什么,只是碰巧发现了它。也许它不用于删除行,但恰好有相同的效果。如果有人知道,请告诉我,谢谢:)

在Bash中工作,但在Fish中不工作。


为了清洁整条线(2种不同的方法):

Home键,Ctrl+K 结束,按Ctrl+U键


Alt+#注释掉当前行。如果需要,它将在历史中可用。


另一个很好的完整列表:

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

Ctrl+Alt+Backspace用于删除行尾向后的单词

Ctrl+Delete用于删除行首向前的单词