Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's what I'm doing: I'm echoing through Php colors like this:

shell colors

php creates output containing ANSI escape sequences that color text when it is displayed through the shell on my terminal. You can find the php class and explanation here.

But if I send my output to a file, and try to read it with vim it's not "colored", I just can see the special characters. Is there a way to display the colors like they are displayed in the shell?

share|improve this question
It might help if you could mention how and with what program you are creating the file with the text in color, and how you are later trying to display it. – John S Gruber Aug 6 '12 at 3:00
Sorry if I wasn't precise enough. Quote my question: I'm echoing through Php. I.e. "php -f filename" and i'm echoing using this class here:… – Olivier Pons Aug 6 '12 at 10:03
Possible cross site duplicate of:… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Mar 23 '14 at 15:17
up vote 6 down vote accepted

The terminal output will be colored if the content of the file will be sent "as-is" to the terminal, without any modifications. However, vim and some other editors will escape meta characters in the text and instead maybe add some other color codes for their syntax highlighting, so this doesn't work.

Try dumping the file to the terminal with cat, this should work. Some simple editors or pagers like less might also work.

Edit: I have not found a way to let vim "pass-through" all the escape codes, but I have found this answer which links to this vim script, which parses the escape codes and uses the vim syntax highlighting to recreate the color codes in the output. According to its description, it should do exactly what you want (but I have not tested it).

share|improve this answer
Is there a way to do this with vim (= precise not to escape)? – Olivier Pons Aug 6 '12 at 10:52
@OlivierPons see my edit – Philipp Wendler Aug 6 '12 at 11:02
It didn't work with less but did work with more: cat ~/myfile.txt | more – William Jan 5 at 13:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.