How to change and delete words and lines in Vim

ciwccddx

Put the cursor anywhere on a word and type ciw. The word disappears and you are in Insert mode: type the new word, then press Esc.

To change the whole line, type cc. To delete instead of change, use d in place of c: diw deletes a word, dd deletes a line. x deletes one character.

Worked example

Change small to light. The cursor starts on the m.

ciwlightEsc
Your textVim mode: Normal
Change small to light. The cursor starts on the m. Before: Pack a small bag.. After: Pack a light bag..

ciw means "change inner word". It takes the whole word, wherever the cursor is inside it, and leaves the spaces around it alone.

Commands

ciw
Change the word under the cursor.
cw
Change from the cursor to the end of the word.
cc
Change the whole line.
C
Change from the cursor to the end of the line.
daw
Delete the word and one space next to it.
dw
Delete to the start of the next word.
de
Delete to the end of the word. The space after it stays.
dd
Delete the whole line.
D
Delete from the cursor to the end of the line.
x
Delete the character under the cursor.
r
Replace one character, then stay in Normal mode. Type the new character after r.

Start typing in the right place

Sometimes you add text instead of replacing it. Six keys enter Insert mode at different places: i before the cursor, a after it, I at the start of the line's text, A at the end of the line, o on a new line below and O on a new line above.

A
Add text at the end of the line.
I
Add text before the first non-blank character.
o
Open a new line below and type there.
O
Open a new line above and type there.

Join, indent and change case

Some changes reshape text without retyping it. J joins the next line onto this one with a space between. >> indents the line. gU followed by a motion or text object makes that text upper case, so gUiw capitalises one word.

J
Join the next line to this one.
>>
Indent the line by one level.
gUiw
Make the word upper case.

Exceptions

  • cw on a word works like ce: it keeps the space after the word. dw does not; it deletes the space too.
  • From the middle of a word, cw changes only the rest of it. Use ciw when you want the whole word.
  • At the end of a line there is no space after the word, so daw takes the space before it.
  • Punctuation is a word of its own. In notes.md, ciw on notes stops at the dot.
  • A count makes one change cover more: 2dd deletes two lines, and one u brings both back.
  • In a fresh Vim, >> indents with a tab; your own Vim may use spaces, depending on its settings. This site's editor uses two spaces.

Try it