Save vimdiff output to html

The script ( ) matches the filename from first directory to same filename from second directory and takes a difference between two files using vimdiff and saves a html of diff into output directory under the matching name of the filename

for example, out put of below command, “vimdiff first/a.c second/a.c” will be saved as html in out/a/Diff.html

$ vim




#cleanup any previous reports
rm -rf $REPORTS

for f in $(find $DIR1 -name "$SEARCH_FILE_TYPES")
        echo "file found is $f"
        file_without_extention=${file_with_extention%$FILE_EXTENTION} #remove extention
        echo "file name for directory is $file_without_extention"

        mkdir -p $REPORTS/$file_without_extention

        cd $REPORTS/$file_without_extention #to save output Diff.html is respective directory
        vimdiff $TOP_DIR/$f $TOP_DIR/$DIR2/$file_with_extention -c ":TOhtml" -c ":wq!"
        cd $TOP_DIR #back to top dir for next iteration

To demonestrate, the working of above script, we create two directories “first” and “second”, both of this directories will have same file “a.c” but there will be difference in source code, which we want to identify and save to html.

$ mkdir first
$ vim first/a.c
#include <stdio.h>

int main(void) {
        int a;
        printf("Hello World\n");
        return 0;
$ mkdir second
$ vim second/a.c
#include <stdio.h>

int main(int argc, char **argv) {
        int a;
        printf("Hello World\n");
        a = 10;
        return 0;

and we will create a “out” directory where the script will save the difference html.

Now, lets run the script as,

$ bash

Above script will auto exit and create a file as,

$ tree out/
└── a
    └── Diff.html

Now, if we open this DIff.html using any browser, it will show as,


Above is a automated script , which inside use a simple command as below,

$ vimdiff first/a.c second/a.c -c :TOhtml -c :wq!

You may use above command to generate html for single file.

Google Sheets Import Data - Import ... x
Google Sheets Import Data - Import from multiple spreadsheets to one range

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux