Last active
June 12, 2023 10:01
-
-
Save slarwise/27a9f31246fcf93efdca03e23a9733e4 to your computer and use it in GitHub Desktop.
Navigate vim splits in kitty terminal and other windows with the same skhd keybinds. Window manager yabai.
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
" The (neo)vim function that takes care of navigation within vim. | |
" Same concept as vim-tmux-navigator. If we navigate in the wanted | |
" direction and the winnr() hasn't changed, then we are at the edge | |
" and should forward the navigation to the window manager. | |
function! NvimYabaiNavigate(yabai_direction, vim_direction) | |
let win_nr_before = winnr() | |
execute("wincmd " . a:vim_direction) | |
if win_nr_before ==# winnr() | |
call system("yabai -m window --focus " . a:yabai_direction) | |
endif | |
endfunction |
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 window/vim split to the left/west using keybind alt - h. | |
# Same concept for other directions, just change west to south/north/east and h to e.g. j/k/l. | |
# This assumes that kitty is listening on the address `unix:/tmp/mykitty`. | |
alt - h [ | |
"kitty" : if [ "$(kitty @ --to unix:/tmp/mykitty ls | jq '.[] | select(.is_focused) | .tabs[].windows[].foreground_processes[].cmdline[] | select(. == "nvim")' | wc -l)" -eq 1 ];\ | |
then kitty @ --to unix:/tmp/mykitty send-text :call NvimYabaiNavigate\(\'west\',\'h\'\)\\x0d;\ | |
else yabai -m window --focus west; fi | |
* : yabai -m window --focus west | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution is slow! It seems that kitty @ ls and kitty @ send-text takes the most time. Would be nice to speed it up.