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

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

> 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+R,开始键入搜索历史中以前的命令。将显示整行。 再次按CTRL+R循环。

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

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

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

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

总结一下所有的答案:

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+A(开始行)和Ctrl+K(删除行),我熟悉emacs中的这些命令,并意外地发现了它们。