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

How do I set marks that work across files?

Answer

m{A-Z}

Explanation

Uppercase marks (A-Z) are global marks that remember both the file and the cursor position. Jumping to a global mark will open the file if it is not already loaded.

How it works

  • mA sets global mark A at the current position and file
  • 'A jumps to mark A, opening the file if necessary
  • `A jumps to the exact line and column

Example

While editing src/main.go at line 42, press mM. Later, while editing src/utils.go, press 'M to jump back to line 42 in main.go.

Tips

  • Global marks persist across Vim sessions if viminfo/shada is configured
  • You have 26 global marks (A-Z)
  • :marks shows all marks including globals
  • :delmarks A deletes mark A
  • Useful for bookmarking frequently visited files in a project

Next

How do you yank a single word into a named register?