Mark my Words

comment 1
The Young Person's Guide to Vim

Hello there, friend. Do you ever find yourself scrolling through your own code, trying to find something you just saw a moment ago? Do you ever forget the name of that method that just scrolled out of sight? Do you ever lie awake at night, wondering if all consciousness is the product of a single mind, oscillating at such a speed as to seemingly inhabit multiple bodies at once?

If so, you’re in luck! I can help you with those first two problems!

The solution to this problem in vim is to use marks. You can set a mark in normal mode by typing m  followed by any lowercase letter ( ma  to set the mark a). You can then return to this mark by typing either a backtick followed by the letter of the mark ( `a ) or an apostrophe followed be the letter of the mark ( 'a ). I’ll go over the difference between those two options in a future post. There are some other things you should know about these marks–

  • They are local — that is, the mark exists within only one file at a time
  • Since they are local, you can use the same letter to mark places in different files. Mark a  in file.rb is a different mark than mark a  in file_spec.rb, for example
  • They do not persist between vim sessions (by default)

So next time you find yourself jumping around a file again and again, consider the lowly mark! As for that third problem, you’re on your own.

1 Comment

  1. Pingback: Global Marks | KMCG

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">