Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created December 31, 2013 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OscarGodson/8201636 to your computer and use it in GitHub Desktop.
Save OscarGodson/8201636 to your computer and use it in GitHub Desktop.
Window swapping in vim

To use (assuming your mapleader is set to ) you would:

  1. Move to the window to mark for the swap via ctrl-w movement
  2. Type \mw
  3. Move to the window you want to swap
  4. Type \pw
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment