Vim (and vi before it) has a command set that is a composable language.
First, you have motions
. These are actually the nouns of the command language, but on their own they mean cursor movements. There are a whole lot of them. h
is left, l
is right, j
is down, k
is up (all one character). $
is end of line, ^
is beginning of line, (
and )
are beginning and end of paragraph. That’s enough for now (but there are heaps more).
Then you have verbs. Verbs
are followed by a motion to make a sentence. d
is delete. dl
is delete next character, dh
is delete previous. So now you can guess that (d)
is delete this paragraph, d$
is delete the rest of this line… and so on.
Double a verb to apply it to the whole current line… dd
for example.
Prefix it with a number to do it that many times… 55dd
deletes the next 55 lines.
So how do you actually put stuff in to a file?
i
lets you insert stuff in front of the cursor (it’s an exception because it doesn’t take a motion). After you typei
you’re in insert mode; press theESCAPE
key orcontrol-[
to get out. Note that vim starts in view mode, you have to type a command to get in to insert mode to start typing stuff.s
means substitute, and it will replace the motion with whatever you type.sw
is substitute word, and a command I use a lot.ss
is substitute current line.a
means append, and it’s exactly like insert except it goes the other side of the cursor.
There’s a bunch of verbs for useful things like cut and paste.
Delete
is actually cutp
pastes after the cursorP
pastes before.
Lastly, :
lets you into vim’s other main mode, command mode, which has a lot of power. Something like:
:w
is the save command:q
is quit.- You can combine them as
:wq
. - Help is
:h
.
So, that command set as language idea makes vim completely different from other editors in how it sits in your mind.
Original content source: Andrew McGregor, Performance Measurement Lead at Fastly (2019-present), who’ve answered it here.