如何配置 matchit.vim 以使用而不是%?
我是 matchit.vim 插件的忠实粉丝,但我更喜欢使用
键在匹配的分隔符之间跳转。然而,似乎 matchit 是硬编码的,以便在按 % 键时激活。
我的第一个想法是,我只需将此行放入我的 .vimrc 中,并将 '%
' 更改为 '
',从而将 Match_wrapper 调用绑定到Tab 键:
nnoremap <silent> % :<C-U>call <SID>Match_wrapper('',1,'n') <CR>
但是,这似乎不起作用;我猜这与
(据我所知是脚本唯一的 ID?)或 Match_wrapper 是脚本本地的事实有关。 (我对 Vimscript 还很陌生)
到目前为止,我已经成功地通过使用“nmap”将
映射到 %
来实现,但这是一个非常脆弱的黑客攻击。
无论如何,任何帮助将不胜感激! :)
I'm a big fan of the matchit.vim plugin, but I prefer to jump between matching delimiters with the <tab>
key. However, it seems that matchit is hard-coded to activate when pressing the % key.
My first thought would be that I would simply put this line in my .vimrc, and change '%
' to '<tab>
', thus binding the Match_wrapper call to the tab key:
nnoremap <silent> % :<C-U>call <SID>Match_wrapper('',1,'n') <CR>
However, this doesn't seem to work; I'm guessing it has got something to do with the <SID>
(which as far as I understand is an ID unique to the script?) or the fact that Match_wrapper is script-local. (I'm pretty new to Vimscript)
Thus far I've managed to get by mapping <tab>
to %
with 'nmap', but it's a pretty fragile hack.
Anyway, any help would be greatly appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,如果您知道
%
将总是被重新映射,那么使用是安全的(前面缺少
n
是故意的:%
在:map
涵盖的所有模式中定义。但您始终可以做的是将
替换为{N}_
,其中{N}
是数字:scriptnames
输出中的 matchit 脚本的名称。在较新的 vim 中,您还可以使用maparg('%', 'n', 0, 1)
,它将输出一个字典,其中包含lhs
和 <代码>sid。在这种情况下,代码可能如下所示:在这种情况下
,也可以接受,因为 maparg 的“旧”(没有第四个参数)行为是扩展
。Well, if you know that
%
will always be remapped, then usingis safe (absence of
n
in front is intentional:%
is defined in all modes covered by:map
). But what you can always do is to replace<SID>
with<SNR>{N}_
where{N}
is the number of the matchit script in the outputs of:scriptnames
. In a newer vim you can also usemaparg('%', 'n', 0, 1)
, it will output a dictionary that among other values containslhs
andsid
. In this case code may look like this:In this case
is also acceptable as “old” (without fourth argument) behavior of maparg is to expand
<SID>
.这就是我所做的:
Here's what I did:
或者,为了以防万一,您也可以使用这些映射(使用 Vim 8.0 进行测试):
Or, just in case, you can also use these mapping (tested with Vim 8.0):