Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If I comment out or in a line with Ctrl+/ in IntelliJ 14 the cursor moves a line down. How can I disable that?

like image 514
simonides Avatar asked Dec 17 '14 18:12

simonides


People also ask

What is Ctrl Alt L in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.

What is the shortcut key for comment in IntelliJ?

To quickly add a line comment in IntelliJ IDEA, press ⌘ / on macOS or Ctrl + / on Windows and Linux. Block comments or multi-line comments usually take the form of a paragraph.

How do I comment lines in IntelliJ?

Comment and uncomment blocks of codeFrom the main menu, select Code | Comment with Block Comment. Press Ctrl+Shift+/ .

How do I move the cursor to the end of the line in IntelliJ?

Move Caret to Line End Alt + L.


2 Answers

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

like image 173
sina72 Avatar answered Sep 28 '22 03:09

sina72


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.

like image 41
Martin Klosi Avatar answered Sep 28 '22 03:09

Martin Klosi