21

I have installed a plugin that doesn't provide a mechanism to disable the key mappings it defines. I want to redefine one of the mappings (<leader>cc) defined by the plugin for my own pursope, I've tried to put the following line in my .vimrc:

noremap <leader>cc echo "my purpose"

But this doesn't work, <leader>cc is still executing the plugin command.

How can I define my mapping so that it overrides those defined by the plugin?

  • one (admittedly not great) option is to just go in and edit the source and remove the offending mapping directly – JonnyRaa Apr 17 '18 at 9:32
20

Plugins are sourced after your vimrc so there's no way to override a plugin mapping in your vimrc if the plugin doesn't provide a way to do so.

Placing your custom mapping in ~/.vim/after/plugin/mystuff.vim (the name of the file doesn't matter) should allow you to override the plugin mapping.

  • 1
    Doing this doesn't work for me. I place map <C-l> something in there and it still gets overriden by Pydocstring. – oarfish Nov 19 '17 at 11:07
  • Is there a way to do this that is specific to a filetype (like ftplugin)? – Steven Lu Jul 11 '18 at 15:00
  • Also, agree, this doesn't actually even work. – Steven Lu Jul 11 '18 at 15:55
17

As mentioned in other answers, the plugins are sourced after the vimrc is done.

If you want to keep your overrides in your vimrc instead of doing an after plugin, you can use this "trick" anywhere in your vimrc file:

autocmd VimEnter * noremap <leader>cc echo "my purpose"

From :help VimEnter:

VimEnter: After doing all the startup stuff, including loading .vimrc files, executing the "-c cmd" arguments, creating all windows and loading the buffers in them.

So, anything you put in a VimEnter auto command gets run after Vim is ready. Using VimEnter this way allows you to keep all your mappings with your other settings where you are used to keeping them: vimrc.

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.