I am using https://github.com/scrooloose/nerdcommenter/ plugin to comment the code. It's working fine, but I would like to do a modification.

Currently these are the default mappings:

  • <leader>cc comments the line
  • <leader>ci inverts the comment
  • <leader>cu undo last comment/uncomment action

I am looking to map <leader>cc to the action of invert comment i.e. <leader>ci. It's not a nerdcommenter question, but a question of vim mappings itself, hence asking here.

I tried

nnoremap <leader>cc <leader>ci

and also

nmap <leader>cc <leader>ci

But there doesn't seems to be any effect of these mapping. On pressing <leader>cc, I am seeing original action of it not the one I am trying to define.

EDIT: FYI, answer to this question https://vi.stackexchange.com/a/763/8092 doesn't help either. i.e. to define custom mappings in .vim/after/plugin/somefile.vim

  • 1
    Does it work to put this in your .vim/after/plugin/somefile.vim: call s:CreateMaps('nx', 'Invert', 'Invert', 'cc') – DJMcMayhem Jun 20 '16 at 2:23
  • 4
    It is a nerdcommenter question, since the answer can be found in the manual: nmap <Leader>cc <Plug>NERDCommenterInvert. – Sato Katsura Jun 20 '16 at 3:46
  • 3
    No, it's a plugin-specific question. Remove any reference to NERDCommenter and rework the title to make it a generic question. – romainl Jun 20 '16 at 6:23
  • 1
    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. – nobe4 Jun 20 '16 at 8:04
  • 1
    You can use verbose nmap <leader>cc to see where the mapping was defined. – Karl Yngve Lervåg Jun 20 '16 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.