vscode-intellij-idea-keybindings icon indicating copy to clipboard operation
vscode-intellij-idea-keybindings copied to clipboard

Commenting to move to next line as in Idea

Open wibotwi opened this issue 3 years ago • 13 comments

Found this thread: https://www.reddit.com/r/vscode/comments/7nlp9k/when_commenting_a_line_move_the_cursor_to_the/ They suggested:

You can use the geddski.macros extension to bind the two commands to a key combo:

Add macro to settings.json -- "macros": { "commentLine": ["editor.action.commentLine","cursorDown"] }

Map a key in keybindings.json (use you own favorite key combo) -- { "key": "ctrl+/", "command": "macros.commentLine", "when": "editorTextFocus && !editorReadonly" }

Can we add this to vscode-intellij-idea-keybindings ?

wibotwi avatar Jul 09 '21 16:07 wibotwi

uff, VS Code is so stupid :( It does not do line comment if multiple lines are selected :( See https://github.com/microsoft/vscode/issues/35464

wibotwi avatar Jul 09 '21 16:07 wibotwi

I was a very happy when I found the IntelliJ IDEA Keybindings (as a former IDEA user)

The only thing anoing was the commmentLine didn't move cursor down! Was happy to find the fix myself when I added this to my keybindings.json:

{
    "key": "ctrl+Numpad_Divide",
    "command": "runCommands",
    "args": {
      "commands": ["editor.action.commentLine", "cursorDown"]
    },
    "when": "editorTextFocus && !editorReadonly"
  },

stenaksel avatar Mar 31 '23 08:03 stenaksel

Thanks @stenaksel. This was driving me crazy.

"ctrl+Numpad_Divide" did not work for me. I had to use "ctrl+[Slash]"

close2 avatar Sep 11 '23 04:09 close2

@wibotwi @stenaksel @close2 I add "cursorDown" for this. Please check v1.5.11

kasecato avatar Oct 08 '23 03:10 kasecato

@kasecato is there any way to disable that feature after updating to v1.5.11? I want to keep the cursor on the same line after applying a one-line-comment

ivan-nosar avatar Oct 13 '23 21:10 ivan-nosar

@kasecato is there any way to disable that feature after updating to v1.5.11? I want to keep the cursor on the same line after applying a one-line-comment

I also would like to disable this feature. While I can see it might be useful when commenting out a line of code, it's pretty annoying when adding a new comment via Cmd+/ to then have to go back up a line to write the comment. I suppose that I could just write the comment and then Cmd+/ to turn it into a proper comment, but that's not how I work and I'd rather disable it then have to relearn the muscle memory.

dspigarelli avatar Oct 17 '23 13:10 dspigarelli

it's pretty annoying when adding a new comment via Cmd+/

just checked IDEA, it actually doesn't move to new line if you hit Cmd+/ on empty line IDEA is quite smart :)

wibotwi avatar Oct 17 '23 16:10 wibotwi

@dspigarelli I found a workaround, just in case anybody else is interested.

Add this entry to your keybindings.json to overwrite the behavior introduced by the extension:

{
    "key": "ctrl+/",
    "command": "editor.action.commentLine",
    "when": "editorTextFocus && !editorReadonly"
}

ivan-nosar avatar Oct 17 '23 20:10 ivan-nosar

Thanks for the suggestion, @ivan-nosar. However, it didn't seem to work for me when I added it to ~/Library/Application Support/Code/User/keybindings.json. For now I've downgraded to 1.5.10 and will probably stay there unless this is reversed or some config put in place to disable the behavior.

dspigarelli avatar Oct 18 '23 12:10 dspigarelli

Reverted on v1.5.12.

kasecato avatar Oct 20 '23 00:10 kasecato

@kasecato I don't really understand why you reverted this commit. The correct behavior is to move to the next line.

If some users don't like intellij keybindings, they should either not use intellij keybindings or customize their bindings (as they would need to do in intellij as well).

I would imagine that commenting an empty line happens far less often than commenting a line of code.

close2 avatar Oct 25 '23 04:10 close2

@close2 It seems like the functionality as implemented in this PR doesn't behave exactly like intellij. If this change behaved like intellij for commenting both an empty line (i.e. stay on line) and an existing line of code (i.e. skip down a line), I don't think there would be any issue with it.

dspigarelli avatar Oct 25 '23 14:10 dspigarelli

To fully support this feature, we need to have LSPs support per-language Statements related with https://github.com/kasecato/vscode-intellij-idea-keybindings/issues/175#issuecomment-1950998550

kasecato avatar Feb 23 '24 08:02 kasecato