What Does vi Stand For?

The classic vi or visual editor comes pre-installed in all Linux distributions and works as a text editor on your terminal screen. It is used to read, write, or edit the contents of a text file, and users like it because of its user-friendliness, but to get full advantage of it, you’ve to learn a few things to pave your way through it.

Although an advanced version of vi called VIM or vi-improved comes with a few more features, the old one is gold.

This guide will explain everything about the vi editor while covering the following aspects.

In the sections below, we’d explain each of the above in detail.

What is the vi editor?

The vi editor is the default text editor in Unix-like systems, which makes it quite famous? It may lack modern features but is still used by many professionals due to ease of use and being more user-friendly. There are two modes of the vi editor that include the following.

Command Mode: The vi editor, when launched, opens up in the command mode that allows free movement of the cursor across the file while allowing copy, pasting, or deleting the text and saving or deleting the files.

Insert Mode: Inserting the text into a file can be done in this mode and invoked/revoked using the “a”/”ESC” keys.

Syntax of the vi editor

The syntax of the vi editor is like every other prominent text editor in Linux, which is as follows.

$ vi <File-Name>

The file was created before running this command, and you can also create a new file using the vi editor by using this command.

$ vi

When you see the above message, press any alphabetical key to start inserting the text; once done, press the “ESC” key to enter command mode, type this and press the “enter” key to save the file.

:wq <File-Name>

The “:wq” means to save and quit, and to create a new file, you’ve to enter its name of it, but this can only be done in the command mode.

To get more help regarding the vi editor, use this command.

$ vi --help

How to Use the vi in Linux?

While using the vi editor, you can use a good number of commands and options, which are as follows.

Options of vi

The options of the vi editor include the following.

-sTo remove all user feedback while executing the scripts
-lEnter the LISP mode
-LList the names of all files that were saved when the system last crashed
-ROpens the file in a read-only mode
-r file, -LTo recover the file that was being edited during the system crash (from the buffer)
-xFor encryption and decryption, using a key provided by the user also encrypts the temporary buffer

Other options are also available but aren’t as helpful and can be viewed through the help command.

Commands of vi Editor

The commands of the vi editor are used only in command mode (press the “ESC” key to enter” and include the following.

To Delete Text: You can delete the text using multiple commands, including the following:

dwDeletes the last word on the right of the cursor
ddTo delete the whole line where the cursor stands
dGDeletes the text from the current position of the cursor toward the end
d1GDeletes the text from the start of the file to the cursor
:5,10 dDeletes the lines from five to ten (you can change the numbers accordingly)

Copying or Moving the Text: The commands related to the copy/move functionality of the vi editor are listed in the following table:

:set nuTo view the line number(s)
:set nonuTo hide the line number(s)
yyCopy the whole line where the cursor is at
pPlace the deleted line below the current line
PPlace the deleted line above the current position of the cursor.
:1,2 co 3Copy lines (1,2) and place them after line 3 (the line numbers can be changed accordingly)
:1,2 mo 3Move lines (1,2) and place them after line 3 (the line numbers can be changed accordingly)

Searching a Line or Text: You can go to a specific line or find or replace the text using the following commands.

GView the ending line of the file
10GGo to line ten (numbers can be changed accordingly)
/Text-To-Be-SearchedSearches the text put after the “/”
:g/search/s//replace/gSearches and replaces the text entered.

Inserting a New File in the Current File: You can insert a new file into the currently opened file using these commands.

:r File-NameInserts the file before the cursor’s current position
:8 r File-NameInsert the file after the eighth line of the current file

Saving and Quitting: The file can quit with or without saving using these commands.

:wSaves changes but doesn’t quit
:wq or ZZSave changes and quit the vi editor
:q!To quit the vi editor without saving changes
:w File-NameWrite changes to the newly created file with the vi editor

Note: To read out detailed usage of these commands, read our “25 Vim Commands”.

Conclusion

The vi editor may be old, but as they say, “old is gold,” which is the same case here. It is one of the most widely used text editors. Although the VIM editor replaces it, people still prefer the original. This guide teaches the users everything about the vi editor, including what vi stands for in Linux.