Why does vim select this file differently?

Note

I use the local vim plugin, which allows me to use a specific project .vimrc file, in general it works fine and, as expected.

Background

I work with Silverstripe and therefore should work with Silverstripe templates, which are * .ss files, but by default vim assigns * .ss files to schema files. Now I use only Silverstripe for one project and use the html filetype installed in my project for the .vimrc widget for selection, however, after detecting several errors, I decided that I would add the selection for * .ss files to htmlss.vim (using html.vim in as a base, I just added template rules closer to the end). After several trial and error, I got it working and highlighting correctly, however, I ran into a strange error ...

Question

Using this .vimrc project:

augroup filetypedetect autocmd! * *.ss autocmd! BufEnter *.ss setf htmlss augroup END 

Everything works fine, however, using this .vimrc:

 augroup filetypedetect autocmd! * *.ss autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss augroup END 

Syntax highlighting fails, it sets the file type correctly, but highlighting becomes creepy.

I suppose I want to know why version 1 works, but version 2 does not work, no matter what changes.

adding

After a little research, I found that removing autocmd! * *.ss autocmd! * *.ss does a second job only if I delete ! from autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss . i.e.

 augroup filetypedetect autocmd BufEnter,BufRead,BufNewFile *.ss setf htmlss augroup END 

works but

 augroup filetypedetect autocmd! BufEnter,BufRead,BufNewFile *.ss setf htmlss augroup END 

and

 augroup filetypedetect autocmd! * *.ss autocmd BufEnter,BufRead,BufNewFile *.ss setf htmlss augroup END 

not.

Again, my question is why these differences occur, I now have a working implementation, so I'm not interested in any kind of research. I do not want solutions because I have no problems.

+4
source share
1 answer

This is probably due to the fact that your syntax file contradicts itself with repeated use. One of the first lines in the syntax file is probably syntax enable , which allows syntax without changing any current selection settings. Per docs :

 The ":syntax enable" command will keep your current color settings. This allows using ":highlight" commands to set your preferred colors before or after using this command. If you want Vim to overrule your settings with the defaults, use: :syntax on 

So, an adequate β€œsolution” should be to change syntax enable to syntax on in the syntax file.

+2
source

Source: https://habr.com/ru/post/1394073/


All Articles