IntelliJ’s settings worth changing
IntelliJ is a very complex tool, with thousands of different settings, templates, customisations… Possibilities are endless, but there are a few check boxes that I would consider quick wins – changing them won’t take much of your time, but it can make a big difference to the way you work.
Asterisk imports
Although this one falls into code style, this is one of the settings that I would consider mandatory. Asterisk imports in Java are bad and can cause you (or your colleagues) a lot of problems.
Look at the screenshot below – you should change both numbers in the centre to something larger than default 3 or 5. Also, just below there is a list of exclusions, and even though by default it contains Java Swing packages that you might not use, it’s worth clearing it too.
New line character at the end of file
By definition, a line is a sequence of characters followed by a new line character. And although majority of modern text editors will handle it, some unix tools might simply ignore the last line in your file. See this StackOverflow question for more details. That’s why you should make IntelliJ to always add it, so that you don’t have to remember about it.
Clipboard history size
Clipboard history is one of my favourite features, as I can copy multiple things and then pick what I want to paste by pressing CTRL + SHIFT + V
. By default it stores only 5 items copied and if you want to rely on this feature, I would recommend to increase it to at least 20.
Update January 2020: Note that in the newest IntelliJ (version 2019.3) this option is no longer there – it seems that the limit has been removed completely.
Highlight edited unsaved files
You might have a habit of hitting CTRL + S
in every file, without realising that this shortcut in IntelliJ actually saves all edited files. Also, IntelliJ saves files periodically and on certain events such as window focus lost. There is a setting that will show an asterisk next to the filenames that were edited but not saved.
Code folding
Might sound like a code style, but it’s not. IntelliJ by default will collapse certain blocks and expressions – such as imports, annotations, comments, one-line methods and so on. I like to see the code as it really is, but of course it’s a matter of preference. If you would like IntelliJ to not display you different code than what was actually committed, simply uncheck all the boxes below.
Displaying parameters names
In one of the recent versions of IntelliJ they added a new setting, enabled by default, that displays parameters names within the code. It looks like code, but it’s not selectable text. It is another case where IntelliJ decides to display something different than the actual code. It’s again a matter of preference – you might like it, but I prefer to hit CTRL + P
when I need to see the parameters names (which will give me also their types and highlight the current parameter depending on the caret’s position).
Update January 2020: Note that in the newest IntelliJ (version 2019.3) this is no longer in Editor -> General -> Appearance
but in Editor -> Inlay Hints -> Java -> Parameter hints
.
File headers
Moving on to templating, which deserves its own blog post, there are a few that can be quickly changed. One of them is the file header, that will add a comment at the top of every Java class you create, with your system username and current time. These comments don’t add any value and can be simply deleted. And rather than doing this manually for every file you create, you can just modify the template to not parse the file header in the Java class. You can also modify the header itself to be empty.
Try-catch for checked exceptions
When something throws a checked exception, you can hit ALT + ENTER
and ask IntelliJ to wrap it into a try-catch block. I am one of those who believe that checked exceptions should not exist, because in majority of these cases you just want to re-throw it. However, IntelliJ will not wrap it into a RuntimeException
, but print a stack trace instead, requiring you to manually change it afterwards (if you remember). This is another template that you can quickly modify:
Searching recently opened projects (and customising menu bar)
If you have a lot of projects that you work on, I mean really a lot, you probably noticed that if you select “Open Recent” in IntelliJ, the list doesn’t fit on the screen. “Open Recent” also has a useful/annoying feature of sorting the projects by time when they were last open. So when you want to open something that you didn’t work on for a couple of months, you have to spend some time on scanning this list.
However, at the bottom of this list there is a magic button “Manage Projects”, which will show you recent projects in the pop up where you can type to search for what you want. The problem is that getting to this button takes too many clicks and it can be also displayed off screen, if the list of recent projects is too big. Luckily, you can add this button somewhere else! Navigate to Menus and Toolbars, pick some existing button, hit “Add After…”, select “Manage Projects…”, click “OK” – and now you have “Manage Projects” button in additional place.
Reopen last project
Did your IntelliJ crash (or you had to kill it) or your machine restarted? Now, when you open IntelliJ, it will take 15 minutes to open these 10 projects that you had open. This can be disabled, so that when you open IntelliJ, you have to pick which project you want to open (you get a nice list of recent projects).
TL;DR
Settings -> Editor -> Code Style -> Java -> Imports -> Class count to use import with '*' -> set to 999 Settings -> Editor -> Code Style -> Java -> Imports -> Names count to use import with '*' -> set to 999 Settings -> Editor -> Code Style -> Java -> Imports -> Packages to Use Import with '*' -> remove all Settings -> Editor -> General -> Other -> Ensure line feed at file end on Save -> check box old: Settings -> Editor -> General -> Maximum number of contents to keep in clipboard -> set to 20 new: setting removed, clipboard size is unlimited (?) Settings -> Editor -> General -> Editor Tabs -> Mark modified tabs with asterisk -> check box Settings -> Editor -> General -> Code Folding -> uncheck all old: Settings -> Editor -> General -> Appearance -> Show parameter name hints -> uncheck box new: Settings -> Editor -> Inlay Hints -> Java -> Parameter hints -> uncheck box Settings -> Editor -> File and Code Templates -> Files -> Class -> remove line: #parse("File Header.java") Settings -> Editor -> File and Code Templates -> Includes -> File Header -> remove all lines Settings -> Editor -> File and Code Templates -> Code -> Catch Statement Body -> replace with: throw new RuntimeException(${EXCEPTION}); Settings -> Appearance & Behavior -> Menus and Toolbars -> select "Main menu/File/File Open Actions/Close Project" -> Add After... -> select "All Actions/Main menu/File/Open Recent/Manage Projects..." Settings -> Appearance & Behavior -> System Settings -> Reopen last project on startup -> uncheck box
Posted on October 16, 2018, in Development. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0