How do I bookmark a position in one file and jump back to it from any other file?
Answer
mA to set, 'A to jump
Explanation
Uppercase marks (A–Z) are global marks — they persist across files and Vim sessions. Setting a global mark with mA records both the file path and cursor position. From anywhere in Vim, 'A opens that file (if it is not already open) and jumps directly to the marked line.
How it works
m{A-Z}— Set a global mark using an uppercase letter. The mark is stored inviminfo/shada, so it survives closing and reopening Vim.'{A-Z}— Jump to the first column of the line holding that mark (opening the file if needed)`{A-Z}— Jump to the exact column of the mark (not just the line)
Lowercase marks (a–z) are local to a single buffer and are lost when that buffer is wiped. Uppercase marks cross buffer and session boundaries.
Example
Suppose you are deep inside src/config/database.go and need to jump to cmd/main.go repeatedly:
# In src/config/database.go, line 42:
mA ← set global mark A here
# Now in cmd/main.go, line 7:
mB ← set global mark B here
# Jump between them from anywhere:
'A ← instantly back to database.go:42
'B ← instantly back to main.go:7
Tips
- Use
:marksto list all current marks and their file paths - Develop a personal convention:
Afor the last config file edited,Bfor the test file,Cfor the main entry point, etc. '0through'9are special read-only marks set automatically by Vim to the last cursor position in the last 10 files closed — useful for resuming work