The vi editor is a command-line text editor that is available on most Unix-based systems. It was originally created by Bill Joy for the BSD Unix operating system in the 1970s and has since become one of the most widely used text editors in the Unix/Linux world. The vi editor is a lightweight tool that is designed to run in a terminal environment, making it ideal for editing text files on remote servers or other headless systems.

Linux file options with vi editor:

  1. To open a file in vi:

vi filename

  1. To insert text in the file:

Press i to enter insert mode, then type the text.

  1. To save changes and exit:

Press Esc to exit insert mode, then type :wq and press Enter.

  1. To quit without saving changes:

Press Esc to exit insert mode, then type :q! and press Enter.

  1. To move the cursor:

Use the arrow keys or the h, j, k, and l keys (left, down, up, and right respectively).

  1. To delete text:

Press x to delete the character under the cursor, or press dd to delete the current line.

  1. To undo changes:

Press u to undo the last change.

  1. To search for text:

Press / and enter the text to search for, then press Enter.

  1. To replace text:

Press Esc to exit insert mode, then type :%s/old_text/new_text/g and press Enter, where old_text is the text to be replaced and new_text is the replacement text.

  1. To set editor options:
  1. :set number – displays line numbers on the left side of the screen
  2. :set autoindent – automatically indents new lines based on the previous line
  3. :set tabstop=4 – sets the tab stop to 4 spaces
  4. :set expandtab – converts tabs to spaces

These are just a few basic vi commands. There are many more commands and options available in vi, and it can take some time to become proficient with the editor.