diff --git a/tmux.conf b/tmux.conf index 3847513..2e88298 100644 --- a/tmux.conf +++ b/tmux.conf @@ -51,11 +51,24 @@ unbind Enter bind Enter resize-pane -Z bind C-Enter resize-pane -Z -# Use Alt-[j/i/l/k] keys without prefix key to switch panes. -bind -n M-j select-pane -L -bind -n M-k select-pane -D -bind -n M-i select-pane -U -bind -n M-l select-pane -R +# Enable smart pane switching that's Emacs aware. +is_emacs='echo "#{pane_current_command}" | grep -iqE "(^|\/)emacs$"' + +# Use Alt-[i/k/j/l] keys without prefix key to switch panes if current pane is +# not running Emacs. If the pane is running Emacs, let Emacs receive the +# keybindings instead. +bind -n M-i if-shell "$is_emacs" "send-keys M-i" "select-pane -U" +bind -n M-k if-shell "$is_emacs" "send-keys M-k" "select-pane -D" +bind -n M-j if-shell "$is_emacs" "send-keys M-j" "select-pane -L" +bind -n M-l if-shell "$is_emacs" "send-keys M-l" "select-pane -R" +bind -T copy-mode M-i if-shell "$is_emacs" "send-keys M-i" "select-pane -U" +bind -T copy-mode M-k if-shell "$is_emacs" "send-keys M-k" "select-pane -D" +bind -T copy-mode M-j if-shell "$is_emacs" "send-keys M-j" "select-pane -L" +bind -T copy-mode M-l if-shell "$is_emacs" "send-keys M-l" "select-pane -R" +bind -T copy-mode-vi M-i if-shell "$is_emacs" "send-keys M-i" "select-pane -U" +bind -T copy-mode-vi M-k if-shell "$is_emacs" "send-keys M-k" "select-pane -D" +bind -T copy-mode-vi M-j if-shell "$is_emacs" "send-keys M-j" "select-pane -L" +bind -T copy-mode-vi M-l if-shell "$is_emacs" "send-keys M-l" "select-pane -R" # Toogle synchronize-panes without prefix key. bind -n M-I setw synchronize-panes