No plugins needed!
Last active
June 29, 2022 23:36
-
-
Save danijar/ba4de0b2002b52ef9263dc01f57efd82 to your computer and use it in GitHub Desktop.
Seamless focus switching between Vim splits, Vim tabs, and Tmux panes.
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
# Forward movements commands if Vim is focused. | |
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ | |
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'" | |
bind -n C-h if-shell "$is_vim" 'send-keys C-h' 'select-pane -L' | |
bind -n C-j if-shell "$is_vim" 'send-keys C-j' 'select-pane -D' | |
bind -n C-k if-shell "$is_vim" 'send-keys C-k' 'select-pane -U' | |
bind -n C-l if-shell "$is_vim" 'send-keys C-l' 'select-pane -R' |
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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Focus Movements | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function! SplitTabPaneRight() | |
let win = winnr() | |
wincmd l | |
if win != winnr() | |
return | |
elseif tabpagenr() != tabpagenr('$') | |
normal gt | |
else | |
:call system('tmux select-pane -R') | |
endif | |
endfunction | |
function! SplitTabPaneLeft() | |
let win = winnr() | |
wincmd h | |
if win != winnr() | |
return | |
elseif tabpagenr() != 1 | |
normal gT | |
else | |
:call system('tmux select-pane -L') | |
endif | |
endfunction | |
function! SplitTabDown() | |
let win = winnr() | |
wincmd j | |
if win == winnr() | |
:call system('tmux select-pane -D') | |
endif | |
endfunction | |
function! SplitPaneUp() | |
let win = winnr() | |
wincmd k | |
if win == winnr() | |
:call system('tmux select-pane -U') | |
endif | |
endfunction | |
nnoremap <silent> <c-h> :call SplitTabPaneLeft()<cr> | |
nnoremap <silent> <c-l> :call SplitTabPaneRight()<cr> | |
nnoremap <silent> <c-j> :call SplitTabDown()<cr> | |
nnoremap <silent> <c-k> :call SplitPaneUp()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment