Visual Studio Code - 如何使用 [Alt]+[左/右] 逐字跳转

Mic*_*pai 12 editor visual-studio-code

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

Alt+Left/Right跳转真的很烦人,因为它跳转到完整标识符而不是一个单词。

例子:

  • ?create_foo() Alt+ Rightcreate_foo?()
  • ?createFoo() Alt+ RightcreateFoo?()

我希望例如Ctrl+Right做上面的事情并修改Alt+的行为,Right以便它逐字跳转。

我想要的行为:

  • ?create_foo() Alt+ Rightcreate_?foo()
  • ?create_foo() Ctrl+ Rightcreate_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"
    },
]
Run Code Online (Sandbox Code Playgroud)

Mar*_*ark 18

你正在寻找

cursorWordPartRight
Run Code Online (Sandbox Code Playgroud)

绑定到Shift- Alt- Q

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

{
    "key": "alt+right",
    "command": "cursorWordPartRight",
    "when": "editorTextFocus",
  },
  {
    "key": "alt+left",
    "command": "cursorWordPartLeft",
    "when": "editorTextFocus",
  }
Run Code Online (Sandbox Code Playgroud)

不过,它可能需要每个语言解析器都支持它。它确实适用于 JavaScript。

cursorWordPartLeft (command exists but is unbound by default).
Run Code Online (Sandbox Code Playgroud)

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

cursorWordPartRightSelect
cursorWordPartLeftSelect
cursorWordPartStartLeft
cursorWordPartStartLeftSelect
Run Code Online (Sandbox Code Playgroud)

  • 因为“alt+right”还有一些其他的按键绑定,以减少可能的冲突。 (3认同)