Learn Vim Progressively-Min
Learn Vim Progressively-Min
French
Change Theme
↓ Menu ↓
tl;dr: You want to teach yourself vim (the best text editor known to human
kind) in the fastest way possible. This is my way of doing it. You start by
learning the minimal to survive, then you integrate all the tricks slowly.
Learn vim and it will be your last text editor. There isn’t any better text
editor that I know of. It is hard to learn, but incredible to use.
1. Survive
2. Feel comfortable
3. Feel Better, Stronger, Faster
4. Use superpowers of vim
But before we start, just a warning. Learning vim will be painful at first. It
will take time. It will be a lot like playing a musical instrument. Don’t expect
to be more efficient with vim than with another editor in less than 3 days. In
fact it will certainly take 2 weeks instead of 3 days.
You should feel a bit better. You can type letters like in a standard editor. To
get back to Normal mode just press the ESC key.
You now know how to switch between Insert and Normal mode. And now,
1 of 8 11/1/19, 3:38 AM
YBlog - Learn Vim Progressively file:///home/andras/Dropbox/Learn/Misc/text_edi...
here are the commands that you need in order to survive in Normal mode:
Recommended:
Only 5 commands. That is all you need to get started. Once these command
start to become natural (maybe after a day or so), you should move on to
level 2.
But first, just a little remark about Normal mode. In standard editors, to copy
you have to use the Ctrl key (Ctrl-c generally). In fact, when you press Ctrl, it
is as if all of your keys change meaning. Using vim in normal mode is a bit
like having the editor automatically press the Ctrl key for you.
2. Basic moves
2 of 8 11/1/19, 3:38 AM
YBlog - Learn Vim Progressively file:///home/andras/Dropbox/Learn/Misc/text_edi...
3. Copy/Paste
4. Undo/Redo
u → undo
<C-r> → redo
:e <path/to/file> → open
:w → save
→ save to <path/to/file>
:saveas <path/to/file>
:x, ZZor :wq → save and quit (:x only save if necessary)
:q! → quit without saving, also: :qa! to quit even if there
are modified hidden buffers.
:bn (resp. :bp) → show next (resp. previous) file (buffer)
Take the time to learn all of these command. Once done, you should be able
to do every thing you are able to do in other editors. You may still feel a bit
awkward. But follow me to the next level and you’ll see why vim is worth the
extra work.
Better
3 of 8 11/1/19, 3:38 AM
YBlog - Learn Vim Progressively file:///home/andras/Dropbox/Learn/Misc/text_edi...
desu desu desu desu desu desu desu desu desu desu desu
desu desu desu desu desu desu desu desu desu desu desu
desu desu desu desu desu desu desu desu desu desu desu
desu desu desu desu desu desu desu desu desu desu desu
desu desu desu desu desu”
. → Just after the last command will write again the 100
“desu”.
3. → Will write 3 “desu” (and not 300, how clever).
Stronger
Knowing how to move efficiently with vim is very important. Don’t skip this
section.
1. NG → Go to line N
2. gg → shortcut for 1G - go to the start of the file
3. G → Go to last line
4. Word moves:
%: Go to the corresponding (, {, [.
*(resp. #) : go to next (resp. previous) occurrence of the word
under the cursor
Faster
4 of 8 11/1/19, 3:38 AM
YBlog - Learn Vim Progressively file:///home/andras/Dropbox/Learn/Misc/text_edi...
We also can do things like ye, yank from here to the end of the word. But also
y2/foo yank up to the second occurrence of “foo”.
But what was true for y (yank), is also true for d (delete), v (visual select), gU
(uppercase), gu (lowercase), etc…
0 → go to column 0
^ → go to first character on the line
$ → go to the last column
g_ → go to the last character on the line
fa → go to next occurrence of the letter a on the line. , (resp. ;)
will find the next (resp. previous) occurrence.
t, → go to just before the character ,.
3fa → find the 3rd occurrence of a on this line.
F and T → like f and t but backward.
Line moves
These command can only be used after an operator in visual mode. But they
are very powerful. Their main pattern is:
Where action can be any action, for example, d (delete), y (yank), v (select in
visual mode). The object can be: w a word, W a WORD (extended word), s a
sentence, p a paragraph. But also, natural character such as ", ', ), }, ].
5 of 8 11/1/19, 3:38 AM
YBlog - Learn Vim Progressively file:///home/andras/Dropbox/Learn/Misc/text_edi...
Rectangular blocks are very useful for commenting many lines of code.
Typically: 0<C-v><C-d>I-- [ESC]
Rectangular blocks
Note: in Windows you might have to use <C-q> instead of <C-v> if your
clipboard is not empty.
In Insert mode, just type the start of a word, then type <C-p>, magic…
Completion
qa record your actions in the register a. Then @a will replay the macro saved
into the register a as if you typed it. @@ is a shortcut to replay the last
executed macro.
Example
qaYp<C-a>q→
qa start recording.
Yp duplicate this line.
<C-a> increment the number.
q stop recording.
@a → write 2 under the 1
@@ → write 3 under the 2
Now do 100@@ will create a list of increasing numbers until 103.
Macros
6 of 8 11/1/19, 3:38 AM
YBlog - Learn Vim Progressively file:///home/andras/Dropbox/Learn/Misc/text_edi...
We saw an example with <C-v>. There is also v and V. Once the selection has
been made, you can:
Autoindent
<C-v>
go to desired line (jjj or <C-d> or /pattern or % etc…)
$ go to the end of the line
A, write text, ESC.
These are the most important commands, but you should look at :help split.
Split
Conclusion
That was 90% of the commands I use every day. I suggest that you learn no
more than one or two new commands per day. After two to three weeks you’ll
start to feel the power of vim in your hands.
Then, you will learn about !, folds, registers, plugins and many other
features. Learn vim like you’d learn piano and all should be fine.
r·t·`·g
These social sharing links preserve your privacy
7 of 8 11/1/19, 3:38 AM