Sau*_*mar 21 bash shortcut-keys
我在与bash 命令行交互时使用了许多快捷方式,以使工作更轻松、更快捷。
喜欢:
还有更多,我想知道并且学习肯定有用。
我想知道从哪里可以获得 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。小智 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 文件中以使其永久化(请注意,您一次只能将一个组合键绑定到一件事,因此它将失去之前的任何绑定)。
以下命令提供了一个很好的柱状输出,显示了用法和快捷方式。
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
Run Code Online (Sandbox Code Playgroud)
删除所有未分配的快捷方式
grep "can be found"
Run Code Online (Sandbox Code Playgroud)
对输出进行排序
sort
Run Code Online (Sandbox Code Playgroud)
打印第一列(即函数)并对齐文本
awk '{printf "%-40s", $1}
Run Code Online (Sandbox Code Playgroud)
这是上一个命令的一部分。它打印第 6+ 列(即快捷方式)。
{for(i=6;i<=NF;i++){printf "%s ", $i}{printf"\n"}}'
Run Code Online (Sandbox Code Playgroud)
将输出放入名为快捷方式的主目录中的一个漂亮的文本文件中
> shortcuts
Run Code Online (Sandbox Code Playgroud)
您可以通过运行以下命令来了解该命令的工作原理。
bind -P
bind -P | grep "can be found"
bind -P | grep "can be found" | sort
Run Code Online (Sandbox Code Playgroud)