如何将键绑定到未曝光的插件函数?

问题描述 投票:0回答:1

我正在使用Commentary。它定义了以下键绑定:

command! -range -bar Commentary call s:go(<line1>,<line2>)
xnoremap <expr>   <Plug>Commentary     <SID>go()
nnoremap <expr>   <Plug>Commentary     <SID>go()
nnoremap <expr>   <Plug>CommentaryLine <SID>go() . '_'
onoremap <silent> <Plug>Commentary        :<C-U>call <SID>textobject(get(v:, 'operator', '') ==# 'c')<CR>
nnoremap <silent> <Plug>ChangeCommentary c:<C-U>call <SID>textobject(1)<CR>
nmap <silent> <Plug>CommentaryUndo :echoerr "Change your <Plug>CommentaryUndo map to <Plug>Commentary<Plug>Commentary"<CR>

if !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# ''
  xmap gc  <Plug>Commentary
  nmap gc  <Plug>Commentary
  omap gc  <Plug>Commentary

  nmap gcc <Plug>CommentaryLine " <-------------------- I WANT TO REBIND THIS

  if maparg('c','n') ==# '' && !exists('v:operator')
    nmap cgc <Plug>ChangeCommentary
  endif
  nmap gcu <Plug>Commentary<Plug>Commentary
endif

为了保持我的肌肉记忆在Vim和Emacs之间兼容,我想将gcc映射到M-;,因为这是我的Emacs绑定评论切换。但我无法弄清楚如何做到这一点,因为CommentaryLine没有曝光。意思是我不能用“迷你缓冲器”中的:来调用它(Vim中的名字?)。

如何映射仅通过预定义键绑定可供用户访问的此类未公开函数?

vim plugins key-bindings
1个回答
3
投票

“插件”映射允许插件作者为他们的插件创建尽可能多的映射,而不会干扰用户自己的映射:

  • 该插件公开了一个未映射到任何键的<Plug>Whatever
  • 用户可以将该插件映射映射到他想要的任何键或键序列。

在这种情况下,作者创建了许多插件映射(<Plug>CommentaryLine<Plug>Commentary等)并将它们映射到无害的密钥序列(gcgcc等,默认情况下在Vim中没有做任何事情),检查它们是否是尚未映射到别的东西。

但我无法弄清楚如何做到这一点,因为CommentaryLine没有曝光。意思是我不能用“迷你缓冲器”中的:来调用它(Vim中的名字?)。

好吧,开始时没有CommentaryLine命令或功能,因此您很难在任何地方找到它或从命令行调用它(这是您的“迷你缓冲区”的名称)。

如何映射仅通过预定义键绑定可供用户访问的此类未公开函数?

再次,CommentaryLine比未曝光更糟糕;它不存在!

nmap gcc <Plug>CommentaryLine " <-------------------- I WANT TO REBIND THIS

你试过以下吗?

nmap <key> <Plug>CommentaryLine

:help <Plug>

© www.soinside.com 2019 - 2024. All rights reserved.