skip to Main Content

I have made some changes in 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"
}

My idea was to prevent the following situation:

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

Now, after the change, although cursor is before ") it skips to the new line after pushing "Enter", which is as expected (90% of usage).

My problem now is, that the previous command (after pressing "Enter") exist no more.
So I can’t halve the line in the middle (10% of usage) and go to the new line with the rest of the previous line after the cursor.

I am looking for a command which I could pin to "Cmd + Enter". I thought maybe just "editor.action.insertLine" but it’s not correct.

Thank you for your help,
sercheese

2

Answers


  1. cmd shift P >> Open keyboard shortcuts

    Login or Signup to reply.
  2. Seems that you can leverage "insert snippet" command feature that calls snippet consisting of single line separator (n):

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

    Thanks: Visual Studio Code snippet as keyboard shortcut key

    Tried something like your requirements with…

      {
        "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"
      },
    

    …and it seems to work as intended on Windows. (I’ve added more restrictive "when" rule to be still able to confirm suggestion.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search