简体   繁体   English

vimrc文件中的vim映射问题,但找不到我设置的映射

[英]vim mapping problem in vimrc file but can not find the mapping that I set

I am using vim-markdown-toc plugin(successfully installed) and want to remapping some hotkey to specific function.我正在使用 vim-markdown-toc 插件(已成功安装)并希望将一些热键重新映射到特定功能。 I export this code autocmd Filetype markdown noremapb <silent> <Cx> :GenTocMarked to my .vimrc file.我将此代码autocmd Filetype markdown noremapb <silent> <Cx> :GenTocMarked到我的 .vimrc 文件中。 But when I type :verbose imap <Cx> , it shows can not find the mapping.但是当我输入:verbose imap <Cx>时,它显示找不到映射。

Can anyone tell me what's the problem about this?谁能告诉我这有什么问题?

and also I also want to ask how to map one hotkey to multiple function?而且我还想问如何将一个热键映射到多个功能?

autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked

has two obvious errors:有两个明显的错误:

  1. noremapb should be noremap , without the b : noremapb应该是noremap ,没有b

     noremap <silent> <Cx> :GenTocMarked
  2. There should be a <CR> at the end:最后应该有一个<CR>

     noremap <silent> <Cx> :GenTocMarked<CR>

    The right-hand-side of a mapping is a macro: since you press <CR> to execute the command :GenTocMarked , it should be present in the RHS.映射的右侧是一个宏:由于您按<CR>执行命令:GenTocMarked ,因此它应该存在于 RHS 中。

Then comes the diagnostic mistake: the :map command, and its non-recursive buddy :noremap create mappings for normal, visual, and operator-pending modes, but :imap prints out insert mode mappings so you can't really expect it to find a mapping created with :map .然后是诊断错误: :map命令及其非递归伙伴:noremap为正常、可视和操作符挂起模式创建映射,但是:imap打印出插入模式映射,所以你不能指望它找到使用:map创建的映射。

Then comes the semantic mistake: the re in noremap is part of nore (short for non-recursive), not of remap .然后是语义错误: noremap中的renore (非递归的缩写)的一部分,而不是remap的一部分。 <Cx> is not a mapping so you are not "remapping" anything. <Cx>不是映射,因此您不会“重新映射”任何东西。

Then comes the scoping mistake: :noremap creates mappings for three modes, which is something you probably don't want.然后是范围错误: :noremap为三种模式创建映射,这可能是您不想要的。 You should be more specific:你应该更具体:

" normal mode mapping
nnoremap <silent> <C-x> :GenTocMarked<CR>

and, finally, the autocommand abuse mistake: there already is a built-in mechanism for sourcing filetype-specific config so there is no need to reinvent the wheel in your vimrc :最后,自动命令滥用错误:已经有一个用于获取文件类型特定配置的内置机制,因此无需在vimrc中重新发明轮子:

" in after/ftplugin/markdown.vim
nnoremap <buffer> <silent> <C-x> :GenTocMarked<CR>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM