Created
December 22, 2014 17:53
-
-
Save pencilcheck/1da72144678b8f284720 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 | |
function! DetermineLocation() | |
let nr = winnr() | |
let locations = [] | |
call VimNavigate('h') | |
if (nr ==? winnr()) | |
call add(locations, 'left') | |
else | |
execute nr . "wincmd w" | |
endif | |
call VimNavigate('l') | |
if (nr ==? winnr()) | |
call add(locations, 'right') | |
else | |
execute nr . "wincmd w" | |
end | |
call VimNavigate('k') | |
if (nr ==? winnr()) | |
call add(locations, 'top') | |
else | |
execute nr . "wincmd w" | |
endif | |
call VimNavigate('j') | |
if (nr ==? winnr()) | |
call add(locations, 'bottom') | |
else | |
execute nr . "wincmd w" | |
endif | |
return locations | |
endfunction | |
function! MyResize(dir) | |
let l:cmd = '' | |
let locations = DetermineLocation() | |
for location in locations | |
if (location ==? 'right') | |
let location_right = 1 | |
if ('h' ==? a:dir) | |
let l:cmd = ">" | |
endif | |
if ('l' ==? a:dir) | |
let l:cmd = "<" | |
endif | |
elseif (location ==? 'left') | |
let location_left = 1 | |
elseif (location ==? 'top') | |
let location_top = 1 | |
elseif (location ==? 'bottom') | |
let location_bottom = 1 | |
if ('k' ==? a:dir) | |
let l:cmd = "+" | |
endif | |
if ('j' ==? a:dir) | |
let l:cmd = "-" | |
endif | |
endif | |
endfor | |
if (l:cmd == '') | |
if ('h' ==? a:dir) | |
let l:cmd = "<" | |
elseif ('l' ==? a:dir) | |
let l:cmd = ">" | |
elseif ('k' ==? a:dir) | |
let l:cmd = "-" | |
elseif ('j' ==? a:dir) | |
let l:cmd = "+" | |
endif | |
endif | |
return "5\<c-v>\<c-w>" . l: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