Prabhjot Kaur Kang
An Engineering graduate by qualification and currently serving in an Info Tech. MNC, she consistently stayed a record-setter (Habitual Scholar) during her college tenure. With her remarkable passion for studies and an equal enthusiasm of sharing it to needful lads, she currently accounts for majority of IT related information at XAmplified.
Table Of Content
Introduction
VI is a standard UNIX editor which is fast and powerful. It has short commands and basic modes to work with.It do not have any menus.
VI Modes
Various modes of a VI Editor are as follows:
Command Mode
It is the default mode of a VI editor and it is used for text manipulation and cursor moving. These commands are case-sensitive and some of the commands do not appear on screen when written but appear on the last line.
Command for entering, deleting and changing text
- I – Enter text entry mode
- X –Delete a character
- dd – Deleting whole line
- r – Replacing a character
- R – Overwriting text
One must be in command mode before exiting VI Editor.
Commands for quitting editor
- ZZ – Write and quit (when changes are made)
- :wq – Write and quit
- :q – quit if file has not been changed
- :q! – quit without saving changes to the file.
Insert (or Text) Mode (Overtype Mode)
It is a designed for inserting text only. There is more than one way to get into insert mode but only one way to leave. You can return to command mode by pressing ‘:’
The only difference in ‘Insert mode’ and ‘Overtype mode’ is that characters are placed in front of text after the cursor in Insert mode, whereas existing characters are overwritten in Overtype mode.
Entering Insert Mode
- a – Append text after curser
- I – Insert text before curser
- R – Enter overtype mode
- A – Append text after end of line
- I – Insert text before first non-white space character
- o- Open new line below curser in Insert mode.
- O – Open new line above curser in Insert mode.
Basic VI session
To open a file and work upon it in a VI Editor, one can use following set of commands.
- To enter VI type, vi: filename
- To enter Insert/text mode, type: I .Now, type the text
- Return to command mode by pressing ‘:’
- In command mode, save changes and exit VI Editor by typing ‘: wq’
Ex commands
‘Ex’ are known as execute commands which are used to execute command on specific lines obtained from the address part of the general form. If address is admitted then current line can be used.
So ‘ex’ acts as a line based editor.
Environment variables can also be set in the VI Editor by command
‘set var = value’
References
- VI reference Manual for the VI text editor, Link : gnulamp.com/vieditor htm.