In VS Code, there is currently no built-in command or shortcut that allows you to directly move the cursor to the next line after using Ctrl + / to comment the current line. However, you can do this by creating a new keyboard shortcut (keybinding).
You can follow the steps below to create a new keyboard shortcut to automatically move the cursor to the next line after Ctrl + /:
-
In VS Code, click the File menu (File), select Preferences (Preferences), then select Keyboard Shortcuts (Keyboard Shortcuts).
-
In the Keyboard Shortcuts window, click
{}
the icon to openkeybindings.json
the file. -
In
keybindings.json
a file , you can add a new keyboard shortcut that will first trigger the command to comment the current line, and then trigger the command to move the cursor to the next line. The following is the specific JSON configuration:
{
"key": "ctrl+/",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+/",
"command": "cursorDown",
"when": "editorTextFocus && !editorReadonly"
}
Then save and close keybindings.json
the file .
Now, when you press Ctrl + / in VS Code, the current line should be commented first, and the cursor should automatically move to the next line.
It should be noted that this configuration may override the function of your original Ctrl + / shortcut key, so if you don't want this, you can choose to use other shortcut keys to trigger this function.
In addition, when
the condition indicates that this shortcut key will only be triggered when the editor's text area has focus and is not read-only. You can adjust when
the condition .