如何在 Vim 启动后手动加载 ftplugin?
假设我将 .txt 文件加载到 Vim 中。然后我想更改 filetype=html
但我还想加载关联的 ftplugin。我该怎么做?
我尝试过类似的东西: :set filetype plugin on
和 :set filtype plugin_name
on 以及 :filetype plugin_name
on 等等,但是我似乎无法手动加载 ftplugin。有什么建议吗?
我尝试过 :filetype=html
和 :filetype plugin on
以及其他组合,但均无济于事。
编辑:我无法用任何答案“完全”解决这个问题(但这可能是我的配置的个别问题)。然而,皮埃尔的回答非常好,所以我给了他绿色的复选标记。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我相当确定,当您使用
:set ft=X
切换文件类型时,它会自动在 .vim/ftplugin 文件夹中加载关联的插件。例如:set ft=html
将加载 .vim/ftplugin/html.vim,您可以在其中加载任何关联的插件。但是,与 html 文件关联的BufEnter
和BufNew
插件加载将不会加载,因为设置新文件类型不会触发这些事件。因此,如果您的 .vimrc 中有使用BufNew
或BufEnter
加载的 html 特定插件,您可能需要将它们放入 .vim/ftpluging/html.vim 文件中。您始终可以将模型行添加到更改文件类型的文本文件中。例如
。
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. HoweverBufEnter
andBufNew
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 withBufNew
orBufEnter
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 -->
.刚刚遇到了同样的情况,即使我打开了 Perl 文件,ftplugins 也没有加载。结果我的 Vim 副本(来自
Git for Windows
)没有附带ftplugin.vim
和ftplugof.vim
以下是我的情况意识到这一点:
:filetype
:scriptnames
ftplugin\
的脚本。ftplugin.vim
。检查 Vim 目录 (< code>{git-path}/share/vim/vim{version}/) 有
ftplugin.vim
和ftplugof.vim
:filetype plugin on
和:filetype plugin off
时获取的为了解决这个问题,我从 Vim 运行时文件 并复制到它应该去的地方。
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 withftplugin.vim
andftplugof.vim
Here's how I arrived at that realization:
:filetype
:scriptnames
ftplugin\
is sourced.ftplugin.vim
in there.check if Vim directory (
{git-path}/share/vim/vim{version}/
) has theftplugin.vim
andftplugof.vim
: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.
当您更改文件类型时,Vim 会自动加载正确的插件
您可以以详细模式启动 vim:
这将显示 vim 正在执行什么。如果您打开文件并手动设置文件类型,vim 将显示它是否正在加载正确的插件。
Vim automatically loads the correct plugin when you change the filetype
You can start up vim in verbose mode:
This will show you what vim is executing. If you open a file and manually set the filetype, vim will show if it's loading the correct plugin.