IntelliJ, disable cursor moving after commenting a line with a shortcut?

workaround with no macros: if you select the line or a single character from the line, and then comment out, the caret will stay at same position.


You cannot disable that, however you can define a macro.

  1. Start with Edit | Macros | Start Macro Recording
  2. Press Ctrl+/ to comment out current line
  3. Press Up to move caret to that line again
  4. End with Edit | Macros | Stop Macro Recording

The caret will return to the same logical position as before, just as expected.

You can assign that macro to any keyboard shortcut you like: Settings | Keymap | Macros


The solution mentioned by Dmitry Batrak on the YouTrack forum worked for me.

Go to Settings > Advanced Settings. In the Editor section, deselect "Move caret down after Comment with Line Comment action".

The macro method in the accepted answer is not required anymore.