This article lists the most commonly used commands and shortcuts in Vim (not all), please make good use of the search.
Vim Keymap
Global Commands#
Command / Shortcut | Function Description |
---|---|
elp keyword | Display help for the specified keyword |
eas filename | Save as... |
se | Close the current window |
minal | Open a new terminal window |
:! command | Temporarily leave Vim to execute command in the command line and display the result |
K | Open the man page for the word under the cursor |
Move Cursor#
Command / Shortcut | Function Description |
---|---|
h | Move cursor left |
j | Move cursor down |
k | Move cursor up |
l | Move cursor right |
H | Move to the top of the current page |
M | Move to the middle of the current page |
L | Move to the bottom of the current page |
w | Move to the beginning of the next word |
W | Move to the beginning of the next word (including punctuation) |
e | Move to the end of the next word |
E | Move to the end of the next word (including punctuation) |
b | Move to the beginning of the previous word |
B | Move to the beginning of the previous word (including punctuation) |
% | Jump to the matching symbol |
0 | Move to the beginning of the line |
^ | Move to the first non-blank character of the line |
$ | Move to the end of the line |
} | Move to the next paragraph (or function/code block when editing code) |
{ | Move to the previous paragraph (or function/code block when editing code) |
zz | Center the cursor on the screen |
Ctrl + e | Scroll down one line (keeping the cursor in place) |
Ctrl + y | Scroll up one line (keeping the cursor in place) |
Ctrl + b | Scroll up one screen |
Ctrl + f | Scroll down one screen |
Ctrl + d | Scroll down half a screen |
Ctrl + u | Scroll up half a screen |
Insert Mode#
Command / Shortcut | Function Description |
---|---|
i | Start inserting characters from before the cursor |
I | Start inserting characters from the beginning of the line |
a | Start inserting characters from after the cursor |
A | Start inserting characters from the end of the line |
o | Start a new line below the current line and begin inserting characters |
O | Start a new line above the current line and begin inserting characters |
ea | Start inserting from the end of the current word |
Ctrl + h | Delete the character before the cursor in insert mode |
Ctrl + w | Delete the word before the cursor in insert mode |
Ctrl + j | Start a new line in insert mode |
Ctrl + t | Indent right in insert mode, width controlled by shiftwidth |
Ctrl + d | Indent left in insert mode, width controlled by shiftwidth |
Ctrl + n | Insert the next match of auto-completion before the cursor in insert mode |
Ctrl + p | Insert the previous match of auto-completion before the cursor in insert mode |
Ctrl + rx | Insert the contents of register x at the current cursor position |
Esc | Exit insert mode |
Edit Text#
Command / Shortcut | Function Description |
---|---|
u | undo - Undo the last operation |
U | Restore/undo the last modified line |
Ctrl + r | redo - Redo (opposite of u) |
. | Repeat the last command |
Select Text and Visual Mode#
Command / Shortcut | Function Description |
---|---|
v | Enter visual mode, move the cursor to highlight selection, then execute commands on the selected text |
V | Enter visual mode, select by line |
o | In visual mode, toggle the cursor between the start and end of the selection |
O | In visual mode, toggle the cursor to the corners of the selection |
Ctrl + v | Enter visual mode, block selection (i.e., column mode) |
aw | In visual mode, select the current word |
ab | In visual mode, select the content wrapped in () (including parentheses) |
aB | In visual mode, select the content wrapped in {} (including braces) |
at | In visual mode, select the content wrapped in <> (including <> tags) |
ib | In visual mode, select the content wrapped in () (excluding parentheses) |
iB | In visual mode, select the content wrapped in {} (excluding braces) |
it | In visual mode, select the content wrapped in <> (excluding <> tags) |
Esc | Exit visual mode |
> | Indent right |
< | Indent left |
y | Copy the selected text |
d | Cut the selected text |
~ | Toggle the case of the selected text |
u | Convert the selected text to lowercase |
U | Convert the selected text to uppercase |
Exit#
Command / Shortcut | Function Description |
---|---|
Write the edited data to disk (save) | |
! | Force write the file if it is read-only |
!sudo tee % | Save the current file using sudo |
or or ZZ | Save and exit |
Exit (Vim will warn if the file has been modified and not saved) | |
! or ZQ | Force exit (even if the file is not saved, equivalent to force exit) |
Save all tabs and exit |
Vim Modes#
Mode | Entering Method |
---|---|
Normal Mode | Enter by pressing Esc or Ctrl+[ ; filename or empty at the bottom left |
Insert Mode | Enter by pressing i; --INSERT-- at the bottom left |
Visual Mode | Enter by pressing v; --VISUAL-- at the bottom left |
Replace Mode | Start by pressing r or R; --REPLACE-- at the bottom left |
Command Line Mode | Start by pressing : or / or ? |