I understand that the recommended method for defining filetype-specific behavior in Vim is with .vim
files and filetype plugin
option. To add settings for .html
files, for instance, I would add filetype plugin on
in my .vimrc
and add the settings to ~/.vim/ftplugin/html.vim
.
All examples of this method that I can find, however, are about popular existing filetypes like .html
or .sql
. Would the same fix work for custom-defined file types? Let's say I want to use a new filetype with the extension .newft
. If I create ~/.vim/ftplugin/newft.vim
with the settings for this new type and load somefile.newft
, would Vim automatically detect its type and load newft.vim
?
I'm asking this because this is exactly what I'm doing and it's not working so far. I'd like to know whether this is an error or an expected behavior of Vim.
:h new-filetype
outlines the different ways to add support for a new filetype.
I recommend method A
which is as simple as writing the following in ~/.vim/ftdetect/newft.vim
:
autocmd BufRead,BufNewFile *.newft set filetype=newft
and letting Vim deal with the rest.
Assuming you have filetype plugin on
in your ~/.vimrc
, the example above will make Vim try to source ~/.vim/ftplugin/newft.vim
each time you read or create a buffer associated with a *.newft
file or do :setfiletype newft
/:set filetype=newft
on an existing buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With