2011-12-22 11:55:18 -08:00
|
|
|
" Use Q to intelligently close a window
|
|
|
|
" (if there are multiple windows into the same buffer)
|
|
|
|
" or kill the buffer entirely if it's the last window looking into that buffer
|
|
|
|
function! CloseWindowOrKillBuffer()
|
2012-01-25 12:09:40 -08:00
|
|
|
let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')"))
|
|
|
|
|
2012-06-11 10:48:47 -05:00
|
|
|
" We should never bdelete a nerd tree
|
|
|
|
if matchstr(expand("%"), 'NERD') == 'NERD'
|
|
|
|
wincmd c
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-01-25 12:09:40 -08:00
|
|
|
if number_of_windows_to_this_buffer > 1
|
2011-12-22 11:55:18 -08:00
|
|
|
wincmd c
|
|
|
|
else
|
|
|
|
bdelete
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
nnoremap <silent> Q :call CloseWindowOrKillBuffer()<CR>
|