Skip to content

Commit f9a9339

Browse files
committed
allow plugins to override the default mappings
1 parent aa831e2 commit f9a9339

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

doc/NERD_tree.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()*
10601060
"callback" - the function the new mapping will be bound to
10611061
"quickhelpText" - the text that will appear in the quickhelp (see
10621062
|NERDTree-?|)
1063+
"override" - if 1 then this new mapping will override whatever previous
1064+
mapping was defined for the key/scope combo. Useful for overriding the
1065+
default mappings.
10631066

10641067
Additionally, a "scope" argument may be supplied. This constrains the
10651068
mapping so that it is only activated if the cursor is on a certain object.

lib/nerdtree/key_map.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ endfunction
134134

135135
"FUNCTION: KeyMap.Create(options) {{{1
136136
function! s:KeyMap.Create(options)
137-
let newKeyMap = copy(self)
138137
let opts = extend({'scope': 'all', 'quickhelpText': ''}, copy(a:options))
138+
139+
"dont override other mappings unless the 'override' option is given
140+
if get(opts, 'override', 0) == 0 && !empty(s:KeyMap.FindFor(opts['key'], opts['scope']))
141+
return
142+
end
143+
144+
let newKeyMap = copy(self)
139145
let newKeyMap.key = opts['key']
140146
let newKeyMap.quickhelpText = opts['quickhelpText']
141147
let newKeyMap.callback = opts['callback']

0 commit comments

Comments
 (0)