按文件类型设置 Vim 空白首选项 [英] Setting Vim whitespace preferences by filetype

查看:31
本文介绍了按文件类型设置 Vim 空白首选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作中,我被要求按照房屋样式进行缩进,具体如下:

At my work, I am required to follow the house style for indentation, which goes as follows:

  • 编码 html 和 ruby​​ 时有 2 个空格
  • 在编写 javascript 时使用制表符,推荐使用 tabwidth=4

为每种文件类型指定不同的空白首选项的最佳方法是什么?

What is the best way to specify different whitespace preferences per filetype?

推荐答案

有很多方法,但这里有一个简单易懂的方法.将这些行添加到您的 ~/.vimrc:

there are many ways, but here's a simple, easy to understand way. add these lines to your ~/.vimrc:

autocmd FileType html setlocal ts=2 sts=2 sw=2
autocmd FileType ruby setlocal ts=2 sts=2 sw=2
autocmd FileType javascript setlocal ts=4 sts=4 sw=4

这篇关于按文件类型设置 Vim 空白首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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