vi
Modes:
Command Mode: Press
escto enter. Use single key commands for navigation, editing, and file operations.Insert Mode: Press
i,a, oroto enter. Type text normally. Pressescto return to Command Mode.
Movement:
h, j, k, l: Move left, down, up, right (one character)
H, M, L: Move to top, middle, bottom of screen
0 (zero): Move to beginning of line
$: Move to end of line
n, N: Find next/previous occurrence of current word
b, B: Move to beginning/end of word
G: Go to specific line number (e.g.,
G10)gg: Go to the very beginning of file
Ctrl-f, Ctrl-b: Page forward/backward
Editing:
x: Delete current character
X: Delete current line
d: Delete (repeat for more characters/lines)
dw, de: Delete word or to end of word
yy, yank: Copy current line
p: Paste copied text
r: Replace current character with new character
c: Change (replace) text (e.g.,
cwto change word)I: Enter Insert Mode at beginning of line
A: Enter Insert Mode at end of line
o: Enter Insert Mode below current line
Saving and Quitting:
:w (write): Save changes
:wq (write & quit): Save changes and quit
:q (quit): Quit without saving (may prompt)
Other:
:set nu (number): Show line numbers
/, ?: Search forward/backward for text
!:command: Run shell command
Remember:
escis your escape key in Command Mode.Most commands can be prefixed with a number for repetition (e.g.,
3dddeletes 3 lines).Explore
:helpfor more advanced commands and options.
Last updated