将制表符重新定义为 4 个空格 [英] Redefine tab as 4 spaces

查看:41
本文介绍了将制表符重新定义为 4 个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的设置假设为 8 个空格;我怎么能重新定义它?

My current setting assumes 8 spaces; how could I redefine it?

推荐答案

这取决于你的意思.您是否希望文件中的实际制表符 出现 4 个空格宽,或者制表符"实际上是指按制表键生成的 缩进,这将导致文件字面上为您键入的每个制表符"包含(最多)4 个空格字符?

It depends on what you mean. Do you want actual tab characters in your file to appear 4 spaces wide, or by "tab" do you actually mean an indent, generated by pressing the tab key, which would result in the file literally containing (up to) 4 space characters for each "tab" you type?

根据您的回答,选择以下一组设置应该适合您:

Depending on your answer, one of the following sets of settings should work for you:

  • 对于出现 4 个空格宽的制表符:

set tabstop=4

如果您在源代码中使用了实际的制表符,您可能还需要这些设置(这些实际上是默认值,但您可能想要防御性地设置它们):

If you're using actual tab character in your source code you probably also want these settings (these are actually the defaults, but you may want to set them defensively):

set softtabstop=0 noexpandtab

最后,如果你想让一个缩进对应一个标签,你还应该使用:

Finally, if you want an indent to correspond to a single tab, you should also use:

set shiftwidth=4

  • 对于由 4 个空格字符组成的缩进,但使用 Tab 键输入:

  • For indents that consist of 4 space characters but are entered with the tab key:

    set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
    

  • 要使上述设置永久添加这些行到您的 vimrc.

    如果您需要进行调整,或者只是想了解这些选项的全部含义,以下是每个选项含义的细分:

    In case you need to make adjustments, or would simply like to understand what these options all mean, here's a breakdown of what each option means:

    硬制表位的宽度(以空格"为单位)——实际上是实际制表符的(最大)宽度.

    tabstop

    The width of a hard tabstop measured in "spaces" -- effectively the (maximum) width of an actual tab character.

    缩进"的大小.它也是用空格来衡量的,所以如果你的代码库用制表符缩进,那么你希望 shiftwidth 等于制表符的数量乘以 tabstop.这也被 =>< 命令使用.

    The size of an "indent". It's also measured in spaces, so if your code base indents with tab characters then you want shiftwidth to equal the number of tab characters times tabstop. This is also used by things like the =, > and < commands.

    将此设置为 tabstop 以外的非零值将使 Tab 键(在插入模式下)插入空格(可能还有制表符)组合以模拟制表位在此宽度处.

    Setting this to a non-zero value other than tabstop will make the tab key (in insert mode) insert a combination of spaces (and possibly tabs) to simulate tab stops at this width.

    启用此选项将使 Tab 键(在插入模式下)插入空格而不是制表符.这也会影响 retab 命令的行为.

    Enabling this will make the tab key (in insert mode) insert spaces instead of tab characters. This also affects the behavior of the retab command.

    启用此选项将使制表键(在插入模式下)插入空格或制表符转到下一个缩进当光标位于行首时(即只有前面的字符是空格).

    Enabling this will make the tab key (in insert mode) insert spaces or tabs to go to the next indent of the next tabstop when the cursor is at the beginning of a line (i.e. the only preceding characters are whitespace).

    有关其中任何一个的更多详细信息,请参阅 vim 中的 :help 'optionname'(例如 :help 'tabstop')

    For more details on any of these see :help 'optionname' in vim (e.g. :help 'tabstop')

    这篇关于将制表符重新定义为 4 个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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