Hacker News new | ask | show | jobs
by LeonM 2243 days ago
Ctrl-alt-L (cmd-alt-L) is my all-time favorite. It reformats the code consistently. It's the first thing I do when I start work on a new codebase, and the last thing I do before a commit.

No need for endless discussions on which style is best, as the IDE allows you to set the preferences on a per-project basis. It can also read editor config dotfiles so you can use code formatting consistently throughout a team.

4 comments

+1 on this one.

And yes, there is no such thing as best style, so at the end of the day it boils down to personal preference. I find myself using the ctrl+alt+l often but before i commit any code i carefully go over everything and change it to my particular liking(which is often close enough to what the IDE has done so I rarely spend more than a minute or two on it). Also the reason why I haven't bothered to dig deep into the preferences.

A potential next step if it fits your workflow is to create a macro triggered by save. I have one that optimizes imports, reformats code and do silent code cleanup.
There is already an intellij plugin called Save Actions which does this (import, reformats, and some extra stuff, like adding final to variables wherever possible(optional off course).
Oh that's nice! Thank you.
IntelliJ IDEA's commit dialog already offers checkboxes to "optimize imports" and "reformat code" ("run gofmt" in case of Go), among others.
I'm a JS dev, and Webstorm integrates perfectly with ESLint and Prettier. it takes like two clocks to set up a file watcher on a project and never have to worry about formatting your code again
Thank you! I've been using Resharper and IntelliJ (Rider, etc) forever and I somehow I managed to miss that shortcut.