如何在 vim 之外自定义 vim 键绑定(例如:终端)? [英] How to customize vim key bindings outside vim (eg: terminal)?
问题描述
在我的 vim 编辑器中,我重新映射了一些操作,因为我不喜欢它们的默认键绑定.(例如,我使用 Ctrl h/l 转到行的开头/结尾而不是 0/$,因为以前的绑定更容易使用.)
In my vim editor, I have remapped some of the actions, as I don't like their default key bindings. (For example, I use Ctrl h/l to go to the beginning/end of the line instead of 0/$, as the former bindings are much easier to use.)
我还在我的终端(bash 和 tmux)中使用 vim 绑定,并且一些命令(如less")也使用 vim 绑定.我的自定义在那里不起作用,所以我需要记住我的自定义以及默认的键绑定,这很不方便.
I am also using vim binding in my terminal (bash and tmux) and some commands like "less" use vim bindings as well. My customization doesn't work there, so I need to remember my custom as well as the default key bindings, which is pretty inconvenient.
如何自定义 vim 之外的键绑定(例如:在 bash、tmux 和 less 中)?
How can I customize the key bindings outside vim (eg: in bash, tmux and less) ?
推荐答案
对于使用 readline 的应用程序,您可以在 ~/.inputrc 中自定义它们的键绑定.
For applications using readline, you can customize their key bindings in ~/.inputrc.
set keymap vi-insert
set keymap vi-command
"\C-h": beginning-of-line
"\C-l": end-of-line
# Line navigation in insert mode.
bind -m vi-insert "\C-h":beginning-of-line
bind -m vi-insert "\C-l":end-of-line
# Line navigation in command mode (after hitting ESC).
bind -m vi-command "\C-h":beginning-of-line
bind -m vi-command "\C-l":end-of-line
通过运行 bind -f ~/.inputrc
现在,您可以使用 Ctrl+h 和 Ctrl+l 分别移动到行首或行尾.
Now, you can use Ctrl+h and Ctrl+l to move to the beginning or end of the line respectively.
此链接包含您可以在映射中使用的所有 readline 命令:https://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html
This link contains all the readline commands you can use in your mapping: https://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html
这篇关于如何在 vim 之外自定义 vim 键绑定(例如:终端)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!