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

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 (az) are local to the current buffer and are lost when you close it. Uppercase marks (AZ) 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 mark A at the current cursor position in the current file
  • 'A — jump to the line of global mark A, even if it is in a different file
  • `A — jump to the exact line and column of global mark A
  • Uppercase marks persist across sessions because Vim writes them to ~/.viminfo or ~/.local/share/nvim/shada/main.shada on 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: M for Makefile, V for vimrc, T for 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'A deletes from the cursor to mark A, y'A yanks to it
  • There are 26 global marks (AZ), one set per letter — reassigning overwrites the previous location

Next

How do I programmatically set a register's content in Vimscript to pre-load a macro?