diff --git a/README.md b/README.md index ad7b5f9..235b165 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/plugin/vim-nerdtree-sync.vim b/plugin/vim-nerdtree-sync.vim index 1c34a99..62a6009 100644 --- a/plugin/vim-nerdtree-sync.vim +++ b/plugin/vim-nerdtree-sync.vim @@ -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'