Most editing in Vim happens in Normal mode, without typing any new text. Press Esc first.
Deleting
xdeletes the character under the cursor.dddeletes the whole line.dwdeletes from the cursor to the start of the next word.Dord$deletes to the end of the line.
The pattern is "operator plus motion": d says what to do, and the motion says how far. A count works too, so 3dd deletes three lines.
Changing
c works like d but leaves you in Insert mode afterwards. cw changes a word and cc changes a whole line. Type the new text and press Esc.
Copying and pasting
Vim calls copying "yanking".
yyyanks the current line.ywyanks a word.pputs the text after the cursor, or below the line for whole lines.Pputs it before, or above.
Deleted text is kept as well, so dd followed by p moves a line down by one.
To select first and act second, press v for characters or V for whole lines, move, then press d, c or y.
Vim's internal registers are separate from your desktop clipboard in many setups, so a yank may not be available in other programs.
Undo and redo
uundoes the last change.Ctrl-rredoes it.
In full Vim you can press u repeatedly to go further back. In original vi behaviour, which some minimal builds follow, a second u reverses the first one instead.
Search and replace
The substitute command is typed after a colon:
:s/http/https/
:s/http/https/g
:%s/http/https/g
:%s/http/https/gcWithout a range, :s works on the current line only, and changes just the first match. The g flag changes every match on the line. % means every line in the file. The c flag asks you to confirm each one: answer y or n, or q to stop.
If your text contains slashes, use another separator:
:%s#/var/www#/srv/www#gTwo small extras: J joins the next line onto the current one, and . repeats the last change.
Try it
- Create a file:
printf 'one http\ntwo http http\nthree\n' > edit.txt. - Open it with
vim edit.txt. - Press
dd, thenp, and watch the first line move down. - Press
uto undo the paste, thenuagain to undo the delete (full Vim). - Run
:%s/http/https/g. - Save with
:wqand check withcat edit.txt.
For a live Linux shell, there is the permissions lab.
Check your understanding
Vim Editing
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.