3 ms·
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
by LeonM 7y 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.
- GiorgioG 7y agoThank you! I've been using Resharper and IntelliJ (Rider, etc) forever and I somehow I managed to miss that shortcut.
- axegon_ 7y ago+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.
- wmfiv 7y agoA 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.
- enitihas 7y agoThere 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).
- wmfiv 7y agoOh that's nice! Thank you.
- noisem4ker 7y agoIntelliJ IDEA's commit dialog already offers checkboxes to "optimize imports" and "reformat code" ("run gofmt" in case of Go), among others.
- schwartzworld 7y agoI'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