How to exit (quit) Linux vi editor with or without saving changes Step-by-Step

Direct answer

Incredibly simple; if you know how…. First how to launch vim From the command prompt: change to path where file is located with “cd” vi filename This will edit filename starting at line 1. ========================= To exit without saving changes made: Press <Escape>. (You must be in insert or append mode if not, just start […]

Incredibly simple; if you know how….

First how to launch vim

From the command prompt:

change to path where file is located with “cd”

vi filename

This will edit filename starting at line 1.

=========================

**To exit without saving changes made:**

1. Press <**Escape>**.

(You must be in insert or append mode if not, just start typing on a blank line to enter that mode)

1. Press **:** .

The cursor should reappear at the lower left corner of the screen beside a colon prompt. The colon indicates that what follows is a Vim command.

1. Enter the following:

                 q!

1. Then press .

This will quit the editor, and abandon all changes you have made; all changes to the document will be lost.

**To exit with saving changes made:**

1. Press <**Escape>**.

(You must be in insert or append mode if not, just start typing on a blank line to enter that mode)

1. Press **:** .

The cursor should reappear at the lower left corner of the screen beside a colon prompt. The colon indicates that what follows is a Vim command

1. Enter the following:

                 wq

Type “wq” , the “w” indicates that the file should be written, or saved which will overwrite existing file and the “q” indicates that vim should quit, or exit

1. Then press <Enter>.

This will quit the editor, and write all changes you have made; all changes to the document will be saved.

After exiting you can display the contents of the file with

cat filename

Dan Stolts

Founder and Chief AI Officer of Just In Time AI, with an IT career that began in 1988 -- nearly four decades of experience. Over a decade of that career went into building ITProGuru into a 250,000-uniques/mo IT-community resource, and he now applies the same teach-first approach to AI systems that run real businesses. Full profile →