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

How do I set a mark that works across different files?

Answer

mA / 'A

Explanation

Uppercase marks (A-Z) are global marks — they remember not only the line and column position, but also the file where they were set. Jumping to a global mark with 'A or `A will automatically switch to the correct buffer, even if it is not currently visible. This makes them perfect for bookmarking important locations across a multi-file project.

How it works

  • mA sets global mark A at the current cursor position in the current file
  • 'A jumps to the line of mark A, opening the file if necessary
  • `A jumps to the exact line and column of mark A
  • You have 26 global marks (A-Z), each storing a file path, line number, and column number
  • Global marks persist across buffer switches and, if viminfo is configured, across Vim sessions

Contrast this with lowercase marks (a-z), which are local to the current buffer and cannot jump between files.

Example

You are editing src/main.go and set a mark on an important function:

mM

Now you open src/utils.go and start working there. At any point, press 'M to instantly jump back to the marked location in main.go. Vim switches buffers automatically.

Set another global mark in utils.go:

mU

Now 'M jumps to main.go and 'U jumps to utils.go — your own personal cross-file bookmarks.

Tips

  • Use :marks to list all marks and their file locations — global marks show the full file path
  • Develop a personal convention: mM for main file, mT for test file, mC for config — whatever makes sense for your workflow
  • Global marks survive buffer switches but are overwritten if you use the same letter again — each uppercase letter stores only one position
  • With set viminfo+=... properly configured, global marks persist between Vim sessions, so your bookmarks are still there when you restart Vim
  • Use `A (backtick) instead of 'A (quote) for exact column positioning — 'A only jumps to the first non-blank character on the line
  • Combine with <C-o> to jump back to where you were after visiting a global mark
  • Global marks are especially useful in large codebases where you frequently bounce between a handful of key files

Next

How do I edit multiple lines at once using multiple cursors in Vim?