代码之家  ›  专栏  ›  技术社区  ›  lo tolmencre

如何将密钥绑定到未公开的插件函数?

  •  0
  • lo tolmencre  · 技术社区  · 7 年前

    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
    

    gcc M-; ,因为这是用于注释切换的Emacs绑定。但我也不知道该怎么做 CommentaryLine 没有暴露。意思是我不能用 : 从“minibuffer”(Vim中的名称?)。

    这些未公开的函数只能通过预定义的键绑定供用户访问,如何映射这些函数?

    1 回复  |  直到 7 年前
        1
  •  3
  •   romainl    7 年前

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

    <Plug>CommentaryLine , <Plug>Commentary ,并将它们映射到无害的键序列( gc gcc ,在检查它们是否还没有映射到其他对象之后。

    但我也不知道该怎么做 CommentaryLine 没有暴露。意思是我不能用 :

    嗯,没有 注释行 命令或函数,这样您将很难找到它暴露在任何地方或从命令行调用它(这是您的“minibuffer”的名称)。

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

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

    nmap <key> <Plug>CommentaryLine
    

    看到了吗 :help <Plug>