Thursday, June 28, 2018

Anyone know how I can use the same keys to move between Vim windows as well as Tmux (or tiling WM) panes?

Anyone know how I can use the same keys to move between Vim windows as well as Tmux (or tiling WM) panes?


For example when I use my key combination to move to the right pane within VIM, VIM should first detect if there actually is a VIM pane to the right. If not it should call a Tmux command to move to the tmux pane on the right (if a tmux pane on the right exists).


Something similar would have to happen if you move back while being in a Tmux pane.


I suppose that besides Tmux you could also use this with a tiling window manager.


Update: moving out of VIM into a Tmux pane can be done as follows:


function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr()) "we haven't moved
if (match(a:key,'[h]')) "we're we going left
silent execute "!tmux select-pane -L &>/dev/null &" | redraw!
elseif (match(a:key,'[j]')) "we're we going down
silent execute "!tmux select-pane -D &>/dev/null &" | redraw!
elseif (match(a:key,'[k]')) "we're we going up
silent execute "!tmux select-pane -U &>/dev/null &" | redraw!
elseif (match(a:key,'[l]')) "we're we going right
silent execute "!tmux select-pane -R &>/dev/null &" | redraw!
endif
endif
endfunction
map
nmap :call WinMove('k')
map
nmap :call WinMove('j')
map
nmap :call WinMove('h')
map
nmap :call WinMove('l')

Not sure yet if moving back is even possible, but I'm going to investigate it.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...