Working with Vi Editor in Unix

Working with Unix Vi Editor:

Vi is the standard editor that is available on Unix systems.

This visual editor enables manipulation of text while showing a screenful of text unlike ‘sed’ that works at the line level. 

Unix Video #12:

Modes of Unix Vi Editor

The vi editor has three modes of operation viz. the command mode, the insert mode, and the ex-command mode.

#1) Command mode:

In this mode, all the keys work as commands. These keys are used for inserting, appending, deleting, opening new lines, moving the cursor over the paragraphs and sentences, etc. In this mode, the keys are not displayed but each key performs an operation.

By default the vi editor is in command mode, hence we cannot type text in command mode. In order to write programs or text in vi editor, we need to switch to the insert mode which can be done by pressing the escape button.

#2) Insert mode:

In this mode, we can insert, append, edit or replace texts. We can switch from the command mode to Insert mode by pressing the escape button and then press I or A to enter into insert mode.

#3) Ex command mode:

This mode is used for entering commands at the bottom line of the vi editor called as a command line. To switch to Ex command mode press escape key then type: (colon). In order to save the contents and quit from the vi editor press wq after the : (colon). i.e :wq.

Vi editor saving  and quitting commands:

:w -Save the contents of the file.

:q – Quit from vi editor.

:q! -quit from vi editor by discarding any changes.

:wq -Save the file and quit from the vi editor.

This tutorial will cover the various commands that are used in the command and ex-command modes. This includes commands to navigate around the screen by paragraph, line, word or character.

We will also cover commands for switching the mode, deleting characters, words, lines or paragraphs.

Our upcoming tutorial will brief more on the Features in Shell Scripting!!

PREV Tutorial | NEXT Tutorial