fix(tmux): always-on Neovim-style NORMAL/VISUAL mode indicator

NORMAL = always visible when working in tmux (green)
VISUAL = switches in when entering copy-mode via prefix+Enter (blue)

Uses pane-mode-changed hook with -F flag for clean format evaluation.
Default @mode_indicator set to NORMAL on config load.
This commit is contained in:
2026-07-18 14:47:18 +05:30
parent 04b03d85cd
commit 1ec7aff593
+14 -28
View File
@@ -366,36 +366,22 @@ source-file "/Users/jsarthak/dotfiles/tmux/config/keybindings.conf"
setw -g window-status-separator " #[fg=#484848]• " #!important setw -g window-status-separator " #[fg=#484848]• " #!important
# ── Mode indicators via hooks ───────────────────────────────────────────────── # ── Mode indicator (always-on, Neovim-style) ──────────────────────────────────
# oh-my-tmux's awk pipeline mangles #{?pane_in_mode,...} inline conditionals, # NORMAL = working in tmux (default, always visible)
# so we drive @mode_indicator via hooks instead. # VISUAL = in copy-mode (prefix + Enter)
# #
# Clear indicator when exiting copy-mode # #{@mode_indicator} is a window user-option set via pane-mode-changed hook.
# We use -F flag so #{pane_in_mode} is evaluated as a tmux format (1=in mode).
# This bypasses oh-my-tmux's awk pipeline which mangles inline #{?...} conditionals.
# Set NORMAL as the default on startup
set-window-option -g @mode_indicator "#[fg=#25be6a,bold] NORMAL "
# Switch between NORMAL and VISUAL whenever the pane mode changes
set-hook -g pane-mode-changed \ set-hook -g pane-mode-changed \
'if-shell "tmux display-message -p \"#{pane_in_mode}\" | grep -q 1" \ 'if-shell -F "#{pane_in_mode}" \
"" \ "set-window-option -g @mode_indicator \"#[fg=#78a9ff,bold] VISUAL \"" \
"set-window-option -g @mode_indicator \"\""' "set-window-option -g @mode_indicator \"#[fg=#25be6a,bold] NORMAL \""'
#
# NORMAL mode (entered copy-mode, no selection yet)
bind-key -T copy-mode-vi Escape { send -X cancel; set-window-option -g @mode_indicator "" }
bind-key -T copy-mode-vi v {
send -X begin-selection
set-window-option -g @mode_indicator "#[fg=#78a9ff,bold] VISUAL "
}
bind-key -T copy-mode-vi y {
send -X copy-selection-and-cancel
set-window-option -g @mode_indicator ""
}
# Set NORMAL indicator on copy-mode entry (overrides keybindings.conf Enter bind)
bind Enter {
copy-mode
set-window-option -g @mode_indicator "#[fg=#25be6a,bold] NORMAL "
}
bind -T root MouseDrag1Pane {
if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" \
"send-keys -M" \
"copy-mode -e; set-window-option -g @mode_indicator \"#[fg=#25be6a,bold] NORMAL \""
}
# ── Per-machine local override (untracked) ──────────────────────────────────── # ── Per-machine local override (untracked) ────────────────────────────────────
# Create ~/.tmux.conf.machine.local on each machine for host-specific tweaks # Create ~/.tmux.conf.machine.local on each machine for host-specific tweaks