A brief Introduction to the vi Text Editor on Ubuntu Linux

omid armin ztvxSNFJih0 unsplash
omid armin ztvxSNFJih0 unsplash

This brief tutorial introduces the vi editor to new users and students who are not familiar with Linux.

If you’re a student or new user looking for a Linux system to start learning on, the easiest 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 run to 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 simple to use than vi. More people are using the vim editor than just vi.

It is very easy 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 two modes: Command and Insert.

When you first 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 go into the insert mode, you will have to 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. When you’re done, editing text, simply press the Esc key to go back 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 content of the file 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 which to abandon all your changes and leave the file as is, simply run the commands below:

Esc key to go back 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 with using vi as a text editor on the command line terminal.

That’s it!

Posted by
Richard W

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: