My Journey Learning Vim Motions with IntelliJ IDEA

How Vim motions can help your code editing skills and unlock some cool new tech DLC.

Fabrício Yamamoto
WAES
8 min read6 days ago

--

The truth is that, once in a lifetime, every developer is afraid of Vim.

I was afraid of Vim when I was bravely learning git and my commit accidentally triggered that inequitable black and intimidating screen, or when I had to SSH that old server and change some text, or even when I decided to learn how to use it properly for the first time and failed miserably.

Life goes on, and the beginner learns; now he knows how to exit Vim, how to press insert to make the edition available, and how to survive in this intimidating environment… And that’s all.

But now, after years of surviving, I finally set up a path to mastering Vim motions and using it as my main way to code. There’s still much to be improved, but this summarizes my past experiences during the last three months.

Touch Typing

If you are already a touch typer, don’t bother and just skip this section.

In my 20 years of experience typing on a computer, I never really cared if I looked at the keyboard while typing; I just wanted to go fast, and modestly, my speed in this typing style is pretty good. The problem is that I didn't use all my fingers, and I would need to constantly rearrange my hands after typing a long word or phrase.

It's been a huge internal battle for me to fix this issue that I've been cultivating for 20 years, but luckily, there is a website where it's possible to practice touch typing in a nice gamification way. It's called TypingClub, and it really helps me use the correct fingers for each letter and keep track of the home row of the keyboard.

My TypingClub exercises.

I am not saying you must master touch typing if you want to learn Vim motions, but if you want to use it as your main text editing style, it’s one of the most important things to learn. With Vim, one becomes keyboard-dependent and wants to write fast commands, use symbols and function keys to achieve results efficiently and transform the keyboard into an extension of your body.

Vim Motions

This is when things start to get interesting. In Vim, motions are commands that move the cursor throughout the text. Mastering these motions is essential for efficient navigation and editing. By combining motions with operators (like d for delete, y for yank, c for change), you can perform powerful text manipulations with minimal keystrokes.

The most basic and most used motion was also the most difficult motion to master, which are the basic movements. Instead of using the arrow keys, Vim uses hjkl keys. The reason is pretty simple: the creator's keyboard had arrows on these keys.

ADM-3A keyboard’s hjkl keys with arrows.
  • h : Move left by one character.
  • j : Move down by one line.
  • k : Move up by one line.
  • l : Move right by one character.

It took me 2 months to get comfortable with it, but after you get this right and moving around the text becomes natural, all the other things get easier.

The second most important motions are the word-based movements

  • w : Move forward to the beginning of the next word.
  • b : Move backward to the beginning of the previous word.
  • e : Move forward to the end of the next word.

The third most important is the line-based movements

  • 0 (zero): Move to the beginning of the current line.
  • ^ : Move to the first non-blank character of the current line.
  • $ : Move to the end of the current line.

By knowing these motions, it’s already possible to move around and do some nice commands, such asdw to delete a word or y$ to yank from the cursor to the end of the line. Mastering these combinations is essential for fast and precise editing in Vim. You can also check these 50 useful Vim commands.

Beyond motions, Vim also has some modes, such as Normal, Insert, Select, Replace, and Command. These modes are also integrated with the basic motions we’ve seen here before.

Enough said, it’s a HUGE topic, for the newcomers to Vim, I would recommend typing vimtutor in the terminal and performing the Vim tutorial at least once before messing with IdeaVim.

IntelliJ IDEA + IdeaVim Plugin

All my journey started with this plugin in mind so I could use it during work hours. In the beginning, it was all about practicing Vim motions to edit some text. It was fun because sometimes editing a text was like a puzzle that you had to solve by using some “correct” keystrokes. At this phase, it is completely normal to just stop and think for some time about which key to press and also search for some tips online. (And also check some @vim_tricks)

Honestly, learning vim motions is very unproductive in the beginning, and it takes a good amount of time to get used to it, so it’s totally fine to use the mouse to scroll, edit, and select some text while working. This plugin also has mouse support, and most of the “normal” editing shortcuts are still available. As one gets more used to it, using the mouse for text navigation should be avoided.

It's important to say that it’s highly advised to remap your ESC key to an easier-to-reach position. I personally like using it remapped to my Caps Lock, and you can do this in MacOS pretty easily.

IdeaVim Magic: Customization

Vim is not only good for its motions but also for being highly customizable. After mastering the basic Vim motions, it’s time to start creating new configurations and bindings to mess with our IntelliJ, and this is done by customizing the .ideavimrc file.

This part can be a bit tricky, and that’s why there’s this whole book about it, but because only basic things are being mapped, it will basically be writing a command and executing an action. For context, they could be divided in some categories:

Recursiveness

  • map : Mapping can be recursive
  • noremap : Mapping avoiding recursive

Modes

  • map and noremap: Mapping will be applied in any mode.
  • nmap and nnoremap: Mapping will only be applied in Normal mode.
  • imap and inoremap: Mapping will only be applied in Insert mode.
  • vmap and vnoremap : Mapping will only be applied in Visual mode.

So, for example, if the Normal mode is active and the screen needs to be split vertically: nnoremap <c-\> :action SplitVertically<CR> and so on…

Does mapping to different modes add more complexity and things to remember? Maybe. Is it a problem? Not really…

Once you start using Vim often you won’t be thinking about the individual keys you’re typing any more. You’ll think: “delete a line” and not “press dd". Your fingers and brain will learn your mappings and the keys themselves will become subconscious. — Learn Vimscript the Hard Way

Here is where things start to get serious, and some time must be invested in creating good mnemonics for shortcuts and mapping them to make the workflow smooth and comfortable.

For example ctrl + \ could split the screen vertically while ctrl + — could do the same but horizontally, another example is using <leader>gm to open the git menu. In this case, the leader key is any key you want to choose as your leader key, I use space.

Here it’s possible to configure bindings for splitting the view, toggle zen mode, refactor, run the current code, change tabs, open the terminal, go to the upper method, and everything else that you would normally do in the IDE, but now using only the keyboard; there are many people sharing experiences in the internet, and trying to find mnemonics on their setup before using is advisable (also creating your own).

Another good thing about customizing, mapping keybindings, and getting tips online is that it’s always possible to discover new things or IntelliJ actions that were previously unknown or underused but could be helpful.

Beyond IntelliJ

In my opinion, Vim is not worth it if its only use is to edit some text; there are plenty of good IDEs and text editors that have their own shortcuts and ways of doing things. The good thing about Vim configuration is that it is highly customizable, and you can bind your own shortcuts and use them in every different place that you want to code.

That said, by learning Vim motions, getting used to binding creations, and hitting keystrokes comfortably, you can relate these commands to other environments that are not only related to code or text.

For example, I started using a plugin called Vimium, so now I can even browse the internet using only vim related bindings. I also have installed a MacOS tile manager called yabai, that basically let’s me move windows and changing focus on applications on my screen by only using hjkl and some other function keys altogether.

There are many other CLI based applications that make usage of Vim keybindings, in fact, some of them are created with it in mind. Honorable mention to the Brazilian NeoVim and the new modern text editor called Zed, which is also very customizable and well-built for Vim motions.

Sharing configuration

After so many customizations inside .ideavimrc files (and others), it would be a shame if your configurations were lost. That’s why whoever messes with tons of customization has always a dotfile repository to backup and save all their stuff. A good way of managing it is by using Git + GNU Stow and taking care not to share too much (SSH files 👀). If you're somehow curious, here are my configurations.

Conclusion

Which was only meant to be a fun activity to prove to myself I could handle editing some text using Vim actually opened some doors for many other applications and a community that I didn’t know that was so big. Learning something new is always nice.

I also figured out that touch typing can become a bit painful after some time; maybe I am not very used to staying with my hands so close to each other for so long. Now I kind of understand people who buy those split keyboards, and I think this will be my next step too.

Fancy shit. (ZSA Moonlander)

I hope my experience was helpful somehow and could give you some insights. See you around. :)

Do you think you have what it takes to be one of us?

At WAES, we are always looking for the best developers and data engineers to help Dutch companies succeed. If you are interested in becoming a part of our team and moving to The Netherlands, look at our open positions here.

WAES publication

Our content creators constantly create new articles about software development, lifestyle, and WAES. So make sure to follow us on Medium to learn more.

Also, make sure to follow us on our social media:
LinkedInInstagramTwitterYouTube

--

--