Skip to content

Instantly share code, notes, and snippets.

@scrooloose
Created December 28, 2011 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scrooloose/1527501 to your computer and use it in GitHub Desktop.
Save scrooloose/1527501 to your computer and use it in GitHub Desktop.
Couple of custom key maps for nerdtree
if exists("g:loaded_nerdtree_custom_maps")
finish
endif
let g:loaded_nerdtree_custom_maps = 1
"adds a keymapping on 'o' that overrides the standard nerdtree 'o' mapping and
"to open the file node and close the tree
call NERDTreeAddKeyMap({
\ 'key': 'o',
\ 'callback': "NERDTreeCustomMapsOpenAndClose",
\ 'quickhelpText': 'open current file and close tree' })
function! NERDTreeCustomMapsOpenAndClose()
let n = g:NERDTreeFileNode.GetSelected()
if n != {}
if !n.path.isDirectory
call n.open()
NERDTreeClose
else
" if the node is a dir then just activate it as norm
call n.activate(0)
endif
endif
endfunction
"adds a new keymapping on 'gT' that opens the selected file in a bg tab and
"closes the tree
call NERDTreeAddKeyMap({
\ 'key': 'gT',
\ 'callback': "NERDTreeCustomMapsOpenInNewTabAndClose",
\ 'quickhelpText': 'open in bg tab and close tree' })
function! NERDTreeCustomMapsOpenInNewTabAndClose()
let n = g:NERDTreeFileNode.GetSelected()
if n != {}
call n.openInNewTab({'stayInCurrentTab': 1})
NERDTreeClose
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment