2

In order to see the difference between two or more text files there is the diff command. But to see the difference with colors, after a little bit of research I found the vimdiff, with an option to export the difference to a HTML file with :TOhtml

Here's my problem: i am trying to do all that with a script and i have not been able to find a way to add the :TOhtml to the script.

I tried with vimdiff t1 t2 | :TOhtml but it does not really work.

So if anyone of you could help me or give a clue, i would really be thankful.

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
Tifou
  • 33
  • 1
  • 3

3 Answers3

6

A one-liner, based on the accepted reply, where you specify the name of the output HTML file

vimdiff -c TOhtml -c "w custom_name.html | qa!" $1 $2
amine
  • 502
  • 5
  • 14
3

You can do it in a short script in bash. What you want to do is call vimdiff file1 file2 and inside vim call :TOhtml and last :wqa to exit from vim. This translate to:

/usr/bin/vimdiff $1 $2 <<EOF


:TOhtml
:wqa
EOF

Explanation:

Call vimdiff directly with its full path, this will ignore aliases and such. There are two files to be used as input for vimdiff, and you can add sanity checks at this point. This command will get direct input from the script until it reaches the EOF block.

Next line is empty. VIM might complain that it is not running from a console and you would have needed to press Enter at this point. The empty line emulates Enter key press.

Next two lines are the commands that you wanted to execute from within VIM and the last line finishes it all. The output here will be a file called Diff.html in the folder in which you ran the script.

cmyster
  • 76
  • 2
0

Or you can use colordiff, "a tool to colorize diff output".

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178