I learnt how to work with my intelliJ / Android Studio without using my mouse and what I most like is that I spend less time executing the actions that I need, like refactoring, managing files, etc and I am more focus in what is really important, the code.

Don’t let yourself get distracted

What do you prefer a clean and minimalistic desk without nothing to get distracted or a desk full of papers, cables and other stuff? It’s not me, as you can see there are many articles on the internet talking about why decreases the stress. If you don’t use something, just clean it. So, I try to apply this to my IDE. The first thing that I find useless are the tabs. I don’t need tabs because I find is horrible to navigate between them, as soon as you start navigating between files in a project you get plenty of them and you get lost. So, Is there any other solution to navigate? There are some Alternatives like:

Short desc Shortcut Long desc Recent files Ctrl + E ⌘ + E As the name says is a list of all recent files that you navigated, is my preferred way to navigate between files Quick switcher Ctrl + Tab ^ + Tab The same as before but is quicker because you save one keystroke Jump to navigation bar Alt + Home ⌥ + Home Shows in a popup the top bar and you can navigate between packages / files. Useful when you want to navigate to a file that you already know that is in the same package

So now, that we have a way to navigate between files, we can remove the tabs. To do that, we can go to: Settings > Editor > General > Editor tabs > Placement none .

Another thing that we can get rid of is the menus at the sides, by pressing the following button at the bottom left of the IDE:

And then we can access again the side menus with the keyboard:

Short desc Shortcut Long desc Show side menus Alt + desired num ⌘ + desired num Shows the side menu for the num, for ex. 1 is for the project structure Show side menu bars Alt + Alt (maintain) ⌥ + ⌥ (maintain) Shows the side bars where you can see the numbers of the menus Hide all shown menus Ctrl + ⇧ + F12 ^ + ⇧ + F12 Completly hide all the side menus

With that configuration our IDE becomes cleaner, something like this:

If you want to keep it minimal you can activate the distraction free mode: View > Enter distraction free mode > . This mode is my preferred way to work, is relaxing because you get rid of most of the useless buttons of the IDE.

I don’t know how to get rid of the main bar menu, but that will be awesome 🙂 I think other OS like OSX and Windows the behaviour of the distraction mode is different, so if in your computer does not look exactly the same, that would be the reason.

Shortcuts

Obviously, we need to know how to perform most of the common actions with the keyboard. If we get lost anytime don’t use the mouse! Use the actions shortcut:

Short desc Shortcut Long desc Show actions Ctrl + ⇧ + A ⌘ + ⇧ + A Shows a dialog where you can search actions of the IDE, so for example if you want to debug and you forgot the shortcut, just type debug

This is the first shortcut you should learn, and after that this is a relation of the most common one or at least that ones that come to my mind in my current workflow:

Editing

Short desc Shortcut Long desc Add selection for next occurrence Alt + J ^ + G Imagine that you have 5 lines containing Log.d and you want to change it to Log.e instead of change it manually, select with your cursor “Log.d” press this shortcut and you will see that the column mode is enabled and you will be able to modify that 5 lines at the same time. Surround with Ctrl + Alt + T ⌘ + ⌥ + T Surrounds the current line with a block of code like if, try/catch, etc… Enable column mode Alt + ⇧ + Ins ⌘ + ⇧ + 8 When you are in column model you can modify multiple lines at the same time. Create a class in the current directory Ctrl + Alt + Ins ^ + N Organize imports Ctrl + Alt + O ⌘ + ⌥ + O Removes the unused imports of the current file Format code Ctrl + Alt + L ⌘ + ⌥ + L Reorganizes and formats your current file Generate Alt + Ins ⌘ + N Code generation like contructors, getters, setters.. Extend selection Ctrl + W ⌥ + Up Extends the selection to line/block/method/class.. Shrink selection Ctrl + ⇧ + W ⌥ + Down Shrinks the selection to line/block/method/class.. Move statement up Ctrl + ⇧ + Up ⌘ + ⇧ + Up Moves the current statement up, for ex. if it is a method, it will move above next method Move statement down Ctrl + ⇧ + Down ⌘ + ⇧ + Down Moves the current statement down, for ex. if it is a method, it will move above next method

Navigating

Short desc Shortcut Long desc Go to next error F2 F2 If there is any error, place your cursor in the next one Go to previous error ⇧ + F2 ⇧ + F2 If there is any error, place your cursor in the previous one File structure Ctrl + F12 ⌘ + F12 Navigate between methods / fields in the same file Jump up hierarchy Ctrl + U ⌘ + U Navigate to the super class while inside a file Implemenetations Ctrl + Alt + B ⌘ + ⌥ + B Navigate to a child class while inside a file Quick definition Ctrl + ⇧ + I ⌘ + ⇧ + I Place the caret in a variable for ex, press the shortcut and you’ll see in a popup the definition Show method parameters Ctrl + P ⌘ + P When fulfilling method parameters, press this to see all the parameters needed for this method Next/previous splitter NO SHORTCUT NO SHORTCUT I don’t know why there is not a default shortcut for this one but is really useful, when pressing and having one or more splitters (editors) you can switch between them Hide method implementations Ctrl + ⇧ + - ⌘ + ⇧ + - Are your method names readable enough? Collapse them and you should be able to understand what is your method doing. I find it pretty useful for testing, the testing method names should be enough to understand what is going on with your test Show method implementations Ctrl + ⇧ + + ⌘ + ⇧ + + The same as before but to expand it instead of collapse

Refactoring

Short desc Shortcut Long desc Refactor this Ctrl + Alt + ⇧ + T ⌘ + ⌥ + ⇧ + T Is like the master command, if you forget the others just use this Move F6 F6 Move class from this package, can extract also an Inner class Change signature Ctrl + F6 ⌘ + F6 Changes the signature of a method, class, etc… Extract variable Ctrl + Alt + V ⌘ + ⌥ + V Extracts a local variable where you have the cursor, if you can extract various thing it will show a popup to select Extract method Ctrl + Alt + M ⌘ + ⌥ + M Extracts a method with the selection Extract field Ctrl + Alt + F ⌘ + ⌥ + F Same as extract vairable but this time creates a field Extract constant Ctrl + Alt + C ⌘ + ⌥ + C Same as extract vairable but this time creates a constant

Debugging

Short desc Shortcut Long desc Toggle breakpoint Ctrl + F8 ⌘ + F8 Enables or disables a breakpoint in the current location Step into F7 F7 While debugging you can select step into to go debug the implementation of that method Next step F8 F8 While debugging if you select next you will advance to next instruction without going inside of the implementation of the current one Continue F9 ⌘ + ⌥ + R Continues to the next breakpoint if there is any, if not let the program cotinue as normal

Git

Short desc Shortcut Long desc VCS Actions Alt + ` ^ + V Shows a popup with the most useful actions for version control Commit Ctrl + K ⌘ + K Commits the current changes Push Ctrl + ⇧ + K ⌘ + ⇧ + K Variation of the previous one, pushes changes Revert Ctrl + Alt + Z ⌘ + ⌥ + Z If we are in a git changed line, it will revert only this block, if we are in a changed file it will revert the whole file

Running code

Short desc Shortcut Long desc Debug ⇧ + F9 ^ + D Runs with the debugger attached Debug configurations Alt + ⇧ + F9 ^ + ⌥ + D Launches a popup with the debug configurations Run ⇧ + F10 ^ + R Runs the app with the current configuration Run configurations Alt + ⇧ + F10 ^ + ⌥ + R Launches a popup with the run configurations

Live templates

Another essential tool for my toolbox is the live templates which I find particularly useful to not have to write loops. Why would you type tedious index based loops yourself when you can do so just by typing “fori” and just fill the gaps, the same thing goes for iteration loops which can be shortened up by just typing “iter”.

There are plenty of live templates available on intelliJ for many different files (Java, Android, XML, JavaScript, HTML, etc..) and you can even create your own, so the possibilities are endless!

The menu to check and create live templates can be found under Settings > Editor > Live templates

Postfix Code Completion

Let’s conclude the article with the cherry on the cake, postfix code completion. Postfix code completion will further boost your productivity by transforming an expression to another one based on the postfix applied and the context of the expression. Two of my favourite ones for boolean expressions are “.not” and .if” which will negate and wrap the expression as we go. Another two which are also really useful are “.null” and “.notnull checks the expression for null and not null respectively.

The list of all postfix completions can be found at Settings > Editor > General > Postfix Templates but I’ll include a screenshot so you can quickly have a look at them. Also, note that postfix completion suggestions are part of the basic completion, so we can easily autocomplete them and save a few extra types. To check all the possible postfix completions available in the current caret context, use Ctrl + J ( ⌘ + J for OS X).

Do you type fast enough?

You are using your keyboard for many years I’m pretty sure about that, but, do you know how to use it properly? I’m at that point that I realised that I’m not using enough fingers, is not that I don’t type fast, is just that I can type faster if I practice and I learn the basics of how to touch typing. To do that I proposed to myself practice during 30 min every day. To test my progress I discovered: Type racer a simple game to practice and also measure your current words per minute (wpm).

A good keyboard is something that can help you to type faster. I bought a mechanical keyboard some time ago and I’m getting used not only to the mechanical keys also to the layout of that keyboard. To be more comfortable with my keyboard I switched some keycaps, is my tool and I really love to have something that looks nice! I discovered also that I feel more comfortable using Cherry MX brown switches to type. This is a photo of my current keyboard setup:

My filco keyboard now looks properly :)) pic.twitter.com/uE5HGttJm1 — Christian Panadero (@PaNaVTEC) 15 de marzo de 2016

Conclusion

I spend many hours writing code, is necessary for me to have a good-looking desk/OS and be comfortable with all the tools that I use, as well as the carpenter knows how to handle the hammer, you as a developer need to know how to use your tools properly and know them as the palm of your hand.

References and further reading