~3 min read • Updated Jul 19, 2025
1. Why Learn vi?
- Universal Availability: Installed by default on most Unix systems via POSIX compliance
- Speed and Efficiency: Minimal startup time and memory usage
- Command-Line Fluency: Considered a core Unix skill
2. Launching and Configuring vi
vi filename.txtTo enable improved vim features:
echo "set nocp" >> ~/.vimrc3. Exiting vi
:q # Quit
:q! # Quit without saving
:w # Save file
:wq # Save and quit
ZZ # Save and quit (shortcut)
Press Esc to return to command mode if uncertain.
4. Understanding Modes
- Command Mode: For navigation and operations
- Insert Mode: Entered via
i,a,o,A, etc. - Switch back to command mode with
Esc
5. Cursor Movement
h / l # Move left / right
j / k # Move down / up
0 / $ # Start / end of line
w / b # Next / previous word
G / 1G / 5G # Go to last / first / specific line
Ctrl+F / Ctrl+B # Scroll forward / backward
6. Basic Editing
i # Insert before cursor
a / A # Append after / at line end
o / O # Open new line below / above
x / 3x # Delete character(s)
dd / d$ / dW# Delete line / to end / word
u # Undo last change
7. Cut, Copy, Paste
dd # Cut current line
yy / yW # Copy line / word
p / P # Paste after / before
J # Join line with next
8. Search and Replace
/pattern # Search forward
n # Repeat last search
:%s/old/new/g # Replace globally
:%s/term/Term/gc # Confirm each replacement
9. Working with Multiple Files
vi foo.txt bar.txt # Open multiple files
:bn / :bp # Next / previous buffer
:buffers # List open buffers
:buffer 2 # Switch to buffer 2
:r otherfile.txt # Read contents into current file
10. Saving Variants
:w # Save file
:w newname.txt # Save as new file
:wq or ZZ # Save and exit
:q! # Quit without saving
Conclusion
The vi editor is a cornerstone of Unix and Linux text manipulation. Its modal architecture and speed offer unmatched control from the terminal. Though its interface may challenge new users, consistent practice reveals its depth for scripting, configuration, and system administration.
Written & researched by Dr. Shahin Siami