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

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.

Practice free — no signup →

Keep going