file

:w / :saveas

Write (save) the current buffer to disk. Without an argument :w saves to the current file; with an argument it writes a copy without switching buffers. Use :saveas when you want to rename the buffer to the new file and keep editing that one.

:w [filename]   :saveas {filename}  (command mode)

Variations

Keystroke Effect
:w! Force write, even if read-only or file changed on disk
:w newfile.txt Write buffer to newfile.txt (buffer stays on original)
:wa Write all modified buffers
:saveas draft.md Save AS a new filename and switch the buffer to it
:w !sudo tee % Classic trick to save a file that needs root

Examples

:w

Save current file

:w backup.txt

Save a copy as backup.txt without switching to it

:saveas notes.md

Save as notes.md and keep editing notes.md going forward

:wa

Save every modified buffer in the session

Gotcha

:w newname just copies — the buffer still points at the original; use :saveas if you want to actually 'rename and continue editing'. New [No Name] buffers require a filename to :w.

Related

← All Vim commands · Vim cheat sheet