我如何防止vim替换空间与标签时autoindent是吗?

一个例子:如果我有两个标签和7空间的开始线, tabstop=3, 和我的新闻输入,下一个线有四个标签和1空间的开始,但我不想这样...

有帮助吗?

解决方案

这也许是个好主意不要使用标签。

:set expandtab

如果你想要更换的所有标签在你的文件3格(它看起来非常相似 tabstop=3):

:%s/^I/   /

(在那里 ^I 是的 字)

从VIM在线帮助:

'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.

其他提示

所有我想要的是autoindented行为具有完全相同的压痕字作为前线。

:help copyindent

'copyindent' 'ci' 布尔 (默认关闭);本地的缓冲区;{不在六}

复制结构的现有行缩进当autoindenting一个 新的线路。通常的新缩进重建的一个系列的 标签后通过空间要求(除非 'expandtab' 启用, 在这种情况下,只有空间使用)。使这一选择使 新的线复制任何人物都用于在缩进 现有线。如果新缩大于对现有的 行,剩下的空间是充满了以正常方式。

注: 'copyindent' 重置的时候 "兼容" 被设定。
也见 'preserveindent'.

:help preserveindent

'preserveindent' 'pi' 布尔 (默认关闭);本地的缓冲区;{不在六}

当改变缩的前线,维护尽可能多的 缩进结构成为可能。通常的缩进替代 系列的标签,随后通过空间要求(除非 'expandtab' 是 启用,在这种情况下,只有空间使用)。使得这个选项 意味着缩进将保留作为许多现有的字作可能的 为缩进和只增加额外的标签或空间作为必需的。

注:当使用的">>"多次所得缩进是一个混合的 标签和空间。你可能不喜欢这一点。
注: 'preserveindent' 重置的时候 "兼容" 被设定。
也见 'copyindent'.
使用:retab清洁的空白。

你可以把所有 TABSPACE

:set et
:ret!

或者把所有 SPACETAB

:set et!
:ret!

这里部分的我 .vimrc:

set autoindent
set expandtab
set softtabstop=4
set shiftwidth=4

这工作很适合我因为我绝对不想要签在我的源码。它似乎从你的问题你想要保留两个标签和七个空间上的下一行,我不确定有一种方法教vim以容纳这种风格。

也许这可以帮助你?

标准vi解释表键字面上的,但也有很受欢迎六源的替代品,这是聪明的,就像vim。获得vim解释卡作为一种`缩"的命令,而不是插入一个选项命令,这样做:

set softtabstop=2

如果你想要更换所有弹片和空间基础设置的'ts',可以使用:retab.它也可以做相反。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top