vimtricks.wiki Concise Vim tricks, one at a time.

How do I add custom markers or icons in Vim's sign column next to specific lines without any plugins?

Answer

:sign define and :sign place

Explanation

Vim's built-in sign system lets you define custom symbols and place them in the sign column — the narrow gutter to the left of line numbers. Plugins like vim-gitgutter and LSP clients use this system internally, but you can use it directly in scripts or mappings to annotate lines with your own markers.

How it works

Step 1 — Define a sign type (once per session):

:sign define {name} text={chars} texthl={group}

Key fields:

  • text= — 1–2 character symbol shown in the column (e.g., >>, !!, *)
  • texthl= — highlight group for the symbol (e.g., Error, WarningMsg, Search)
  • linehl= — optionally highlight the entire line

Step 2 — Place the sign on a specific line:

:sign place {id} line={lnum} name={name} file={filepath}

Remove signs:

:sign unplace {id} file={filepath}
:sign unplace * file={filepath}   " remove all signs from the file

Example

Mark line 10 of the current file with an arrow:

sign define MyMark text=>> texthl=Search
sign place 1 line=10 name=MyMark file=%

List all placed signs:

:sign place

Clear them:

:sign unplace * file=%

Tips

  • Enable the sign column with :set signcolumn=yes if it does not appear automatically
  • Use buffer={bufnr('%')} instead of file= when working programmatically with buffer numbers
  • Multiple signs on the same line are sorted by priority (:help sign-priority)
  • Signs persist until explicitly removed — useful for bookmarking lines during a session

Next

How do I save and restore the current window layout after temporarily changing window sizes in a Vim script?