Skip to main content
Error Code Decoders & Troubleshooting

Vim Quit No Save: Syntax, Examples, and Error Resolution

Vim Quit No Save

vim quit no save is the action of exiting Vim while discarding all unsaved changes, performed via :q! or ZQ from normal mode.

# Force quit without saving (discard all changes)
:q!

# Quit without saving and return non-zero exit code
:cq

# Quit without saving from normal mode (uppercase Z then uppercase Q)
ZQ

Tested on Ubuntu 22.04 with Vim 9.0.

Syntax

These commands work in command mode (press Esc to enter normal mode, then : to enter command-line mode). The ! overrides the “No write since last change” warning. ZQ works directly from normal mode without a colon.

Options and Flags (Colon-Command Variants)

Command Type Default Behavior Description
:q! Force quit Exits without saving Overrides the “No write since last change” warning (E37).
:cq Force quit with error Exits without saving, returns exit code 1 Useful in scripting to signal failure when file must not be saved.
ZQ Normal-mode shortcut Exits without saving Works without entering command mode. Case-sensitive.
:q Normal quit Exits only if no unsaved changes Fails with E37 if modifications exist. Use :q! to bypass.
:qa! Force quit all buffers Exits all open files without saving Use when multiple files are opened with vim file1 file2.

Usage Examples

1. Force quit after accidental modification

# Open a config file, make an unwanted change, then quit without saving
vim /etc/nginx/nginx.conf
# Press i to enter insert mode, accidentally type something, press Esc
:q!

Use this when you opened a file only to read it but accidentally triggered an edit. The exclamation mark forces Vim to exit ignoring the unsaved buffer.

See also  Cisco Ios Xe: Quick Cheat Sheet, Flags and Verified Examples

2. Use :cq in a CI pipeline to abort on file corruption

# In a script, open a file for review, exit with error if unable to process
vim -c "/ERROR" -c "cq" logfile.txt
# If the pattern is found, Vim exits with code 1, causing the pipeline to fail

:cq returns exit code 1, allowing automated workflows to detect that the file was not saved and should be flagged.

3. Quit all open tabs and windows without saving

# When editing multiple files with vim -p file1 file2 file3, force exit all
:qa!

This variant closes every buffer, tab, and window unconditionally. Equivalent to running :q! on each buffer followed by quitting.

Troubleshooting and Common Errors

Error Message Root Cause Resolution Command
E37: No write since last change (add ! to override) Attempting :q with unsaved changes. :q!
E45: ‘readonly’ option is set (add ! to override) File opened in read-only mode (vim -R or view). :q! – no need to save read-only files.
E89: No write since last change for buffer (add ! to override) Using :q on a hidden buffer that is modified. :q! or :qa! to force quit all.
Still in Insert mode Pressing : while in Insert mode inserts a colon instead of entering command mode. Press Esc first, then type :q!.

Frequently Asked Questions

What is the difference between :q! and :cq in Vim?

Answer: :q! quits discarding changes with exit code 0; :cq quits discarding changes with exit code 1, signaling failure to scripts.

Use :q! for manual forced exit. :cq (cquit) is designed for CI/CD pipelines where a non-zero exit code is required to indicate a deliberate abort. Example:

:cq

How do I fix “E37: No write since last change” when trying to quit Vim without saving?

Answer: Use :q! to force quit without saving, or :cq to quit with exit code 1.

Vim’s :q command blocks exit if modifications exist. Append ! to override. :cq also forces exit but sets exit status to 1. Example:

:q!

Does :q! work on all platforms (Linux, macOS, Windows)?

Answer: Yes, :q! is a standard Vim ex command and works identically on Linux, macOS, and Windows with any Vim installation.

No platform-specific differences. Works in terminal Vim, gVim, and embedded versions. Verify with:

vim -c ":q!" -c ":qa"

What is the fastest way to quit Vim without saving any changes?

Answer: Press Esc, then type :q! and Enter (4 keypresses).

ZZ saves and quits – avoid. 😡 also saves. Fastest keystrokes for unsaved quit: Esc then :q! Enter. Map to a key for even faster:

:nnoremap <C-Q> :q!<CR>