Move to the next line when commenting a line in VS Code

See https://stackoverflow.com/a/75808372/836330 for more on runCommands. No extension is needed anymore as macro-like functionality has been built into vscode v1.77+ so these keybindings work now (in your keybindings.json):

{
  "key": "ctrl+/",  // whatever keybindings you want
  "command": "runCommands",
  "args": {
    "commands": [
      "editor.action.commentLine",
      "cursorDown"
    ]
  },
  "when": "editorTextFocus"
},
{
  "key": "shift+alt+A",
  "command": "runCommands",
  "args": {
    "commands": [
      "editor.action.blockComment",
      "cursorDown"
    ]
  },
  "when": "editorTextFocus"
}

Previous Answer:

Using this keybinding (in your keybindings.json) and the macro extension multi-command:

{
  "key": "ctrl+/",                     // whatever you want 
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "editor.action.commentLine",     // for line comments 
      "editor.action.insertLineAfter"
      // "cursorDown"
    ]
  },
  "when": "editorTextFocus"
},
{
  "key": "shift+alt+A",                   // whatever keybinding you want
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "editor.action.blockComment",       // for block comments too
      "editor.action.insertLineAfter"
      //  "cursorDown"
    ]
  },
  "when": "editorTextFocus"
}

The only downside to this is that it also inserts a line when you uncomment. Instead of inserting a line, if you just want to go down a line (where there might be pre-existing text, use the command "cursorDown" instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)