├── LICENSE ├── README.md └── nerdtree_plugin ├── bwipeout.vim └── highlight_open_buffers.vim /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Phil Runninger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nerdtree-buffer-ops 2 | This is a NERDTree plugin that highlights all visible nodes that are open in Vim. 3 | 4 | It also maps a key `w` to close (wipeout) the buffer associated with the current node. 5 | 6 | --- 7 | 8 | **NOTE: This plugin is incompatible with** [nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin.git) **and** [vim-devicons](https://github.com/ryanoasis/vim-devicons.git)**.** This plugin causes flags to be completely concealed, while the aforementioned plugins rely on the flags being visible. Don't ask for this to be changed. 9 | -------------------------------------------------------------------------------- /nerdtree_plugin/bwipeout.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " Description: plugin for NERD Tree that provides a buffer wipeout command 3 | " Notes: The logic in NERDTreeBufWipeout is a modified version of that found here: 4 | " http://vim.wikia.com/wiki/Deleting_a_buffer_without_closing_the_window 5 | " ============================================================================ 6 | if exists("s:loaded") 7 | finish 8 | endif 9 | let s:loaded = 1 10 | 11 | call NERDTreeAddKeyMap({ 12 | \ 'key': 'w', 13 | \ 'callback': 'NERDTreeBufWipeout', 14 | \ 'quickhelpText': 'Wipeout file''s buffer', 15 | \ 'override': 0, 16 | \ 'scope': 'FileNode'}) 17 | 18 | function! NERDTreeBufWipeout(fileNode) 19 | let bufferNumber = bufnr(a:fileNode.path.str()) 20 | if bufferNumber < 0 || !buflisted(bufferNumber) 21 | call nerdtree#echo(fnamemodify(a:fileNode.path.str(),":t"). " is not open in any buffer.") 22 | return 23 | endif 24 | 25 | " Numbers of windows that view target buffer which we will wipeout. 26 | let wnums = filter(range(1, winnr('$')), 'winbufnr(v:val) == bufferNumber') 27 | let wcurrent = winnr() 28 | 29 | " For each window the buffer is in, switch buffers. 30 | for w in wnums 31 | execute w.'wincmd w' 32 | let prevbuf = bufnr('#') 33 | if prevbuf > 0 && buflisted(prevbuf) 34 | buffer # 35 | else 36 | let availableBuffers = filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != bufferNumber && bufwinnr(v:val) < 0') 37 | let bjump = (availableBuffers + [-1])[0] 38 | if bjump > 0 39 | execute 'buffer '.bjump 40 | else 41 | execute 'enew!' 42 | endif 43 | endif 44 | endfor 45 | 46 | execute 'confirm bwipeout'.' '.bufferNumber 47 | execute wcurrent.'wincmd w' 48 | call nerdtree#echo("Buffer ". bufferNumber ." [". fnamemodify(a:fileNode.path.str(),":t") ."] was wiped out.") 49 | endfunction 50 | -------------------------------------------------------------------------------- /nerdtree_plugin/highlight_open_buffers.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " Description: Plugin for NERD Tree that highlights open files 3 | " Inspiration: https://github.com/Xuyuanp/nerdtree-git-plugin 4 | " ============================================================================ 5 | " Stop processing if already loaded. 6 | if exists('s:loaded') 7 | finish 8 | endif 9 | let s:loaded = 1 10 | 11 | " Setup NERDTree listener callback. 12 | call g:NERDTreePathNotifier.AddListener('init', 'NERDTreeHighlightOpenBuffers') 13 | call g:NERDTreePathNotifier.AddListener('refresh', 'NERDTreeHighlightOpenBuffers') 14 | call g:NERDTreePathNotifier.AddListener('refreshFlags', 'NERDTreeHighlightOpenBuffers') 15 | 16 | function! NERDTreeHighlightOpenBuffers(event) 17 | let l:path = a:event.subject 18 | let l:flag = buflisted(expand(l:path.str())) ? s:open_buffer_glyph : "" 19 | call l:path.flagSet.clearFlags('highlight_open') 20 | if l:flag !=# '' 21 | call l:path.flagSet.addFlag('highlight_open', l:flag) 22 | endif 23 | endfunction 24 | 25 | " Autocmds to trigger NERDTree flag refreshes 26 | augroup NERDTreeHighlightOpenBuffersPlugin 27 | autocmd CursorHold,BufEnter * silent! call s:RefreshFlags() 28 | autocmd BufWritePost,BufReadPost * silent! s:RefreshFlags() 29 | augroup END 30 | function! s:RefreshFlags() 31 | if g:NERDTree.IsOpen() && !exists('s:stop_recursion') 32 | let s:stop_recursion = 1 33 | let l:winnr = winnr() 34 | let l:altwinnr = winnr('#') 35 | 36 | call g:NERDTree.CursorToTreeWin() 37 | call b:NERDTree.root.refreshFlags() 38 | call NERDTreeRender() 39 | 40 | execute l:altwinnr . 'wincmd w' 41 | execute l:winnr . 'wincmd w' 42 | endif 43 | unlet! s:stop_recursion 44 | endfunction 45 | 46 | " Setup the syntax highlighting 47 | " The open_buffer_glyph is used just to find the line in NERDTree for syntax 48 | " highlighting. The line containing the glyph is highlighted (Special), and 49 | " then the flag itself is concealed. 50 | let s:open_buffer_glyph='○' 51 | augroup AddHighlighting 52 | autocmd FileType nerdtree call s:AddHighlighting() 53 | augroup END 54 | function! s:AddHighlighting() 55 | execute 'syntax match NERDTreeOpenBufferFlag #\[.\{-}' . s:open_buffer_glyph . '.\{-}\].# conceal contains=NERDTreeNodeDelimiters containedin=NERDTreeOpenBuffer' 56 | setlocal conceallevel=2 57 | setlocal concealcursor=nvic 58 | 59 | execute 'syntax match NERDTreeOpenBuffer #\[.\{-}' . s:open_buffer_glyph . '.\{-}\].\+$# containedin=NERDTreeFile,NERDTreeLinkFile,NERDTreeExecFile,NERDTreeRO' 60 | highlight default link NERDTreeOpenBuffer Constant 61 | endfunction 62 | --------------------------------------------------------------------------------