How to surround code by curly braces in IntelliJ IDEA?

后端 未结 7 2069
予麋鹿
予麋鹿 2021-02-03 16:50

How to surround code by curly braces in IntelliJ IDEA? Is there any keyboard-shortcut for such operation?

相关标签:
7条回答
  • 2021-02-03 17:26

    Easy, just follow the arrows in this picture, from left to right: Screenshot with arrows

    0 讨论(0)
  • 2021-02-03 17:29

    Yes, try Ctrl+Alt+T (Surround With), then A (Curly Braces).

    0 讨论(0)
  • 2021-02-03 17:36

    Just configure Smart Keys as follow:
    IDE Settings > Editor > General > Smart Keys > Surround selection on typing quote or brace.

    From the IntelliJ built-in help:

    If this check box is selected, the selected text on typing a quote, double-quote or brace, will be surrounded with these characters.

    If this check box is not selected, then the typed quotes, double-quotes or braces will replace the selection.

    0 讨论(0)
  • 2021-02-03 17:37

    Just click as the below 2 steps

    1, CTRL + ALT + T
    2, then press ALT + A at the same time.

    Hope to help you.

    0 讨论(0)
  • 2021-02-03 17:47

    I had oneline if statement without curly braces and I had to update it with braces in whole file. So I updated code style to always add braces for if/else statement. In Idea go to:

    Settings -> Editor -> Code Style -> Java -> Wrapping and Braces (tab)

    Find "'If()' Statement"/"Force braces" and change value from "Do not force"(default) to "Always". Press ctrl + alt + L to reformat your file and curly braces would be added. settings

    0 讨论(0)
  • 2021-02-03 17:49

    Add "Control flow statement without braces" to inspection settings. Then run inspection, select them in the list and then select "Apply Fix 'Add braces'".

    It just saved me a whole days tedious work!

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