没有扩展名的文件的 vim 默认语法 [英] vim default syntax for files with no extension

查看:29
本文介绍了没有扩展名的文件的 vim 默认语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为 vim 中没有扩展名的文件设置默认语法?

How do I set up a default syntax for files that have no extension in vim?

推荐答案

对于没有设置语法的文件,一种方法是在 .vimrc 中添加自动命令:

One way would be to add an autocommand to your .vimrc for files that don't have the syntax set:

au BufNewFile,BufRead * if &syntax == '' | set syntax=html | endif

或者,您可以为任何未定义的文件设置文件类型:

Or, you could set the filetype for any file that it's not defined for:

filetype plugin on
au BufNewFile,BufRead * if &ft == '' | set ft=html | endif

filetype plugin onau 命令一起设置可以提供加载 HTML 插件(如果有的话)的额外好处.这也将语法设置为html".

Setting filetype plugin on along with the au command gives the added benefit of loading HTML plugins if you have any. This also sets the syntax to "html" as well.

这篇关于没有扩展名的文件的 vim 默认语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆