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?

toro2k
  • 4,882
  • 1
  • 31
  • 35
  • 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 09:32

3 Answers3

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.

romainl
  • 40,486
  • 5
  • 85
  • 117
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.

John O'M.
  • 8,552
  • 2
  • 42
  • 58
  • 2
    a downside to this approach is that you need to restart vim after adding such a mapping – jameh May 09 '20 at 06: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!

Kaka Ruto
  • 311
  • 3
  • 6