How to surround code by curly braces in IntelliJ IDEA?

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

enter image description here

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.


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


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!