How do I set a bookmark that persists across different files and Vim sessions?
Answer
mA and 'A
Explanation
Vim has two tiers of marks. Lowercase marks (a–z) are local to the current buffer and are lost when you close it. Uppercase marks (A–Z) are global — they store both the file path and the cursor position, and Vim saves them between sessions via viminfo (Vim) or shada (Neovim). This makes uppercase marks a powerful way to bookmark frequently visited files and jump to them instantly from anywhere.
How it works
mA— set global markAat the current cursor position in the current file'A— jump to the line of global markA, even if it is in a different file`A— jump to the exact line and column of global markA- Uppercase marks persist across sessions because Vim writes them to
~/.viminfoor~/.local/share/nvim/shada/main.shadaon exit
Example
While editing ~/.vimrc, press mV to bookmark it. Later, from any file in any Vim session:
'V
Vim opens ~/.vimrc and jumps directly to the marked line — no need to remember the path.
Tips
- Pick memorable letter assignments:
Mfor Makefile,Vfor vimrc,Tfor TODO file :marks— list all marks, both local and global, with their file and position:delmarks A— delete a specific global mark- Uppercase marks work as motion targets:
d'Adeletes from the cursor to markA,y'Ayanks to it - There are 26 global marks (
A–Z), one set per letter — reassigning overwrites the previous location