142

I'm finally making the voyage back to IntelliJ via Eclipse. Currently my Eclipse is set up so that if I currently have a statement such as this (where ^ denotes where my cursor currently sits):

foo.bar("hello"^)

and I hit the semi-colon (;) key, it will automatically put the semi-colon at the end of the statement:

foo.bar("hello");

Currently IntelliJ does this:

foo.bar("hello";)

Meaning I will have to explicitly type the closing bracket before typing the semi-colon.

Not a huge problem obviously but I have found myself putting the semi-colon in the wrong place a few times today as I make the transition back to IntelliJ and thought that it may be more efficient (for both my fingers and brain) not to have to type the closing bracket.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
digiarnie
  • 22,305
  • 31
  • 78
  • 126
  • 3
    Thanks, by the way there is no such thing as "curly braces" they are just "braces". – Gordon Dickens Nov 08 '12 at 19:40
  • 2
    I have added the netbeans shortcut (ctrl+;) to IntelliJ for this functionality. You can add it in File -> Settings -> Keymap -> search for "complete current statement" -> add keyboard shortcut. – Stefanos Kalantzis May 13 '14 at 15:36
  • 1
    not only the semicoln, but also the brace. And If I DO want to put the semicon at the cursor position but eclipse smartly put it at the end, just press backspace and It will go back to where it should be. That why I still keep using eclipse instead of as. – jiashie Nov 25 '15 at 01:58

3 Answers3

236

For Windows or Linux users, Ctrl+Shift+Enter.

For macOS/OS X users, ⌘ Command+⇧ Shift+Enter.

That finishes the statement you're currently writing. Try it in a few different situations, like in if statements, for loops etc, and you'll see that it'll complete the line and open some curly braces for you if necessary.

agilob
  • 6,082
  • 3
  • 33
  • 49
Noel M
  • 15,812
  • 8
  • 39
  • 47
  • 10
    Not quite as nice as in Eclipse as it requires thinking about the context and it's three keys instead of one. But better than End; Semicolon, so thanks! – robinst Jun 23 '14 at 02:15
  • 32
    I don't like it. Eclipse wins on this one, it's a painful annoyance. It's not even a shortcut in Eclipse, it just moves the semicolon to the end because it's obvious that it should (when the setting is turned on). Using any kind of shortcut key to do this is stupid. – Manius Jan 15 '15 at 03:15
  • 6
    Strongly agree that Eclipse is much better in this case. There are plenty of others also, which lead me to occasionally calling the JetBrains IDE: UnIntelliJ – Stan Kurdziel Mar 19 '15 at 17:20
  • 2
    I don't think the OP wants a keyboard shortcut to do what the one key (the semicolon) should do. Especially if you have to move your hand and hit three times as many keys in the process. – SMBiggs Dec 28 '15 at 22:55
  • 2
    The worse thing in IntelliJ, especially for those coming from Eclipse, is to adapt to the shortcuts. I think they have spent lots of time to figure out how to make them less intuitive as possible. – Jordan Silva Dec 19 '17 at 01:50
42

You can add a keymap of your own. I added Ctrl+; to my Keymaps for the "Complete Current Statement" action. This saved me an extra key stroke and made it a little bit more intuitive.

  1. Go to Settings > Keymap
  2. In the search box, enter "Complete Current Statement".
  3. Right-click on the entry and select "Add Keyboard shortcut"
  4. With the First Stroke field hightlighted, enter your key combination. E.g., Ctrl+;, which will display as Ctrl+Semicolon
  5. Click OK, and OK to save and exit.

You can opt to remove or keep the existing mapping. Should look something like this when you're done:

enter image description here

LimaNightHawk
  • 6,613
  • 3
  • 41
  • 60
  • 3
    I used the semicolon symbol `;` as the shortcut. Seems to work just fine. – SMBiggs Apr 27 '20 at 21:47
  • 2
    @SMBiggs I thought it was a good idea too, but it's not good for a `for` loop, because we type semicolons in the middle of the statement. – Drarig29 Nov 04 '20 at 18:17
  • @Drarig29 Ha! You're right! I rarely use the old-school for loops, but it totally breaks. And there are still plenty of reasons to use the old for loop syntax. So it goes. – SMBiggs Nov 09 '20 at 16:51
3

if you want always have it just do this

enter image description here

Hamidreza Sadegh
  • 2,155
  • 31
  • 33