A brief Introduction to the vi Text Editor on Ubuntu Linux

The tutorial introduces new users and students to the vi editor in Ubuntu Linux OS. Vi, a 43-year-old text editor, is widely used by Linux administrators, with more users opting for its improved version, Vim. Invoking vi to create or edit files is straightforward, and the editor operates in two modes: Command and Insert. The…

This brief tutorial introduces the vi editor to new users and students unfamiliar with Linux.

If you’re a student or new user looking for a Linux system to start learning on, the most accessible place to start is Ubuntu Linux OS. It’s a great Linux operating system for Linux beginners.

Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

The vi editor is the most popular and still the favorite command line text editor among Linux administrators for file creation and editing.

This 43-year-old vi (pronounced vee-eye) editor is still an advanced, simple-to-use editor that most system admins use when editing configuration files, creating lists, and writing scripts via the command line.

The vi editor has a symbolic link or alias to vim (vi Improved). Vim is an improvement to the original vi and much more straightforward to use than vi. More people are using the Vim editor than just vi.

It is straightforward to invoke the vi editor.

Simply use the commands below to create a new file or edit an existing file when the name filename.txt

vi filename.txt

The vi (aka, vim) has Command and Insert modes.

When you open the file with the vi command, it puts you in command mode. This mode allows you to use the keyboard to navigate, delete, copy and paste, and do other tasks.

You can not enter text in the command mode.

To leave the command mode and enter the insert mode, press the I key on your keyboard.

In the Insert mode, you can enter text, use the Enter key to go to a new line, and use the arrow keys to navigate the text and other tasks. After editing the text, press the Esc key to return to the command mode.

To save a file after editing, you must first be in the command mode. From the Insert mode, press the Esc key to go to the command mode, then press these keys:wq to save the file’s content and exit.

:w ====> Write
:q ===== Quit

You can also use the ZZ key to write or save your content and quit the vi editor.

If you made a mistake and edited the file and want to abandon all your changes and leave the file as is, simply run the commands below:

Esc key to return to the command mode, then press:q!

Below is a table of the vi command options:

vi switchesPurpose
vi filename.txt Create or edit an existing file
iSwitches to Insert mode from the command mode
EscSwitches to the command mode from the Insert mode
:wWrite or save your changes while in the Insert mode and continue editing
:wq or ZZSave your changes and exit or quit the vi editor
:q!Quit  vi and abandon all changes to the file
yyCopy the line of the file while in the command mode
pPaste a line below the current line
oThe open new line below the current line
OOpen a new line above the current line
ddDelete the entire line
GGo to the last line of the file
ggGo to the first line of the file
:numDisplay the number line’s line number
hMove to the left character
kMove up one line.
jMove down one line
lMove right one character
XGGo to X in the line

As you can see in the table above, you do a lot with the vi editor. If you learn these options, you should be comfortable using vi as a text editor on the command line terminal.

That’s it!

Richard Avatar

Comments

Leave a Reply

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