Skip to content

Instantly share code, notes, and snippets.

@anyakichi
Created April 23, 2011 23:20
Show Gist options
  • Save anyakichi/939080 to your computer and use it in GitHub Desktop.
Save anyakichi/939080 to your computer and use it in GitHub Desktop.
Close duplicate tabs and show hidden buffers in tabs.
function! ReorganizeTabs(only)
let tablists = []
let bufs = {}
tabfirst
let tabnr = 1
while type(tabpagebuflist(tabnr)) == type([])
let tablist = tabpagebuflist(tabnr)
if a:only && len(tablist) > 1
execute "normal! 999\<C-w>k"
only
endif
if !empty(filter(copy(tablists), 'v:val == ' . string(tablist)))
tabclose
continue
endif
call add(tablists, tablist)
for i in tablist
let bufs[i] = 1
endfor
tabnext
let tabnr += 1
endwhile
tablast
for n in range(1, bufnr('$'))
if get(bufs, n, 0) || !buflisted(n)
continue
endif
tab split
execute 'buffer ' . n
endfor
tabfirst
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment