I've made myself a vim script to make the resizing similar to Tmux' behavior.
It might be what you are looking for.
" Tmux-like window resizing
function! IsEdgeWindowSelected(direction)
let l:curwindow = winnr()
exec "wincmd ".a:direction
let l:result = l:curwindow == winnr()
if (!l:result)
" Go back to the previous window
exec l:curwindow."wincmd w"
endif
return l:result
endfunction
function! GetAction(direction)
let l:keys = ['h', 'j', 'k', 'l']
let l:actions = ['vertical resize -', 'resize +', 'resize -', 'vertical resize +']
return get(l:actions, index(l:keys, a:direction))
endfunction
function! GetOpposite(direction)
let l:keys = ['h', 'j', 'k', 'l']
let l:opposites = ['l', 'k', 'j', 'h']
return get(l:opposites, index(l:keys, a:direction))
endfunction
function! TmuxResize(direction, amount)
" v >
if (a:direction == 'j' || a:direction == 'l')
if IsEdgeWindowSelected(a:direction)
let l:opposite = GetOpposite(a:direction)
let l:curwindow = winnr()
exec 'wincmd '.l:opposite
let l:action = GetAction(a:direction)
exec l:action.a:amount
exec l:curwindow.'wincmd w'
return
endif
" < ^
elseif (a:direction == 'h' || a:direction == 'k')
let l:opposite = GetOpposite(a:direction)
if IsEdgeWindowSelected(l:opposite)
let l:curwindow = winnr()
exec 'wincmd '.a:direction
let l:action = GetAction(a:direction)
exec l:action.a:amount
exec l:curwindow.'wincmd w'
return
endif
endif
let l:action = GetAction(a:direction)
exec l:action.a:amount
endfunction
" Map to buttons
nnoremap <M-h> :call TmuxResize('h', 1)<CR>
nnoremap <M-j> :call TmuxResize('j', 1)<CR>
nnoremap <M-k> :call TmuxResize('k', 1)<CR>
nnoremap <M-l> :call TmuxResize('l', 1)<CR>
You can use the TmuxResize
function to map other keys to it.
The first argument is the direction ('h'
, 'j'
, 'k'
or 'l'
), the second argument is how much should the split border move.