Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ let g:NERDTreeHighlightCursorline = 1
```
That will run `setlocal cursorline` in the NERDTree window


## Excluding Buffers

You can exclude buffers from being highlighted in NERDTree.

Exclude "FooBar" buffers and any buffer ending in ".log" - separate multiple patterns with `\|`
```
let g:nerdtree_sync_excluded_patterns = 'FooBar\|.log$'
```
Or to exclude only "FooBar":
```
let g:nerdtree_sync_excluded_patterns = 'FooBar'
```
Or to exclude multiple specific file paths:

```
let g:nerdtree_sync_excluded_patterns = '/path/to/exclude/file1.txt\|/another/file.log'
```

## Credits

* [Lambart](https://superuser.com/users/158390/lambart) from superuser for his [answer](https://superuser.com/questions/195022/vim-how-to-synchronize-nerdtree-with-current-opened-tab-file-path/474298#474298)
Expand Down
8 changes: 6 additions & 2 deletions plugin/vim-nerdtree-sync.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ let g:loaded_nerdtree_sync = 4 " plugin version
let s:keepcpo = &cpo
set cpo&vim

if !exists('g:nerdtree_sync_excluded_patterns')
let g:nerdtree_sync_excluded_patterns = ''
endif

function! s:isNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction

" calls NERDTreeFind iff NERDTree is active, current window contains a modifiable file, and we're not in vimdiff
" calls NERDTreeFind if NERDTree is active, current window contains a modifiable file, and we're not in vimdiff or an excluded buffer
function! s:syncTree()
if exists("g:nerdtree_sync_cursorline") && g:nerdtree_sync_cursorline == 1
if &modifiable && s:isNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff && bufname('%') !~# 'NERD_tree'
if &modifiable && s:isNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff && bufname('%') !~# 'NERD_tree' && (g:nerdtree_sync_excluded_patterns == '' || bufname('%') !~# g:nerdtree_sync_excluded_patterns)
try
NERDTreeFind
if bufname('%') =~# 'NERD_tree'
Expand Down