A small collection of IntelliJ tips and tricks for getting more out of your day or simply doing the same amount for work with less effort.
1. Install the IntelliJ Go plugin from here
Enough said.
2. Project structure
3. Editor defaults
This one won’t necessarily speed you up but it should make life a little more comfortable.
Use the “Code Style” preferences, make a custom scheme and set all the tab and indent settings to 4. This will stop the code jumping around once it’s formatted by the regular go tools.
4. Testing (and formating)
While I am not a TDD fanatic, I do like to run my tests quite often. I use the “Run Test” feature in IntelliJ to also format and fix the imports. To do this:
5. Live Templates
This is perhaps the best way to make yourself more efficient (excluding learning and using keyboard shortcuts). Live Templates allow you to specify “shortcuts” that you can quickly turn into blocks of code.
For example if you type “forr” and press Tab it will insert:
The thing most likely to trip you up when creating your own Live Templates is the “Applicable in Go: xxx” setting at the bottom of the panel (see below).
Generally, to insert “top level” elements like structs & interface definitions or functions then use “Go file”. To insert chunks of code inside a function use “Go block”. I have not personally used the other two options.
Here are some others that you might like:
“printf”
“test”
“tdd”
I like to use the Testify lib for my tests so I find these particularly useful.
“ae”
an
ann
at
Happy Coding!
If you like this content and would like to be notified when there are new posts or would like to be kept informed regarding the upcoming book launch, please join my Google Group (very low traffic and no spam).