问题
After installing vim-ruby-debugger that plugin "hijacks" several mappings. Like <leader>n
, or <leader>t
which I use for respectively NERDTreeToggle and Command-T find.
The culprit is found at the hardcoded mappings in this ruby-debugger.
I'd prefer to have these remapped as <leader>rdX
, i.e.: prefixed with *r*uby-*d*ebugger. Obviously, I could simply hack the plugin and change the mappings there. But that seems a bit too hackish (and will probably break on updates).
How can I unmap these mappings, so vim will fallback to my own mappings again? And so that I can remap the commands in my .vimrc (where it should be, IMHO).
回答1:
First, I agree with ZyX's comments that this is a problem in the plugin that should be fixed. Please ask the plugin author to provide customization.
There is no easy way to unmap, because Vim does not remember the original mappings when a mapping is overridden. You have to make a note of the original mappings (:map ...
when the offending plugin is temporarily disabled, or look in the Vim script for their definitions), then re-execute them after the offending plugin has been loaded (minus any <unique>
flags it may have, as these will cause errors on re-execution). This cannot be done in .vimrc
, it is sourced first; I would recommend a place like ~/.vim/after/plugin/zzzmappings.vim
for this.
回答2:
I keep all of my mappings in after/plugin/keys.vim
. This seems to ensure that they always take precedence over plugin mappings. (I use a bunch of plugins, and the collisions seem taken care of) (here's my nvim config)
FWIW, I also keep filetype-specific mappings in the same folder, but write them as autocmd FileType
commands with the <buffer>
keyword. For example, the following is a mapping that conflicts with bullets.vim's ToggleCheckbox
function (it adds an empty checkbox to the bullet if there is none)
autocmd FileType markdown nnoremap <buffer> <expr> <leader>x (getline('.') =~ '^\s*- \[' ? ':ToggleCheckbox<cr>' : '0/-<space><cr>la[<space>]<space><esc>')
来源:https://stackoverflow.com/questions/12770103/overriding-a-remapping-from-a-plugin