31

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?

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

3 Answers 3

28

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.

3
  • 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, 2017 at 11:07
  • Is there a way to do this that is specific to a filetype (like ftplugin)?
    – Steven Lu
    Jul 11, 2018 at 15:00
  • Also, agree, this doesn't actually even work.
    – Steven Lu
    Jul 11, 2018 at 15:55
26

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.

1
  • 2
    a downside to this approach is that you need to restart vim after adding such a mapping
    – jameh
    May 9, 2020 at 6:34
3

I wanted to unmap <leader>is from the 'alternates' plugin a.vim

Oh, but before I knew it came from a.vim, I had to find out which plugin caused this, so I checked with :verbose map <leader>is and there it was in it's glory

I then created a new file to hold all unmaps at ~/.vim/after/plugin/unmap.vim and wrote the unmap

unmap <leader>is

Now <leader>is behaves as I want it to!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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