无法在VSCode中使用alt+箭头键切换tmux窗格

4
我是一个tmux用户,个人更喜欢使用alt+方向键来切换窗格。然而,在vscode中,这个组合键无法使用。我甚至尝试删除默认快捷键以避免重叠冲突,但问题依旧存在。
我尝试将其绑定到alt+u/h/j/k,并且它可以正常工作。我认为在vscode中存在alt+arrow键绑定的问题。我是否有所遗漏或这是一个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
2个回答

3
[
  {
    "key": "alt+up",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u001b[1;3A" },
    "when": "terminalFocus"
  },
  {
    "key": "alt+down",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u001b[1;3B" },
    "when": "terminalFocus"
  },
  {
    "key": "alt+left",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u001b[1;3D" },
    "when": "terminalFocus"
  },
  {
    "key": "alt+right",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u001b[1;3C" },
    "when": "terminalFocus"
  }
]

除了Daniel上面的回答之外,xterm.js按下alt + left的默认行为是向后跳一个单词,就像ctrl + left(右侧也一样)。 为了让alt + left发送正确的序列,需要将上述两个键绑定添加到keybindings.json中。

2

when子句已更改,因此实际上并未删除这些键绑定。您可以通过将日志级别更改为trace并查看devtools控制台来检查此内容。

忽略这些键绑定的更好方法是通过以下设置将它们从优先于将序列发送到shell的方式中删除:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接