What Are Vim Motions?
Vim motions are commands that allow you to move the cursor efficiently within a file. They are the foundation of Vim’s powerful editing capabilities, as they can be combined with operators (like d
for delete, y
for yank, or c
for change) to perform complex text manipulations with minimal keystrokes. Motions can be used to navigate by characters, words, lines, paragraphs, sentences, or even search patterns.
You Don’t Need Vim to Use Vim Motions
You don’t need to use the Vim editor to start learning Vim motions. If you’re already comfortable with VS Code, you can use Vim motions by installing the popular Vim extension for VS Code. This extension brings Vim-like keybindings and motions to VS Code, allowing you to practice and get used to Vim’s navigation and editing style.
Once you’re comfortable with Vim motions in VS Code, you can easily transition to the Vim editor for an even more powerful and efficient workflow.
Types of Motions
Type | Description |
---|
Character Motions | Move the cursor by individual characters. |
Word Motions | Jump between words or WORDS (ignoring punctuation). |
Line Motions | Navigate to the start, end, or specific parts of a line. |
Paragraph/Sentence | Move between logical blocks of text. |
Search Motions | Quickly find specific text or patterns. |
Screen Motions | Navigate relative to the visible portion of the screen. |
Text Object Motions | Operate on logical text objects like words, sentences, or paragraphs. |
Mark and Jump Motions | Jump to specific marks or previous positions in the file. |
Why Use Motions?
Benefit | Description |
---|
Efficiency | Motions reduce the need for repetitive arrow key presses. |
Precision | They allow you to target specific parts of your text with ease. |
Combination | When combined with operators, motions enable powerful editing workflows. |
For example, daw
deletes a word, including surrounding spaces.
Learn More
Character Motions
Command | Description |
---|
h | Move left (←) |
l | Move right (→) |
Word Motions
Command | Description |
---|
w | Move to the start of the next word |
W | Move to the start of the next word (ignores punctuation) |
e | Move to the end of the current/next word |
E | Move to the end of the current/next word (ignores punctuation) |
b | Move to the start of the previous word |
B | Move to the start of the previous word (ignores punctuation) |
Line Motions
Command | Description |
---|
0 | Move to the beginning of the line |
^ | Move to the first non-whitespace character of the line |
$ | Move to the end of the line |
Paragraph Motions
Command | Description |
---|
{ | Move to the beginning of the current/previous paragraph |
} | Move to the end of the current/next paragraph |
Search Motions
Command | Description |
---|
/pattern | Search forward for pattern |
?pattern | Search backward for pattern |
n | Repeat the last search forward |
N | Repeat the last search backward |
Sentence Motions
Command | Description |
---|
( | Move to the beginning of the current/previous sentence |
) | Move to the beginning of the next sentence |
Screen Motions
Command | Description |
---|
H | Move to the top of the screen |
M | Move to the middle of the screen |
L | Move to the bottom of the screen |
Command | Description |
---|
Ctrl-d | Scroll down half a screen |
Ctrl-u | Scroll up half a screen |
Ctrl-f | Scroll down a full screen |
Ctrl-b | Scroll up a full screen |
zz | Center the current line in the screen |
Search for Matching
Command | Description |
---|
% | Jump to the matching parenthesis, bracket, or brace |
Text Object Motions
Command | Description |
---|
aw | A word (including surrounding spaces) |
iw | Inner word (excluding surrounding spaces) |
aW | A WORD (ignores punctuation, includes spaces) |
iW | Inner WORD (ignores punctuation, excludes spaces) |
ap | A paragraph (including surrounding spaces) |
ip | Inner paragraph (excluding surrounding spaces) |
as | A sentence (including surrounding spaces) |
is | Inner sentence (excluding surrounding spaces) |
Mark and Jump
Command | Description |
---|
'' | Jump to the position before the last jump |
```` | Jump to the position before the last edit |
g; | Jump to the last change |
g, | Jump to the next change |
Line Number Motions
Command | Description |
---|
gg | Go to the beginning of the file |
G | Go to the end of the file |
nG | Go to line n |
Search for Characters
Command | Description |
---|
f<char> | Move to the next occurrence of <char> on the current line |
F<char> | Move to the previous occurrence of <char> on the current line |
t<char> | Move to just before the next occurrence of <char> on the current line |
T<char> | Move to just before the previous occurrence of <char> on the current line |
; | Repeat the last f , F , t , or T motion forward |
, | Repeat the last f , F , t , or T motion backward |
Visual Mode Motions
Command | Description |
---|
v | Start visual mode |
V | Start visual line mode |
Ctrl-v | Start visual block mode |