Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created May 5, 2014 15:07
Show Gist options
  • Save ashwin/3c6a40b2d1245f1c5b96 to your computer and use it in GitHub Desktop.
Save ashwin/3c6a40b2d1245f1c5b96 to your computer and use it in GitHub Desktop.
Highlight current file in NERDTree
" Check if NERDTree is open or active
function! rc:isNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! rc:syncTree()
if &modifiable && rc:isNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call rc:syncTree()
@yasserhussain1110
Copy link

This doesn't work.
I tried to use this https://stackoverflow.com/questions/7692233/nerdtree-reveal-file-in-tree but got b:NERDTree is undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment