vim - 如何将密钥绑定到未公开的插件功能?
问题描述
我正在使用评论。它定义了以下键绑定:
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 中的名称?)中调用它。
如何映射这些只能通过预定义的键绑定访问的未公开功能?
解决方案
“Plug”映射让插件作者可以为他们的插件创建尽可能多的映射,而不会干扰用户自己的映射:
- 该插件公开了一个
<Plug>Whatever
未映射到任何键的 - 用户可以将该插头映射映射到他想要的任何键或键序列。
在这种情况下,作者创建了许多插件映射(<Plug>CommentaryLine
,<Plug>Commentary
等),并在检查它们是否尚未映射到之后将它们映射到无害的键序列(gc
,gcc
等,默认情况下在 Vim 中不做任何事情)别的东西。
但我不知道该怎么做,因为
CommentaryLine
没有暴露。这意味着我不能:
从“迷你缓冲区”(Vim 中的名称?)中调用它。
好吧,没有CommentaryLine
命令或函数开始,所以你很难找到它暴露在任何地方或从命令行调用它(这是你的“迷你缓冲区”的名称)。
如何映射这些只能通过预定义的键绑定访问的未公开功能?
再次,CommentaryLine
比未曝光更糟糕;它不存在!
nmap gcc <Plug>CommentaryLine " <-------------------- I WANT TO REBIND THIS
您是否尝试过以下操作?
nmap <key> <Plug>CommentaryLine
见:help <Plug>
。
推荐阅读
- docker - 将 ssh-agent 传递给 dockerfile 以安装私有存储库模块
- python - Python将核苷酸翻译成氨基酸
- c++ - 我可以以某种方式将套接字从 winsock2.h 传递给 unique_ptr 并为他制作自定义删除器吗?
- amazon-web-services - 如何为存储库输入新的 AWS CodeCommit 凭证?
- c++ - 输出窗口显示抛出的异常
- windows - 如何从脚本更改 Windows 中的代理设置?
- r - 删除多个栅格图层的顺序
- html - 出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类
- facebook - Whatsapp Business API 注册 - 从 whatsapp 业务经理处获取证书
- docker - 收到 http 请求时如何在 Kubernetes 集群中执行 docker 镜像