vimtricks.wiki Concise Vim tricks, one at a time.

How do I jump to the start or end of the last changed, yanked, or pasted text using automatic marks?

Answer

'[ and ']

Explanation

Vim automatically sets two special marks after every change, yank, or put operation: '[ and ']. These jump to the first and last line of the affected text, respectively. Because they update automatically, you never need to manually place marks to revisit or re-operate on recently edited regions.

How it works

  • '[ — jump to the first line of the last changed, yanked, or put text
  • '] — jump to the last line of the last changed, yanked, or put text
  • `[ and `] — backtick variants that jump to the exact column instead of the line start

These marks are updated by: y (yank), c (change), d (delete), p / P (put), and :read.

Example

You yank a 10-line function on lines 40–49, navigate away to line 200, then want to re-indent the pasted block:

p        " paste the function somewhere
'[V']=  " jump to paste start, visually select to paste end, re-indent

With `[v`] (backtick version) you select the exact characters rather than whole lines — useful when the pasted text starts or ends mid-line.

Tips

  • Quick re-indent after paste: '[V']=
  • Reselect last paste as visual: `[v`]
  • Check all special marks: :marks — look for [ and ] in the output
  • After :read file, '[ points to the first line read in and '] to the last
  • These marks are buffer-local and reset with each new change/yank/put in that buffer

Next

How do I trigger a custom user-defined completion function in insert mode?