Snippets

Sergio Luiz Araújo Silva Close all buffers but current one

Updated by Sergio Araújo

File deleteallbuffers.vim Modified

  • Ignore whitespace
  • Hide word diff
 " the main reference: https://salferrarello.com/vim-close-all-buffers-except-the-current-one/
+" https://bitbucket.org/snippets/sergio/9nbyGy/close-all-buffers-but-current-one
 
 " needed function preserve to avoid `"
 " this function can be used for many other things like reload vimrc withou moving the cursor
Updated by Sergio Araújo

File deleteallbuffers.vim Modified

  • Ignore whitespace
  • Hide word diff
+" the main reference: https://salferrarello.com/vim-close-all-buffers-except-the-current-one/
+
 " needed function preserve to avoid `"
 " this function can be used for many other things like reload vimrc withou moving the cursor
 " or reindent the current buffer keeping the cursor position
Created by Sergio Araújo

File deleteallbuffers.vim Added

  • Ignore whitespace
  • Hide word diff
+" needed function preserve to avoid `"
+" this function can be used for many other things like reload vimrc withou moving the cursor
+" or reindent the current buffer keeping the cursor position
+" preserve function
+
+" Utility function that save last search and cursor position
+" http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
+" video from vimcasts.org: http://vimcasts.org/episodes/tidying-whitespace
+" using 'execute' command doesn't overwrite the last search pattern, so I
+" don't need to store and restore it.
+
+if !exists('*Preserve')
+    function! Preserve(command)
+        try
+            let l:win_view = winsaveview()
+            "silent! keepjumps keeppatterns execute a:command
+            silent! execute 'keeppatterns keepjumps ' . a:command
+        finally
+            call winrestview(l:win_view)
+        endtry
+    endfunction
+endif
+
+command! BufOnly silent! call Preserve("exec '%bd|e#|bd#'")
+cab bo BufOnly
+
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.