【问题标题】:How to bind key to unexposed plugin function?如何将密钥绑定到未公开的插件功能?
【发布时间】:2018-09-02 14:14:18
【问题描述】:

我正在使用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 没有暴露。这意味着我不能用“minibuffer”中的: 调用它(Vim 中的名称?)。

如何映射这些只能通过预定义的键绑定访问的未公开功能?

【问题讨论】:

    标签: vim plugins key-bindings


    【解决方案1】:

    “插件”映射让插件作者可以为其插件创建任意数量的映射,而不会干扰用户自己的映射:

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

    在这种情况下,作者创建了许多插件映射(&lt;Plug&gt;CommentaryLine&lt;Plug&gt;Commentary 等)并将它们映射到无害的键序列(gcgcc 等)默认情况下 Vim 中的任何内容)在检查它们是否尚未映射到其他内容之后。

    但我不知道该怎么做,因为CommentaryLine 没有暴露。这意味着我不能用“minibuffer”中的: 调用它(Vim 中的名称?)。

    嗯,没有CommentaryLine 命令或函数开始,所以你很难找到它暴露在任何地方或从命令行调用它(这是你的“迷你缓冲区”的名称)。

    如何映射这些只能通过预定义的键绑定访问的未公开功能?

    同样,CommentaryLine 比未曝光更糟糕;它不存在!

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

    您是否尝试过以下操作?

    nmap <key> <Plug>CommentaryLine
    

    :help &lt;Plug&gt;

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 2019-12-11
      相关资源
      最近更新 更多