If you work with Linux or Unix systems, you’ve probably heard of the vi editor. Love it or fear it, vi is one of the most powerful and widely available text editors in the Unix world. This blog will help you understand what vi is, why it matters, and how to use it confidently.
What is vi?
vi (short for visual editor) is a command-line text editor available on almost every Unix/Linux system by default. It is lightweight, fast, and does not require a graphical interface—making it perfect for servers and remote systems.
Most modern systems actually use vim (Vi IMproved), which is backward compatible with vi and adds extra features.
Why Use vi?
Here’s why vi is still relevant today:
-
✅ Available on almost every Linux/Unix system
-
✅ Works in terminal-only environments
-
✅ Extremely fast and efficient
-
✅ Ideal for editing config files on servers
-
✅ Powerful keyboard-based controls
Once you get used to it, vi can be much faster than GUI editors.
Starting vi
To open a file using vi:
If the file doesn’t exist, vi will create it.
Understanding vi Modes
This is the most important concept in vi.
1. Command Mode (Default Mode)
-
Used to navigate, delete, copy, paste, save, and quit
-
You cannot type text in this mode
2. Insert Mode
-
Used to insert or edit text
-
Press
ito enter Insert Mode
3. Last Line Mode (Ex Mode)
-
Used for saving, quitting, searching, and replacing
-
Press
:to enter this mode
👉 Press Esc anytime to return to Command Mode
Common vi Commands
Switching Modes
| Action | Command |
|---|---|
| Insert at cursor | i |
| Insert at line start | I |
| Insert at line end | A |
| Exit insert mode | Esc |
Saving and Quitting
| Action | Command |
|---|---|
| Save file | :w |
| Quit | :q |
| Save and quit | :wq |
| Quit without saving | :q! |
Navigation Commands
| Action | Command |
|---|---|
| Move left | h |
| Move right | l |
| Move up | k |
| Move down | j |
| Beginning of line | 0 |
| End of line | $ |
| Go to line number | :10 |
Editing Text
| Action | Command |
|---|---|
| Delete a character | x |
| Delete a line | dd |
| Copy a line | yy |
| Paste | p |
| Undo | u |
| Redo | Ctrl + r |
Searching and Replacing
Search
-
Press
nfor next match -
Press
Nfor previous match
Replace
-
Replaces all occurrences in the file
Useful Tips for Beginners
-
🔹 Always remember
Escis your safety key -
🔹 If stuck, press
Esctwice -
🔹 Use
:set numberto show line numbers -
🔹 Practice with small files first
When Should You Use vi?
-
Editing config files like
/etc/passwd,/etc/ssh/sshd_config -
Working on remote servers via SSH
-
Quick file edits without installing software
-
Emergency troubleshooting in minimal environments
No comments:
Post a Comment