Ubuntu – How to set vim filetype when editing nginx config files

Ubuntuvim

When I open vim for a file like /etc/nginx/sites-available/default, syntax highlighting works fine. But then if I create my own file /etc/nginx/sites-available/myapp, vim does not highlight its syntax. I have to do :setf conf every time.

Is there anything I can put in ~/.vimrc to tell vim "if you don't know which syntax to use, just use conf" ?

A .vimrc template for a vim noob is also welcome. I'm not using it as an IDE, I use vim mostly for config files only.

Note: I'm using Ubuntu 12, in case it matters.

Best Answer

The following line in ~/.vimrc should do this.

autocmd BufRead,BufNewFile /etc/nginx/sites-*/* setfiletype conf
Related Topic