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.
There's actually an Nginx file type defined in the official Nginx repository in the contrib/vim directory. It provides better syntax highlighting than conf.
To use it, copy the detection lines to your .vimrc (and tweak as desired):
Then copy nginx.vim to your ~/.vim/syntax directory.
All Nginx files following the above rules should now be highlighted.
If you'd like the indenting as well, you can also copy the file from the indent directory into your .vimrc.
The following line in
~/.vimrc
should do this.Easiest way to get vim filetype you want is to specify it at the top of the file via a modeline. In this case, place the following comment in the first 5 lines of the file
More information on filetype and modeline is available here http://vimdoc.sourceforge.net/htmldoc/filetype.html http://vimdoc.sourceforge.net/htmldoc/options.html#modeline
No need to edit
vimrc
for that. Just takecontrib/vim
files fromnginx
source tree and place them into$HOME/.vim
so that tree should be like that:Then whenever you open
nginx.conf
ft
gets detected and highlight gets applied automatically.In my case, on a small Debian install, the relevant files already existed (possibly for the default
vim.tiny
) but weren't sourced in regularvim
. It was easily fixed with this: