Skip to content

Instantly share code, notes, and snippets.

@c9s
Created October 21, 2009 02:49
Show Gist options
  • Save c9s/214801 to your computer and use it in GitHub Desktop.
Save c9s/214801 to your computer and use it in GitHub Desktop.
window ctrl for gvim
" Window Ctrl Config"{{{
let g:window_ctrl_h_inc = 13 " columns
let g:window_ctrl_v_inc = 3 " lines
let g:window_ctrl_x_inc = 400
let g:window_ctrl_y_inc = 300
"}}}
" Window Ctrl"{{{
"
function! WHLeft()
execute printf('winsize %d %d', g:screen_cols / 2 , g:screen_rows )
execute printf('winpos %d %d', g:zero_x , g:zero_y )
endfunction
function! WHRight()
execute printf('winsize %d %d', g:screen_cols / 2 , g:screen_rows )
execute printf('winpos %d %d', g:screen_w / 2 , g:zero_y )
endfunction
function! WFull()
execute printf('winsize %d %d', g:screen_cols , g:screen_rows )
execute printf('winpos %d %d', g:zero_x , g:zero_y )
endfunction
fun! AdjustHeight(op)
let cur_lines = &lines
exec 'let cur_lines ' a:op . '=' . g:window_ctrl_v_inc
exec 'set lines=' . cur_lines
endf
fun! AdjustWidth(op)
let cur_columns = &columns
exec 'let cur_columns ' a:op . '=' . g:window_ctrl_h_inc
exec 'set columns=' . cur_columns
endf
fun! AdjustX(op)
let x = getwinposx()
let y = getwinposy()
exec 'let x ' . a:op . '=' . g:window_ctrl_x_inc
exec 'winpos ' . x . ' ' . y
endf
fun! AdjustY(op)
let x = getwinposx()
let y = getwinposy()
exec 'let y ' . a:op . '=' . g:window_ctrl_y_inc
exec 'winpos ' . x . ' ' . y
endf
fun! WindowSnapToGrid()
let x = getwinposx()
let y = getwinposy()
if x <= g:screen_w / 2
let x = 0 + g:zero_x
else
let x = g:screen_w / 2
endif
if y <= g:screen_h / 2
let y = 0 + g:zero_y
else
let y = g:screen_h / 2
endif
exec 'winpos ' . x . ' ' . y
endf
com! WindowSnapToGrid :call WindowSnapToGrid()
com! IncHeight :call AdjustHeight('+')
com! DecHeight :call AdjustHeight('-')
com! IncWidth :call AdjustWidth('+')
com! DecWidth :call AdjustWidth('-')
fun! EnableWindowCtrl()
nnoremap <buffer> <silent> <Up> :DecHeight<CR>
nnoremap <buffer> <silent> <Down> :IncHeight<CR>
nnoremap <buffer> <silent> <Left> :DecWidth<CR>
nnoremap <buffer> <silent> <Right> :IncWidth<CR>
nnoremap <buffer> <silent> j :call AdjustY('+')<CR>
nnoremap <buffer> <silent> k :call AdjustY('-')<CR>
nnoremap <buffer> <silent> l :call AdjustX('+')<CR>
nnoremap <buffer> <silent> h :call AdjustX('-')<CR>
nnoremap <buffer> <silent> gg :WindowSnapToGrid<CR>
"nnoremap <buffer> <silent> gh :exec printf('winpos %d %d' , 0 , g:zero_y )<CR>
"nnoremap <buffer> <silent> gl :exec printf('winpos %d %d' , g:screen_w / 2 , g:zero_y )<CR>
nnoremap <buffer> <silent> gh :call WHLeft()<CR>
nnoremap <buffer> <silent> gl :call WHRight()<CR>
endf
fun! DisableWindowCtrl()
nunmap <buffer> <silent> <Up>
nunmap <buffer> <silent> <Down>
nunmap <buffer> <silent> <Left>
nunmap <buffer> <silent> <Right>
nunmap <buffer> <silent> gg
nunmap <buffer> <silent> gh
nunmap <buffer> <silent> gl
nunmap <buffer> <silent> j
nunmap <buffer> <silent> k
nunmap <buffer> <silent> h
nunmap <buffer> <silent> l
endf
let g:window_ctrl = 0
fun! ToggleWindowCtrl()
if g:window_ctrl
echo 'Window Ctrl: off'
call DisableWindowCtrl()
let g:window_ctrl = 0
redraw
else
echo 'Window Ctrl: on'
call EnableWindowCtrl()
let g:window_ctrl = 1
redraw
endif
endf
nnoremap <silent> <leader>ww :call ToggleWindowCtrl()<CR>
"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment