C.W.K.
Stream
Lesson 03 of 08 · published

Opening, Saving, and Quitting

~10 min · vim, basics, files

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

The first thing every Vim user has to unlearn

You don't Cmd+S in Vim. You don't File → Save As…. You drop into Command-line mode with :, type a one- or two-letter command, and hit Enter. It feels archaic for a day, then it feels like a remote control: a tiny number of buttons that cover everything.

Opening files

From the shell, point Vim at a path. From inside Vim, use :e (edit) to switch to a different file in the current window.

Quitting — the part everyone gets stuck on

Two letters, two ideas: w writes (saves), q quits. Combine them. Add ! to force past warnings. ZZ and ZQ are Normal-mode shortcuts that skip the colon entirely.

Multiple files at once

Vim opens many files into buffers — files held in memory. :bn / :bp cycle. :qa quits all buffers; :wqa writes and quits all. We'll go deeper on buffers in Track 3 — for now, know that vim file1 file2 file3 is a normal thing to do.

ZZ is your fastest exit. Two keystrokes in Normal mode, no colon, no Enter. Pair it with ZQ (quit without saving) and you'll never type :wq again.

Vim refuses to quit — what now?

If :q says "E37: No write since last change," Vim is protecting unsaved work. Decide: :w to save then :q, or :q! to discard and quit. The error message is useful, not rude.

Code

Opening files from the shell and from inside Vim·bash
# From shell
vim file.txt              # open one file
vim file1.txt file2.txt   # open multiple files (each becomes a buffer)
vim +42 file.txt          # open at line 42
vim +/pattern file.txt    # open and jump to first match
vim -                     # open stdin (great with pipes: ps aux | vim -)

# Neovim equivalents
nvim file.txt
nvim +42 file.txt
Save / quit cheatsheet — memorize this whole block·vim
:q          " quit (refuses if unsaved changes exist)
:q!         " quit and discard changes
:w          " save
:w newname  " save as 'newname'
:wq         " save and quit
:x          " save (only if changed) and quit
ZZ          " Normal-mode :x
ZQ          " Normal-mode :q!
:qa         " quit all open buffers
:qa!        " quit all and discard everything
:wqa        " save all and quit
Inside Vim — switching files without exiting·vim
:e other.txt    " open 'other.txt' in the current window
:e .            " open the current directory in the file browser (netrw)
:e!             " reload the current file from disk, discarding unsaved changes
:ls             " list all open buffers
:bn             " switch to next buffer
:bp             " switch to previous buffer
:bd             " close (delete) the current buffer

External links

Exercise

Create a fresh file ~/scratch/vim-warmup.txt in Vim, type a paragraph in Insert mode, save with ZZ. Reopen it with vim +$ ~/scratch/vim-warmup.txt (which jumps to the last line). Add a second paragraph, then quit with :q — Vim should refuse. Decide which way out you want (:wq or :q!) and use it deliberately. The point is to feel the refusal, not to memorize it.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.