Learn Vim / How to Save a File in Vim

How to Save a File in Vim

The answerPress Esc, then type :w and press Enter.

Like every ex command, :w only works from normal mode — Esc first if you've been typing.

All the ways

KeysWhat it does
:wsave
:wqsave and quit
:w newname.txtsave a copy under a new name
:w !sudo tee %the classic: save a root-owned file you opened without sudo
:wasave all open buffers
▶ live vim buffertarget 3 keystrokes
Line 1 is missing its period. With the cursor anywhere on line 1, press A to append at the end of the line, type a period, then Esc.

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “The missing period” mission takes about a minute.

Sign in free to practice →

Keep going