IntelliJ autocomplete escape

后端 未结 4 1247
北恋
北恋 2021-02-20 07:37

I\'m trying out IntelliJ and have one minor annoyance that I can\'t figure out if there is a possible solution for in IntelliJ. In Eclipse and even TextMate (as well as many ot

相关标签:
4条回答
  • 2021-02-20 08:04

    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 ()

    0 讨论(0)
  • 2021-02-20 08:08

    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.

    0 讨论(0)
  • 2021-02-20 08:20

    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.

    0 讨论(0)
  • 2021-02-20 08:24

    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

    0 讨论(0)
提交回复
热议问题