1

I would like to tag or annotate lines so that I can later refer to those lines and perform commands on them. I wouldn't like for the tag to be in the actual text but external metadata. Is there any way for this to be possible?

2
  • 1
    this can possibly be done using text-properties. Sep 14, 2021 at 12:15
  • 2
    Looks like you're looking for the :h mark-motions feature: use ma to mark a line in a buffer, 'a to go back to the mark. Lower case marks (ma, mb, etc) are local to a buffer and upper case marks (mA, mB) are shared across your filesystem. I think that's built-in feature the closest to what you are looking for.
    – statox
    Sep 14, 2021 at 13:03

1 Answer 1

3

As statox mentions in the comment, the simplest version is marks. You can use viminfo-related options to make sure these are persisted between vim instances.

The idea is to m and a letter on a line (or the ex commands :mark/:k). Lower-case is file-specific; upper-case is global.

Then use ' with the mark name to get back to the line or ` to get back to the line and column. You can also use marks in ranges at the ex command prompt.

Vim also sets some builtin marks that are symbols rather than letters. You may have seen the range :'<,'> when pressing the colon key in visual mode—now you know why.

For more advanced cases, or for plugin authors who wish to not overwrite user marks, text properties would be a better direction (as also indicates in the comments by Christian).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.