In order to swap
window positions, the effect is equivalent to swapping buffers that those two windows show.
e.g. If window A has buffer 2 and window B has buffer 8, you'll want to go to Window A, select buffer 8, then to Window B, select buffer 2.
This idea inspired me to script it - and it's already in my own toolbox as well
let thiswin = winnr()
let thisbuf = bufnr("%")
let lastwin = winnr("#")
let lastbuf = winbufnr(lastwin)
exec lastwin . " wincmd w" ."|".
\ "buffer ". thisbuf ."|".
\ thiswin ." wincmd w" ."|".
\ "buffer ". lastbuf
command! Wswap :call WinBufSwap()
map <Leader>bs <C-c>:call WinBufSwap()<CR>
- Select window A
- Select window B
This swaps the buffers in the two pre-selected windows, leaving the cursor in the original window.
Selecting the two desired windows to be swapped ahead of time is the key detail, as that is needed to specify for Vim which ones to work with.