Skip to content

Instantly share code, notes, and snippets.

@rickarubio
Created March 27, 2015 02:48
Show Gist options
  • Save rickarubio/50bd1c6ca20649c379e4 to your computer and use it in GitHub Desktop.
Save rickarubio/50bd1c6ca20649c379e4 to your computer and use it in GitHub Desktop.
nerdtree customization taken from janus
let NERDTreeIgnore=['\.pyc$', '\.pyo$', '\.rbc$', '\.rbo$', '\.class$', '\.o$', '\~$']
" Default mapping, <leader>n
call janus#add_mapping('nerdtree', 'map', '<leader>n', ':NERDTreeToggle<CR> :NERDTreeMirror<CR>')
augroup AuNERDTreeCmd
autocmd AuNERDTreeCmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
autocmd AuNERDTreeCmd FocusGained * call s:UpdateNERDTree()
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
let explicitDirectory = isdirectory(a:directory)
let directory = explicitDirectory || empty(a:directory)
if explicitDirectory
exe "cd " . fnameescape(a:directory)
endif
" Allows reading from stdin
" ex: git diff | mvim -R -
if strlen(a:directory) == 0
return
endif
if directory
NERDTree
wincmd p
bd
endif
if explicitDirectory
wincmd p
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(...)
let stay = 0
if(exists("a:1"))
let stay = a:1
end
if exists("t:NERDTreeBufName")
let nr = bufwinnr(t:NERDTreeBufName)
if nr != -1
exe nr . "wincmd w"
exe substitute(mapcheck("R"), "<CR>", "", "")
if !stay
wincmd p
end
endif
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment