Skip to content

Instantly share code, notes, and snippets.

@flipjs
Last active August 29, 2015 14:05
Show Gist options
  • Save flipjs/f1f51d7d019c955fd87b to your computer and use it in GitHub Desktop.
Save flipjs/f1f51d7d019c955fd87b to your computer and use it in GitHub Desktop.
VIM: Swap files between split windows
function! MarkWindowSwap()
let g:markedWinNum = winnr()
endfunction
function! DoWindowSwap()
"Mark destination
let curNum = winnr()
let curBuf = bufnr( "%" )
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
endfunction
nmap <silent> <leader>mw :call MarkWindowSwap()<CR>
nmap <silent> <leader>pw :call DoWindowSwap()<CR>
" - sgriffin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment