21

I'm a beginner in android programing. I use Android Studio (v0.8.9). Here is problem a tackled with:

Ctrl + Shift + Enter adds a semicolon and moves the caret to the end of the line, Shift + Enter does not a add semicolon and moves the caret to a new line. Question is how to make InteliJ IDEA add semicolon to the end of current line and move caret to the new line by pressing, say, Shift + Enter?

MendelG
  • 14,885
  • 4
  • 25
  • 52
Sergii
  • 1,017
  • 1
  • 10
  • 19
  • possible duplicate of [How to add semicolon after method call when inside parameter list in IntelliJ IDEA?](http://stackoverflow.com/questions/3332227/how-to-add-semicolon-after-method-call-when-inside-parameter-list-in-intellij-id) – Noel M Sep 10 '14 at 15:39
  • Not quite. They recommend use ctrl+shift+Enter - which adds semicolon BUT lives caret at the end of the line. I need add caret and goto new line, as if you pressed consequently ctrl+shift+Enter and then Enter. – Sergii Sep 10 '14 at 15:46

4 Answers4

42

Pressing Ctrl + Shift + Enter twice should do the job. You can record a keyboard macro that does it, and assign a custom shortcut to it.

MendelG
  • 14,885
  • 4
  • 25
  • 52
Peter Gromov
  • 17,615
  • 7
  • 49
  • 35
  • 2
    Thank you Peter. This should work but it's kind of... ugly. There should the way to do it by means of android studio, without any macro recorders, right? – Sergii Sep 11 '14 at 07:57
  • There's currently no such action built into IntelliJ or Android Studio. There's a request for changing Complete Statement (http://youtrack.jetbrains.com/issue/IDEABKL-7065) but it's not very likely to be implemented because it breaks user habits. – Peter Gromov Sep 11 '14 at 08:51
  • 1
    Wouldn't it be best if there's just a setting for it? Like an opt-in in the Preferences or something. – bytehala Jan 10 '15 at 07:26
  • That might be possible, especially if it becomes clear there's more benefit than harm from complicating the UI and the behavior. – Peter Gromov Jan 12 '15 at 10:37
  • 1
    This works great. And it could not only add semicolon, but also add curly bracket based on context. – Jason Jul 25 '18 at 19:51
  • Recording a macro is super easy. You press Ctrl+Shift+Enter twice, name it, then select it from the Keymap. – Det Jul 11 '19 at 17:07
  • `cmd + shift + enter` on mac – Janac Meena Jun 04 '20 at 20:59
  • True life saver. Didn't know that. Now I can get rid of my stupid macro. – Claudson Martins Nov 17 '20 at 12:29
2

It's 2020 now and Ctrl + Shift + Enter shortcut now works as expected in Android Studio (tested 4.1.1). MacOS version should have a different modifier, but should be almostly same.

ttimasdf
  • 1,367
  • 1
  • 12
  • 19
1

Another way to get the IDE to add semicolon If you have code completion enabled you can press tab on your code snippet, then press shift+enter to go to a new line.

For example:
1. type sout and press tab.
2. the editor fills in System.out.println($CursorHere);
3. type "foobar" where the cursor appears.
4. press shift enter and you'll be taken to a new line.

MTen
  • 186
  • 1
  • 4
1

You can customise your shortcuts in preferences - > Keymap

Set custom shortcut

Edit or add new shorts cut is very easy from here.

Sumit Patel
  • 379
  • 3
  • 8