vscode + vim: commenting line doesn't move cursor down

3.9k Views Asked by At

How to make Visual Studio Code move my cursor one line down, after commenting current line with ctrl + / shortcut? I tried (in user settings):

"vim.normalModeKeyBindings": [
    {
        "before": ["<C+/>"],
        "after": ["<C+/>", "j"]
    }
]

but it doesn't work.

Using Linux Manjaro + vscode 1.27.2

2

There are 2 best solutions below

6
Kossak On BEST ANSWER

The solution for current vscode (1.48.0):

  1. Install this extension: geddski.macros
  2. Add this line to settings.json:
"macros": { "commentLine": ["editor.action.commentLine","cursorDown"] },
  1. Add these lines to keybindings.json:
{
    "key": "ctrl+/",
    "command": "macros.commentLine",
    "when": "editorTextFocus && !editorReadonly"
},

How to quickly open these files:

  • For keybindings.json press Ctrl+Shift+p and write Preferences: Open Keyboard Shortcuts (JSON)
  • For settings.json press above shortcut and write Preferences: Open Settings (JSON)

Physical location of files:
Linux:

  • ~/.config/Code/User/keybindings.json
  • ~/.config/Code/User/settings.json

Windows:

  • %UserProfile%\AppData\Roaming\Code\User\keybindings.json
  • %UserProfile%\AppData\Roaming\Code\User\settings.json

MacOS:

  • ~/Library/Application\ Support/Code/User/keybindings.json
  • ~/Library/Application\ Support/Code/User/settings.json
0
Shihe Zhang On

If you check the keybindings.json (Click the gear icon) search comment
You will find there is a Toggle Line Comment Command there.
So you may need to disable it first.