DEV Community

@kon_yu
@kon_yu

Posted on

How to terminate Vim / Vi

I've opened and modified a vim or vi that I don't normally use when editing a configuration file, but I can't get back to the terminal from vim/vi.
How to terminate vim/vi (hereafter referred to only as vim) in such cases

First, press the escape key [Esc].

This will put Vim in neutral mode and allow you to enter commands

Enter the exit command.

You should see the command you're typing in the lower left corner of the screen.

When exiting a saved file from an open vim

:q
Enter fullscreen mode Exit fullscreen mode

Exiting vim without saving the file

:q!
Enter fullscreen mode Exit fullscreen mode

If you save the file and then exit the vim

:wq
Enter fullscreen mode Exit fullscreen mode

digression

I'm an uncle of emacs, so I must have forgotten how to terminate Vi.

Top comments (3)

Collapse
 
confusednerd profile image
confused-nerd • Edited

I have been using these for a while with some very basic usage with vi/vim. I have recently learnt a few alternatives are slightly different:

ZZ - Write current file, if modified, and close the current window (same as :x).
ZQ - Quit without checking for changes (same as :q!).

Reference vimhelp.org

Collapse
 
konyu profile image
@kon_yu

@confused-nerd
Thanks for your information. I didn't know those commands.

Collapse
 
aadavthomas profile image
AadavThomas

To save a file and exit Vi/Vim simultaneously, use the :wq command and hit. best tantrik in Jamshedpur