How do I jump to the start or end of my last yank or change in Vim?
Answer
'[ and ']
Explanation
Vim automatically sets the marks '[ and '] whenever you yank, change, or paste text. They point to the first and last characters of that operation, letting you act on the same range again without re-selecting it. This is especially useful for reindenting after a paste or visually inspecting what was just modified.
How it works
'[jumps to the first line/character of the last yank or change']jumps to the last line/character of the last yank or change- These marks are set automatically — no manual
m{a-z}needed - Work with all operators:
y,c,d,p,P,>,<,=, and filter! - In linewise operations,
'[and']point to the first and last lines
Example
After pasting a block of code with p, re-indent it without re-selecting:
p " paste the block
'[='] " reindent from start to end of pasted block
Or visually select exactly what was just yanked to verify it:
yip " yank inner paragraph
`[v`] " visually select it (character-precise)
Tips
- Use
`[and`](with backtick) for character-precise jumps instead of line-wise jumps - Combine with operators:
'[>']to indent the last pasted region :echo line("'[")and:echo line("']")print the line numbers for scripting- After
:read file.txt,'[and']mark the range of the inserted file content