How do I exit Vim?

Viewed 2711787

I am stuck and cannot escape. It says:

type :quit<Enter> to quit VIM

But when I type that it simply appears in the object body.

13 Answers

One guaranteed way is to kill the port that runs vim

! kill - 9 $(ps | grep vim | cut -d " " -f 1)

From any of four modes: insert, visual, command or command-line (ex) mode, press this to save if changed then exit vim:

Alt-Z Z

That is, press: alt + shift + z then shift + z

Why this works: From insert mode and apparently other modes, you can exit to command mode and do a command by the combination of holding Alt with any command character. The second Alt+Shift+Z is ignored, so you must let go of the Alt but keep the Shift. Work that muscle memory! :-)

Q-first vs. Colon-first

Many people know about the colon-q exit strategy. But for extra strategery and posterity, here is the q-colon-i-q method:

In Normal mode you can type:

q:iq<enter>

If you look closely and squint, you can almost read that command aloud as "quick," since this is the slow way to exit.

(Note: my attempt at humor notwithstanding, this does work!)

Related