How to exit the Vim editor when :q or :x doesn't work

Viewed 11368

Newbie to vi / vim, I normally use pico but using a locked down box (for now) that only has these 2 editors.

I am having trouble getting it to save a file or even just quit. I see others having the same issue and they were told to use :x but even that doesn't work, just throws up an error message.

Is there an exit command that JUST works?

thanks

2 Answers

:q should work, unless the file hasn't been saved.

:q! will work.

:wq will attempt to save and quit, but won't quit if it can't save.

:wq! will attempt to save, and then quit whether or not it can save.

E: Credit to @GregoryNisbet for reminding me: if you have multiple files open, there is a series of 'all' quit commands:

:qa should quit all buffers (open files, more or less).

:qa! will quit all buffers regardless of if they have been saved.

:wqa will attempt to save and quit all buffers.

:wqa! will attempt to save all buffers, and then quit whether or not they are saved.

The solution that has worked for me is

  1. Esp Z + Z
  2. :wq!
Related