【问题标题】:Swapping "Enter" command with "Cmd + Enter" in VSCode在 VSCode 中用 \"Cmd + Enter\" 交换 \"Enter\" 命令
【发布时间】:2022-09-22 22:59:35
【问题描述】:

我在 keybindings.json 中做了一些更改:

    {
    \"key\": \"cmd+enter\",
    \"command\": \"editor.action.insertLine\", // this doesn\'t work, command not found
    \"when\": \"editorTextFocus\"
},
{
    \"key\": \"enter\",
    \"command\": \"editor.action.insertLineAfter\", // to insert line below, this works correctly
    \"when\": \"editorTextFocus\"
}

我的想法是防止出现以下情况:

print(\"sentence~\") # here I am pushing \"Enter\" while cursor is in ~ place
print(\"sentence
\")

现在,在更改之后,虽然光标在 \") 之前,但它在按下 \"Enter\" 后会跳到新行,这与预期的一样(90% 的使用率)。

我现在的问题是,之前的命令(在按下 \"Enter\" 之后)不再存在。 所以我不能将中间的行减半(使用量的 10%),然后在光标后的前一行的其余部分转到新行。

我正在寻找一个可以固定到“Cmd + Enter”的命令。我想也许只是“editor.action.insertLine”,但它是不正确的。

谢谢您的帮助, 乳酪

    标签: visual-studio-code


    【解决方案1】:

    似乎您可以利用“插入 sn-p”命令功能来调用由单行分隔符 (\n) 组成的 sn-p:

    "command": "editor.action.insertSnippet",
    "args": { "snippet": "\n" }`
    

    谢谢:Visual Studio Code snippet as keyboard shortcut key

    尝试了类似您的要求的东西......

      {
        "key": "enter",
        "command": "editor.action.insertLineAfter",
        "when": "editorTextFocus && !suggestWidgetVisible"
      },
      {
        "key": "ctrl+enter",
        "command": "editor.action.insertSnippet",
        "args": { "snippet": "\n" },
        "when": "editorTextFocus && !suggestWidgetVisible"
      },
      {
        "key": "shift+enter",
        "command": "editor.action.insertLineBefore",
        "when": "editorTextFocus && !suggestWidgetVisible"
      },
    

    …它似乎在 Windows 上按预期工作。 (我添加了更多限制性的“何时”规则以仍然能够确认建议。)

    【讨论】:

      【解决方案2】:

      cmd shift P >> 打开键盘快捷键

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2020-05-05
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多