Vi - readline library cheat sheet

Bash Vi Editing Mode Cheat Sheet

In Bash, you can switch to Vi editing mode with the command set -o vi. Here’s a collection of the most useful shortcuts in Vi mode.

Modes

In Vi mode, you start in “command mode” where you can navigate and manipulate text but cannot insert new text. To insert or append text, you’d enter “insert mode.”

CommandDescription
EscEnter command mode
iEnter insert mode (before cursor)
IEnter insert mode (beginning of line)
aEnter insert mode (after cursor)
AEnter insert mode (end of line)
REnter replace mode

Cursor Movement

CommandDescription
hMove cursor left
lMove cursor right
jMove to previous command in history
kMove to next command in history
wMove forward one word
bMove backward one word
0 or ^Move to beginning of line
$Move to end of line

Editing Text

CommandDescription
xDelete the character under the cursor
XDelete the character before the cursor
dwDelete word from cursor to word end
dbDelete word from cursor to word start
D or d$Delete to end of line
d^Delete to beginning of line
ddDelete entire line
uUndo the last change
Ctrl-rRedo the last undo
pPaste text after cursor
PPaste text before cursor

Command History

CommandDescription
/Search backward in command history
?Search forward in command history
nRepeat the last / or ? command

Miscellaneous

CommandDescription
: followed by a commandExecute a command (e.g., :ls will run the ls command)
vEdit the current line in an external editor (usually vi or vim)

Note: Always remember that you start in command mode in Vi mode. Use i, I, a, A, or R to enter different variations of insert or replace mode.


** If you want to check what else I'm currently doing, be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message, you can send it to derik@rderik.com.