How do I select the text I just pasted or changed?
Answer
`[v`]
Explanation
The `[v`] sequence visually selects the exact region of text that was last changed, pasted, or yanked into the buffer. This is incredibly useful for re-indenting pasted code, reformatting a block, or verifying exactly what was affected by your last operation.
How it works
`[is a mark that points to the first character of the previously changed or yanked text`]is a mark that points to the last character of that same regionvstarts visual mode between those two marks- Together,
`[v`]visually selects the entire region that was just modified
These marks are updated automatically after any put (p/P), yank (y), delete (d), or change (c) operation.
Example
You paste a block of code with p:
function greet() {
console.log("hello");
}
The indentation is wrong. Immediately press `[v`] to select the pasted block, then press = to auto-indent it:
function greet() {
console.log("hello");
}
Or after pasting, press `[v`]> to indent the pasted region by one shiftwidth.
Tips
- Map this to a shortcut for quick access:
nnoremap gp[v]— nowgpselects the last pasted text - The
'[and'](with single quotes) variants jump to the line of the start/end marks rather than the exact column — use backtick versions for precise character selection - After yanking text with
y,`[v`]selects the yanked region — useful for highlighting what was just copied - These marks also update after
:read,:substitute, and other Ex commands that modify the buffer - Use
`[V`](with capital V) to select in linewise visual mode instead, which is often more practical for pasted blocks - Combine with any operator:
`[y`]re-yanks the last changed text,`[d`]deletes it,`[>`]indents it - The
gvcommand is related but different — it reselects the last visual selection, not the last changed text