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?
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.
- Why learn Vim
- Learning Vim
- Resources to Learn Vim
- Mastering the Help Command
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.
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:
- 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
curl. You can also run
- 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).
- 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).
In first part, I will show some practical steps to learn Vim from absolute beginner. In second part, I will share useful tips/tricks.
- ✅ Learn how to exit Vim.
- ✅ Go through
- ✅ 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)
✅ Learn Vim Grammar to "talk" to Vim.
✅ Learn navigation.
✅ Learn Vim modes.
✅ Learn text object.
✅ Learn how to modify vimrc.
✅ Learn basic Command-line mode (ex) commands (first, learn search/replace).
✅ Learn the dot command.
✅ Learn macros.
✅ Learn something new everyday and apply it.
✅ Do Vimgolf.
✅ Perpetual self learning.
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.
- 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.
- 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.
- Learn touch typing.
- 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.
Below, I compiled some of the popular resources to learn Vim.
Books I found extremely useful:
"Must-read" Vim articles:
- Learn vim For the Last Time: A Tutorial and Primer
- Grokking Vi
- Why I love Vim: It’s the lesser-known features that make it so amazing
- operator, the true power of Vim
- Coming Home to Vim
- Vim Anti-Patterns
Other online resources:
- Vim reddit for vim discussions/tips/Q&A
- Vimcasts for tutorials
- Vimgolf for training
- Vim adventures
- Derek Wyatt Vim tutorials
- Learn Vimscript the Hard Way
Once you get comfortable, feel free to add plugins. Here is a (opinionated) list of plugins to make Vim more "IDE"-like:
- Quick quote/parentheses: vim-surround
- Search: fzf.vim
- No-nonsense config: vim-sensible
- NERDTree: nerdtree (alternative: netrw, or its enhancement vim-vinegar, ranger)
- Emmet: emmet-vim
- tags: vim-gutentags
- autocompletion: (youcompleteme, coc.nvim, deoplete)
- language pack:vim-polyglot
- tmux-integration: vim-tmux-navigator
- commenting: vim-commentary, tcomment
- LSP support/ syntax: ale
- Git: vim-fugitive (also vim-gitgutter)
- Indent: indentline
- Text-object: vim-textobj-user
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.
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>.
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
You can go toggle previous/current window with
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 (
Some useful navigation:
- List all helpgrep results with
- Go to next match with
- Go to previous match with
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.