Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

In short, I'm in an effort to replace less with vim (vimpager). I have settings for scripts to spit out colors (and bold and everything nice) whenever they can. less understands the color codes and displays them nicely. How can I make vim parse the codes and display colors/boldness the way less does?

share|improve this question
up vote 20 down vote accepted

Two answers:

A short one: you want to use this vim script. It will conceal the actual ANSI escape sequences in your file, and use syntax highlighting to color the text appropriately. The problem with using this in a pager is that you will have to make vim recognize when to use this. I am not sure if you can simply always load it, or if it will conflict with other syntax files. You will have to experiment with it.

A long answer: The best you can hope for is a partial non-portable solution. Less does not actually understand the terminal escape sequences, since these are largely terminal dependent, but less can recognize (a subset of) these, and will know to pass them through to the terminal, if you use the -r (or -R) option. The terminal will interprets the escape sequences and changes the attributes of the text (color, bold, underline ...). Vim, being an editor rather than a pager, does not simply pass raw control characters to the terminal. It needs to display them in some way, so you can actually edit them. You can use other features of vim, such as concealment and syntax highlighting to hide the sequences and use them for setting colors of the text, however, it will always handle only a subset of the terminal sequences, and will probably not work on some terminals.

This is really just one of many issues you will run into when you try to use a text editor as a pager.

share|improve this answer
To put it in a nutshell, you have to write part of a terminal emulator in Vim, the part that handles the terminal escape sequences that are present in your input. – Gilles Feb 20 '11 at 19:02
Thanks, I think I'm giving up. If it's not easy it doesn't make much sense anymore. – phunehehe Feb 21 '11 at 2:10
By the way, if all you are trying to do is have a pager with syntax highlighting, look at this link: linux-tips.org/article/78/syntax-highlighting-in-less – Jan Hlavacek Feb 21 '11 at 3:00
@JanHlavacek link is broken :( – Nitrodist Aug 16 '13 at 20:09
@Nitrodist, Looks fixed now if you still need it. – Stuart Feb 7 '14 at 2:28

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.