有没有解决方案可以在终端使用中为单词分配特殊组合键。例如,less 命令非常有用,我经常使用它来通过管道传输另一个进程的输出。
这个想法是设置仅在终端使用时才有效、用于编写不同命令的特殊组合键?因此,在终端窗口中按Ctrl+可以编写L
| less
或Ctrl+G可以代表
| grep
注意:我只是说将字母添加到命令行而不是执行 finally。方法与 tabcompletion 类似但更具体。
答案1
是的,你可以使用 bind 命令
bind '"\ey"':"\"less \C-m\""
将 Alt-e 映射到 less 命令并执行它(使用 \Cm 又名 Ctrl-m )
可能对于|你需要逃避它。
bind '"\ey"':"\"\|less \C-m\""
如果您只想将其附加到命令行,请删除 *\Cm\""
请小心,因为已经定义了一些绑定:
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor
Alt + F Move cursor forward one word on the current line
Alt + B Move cursor backward one word on the current line
Tab Auto-complete files and folder names
如上所示,Control 键由 Cm 组成,因此您可以使用 Ctrl-g 启动 less 命令,如下所示:
绑定'“\Cg”':“\”\|less *\Cm\”
要获取 Alt 的键代码(仅适用于 ALT),您可以使用 shell 中的 read 命令:
@~$ read
^[y
^[y 等于 \ey
欲了解更多信息,请访问 stackoverflow 了解该问题的答案:
https://stackoverflow.com/questions/4119991/bash-call-script-with-customized-keyboard-shortcuts