We spend most of our days in front of our computers. And since you are reading this, you are probably spending most of your time inside your IDE (which is Android Studio / IntelliJ).
To navigate around in your source code you probably use both your keyboard and your mouse. But the constant switch between mouse <-> keyboard can be annoying and time consuming.
You've heard about those mythical engineers that don't have to use the mouse at all. Maybe you've even seen one. But you said that this is not for you. You can't learn all those keyboard shortcuts. Your mouse is enough for you.
Fear not. The truth is that navigating in your source code without a mouse is not that hard and the shortcuts are not that many. Trust me, I've been there not wanting to leave my mouse for some stupid keyboard shortcuts. The truth is though that it can help you to be more productive and express faster your thoughts in code.
It's not that you will never use the mouse, but you will use it less. I am not an expert myself, but I enjoyed the transition to a using-the-mouse-less world.
You might have heard vim, one of the oldest and most popular command-line text editors. It's described as "a highly configurable text editor built to make creating and changing any kind of text very efficient". And it delivers on its promise.
In Vim, there are 2 modes: command mode and insert mode. In command mode, you don't edit the text but you move around (navigate). In insert mode, you enter text, and is the regular text-input mode that you know and love.
IdeaVim is an IntelliJ plugin for "porting" some of Vim's features into Android Studio / IntelliJ. Not everything is there, but the most important ones necessary for navigating around your source code fast and efficiently are there.
A bonus of learning these shortcuts is that you can use them in regular vim that can be found installed in every Unix/Linux OS (including macOS).
Go to Preferences -> Plugins -> Marketplace -> Search for "IdeaVim" -> Install.
To switch between insert and command modes you use
i. I repeat: command mode to move around, insert mode to edit/insert text. The rectangular cursor indicates that you are in command mode. The regular cursor means you are in insert mode.
- Command mode -> Insert mode:
- Insert mode -> Command mode:
- Move up:
- Move down:
- Move left:
- Move right:
More advanced navigation
- Go to the beginning of the next word:
- Go to the end of the next word:
- Go to the next block of code / method / paragraph:
- Go to the previous block of code / method / paragraph:
- Go to the first character of the file:
- Go to the last character of the file:
- Search for text (case-sensitive):
/(enter text + hit enter)
- Find the next occurrence of the last search term:
- Find the previous occurrence of the last search term:
- Delete current line:
- Add a new line below and switch to insert mode to insert text:
- Add a new line above and switch to insert mode to insert text:
These are just the tip of the iceberg. There are so many shortcuts in vim. You can take a look and see what's more convenient for your work type. But don't be intimidated. Give it a try, resist your initial urge to revert to your comfortable usual keyboard+mouse setup, and you will soon get used to moving around using the keyboard. Happy coding!