Skip to content

Instantly share code, notes, and snippets.

@orther
Created April 5, 2011 23:13
Show Gist options
  • Save orther/904781 to your computer and use it in GitHub Desktop.
Save orther/904781 to your computer and use it in GitHub Desktop.
Vim script to allow you to swap window buffers easily
" Swap window buffers.
function! SwapWindowBuffers()
if !exists("g:markedWinNum")
" set window marked for swap
let g:markedWinNum = winnr()
:echo "window marked for swap"
else
" mark destination
let curNum = winnr()
let curBuf = bufnr( "%" )
if g:markedWinNum == curNum
:echo "window unmarked for swap"
else
exe g:markedWinNum . "wincmd w"
" switch to source and shuffle dest->source
let markedBuf = bufnr( "%" )
" hide and open so that we aren't prompted and keep history
exe 'hide buf' curBuf
" switch to dest and shuffle source->dest
exe curNum . "wincmd w"
" hide and open so that we aren't prompted and keep history
exe 'hide buf' markedBuf
:echo "windows swapped"
endif
" unset window marked for swap
unlet g:markedWinNum
endif
endfunction
noremap <leader><C-s> :call SwapWindowBuffers()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment