是否有任何手册可以获取 bash 快捷键列表?

Sau*_*mar 21 bash shortcut-keys

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

喜欢:

  • ctrl+ L: 清屏
  • ctrl+ a/ ctrl+ e: 移动行的开始/结束
  • ctrl+ r: 只写几个字符就可以搜索命令的历史记录
  • ctrl+ u/ ctrl+ y: 剪切/粘贴行。

还有更多,我想知道并且学习肯定有用。

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

笔记:

我想在一个地方获取快捷方式列表及其操作。在很短的时间内学习其中的许多知识真的很有帮助。那么我们有没有办法得到这样的列表呢?虽然感谢这里给出的答案..

Spa*_*awk 24

默认值在 中man bash,以及有关每个命令的作用的详细信息。如果您更改了键绑定,请参阅 BroSlow 的回答。

   Commands for Moving
       beginning-of-line (C-a)
              Move to the start of the current line.
       end-of-line (C-e)
              Move to the end of the line.
       forward-char (C-f)
              Move forward a character.
       backward-char (C-b)
              Move back a character.
       forward-word (M-f)
              Move forward to the end of the next word.  Words are composed of alphanumeric characters (letters and digits).
       backward-word (M-b)
              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 (C-l)
              Clear the screen leaving the current line at the top of the screen.  With an argument, refresh the current line without clearing the screen.
Run Code Online (Sandbox Code Playgroud)

...

       reverse-search-history (C-r)
              Search backward starting at the current line and moving `up' through the history as necessary.  This is an incremental search.
Run Code Online (Sandbox Code Playgroud)

...

       unix-line-discard (C-u)
              Kill backward from point to the beginning of the line.  The killed text is saved on the kill-ring.
Run Code Online (Sandbox Code Playgroud)

...

       yank (C-y)
          Yank the top of the kill ring into the buffer at point.
Run Code Online (Sandbox Code Playgroud)

编辑

这些命令都在手册的连续部分中,因此您可以从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
Run Code Online (Sandbox Code Playgroud)

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

awk 代码说明

  • 在(仅)出现 时Commands for Moving,将变量设置print_this为 1。
  • 在(仅)出现 时Programmable Completion,即以下部分,将变量设置为 0。
  • 如果变量为 1,则去掉前导空格(三个空格),并打印该行。


小智 21

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

例如

bind -P | grep clear
clear-screen can be found on "\C-l".
Run Code Online (Sandbox Code Playgroud)

要更改它们,您可以执行以下操作

 bind '\C-p:clear-screen'
Run Code Online (Sandbox Code Playgroud)

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

  • @SauravKumar `bind -P` 应该给你所有的快捷方式。如果您的意思是忽略那些没有绑定/读取线函数映射的那些,您可以执行类似`bind -P | 的操作。grep -v“未绑定”` (2认同)

Reg*_*ser 9

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

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

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

abort                                   "\C-g", "\C-x\C-g", "\e\C-g". 
accept-line                             "\C-j", "\C-m". 
backward-char                           "\C-b", "\eOD", "\e[D". 
backward-delete-char                    "\C-h", "\C-?". 
backward-kill-line                      "\C-x\C-?". 
backward-kill-word                      "\e\C-h", "\e\C-?". 
backward-word                           "\e\e[D", "\e[1;5D", "\e[5D", "\eb". 
beginning-of-history                    "\e<". 
beginning-of-line                       "\C-a", "\eOH", "\e[1~", "\e[H". 
call-last-kbd-macro                     "\C-xe". 
capitalize-word                         "\ec". 
character-search-backward               "\e\C-]". 
character-search                        "\C-]". 
clear-screen                            "\C-l". 
complete                                "\C-i", "\e\e". 
...
Run Code Online (Sandbox Code Playgroud)

使用以下命令将此输出转换为文本文件

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

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

解释

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

bind -P
bind -P | grep "can be found"
bind -P | grep "can be found" | sort
Run Code Online (Sandbox Code Playgroud)

  • +1 为您的回答并使其更有意义.. :) 我错过了 **to** 并且它改变了句子的整体含义 ;) 不,您不必添加任何内容。你已经尽力了。。 (2认同)