Printed on demandShips worldwide14-day returns

What Does :wq Mean? Vim’s Save-and-Quit Explained

:wq is the Vim command to save the file and quit. The colon opens command-line mode, w means write (save) and q means quit. Press Esc first to make sure you are in Normal mode, then type :wq and press Enter.

How to exit Vim, step by step

  • Press Esc. This leaves Insert mode. Pressing it twice does no harm.
  • Type :. The cursor jumps to the bottom of the screen.
  • Type wq to save and quit, or q! to quit without saving.
  • Press Enter.

:wq, :x, :q! and friends

Vim has several ways to leave. They differ in one thing: whether they write the file. The definitions below follow the official help, editing.txt.

CommandWhat it does
:wWrite (save) the file. Stay in Vim
:qQuit. Vim refuses if there are unsaved changes
:q!Quit without writing, even with unsaved changes. Changes are lost
:wqWrite the file and quit, always, even if nothing changed
:xLike :wq, but writes only when there are changes
ZZNormal-mode shortcut, no colon. Same as :x
ZQNormal-mode shortcut. Same as :q!
:wqaWrite all changed buffers and quit
:qa!Quit all windows and discard every change

:wq vs 😡

Both save and quit. The difference is the write. :wq always writes the file, so its modification time changes even if you touched nothing. :x only writes if the buffer was modified. That matters for build tools like make, which decide what to rebuild from file timestamps.

$ vim notes.txt     # open, change nothing
:wq                 # file is written, mtime updates

$ vim notes.txt     # open, change nothing
:x                  # nothing written, mtime unchanged

Why does :q say “No write since last change”?

Vim protects your work. If the buffer has unsaved changes, :q stops with error E37. Use :wq to keep the changes or :q! to throw them away.

Why :wq is a programmer joke

Vim starts in Normal mode, where letters are commands, not text. A newcomer opens it by accident, often because Git launched it for a commit message, types “quit” and watches strange things happen. There is no menu and no close button in the terminal.

“How do I exit Vim?” became one of the most famous programming questions on the internet, and a running gag in developer culture. Jokes about it range from “I’ve been using Vim for two years, mostly because I can’t figure out how to exit” to turning the computer off and on again, a fix we explain in Have you tried turning it off and on again.

So wearing :wq says something simple: I know how to get out. It is a small badge for anyone who lives in a terminal, and an inside joke that every developer recognises.

If Git opened Vim for you

Write your commit message on the first line, then press Esc and type :wq. If you want to cancel the commit, quit with :cq: Vim exits with an error code, and Git aborts. To use another editor next time:

git config --global core.editor "nano"

Wear the command

Two ways to say you know how to exit Vim. Both are in the Vim collection.

:wq Vim T-Shirt, front

:wq Vim T-Shirt · 24 €
Save and get me out of here.

:wq Vim Cap, front

:wq Vim Cap · 29 €
The same command, in a cap.

The shirt is unisex, S to 5XL: check the size guide. The cap costs 29 €. More ideas in the Christmas gift guide for programmers.

A few more Vim survival commands

Once you can leave, these help you stay a little longer:

KeysModeWhat it does
iNormalEnter Insert mode, so you can type text
EscInsertReturn to Normal mode
uNormalUndo the last change
Ctrl+rNormalRedo
/wordNormalSearch forward for “word”
:helpCommand-lineOpen the built-in manual

New to Vim? Run vimtutor in a terminal. It is an interactive lesson that ships with Vim and takes about half an hour.

Why Vim works this way

Vim descends from vi, written by Bill Joy for BSD Unix in the 1970s, when terminals were slow and many keyboards had no arrow keys. Separate modes let every letter act as a command in Normal mode, so you can edit without moving your hands from the home row. The price is the learning curve: the editor does nothing obvious when you first type, and the way out is hidden behind a colon.

Fans argue that the colon commands are the point. Once :wq is in your fingers, saving and quitting takes four keystrokes and no mouse. That habit is also why some developers type :wq into chat windows and word processors by accident.

FAQ

What does :wq! do?

It writes and quits even when Vim would normally refuse, for example with a read-only file you have permission to write.

Is 😡 the same as ZZ?

Yes. The Vim help defines ZZ as “same as :x”: write if modified, then close the window.

Does :wq work in vi and Neovim?

Yes. :w, :q, :wq, :x and ZZ work in vi, Vim and Neovim.