Search code examples
debuggingvisual-studio-codetmux

Unable to swtich tmux pane with alt+arrow in vscode


I am a tmux user and personally perfer switch pane with alt+arrow. However, in vscode, it does not work. Even I tried removing the default keybinding in prevent of overlapping.

I tried binding to alt+u/h/j/k and it work fine. I think there is a problem with alt+arrow key binding in vscode. Is there any setting I did not find or is it a bug?

keybinding.json - vscode

 {
        "key": "alt+up",
        "command": "-workbench.action.terminal.focusPreviousPane",
        "when": "terminalFocus"
    },
    {
        "key": "alt+down",
        "command": "-workbench.action.terminal.focusNextPane",
        "when": "terminalFocus"
    },
    {
        "key": "alt+left",
        "command": "-workbench.action.terminal.focusPreviousPane",
        "when": "terminalFocus"
    },
    {
        "key": "alt+right",
        "command": "-workbench.action.terminal.focusNextPane",
        "when": "terminalFocus"
    }

.tmux.conf

# switch panes with "(alt) + (↑ ↓ ← →)"
## This does not work in vscode integrated terminal
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R

## This do work
bind -n M-u select-pane -U
bind -n M-j select-pane -D
bind -n M-h select-pane -L
bind -n M-k select-pane -R

Solution

  • The when clause changed so those keybindings aren't actually being removed. You can check this by changing your log level to trace and viewing the devtools console.

    A better way to ignore those keybindings is to remove them from being prioritized over sending sequences to the shell via this setting:

      "terminal.integrated.commandsToSkipShell": [
        "-workbench.action.terminal.focusPreviousPane",
        "-workbench.action.terminal.focusNextPane",
        "-workbench.action.terminal.focusPreviousPane",
        "-workbench.action.terminal.focusNextPane",
      ],