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 1


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 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
  • 1
    You should probably move the "edit" to the top of the post. :D
    – muru
    Jan 25, 2016 at 14:27
  • 1
    Your 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.
    – Rich
    Jan 25, 2016 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.