How do I set up a default syntax for files that have no extension in vim?
A:
If I remeber it right you can put a file named syntax.vim inside your ~/.vim/syntax folder. This file is used as default syntax highlight source. If your .vim folder does not exist, you have to create it:
mkdir ~/.vim
mkdir ~/.vim/syntax
touch ~/.vim/syntax/syntax.vim
Now you can add your default syntax to the syntax.vim file. For further documentation you can look at the vim sourceforge page.
Hope this helps.
wroks
2010-04-19 10:42:29
not what I asked for.. sorry
zly
2010-04-19 11:19:42
Then please be more accurate about your problem in your description.. it's not very descriptive right now.
wroks
2010-04-19 12:12:23
Some files have no extensions (suffixes) right? Case in point, html files I work on don't have .html suffixes. They're named like this: file1, file2, etc. Now, I'd like vim to automatically set html syntax when I'm opening those extension-less files. How do I do that?
zly
2010-04-19 13:40:40
@zly: This can be used to do *exactly* what you asked for - you can edit the installed syntax.vim, or copy it into ~/.vim/syntax. This file is sourced when you run `syntax enable`, so it can easily check to see if a filetype was detected, and use a default (e.g. html) syntax if not.
Jefromi
2010-04-19 18:49:23
@Jefromi, I was expecting specifics not guidelines; guess I wasn't specific enough what I was expecting ;-) @Curt Nelson did answer my question tho.
zly
2010-04-20 10:20:19
+3
A:
One way would be to add an autocommand to your .vimrc
for files that don't have the syntax set:
au BufNewFile,BufRead * if &syntax == '' | set syntax=html | endif
Or, you could set the filetype for any file that it's not defined for:
filetype plugin on
au BufNewFile,BufRead * if &ft == '' | set ft=html | endif
Setting filetype plugin on
along with the au
command gives the added benefit of loading HTML plugins if you have any. This also sets the syntax to "html" as well.
Curt Nelson
2010-04-19 16:56:44