Unlock the power of modal editing with this comprehensive guide
VI (and its improved version Vim) is a powerful text editor available on almost all Unix-like systems. It's lightweight, efficient, and once mastered, can dramatically increase your text editing speed.
Unlike most editors, Vim uses modal editing with different modes for inserting text, navigating, and executing commands.
Default mode for navigation and commands. Press Esc to return to Normal mode from any other mode.
For inserting text. Enter with i, a, o, etc.
For selecting text. Enter with v (character-wise), V (line-wise), or Ctrl+v (block-wise).
For entering commands. Enter with :.
h left, j down, k up, l right
w next word, b previous word
0 start of line, $ end of line
Ctrl+f page down
Ctrl+b page up
gg top of file
G bottom of file
/pattern search forward
?pattern search backward
n next match
N previous match
i insert before cursor
a append after cursor
o new line below
O new line above
r replace character
cw change word
cc change line
c$ change to end of line
x delete character
dw delete word
dd delete line
D delete to end of line
yy yank (copy) line
yw yank word
p paste after cursor
P paste before cursor
u undo
Ctrl+r redo
:%s/old/new/g replace all
:s/old/new/g replace in line
:n,ms/old/new/g replace between lines
qq start recording macro 'q'
q stop recording
@q execute macro 'q'
:e file open file
:bn next buffer
:bp previous buffer
:bd close buffer
:sp horizontal split
:vsp vertical split
Ctrl+w then arrow key to navigate
:set number show line numbers
:set relativenumber relative numbers
:set nonumber hide line numbers
While VI is the original editor, Vim (Vi Improved) adds many features:
Most commands work in both editors, but Vim offers many enhancements.
Try out some Vim commands in the text area below (note: this is a simulation, not actual Vim):
1. Start by learning basic navigation (h, j, k, l) and how to switch between modes.
2. Practice daily for 15-30 minutes to build muscle memory.
3. Force yourself to use Vim for all text editing tasks.
4. Learn one new command each day and practice it until it becomes natural.
5. Customize your .vimrc file with settings that work for you.
• Vim has a steep learning curve but pays off in the long run.
• Don't try to learn everything at once - focus on the commands you use most often.
• If you get stuck, press Esc to return to Normal mode.
• To exit Vim, type :q to quit or :wq to save and quit.