I am using vim-markdown-toc plugin(successfully installed) and want to remapping some hotkey to specific function. I export this code autocmd Filetype markdown noremapb <silent> <Cx> :GenTocMarked
to my .vimrc file. But when I type :verbose imap <Cx>
, it shows can not find the mapping.
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:
noremapb
should be noremap
, without the b
:
noremap <silent> <Cx> :GenTocMarked
There should be a <CR>
at the end:
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.
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
.
Then comes the semantic mistake: the re
in noremap
is part of nore
(short for non-recursive), not of remap
. <Cx>
is not a mapping so you are not "remapping" anything.
Then comes the scoping mistake: :noremap
creates mappings for three modes, which is something you probably don't want. 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
:
" in after/ftplugin/markdown.vim
nnoremap <buffer> <silent> <C-x> :GenTocMarked<CR>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.