Like many other plug-ins, NERDCommenter creates internal mappings using the <plug>
virtual key as a prefix, that you can use to map your own key-bindings to.
See :help NERDCommenterMappings
:
To change a mapping just map another key combo to the internal <plug>
mapping.
For example, to remap the NERDCommenterComment
mapping to ,omg
you would put
this line in your vimrc:
map ,omg NERDCommenterComment
This will stop the corresponding default mappings from being created.
See the help for the mapping in question to see which <plug>
mapping to
map to.
So:
You can find which <plug>
mapping to use by looking it up at the help for the original mapping.
NERDCommenter will not add its default mapping if it finds another mapping pointing to the <plug>
mapping already, so you can use that to prevent it from creating its own mappings (such as <leader>cc
), potentially overwriting yours.
Note that these mappings need to be recursive, since the <plug>
ones are mappings themselves.
In your case, I believe this is what you want:
nmap <leader>cc <plug>NERDCommenterInvert
xmap <leader>cc <plug>NERDCommenterInvert
This mapping is relevant in Normal and Visual modes, therefore remapping it with nmap
and xmap
here.
Note also that since you're using a default mapping of NERDCommenter, you'll need to remap that <plug>
mapping to some other key, in order to prevent NERDCommenter from overwriting your mapping. For example, to use <leader>ci
for the Comment mapping (effectively swapping the two keys):
nmap <leader>ci <plug>NERDCommenterComment
xmap <leader>ci <plug>NERDCommenterComment
But note that you don't need to use <leader>ci
here, you can use any other key combination.
If you would like to prevent NERDCommenter from adding all its mappings, you can use this in your vimrc:
let g:NERDCreateDefaultMappings = 0
See :help 'NERDCreateDefaultMappings'
.
Unfortunately it seems there's no granular way to prevent it from adding one mapping only (if you wanted to leave one or a few functions without key-bindings), it's all or nothing.
.vim/after/plugin/somefile.vim
:call s:CreateMaps('nx', 'Invert', 'Invert', 'cc')
nmap <Leader>cc <Plug>NERDCommenterInvert
.nmap <leader>cc <leader>ci
works here when I source my vimrc file manually (but not when vim opens). What I suspect is that your mapping gets overridden by the plugin.verbose nmap <leader>cc
to see where the mapping was defined.