How do I set a bookmark that takes me back to a specific line in any file?
Answer
mA
Explanation
Uppercase marks (A–Z) 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 operatorA–Z— 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 (a–z) 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
:marksto list all currently set marks and their file locations - Marks
0–9are set automatically by Vim to your last exit positions —'0takes you to where you last closed Vim - To make uppercase marks persist across sessions in Neovim, ensure
'orfis in yourshadaoption (e.g.,:set shada='100,f1) - Combine with
''(two apostrophes) to jump back to where you were before the last mark jump