Using Vim syntax highlighting on custom file types

Let’s say you have a file type whose contents are in XML format but have a different file extension such as .tim . If you want to edit these files with Vim with syntax highlighting, simply add the following to ~/.vimrc (affects only your Vim environment) or /etc/vim/vimrc (affects everyone’s Vim environment):

au BufNewFile,BufRead *.tim set filetype=xml

This can be done for any file type. To give another example, if you’re storing PostgreSQL code in a file called setup.psql and want SQL syntax highlighting in Vim, add the following line:

au BufNewFile,BufRead *.psql set filetype=sql

Leave a Reply

Your email address will not be published.