7

Is there an easy way to add text to the left margin of a vim document (to the left of the line numbers)?

I know that it is possible to do because plugins such as vim-signature do it, but I am curious how this is done, and what the easiest way to do it would be.

10

I think what you are referring to is called a sign by vim.

Adding a sign seems to be a two-step process. First you define what it looks like, then you place it where you want.

The basic syntax to define a sign is:

:sign define {name} {argument}...

Where {argument}... is a series of arguments that you can choose :

  • icon= full path to an icon
  • linehl= highlighting group for the whole line on which you will place the sign
  • text= text to display if there's no icon or you run vim in a terminal
  • texthl= highlighting group for text

To place your sign, once you've defined it :

:sign place {id} line={lnum} name={name} file={fname}
  • {id} is an arbitrary number which will allow you to manipulate the sign later
  • {lnum} and {fname} are respectively the line number and the file in which you want to place your sign
  • {name} is the name of your sign

To list your signs and see their attributes:

:sign list

To remove a sign :

:sign unplace {id} file={fname}

Usage example

:sign define mysign text=>> texthl=Search

... defines the sign mysign, which will display the text >> with the colors from the highlighting group Search.

Now, assuming you're editing the file /tmp/foo, you can place your sign on its 10th line with:

:sign place 9999 line=10 name=mysign file=/tmp/foo

Here the id 9999 was chosen.

Finally, to remove the sign you just placed:

:sign unplace 9999 file=/tmp/foo

There are many other ways to define, place and unplace a sign.
For more information, see:

:help sign-commands
:help :sign-define
:help :sign-undefine
:help :sign-list
:help :sign-place
:help :sign-unplace
:help :sign-place-list
:help :sign-jump
| improve this answer | |
  • 1
    This is exactly what I was looking for :)... I initially wanted to know for curiosity and also because I use vim-signature, and gitgutter for vim but they both use the sign column. I was wanting to see if I could add an extra sign column so that I could use the information from both plugins simultaneously, but it would appear that this is not possible. I did find that vim-signature has a flag you can set that helps with that. See the issue I had opened here which also has my solution and a link to the commit I made on my vimrc to use it. – Steven Hall Dec 8 '15 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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