Vi Editor in Linux

Vi Editor in Linux

What is vi?

Vi is a short form for visual instrument. It is a screen-oriented text editor in the Linux family. It is referred to as a screen-oriented text editor because it features the ability to modify any visible text on the screen by moving the cursor to its location. Vi editor is a powerful and widely used text editor in the Linux (Unix - like) operating system. Vi has two modes:

  1. Command Mode: in this mode, you can use keyboard keys to navigate, delete, copy, paste, and do several other tasks—except entering text. This is the mode a user meets when he/she opens the vi editor. To be able to type in texts or codes, the user will have to enter into the insert mode by striking the I alphabet on the keyboard.

  2. Insert Mode: In insert mode, a user can enter texts and use vi as a free-form text editor. Performing command mode operations like using the Enter key to go to a new line and using the arrow keys to navigate text is also possible in this mode. To return to command mode, use the Esc key on the keyboard.

Who is Bill Joy?

Bill Joy played an integral role in the early development of BSD UNIX while being a graduate student at Berkeley. He is the original author of the vi text editor.

How to start vi

The vi editor can be started by using the command vi file_name. If the file doesn't exist, a file will be created with the file name specified.

How to cut and paste lines

Cutting lines in vi is done in the command mode. Be sure to press the Esc key before cutting. steps:

  • highlight the line you want to cut

  • press dd on the keyboard i.e. d twice

Pasting lines is as easy as cutting them. Still in command mode, press y on the keyboard. The copied or cut line will be pasted.

How to undo

To undo in vi, all you need to do is press the u key on the keyboard. This is to be done in command mode too.

How to quit vi

One can quit vi in many ways depending on what the user wants to do with the content written. They include:

  • Saving and quitting: After writing into a file, one can save and exit the editor. this is done by using the command :wq meaning write and quit.

  • Quitting without saving: If the user wants to exit a file without saving changes made, he/she is to use the command :q!

    Note: also done in command mode.