Taking your hand off the keyboard and putting it on a mouse is an expensive operation. It costs a lot of time and energy and although it sounds like a joke I am actually serious.
Compared to having your hands lying still and just tapping fingers, any whole-arm movement suddenly feels like a helluva work. Maybe I’m that lazy, but actually just moving my right hand to reach the arrow keys bothers me somewhat.
Also, consider how much slower it is to grab a mouse and point the cursor to a tight space right between two characters where you want to do some editing. Or tap the arrows like a hundred times to move the caret to a place few words away.
As programmers, we do those things enough times a day for all those inefficiencies to be a big deal.
One map to rule them all
Both IDEs and glorified text editors help us avoid paying the hefty price of excessive arm movement with keyboard shortcuts. The problem is that every tool comes with its own keymap, and if you’re switching between editors often, it becomes a problem.
So I’ve finally decided to pick my favorite shortcuts and apply them to all the tools I use. I am a long-time user of IntelliJ and now Rider, so my choice is based on their defaults. However, since I also regularly write in VS Code, I will focus on basic code editing commands that don’t require fully fledged IDE to be available.
I really suggest giving them all a try if you haven’t already.
Note on learning those shortcuts
Learning keyboard shortcuts in a new tool takes a while. There are always some commands that stick well, while some others stay in oblivion. Here’s what I think can help to master them.
Firstly, I like to think of commands in categories of function. Usually, those similar functions will be mapped somewhat symmetrically – just adding a modifier key brings us from one to another. It is best to learn those categories as a whole rather than shortcut by shortcut.
Pick one category. Try out each of the commands. Then tell yourself that you will be deliberately using them for the next few minutes of coding. Watch yourself and think ahead what are you about to do. You will be going against your habits now and it’s always a bit difficult. Do it a couple of times. Repeat the exercise the next day. Eventually, it will start happening automatically and you will no longer have to think about it. Your goal is to have your editing intentions translated directly to the new behavior.
My favorite command groups
So here are those basic code editing commands I like the most.
Inline caret movements, selects and deletes
Those are for moving caret left and right within the current line. It’s all very similar whether you intend just to move the caret, move and select everything from here to there, or to immediately follow it all up with hitting backspace or delete.
|Step||Caret||+ Select||+ Delete|
|character||left/right||shift + left/right||bksp/del|
|word||ctrl + left/right||ctrl + shift + left/right||ctrl + bksp/del|
|line beginning/end||home/end||shift + home/end||alt+shift+bksp/del|
Moving on to manipulating whole lines of code. I find myself editing something in the middle of a line and then immediately wanting to either delete it or start a new one pretty much all the time. It is very convenient to be able to do that with one keystroke regardless of where the caret is.
|Start new line||shift + enter|
|Start new line above||ctrl + alt + enter|
|Move line up / down||alt + shift + up/down|
|Duplicate line at caret||ctrl + d|
|Delete line at caret||ctrl + y|
|Select line at caret||ctrl + shift + y|
Go to commands
Another set of commands I find myself using all the time. Very handy when navigating large solutions with many directories.
|Go to class||ctrl + n|
|Go to file||ctrl + shift + n|
|Go to symbol||ctrl + alt + shift + n|
|Go to declaration||ctrl + b|
|Go to type declaration||ctrl + shift + b|
|Go to test||ctrl + shift + t|
Meta navigation functions
Among all the navigation functions the ones I hold the dearest are those allowing me to go where I was before or where I did my last edits. Thanks to those, I can quickly get on with whatever I was doing before going down the rabbit hole, which often results with a lot of opened files.
|Undo / Redo navigation||ctrl + alt + left/right|
|Go to previous / next occurrence||ctrl + alt + up / down|
|Go to last edit location||ctrl + shift + bksp|
Got any other code editing ninja moves I am apparently unaware of? Don’t hesitate pointing out my ignorance in the comment section. I will really appreciate it.