VIM filetypes - why do some file type matchers use "call" and others "setf"?

220 Views Asked by At

Suppose I've written a new syntax file for vim, for some file type, and I now want to integrate it into vim (8.1). I'm looking at /usr/share/vim/vim81/filetypes.vim, and I'm noticing some lines have the form:

au BufNewFile,BufRead *.ext                     setf foo

For some extension .ext and syntax file syntax/foo.vim. But some lines have something else:

au BufNewFile,BufRead *.asm,*.[sS],*.[aA],*.mac,*.lst,*.ptx     call dist#ft#FTasm()

or

au BufNewFile,BufRead proftpd.conf*             call s:StarSetf('apachestyle')

Why this difference? And which should I be using?

1

There are 1 best solutions below

2
romainl On

:setf foo is a pretty simple command that sets the filetype of the current buffer to foo if it wasn't already set.

The authors of the scripts you quote probably have other needs, or they may have to perform more checks or whatever, so they decided to encapsulate all that stuff in custom functions, which are called with :call FunctionName().

So…

  • use the first form if you have basic needs,
  • use the second form if you have more complex needs.

See :help :setf and :help :call.