Skip to content

Instantly share code, notes, and snippets.

@juanxo
Created April 30, 2014 23:54
Show Gist options
  • Select an option

  • Save juanxo/1b3682b76b08d1bfed7e to your computer and use it in GitHub Desktop.

Select an option

Save juanxo/1b3682b76b08d1bfed7e to your computer and use it in GitHub Desktop.
Vim function to improve handling of closing buffers
map <leader>bd :Bclose<cr>
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment