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.
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:
!
, you can execute commands like ls
, curl
. You can also run ex
commands with :
).Challenges:
In first part, I will show some practical steps to learn Vim from absolute beginner. In second part, I will share useful tips/tricks.
:vimtutor
(:Tutor
).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.
:h motion.txt
/ :h navigation
✅ Learn Vim modes.
:h vim-modes-intro
✅ Learn text object.
:h text-objects
✅ 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.
✅ Read (and reread) Practical Vim and/or Mastering Vim Quickly.
✅ 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.
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.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:
Other online resources:
Once you get comfortable, feel free to add plugins. Here is a (opinionated) list of plugins to make Vim more "IDE"-like:
: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.
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>
.
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
.
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:
:clist
:cnext
:cprev
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.