Created
May 13, 2010 10:37
-
-
Save tyru/399708 to your computer and use it in GitHub Desktop.
Move current window position.
This file contains 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
" Move window position: <C-w>r, <C-w>R, <C-w>x suck! {{{ | |
nmap <Space><C-n> <SID>swap_window_next | |
nmap <Space><C-p> <SID>swap_window_prev | |
nmap <Space><C-j> <SID>swap_window_j | |
nmap <Space><C-k> <SID>swap_window_k | |
nmap <Space><C-h> <SID>swap_window_h | |
nmap <Space><C-l> <SID>swap_window_l | |
" nmap <Space><C-t> <SID>swap_window_t | |
" nmap <Space><C-b> <SID>swap_window_b | |
nnoremap <silent> <SID>swap_window_next :<C-u>call <SID>swap_window_count(v:count1)<CR> | |
nnoremap <silent> <SID>swap_window_prev :<C-u>call <SID>swap_window_count(-v:count1)<CR> | |
nnoremap <silent> <SID>swap_window_j :<C-u>call <SID>swap_window_dir(v:count1, 'j')<CR> | |
nnoremap <silent> <SID>swap_window_k :<C-u>call <SID>swap_window_dir(v:count1, 'k')<CR> | |
nnoremap <silent> <SID>swap_window_h :<C-u>call <SID>swap_window_dir(v:count1, 'h')<CR> | |
nnoremap <silent> <SID>swap_window_l :<C-u>call <SID>swap_window_dir(v:count1, 'l')<CR> | |
nnoremap <silent> <SID>swap_window_t :<C-u>call <SID>swap_window_dir(v:count1, 't')<CR> | |
nnoremap <silent> <SID>swap_window_b :<C-u>call <SID>swap_window_dir(v:count1, 'b')<CR> | |
function! s:modulo(n, m) "{{{ | |
let d = a:n * a:m < 0 ? 1 : 0 | |
return a:n + (-(a:n + (0 < a:m ? d : -d)) / a:m + d) * a:m | |
endfunction "}}} | |
function! s:swap_window_count(n) "{{{ | |
let curwin = winnr() | |
let target = s:modulo(curwin + a:n - 1, winnr('$')) + 1 | |
call s:swap_window(curwin, target) | |
endfunction "}}} | |
function! s:swap_window_dir(n, dir) "{{{ | |
let curwin = winnr() | |
execute a:n 'wincmd' a:dir | |
let targetwin = winnr() | |
wincmd p | |
call s:swap_window(curwin, targetwin) | |
endfunction "}}} | |
function! s:swap_window(curwin, targetwin) "{{{ | |
let curbuf = winbufnr(a:curwin) | |
let targetbuf = winbufnr(a:targetwin) | |
if curbuf == targetbuf | |
" TODO: Swap also same buffer! | |
else | |
execute 'hide' targetbuf . 'buffer' | |
execute a:targetwin 'wincmd w' | |
execute curbuf 'buffer' | |
endif | |
endfunction "}}} | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment