From f9a933991d8e6033e501603ba2ff6f3319b4f308 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Tue, 15 Jul 2014 18:54:57 +0100 Subject: [PATCH] allow plugins to override the default mappings --- doc/NERD_tree.txt | 3 +++ lib/nerdtree/key_map.vim | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt index 4ddc250..79b649f 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERD_tree.txt @@ -1060,6 +1060,9 @@ NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()* "callback" - the function the new mapping will be bound to "quickhelpText" - the text that will appear in the quickhelp (see |NERDTree-?|) + "override" - if 1 then this new mapping will override whatever previous + mapping was defined for the key/scope combo. Useful for overriding the + default mappings. Additionally, a "scope" argument may be supplied. This constrains the mapping so that it is only activated if the cursor is on a certain object. diff --git a/lib/nerdtree/key_map.vim b/lib/nerdtree/key_map.vim index 27dab55..07311ef 100644 --- a/lib/nerdtree/key_map.vim +++ b/lib/nerdtree/key_map.vim @@ -134,8 +134,14 @@ endfunction "FUNCTION: KeyMap.Create(options) {{{1 function! s:KeyMap.Create(options) - let newKeyMap = copy(self) let opts = extend({'scope': 'all', 'quickhelpText': ''}, copy(a:options)) + + "dont override other mappings unless the 'override' option is given + if get(opts, 'override', 0) == 0 && !empty(s:KeyMap.FindFor(opts['key'], opts['scope'])) + return + end + + let newKeyMap = copy(self) let newKeyMap.key = opts['key'] let newKeyMap.quickhelpText = opts['quickhelpText'] let newKeyMap.callback = opts['callback']