vi Editor – Visual editor

Introduction

The vi editor is a screen-oriented, full-screen text editor used in UNIX and Linux operating systems. It is one of the oldest and most powerful text editors, designed to work efficiently from the command line. The name vi comes from “visual editor”. Because of its speed, small size, and availability on almost every UNIX/Linux system, vi is widely used by system administrators, programmers, and students.


Features of vi Editor

  • Works completely in terminal/command-line
  • No graphical interface required
  • Very fast and lightweight
  • Supports keyboard-based editing
  • Available by default on almost all UNIX/Linux systems
  • Can edit very large files efficiently

Working Principle of vi

The vi editor works using different modes. Each mode has a specific purpose. This mode-based working style makes vi very powerful but slightly difficult for beginners.


Modes of vi Editor

1. Command Mode (Normal Mode)

  • This is the default mode when vi starts.
  • Used for navigation, deleting, copying, pasting, saving, and quitting.
  • No text can be typed in this mode.
  • Press Esc anytime to return to command mode.

Examples:

dd   → delete a line
yy   → copy a line
p    → paste copied text
u    → undo last change

2. Insert Mode

  • Used to enter or modify text.
  • You can type characters normally in this mode.
  • Enter Insert Mode using:
i  → insert before cursor
a  → insert after cursor
o  → open a new line below
  • Exit Insert Mode by pressing Esc.

3. Last Line Mode (Ex Mode)

  • Used for saving files, quitting, searching, and replacing text.
  • Enter this mode by typing : in command mode.

Common commands:

:w      → save file
:q      → quit
:wq     → save and quit
:q!     → quit without saving

Starting vi Editor

To open a file in vi:

vi filename

Example:

vi notes.txt
  • If the file does not exist, vi will create it.

Cursor Movement Commands

h → move left
l → move right
k → move up
j → move down

Text Editing Commands

x    → delete a character
dd   → delete a line
D    → delete from cursor to end of line
r    → replace a character

Copy and Paste Commands

yy   → copy a line
yw   → copy a word
p    → paste after cursor
P    → paste before cursor

Search and Replace

/word        → search forward
?word        → search backward
n            → next occurrence
:%s/old/new/g → replace all occurrences

Advantages of vi Editor

  • Available on almost every system
  • Extremely fast and efficient
  • Requires very less memory
  • Ideal for remote servers
  • Powerful editing commands

Disadvantages of vi Editor

  • Difficult for beginners
  • No mouse support
  • Commands must be memorized

Uses of vi Editor

  • Editing configuration files
  • Writing shell scripts
  • Programming in C, Python, etc.
  • System administration tasks
  • Editing files on remote servers

By admin

Leave a Reply

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