I want vim to automatically set the filetype to PKGBUILD when I am editing files that are named "PKGBUILD". How can I accomplish this?
1 Answer
You could define the following autocmd in your vimrc :
autocmd BufRead,BufNewFile PKGBUILD set filetype=PKGBUILD
And to make sure the autocmd is not duplicated every time your vimrc is sourced, you could wrap it into an augroup and empty the latter at the beginning (autocmd!
):
augroup pkgbuild
autocmd!
autocmd BufRead,BufNewFile PKGBUILD set filetype=PKGBUILD
augroup END
BufRead
and BufNewFile
are 2 possible events which will trigger, for a buffer whose name is PKGBUILD
, the command: set filetype=PKGBUILD
For more information, see:
:help autocmd
:help autocmd-events
:help augroup
-
1You should probably move the "edit" to the top of the post. :D– muruCommented Jan 25, 2016 at 14:27
-
1Your new edit implies that the augroup brings "no advantage", which is not correct. I'd be tempted just to remove the older version of the autocmd entirely.– RichCommented Jan 25, 2016 at 15:28