I have a file in my
~/.vim/ftdetect directory, which includes configuration such as:
autocmd BufRead,BufNewFile,BufWritePost .envrc.template set filetype=sh
However, I also have the
vim-polyglot plugin installed (in
~/.vim/pack/packager/start/vim-polyglot/ftdetect/polyglot.vim, which includes the (less specific) instruction:
autocmd BufNewFile,BufRead *.template setlocal filetype=json
The loading order appears to ensure that the latter
autocmd takes priority, which means that files called
.envrc.template are incorrectly detected as JSON files.
How can I elegantly fix this? Ideally I'd like to keep the
vim-polyglot plugin installed; and use the
~/.vim/ftdetect directory as I think it's intended. Is there a way to change the order in which the autocmds are applied?
An extract of the output of
:scriptnames (edited for privacy and with large sections of files in similar/identical paths removed for length) below. Note the relative positions of lines 5 and 96.
1: /etc/xdg/nvim/sysinit.vim 2: /usr/share/nvim/archlinux.vim 3: ~/.vim/init.vim 4: /usr/share/nvim/runtime/filetype.vim 5: ~/.vim/after/ftdetect/all.vim 6: /usr/share/vim/vimfiles/ftdetect/dockerfile.vim ... 8: /usr/share/nvim/runtime/ftplugin.vim 9: /usr/share/nvim/runtime/indent.vim 10: /usr/share/nvim/runtime/syntax/syntax.vim 11: /usr/share/nvim/runtime/syntax/synload.vim 12: /usr/share/nvim/runtime/syntax/syncolor.vim ... 17: ~/.vim/plugin/completion.vim 18: ~/.vim/plugin/diff.vim ... 36: /usr/share/nvim/runtime/plugin/gzip.vim 37: /usr/share/nvim/runtime/plugin/health.vim ... 96: ~/.vim/pack/packager/start/vim-polyglot/ftdetect/polyglot.vim ... 127: ~/.vim/after/plugin/vim-pencil.vim 128: ~/.vim/after/plugin/vim-polyglot.vim ...
'runtimepath' as per Ben Knoble's question (again, edited for length) is:
/Users/user/.config/nvim ... /Users/user/.config/nvim/pack/packager/start/vim-polyglot ... /Users/user/.config/nvim/pack/packager/start/ale /etc/xdg/nvim /Users/user/.local/share/nvim/site /usr/local/share/nvim/site /usr/share/nvim/site /usr/local/Cellar/neovim/0.4.3/share/nvim/runtime /usr/local/Cellar/neovim/0.4.3/share/nvim/runtime/pack/dist/opt/matchit /usr/share/nvim/site/after /usr/local/share/nvim/site/after /Users/user/.local/share/nvim/site/after /etc/xdg/nvim/after /Users/user/.config/nvim/after