Previous Section  < Day Day Up >  Next Section

Recipe 6.13. Navigating Quickly in Vim with Marks

6.13.1 Problem

You are editing a large document, or you are editing several files at once, and you need to jump back and forth between different sections. But it takes time, and you keep losing your place.

6.13.2 Solution

Use Vim's marks to mark cursor positions, like bookmarks.

There are 52 available marks: a-z and A-Z. In Command mode, position the cursor, then type:

ma

to mark the spot. To return to this mark, type:

`a

That is a backtick, not an apostrophe.

Lowercase marks work only inside a single file. Use uppercase marks to navigate between files. Suppose you mark a location in the file configstuff.txt:

mA

Now when you hit `A from any other open file, or any Vim window, it will go to that location in configstuff.txt, opening it if necessary. Uppercase marks are stored in ~/.viminfo, so they survive between sessions.

Numbered marks are a cool thing that Vim does for you. Every time you exit Vim, it stores your last cursor position. Next time you fire up Vim, you can return to where you left off by typing:

`0

Vim stores these marks in ~/.viminfo and rotates through numbers 0-9. So, if you want to go back to where you exited three sessions ago, type:

`2

To see all of your marks, type:

:marks

6.13.3 See Also

  • Vim's online help (:help mark-motions, :help viminfo)

    Previous Section  < Day Day Up >  Next Section