Visual Studio代码-如何通过[Alt] + [左/右]逐字跳转

时间:2019-02-18 11:41:26

标签: visual-studio-code editor

我已经开始在MacOS上使用Visual Studio代码。

Alt + 左/右跳转确实很烦人,因为它跳了完整的标识符而不是一个单词。

示例:

  • ▼create_foo() Alt + create_foo▼()
  • ▼createFoo() Alt + createFoo▼()

我想要 Ctrl + 可以完成上述操作,并修改 Alt + 的行为,使其按单词跳转

我想要的行为:

  • ▼create_foo() Alt + create_▼foo()
  • ▼create_foo() Ctrl + create_foo▼()

解决方案:

我最后的keybindings.json配置带有添加的 Shift (选择)选项:

[
    {
        "key": "alt+left",
        "command": "cursorWordPartLeft",
        "when": "editorTextFocus",
    },
    {
        "key": "alt+right",
        "command": "cursorWordPartRight",
        "when": "editorTextFocus",
    },
    {
        "key": "shift+alt+left",
        "command": "cursorWordPartLeftSelect",
        "when": "editorTextFocus"
    },
    {
        "key": "shift+alt+right",
        "command": "cursorWordPartRightSelect",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+left",
        "command": "cursorWordStartLeft",
        "when": "editorTextFocus"
    }, 
    {
        "key": "ctrl+right",
        "command": "cursorWordEndRight",
        "when": "editorTextFocus"
    },
    {
        "key": "shift+ctrl+left",
        "command": "cursorWordStartLeftSelect",
        "when": "editorTextFocus"
    },
    {
        "key": "shift+ctrl+right",
        "command": "cursorWordEndRightSelect",
        "when": "editorTextFocus"
    },
]

1 个答案:

答案 0 :(得分:1)

您正在寻找

cursorWordPartRight
Shift - Alt - Q 绑定的

Alt -已绑定到“ Go Forward”命令,您可以删除该绑定并将其用于cursorWordPartRight命令。

{
    "key": "alt+right",
    "command": "cursorWordPartRight",
    "when": "editorTextFocus",
  },
  {
    "key": "alt+left",
    "command": "cursorWordPartLeft",
    "when": "editorTextFocus",
  }

它可能需要每种语言解析器都支持。它确实可以在JavaScript中工作。

cursorWordPartLeft (command exists but is unbound by default).

还有其他未绑定的相关命令:

cursorWordPartRightSelect
cursorWordPartLeftSelect
cursorWordPartStartLeft
cursorWordPartStartLeftSelect