diff --git a/vim/.config/vim/plug.d/nerdtree.vim b/vim/.config/vim/plug.d/nerdtree.vim index f767c6a..afc0339 100644 --- a/vim/.config/vim/plug.d/nerdtree.vim +++ b/vim/.config/vim/plug.d/nerdtree.vim @@ -1,20 +1,31 @@ -Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle', 'tag': '6.9.8' } - -" Close all open buffers on entering a window if the only -" buffer that's left is the NERDTree buffer -function! s:CloseIfOnlyNerdTreeLeft() - if exists("t:NERDTreeBufName") && - \ bufwinnr(t:NERDTreeBufName) != -1 && - \ winnr("$") == 1 - quit - endif -endfunction +Plug 'preservim/nerdtree', { 'tag': '6.9.11' } let g:NERDTreeDirArrowExpandable = '▸' let g:NERDTreeDirArrowCollapsible = '▾' let NERDTreeDirArrows=1 -let NERDTreeIgnore = ['\.pyc$', '\.swp$'] +let NERDTreeIgnore = ['\.swp$'] map nt :NERDTreeToggle -autocmd WinEnter * call s:CloseIfOnlyNerdTreeLeft() + +" Close nerdtree if it's the last buffer +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() +\ | quit +\ | endif + +" Mirror nerdtree in each tab +autocmd BufWinEnter * silent NERDTreeMirror + +" check if reading from stdin +autocmd StdinReadPre * let s:std_in=1 + +" open nerdtree if no args in passed to vim +autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | wincmd p | endif + +" open nerdtree if vim opens to a directory +autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') +\ | execute 'NERDTree' argv()[0] +\ | wincmd p +\ | enew +\ | execute 'cd '.argv()[0] +\ | endif