From 03ecd19878999cec293319963b5724379ca9cf98 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 9 Apr 2023 08:08:09 -0300 Subject: Feat: adds the wipeout plugin --- vim.dot.link/plugin/wipeout.vim | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 vim.dot.link/plugin/wipeout.vim diff --git a/vim.dot.link/plugin/wipeout.vim b/vim.dot.link/plugin/wipeout.vim new file mode 100644 index 0000000..731b3f0 --- /dev/null +++ b/vim.dot.link/plugin/wipeout.vim @@ -0,0 +1,32 @@ +" wipeout.vim - Destroy all buffers that are not open in any tabs or windows. +" https://www.vim.org/scripts/script.php?script_id=4882 +" +" Adapted from the following StackOverflow answer: +" http://stackoverflow.com/questions/1534835 +" +" Author: Artem Nezvigin + +command! -bang Wipeout :call Wipeout(0) + +function! Wipeout(bang) + " 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 + let l:cmd = 'bw' + if a:bang + let l:cmd .= '!' + endif + for b in range(1, bufnr('$')) + if buflisted(b) && !has_key(visible, b) + let l:tally += 1 + exe l:cmd . ' ' . b + endif + endfor + echon "Deleted " . l:tally . " buffers" +endfun -- cgit v1.2.3