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?
-
2Welcome to Vi and Vim!– D. Ben Knoble ♦Aug 28, 2020 at 13:57
Add a comment
|
1 Answer
Put this into
~/.vim/ftdetect/dist.vim
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.
-
1Thank you! When I think of all these years I wasted not asking this question…– greg0ireAug 27, 2020 at 18:24