Learning Vim: Day 2

Changing regions of text

By character

Keys to type What they do
x deletes the character under the cursor
r replaces one character with the next one typed
s substitutes for a single character whatever is typed next until esc is hit

Why use r instead of s?
r and s seem to do almost the same thing. Why use r, when s seems more flexible? Well, if you know you only need to substitute one character for another, r saves you from entering insert mode, and then having to leave it.

By word

Keys to type What they do
cw Changes the word under the cursor to whatever is typed up until esc.
dw Deletes the word under the cursor

By line

Keys to type What they do
dd Deletes the entire line of text under the cursor
C Changes the line from the point the cursor is at on
J Pulls the next line up into the line the cursor is on

Adding a count

Most of these commands can take a number in front, so 10cw changes ten words.



Practice

Type vi practice.txt.