Basics of VI editor

VI Editor

In Unix or Linux Operating systems, we use VI editor to create scripts or make changes to configuration files or programs.

Below commands might be useful for you at the initial stages.

Procedure to create or edit file is as shown below.

  1. Open the terminal application in Linux or Unix
  2. Next, open a file or create a file in  vi, type: vi filename
  3. To save a file in  vi, press Esc key, type :w and hit Enter key
  4. One can save a file and quit  Vi by pressing Esc key, type :x or :wq! and hit Enter key.
  5. If you do not want to save any changes, first press Esc key. To exit Vi without saving changes press :q! followed by ENTER key

Summary of vim/vi commands

CommandDescription
Press the ESC key
Type :q!
Press the ENTER key
Exit vim without saving changes i.e. discards any changes you made.
Press the ESC key
Type :wq
Press the ENTER key
Save a file and exit.
Press the ESC key
Type :x
Press the ENTER key
Save a file and exit.


Comments