Skip to content

Instantly share code, notes, and snippets.

@nelstrom
Created June 9, 2010 15:45
Show Gist options
  • Save nelstrom/431677 to your computer and use it in GitHub Desktop.
Save nelstrom/431677 to your computer and use it in GitHub Desktop.
" Delete all inactive buffers by running:
" :call CloseHiddenBuffers()
" or the
" :Only
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's loaded and not visible
for b in range(1, bufnr('$'))
if bufloaded(b) && !has_key(visible, b)
exe 'bd ' . b
endif
endfor
endfun
" http://stackoverflow.com/questions/1534835/how-do-i-close-all-buffers-that-arent-shown-in-a-window-in-vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment