【问题标题】:Visual Studio Code - How to jump by word with [Alt]+[Left/Right]Visual Studio Code - 如何使用 [Alt]+[Left/Right] 逐字跳转
【发布时间】:2019-02-18 11:41:26
【问题描述】:

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

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

例子:

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

我想要例如Ctrl+Right 执行上述操作并修改 Alt+Right 的行为,使其逐字跳转.

我想要的行为:

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

解决方案:

我的最终keybindings.jsonconfig 添加了 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"
    },
]

【问题讨论】:

  • 有人对使用vscode 1.43.2macOS Catalina 10.15.1ctrl 快捷方式有问题吗?不包括ctrl 的任何其他键绑定都可以...

标签: visual-studio-code editor


【解决方案1】:

你正在寻找

cursorWordPartRight

绑定到Shift-Alt-Q

Alt-Right 绑定到“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

【讨论】:

  • 谢谢。你为什么使用editorTextFocus 选项?
  • 因为“alt+right”还有一些其他的键绑定,以减少可能的冲突。
猜你喜欢
  • 1970-01-01
  • 2021-09-04
  • 2020-04-16
  • 2015-07-17
  • 2017-06-10
  • 2021-08-04
  • 2021-10-24
  • 2020-02-21
  • 2015-07-11
相关资源
最近更新 更多