Skip to content

Instantly share code, notes, and snippets.

@slarwise
Last active June 12, 2023 10:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slarwise/27a9f31246fcf93efdca03e23a9733e4 to your computer and use it in GitHub Desktop.
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.
" 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
# 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
]
@slarwise
Copy link
Author

slarwise commented Apr 8, 2020

This solution is slow! It seems that kitty @ ls and kitty @ send-text takes the most time. Would be nice to speed it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment