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

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

问题描述

每次在CSS中添加选择器,然后按输入即可定义其属性,如下所示:

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个空格标签)

如何配置Vim使其像这样:

How can I configure Vim to make it like this:

#selector {
    property: value;
}

(4个空格标签)

推荐答案

扩展zoul的答案:

如果要在编辑特定文件类型时设置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实际插入空格(它们的数量由 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).

为了做出有关如何设置的完整教育决策,您需要在 tabstop shiftwidth softtabstop expandtab 。最有趣的位在 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'。

  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'选项卡和空格,然后输入并显示每4(或3)和'shiftwidth'到任何你喜欢和使用'expandtab'。这样,你将总是插入空格。

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 |在再次编辑文件时设置这些值。

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'。这应该然后工作(只有初始缩进)人们使用的任何制表符设置。在第一个非空白之后插入制表符作为空格可能很好,如果你这样做。

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天全站免登陆