LnL7 / vim-nix

Vim configuration files for Nix http://nixos.org/nix
MIT License
287 stars 26 forks source link

Use setfiletype instead of set filetype #31

Closed doronbehar closed 3 years ago

doronbehar commented 4 years ago

Hi,

This is kind of hard to explain, and I can't really point to the right location in the docs that explains this, but the TL;DR of this change is:

Enable me to add something like this to my filetype.vim

" Nixpkgs
au BufNewFile,BufRead /var/src/nixpkgs/** setf nix.nixpkgs

(While I set some extra settings to ftplugin/nixpkgs.vim).

I've learned about this subtlety at https://github.com/neomutt/neomutt.vim/pull/4 .

doronbehar commented 4 years ago

BTW great plugin! Without you it'd have taken me a month to get errorformat as I needed :).

bew commented 3 years ago

This is a good change! The docs of setfiletype explains it quite well:

:setf[iletype] {filetype}           *:setf* *:setfiletype*
            Set the 'filetype' option to {filetype}, but only if
            not done yet in a sequence of (nested) autocommands.
            This is short for:
                :if !did_filetype()
                :  setlocal filetype={filetype}
                :endif
            This command is used in a filetype.vim file to avoid
            setting the 'filetype' option twice, causing different
            settings and syntax files to be loaded.
            {not in Vi}

Since plugins autocommands are run after user ones, we can't override the filetype if we want to change it a little like @doronbehar shows.