Open, Save, Quit

Launch Neovim, write your work, and get out โ€” three ways each

Keys: :w, :q, :wq, :x, ZZ, :q!, ZQ

Open a file with nvim. Write with :w. Quit with :q. Combine with :wq, :x, or ZZ. Discard with :q! or ZQ.

The single most-googled question about Vim is "how do I exit?" Let's get that out of the way first, then make it a real skill.

Opening a file

Launch Neovim editing hello.txt
KeyNote
@nvim hello.txt
Enter

If the file exists, you see its contents. If it doesn't, you see an empty buffer that will be saved as hello.txt the first time you write. Vim doesn't create the file on disk until you save.

Opening a file

Saving

Write the buffer to its file
KeyNote
:
w
Enter

:w "writes" โ€” Vim's word for save. :w {filename} writes to a different filename (Save As). :w! forces a write through read-only flags.

Saving with :w

Quitting

Quit (only if no unsaved changes)
KeyNote
:
q
Enter

:q quits โ€” if the buffer is clean. If there are unsaved changes, Vim refuses and tells you to save or force-quit. Force-quit with :q! discards changes and exits.

Quitting Vim

Save and quit

Command Behavior
:wq Write, then quit. Always writes (even if nothing changed).
:x Write if changed, then quit. Quieter than :wq.
ZZ Same as :x โ€” write-if-changed, then quit. Normal-mode shortcut.
Save-and-quit: :wq, :x, ZZ

Quit without saving

Command Behavior
:q! Discard changes and quit.
ZQ Same โ€” Normal-mode shortcut.
Quit without saving

Reference

Goal Command
Open a file `nvim file` from the shell
Save :w
Save as :w new-name
Save (force, e.g. read-only) :w!
Quit (clean buffer) :q or :qa for all
Save then quit (always writes) :wq
Save then quit (only if changed) :x or ZZ
Quit, discarding changes :q! or ZQ
Reload from disk (lose changes) :e!

Worked example โ€” :w and :q

Save and quit from the Ex prompt.

Step 1 ยท Modified buffer ([+]).
Modified buffer ([+]).
Step 2 ยท :w ยท :w writes the file.
:w writes the file.

Status loses [+]; the file is on disk. :q would now leave Vim.

โ–ถ Try this in the simulator

See also: Insert and Back Again, Undo and Redo, File Operations, Buffers