Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to surround code by curly braces in IntelliJ IDEA?

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

like image 396
Pavel Avatar asked Mar 18 '13 11:03

Pavel


People also ask

How do I surround the code with if for Try Catch IntelliJ?

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

How do you write curly braces in Java?

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.

How do you surround the code with if for try catch?

Select the code, and then either: Choose Code > Surround With. Press Ctrl-Alt-T.

What does Ctrl Alt l do in IntelliJ?

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.


1 Answers

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.

like image 57
Ajang R Avatar answered Oct 02 '22 21:10

Ajang R