Skip to content

Instantly share code, notes, and snippets.

@jmlacroix
Created September 15, 2011 01:40
Show Gist options
  • Save jmlacroix/1218309 to your computer and use it in GitHub Desktop.
Save jmlacroix/1218309 to your computer and use it in GitHub Desktop.
Use VIM to output HTML-formatted syntax highlight of a file
#/bin/bash
OUTFILE=$(mktemp -t highlight)
INFILE=$1
PARAM="set nonumber"
if [ -z "$INFILE" ]
then
echo "usage: $0 source.file"
exit
fi
vim +"$PARAM" \
+'let html_use_css=1' \
+'TOhtml' \
+'/<pre>/,/<\/pre>/d a' \
+'g/./d' \
+'1pu! a' \
+'$d' \
+"wq! $OUTFILE" \
+'q!' $INFILE &>/dev/null
cat $OUTFILE && rm $OUTFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment