Is there a common way to remap keys used in specific Vim plugins, like NERDTree or 开发者_开发问答TagList? I've been trying to remap some keys for the TagList plugin but I've been unable to do so. NERDTree's keys have been easier to remap, but is that because of the way the plugin is written?
Modern plugins can be written to be re-mappable like built-in vim commands if they use <Plug>
(:help using-<Plug>
). The plugin can check if the user has mapped something to the <Plug>
command (example: <Plug>(textobj-indent-a)
), if not then it uses its own mapping. That way the user can define the maps they want and the plugin will fill in the rest.
In rkulla's answer, he shows you NERD_tree's mapping code. What they're doing is providing variables for the user to set to change their mappings:
let g:NERDTreeMapDeleteBookmark = 'A'
let g:NERDTreeMapMenu = 'B'
let g:NERDTreeMapHelp = 'C'
Those statements can be added to your vimrc to define your own maps (instead of changing the plugin code).
Other plugins will use a variable named something like no_nerdtree_maps
(different name for each plugin). If you set this variable in your vimrc, then you can create your own maps to the plugin's functions/commands.
Just open NERD_tree.vim in your plugins dir and you'll see a section called "Init variable calls for key mappings" with calls like:
call s:initVariable("g:NERDTreeMapDeleteBookmark", "D")
call s:initVariable("g:NERDTreeMapMenu", "m")
call s:initVariable("g:NERDTreeMapHelp", "?")
...
the second argument to s:initVariable() is the keyboard shortcut to use. Simply change it to what you want.
精彩评论