如何更改vim显示硬选项卡的方式

如何更改vim显示硬选项卡的方式,vim,Vim,如何将vim显示选项卡设置为4个空格? 我试着玩set list和set listchars,但这只改变了代表选项卡的8个字符。我想保留制表符,但让它们占用4个空格而不是8个空格。这可能吗 :h 'ts' 你会看到: 'tabstop' 'ts' number (default 8) local to buffer Number of spaces that a <Tab> in the file counts for. Also se

如何将vim显示选项卡设置为4个空格? 我试着玩
set list
set listchars
,但这只改变了代表选项卡的8个字符。我想保留制表符,但让它们占用4个空格而不是8个空格。这可能吗

:h 'ts'
你会看到:

'tabstop' 'ts'      number  (default 8)
            local to buffer
    Number of spaces that a <Tab> in the file counts for.  Also see
    |:retab| command, and 'softtabstop' option.

    Note: Setting 'tabstop' to any other value than 8 can make your file
    appear wrong in many places (e.g., when printing it).

    There are four main ways to use tabs in Vim:
    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 <Tab> and <BS> will
       behave like a tab appears every 4 (or 3) characters.
    2. 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.
    3. 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.
    4. 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.
'tabstop'ts'编号(默认为8)
本地到缓冲区
文件中a所占的空间数。也看到
|:retab |命令和“softtabstop”选项。
注意:将“tabstop”设置为8以外的任何其他值都可以使您的文件
在许多地方出现错误(例如,打印时)。
Vim中有四种主要的选项卡使用方式:
1.始终将“tabstop”设置为8,将“softtabstop”和“shiftwidth”设置为4
(或3或任何您喜欢的)并使用“noexpandtab”。然后是维姆
将混合使用制表符和空格,但键入和
每4(或3)个字符显示一个选项卡。
2.将“tabstop”和“shiftwidth”设置为您喜欢和使用的任意值
“expandtab”。这样,您将始终插入空格。这个
更改“tabstop”时,格式将永远不会混乱。
3.将“tabstop”和“shiftwidth”设置为您喜欢的值,并使用
|modeline |在再次编辑文件时设置这些值。只有
使用Vim编辑文件时工作。
4.始终将“tabstop”和“shiftwidth”设置为相同的值,并且
“noexpandtab”。这样就可以了(仅适用于初始缩进)
对于人们使用的任何tabstop设置。有可能很好
如果执行此操作,则第一个非空选项卡后的选项卡将作为空格插入
不过。当使用“tabstop”时,否则对齐的注释将是错误的
改变。

制表符的宽度由
'tabstop'
选项决定:

:set tabstop=4
请注意,将其从默认值8更改为8可能会影响其他程序显示该文件的方式,因此不鼓励这样做。在这种情况下,最好插入文本空格字符(通过
:set expandtab