Created
October 7, 2012 10:49
-
-
Save bonsaiben/3847844 to your computer and use it in GitHub Desktop.
Vim seamless splitting and movement
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
" if there is no split in the direction of movement, split and then move to it | |
function! MoveOrSplit(direction) | |
" the width of an unsplit window on your display | |
let maxwidth = 181 | |
" the height of an unsplit window on your display | |
let maxheight = 49 | |
let has_no_vsplit = winnr('$') < 2 || winwidth(0) == maxwidth | |
let has_no_split = winnr('$') < 2 || winheight(0) == maxheight | |
if a:direction == 'j' || a:direction == 'k' | |
if has_no_split | |
:split | |
end | |
else | |
if has_no_vsplit | |
:vsplit | |
end | |
end | |
:exec "normal \<c-w>" . a:direction | |
endfunction | |
:command! MoveOrSplitDown :call MoveOrSplit('j') | |
:command! MoveOrSplitUp :call MoveOrSplit('k') | |
:command! MoveOrSplitRight :call MoveOrSplit('l') | |
:command! MoveOrSplitLeft :call MoveOrSplit('h') | |
:map <c-j> :MoveOrSplitDown<cr> | |
:map <c-k> :MoveOrSplitUp<cr> | |
:map <c-l> :MoveOrSplitRight<cr> | |
:map <c-h> :MoveOrSplitLeft<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment