Vim has many movement commands.
The four most important are h, j, k, and l.
They are consecutive keys under the right hand on the home row.
They function as the arrow keys do, but are easier to reach.
h and l move right and left respectively.
j moves down a line, and k moves up a line.
Download this file to your computer and open it in vim.
The five paragraphs in the document are out of order!
Before we fix the paragraphs, let's move around in the document to get used to the movement keys. Move to the bottom and top of the document by holding down j and k respectively. Go right and left within a line with l and h. Using h, j, k, and l to move will feel a little funny at first. Stick with it!
Now we're ready to go to work.
Move your cursor to the first line.
Your cursor can be anywhere within Paragraph 5.
Type dj. (No period! Just dj)
Paragraph 5 and the line below it are gone!
Use j to move your cursor to the empty line below Paragraph 4.
Type p. (No period! Just p)
Paragraph 5 is below Paragraph 4 now!
Move your cursor to the P in Paragraph 3, and type dj.
Use j to move your cursor to the empty line below Paragraph 2.
Everything is fixed!
Type u 4 times to go back to the messed up paragraph order.
Fix the paragraph order again.
Fix the paragraph order a few more times. Better yet, fix it many times.
Make a game out of it. See how fast you can get at fixing paragraph order.
You should be able to make these changes in just a few seconds.
If you write for a living, the payoff for that kind of speed is huge!
Of course, writing is not a race.
The goal is not to write poorly at breakneck speed.
But when vim commands like these are part of your muscle memory, you no longer have to think about them. You think, "This paragraph here, that paragraph there," and your fingers make the changes as if by magic. Your focus stays on your work, not text manipulation.
That's why it's important to learn vim! No other software is better at text manipulation!
Yesterday we learned that d followed by a movement key deletes text.
Today we typed dj to delete the line we were on and the line below it.
Remember, when we type d, the computer still doesn't know what to delete.
We typed j, which told the computer what to delete with relation to the cursor.
In other words, we told the computer to delete from the cursor down one line.
p pastes text. (In vim p stands for put.)
We moved to where we wanted to paste the text and typed p.
It was as simple as that!
We undid changes with u, which is the undo command.
In the future we'll talk about registers.
Here's a short preview.
When we delete text, it goes into the default register.
The default register is like a clipboard.
When we paste text, vim looks in the default register by, ahem, default.
The name default might tip you off that vim has other registers.
Vim does, but we only need the default register for now. (Maybe ever!)