Created
April 12, 2011 22:28
-
-
Save orther/916584 to your computer and use it in GitHub Desktop.
vim script that allows you to easily swap window buffers between windows(splits)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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