IntelliJ autocomplete escape
I'm trying out IntelliJ and have one minor ann开发者_运维问答oyance that I can't figure out if there is a possible solution for in IntelliJ. In Eclipse and even TextMate (as well as many other editors with autocomplete), if you are in the middle of an autocomplete section such as a string or parenthesis area, you can hit Enter or Tab to get to the end of that section. For instance:
if (blah.equals(something.toString()))
The caret would be in the middle of the parenthesis of the toString part. In IntelliJ, you can type through those parenthesis with no issue, or you could maybe hit the "End" key to get to the end of it. One is a minor annoyance, the other is more annoying since I have to take my hands off of the home row. In eclipse I could hit the Enter key and it would get me out of this... TextMate, Tab.
Is there a setting I can tweak or something I can do to give me similar functionality in IntelliJ?
In that context if you press Ctrl-Shift-Enter as CrazyCoder suggests, you kind of get this behavior. It will add the braces and put your cursor on the next line. You can also press Shift-Enter which will put you to the next line and makes less assumptions about the code. Ctrl-Shift-Enter behaves differently depending on the code it is looking at, so that won't give you consistent behavior. For example in the middle of a string it puts you at the end of the line and adds a semi-colon.
It just seems that end is preferred key here to get to the end of the line. You can add in the key map an additional key to go to the end of the line, if a different key combination works better for you, but it won't just change its behavior because you are in the middle of a parentheses.
Looking at the IDEA options, it seems that the parentheses behavior isn't really a live template like automatically creating a for loop, so you don't tab out when you are done, rather it is just automatically complete the parentheses for you, and intelligently recognizing that you may want to type fluidly as if it didn't.
i tried cmd-shift-enter (on mac) and the result seems more useful to me (in javascript code). i'm using a pipe ('|') to visualize the cursor here:
before:
var x = func1(func2(|))
after pressing cmd-shift-enter:
var x = func1(func2());|
so it even adds the semicolon at the end of the line (but you still have to press enter again to jump to the next line).
EDIT
just found this shortcut is even more useful:
before:
if(a == b|)
after pressing cmd-shift-enter:
if(a == b) {
|
}
works both in php and javascript
Since these answers are kind of old, I don't know if anyone is aware that you can get out of the enclosed auto-completed filed by typing Shift+KEY
In Java if you did System.out.println("Hello World!"); If your cursor is within the "", Shift+" will get you outside of the "" and Shift+) will get you outside of the ()
Not currently supported by Intellij. There is an open feature request on this at http://youtrack.jetbrains.com/issue/IDEA-74666. Extra votes would be nice.
精彩评论