I want to generate HTML files in batch to show some gvim colorschemes in action. I took my current solution from the script at http://code.google.com/p/vimcolorschemetest/, but this will open open a gvim window for each colorscheme I want to process.

So far, the only way I have found to avoid the annoying new windows that pop up every second is to start a VNCserver and set the DISPLAY environment variable to that of the VNCserver so that all gvim windows are sent to the display within the VNC session.

However, I would like to know if there is a way I can avoid the whole VNC setup and just run a headless gvim instance that does the conversion and exits, with no windows ever being actually displayed.

I'm using linux, BTW.

2 Answers 2

vim -E -c "TOhtml" -c "w" -c "qa!" -- test.c >/dev/null

Use vim, it will load faster than gvim. You can speed up the loading time a bit by using -X, or a No-X version of vim.

In order to silence it, use >/dev/null. But that will make vim complain (Vim: Warning: Output is not to a terminal) and pause a bit, hence we use -E.

We could have tried -E -s, but I'm somehow unable to use :TOhtml properly, the result is uncolored, and is one a single line.

I pimp the command a little by using -R -c "set noreadonly" or better -n alone. This prevents the usual warning message when opening a file that already has a swapfile. There is nothing particular to prevent failures to open a non writable file (eg. owned by root).

See my vimcat repository at GitHub, for an example usage of vim syntax highlighting used in a terminal.

  • The colors aren't generated correctly unless it's done from gvim, unless you know a solution to that? Aug 20, 2016 at 5:32

I can't really tell whether your problem is that Vim opens too many windows at once, or that it opens any windows at all...

The latter case I can't help you with, however, in any newer Vim, you can do something like this (very primitive, can probably be made a lot nicer):

# gvim -c TOhtml -c w -c q -c q test.c

which will create a test.c.xhtml based on the file test.c using the current color scheme. Then, perhaps another -c to change the colors, stick it all in a shell script...


with no windows ever being actually displayed.

Yeah, so, I'm a moron. Please disregard this post.

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.