How to :quit VIM
If you thought quitting vim was hard, I challenge you to exit its predecessor, the built-in ed editor.
SPOILER ALERT: you don't. VIM is your home now.
Even if you uninstall it, it will still somehow be running.
If you really don't know how to exit VIM, I am honored to give you the rite of passage :: simply smash |ESC| 42 times, followed by the following sequence of characters: :q! and hit |ENTER| (that should do it).
Just hope to God that you didn't hit the letter q beforehand, cause if you did... I will be frank, not even Jesus can save you. You're stuck in hell.
NAH, RELAX! just kidding with ya, if anything just hit CAPITAL letters |ZQ| in sequence and you will be out and free (we hold nobody hostage).
There are multiple CMDS you can use in NORMAL MODE (AKA. :COMMAND MODE).
When in -- INSERT -- MODE you can get back to NORMAL MODE by mashing either:
|ESC| ; |CTRL-[| ; |CTRL-C| OR |CTRL-O|
If these didn't work, hit |q| to possibly exit macro REC mode, and try again.
NORMAL MODE CMDS and KEYMAPS to :quit VIM
whatever is inside [...] is optional.
-
:q[uit][!]:: Quits the current window (fails with unsaved changes). -
|CTRL-W_q|:: Just like :q, attempts to :quit current buffer/window. -
:conf[irm] q[uit]:: Attempts :quit but gives prompt when changes have been made, or when the last file in the arg list has not been edited. -
:q[uit]!:: Force :quit, discarding changes and |hidden| buffers. -
:wq:: Writes current file and attempts to :quit (fails when READ-ONLY). -
:w !sudo tee %:: Writes changes to RO file with !sudo tee %. -
:!sudo vim %:: Re-opens current file with superuser privileges. -
:x:: AKA. :exit and same as :wq -
|ZZ|:: Writes current file if modified, and closes current window (:x). -
|ZQ|:: Quits without checking for changes (same as :q!). -
:bd[!] [N]:: Unloads buffer [N] or current buffer. To delete all buffers instead, use :%bd. You can also list all buffers and their respective [N] IDs with use :ls[!].QUICK TIP: Use |[N] CTRL-^| to SWITCH/GOTO buffer [N]. -
:qall[!]:: Quits ALL buffers unless any of them have unsaved changes. -
:wq [++opt] [file]:: Writes the current file and closes the window. If this is the last |edit-window| vim quits. Writing fails when the file is READ-ONLY or the buffer does not have a name. Quitting fails when the last file in the arg list has not been edited. You can also provide ++opts. Let's say you want to force Unix like endings (\n) and update the current file to a specific encoding, you can do that with: :w ++ff=unix ++enc=UTF-8 -
:[range]wq[!] [++opt] {file}:: Writes [range] to {file} (forces with!)NOTE: range overrides the {file} :: For example -> :22,42wq snippet.txt overwrites snippet.txt with the buffer's content contained in lines 22 to 42, then quits VIM. In the same vein, :1,10w! is VERY DANGEROUS, it overrides the current file with the specified range. -
|CTRL-Z|:: Suspends VIM with a SGTSTP signal and hands control back to the $SHELL where you can proceed to execute any command(s). To resume the stopped VIM job and bring it back to the foreground, simply runfg [N]:
KEYMAP: |CTRL-Z| [1]+ Stopped vim .$ wget https://1.1.1.1 -O index.html --2025-12-21 07:58:40-- https://1.1.1.1/ Connecting to 1.1.1.1:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://one.one.one.one/ [following] HTTP request sent, awaiting response... 200 OK Length: 56614 (55K) [text/html] Saving to: ‘index.html’ index.html 100%[============>] 55.29K --.-KB/s in 0.008s index.html saved [56614/56614]$ ls a.txt b.txt c.txt index.html$ vim index.html# literally anything you want, even emacs!! KEYMAP: |CTRL-Z| [2]+ Stopped vim index.html$ fg 1# will open and resume 1st SUSPENDED VIM job
-
OR :: Don't exit VIM it at all:
-
:sh[ell]:: Starts a shell. When the shell exits you return to VIM. -
:!{cmd}:: Executes {cmd} with the shell. -
:!gcc % -o app:: Recompiles % (current .c file). -
:!!:: Repeats the last CMD. -
:.!shruns the current line in sh and replaces it with STDOUT. -
:ter[minal] [options] [command]:: Opens a new new terminal window right inside VIM (|CTRL-\CTRL-B| to enter VISUAL mode).
-
There is SO much that I haven't covered. Consult the LORDS :help BOok for more.
FUN FACT: Who needs an EDITOR when you have MEOW!?
$ cat > newfile.txt Cat listens for stdin, then redirects it to stdout. Likewise, you can append to newfile.txt with >> And, on the last line use |C-D|C-D| to signal END.$ cat newfile.txt Cat listens for stdin, then redirects it to stdout. Likewise, you can append to newfile.txt with >> And, on the last line use |C-D|C-D| to signal END.