0

Is there a way (even theoretical) for Vim to use an external program for syntax highlighting?

For instance a program that reads buffer content from stdin and prints single-character colour identifiers to stdout (or single-character identifiers for the corresponding syntax groups), thus bypassing Vim's usual mechanism for syntax highlighting?

2
  • 1
    I found this question on SO: ANSI color codes in Vim which may be related.
    – Friedrich
    Jul 4, 2023 at 18:34
  • 2
    Only possible via hacks using the already mentioned AnsiEscape or my colorizer plugin. For Files with lots of such syntax highlighting, Vim will become very slow Jul 4, 2023 at 19:04

1 Answer 1

2

My understanding is that Vim colorization is solely based on the content of the file (and not the output of particular program).

However you could:

  • Transform your text using an external program to add color identifiers
  • Make a colorization that highlight the text using these identifiers
  • Hide these color identifiers to the user

Remark: I believe this is the technique used by Telescope for previewing the files using bat.

But when you save the file it will be saved using the color identifiers.

Of course you could use a filter to remove these identifier right before saving.

2
  • For example, using :help textprop, you could process the results of a program (or daemon using :help job) and add highlighting to a buffer.
    – D. Ben Knoble
    Jul 6, 2023 at 13:37
  • Thanks @BenKnoble. I understand my answer is in-precise. Using text properties we can associate properties computed from the output of an external program and based the colorization of these properties instead of the pure content of the buffer. Jul 6, 2023 at 13:44

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.