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

How do I set a mark and jump back to it later?

Answer

m{a-z} then '{a-z}

Explanation

Vim marks let you bookmark positions in a file and jump back to them instantly. Lowercase marks are local to the current buffer, while uppercase marks work across files.

How it works

  • ma sets mark a at the current cursor position
  • 'a jumps to the line of mark a (first non-blank character)
  • `a jumps to the exact position (line and column) of mark a

Example

While editing a function on line 42:

  1. Press ma to set mark a
  2. Navigate elsewhere to line 200
  3. Press 'a to jump back to line 42

Tips

  • '' jumps to the position before the last jump
  • `. jumps to the position of the last change
  • Uppercase marks (mA through mZ) persist across files
  • :marks lists all current marks

Next

How do you yank a single word into a named register?