kasecato / vscode-intellij-idea-keybindings

Port of IntelliJ IDEA key bindings for VS Code.
https://marketplace.visualstudio.com/items?itemName=k--kato.intellij-idea-keybindings
MIT License
817 stars 135 forks source link

Commenting to move to next line as in Idea #233

Open wibotwi opened 3 years ago

wibotwi commented 3 years ago

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 commented 3 years ago

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

stenaksel commented 1 year ago

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"
  },
close2 commented 11 months ago

Thanks @stenaksel. This was driving me crazy.

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

kasecato commented 11 months ago

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

ivan-nosar commented 10 months ago

@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

dspigarelli commented 10 months ago

@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.

wibotwi commented 10 months ago

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 :)

ivan-nosar commented 10 months ago

@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"
}
dspigarelli commented 10 months ago

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.

kasecato commented 10 months ago

Reverted on v1.5.12.

close2 commented 10 months ago

@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.

dspigarelli commented 10 months ago

@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.

kasecato commented 6 months ago

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