How can I deal with the colored outputs of shell commands when inputing them with :read
?
As an example, I have a self-defined git log
command, and I would like to see it in a split window. That works well enough using
:new | read !git log-command
Unfortunately, the command outputs has some colours. And thus the result looks like
- ^[[33mac74ef4^[[m 2018-10-22 [me, N] - some text
I guess I could just use as :substitute
command to clean it up afterwards, or maybe pipe it through sed
.
But I wanted to know if there was a better way to handle it?
As a minimum, I would like to remove those ^[[m
characters. But even better would be to recognise them and adapt it to color the buffer accordingly.
git
, you can disable colours, which is what I do. Can also usegit --no-color
. I would also expectgit
to automatically disable colours when outputting to something without stdin btw--color=auto
just works), you can strip it by post processing the output, e.g.:r! git log |sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"
sed
and:substitute
are the best options. Well the other page mentions some plugins, I might give them a try.