How to Learn Vim in 2020

March 17, 2020

Follow @learnvim for more Vim tips and tricks!

When I first discovered Vim, I thought it was an outdated editor that was unnecessarily hard to use. Until one day I saw my friend doing Vim magic. I thought that was the coolest thing I have ever seen. Fast forward several years, Vim is now my main editor.

Is it worth learning Vim in 2020, where many are using modern editor like VSCode, Sublime, and Atom?

Definitely.

I will show you how to get started learning Vim. Here are things that I will cover. You don't have to read this linearly.

You may decide that Vim is not for you. That's totally fine. Vim, like other editors, is just a tool. At the end of the day, use whatever tool that lets you get the job done.

Why learn Vim

Vim is not easy to use initially. But Driving a car was not easy initially. Riding a bicycle was not easy initially. Programming was not easy initially. Many things are not easy initially. So why do we stop learning Vim because it was not easy initially?

If you are asking, "why should I learn Vim in 2020? There are many great text editors out there." Here are some advantages of using Vim:

  • Lightweight.
  • Challenging (for those who love challenges).
  • Almost everywhere (if you ever need to SSH to server, you won't find an IDE, but you will almost always find Vim).
  • Good integration with command line (with !, you can execute commands like ls, curl. You can also run ex commands with :).
  • Rewarding and satisfying. (Understanding Vim grammar, customizing Vim, learning Vim Script, etc, unlock a whole new realm of possibilities. It is like playing video game where you could level up, acquire new skills, and combine them).
  • Unique built-in features. (Time travel, macros, text-objects, dot command are built-in features that are almost unique to Vim).

Challenges:

  • Hard to exit the first time.
  • Steep learning curve (not as bad as you think).
  • First time using it will cut productivity (learning always takes time. You don't have to start Vim cold. Keep your regular editor at work. Learn Vim at your time, on your own side project. Switch when you are ready).

Learning Vim

In first part, I will show some practical steps to learn Vim from absolute beginner. In second part, I will share useful tips/tricks.

Steps to Learn Vim

  • ✅ Learn how to exit Vim.
  • ✅ Go through :vimtutor (:Tutor).
  • ✅ Learn the most basic commands to get started:
i (insert mode)
Esc (normal mode/ exit insert mode)
x (delete one character)
h/j/k/l (direction. Personally I would avoid arrow keys from the beginning)
:e {filename} (load document)
:w {filename} (save document)
:q (exit)
:q! (exit + ignore unsaved changes)

Next, learn slightly more advanced commands:

dd (cut a line)
yy (copy a line)
p (paste)
/{pattern} (search for text)
n (go to the next result)
:s/pattern/replacement (replace text)

These should be enough to get you started. There are many more features that I do not list above. You will learn them over time.

Do not feel like you have to know 100% of Vim features. You can get very fast and productive with limited knowledge. There may even be popular features that you will never use. Use whatever features and workflow that helps you most.

Tips/Tricks to learn Vim

  1. Learning Vim is learning a practical skill. You don't learn how to ride a bike by reading a book on how to ride a bike. You learn how to ride a bike by riding a bike. You are building muscle memory. The goal is to be able to do X without thinking. Learn only a few things each day and learn them well.
  2. Don't copy paste someone else's vimrc. It will cloud you from seeing Vim's native ability. Start with blank vimrc. Know what every single line does. You will be surprised that you may not need that many plugins.
  3. Learn touch typing.
  4. When starting, force yourself to use hjkl. You can either add this in your vimrc:
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>

or install vim-hardtime plugin.

Vim Resources

Below, I compiled some of the popular resources to learn Vim.

Books

Books I found extremely useful:

  1. Practical Vim
  2. Mastering Vim
  3. A Byte of Vim
  4. More list of books here

Articles

"Must-read" Vim articles:

  1. Learn vim For the Last Time: A Tutorial and Primer
  2. Grokking Vi
  3. Why I love Vim: It’s the lesser-known features that make it so amazing
  4. operator, the true power of Vim
  5. Coming Home to Vim
  6. Vim Anti-Patterns

Misc Online Resources

Other online resources:

  1. Vim reddit for vim discussions/tips/Q&A
  2. Vimcasts for tutorials
  3. Vimgolf for training
  4. OpenVim
  5. Vim adventures
  6. Derek Wyatt Vim tutorials
  7. Learn Vimscript the Hard Way

List of Plugins

Once you get comfortable, feel free to add plugins. Here is a (opinionated) list of plugins to make Vim more "IDE"-like:

  1. Quick quote/parentheses: vim-surround
  2. Search: fzf.vim
  3. No-nonsense config: vim-sensible
  4. NERDTree: nerdtree (alternative: netrw, or its enhancement vim-vinegar, ranger)
  5. Emmet: emmet-vim
  6. tags: vim-gutentags
  7. autocompletion: (youcompleteme, coc.nvim, deoplete)
  8. language pack:vim-polyglot
  9. tmux-integration: vim-tmux-navigator
  10. commenting: vim-commentary, tcomment
  11. LSP support/ syntax: ale
  12. Git: vim-fugitive (also vim-gitgutter)
  13. Indent: indentline
  14. Text-object: vim-textobj-user

How to use :help

At some point, you will need to start using Vim's built-in :help on your quest to master Vim.

Knowing how to use Vim's built-in help is useful.

Autocomplete

Vim help lets you autocomplete with tab. If you want to learn more about Vim colorscheme, you can type :h color and press <TAB>. Vim will show you different options to choose from. You can navigate forward with <TAB> and back with <SHIFT> + <TAB>.

Jump to definition

While you are in help, sometimes you will see links (it has different color). If you put your cursor on link, you can jump to definition with C-].

You can go toggle previous/current window with C-o and C-i.

helpgrep

Vim has a lesser-known feature called :helpgrep. It does what it sounds like: grepping help. It search for phrases in all help section.

For example, if you want to look at everything related to "colorscheme", you can do :helpgrep colorscheme". Vim searches for all "colorscheme" keywords and list them in Quickfix window (:h quickfix).

Some useful navigation:

  1. List all helpgrep results with :clist
  2. Go to next match with :cnext
  3. Go to previous match with :cprev

Conclusion

Is 2020 too late to learn Vim? No.

Do you have to learn Vim to be a better programmer? Absolutely not. I've seen much better programmer than me who does not use Vim.

Is Vim challenging? It takes a lifetime to become a Vim master (I am also still a Vim student). Vim is unlike other editors I have ever used. There is always something to be discovered. Vim is challenging. The fun kind of challenge.

In the end - I will repeat this again - use whatever best tool for the job. Maybe it is Vim for you, maybe it is VSCode, or maybe it is Notepad++ - or maybe it is all of them. It is good to be well-versed with multiple tools.

Let's get things done.

© Copyright 2021 Igor Irianto