Created
December 22, 2014 16:52
-
-
Save pencilcheck/acb04db11b26c67a35fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function! VimNavigate(direction) | |
try | |
execute 'wincmd ' . a:direction | |
catch | |
echohl ErrorMsg | echo 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits: wincmd k' | echohl None | |
endtry | |
endfunction | |
let g:location_left = 0 | |
let g:location_right = 0 | |
let g:location_top = 0 | |
let g:location_bottom = 0 | |
function! DetermineLocation() | |
let nr = winnr() | |
call VimNavigate('h') | |
let g:location_left = nr == winnr() ? 1 : 0 | |
if (g:location_left == 1) | |
"echo 'left' | |
else | |
execute nr . "wincmd w" | |
endif | |
call VimNavigate('l') | |
let g:location_right = nr == winnr() ? 1 : 0 | |
if (g:location_right == 1) | |
"echo 'right' | |
else | |
execute nr . "wincmd w" | |
end | |
call VimNavigate('k') | |
let g:location_top = nr == winnr() ? 1 : 0 | |
if (g:location_top == 1) | |
"echo 'top' | |
else | |
execute nr . "wincmd w" | |
endif | |
call VimNavigate('j') | |
let g:location_bottom = nr == winnr() ? 1 : 0 | |
if (g:location_bottom == 1) | |
"echo 'bottom' | |
else | |
execute nr . "wincmd w" | |
endif | |
endfunction | |
function! MyResize(dir) | |
let cmd = '' | |
call DetermineLocation() | |
if (g:location_right == 1) | |
if ('h' == a:dir) | |
let cmd = ">" | |
endif | |
if ('l' == a:dir) | |
let cmd = "<" | |
endif | |
else | |
if ('h' == a:dir) | |
let cmd = "<" | |
endif | |
if ('l' == a:dir) | |
let cmd = ">" | |
endif | |
endif | |
if (g:location_bottom == 1) | |
if ('k' == a:dir) | |
let cmd = "+" | |
endif | |
if ('j' == a:dir) | |
let cmd = "-" | |
endif | |
else | |
if ('k' == a:dir) | |
let cmd = "-" | |
endif | |
if ('j' == a:dir) | |
let cmd = "+" | |
endif | |
endif | |
return "5\<c-v>\<c-w>" . cmd | |
endfunction | |
nnoremap ÷ :echo DetermineLocation()<CR> | |
" Alt-hjkl key bindings, but in printed character, otherwise vim cannot | |
" recognize | |
nnoremap ˚ :normal <c-r>=MyResize('k')<CR><CR> | |
nnoremap ∆ :normal <c-r>=MyResize('j')<CR><CR> | |
nnoremap ¬ :normal <c-r>=MyResize('l')<CR><CR> | |
nnoremap ˙ :normal <c-r>=MyResize('h')<CR><CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment