[英]How do I set a .vimrc configuration for many file types?
Let's say I want one group of settings for HTML, CSS and JavaScript files but another set for Ruby files (completely different). 假设我想要一组HTML,CSS和JavaScript文件设置,但另一组设置为Ruby文件(完全不同)。 What's the simplest way to do this? 最简单的方法是什么?
You can give global settings like this. 您可以提供这样的全局设置。
For other files: 对于其他文件:
set shiftwidth=4
for Ruby files: 对于Ruby文件:
autocmd BufRead,BufNewFile *.rb set shiftwidth=2
You can get what you want via autocmd
, it's format as follows: 你可以通过autocmd
获得你想要的东西,它的格式如下:
au[tocmd] [group] {event} {pattern} [nested] {cmd}
[group]
and [nested]
are optional.As I give the example above, BufRead,BufNewFile
is the event, *.rb
is the pattern, and set shiftwidth=2
is the cmd. [group]
和[nested]
是可选的。 BufRead,BufNewFile
我给出的例子, BufRead,BufNewFile
是事件, *.rb
是模式, set shiftwidth=2
是cmd。
more information about autocmd
, please refer: :help automcd
有关autocmd
更多信息,请参阅:help automcd
You can put ftplugin
directory with filetype-specific settings inside .vim
directory 您可以将ftplugin
目录与.vim
目录中的特定于文件类型的设置放在一起
.vim
└── ftplugin
└── ruby.vim
└── markdown.vim
And keep your settings there. 并保持您的设置。 The are applied when file with corresponding filetype is opened. 在打开具有相应文件类型的文件时应用。
Also, you might need to have filetype detection(if not detected properly). 此外,您可能需要检测文件类型(如果未正确检测到)。 You can put this to your .vimrc
你可以将它放到.vimrc
autocmd BufNewFile,BufRead *.markdown,*.md,*.mdown,*.mkd,*.mkdn set ft=markdown
Or, put it into ftdetect
directory 或者,将其放入ftdetect
目录
.vim
└── ftdetect
└── markdown.vim
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.