Home > Software design >  Move to the next line when commenting a line in VS Code
Move to the next line when commenting a line in VS Code

Time:02-23

I just moved from PhpStorm to VS Code and there are still things I'm not used to.

When I comment a line with Ctrl / the cursor stays in that line. I want my cursor to move to the next line (like it actually does in PhpStorm).

Any ideas on how I can add this "go to next line" action after commenting a line ?

CodePudding user response:

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.

  • Related