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

How do I manually add the current position to the jump list before making a large movement?

Answer

m'

Explanation

Vim's jump list automatically records your position whenever you make large motions (like G, /pattern, or <C-]>). But some motions — like counts of j/k or custom mappings — don't add to the jump list. By pressing m' (or m\``) before such a move, you manually push the current position onto the jump list so you can return with `.

How it works

  • m' — sets the special ' mark (the "last jump" mark) at the current position, which pushes it onto the jump list
  • m\`` — identical behavior; sets the `` mark at the current position
  • After the movement, press <C-o> to return to the saved position
  • '' (double apostrophe) also returns to the position, but only the previous last-jump mark

Example

You are on line 100 in a large file and want to jump to the bottom, do some work, then come back:

Line 100 — press m' to save this position
:$ — jump to end of file
[... work at bottom ...]
<C-o> — jump back to line 100

Tips

  • This is especially useful before running a macro that moves far from the current location
  • Use m' in custom mappings to make them jump-list-aware, so users can navigate back with <C-o>
  • :jumps shows the full jump list with all recorded positions
  • The jump list holds up to 100 positions per window

Next

How do I highlight all occurrences of a yanked word without typing a search pattern?