vim-nerdtree-tabs
vim-nerdtree-tabs copied to clipboard
Cd if Directory && Refresh on focus lost
trafficstars
In my repo I've had some thing similar to your plugin.
There are only two missing things that could be useful:
- Cd if we use
vim /my/path/ - Refresh nerdtree(s) when on focus gained
The code could be some like:
" Chdir if we use vim ../my/path
augroup AuNERDTreeCmd
au VimEnter * call s:CdIfDirectory(expand("<amatch>"))
au FocusGained * call s:UpdateNERDTree()
augroup END
" 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
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
Hi, I definitely like the cd feature.
About auto-refreshing I'm not absolutely sure.
- It might be a small, but in some cases probably noticeable delay when switching focus.
- It still won't solve the case when you have NERDTree already focused, then switch to terminal, do some operation in terminal and then switch back to Vim.
I've been busy lately, but I'll definitely add the cd feature when I get to work on nerdtree-tabs again. Thanks ;)