Mac OS X:: VI Keyboard Shortcut Cheat Sheet: Navigation Shortcuts Editing Exiting (Command Mode)
Mac OS X:: VI Keyboard Shortcut Cheat Sheet: Navigation Shortcuts Editing Exiting (Command Mode)
net
h Move cursor left one position r Replace a single character :w Write / save file, without exiting
j Move cursor down one line J Join current line to next line :wq Write / save file, and exit vi
k Move cursor up one line cc Replace entire line :q Quit (error if there are pending changes)
l Move cursor right one position cw Replace text from cursor to end of word :q! Force quit, discarding changes
w Jump to beginning of next word c$ Replace text from cursor to end of line
(punctuation) s Delete character under cursor, insert text Search / Replace
W Jump to beginning of next word (spaces) S Delete current line, insert text These vi commands help with searching for, and replacing
e Jump to end of next word (punctuation) u Undo last action text inside your plain text files.
E Jump to end of next word (spaces) - Redo last action
0 Jump to start of line /pattern Search for a regex pattern (forward)
$ Jump to end of line (similar to regex) Select Text Visual Mode ?pattern Search for a regex pattern (backward)
#G Go To specified line number These commands help you select text in what’s called n Find next search result
% Jump between parentheses or braces “Visual Mode.” There are several different visual modes N Find previous search result
though, so make sure you understand them all. :%s/old/new/g Replace all old with new (with prompt)
Note: Navigation shortcuts can be prefixed with a number, :%s/old/new/gc Replace all old with new (no prompts)
to repeat. For example: 5w will jump five (5) words ahead. v Enter Visual Mode, from Command Mode
21G will jump to line #21. This doesn’t work with the 0 V Enter Visual Mode (line-wise) Multi-file Editing
shortcut, for obvious reasons. Ctrl+v Enter Visual Block mode (select text grid) These commands help navigating multiple files in vi.
y Yank (copy) selected text
Insert Mode o Jump to opposing end of marked text :e filename Re-open the current file
These commands help you insert text in vi. O Jump to opposing corner (Visual Block Mode) :bnext (:bn) Move to next buffer
aw Mark the current word :bprev (:bp) Move to previous buffer
i Invoke Insert mode at cursor’s location ab Select (…) block, including parentheses :bd Delete the current buffer (close file)
I Insert at the beginning of the current line aB Select {…} block, including curly braces :sp filename Open file in new window
a Append text after the cursor’s location ib Select (…) block, excluding parentheses Ctrl+ws Split windows
A Append text at the end of the current line iB Select {…} block, excluding curly braces
o Append new / empty line after current line
O Append new / empty line before current line
Esc Exit Insert Mode, enter Command Mode