【问题标题】:Unable to swtich tmux pane with alt+arrow in vscode无法在 vscode 中使用 alt+箭头切换 tmux 窗格
【发布时间】:2020-05-25 15:22:26
【问题描述】:

我是 tmux 用户,个人更喜欢使用 alt+arrow 的切换窗格。但是,在 vscode 中,它不起作用。即使我尝试删除默认键绑定以防止重叠。

我尝试绑定到alt+u/h/j/k,它工作正常。我认为vscode中的alt+arrow键绑定有问题。是否有任何设置我没有找到或者它是一个错误?

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

【问题讨论】:

    标签: debugging visual-studio-code tmux


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:
      [
        {
          "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"
        }
      ]
      

      除了上面丹尼尔的回答之外,xterm.js在按下alt + left时的默认行为是向后跳一个单词,就像ctrl + left一样(右同)。 为了让alt + left发送正确的序列tmux需要,你必须将上面两个键绑定添加到keybindings.json

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-03
        • 1970-01-01
        • 2011-03-28
        • 2022-06-29
        • 1970-01-01
        • 2016-07-28
        • 2013-03-04
        相关资源
        最近更新 更多