9

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?

13

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.

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

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.)

1

[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, privacy policy and cookie policy

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