From f29d6a4f0ffda654e620bf9606357f807867c332 Mon Sep 17 00:00:00 2001 From: Chris Perl Date: Thu, 26 Jan 2012 16:50:55 -0500 Subject: [PATCH] Escape mappings that use '<>' notation. KeyMap.bind() does not gracefully handle use of '<>' notation. For example, trying to call NERDTreeAddKeyMap() with a 'key' argument of 'e'. There were some workarounds KeyMap.bind() to help with this by specifically allowing you to leave off the '<>' parts for '', '' and mouse mappings and it would add them back for you before creating the mapping. This commit reverts some of that logic and simply says that if the key starts with '<', replace it with . --- plugin/NERD_tree.vim | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 2050785..c1d6fe6 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -510,14 +510,18 @@ endfunction "FUNCTION: KeyMap.bind() {{{3 function! s:KeyMap.bind() - let mapkey = self.key - if mapkey =~? '^\([CM]-\|middlerelease\|2-leftmouse\|leftrelease\)' - let mapkey = '<' . mapkey . '>' + " If the key we're trying to map is a special key we must escape the + " leading '<', otherwise vim will replace it with the actual keycode + " :he <> + if self.key =~# '^<' + let keymapInvokeString = substitute(self.key, '^<', '', '') + else + let keymapInvokeString = self.key endif - let premap = self.key == "leftrelease" ? " " : " " + let premap = self.key == "" ? " " : " " - exec 'nnoremap '. mapkey . premap . ':call KeyMap_Invoke("'. self.key .'")' + exec 'nnoremap '. self.key . premap . ':call KeyMap_Invoke("'. keymapInvokeString .'")' endfunction "FUNCTION: KeyMap.Remove(key, scope) {{{3 @@ -2858,12 +2862,12 @@ endfunction function! s:createDefaultBindings() let s = '' . s:SID() . '_' - call NERDTreeAddKeyMap({ 'key': 'middlerelease', 'scope': "all", 'callback': s."handleMiddleMouse" }) - call NERDTreeAddKeyMap({ 'key': 'leftrelease', 'scope': "all", 'callback': s."handleLeftClick" }) - call NERDTreeAddKeyMap({ 'key': '2-leftmouse', 'scope': "DirNode", 'callback': s."activateDirNode" }) - call NERDTreeAddKeyMap({ 'key': '2-leftmouse', 'scope': "FileNode", 'callback': s."activateFileNode" }) - call NERDTreeAddKeyMap({ 'key': '2-leftmouse', 'scope': "Bookmark", 'callback': s."activateBookmark" }) - call NERDTreeAddKeyMap({ 'key': '2-leftmouse', 'scope': "all", 'callback': s."activateAll" }) + call NERDTreeAddKeyMap({ 'key': '', 'scope': "all", 'callback': s."handleMiddleMouse" }) + call NERDTreeAddKeyMap({ 'key': '', 'scope': "all", 'callback': s."handleLeftClick" }) + call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "DirNode", 'callback': s."activateDirNode" }) + call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."activateFileNode" }) + call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "Bookmark", 'callback': s."activateBookmark" }) + call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "all", 'callback': s."activateAll" }) call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "DirNode", 'callback': s."activateDirNode" })