Linux: How to use the vi Editor

In Linux, there are different editors to edit text files. The most wide-spread editor is vi. Find below the basics on how to use vi:

Open a text file:
vi /etc/lighttpd/lighttpd.conf

There are 2 modes in vi:

  1. Command mode (you are in this mode right after starting vi)
    You can use keyboard keys to navigate, delete, copy, paste, save the file, quit vi and do a number of other tasks - except entering text
  2. Insert mode (-- INSERT -- will appear in the bottom line of vi)
    You can enter text, use the Enter key to add a new line, and also navigate with the keyboard keys

To change to Insert mode, press i
To change to Command mode, press Esc

The following commands can be used in Command mode:

  • :w Save (write) the file to disk and continue editing
  • :q! Quit vi without saving the file to disk (discard changes)
  • :wq Save the file to disk and quit vi

On some Linux distros there is an easier to use editor: Nano

Leave a Reply

Your email address will not be published. Required fields are marked *