1

I'm trying to understand using the autocmd to modify properties for certain files. Here is a basic example I have in my vimrc:

syntax on
autocmd BufRead *.py syntax off

However, when I then open up a new python file, all files in that window (whether python or not) have their syntax highlighting removed. For example:

enter image description here

Why does this occur, and what would be the proper way to change something for only the filetype I'm referencing and not other windows/splits?

Note: the same thing also happens with:

autocmd FileType python syntax off

From Learn Vimscript the Hard Way:

One of the most useful events is the FileType event. This event is fired whenever Vim sets a buffer's filetype.

But if the user has to manually set the ft everytime a file is opened, it seems quite useless (if I'm understanding things correctly).

5

The :syntax command is global. Probably you're looking for the "local to buffer" setting 'syntax' (abbreviation: 'syn'). To disable for current file:

set syn=OFF

per :h 'syn' though set syn= and set syn& seem to work, too.

You can use this with a filetype auto command like so:

autocmd FileType python set syn=OFF

Each time you open a Python file it should be without syntax highlighting.

(I wouldn't be surprised if there were other ways to accomplish this but I verified the above works.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.