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

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 (AZ) 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 in viminfo/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 (az) 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 :marks to list all current marks and their file paths
  • Develop a personal convention: A for the last config file edited, B for the test file, C for the main entry point, etc.
  • '0 through '9 are special read-only marks set automatically by Vim to the last cursor position in the last 10 files closed — useful for resuming work

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?