如何在 Vim 中更改标签大小? [英] How do I change tab size in Vim?

查看:14
本文介绍了如何在 Vim 中更改标签大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我在 CSS 中添加选择器并按 Enter 来定义属性时,它最终会像这样:

Every time I add a selector in CSS and I press Enter to define the properties it ends up like this:

#selector {
        property: value;
}

(8 个空格的制表符)

(8-space tabs)

我如何配置 Vim 使其像这样:

How can I configure Vim to make it like this:

#selector {
    property: value;
}

(4 个空格的制表符)

(4-space tabs)

推荐答案

扩展 zoul 的回答:

Expanding on zoul's answer:

如果您想设置 Vim 在编辑特定文件类型时使用特定设置,您需要使用自动命令:

If you want to setup Vim to use specific settings when editing a particular filetype, you'll want to use autocommands:

autocmd Filetype css setlocal tabstop=4

这将使选项卡显示为 4 个空格.设置 expandtab 将导致 Vim 在按下 Tab 键时实际插入空格(它们的数量由 tabstop 控制);您可能希望使用 softtabstop 使退格符正常工作(也就是说,在使用制表符时减少缩进,而不是每次删除一个字符).

This will make it so that tabs are displayed as 4 spaces. Setting expandtab will cause Vim to actually insert spaces (the number of them being controlled by tabstop) when you press tab; you might want to use softtabstop to make backspace work properly (that is, reduce indentation when that's what would happen should tabs be used, rather than always delete one char at a time).

要做出有关如何设置的充分教育的决定,您需要阅读关于 tabstopshiftwidthsofttabstopexpandtab.最有趣的一点是在 expandtab (:help 'expandtab) 下:

To make a fully educated decision as to how to set things up, you'll need to read Vim docs on tabstop, shiftwidth, softtabstop and expandtab. The most interesting bit is found under expandtab (:help 'expandtab):

在 Vim 中有四种主要的标签使用方式:

There are four main ways to use tabs in Vim:

  1. 始终将 'tabstop' 设置为 8,将 'softtabstop' 和 'shiftwidth' 设置为 4(或 3 或任何您喜欢的值)并使用 'noexpandtab'.然后 Vim 将混合使用制表符和空格,但输入和行为将类似于每 4(或 3)个字符出现一个制表符.

  1. Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4 (or 3 or whatever you prefer) and use 'noexpandtab'. Then Vim will use a mix of tabs and spaces, but typing and will behave like a tab appears every 4 (or 3) characters.

将tabstop"和shiftwidth"设置为您喜欢的任何值并使用expandtab".这样,您将始终插入空格.'tabstop' 改变时格式永远不会搞砸.

Set 'tabstop' and 'shiftwidth' to whatever you prefer and use 'expandtab'. This way you will always insert spaces. The formatting will never be messed up when 'tabstop' is changed.

将 'tabstop' 和 'shiftwidth' 设置为您喜欢的任何值并使用 |modeline|再次编辑文件时设置这些值.仅在使用 Vim 编辑文件时有效.

Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a |modeline| to set these values when editing the file again. Only works when using Vim to edit the file.

始终将 'tabstop' 和 'shiftwidth' 设置为相同的值,以及 'noexpandtab'.这应该适用于人们使用的任何制表位设置(仅适用于初始缩进).如果你这样做的话,在第一个非空白之后插入空格可能会很好.否则当'tabstop'改变时对齐的注释会出错.

Always set 'tabstop' and 'shiftwidth' to the same value, and 'noexpandtab'. This should then work (for initial indents only) for any tabstop setting that people use. It might be nice to have tabs after the first non-blank inserted as spaces if you do this though. Otherwise aligned comments will be wrong when 'tabstop' is changed.

这篇关于如何在 Vim 中更改标签大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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