Created
November 11, 2011 18:28
-
-
Save AndrewRadev/1358783 to your computer and use it in GitHub Desktop.
When :edit-ing in NERDTree, open the file in the closest buffer instead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Whenever you execute an `:edit somefile` command with the cursor in the | |
" NERDTree, the file gets edited in the NERDTree buffer, which is usually not | |
" something you want. This autocommand attempts to edit the given file in the | |
" closest non-NERDTree buffer instead. | |
" | |
" It's fairly hacky, but seems to work. I'll probably use it myself, so I'll | |
" try to remember to update it if I find any problems. | |
augroup AvoidEditingNERDTree | |
autocmd! | |
autocmd BufReadPost * silent call s:BufReadPost() | |
augroup END | |
function! s:BufReadPost() | |
let old_buffer = expand('#') | |
let new_buffer = expand('%') | |
if old_buffer =~ 'NERD_tree_\d\+' && len(tabpagebuflist()) > 1 | |
" go to the next window | |
wincmd w | |
" edit the given buffer there | |
exe 'edit '.new_buffer | |
" go back to the buffer that was the NERDTree | |
wincmd W | |
" close what's there now | |
quit | |
" open up the NERDTree again | |
NERDTreeToggle | |
" go back to the newly edited buffer | |
wincmd w | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment