At my workplace, I want to do a presentation of a custom language I've developed for solving some problems we had. For easier development, I created my own vim syntax file for this particular language.

Now, I need to present it on another computer, that will not have that syntax file. For all I know, it might even not have vim installed (but I doubt it).

It would be perfect if I could less -r a file to get that same syntax highlighting that I do on my own computer.

However, I do not know how to either copy&paste while preserving colors (in terminal from gnome on Debian), or how to output the file with its syntax highlighting as raw control chars from vim. I'm more confident in finding a solution from vim, but I have no idea what to look for to do that.

Do you know any way to output the file you opened with its syntax highlighting as ANSI raw-control-chars in another file?

3 Answers 3


You can use the :TOhtml command that ships with Vim to create an HTML representation of the (syntax highlighted) buffer (or parts of it). Then, your only requirement on the target system would be a browser to display the captured file. See :help :TOhtml for details.

If you insist on outputting ANSI escape sequences, you could probably modify the plugin to do that, but I guess that would be a non-trivial effort.

  • 4
    OH MY GOD! That's just so perfect, I wish I could up your answer more than one time.
    – DainDwarf
    Commented Apr 15, 2015 at 10:15

The program vimpager includes a script called "vimcat". It can output a file with vim's syntax highlighing converted to ansi escape codes.

(Additional self promotion: I wrote a fork for neovim: nvimpager. You can use nvimpager -c to "cat" a file.)

  • The vimpager script doesn't seem to be very good. Takes a long time to render (had to wait for a not-too-large-a-file to be rendered line by line), can get stuck and unresponsive to Ctrl+C & the script looks prone to potentially dangerous race conditions. There should be a simpler way to do it. :/ Commented May 17, 2021 at 21:19
  • @PSkocik Are you only talking about vimcat from vimpager or also about the nvimpager I developed myself?
    – Lucas
    Commented May 18, 2021 at 11:21
  • Just the vimpager vimcat. Upon closer inspection they're using /bin/sh as their shell. If it's not bash, their kills then shouldn't be racy (only on bash, which appears to wait from a sighandler) so no danger of innocent procs getting killed then. The ` cd "$chunks_dir"; rm -f -- *` line looks a bit bothersome but that's easily fixed with an &&. So maybe then it's just slow and not potentially dangerous. :). Thanks for the answer! +1 Commented May 18, 2021 at 11:47
  • 1
    Actually vimpager might restart itself with a different shell: github.com/rkitover/vimpager/blob/master/inc/prologue.sh It is quite the complex script, hence the rewrite.
    – Lucas
    Commented May 18, 2021 at 13:34

[EDIT] : Just noticed cat doesn't do the trick when using vim and script, you can use 'head' however.

guest@demomachine$ head -c [terminalsize] demo.typescript

EXAMPLE: guest@demomachine$ head -c 3710 demo.typescript

If the presentation machine has a colour terminal available and is *nix based, you could record a script with

you@yourmachine$ script -c "vim [sourcefile]" demo.typescript

and then just

guest@demomachine$ cat demo.typescript

cat might not work with vim and script for this very problem, see edit above.

on the presentation machine. HINT: mind the terminal size during recording, should be smaller or same size as demo machine.

Script also allows you to record a whole terminal session, so you can record and play a demo using scriptreplay.

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.