Vim Motions & Navigation
Movement commands and navigation patterns.
Character Motions
" BASIC CHARACTER MOVEMENT
h " Left
l " Right
j " Down
k " Up
" WITH COUNTS
5j " Down 5 lines
10l " Right 10 chars
3k " Up 3 lines
" RELATIVE LINE NUMBERS (relativenumber setting)
" Shows distance from current line - use directly:
7j " Jump to line showing "7"
12k " Jump to line showing "12"
" SPACE AND BACKSPACE (less common)
<Space> " Like l (move right)
<Backspace> " Like h (move left)
" LINE WRAP BEHAVIOR
gj " Down within wrapped line
gk " Up within wrapped line
" Use when lines wrap on screen
Word Motions
" WORD (letters, digits, underscores)
w " Start of next word
b " Start of previous word
e " End of current/next word
ge " End of previous word
" WORD (non-blank sequences)
W " Start of next WORD
B " Start of previous WORD
E " End of current/next WORD
gE " End of previous WORD
" DIFFERENCE: word vs WORD
" Line: hello-world foo.bar
" w from start: hello → - → world → foo → . → bar
" W from start: hello-world → foo.bar
" WITH COUNTS
3w " Three words forward
2b " Two words back
5e " End of 5th word
" WITH OPERATORS
dw " Delete to start of next word
d2w " Delete next 2 words
ce " Change to end of word
cb " Change to start of word
ye " Yank to end of word
Line Motions
" HORIZONTAL LINE MOVEMENT
0 " Start of line (column 0)
^ " First non-blank character
$ " End of line
g_ " Last non-blank character
gm " Middle of screen line
g0 " Start of screen line
g$ " End of screen line
" PRACTICAL PATTERNS
d0 " Delete to line start
d$ or D " Delete to line end
c^ " Change from first char
y$ " Yank to end of line
" FIRST/LAST CHARACTER
" Line: " indented text "
0 " Moves to column 0 (space)
^ " Moves to 'i' (first non-blank)
$ " Moves to last space
g_ " Moves to 't' (last non-blank)
" COLUMN MOVEMENT
| " Go to column 0
5| " Go to column 5
80| " Go to column 80 (line length check)
" VERTICAL LINE MOVEMENT
+ " First non-blank of next line
- " First non-blank of previous line
_ " First non-blank of current line (like ^)
" LINE COUNTS
5+ " 5 lines down, first non-blank
3- " 3 lines up, first non-blank
Search Motions
" SINGLE CHARACTER SEARCH (within line)
f\{char} " Forward to char (inclusive)
F\{char} " Backward to char (inclusive)
t\{char} " Forward until char (exclusive)
T\{char} " Backward until char (exclusive)
" REPEAT CHARACTER SEARCH
; " Repeat f/F/t/T forward
, " Repeat f/F/t/T backward
" PRACTICAL PATTERNS
f: " Jump to colon (YAML editing)
f" " Jump to quote
ct, " Change until comma
df) " Delete through closing paren
dt" " Delete until quote (exclusive)
" PATTERN SEARCH
/pattern " Search forward
?pattern " Search backward
n " Next match (same direction)
N " Next match (opposite direction)
" WORD UNDER CURSOR SEARCH
* " Search forward for word under cursor
# " Search backward for word under cursor
g* " Partial word search forward
g# " Partial word search backward
" SEARCH WITH OPERATORS
d/foo " Delete up to "foo"
y?bar " Yank back to "bar"
c/pattern " Change up to pattern
" SEARCH USEFUL SETTINGS
:set incsearch " Incremental search
:set hlsearch " Highlight matches
:set ignorecase " Case insensitive
:set smartcase " Smart case (if uppercase, case sensitive)
:nohlsearch " Clear highlight (or :noh)
Block and Paragraph Motions
" PARAGRAPH MOVEMENT
{ " Previous blank line
} " Next blank line
" Very useful for code navigation!
d{ " Delete to previous blank line
y} " Yank to next blank line
c} " Change to next blank line
" SENTENCE MOVEMENT
( " Previous sentence
) " Next sentence
" SECTION MOVEMENT (functions in C, sections in docs)
[[ " Previous section
]] " Next section
[] " End of previous section
][ " End of next section
" BRACKET MATCHING
% " Jump to matching bracket
" Works with: ( ) [ ] { } < >
" Also works with: /* */ #if #else #endif (C)
" PRACTICAL: Jump between function braces
{ " Go to function start
% " Jump to closing brace
{ " Back to opening
va{% " Visual select function body
" FOLD MOVEMENT
zj " Next fold
zk " Previous fold
[z " Start of current fold
]z " End of current fold
Jump and Mark Motions
" LINE JUMPS
gg " First line
G " Last line
{n}G " Go to line n
:{n} " Go to line n
{n}gg " Go to line n
" SCREEN JUMPS
H " Top of screen (High)
M " Middle of screen
L " Bottom of screen (Low)
" SCROLL POSITIONING
zt " Scroll current line to top
zz " Scroll current line to center
zb " Scroll current line to bottom
" MARKS
m\{a-z} " Set mark (buffer local)
m{A-Z} " Set mark (global, across files)
'\{mark} " Jump to mark line
`\{mark} " Jump to mark exact position
'' " Previous position (line)
`` " Previous position (exact)
" AUTOMATIC MARKS
'. " Last change
'^ " Last insert
'[ " Start of last change/yank
'] " End of last change/yank
'< " Start of last visual
'> " End of last visual
" JUMP LIST
<Ctrl+O> " Previous jump position
<Ctrl+I> " Next jump position
:jumps " Show jump list
" CHANGE LIST
g; " Previous change position
g, " Next change position
:changes " Show change list
" PRACTICAL: Mark and return
ma " Mark position 'a'
...edit elsewhere...
'a " Return to mark
Scroll Motions
" PAGE SCROLLING
<Ctrl+F> " Page forward (Full)
<Ctrl+B> " Page backward
<Ctrl+D> " Half page down
<Ctrl+U> " Half page up
" LINE SCROLLING
<Ctrl+E> " Scroll down one line
<Ctrl+Y> " Scroll up one line
" SCROLL SETTINGS
:set scrolloff=5 " Keep 5 lines above/below cursor
:set sidescrolloff=5 " Keep 5 columns left/right
" REPOSITION CURSOR ON SCREEN
zt " Current line to top
z<CR> " Same as zt
zz " Current line to middle
z. " Same as zz
zb " Current line to bottom
z- " Same as zb
" SCROLL WITH LINE NUMBER
z{n}<CR> " Scroll line n to top
{n}zt " Scroll with count
" HORIZONTAL SCROLL (when nowrap)
zh " Scroll left
zl " Scroll right
zH " Scroll half screen left
zL " Scroll half screen right
zs " Scroll to cursor (start of screen)
ze " Scroll to cursor (end of screen)
Infrastructure Navigation Patterns
" YAML/CONFIG FILE NAVIGATION
" Jump between sections
/^[a-z].*:<CR> " Next top-level key
?^[a-z].*:<CR> " Previous top-level key
]] " Section forward (with ftplugin)
" FIND KEY-VALUE
/hostname:<CR> " Find hostname key
f:w " Jump to value
" LOG FILE NAVIGATION
/ERROR\|WARN<CR> " Find errors or warnings
n " Next error
N " Previous error
* " Search for word under cursor
" SSH CONFIG NAVIGATION
" Host vault-01
" HostName ...
/^Host <CR> " Next Host block
?^Host <CR> " Previous Host block
" ASCIIDOC NAVIGATION
/^== <CR> " Next section (level 2)
/^=== <CR> " Next subsection (level 3)
/^\[source<CR> " Next code block
?^== <CR> " Previous section
" JUMP TO DEFINITION PATTERNS
gd " Go to local definition
gD " Go to global definition
<Ctrl+]> " Jump to tag
<Ctrl+T> " Jump back from tag
" MARKS FOR INFRASTRUCTURE FILES
mH " Mark hosts file position
mS " Mark ssh config position
mV " Mark vault config position
'H " Jump back to hosts
Motion Gotchas
" WRONG: j/k skip wrapped lines
" Long line that wraps...
j " Goes to next actual line, not visual
" CORRECT: Use gj/gk for wrapped lines
gj " Move within wrapped display line
gk " Same, upward
" WRONG: w/W confusion with punctuation
" hello-world.example
w " hello → - → world → . → example
W " hello-world.example (one move)
" CORRECT: Understand word vs WORD
" word = alphanumeric sequences
" WORD = non-blank sequences
" WRONG: f doesn't cross lines
f) " Only searches current line!
" CORRECT: Use /pattern for multi-line
/) " Searches entire buffer
" WRONG: Forgetting search is a motion
d/pattern " Deletes up to pattern (exclusive)
" CORRECT: Use operator + search
d/pattern<CR> " Delete to match (exclusive)
dn " Delete to next match
" WRONG: % on non-matching brackets
" (unbalanced (parens)
% " Behavior is undefined
" CORRECT: Ensure balanced delimiters before using %
" WRONG: Expecting { } to work like other editors
" Vim { } = blank line, not brace
" CORRECT: Use [{, ]} for brace pairs
[{ " Previous unmatched {
]} " Next unmatched }
" WRONG: Marks disappear
ma " Local mark
:edit other_file
'a " Mark 'a' not here!
" CORRECT: Use uppercase for global marks
mA " Global mark
:edit other_file
'A " Works across files
Quick Reference
" ESSENTIAL MOTIONS CHEATSHEET
" HORIZONTAL
0 ^ $ g_ " Line start/end variants
w b e " Word movement
W B E " WORD movement
f F t T " Character find
; , " Repeat character find
" VERTICAL
j k " Line up/down
{ } " Paragraph
( ) " Sentence
H M L " Screen position
gg G {n}G " File position
" SEARCH
/ ? " Pattern search
n N " Next/prev match
* # " Word search
% " Matching bracket
" JUMPS
<Ctrl+O> <Ctrl+I> " Jump list
g; g, " Change list
'' `` " Previous position
'\{mark} `\{mark} " To mark
" SCROLL
<Ctrl+F> <Ctrl+B> " Page
<Ctrl+D> <Ctrl+U> " Half page
<Ctrl+E> <Ctrl+Y> " Line
zt zz zb " Reposition screen
Marks
Set mark
ma " Set mark 'a' at cursor
mA " Set global mark 'A' (across files)
Jump to mark
'a " Jump to line of mark 'a'
`a " Jump to exact position of mark 'a'
Special marks
'' " Jump to previous position (line)
`` " Jump to previous position (exact)
'. " Jump to last change
`. " Jump to last change (exact)
'^ " Jump to last insert position
'" " Jump to position when file was last closed
'[ " Start of last yank/change
'] " End of last yank/change
'< " Start of last visual selection
'> " End of last visual selection
List marks
:marks " Show all marks
:marks aB " Show specific marks
:delmarks a " Delete mark 'a'
:delmarks! " Delete all lowercase marks
Jump List
Navigate jumps
Ctrl-o " Jump back (older)
Ctrl-i " Jump forward (newer)
:jumps " Show jump list
:clearjumps " Clear jump list
What counts as a jump
" These add to jump list:
G " Go to line
gg " Go to top
/pattern " Search
n / N " Next/prev search
% " Matching bracket
'a " Mark jump
:123 " Go to line 123
Change List
Navigate changes
g; " Jump to older change
g, " Jump to newer change
:changes " Show change list
Last change
`. " Go to last change position
'. " Go to last change line
gi " Go to last insert and enter insert mode
File Navigation
Alternate file
Ctrl-^ " Switch to alternate (last) file
:e # " Same as above
File under cursor
gf " Go to file under cursor
gF " Go to file:line under cursor
Ctrl-w f " Open file in split
Ctrl-w gf " Open file in tab
Include file path
:set path+=** " Search subdirectories
:find file.adoc " Find and open file
Line Navigation
Go to line
:123 " Go to line 123
123G " Go to line 123
123gg " Go to line 123
:$ " Go to last line
Percentage
50% " Go to 50% of file
First/last
gg " First line
G " Last line
Screen Navigation
Move cursor on screen
H " Top of screen (High)
M " Middle of screen
L " Bottom of screen (Low)
Scroll screen
Ctrl-f " Page forward (full)
Ctrl-b " Page backward (full)
Ctrl-d " Half page down
Ctrl-u " Half page up
Ctrl-e " Scroll down one line
Ctrl-y " Scroll up one line
Center cursor
zz " Center line on screen
zt " Line at top of screen
zb " Line at bottom of screen
Paragraph/Section Navigation
Paragraphs
{ " Previous paragraph
} " Next paragraph
Sections
[[ " Previous section
]] " Next section
Method/Function Navigation
Code navigation
[m " Previous method start
]m " Next method start
[M " Previous method end
]M " Next method end
Matching
Match pairs
% " Jump to matching bracket/paren/brace
Tag Navigation
ctags
Ctrl-] " Jump to tag definition
Ctrl-t " Jump back from tag
:tag name " Jump to tag
:tags " Show tag stack
g Ctrl-] " List multiple matches