有没有手册来获取bash快捷键列表?

我在与bash命令行交互时使用了许多快捷方式,以使工作更轻松,更快捷。

喜欢:

  • ctrl + L :清除屏幕
  • ctrl + a / ctrl + e :移动行的开始/结束
  • ctrl + r :搜索命令的历史记录只写少数字符
  • ctrl + u / ctrl + y :剪切/粘贴该行。

还有很多,我想知道,哪些对学习肯定有用。

我想知道从哪里可以获得Ubuntu中这些快捷方式的列表? 是否有任何手册列出这些快捷方式?

注意:

我想在一个地方获取快捷方式列表及其操作。 在很短的时间内学习它们很有帮助。 那么我们可以这样获得这样的列表吗? 虽然感谢这里给出的答案..

默认值为man bash ,以及每个命令的详细信息。 如果您更改了密钥绑定,请参阅BroSlow的答案。

  Commands for Moving beginning-of-line (Ca) Move to the start of the current line. end-of-line (Ce) Move to the end of the line. forward-char (Cf) Move forward a character. backward-char (Cb) Move back a character. forward-word (Mf) Move forward to the end of the next word. Words are composed of alphanumeric characters (letters and digits). backward-word (Mb) Move back to the start of the current or previous word. Words are composed of alphanumeric characters (letters and digits). shell-forward-word Move forward to the end of the next word. Words are delimited by non-quoted shell metacharacters. shell-backward-word Move back to the start of the current or previous word. Words are delimited by non-quoted shell metacharacters. clear-screen (Cl) Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the screen. 

  reverse-search-history (Cr) Search backward starting at the current line and moving `up' through the history as necessary. This is an incremental search. 

  unix-line-discard (Cu) Kill backward from point to the beginning of the line. The killed text is saved on the kill-ring. 

  yank (Cy) Yank the top of the kill ring into the buffer at point. 

编辑

这些命令都在本手册的连续部分中,因此您可以从Commands for Moving进行浏览。 或者,您可以将整个部分保存到文本文件中

 man bash | awk '/^ Commands for Moving$/{print_this=1} /^ Programmable Completion$/{print_this=0} print_this==1{sub(/^ /,""); print}' > bash_commands.txt 

(注意这会打印整个部分,包括没有默认键盘快捷键的命令。)

awk代码的说明

  • 在(仅)出现“ Commands for Moving变量print_this设置为1。
  • 在(仅) Programmable Completion发生(以下部分)中,将变量设置为0。
  • 如果变量为1,则删除前导空格(三个空格),然后打印该行。

您可以通过使用-P选项调用bash builtin bind来列出当前bash shell中的所有快捷方式。

例如

 bind -P | grep clear clear-screen can be found on "\Cl". 

要改变它们,你可以做类似的事情

  bind '\Cp:clear-screen' 

并将其放在一个init文件中以使其永久化(请注意,您一次只能绑定一个键组合,因此它将失去以前的任何绑定)。

以下命令提供了一个很好的柱状输出,显示了使用和快捷方式。

 bind -P | grep "can be found" | sort | awk '{printf "%-40s", $1} {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}' 

这给出了一个输出,看起来像

 abort "\Cg", "\Cx\Cg", "\e\Cg". accept-line "\Cj", "\Cm". backward-char "\Cb", "\eOD", "\e[D". backward-delete-char "\Ch", "\C-?". backward-kill-line "\Cx\C-?". backward-kill-word "\e\Ch", "\e\C-?". backward-word "\e\e[D", "\e[1;5D", "\e[5D", "\eb". beginning-of-history "\e<". beginning-of-line "\Ca", "\eOH", "\e[1~", "\e[H". call-last-kbd-macro "\C-xe". capitalize-word "\ec". character-search-backward "\e\C-]". character-search "\C-]". clear-screen "\Cl". complete "\Ci", "\e\e". ... 

使用以下命令将此输出获取到文本文件中

 bind -P|grep "can be found"|sort | awk '{printf "%-40s", $1} {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}' > ~/shortcuts 

该文件在$ HOME目录中创建。

说明

  • 得到所有的捷径。

     bind -P 
  • 删除所有未分配的快捷方式

     grep "can be found" 
  • 对输出进行排序

     sort 
  • 打印第一列(即函数)并对齐文本

     awk '{printf "%-40s", $1} 
  • 这是上一个命令的一部分。 它打印6+列(即快捷方式)。

     {for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}' 
  • 将输出放入名为快捷方式的主目录中的一个漂亮的文本文件中

     > shortcuts 

您可以通过运行以下命令来了解命令的工作原理。

 bind -P bind -P | grep "can be found" bind -P | grep "can be found" | sort 

好的,我有办法通过过滤bash手册来获取快捷方式列表。 它还将描述每个快捷方式的function。 感谢Sparhawk ,他启发我找到了解决方案。 我需要的是学习正则表达式的使用虽然我仍然不擅长:)

所以这是一行命令:

 man bash | grep "(.-.*)$" -A1 

这是输出的小提取:

  beginning-of-line (Ca) Move to the start of the current line. end-of-line (Ce) Move to the end of the line. forward-char (Cf) Move forward a character. backward-char (Cb) Move back a character. forward-word (Mf) Move forward to the end of the next word. Words are composed of alphanumeric characters (letters and digits). backward-word (Mb) Move back to the start of the current or previous word. Words are composed of alphanumeric characters (letters and digits). clear-screen (Cl) Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the previous-history (Cp) Fetch the previous command from the history list, moving back in the list. next-history (Cn) Fetch the next command from the history list, moving forward in the list. beginning-of-history (M-<) Move to the first line in the history. end-of-history (M->) Move to the end of the input history, ie, the line currently being entered. reverse-search-history (Cr) Search backward starting at the current line and moving `up' through the history as necessary. This is an incremental search. forward-search-history (Cs) Search forward starting at the current line and moving `down' through the history as necessary. This is an incremental search. 

现在将快捷方式保存到文件:

 man bash | grep "(.-.*)$" -A1 > bash_shortcuts 

这就是我所需要的一切。 我只是想知道分配给bash的快捷键,而且我没有像BroSlow问我那样重新配置任何键。

再次感谢所有人的贡献。

注意

如果有人想提高这一点,他/她是最受欢迎的。 我只提到了列出一些键分配的快捷方式的方法。 因此, 如果有人知道如何列出那些没有使用这种方式分配描述的动作,那么最受欢迎:)

只要不修改bash手册以使该命令不正确(这不太可能),以下命令将显示bash所有默认快捷方式。

 man bash | grep -A294 'Commands for Moving' 

这给出了一个看起来像这样的输出:

  Commands for Moving beginning-of-line (Ca) Move to the start of the current line. end-of-line (Ce) Move to the end of the line. forward-char (Cf) Move forward a character. backward-char (Cb) Move back a character. forward-word (Mf) Move forward to the end of the next word. Words are composed of alphanumeric characters (letters and digits). backward-word (Mb) Move back to the start of the current or previous word. Words are composed of alphanumeric characters (letters and digits). shell-forward-word Move forward to the end of the next word. Words are delimited by non-quoted shell metacharacters. shell-backward-word Move back to the start of the current or previous word. Words are delimited by non-quoted shell metacharacters. clear-screen (Cl) Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the screen. redraw-current-line Refresh the current line. Commands for Manipulating the History accept-line (Newline, Return) Accept the line regardless of where the cursor is. If this line is non-empty, add it to the history list according to the state of the HISTCONTROL variable. If the line is a modified history line, then restore the history line to its original state. previous-history (Cp) Fetch the previous command from the history list, moving back in the list. next-history (Cn) ... 

如果修改了bash手册,则可以轻松更改此命令以满足需要。