Is it possible to write a vim plugin that modifies buffer in real time? As a first step, would it for example be possible to modify syntax highlighting of unused variables as suggested in a similar sublime issue? I'm not talking about having personal static highlight config files, nor about setting up multiple vim rules. I think what I want to define custom personal rules but dynamically depending on the context and in a high level way independent of the language being edited. I would need to extract current buffers text and be able to modify them later on, after running some kind of logic in an external js server for example.

1 Answer 1


As far as I know :h text-properties were designed with this in mind.

The main use for text properties is to highlight text.  This can be seen as a
replacement for syntax highlighting.  Instead of defining patterns to match
the text, the highlighting is set by a script, possibly using the output of an
external parser.  This only needs to be done once, not every time when
redrawing the screen, thus can be much faster, after the initial cost of
attaching the text properties.

... possibly using the output of an external parser.

Like some background process parses your buffer and provides info for vim to highlight text whatever needed.

  • The Intoduction section of :help text-properties seems promising. I'll give it a closer look. I wonder how the connection to the script is done.
    – ffigari
    Aug 25, 2021 at 14:43
  • 1
    job_start to start bg process that will respond in a callback where you highlight what is needed.
    – Maxim Kim
    Aug 25, 2021 at 14:56
  • @ffigari check this treesitter plugin for vim that does similar thing github.com/mattn/vim-treesitter
    – Maxim Kim
    Aug 27, 2021 at 14:03
  • Awesome Maxim, had a few ideas about using code as input so ill sure give it a look. But steps keep getting bigger!
    – ffigari
    Aug 27, 2021 at 19:12

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.