Skip to content

Instantly share code, notes, and snippets.

@kenichi
Created June 6, 2012 17:17
Show Gist options
  • Save kenichi/2883384 to your computer and use it in GitHub Desktop.
Save kenichi/2883384 to your computer and use it in GitHub Desktop.
kill buffer, keep window (vim)
" delete buffer, keep window
function Kwbd(kwbdStage)
if(a:kwbdStage == 1)
let g:kwbdBufNum = bufnr("%")
let g:kwbdWinNum = winnr()
windo call Kwbd(2)
execute "bd! " . g:kwbdBufNum
execute "normal " . g:kwbdWinNum . ""
else
if(bufnr("%") == g:kwbdBufNum)
let prevbufvar = bufnr("#")
if(prevbufvar > 0 && buflisted(prevbufvar) && prevbufvar != g:kwbdBufNum)
b #
else
bn
endif
endif
endif
endfunction
map <C-w><C-k> :call Kwbd(1)<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment