6

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') – James Jun 20 '16 at 2:23
  • 5
    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
  • 4
    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
  • 2
    You can use verbose nmap <leader>cc to see where the mapping was defined. – Karl Yngve Lervåg Jun 20 '16 at 8:33
0

Seems that plugins have "actions" that you can call with :call.

For example to map Alt+; to nerdcomment toggle:

nnoremap <M-;> :call NERDComment(0,"toggle")<CR>
vnoremap <M-;> :call NERDComment(0,"toggle")<CR>

Related answer: https://stackoverflow.com/a/30831547/1663462

|improve this answer|||||
  • Welcome to this site Chris! Just a clarification about vocabulary: something that you can call with call is a "function", see :h user-functions. And of course they exists only with the plugin author decides to expose them to the user :) – statox Mar 2 at 16:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.