Step 4 of 8

14. Marks

Marks across buffers

Lowercase marks like 'a and 'b are local to the buffer you’re currently in. This is nice, because it means that different buffers can have a completely different set of marks. But what if we want to set marks that move us between buffers? It’s much more common in a large codebase to want to jump between files rather than to different places in the same file.

Vim’s got our back. Capital letters, when used as marks, mean global marks. For example, the 'A mark not only represents the row and column where it was set, but the file too!

So, you can set a mark with mA and jump back to it from any buffer with 'A (or, as we just learned, `A).

Work through the checklist below. We’re going to work with two buffers this time: set the 'A mark in the initial buffer, open a file called marky with :e marky, and set the 'B mark over there. Then use 'A and 'B to bounce between the two buffers — remember, the capital letter is how Vim knows we’re speaking about a global mark.

  1. Set the global A mark with mA Anywhere in this buffer is fine — the capital letter is what makes the mark global. Press mA.
  2. Open the marky file The statusline at the bottom will show the new name — type :e marky and hit Enter.
  3. Set the global B mark with mB Anywhere in marky is fine — press mB.
  4. Jump back to home base with 'A The global mark remembers its file, so it pulls you across buffers — press 'A.
  5. Bounce forward again with 'B And straight back to marky — press 'B.
Set the global A mark with mA Anywhere in this buffer is fine — the capital letter is what makes the mark global. Press mA.

Next: Open the marky file

Loading editor…