2

I know a little bit of autocmd and use it for few things. Currently, I have

au BufNewFile,BufRead *.inc set filetype=sql
au BufNewFile,BufRead *.tbl set filetype=sql

Reading the man page, the general syntax is

:autocmd [group] {events} {file_pattern} [nested] {command}

I would like to know, whether I can combine the above 2 statements in a single lin i.e. how can we specify more that one file extension in the file_pattern section? The man page doesn't say about this, but I believe it can be comma or space separated. Any hints?

mtk
  • 26,802
  • 35
  • 91
  • 130

1 Answers1

6

I believe it can be comma or space separated

No, the file pattern list must be comma separated with no spaces:

au BufNewFile,BufRead *.tbl,*.inc setf sql

Beware that injecting a space will not result in an error, and the autocmd will still apply properly to patterns before the space, but the ones after that will be ignored.

goldilocks
  • 86,451
  • 30
  • 200
  • 258
  • 1
    I believe it's strictly comma separated and there cannot be a space in the list. This means `*.tbl,*.inc` works, but `*.tbl *.inc` or `*.tbl, *.inc` will not (at least with vim v8.1) – Steve Friedl Aug 14 '22 at 16:27
  • Thanks -- I'm surprised I'd would post this without having confirmed spaces were okay, since looking through my current conf files I don't use spaces, and a quick test demonstrates they are no good. – goldilocks Aug 14 '22 at 19:20
  • We're all here to help :-) – Steve Friedl Aug 14 '22 at 19:45