Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm stuck and cannot escape. It says:

"type :quit<Enter> to quit VIM"

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

share|improve this question
32  
Are you just trying to quit VIM ? If this is the case, press "escape" and then type ':q' – Pop Aug 6 '12 at 12:28
9  
Don't forget the colon! You should type :quit and then hit the [ENTER] key. – Farahmand Mar 4 '14 at 18:33
2  
If you're chained to using the shell (perhaps you're SSHing to the server) and can't use something like Sublime, I also suggest nano (much easier to use and the hotkeys are always displayed at the bottom) – sjagr Nov 24 '14 at 20:03
9  
It's really easy to learn the basics of vim, and it's built right into your system. In terminal type "vimtutor". 25 minutes later you will be going faster than your usual text editor! – Mark Robson Jan 26 '15 at 12:11
5  
950 ^votes and 284 favorite marks for 'quitting vim'? Just ridiculous! Don't quit it! Well, fun apart but really, I can't believe it was asked in 2012 and got such a response (at that time, I believe most of such questions were getting downvoted vigorously just showing reasons as SO standards). – 0xc0de Nov 1 '16 at 7:05

10 Answers 10

up vote 1688 down vote accepted

Hit the Esc key; that goes into command mode. Then you can type

  • :q to quit (short for :quit)
  • :q! to quit without saving (short for :quit!)
  • :wq to write and quit (think write and quit)
  • :wq! to write and quit even if file has only read permission (if file does not have write permission: force write)
  • :x to write and quit (similar to :wq, but won't write if there are no changes)
  • :qa to quit all (short for :quitall)

When you press :, a : will appear at the bottom of the screen.

Or you can press Esc ZZ (Esc Shift+Z Shift+Z) to write/save if the file was changed, then quit.

Or if you don't want to save changes you can use ZQ instead.

Vim has extensive help, so type Esc:helpReturn and you will have all your answers and even a neat tutorial.

share|improve this answer
6  
Unless you have remapped esc or have a weird mapping in your .vimrc then it definitely should. If on linux type xev and make sure escape is the keytype you get when you hit escape. – dirvine Jun 11 '14 at 23:49
2  
Remember you can use ctrl+c if you can't use Esc (like me because my shell is in TotalTerminal). vim.wikia.com/wiki/Avoid_the_escape_key – dotnetCarpenter Jan 27 '15 at 15:12
8  
:x == ZZ but :x != :wq. :x write file iff file has changed, :wq write file always (matter i.e. when using inotify). – Łukasz Niemier Feb 5 '15 at 0:27
1  
@bgvaughan I don't find vim's help any use at all to discover and learn about new features. I use it purely as a reference. Fortunately there are books (practical vim) and sites (learn vimscript the hard way) which help here, plus there's a stack exchange site devoted to vim vi.stackexchange.com) – Dr Eval Sep 24 '15 at 10:20
1  
The first statement ("Hit the Esc key; that goes into command mode.") is based on a common misunderstanding of Vi(m). The Esc (if needed) is the final part of the current command, and when you finish it this way you can type the next command. – Olaf Seibert Oct 28 '15 at 16:23

Before you enter a command, hit the Esc key. After you enter it, hit the Return to confirm.

Esc finishes the current command and switches Vim to command-line mode. Now if you press :, the : will appear at the bottom of the screen. This confirms that you're actually typing a command and not editing the file.

Most commands have abbreviations, with optional part enclosed in brackets: c[ommand].

Commands marked with '*' are Vim-only (not implemented in Vi).

Safe-quit (fails if there are unsaved changes):

  • :q[uit] Quit the current window. Quit Vim if this is the last window. This fails when changes have been made in current buffer.
  • :qa[ll]* Quit all windows and Vim, unless there are some buffers which have been changed.

Prompt-quit (prompts if there are unsaved changes)

  • :conf[irm] q[uit]* Quit, but give prompt when there are some buffers which have been changed.
  • :conf[irm] xa[ll]* Write all changed buffers and exit Vim. Bring up a prompt when some buffers cannot be written.

Write (save) changes and quit:

  • :wq Write the current file (even if it was not changed) and quit. Writing fails when the file is read-only or the buffer does not have a name. :wqa[ll]* for all windows.
  • :wq! The same, but writes even read-only files. :wqa[ll]!* for all windows.
  • :x[it], ZZ(with details). Write the file only if it was changed and quit, :xa[ll]* for all windows.

Discard changes and quit:

  • :q[uit]! ZQ* Quit without writing, also when visible buffers have changes. Does not exit when there are changed hidden buffers.
  • :qa[ll]!*, :quita[ll][!]* Quit Vim, all changes to the buffers (including hidden) are lost.

Press Return to confirm the command.

This answer doesn't reference all Vim write and quit commands and arguments. Indeed, they are referenced in the Vim documentation.

Vim has extensive built-in help, type Esc:helpReturn to open it.

This answer was inspired by the other one, originally authored by @dirvine and edited by other SO users. I've included more information from Vim reference, SO comments and some other sources. Differences for Vi and Vim are reflected too.

share|improve this answer

If you want to quit without saving in vim and have vim return a non-zero exit code, you can use :cq.

I use this all the time because I can't be bothered to pinky shift for !. I often pipe things to vim which don't need to be saved in a file. We also have an odd SVN wrapper at work which must be exited with a non-zero value in order to abort a checkin.

share|improve this answer
2  
Upvoting this for introducing "pinky shifts" to my vocabulary <3 – Frederik Struck-Schøning Dec 12 '16 at 9:09
    
I also use this to abort a git commit, or visudo, or crontab, … – Josh Lee Feb 3 at 18:13

To my knowledge, vim is unexitable. Buying a new computer solved the issue for me.

share|improve this answer
3  
Thanks alot, you've just saved my day! :) – Andrey Rudenko Jan 24 at 12:14
    
kudos for fun answer – nilon Feb 7 at 5:17

In case you need to exit Vim in easy mode (while using -y option) you can enter normal Vim mode by hitting control + L and then any of the normal exiting options will work.

share|improve this answer
1  
Yet another option: you can use Ctrl+O to leave INSERT mode temporarily then enter :q. Trick with this combination is useful in normal vim as well to execute single command and return back to INSERT mode. – Andrey Starodubtsev Sep 17 '15 at 12:08

EscEscEsc:qa!Enter

This in case you have no idea what you've done while attempting to exit, and you don't want to write anything to the files.

It is possible that you enter e.g. insert mode, then visual mode and then operator pending mode and thus need to press Esc three times. (To try this, do iCtrl-ovg.)

However, that doesn't work if you have entered Ex mode. In that case you would need to do:

viEnter:qa!Enter

So a complete command for "I don't want to know what I've done and I don't want to save anything, I just want out now!" would be

viEnterEscEscEsc:qa!Enter

share|improve this answer
2  
Ahh what splendid efficiency. I mean, it's only 7 keystrokes to perform a frequently needed action – cavalcade Oct 29 '16 at 0:50

After hitting ESC (or cmd + C on my computer) you must hit : for the command prompt to appear. Then, you may enter quit.

You may find that the machine will not allow you to quit because your information hasn't been saved. If you'd like to quit anyway, enter ! directly after the quit (i.e. :quit!).

share|improve this answer

I got Vim by installing a Git client on Windows. :q wouldn't exit Vim for me. :exit did however...

share|improve this answer
    
Similarly for vim doing git on a macintosh this worked. – Joel Apr 29 '15 at 9:55
    
@Joel just checked this on my mac, both commands are legit (vim -version 7.3). – Nick Volynkin Jun 8 '15 at 13:47

Press Escape then
:q to quit (short for :quit)
:q! to quit without saving (short for :quit!)
:wq to write and quit (think write and quit)
:wq! to write and quit even if file has only read permission (if file does not have write permission: force write)

share|improve this answer

So, I guess like me you are not into Vim and want to Quit without Saving.

Just do the following

  • Press the Esc key.
  • Now type :cq
  • Then press Return or Enter.

And we are back home :)

share|improve this answer
4  
This adds nothing to the other answers. – Winger Sendon Jul 15 '16 at 10:31
    
@WingerSendon my solution is pretty simple! Didn't find a straight forward answer above. – Ahmad Awais Feb 10 at 11:06

protected by Yu Hao Nov 28 '14 at 15:30

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.