Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Say I load a .txt file into Vim. Then I want to change the
filetype=html
but I also want an associated ftplugin loaded. How can I do this?
I've tried stuff like:
:set filetype plugin on
and
:set filtype plugin_name
on and also
:filetype plugin_name
on etc etc., but I can't seem to manually load the ftplugin. Any suggestions?
I've tried
:filetype=html
and then
:filetype plugin on
and other combinations to no avail.
EDIT: I was not able to "completely" solve this with any of the answers (but it maybe something individual to my configuration). However, Pierre's answers were pretty darn good so I'm giving him the green check mark.
I'm fairly sure that when you switch a file's type using
:set ft=X
it will automatically load the associated plugin in your .vim/ftplugin folder. E.g.
:set ft=html
would load .vim/ftplugin/html.vim where you would load any associated plugins. However
BufEnter
and
BufNew
plugin loads associated with html files won't be loaded as setting a new filetype does not trigger these events. So if you have html specific plugins in your .vimrc that are loaded with
BufNew
or
BufEnter
you may want to put them in a .vim/ftpluging/html.vim file instead.
You could always add a modeline to your text file that changes the filetype. E.g.
<!-- vim: ft=html -->
.
–
–
–
–
–
Just had the same situation where ftplugins weren't loading even though I had a Perl file open. Turns out that my copy of Vim (from
Git for Windows
) didn't come with
ftplugin.vim
and
ftplugof.vim
Here's how I arrived at that realization:
:filetype
check that filetype plugin is indeed turned on.
:scriptnames
print the list of sourced scripts, found out no script from
ftplugin\
is sourced.
I didn't realize it at that time, but I should've noticed that I didn't see
ftplugin.vim
in there.
check if Vim directory (
{git-path}/share/vim/vim{version}/
) has the
ftplugin.vim
and
ftplugof.vim
these files are sourced when you execute
:filetype plugin on
and
:filetype plugin off
To fix this, I grabbed the missing files from the
Vim runtime files
and copied to where it should go.
–
–
–
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.