如何将密钥绑定到未公开的插件功能?
How to bind key to unexposed plugin function?
我正在使用 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 中的名称?)。
如何映射这些只能通过预定义键绑定访问的未公开功能?
"Plug" 映射让插件作者可以为他们的插件创建尽可能多的映射,而不会干扰用户自己的映射:
- 插件暴露了一个
<Plug>Whatever
没有映射到任何键,
- 用户可以将该插头映射映射到他想要的任何键或键序列。
在这种情况下,作者创建了一些插头映射(<Plug>CommentaryLine
、<Plug>Commentary
等)并将它们映射到无害的键序列(gc
、gcc
, 等等,默认情况下在 Vim 中不执行任何操作)在检查它们是否尚未映射到其他内容后。
But I can't figure out how to do that, as CommentaryLine
is not exposed. Meaning I cannot call it with :
from the "minibuffer" (name for that in Vim?).
好吧,没有 CommentaryLine
命令或函数开始,因此您将很难找到它暴露在任何地方或从命令行调用它(这是您的 "minibuffer" ).
How can such unexposed functions, that are only accessible to the user through predefined key bindings, be mapped?
同样,CommentaryLine
比未曝光还差;它不存在!
nmap gcc <Plug>CommentaryLine " <-------------------- I WANT TO REBIND THIS
您尝试过以下方法吗?
nmap <key> <Plug>CommentaryLine
见:help <Plug>
。
我正在使用 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 中的名称?)。
如何映射这些只能通过预定义键绑定访问的未公开功能?
"Plug" 映射让插件作者可以为他们的插件创建尽可能多的映射,而不会干扰用户自己的映射:
- 插件暴露了一个
<Plug>Whatever
没有映射到任何键, - 用户可以将该插头映射映射到他想要的任何键或键序列。
在这种情况下,作者创建了一些插头映射(<Plug>CommentaryLine
、<Plug>Commentary
等)并将它们映射到无害的键序列(gc
、gcc
, 等等,默认情况下在 Vim 中不执行任何操作)在检查它们是否尚未映射到其他内容后。
But I can't figure out how to do that, as
CommentaryLine
is not exposed. Meaning I cannot call it with:
from the "minibuffer" (name for that in Vim?).
好吧,没有 CommentaryLine
命令或函数开始,因此您将很难找到它暴露在任何地方或从命令行调用它(这是您的 "minibuffer" ).
How can such unexposed functions, that are only accessible to the user through predefined key bindings, be mapped?
同样,CommentaryLine
比未曝光还差;它不存在!
nmap gcc <Plug>CommentaryLine " <-------------------- I WANT TO REBIND THIS
您尝试过以下方法吗?
nmap <key> <Plug>CommentaryLine
见:help <Plug>
。