How to surround code by curly braces in IntelliJ IDEA? Is there any keyboard-shortcut for such operation?
Simply select the code block to surround (don't forget to use Ctrl + W to increase the current selection) and then press Ctrl + Alt + T (or right-click the selection and select Surround with… from the menu).
Always include curly brackets. Always include curly brackets, even for one-line if statements or for loops. Java has a "feature" which allows you to omit curly brackets when writing if statements, for loops, or while loops containing only a single statement.
Select the code, and then either: Choose Code > Surround With. Press Ctrl-Alt-T.
If you choose Code | Reformat Code from the main menu or press Ctrl+Alt+L , IntelliJ IDEA tries to reformat the source code of the specified scope automatically. For more details on how to reformat, or exclude files from formatting, refer toReformat code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With