可以根据文件扩展名更改选项卡的长度吗? [英] Possible to change length of tab depending on file extension?

查看:20
本文介绍了可以根据文件扩展名更改选项卡的长度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
按文件类型更改 Vim 缩进行为

你好.因此,我经常在制表符的2"和4"空格之间切换.通常我使用 2 个空格作为 HTML 文件的制表符和 4 个空格作为编程的制表符.反正有没有配置VIM,所以它会根据文件扩展名自动调整?另外,为什么 VIM 有时会缩进 8 个空格,比如在我输入一个左括号之后?我将它设置为 4 个空格.谢谢.

Hello. So, I switch between '2' and '4' spaces for tabs very often. Usually I use 2 spaces for a tab for HTML files and 4 spaces for a tab for programming. Is there anyway to configure VIM, so it will automatically adjust depending on the file extension? Also, how come VIM indents 8 spaces sometimes, like after I enter an open brace? I have it set to 4 spaces. Thanks.

推荐答案

set sw=4 ts=4 sts=4                             " Defaults: four spaces per tab "
autocmd FileType html :setlocal sw=2 ts=2 sts=2 " Two spaces for HTML files "

这里有三个不同的选项:'shiftwidth' ('sw') 控制自动缩进的空格数和一些移位命令(如 <<< 在正常模式下),'tabstop'('ts') 控制实际制表符的可视长度,您可能希望保留默认值(8 个可视单元格),'softtabstop' ('sts') 控制按下 <Tab> 时插入/删除的内容..我建议您将其设置为 'tabstop' 的值或将其与 'expandtab' 一起设置,因为在其他情况下它会产生难看的制表符+空格缩进.

Here are three different options: 'shiftwidth' ('sw') controls number of spaces for automatic indentation and some shifting commands (like << in normal mode), 'tabstop' ('ts') controls visual length of a real tab character, you may want to leave defaults (8 visual cells), 'softtabstop' ('sts') controls what is being inserted/removed when you press <Tab> and <CR>. I suggest you either set it to the value of 'tabstop' or set it alongside with 'expandtab' because in other cases it will produce ugly tabs+spaces indentation.

这篇关于可以根据文件扩展名更改选项卡的长度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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