After vscode presses ctrl+/ comment, how to automatically wrap?

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 + /:

  1. In VS Code, click the File menu (File), select Preferences (Preferences), then select Keyboard Shortcuts (Keyboard Shortcuts).

  2. In the Keyboard Shortcuts window, click {}the icon to open keybindings.jsonthe file.

  3. In keybindings.jsona 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.jsonthe 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, whenthe 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 whenthe condition .

Guess you like

Origin blog.csdn.net/m0_57236802/article/details/130965584