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

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

> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now>

是否有一个热键或命令可以从上面切换到:

>

?

通常我会按↓键,如果我的当前行是一个全新的历史记录,这将清除它。但如果我通过↑键浏览我的命令历史记录并开始编辑或使用这些命令,↓只会将提示符更改为历史记录中下一个最新的命令,所以除非我多次按↓,否则它不会在这里工作。


当前回答

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

其他回答

您可以使用Ctrl+U清除开始。

你可以使用Ctrl+W删除一个单词。

也可以使用Ctrl+C取消。

如果你想保留历史记录,你可以使用Alt+Shift+#使其成为注释。


Bash Emacs编辑模式备忘单

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

如果需要删除整行,且不考虑光标所在位置,可以使用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+W将清除左边的单词。

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