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

How do I set a bookmark that takes me back to a specific line in any file?

Answer

mA

Explanation

Uppercase marks (AZ) are global marks in Vim — they persist across files and even across sessions (when viminfo or shada is configured). Setting mA in one file lets you jump back to that exact position from anywhere with 'A, automatically switching to the correct buffer.

How it works

  • m — the mark-setting operator
  • AZ — uppercase letter creates a global (cross-file) mark
  • 'A — jump to line of mark A (lands on first non-blank character)
  • `A — jump to exact cursor position of mark A (line and column)

Lowercase marks (az) are local to the current buffer. Uppercase marks are the only marks that cross file boundaries.

Example

You're editing config.py and want to bookmark a function you'll return to:

# config.py, line 42
def load_settings():   ← cursor here, press mA

Later, from any other file:

'A

Vim opens config.py and jumps to line 42.

Tips

  • Use :marks to list all currently set marks and their file locations
  • Marks 09 are set automatically by Vim to your last exit positions — '0 takes you to where you last closed Vim
  • To make uppercase marks persist across sessions in Neovim, ensure ' or f is in your shada option (e.g., :set shada='100,f1)
  • Combine with '' (two apostrophes) to jump back to where you were before the last mark jump

Next

How do I build a macro programmatically using Vimscript instead of recording it?