无法在 vscode 中使用 alt+箭头切换 tmux 窗格
Posted
技术标签:
【中文标题】无法在 vscode 中使用 alt+箭头切换 tmux 窗格【英文标题】:Unable to swtich tmux pane with alt+arrow in vscode 【发布时间】: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
【问题讨论】:
【参考方案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
【讨论】:
以上是关于无法在 vscode 中使用 alt+箭头切换 tmux 窗格的主要内容,如果未能解决你的问题,请参考以下文章
Eclipse4.7使用基础 快捷键 alt + 左右箭头 实现当前打开的不同文件间的切换