Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I started Vi on my Ubuntu machine. However I don't know Vi, and now I can not quit. I see the editor and I can write text, at the bottom line there is a label "recording".

How do I quit from Vi?

share|improve this question
1  
The "recording" by the way meant that you were recording a macro. Not that that matters any more. –  frabjous Oct 20 '10 at 23:19
2  
This question brings back such "fun" memories. I'm so glad I got over that feeling, however. –  frabjous Oct 21 '10 at 1:06
    
How we can come back in insert mode from read only mode in Linux (Ubuntu in VMware installed ) VI Editor? –  Prakash Kumar Arya Aug 21 at 17:39

4 Answers 4

up vote 11 down vote accepted

vim is a modal editor. Hit the ESC key to get into Normal (command) mode then type :q and press Enter.

To quit without saving any changes, type :q! and press Enter.

See also Getting out in Vim documentation.

share|improve this answer
3  
Thanks: I tried that commands, but after running them I was prompted with: E37: No write since last change (add ! to override). I have nothing to save. –  Jonas Oct 20 '10 at 22:49
    
Use :wq if you want to save what you have edited and then exit. :q! if you want to exit and leave your changes behind. –  Steven D Oct 20 '10 at 22:50
    
Or if you've written something you want to make a copy of, :w newFileName.txt, then sort out the read-only issue outside of vi or vim. –  Kevin Cantu Oct 20 '10 at 23:17
2  
quit :q ; force quit :q! ; quit and save :wq or :x –  fromnaboo Oct 6 '12 at 10:52

I use ctrl+[ to generate the esc sequence, this keeps me from having to move my fingers from the home row (remember the esc key was in a different place when vi was invented. :wq will write all files regardeless of necessity. I suggest using ZZ (which is shift+z twice) which will only write if a change has been made in the file. Also :xa is the same as ZZ except if you have more than 1 file open in the editor instance (such as vim tabs). note: I'm not sure all this is 100% compat with all vi clones, but I know it works with vim

share|improve this answer
1  
Thanks. The ZZ command seems to be useful. I can see the point with Ctrl+[ but I'm using a swedish keyboard layout and I have to press AltGr+8 to get [ so that would be Ctrl+AltGr+8 for me :( –  Jonas Oct 21 '10 at 1:17

As Sinan said, vim is a modal editor. If you want to know whether that works for you you should maybe invest some time and run vimtutor which is an interactive way to learn vim. (It also covers how to exit, what the modes mean and what you can do in each mode).

share|improve this answer

The quit from the vi is another way is Esc :x.

The option is used for save and quit at the same time.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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