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

3

5

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

Counterfoil answered 15/11, 2017 at 19:4 Comment(0)
T
10

: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.

Trypsin answered 15/11, 2017 at 19:6 Comment(2)
:qa! will quit an unlimited number of buffers regardless of their saved-nessTorquemada
Don't forget to exit edit mode by pressing escape. For the truly new, it's possible to get stuck in edit mode.Nsf
A
1

The solution that has worked for me is

  1. Esp Z + Z
  2. :wq!
Abampere answered 6/4, 2021 at 16:56 Comment(0)
J
-2

you should type :q not q.Every command in vim should start with :

Juliojulis answered 27/2 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.