autocmd 文件类型与 ftplugin
有什么区别
autocmd FileType ruby setlocal ts=2
放置:
setlocal ts=2
在我的 ~/.vimrc
中放置:和在 ~/.vim/ftplugin/ruby.vim
中
?如果没有区别,我应该在哪里放置特定于一种文件类型的命令?
What is the difference between placing:
autocmd FileType ruby setlocal ts=2
in my ~/.vimrc
and placing:
setlocal ts=2
in ~/.vim/ftplugin/ruby.vim
?
If there is no difference, where should I place commands that are specific to one filetype?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,两者之间并没有真正的区别。
我更喜欢将这样的命令放在 ftplugin 中,并保持我的主要 .vimrc 与语言无关......但是没有硬性规则。将其保留在
vimrc
中的一个优点是您的 vim 设置将更容易移动(例如,您只需复制.vimrc 即可在新计算机上获取所有 vim 设置)
,而不是.vimrc
+.vim
)。显然,将它们放入您的.vimrc
也会有轻微的性能损失(即,它们将为每个文件加载+执行,而不仅仅是 ruby 文件)......但我真的不会担心这一点。As far as I know, there isn't really a difference between the two.
I prefer to put commands like that in
ftplugin
and keep my main.vimrc
language-agnostic… But there are no hard-and-fast rules. An advantage to keeping it in yourvimrc
would be that your vim settings would be easier to move around (ex, you could get all your vim settings on a new machine by simply copying your.vimrc
, instead of.vimrc
+.vim
). Obviously putting them in your.vimrc
will also have a minor performance penalty (ie, they will be loaded + executed for every file, not just ruby files)… But I wouldn't really worry about that.