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
mAsets global markAat the current cursor position in the current file'Ajumps to the line of markA, opening the file if necessary`Ajumps to the exact line and column of markA- 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
viminfois 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
:marksto list all marks and their file locations — global marks show the full file path - Develop a personal convention:
mMfor main file,mTfor test file,mCfor 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 —'Aonly 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