Bookmark frequent locations

4.7
(37)

Vim has a built-in concept called “marks” (see :help mark) which allows bookmarking of locations within files. The easiest way to use marks is by pressing m followed by any letter. You can jump back to the mark you made by pressing ' followed by the letter.

A few points you should be aware of:

  • The a-z lowercase letter mark locations are local to each file.
  • The A-Z capital letter mark locations work across files.
  • Use ' followed by the letter to jump to the line you marked. This goes to the first non-blank character of the line.
  • Use ` followed by the letter to jump to the specific column on the specific line that you marked.

A useful case for marks is creating simple bookmarks to jump to frequently edited locations. With capital letter mark locations, these bookmarks can transcend files and even projects, allowing you to create mappings that jump to frequently edited locations. For example — your .vimrc.

Here’s a useful example I use. If you’re using a plugin manager such as vim-plug, you likely have a section of your .vimrc dedicated to listing out plugins. With your cursor positioned at the start of the plugin section, press mP. This creates a mark, P, at this location. Now, when you’re editing any file in any location, you can press 'P to return to your plugin list.

Bonus tip: Use :source % to source changes to your .vimrc file after you edit it.

Check out the video below showing this in action.

How useful was this tip?

Average rating 4.7 / 5. Vote count: 37

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts