homeposts

Created: 8/13/2022

Zero to Hero Vim Tutorial

The goal of this post is to be a roadmap that can help someone with effectively zero vim or neovim knowledge work up to the full neovim-as-an IDE experience.

I won't try to persuade you to learn (neo)vim, but I'll just say that using (neo)vim brings me immeasurable joy each day, and I hope that everyone can experience the mind-tool connection that it provides. There are a lot of false prophets of vim who say it will make you faster or give you some other superhuman benefits. Vim can probably be a pathway to speed and throughput as a developer, but it can also be a subject of tinkering which ultimately slows you down!

To me, using neovim at its best feels like playing a musical instrument. It elicits a flow state and drives my focus through the day, but most of all, it just makes me happy. To that end, I hope that this guide helps you join me.

vim vs neovim

The first question for someone entering this space is, what is the difference between vim and neovim, and which one should I learn? For a quick overview, check out my post: vim vs. neovim

My Configurations

My vim config aims to be minimal and portable. There are some plugins, but there is also a single fully-portable common.vim file that can be scp'd onto to any remote machine to quickly bring a base-level of comfort.

My neovim config, on the other hand, has all the bells and whistles: fuzzy finder, live grep, integrated debugger, language support, dynamically inlined lint errors, intelligent syntax highlighting and folding, and more.

You can find each, with setup instructions, on my GitHub:

Transitioning to (neo)vim

In my view, it's best done as a three step process which I'll now lay out:

  1. Use a plugin for your current editor to learn the vim shortcuts
  2. Use vim itself with a minimal config
  3. Optionally, use neovim with an IDE-like config (if that's your cup of tea)

Step 1: Editor Plugin

The thing that killed me about trying to learn vim was trying to figure out how to navigate between files while also becoming comfortable with all of the many editing commands. I think that doing both of these things at the same time is overwhelming, and there's no reason to do that to yourself. Visual Studio Code has a vim plugin, and so does the whole jetbrains IDE family. Whatever editor you're comfortable with probably has one too, and it's a great place to start.

Most vim editor plugins will make your IDE modal in the same way that vim is, and give you the same keyboard shortcuts for manipulating text and moving between editing modes. However, editor plugins stop at the vim-text-editing experience (arguably the best part of vim). For all of your other development tasks, the IDE is still there for you in all the ways it normally is. This is like vim training wheels, and I it's fair to say that you will be much more successful with the real thing after the key mappings for regular editing become second-nature. To that end, there's no shame in honing your skills in this phase for three to six months.

Configuring Editor Plugins

Most of the benefit of editor plugins is that you can get started without going crazy on configuration, but I do have one suggestion.

Some people are bothered by needing to constantly reach for the escape key, including myself. If you are interested in mapping escape to some other key or key combination, now is a great time to do that. Personally, I map jk to <Esc>. You can achieve that with the VSCode vim plugin like this

"vim.insertModeKeyBindings": [
  {
    "before": ["j", "k"],
    "after": ["<Esc>"]
  }
],

If you want this behavior for vim and neovim, you can use this bash snippet:

mkdir -p ~/.config/nvim

config="inoremap jk <Esc>
tnoremap jk <C-\><C-n>"

echo $config >> ~/.vimrc
echo $config >> $XDG_CONFIG_HOME/nvim/init.vim

Beyond that, this is your opportunity to learn "the vim way," of editing text. Vim is like a programming language for text transformation – try to avoid creating excessive mappings unless you're certain that there is no other way. There are a ton of resources for learning these basics. I recommend starting by running vimtutor from the command line, which will open vim in your terminal with an interactive tutorial that you can follow along with. There are also tons of vim cheat sheets to help you. Good luck!

Step 2: vim

You already know the basics of editing text, but transitioning towards using "real" vim means that you're going to learn some more "meta" vim concepts. I have a dedicated post about vim "meta" concepts.

Step 3: neovim

Again, take a look at my neovim config and follow the readme instructions for setup. Take a look at my corresponding post, "My Neovim Config"

That's It!

Start with an editor plugin, start using vim and figure out how to "grok vi," and finally move onto a modern neovim setup if you wish. Using these tools for programming and editing text in general is something that I deeply enjoy, and I hope that this is somewhat useful for others who would like to join me!