How to actually learn vim motions (at least for me)
table of contents
What is Neovim/Vim motions? #
Yes, stupid question if you clicked on this post, but let’s at least get it out of the way: Neovim is a hard fork of Vim, which in itself is a clone / improved implementation of the vi text editor. Vim made vi better in several ways by adding modern features. These include syntax highlighting, chained undos and visual highlighting.
Neovim builds on top of this and adds even more features focused on customizability and adds a Lua scripting engine, more powerful API integration for said scripting engine, and recently, a native plugin manager called vim.pack.
Vim motions is what makes vim/vi/neovim… well… vim-y? Vim motions are a set of semantic keybinds which, when mastered, lets you edit and navigate text close to the speed of thought entirely from your keyboard, no mouse! Vim motions is what makes vim/v/neovim stand out and is generally considered quite hard to learn and almost impossible to master.
Okay but why would I learn vim motions / Neovim? #
You don’t have to! It is completely fine to use a more intuitive code editor such as Zed or VSCode. The thing that makes the 3 vi’s so special are these motions, but they can be hard to learn, speaking from experience. But the bonus they give when you get used is immense, they can make you able to type, debug and write code stupidly fast compared to other editors!
If you are interested in a simple code editor that just works out of the box, then maybe Neovim isn’t for you, and you should consider other alternatives like Zed, VSCode or the JetBrains Suite. But if you are like me, and love tinkering and learning new stuff, Neovim is heaven! Because of Neovim’s extensive ecosystem of plugins and scripting engine, it is incredibly customizable down to every character.
If you are interested in my setup specifically, you can find it on my tangled. It is a from-scratch written config, but I highly encourage you to write your own! If you aren’t up for writing your own config from scratch, then that is completely fine as well. There are a lot of premade configs out there, like LazyVim and NvChad.
Okay, but how do I actually learn vim motions then? #
What most people I’ve heard have said #
I’ve seen a lot of people just saying “use Tutor” or “look at a cheatsheet”. But in my opinion, these are incredibly wrong. This, alone, won’t teach you anything in the long term and you will be forever stuck navigating with hjkl or the arrow keys. Okay, maybe that’s an overexaggeration but at least for most people this will be true in the long term.
So what is the right way to learn? #
This may sound weird, but start with Tutor! Now I’m not saying that you should use only Tutor, like some others I’ve seen online. I am just saying that it’s a great start to learn the basics of navigation. After you have gone through Tutor a couple times, I would recommend doing a mix of the following 3:
- Vim-Adventures.com: Vim Adventures is a rpg-esque puzzle game where you use vim motions to move around, and unlock more actions/motions/keyboard keys as you progress in the game. It makes use of clever obstacles and such to make you have to use all keyboard keys you have unlocked and forces you to utilize them, not just spam the arrow keys. It teaches you in a very engaging and fun way.
- Vim-Be-Better: Vim-Be-Better is an improved fork of Vim-Be-Good, a nvim plugin developed originally by ThePrimeagen and lets you access several minigames with difficulty levels that makes you practise navigation, text manipulation and more via vim motions.
- Actually coding: Yes, learning vim motions is probably going to speed up your development process by a noticeable amount, but that doesn’t mean you need to learn it all before you start coding! The best way to learn vim motions in my opinion is to just start coding. If this means that you spam arrow keys, then so be it! While the 2 options above will teach you the more general motions like w/b/e, c/ciw etc, this will teach you the more niche combinations that you actually use, because what I want you to do when coding is find something you do often, and just google if vim motions can make it faster. For me that included stuff like selecting an entire file (ggVG), replacing a line of code with yanked text (Vp) and much more.
If you combine all these methods you will learn motions not only a lot faster than when looking at a cheatsheet, you will also, thanks to method 3, learn the motions you will actually use. This will also allow you to, and feel comfortable to, still code while learning. I’ve come across way too many people that don’t learn vim/nvim just because they obsess over learning every single motion for a week straight and then quit because they didn’t get anything done in that time.
Final thoughts #
I guess to summarize what I am trying to say, don’t just read off a cheatsheet or try to force everything down your own throat from the start. Instead, create a mix of both fun (Vim-Be-Better/Vim-Adventures) learning of the basics and actually productive and more focused learning that will actually help you (actually coding and searching).
Also, to add, I am nowhere near being good at utilizing more advanced chains of motions, and even I feel like I overutilize my arrow keys a bit, and you probably noticed that if you are more experienced and raised an eyebrow when I said that “ggVG” was a “niche combination”. But I don’t think I am writing this for people who are more experienced, but for newbies, people who were like who I was a couple weeks ago and only ever used arrow keys, a/i and escape.
I am actively learning more and more vim motions but this is what I have been using so far (and still am!) and it has been absolutely awesome. I can even say that in my experience, this has been the better way to learn. Because yes, I have been told to “just use Tutor” before and it has discouraged me from learning nvim several times. When I finally decided to bite the bullet one more time and migrate to nvim a couple weeks ago, I, instead of listening to others, chose this technique, and it clearly shows because for the first time, I’ve used nvim as my only text editor for several weeks and even completely uninstalled VSCode from my system.