3

I known lolcat for a while now, and wondered if it was possible to display the text that it output, inside of Vim correctly.

So i tried:

:%! lolcat

But while it update the buffer, the text doesn't seem to change at all (compared to when i use it on the commandline, like with echo "hello world" | lolcat)

Any reason why this doesn't work in Vim? And maybe any ways to make it work?

4

One thing is that lolcat knows how to add colors when writing to a terminal, so by default it will only add colors when it knows it's doing that. When you run lolcat from Vim, it's actually writing to a pipe instead. You can force it to add the colors by using lolcat -f (for --force) instead.

But then, what you'll see is that lolcat is actually adding colors by producing output that includes escape sequences that a terminal recognizes as commands to change colors. Vim doesn't really interpret those by default, and will show them literally, these will look like sequences of ^[[37;41m or ^[[0m etc.

In order to have Vim actually interpret these sequences and render those as colors, you can use a plug-in. For example, install plug-in chrisbra/Colorizer and use the command :ColorHighlight after you have the lolcat -f output with the escape sequences in your buffer.

| improve this answer | |
  • 1
    Interesting to see that's how it color the text (using terminal sequences as you mentioned). I tried doing echo "hello world" | lolcat | hd but noticed no difference in the hex code with/without lolcat...I guess the terminal sequences are discarded, which would explain why they don't appear in hd output? – Nordine Lotfi Sep 26 at 18:52
  • 1
    @Nordine That's exactly the same thing. If you use lolcat | some other command it will not be connected to a terminal, but to a pipe... Use -f and it should work: echo "hello world" | lolcat -f | hd. – filbranden Sep 26 at 19:24
  • 1
    you're right! works with -f :) – Nordine Lotfi Sep 26 at 19:33

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.