leafo
leafo

Reputation: 1852

How can I stop vim from loading a syntax file automatically for certain file types?

I am working on a project writing a GLSL fragment shader, and it just so happens it has the file extension .fs, thus vim automatically loads the forth syntax upon opening the file.

This normally would be no problem, I could just change the syntax using au BufRead but for some reason the forth syntax is loaded first, which completely messes things up. It adds more characters to a "word" which causes syntax highlighting and motions to not work as expected.

Is there a way to stop the forth syntax from loading, and only load my specified syntax?

Upvotes: 3

Views: 1425

Answers (2)

too much php
too much php

Reputation: 90988

Add the following line to the end of your syntax file:

let b:current_syntax = "<filetype>"

Upvotes: 0

Bill Odom
Bill Odom

Reputation: 4193

Create a file in your .vim directory (or vimfiles directory on Windows) called filetype.vim and put this code in it:

if exists("did_load_filetypes")
    finish
endif

augroup filetypedetect

    " Ignore filetypes for *.fs files
    autocmd! BufNewFile,BufRead *.fs  setfiletype ignored

augroup END

This places a custom filetype-detection script ahead of Vim's default filetype autocommands, so your detection autocommands get a chance to determine the filetype before the usual Vim scripts.

Once you restart Vim and attempt to load a .fs file, it should no longer use Forth syntax highlighting, and iskeyword should still be set to the default value. (If you've installed a syntax file for the GLSL fragment files, you can replace the ignored with the appropriate filetype name.)

See these topics for more info:

:help remove-filetype
:help new-filetype
:help :setfiletype

Upvotes: 6

Related Questions