在 Bash 提示符中,为什么 Control+x 和 Backspace 会清除当前行?

在 Bash 提示符中,为什么 Control+x 和 Backspace 会清除当前行?

我偶然发现了这一点:Control+x之后Backspace

有人知道为什么这会清除线路吗?有文档吗?

答案1

是的。来自man bash

   Killing and Yanking
       kill-line (C-k)
              Kill the text from point to the end of the line.
       backward-kill-line (C-x Rubout)
              Kill backward to the beginning of the line.

答案2

这相当于 Windows 中的剪切。您可以使用 Ctrl+Y 将其粘贴回去。

答案3

如上所述,它在手册页中。更准确地说,有问题的组合键来自 EMACS,它是许多 Linux 发行版中 Bash 的默认键绑定。如果您需要在 Bash 下使用 vi,则可以使用:

set -o vi

要切换回 EMACS:

set -o emacs

答案4

bash支持一种叫做readline库,它允许你用 shell 做很多事情。其中之一就是readline配置了一个大量默认键盘快捷键, 例如:

Ctrl-b  Move the cursor one character   ⇦ to the left
Ctrl-f  Move the cursor one character   ⇨ to the right
Alt-b   Move the cursor one word    ⇦ to the left
Alt-f   Move the cursor one word    ⇨ to the right
Ctrl-a  Move the cursor     ⇤ to the start of the line
Ctrl-e  Move the cursor     ⇥ to the end of the line
Ctrl-x-x    Move the cursor      ⇤⇥ to the start, and to the end again
Ctrl-d  Delete  the character   underneath the cursor
Ctrl-u  Delete  everything  ⇤ from the cursor back to the line start
Ctrl-k  Delete  everything  ⇥ from the cursor to the end of the line
Alt-d   Delete  word    ⇨ untill before the next word boundary
Ctrl-w  Delete  word    ⇦ untill after the previous word boundary
Ctrl-y  Yank/Paste  prev. killed text   at the cursor position
Alt-y   Yank/Paste  prev. prev. killed text at the cursor position
Ctrl-p  Move in history one line    ⇧ before this line
Ctrl-n  Move in history one line    ⇩ after this line
Alt->   Move in history all the lines   ⇩ to the line currently being entered
Ctrl-r  Incrementally search the line history   ⇧ backwardly
Ctrl-s  Incrementally search the line history   ⇩ forwardly
Ctrl-J  End an incremental search
Ctrl-G  Abort an incremental search and restore the original line
Alt-Ctrl-y  Yank/Paste  arg. 1 of prev. cmnd    at the cursor position
Alt-.
Alt-_   Yank/Paste  last arg of prev. cmnd  at the cursor position
Ctrl-_
Ctrl-x
Ctrl-u  Undo the last editing command; you can undo all the way back to an empty line
Alt-r   Undo all changes made to this line
Ctrl-l  Clear the screen, reprinting the current line at the top
Ctrl-l  Clear the screen, reprinting the current line at the top
Completion  TAB Auto-complete a name
Alt-/   Auto-complete a name (without smart completion)
Alt-?   List the possible completions of the preceeding text
Alt-*   Insert all possible completions of the preceeding text
Ctrl-t  Transpose/drag  char. before the cursor ↷ over the character at the cursor
Alt-t   Transpose/drag  word before the cursor  ↷ over the word at/after the cursor

以下是一些关于定制的有用信息readline也一样。

相关内容