Blog

It's minimal, but I'm posting things.


Navigating between Tmux panes using Vim motions in Zshell

For use in your .zshrc, this will map the CTRL+H,J,K,L keyboard shortcuts, allowing you to navigate between Tmux panes with Vim-like motions.

# Unbind ZSH keys occupying VIM-like navigation shortcuts.
bindkey -r '^H' # Unbind Ctrl-h
bindkey -r '^J' # Unbind Ctrl-j
bindkey -r '^K' # Unbind Ctrl-k
bindkey -r '^L' # Unbind Ctrl-l

# Define functions calling Tmux pane navigation.
function tmux-navigate-left() {
  tmux select-pane -L
}
function tmux-navigate-down() {
  tmux select-pane -D
}
function tmux-navigate-up() {
  tmux select-pane -U
}
function tmux-navigate-right() {
  tmux select-pane -R
}

# Tell Zsh to use these functions as widgets
zle -N tmux-navigate-left
zle -N tmux-navigate-down
zle -N tmux-navigate-up
zle -N tmux-navigate-right

# Bind CTRL+hjkl to navigate panes
bindkey '^H' tmux-navigate-left
bindkey '^J' tmux-navigate-down
bindkey '^K' tmux-navigate-up
bindkey '^L' tmux-navigate-right

Published on 2024-08-21T19:50:32.268181Z
Last updated on 2024-08-21T19:50:32.268181Z