Created
February 11, 2011 07:52
-
-
Save nelstrom/822055 to your computer and use it in GitHub Desktop.
A command to close all Vim buffers that are not currently visible.
This file contains hidden or 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
command! -nargs=* Only call CloseHiddenBuffers() | |
function! CloseHiddenBuffers() | |
" figure out which buffers are visible in any tab | |
let visible = {} | |
for t in range(1, tabpagenr('$')) | |
for b in tabpagebuflist(t) | |
let visible[b] = 1 | |
endfor | |
endfor | |
" close any buffer that are loaded and not visible | |
let l:tally = 0 | |
for b in range(1, bufnr('$')) | |
if bufloaded(b) && !has_key(visible, b) | |
let l:tally += 1 | |
exe 'bw ' . b | |
endif | |
endfor | |
echon "Deleted " . l:tally . " buffers" | |
endfun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment