There is a standard for providing files that may have an unversioned counterpart. That standard consists in suffixing the filename with .dist, so for example phpunit.xml becomes phpunit.xml.dist. How can I tell vim that whenever it sees that suffix, it should remove it when attempting to determine the filetype?


Put this into


autocmd BufNewFile,BufRead ?\+.dist
    \ execute 'doautocmd filetypedetect BufRead' fnameescape(expand('<afile>:r'))

Basically we strip the .dist extension and re-execute the filetype-detection routine. A similar code is used in $VIMRUNTIME/filetype.vim to detect filetype for *.bak, *.old and a few other "generic" extensions. Unfortunately, *.dist isn't found there.

  • 1
    Thank you! When I think of all these years I wasted not asking this question… – greg0ire Aug 27 '20 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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