18

I noticed that esc will also start listening for instructions to switch panes. I'm new to Tmux, I copied a Tmux conf file earlier today which should only have enabled alt to switch panes, so I'm not sure if this conf file enabled it or if it's standard in Tmux 2.3.

Seeing as I tend to start moving around after entering normal mode, this annoys the hell out of me. Can anyone tell me how to disable pane switching with esc?

Tijsdv
  • 181
  • 1
  • 4

3 Answers3

25

Found this, which fixed the problem for me: https://unix.stackexchange.com/questions/23138/esc-key-causes-a-small-delay-in-terminal-due-to-its-alt-behavior

Add to your ~/.tmux.conf:

set -s escape-time 0
ipetrik
  • 1,749
  • 18
  • 28
  • 4
    This was driving me crazy for weeks but I couldn't realize what was the trigger. Back to sanity. – pedrosaurio Oct 12 '18 at 19:53
  • 1
    My vim just randomly switches panes, I thought it was due to net connection problem, so I change host closer to my location, but it does not work, until I google and find this. – ospider Oct 13 '18 at 08:11
  • This does not work for me. ESC still switches panes. – saidaspen Mar 22 '19 at 22:09
  • As a vim user, I've remapped Caps Lock to be a second Escape key... and this was driving me crazy. I'd try to go back to normal mode in in vim (or bash), and would end up inexplicably switching tmux panes... despite having used `unbind-key -a` to remove all (other) tmux key bindings This seems to have cured it! – Dolph Aug 22 '19 at 02:41
3

I think your ~/.tmux.conf file contains lines like below:

bind -n M-h select-pane -L
bind -n M-j select-pane -D 
bind -n M-k select-pane -U
bind -n M-l select-pane -R

These lines bind Alt-h(j,k,l) to switch pane without need of prefix key. But it seems that ESC+h(j,k,l) will also trigger the Alt-h(j,k,l). I don't know why either.

My way to fix it:

  1. Make sure you have closed the tmux session. ( use "prefix+&+y" to kill all window)
  2. Change the key binding above in .tmux.conf to the new one below:

    bind -n C-j select-pane -D \; display-panes

    bind -n C-k select-pane -U \; display-panes

    bind -n C-h select-pane -L \; display-panes

    bind -n C-l select-pane -R \; display-panes

  3. Restart your tmux. This will remove your previous M-(h,j,k,l) binding, and the new binding will take effect.

    The meaning of the new binding is to: Use Ctrl-vim keys without prefix key to switch pane, and at the same time, show the pane indicator: the current active pane index's color will be red.

  • For whatever reason, the bindings you've lists disable commandline tab completion for me. Tab instead displays pane numbers now. – jcope Jun 09 '21 at 15:45
0

if you run

tmux list-keys

you may see in your list

bind-key    -T root         M-h               previous-window
bind-key    -T root         M-l               next-window

so running

unbind-key -T root M-h
unbind-key -T root M-l

can unbind them. Worked on Tmux 2.5 OSX.

rado
  • 4,040
  • 3
  • 32
  • 26