Tmux の動作に似たサイズ変更を行う vim スクリプトを作成しました。それはあなたが探しているものかもしれません。
" 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>
このTmuxResize
関数を使用して、他のキーをマップすることができます。最初の引数は方向 ( 'h'
、'j'
、'k'
または'l'
) で、2 番目の引数は分割境界線を移動する量です。