I've a file of source code written in a programming language (e.g. PHP) and I would like to convert it into a HTML file, so I can publish it on web in order to share my code.By conversion I mean, for example, converting new lines into <br> tags so that the text will keep the same formatting both in the text editor and in the web browser. Ideally it should also preserve syntax highlighting so it can be also printed. Is this achievable in Vim? If so, how?
How to convert a source code file into HTML?
filetype html
The following vim command would creates an html rendering of the current file.:TOhtmlIt saves the file in the same folder (with .html extension) and it will include styles, foreground/background colours and syntax highlighting, so the file can be straight web published as well as printed.For more options (like adding line numbers, compability with old browsers, etc.), check: :help TOhtml.To convert file non-interactively, try the following command:vim -E -s -c let g:html_no_progress=1 -c syntax on -c set ft=c -c runtime syntax/2html.vim -cwqa myfile.cRelated:Convert codes to HTML with CSS style at stackoverflow