Introduction to vim
vimstands for Vi IMproved- It’s a highly configurable, powerful, command-line-based text editor
- Often pre-installed on most Unix/Linux systems
- Backward compatible with the original
vieditor
Starting Vim
vim filename # Open or create a file with vimVim Modes
| Mode | Purpose |
|---|---|
| Normal | Default mode for navigation and commands |
| Insert | For editing/inserting text |
| Visual | For selecting and manipulating blocks of text |
| Command | For executing colon (:) commands (save, quit etc) |
Mode Switching
Esc– Return to Normal mode from Insert/Visuali– Insert before cursora– Append after cursoro– Open new line below and enter Insert modev– Enter Visual mode:– Enter Command mode (starts with colon)
Basic Editing
Insert Text
i– insert at cursorI– insert at start of linea– append after cursorA– append at end of lineo– open new line belowO– open new line above
Delete Text
x– delete character under cursordd– delete current linedw– delete wordd$– delete from cursor to end of lineu– undoCtrl + r– redo
Copy/Paste (Yank/Put)
yy– yank (copy) current lineyw– yank wordp– paste after cursorP– paste before cursor
Saving and Exiting
| Command | Meaning |
|---|---|
:w | Save (write) file |
:q | Quit |
:wq or ZZ | Save and quit |
:q! | Quit without saving |
Navigation
| Key | Action |
|---|---|
h, j, k, l | Move left, down, up, right |
0, ^, $ | Start, first non-whitespace, end of line |
w, b, e | Move by word forward/backward/end |
gg, G | Go to beginning/end of file |
:n | Go to line n |
Searching
/pattern # Search forward
?pattern # Search backward
n # Repeat search forward
N # Repeat search backwardSummary
Vim is modal, fast, and lightweight. To get comfortable:
- Practice switching modes
- Learn movement commands
- Use
:wqto save and quit
To exit without saving: Esc → :q!
Last updated on