Cannot remap <F5> in Vim

2.1k views Asked by At

I use vundle and some other plugins for Vim

When I execute :map <F5> I see <F5> :!ruby %<CR>

But I have defined in the end of my ~/.vimrc after all Bundle instuctions these mappings:

imap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
nmap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
omap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
cmap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
vmap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
smap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
xmap <F5> <Esc><Esc>:w<CR>:!ruby %<CR>
map <F5> <Esc><Esc>:w<CR>:!ruby %<CR> 

Also if I execute in Vim :map <F5> <Esc><Esc>:w<CR>:!ruby %<CR> it works the way it should. Seems like my mappings in .vimrc are ignored.

Why is that? How to remap <F5> ?

UPDATE:

:verbose map <F5>
   <F5>          :!ruby %<CR>
        Last set from ~/Dropbox/home/.vim/bundle/ruby-menu.vim/plugin/ruby-menu.vim

Actually I don't need ruby-menu plugin, gonna trash it. Btw, why does it remap my mappings?

1

There are 1 answers

1
Ingo Karkat On BEST ANSWER

You can check where this got defined via

:verbose map <F5>

It seems to be from this line in the ruby-menu plugin. That plugin should offer <Plug>-mapping targets that would allow you to change the mapped keys, or disable the mapping altogether. You could file a defect against it.

The plugin overrides your mapping, because by the time the plugin loads, your .vimrc already has finished processing.

To workaround, you need to define the mapping after the plugin loads, with one of these methods:

  1. use the after directory and put your overriding mapping definitions into ~/.vim/bundle/ruby-menu.vim/after/plugin/ruby-menu.vim
  2. use another location (e.g. ~/.vim/after/plugin/mappings-override.vim) that is sourced after the plugins (check with :scriptnames)
  3. try the override from your ~/.vimrc via autocmd VimEnter * map <F5> ..., thereby delaying the actual definition until after the plugins have been initialized