Permalink
Browse files

Added command `:Only` which closes hidden buffers.

  • Loading branch information...
1 parent 9699b3d commit abe4af4135b41d6e9c18872ccbd09a6dd413fb9f @nelstrom committed Jul 5, 2010
Showing with 23 additions and 0 deletions.
  1. +23 −0 vimrc
View
23 vimrc
@@ -192,6 +192,29 @@ function! <SID>SynStack()
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
+" Wipe all buffers which are not active (i.e. not visible in a window/tab) {{{2
+" http://stackoverflow.com/questions/2974192/how-can-i-pare-down-vims-buffer-list-to-only-include-active-buffers
+" http://stackoverflow.com/questions/1534835/how-do-i-close-all-buffers-that-arent-shown-in-a-window-in-vim
+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
+
" Set tabstop, softtabstop and shiftwidth to the same value {{{2
" From http://vimcasts.org/episodes/tabs-and-spaces/
command! -nargs=* Stab call Stab()

0 comments on commit abe4af4

Please sign in to comment.