Linux Administrator

Understanding basic vi (visual editor)

The default editor that comes with the UNIX operating system is called vi (visual editor). [Alternate editors for UNIX environments include pico and emacs, a product of GNU.]

The UNIX vi editor is a full screen editor and has two modes of operation:

  • Command mode commands which cause action to be taken on the file, and
  • Insert mode in which entered text is inserted into the file.

In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the (Escape) key turns off the Insert mode.

The best way to learn about vi is with the vimtutor, you can start your lesson by typing the following command via SSH:

# vimtutor

In this article I will provide short list of a few commands that are very useful for beginners.

Opening a file in vi

This first line is just to simply open a file with vi:

# vi filename

The following command is used to recover a file that was being edited when the system crashed:

# vi -r filename

The next command will open a file as read-only:

# view filename

Find a line in vi

You can use the following to go to the last line in the file:


To go the the first line of the file, you can use the following:


Move around in the editor

  • type h to type move the cursor to the left
  • type l to move it to the right
  • type k to move up
  • type j to move down

Search within vi

To search for text in vi, you can use the “/” key followed by your search term. This example uses neo:

/ neo

Exit from vi

To quit and not save changes, you can use:


If you want to quit and save changes, you can use the following command:


Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment