Navigation
Comprehensive guide to moving around efficiently in Vim.
Basic Movement
Character Movement
h " Move left one character
j " Move down one line
k " Move up one line
l " Move right one character
Arrow Keys Alternative
While hjkl are the standard Vim movement keys, arrow keys also work:
← " Same as h
↓ " Same as j
↑ " Same as k
→ " Same as l
Word Movement
w " Move to beginning of next word
W " Move to beginning of next WORD (space-separated)
b " Move to beginning of previous word
B " Move to beginning of previous WORD
e " Move to end of current word
E " Move to end of current WORD
ge " Move to end of previous word
gE " Move to end of previous WORD
Line Movement
0 " Move to beginning of line (column 0)
^ " Move to first non-blank character
$ " Move to end of line
g_ " Move to last non-blank character
g0 " Move to beginning of screen line (when line wraps)
g$ " Move to end of screen line (when line wraps)
Advanced Movement
Screen Movement
H " Move to top of screen (High)
M " Move to middle of screen (Middle)
L " Move to bottom of screen (Low)
Page Movement
Ctrl+f " Move forward one page (Page Down)
Ctrl+b " Move backward one page (Page Up)
Ctrl+d " Move down half page
Ctrl+u " Move up half page
Ctrl+e " Scroll down one line (cursor stays)
Ctrl+y " Scroll up one line (cursor stays)
Document Movement
gg " Go to first line of document
G " Go to last line of document
1G " Go to line 1 (same as gg)
42G " Go to line 42
:42 " Go to line 42 (command mode)
Search-Based Movement
Character Search
f{char} " Find next occurrence of {char} in line
F{char} " Find previous occurrence of {char} in line
t{char} " Move to before next {char} in line
T{char} " Move to before previous {char} in line
; " Repeat last f, F, t, or T command
, " Repeat last f, F, t, or T command (reverse)
Examples
fa " Find next 'a' in current line
3fa " Find 3rd 'a' in current line
tx " Move to character before next 'x'
F( " Find previous '(' in current line
Pattern Search
/{pattern} " Search forward for pattern
?{pattern} " Search backward for pattern
n " Next match (same direction)
N " Previous match (opposite direction)
* " Search forward for word under cursor
# " Search backward for word under cursor
g* " Search forward for partial word under cursor
g# " Search backward for partial word under cursor
Search Examples
/hello " Search for 'hello'
/\<hello\> " Search for whole word 'hello'
/hello\|world " Search for 'hello' or 'world'
/^Hello " Search for 'Hello' at beginning of line
/world$ " Search for 'world' at end of line
Bracket and Delimiter Movement
Matching Brackets
% " Jump to matching bracket/parenthesis/brace
[( " Jump to previous unmatched (
]) " Jump to next unmatched )
[{ " Jump to previous unmatched {
]} " Jump to next unmatched }
Section Movement
]] " Next section (or function)
[[ " Previous section (or function)
][ " Next end of section
[] " Previous end of section
Jump Navigation
Jump List
Ctrl+o " Jump to older position in jump list
Ctrl+i " Jump to newer position in jump list
:jumps " Show jump list
Change List
g; " Go to older change position
g, " Go to newer change position
Marks
m{letter} " Set mark at current position
'{letter} " Jump to line of mark
`{letter} " Jump to exact position of mark
'' " Jump to line of last jump
`` " Jump to exact position of last jump
Special Marks
'. " Jump to last change
'[ " Jump to beginning of last change/yank
'] " Jump to end of last change/yank
'< " Jump to beginning of last visual selection
'> " Jump to end of last visual selection
'" " Jump to position before last exit
Text Object Movement
Sentence Movement
( " Move to beginning of sentence
) " Move to end of sentence
Paragraph Movement
{ " Move to beginning of paragraph
} " Move to end of paragraph
Function Movement (with appropriate filetype)
[m " Move to beginning of method
]m " Move to end of method
[M " Move to beginning of method (alternative)
]M " Move to end of method (alternative)
Window and Tab Movement
Window Movement
Ctrl+w h " Move to left window
Ctrl+w j " Move to bottom window
Ctrl+w k " Move to top window
Ctrl+w l " Move to right window
Ctrl+w w " Move to next window
Ctrl+w p " Move to previous window
Ctrl+w t " Move to top-left window
Ctrl+w b " Move to bottom-right window
Tab Movement
gt " Go to next tab
gT " Go to previous tab
{n}gt " Go to tab number n
:tabn " Go to next tab
:tabp " Go to previous tab
Fold Navigation
Fold Movement
zj " Move to next fold
zk " Move to previous fold
[z " Move to start of current fold
]z " Move to end of current fold
Advanced Navigation Techniques
Combining Movements with Counts
3w " Move 3 words forward
5j " Move 5 lines down
10G " Go to line 10
2f, " Find 2nd comma in line
Using Movement with Operators
d3w " Delete 3 words
y5j " Yank 5 lines down
c2f; " Change up to 2nd semicolon
Relative Line Numbers
Enable relative line numbers for easier navigation:
:set relativenumber
:set number relativenumber " Show both absolute and relative
With relative numbers, you can quickly jump:
5j " Move 5 lines down (number shown on left)
3k " Move 3 lines up
Navigation Tips
Efficiency Tips
- Use
wandbfor word navigation instead oflandh - Use
fandtfor quick character jumps within lines - Use
*and#to search for word under cursor - Use
%to jump between matching brackets - Set marks for frequently accessed positions
Common Patterns
0w " Go to first word of line
$b " Go to last word of line
gg0 " Go to very beginning of file
G$ " Go to very end of file
Search Shortcuts
/word<CR>n " Find next occurrence of 'word'
?word<CR>N " Find previous occurrence of 'word'
*n " Find next occurrence of word under cursor
#N " Find previous occurrence of word under cursor
Visual Mode Navigation
All navigation commands work in visual mode to extend selection:
v3w " Select 3 words
V5j " Select 5 lines
v% " Select to matching bracket
This navigation system allows you to move quickly and precisely throughout your files. Master these movement commands to dramatically improve your Vim efficiency.