如何“重写"密码?现有的vim键绑定? [英] How to "rewrite" existing vim key bindings?
问题描述
我想分配 CTRL + L 进入下一个标签页(:tabnext
).我将其放置在~/.vimrc
:
I want to assign CTRL+L to go the next tab (:tabnext
). I placed it at ~/.vimrc
:
nmap <c-l> :tabnext<CR>
它工作正常,但是当我在多个窗口上拆分屏幕时,我遇到了无法正常工作的情况.似乎 CTRL + L 与重新绘制屏幕"冲突.默认情况下分配的操作.例如,当我在中心窗口上按 CTRL + L 时,我什么也没得到(请参见屏幕截图):
It worked fine, but I faced with a case when it doesn't work when I split screen on several windows. It seems that CTRL+L conflicts with "redraw screen" action assigned by default. For example, when I press CTRL+L on the center window I get nothing (see the screenshot):
但是,当我在左右两个窗口上按相同的按钮时,它仍然可以正常工作. 我认为我需要重写"默认操作,不是吗?
However when I press the same on either left or right windows it works fine.. I think I need to "rewrite" the default action, doesn't it?
我在终端上使用vim.
推荐答案
如果没有记错的话,中间的窗口是netrw(Vim的文件管理标准插件).它不是一个自定义插件,但仍然是一个插件.
The window in the middle, if I am not mistaken, is netrw (Vim's standard plugin for file management). It is not a custom plugin, but it is a plugin nevertheless.
如果您查看:help netrw-ctrl-l
,您会发现它不仅是重绘,而且还会刷新目录.因此,它是从插件映射的,仅覆盖了netrw Windows的默认ctrl-l映射.
If you take a look at :help netrw-ctrl-l
, you will see that it is not just a redraw - it also refreshes the directory. So it is mapped from the plugin, overriding the default ctrl-l mapping for netrw windows only.
如果在该窗口中执行:verbose nmap <c-l>
,您将确切地看到它的定义位置:在Vim安装的autoload/netrw.vim
文件中.看那里,我们发现以下代码段:
If you execute :verbose nmap <c-l>
in that window, you will see exactly where it is defined: in autoload/netrw.vim
file in your Vim installation. Looking there, we find this snippet:
if !hasmapto('<Plug>NetrwRefresh')
nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
endif
这说,如果<Plug>NetrwRefresh
未绑定任何东西,则绑定<c-l>
.这提供了一个简单的解决方案:由于netrw.vim
与其他所有内容一样,都在.vimrc
之后加载,因此,如果您将这些映射定义为其他键,则不会将它们分配给<c-l>
,并且不会覆盖您的映射.因此,只需在您的.vimrc
:
Which says, if <Plug>NetrwRefresh
is not bound to anything, then bind <c-l>
. This presents an easy solution: since netrw.vim
is, like everything else, loaded after .vimrc
, if you define those mappings to some other key, they won't be assigned to <c-l>
, and your mapping will not be overridden. So just do this in your .vimrc
:
nmap <unique> <c-r> <Plug>NetrwRefresh
但是,更好的方法是不要踩Vim的脚趾.
However, a better way would be to not step on Vim's toes.
这篇关于如何“重写"密码?现有的vim键绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!