"Just two small items left."

Magic trick #6: Surround with.

"For example, suppose we want to wrap some code in a try-catch block. IntelliJ IDEA also has a key combination for this: Ctrl+T.."

"Just select some code, e.g. the same println method in the printAddress method — and press Ctrl+T. Here's what we get:"

Code style - 1

"Here's a menu with a list constructs we can use to wrap the selected code."

"You can wrap it with a loop (item 3), or a try-catch (item 6), and much more."

"Currently, we want to surround the code in a try-catch, so we'll choose item 6."

"The numbers and letters on the left are hotkeys. Simply pressing 6 will select the desired menu item. Of course, you can also use your mouse if you really want to."

"Here's the result:"

Code style - 2

"We selected the code, pressed Ctrl+T, pressed 6 and — voila! — the code is wrapped, and everything's beautiful."

"Yeah, that's really handy."

Magic trick #7: Reformat code.

"Sometimes, unnecessary indents and spaces are introduced as code is edited. On the other hand, sometimes there aren't enough of them. This makes the code ugly and nearly unreadable."

"For example:"

Code style - 3

"IntelliJ IDEA lets you customize code styles: indents, indent sizes, whether {'s should be moved to new lines, and so on."

"This it very easy to do. Select some code you want to reformat (don't select anything if you want to format the entire current document). Then press Ctrl+Alt+L."

Code style - 4

"The current file is selected by default, but you can select 'selected text' or all files in the current folder. Then press Enter and enjoy the result."

"For me, the above example ended up looking like this:"

Code style - 5

"The indentation was corrected on each line of code where spaces needed to be added. This code is prettier and much easier to read."

"Oooh. I love when everything is pretty. Especially code. For us robots, love of beautiful code is in our blood."