Skip to content

Instantly share code, notes, and snippets.

@thinca
Forked from tyru/.vimrc
Created May 16, 2010 00:20
Show Gist options
  • Save thinca/402529 to your computer and use it in GitHub Desktop.
Save thinca/402529 to your computer and use it in GitHub Desktop.
" <Space><C-n>, <Space><C-p>: Move window position {{{
nnoremap <silent> <Space><C-n> :<C-u> call <SID>swap_window(v:count1)<CR>
nnoremap <silent> <Space><C-p> :<C-u> call <SID>swap_window(-v:count1)<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(n) "{{{
let curbuf = bufnr('%')
let target = s:modulo(winnr() + a:n - 1, winnr('$')) + 1
execute 'hide' winbufnr(target) . 'buffer'
execute target . 'wincmd w'
execute curbuf . 'buffer'
endfunction "}}}
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment