Permalink
Browse files

Version 1.0: Initial upload

  • Loading branch information...
0 parents commit 2d9f25a2af78e4de77d9537fa31987420947c3b0 @Soares Soares committed with Sep 30, 2012
Showing with 108 additions and 0 deletions.
  1. +3 −0 README
  2. +20 −0 README.md
  3. +21 −0 doc/butane.txt
  4. +5 −0 doc/tags
  5. +59 −0 plugin/butane.vim
3 README
@@ -0,0 +1,3 @@
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=4245
+
+Adds the :Bclose command, which closes a buffer without re-arranging the windows.
@@ -0,0 +1,20 @@
+# Butane: Vim Buffer Utilities
+## Light your buffers up.
+
+Currently Butane provides only one simple command, the Bclose command, which
+closes a buffer without changing the layout of your windows. (The most recently
+used buffer, or failing that the previous buffer, or finally an empty file will
+be placed in its place.)
+
+If you want to give your buffers a bit of an extra spark I recommend the
+following maps in your .vimrc or equivalent:
+
+ noremap <leader>bd :Bclose<CR> " Close the buffer.
+ noremap <leader>bD :Bclose!<CR> " Close the buffer & discard changes.
+ noremap <leader>bn :bn<CR> " Next buffer.
+ noremap <leader>bp :bp<CR> " Previous buffer.
+ noremap <leader>bl :ls<CR> " List buffers.
+ noremap <leader>bt :b#<CR> " Toggle to most recently used buffer.
+
+Most of these commands are simple, but with a good leader key they are
+much easier to hit than their built-in counterparts.
@@ -0,0 +1,21 @@
+*butane.txt* Buffer Utilities
+
+Author: Nate Soares <http://so8r.es/>
+License: Same terms as Vim itself (see |license|)
+
+INTRODUCTION *butane*
+
+Vim buffer utilities. Light your buffers up.
+
+COMMANDS *butane-commands*
+
+ *butane-:Bclose*
+:Bclose[!] |:bdelete| without changing the window layout.
+
+ABOUT *butane-about*
+
+Grab the latest version or report a bug on GitHub:
+
+http://github.com/Soares/butane.vim
+
+ vim:tw=78:ts=8:noet:ft=help:norl:
@@ -0,0 +1,5 @@
+butane butane.txt /*butane*
+butane-:Bclose butane.txt /*butane-:Bclose*
+butane-about butane.txt /*butane-about*
+butane-commands butane.txt /*butane-commands*
+butane.txt butane.txt /*butane.txt*
@@ -0,0 +1,59 @@
+" butane.vim: Light your buffers up.
+"
+" Author: Vim Tip #165 <http://vim.wikia.com/wiki/VimTip165>
+" Maintainer: Nate Soares <http://so8r.es>
+" Version: 1.0
+" License: The same as vim itself. (See |license|)
+
+if exists("g:loaded_butane") || &cp || v:version < 700
+ finish
+endif
+let g:loaded_butane = 1
+
+function! s:Bclose(bang, buffer)
+ if empty(a:buffer)
+ let btarget = bufnr('%')
+ elseif a:buffer =~ '^\d\+$'
+ let btarget = bufnr(str2nr(a:buffer))
+ else
+ let btarget = bufnr(a:buffer)
+ endif
+ if btarget < 0
+ echoerr 'No matching buffer for '.a:buffer
+ return
+ endif
+ if empty(a:bang) && getbufvar(btarget, '&modified')
+ echoerr 'No write since last change. Use :Bclose!'
+ return
+ endif
+ " Numbers of windows that view target buffer which we will delete.
+ let wnums = filter(range(1, winnr('$')), 'winbufnr(v:val) == btarget')
+ let wcurrent = winnr()
+ for w in wnums
+ execute w.'wincmd w'
+ let prevbuf = bufnr('#')
+ if prevbuf > 0 && buflisted(prevbuf) && prevbuf != w
+ buffer #
+ else
+ bprevious
+ endif
+ if btarget == bufnr('%')
+ " Numbers of listed buffers which are not the target to be deleted.
+ let blisted = filter(range(1, bufnr('$')),
+ \ 'buflisted(v:val) && v:val != btarget')
+ " Listed, not target, and not displayed.
+ let bhidden = filter(copy(blisted), 'bufwinnr(v:val) < 0')
+ " Take the first buffer, if any (could be more intelligent).
+ let bjump = (bhidden + blisted + [-1])[0]
+ if bjump > 0
+ execute 'buffer '.bjump
+ else
+ execute 'enew'.a:bang
+ endif
+ endif
+ endfor
+ execute 'bdelete'.a:bang.' '.btarget
+ execute wcurrent.'wincmd w'
+endfunction
+command! -bang -complete=buffer -nargs=?
+ \ Bclose call s:Bclose('<bang>', '<args>')

0 comments on commit 2d9f25a

Please sign in to comment.