Vim中的悬挂操作器

Vim中的悬挂操作器,vim,Vim,在Vim中使用卡舌缩进时,有没有办法让挂起的操作员?例如,如果我有代码: class some_class { <tab>some_class(); <tab>~some_class(); }; 问题在于空格的外观,而不是它的组成。因此,缩写和缩进规则不行。我不确定我是否理解“挂起运算符”的概念,但您似乎想用空格代替制表符 您可以设置expandtab和tabstop选项: :set expandtab :set tabstop=8 这将把您键入的所有新制表符扩展为8

在Vim中使用卡舌缩进时,有没有办法让挂起的操作员?例如,如果我有代码:

class some_class
{
<tab>some_class();
<tab>~some_class();
};

问题在于空格的外观,而不是它的组成。因此,缩写和缩进规则不行。

我不确定我是否理解“挂起运算符”的概念,但您似乎想用空格代替制表符

您可以设置expandtab和tabstop选项:

:set expandtab
:set tabstop=8
这将把您键入的所有新制表符扩展为8个空格

要将选项卡扩展应用于文件中的现有选项卡,请使用retab命令:

:retab

我想他是在问如果vim能够检测到它是一个操作符,那么
~
是否会向后移动一个空间,从而将~挂在
某个类()的左侧

据我所知,答案是可能的,但并不容易。插入模式的缩写总是零碎的,更复杂的解决方案……也更复杂

除非你真的需要这种行为,否则我认为这是不值得的

编辑:


我想我明白你的意思了。在这种情况下,我可以合理肯定地说,你所要求的是不可能的。您无法更改vim显示文本的方式,这些文本由制表符缩进,并且恰好以希望挂起左边距的运算符开头。这根本行不通。Vim被设置为按原样显示文本,在不更改源代码的情况下,您无法更改它以适应排版风格,我怀疑您是否愿意这样做。

似乎您必须为此编写自己的缩进文件,例如
$VIMRUNTIME/indent
中的缩进文件。但正如sykora所说,这可能不值得付出努力。

我认为您需要的是所谓的“自动缩进”。看:救命啊

'autoindent' 'ai'   boolean (default off)
            local to buffer
    Copy indent from current line when starting a new line (typing <CR>
    in Insert mode or when using the "o" or "O" command).  If you do not
    type anything on the new line except <BS> or CTRL-D and then type
    <Esc>, CTRL-O or <CR>, the indent is deleted again.  Moving the cursor
    to another line has the same effect, unless the 'I' flag is included
    in 'cpoptions'.
    When autoindent is on, formatting (with the "gq" command or when you
    reach 'textwidth' in Insert mode) uses the indentation of the first
    line.
    When 'smartindent' or 'cindent' is on the indent is changed in
    a different way.
    The 'autoindent' option is reset when the 'paste' option is set.
    {small difference from Vi: After the indent is deleted when typing
    <Esc> or <CR>, the cursor position when moving up or down is after the
    deleted indent; Vi puts the cursor somewhere in the deleted indent}.
“自动缩进”“ai”布尔值(默认关闭)
本地到缓冲区
开始新行时从当前行复制缩进(键入
在插入模式下或使用“o”或“o”命令时)。如果你不
在新行中键入除或CTRL-D之外的任何内容,然后键入
,CTRL-O或,再次删除缩进。移动光标
到另一行具有相同的效果,除非包含“I”标志
在“cpoptions”中。
启用“自动缩进”时,格式化(使用“gq”命令或
reach(插入模式下的“文本宽度”)使用第一个文本的缩进
线路。
当“智能缩进”或“cindent”出现在屏幕上时,缩进将在中更改
另一种方式。
设置“粘贴”选项后,将重置“自动缩进”选项。
{与Vi的微小差异:在键入时删除缩进之后
或者,上下移动时光标位置在
删除的缩进;Vi将光标放在删除的缩进}中的某个位置。

否,我不想用空格代替制表符。相反,我希望选项卡有更好的视觉表现。在许多情况下,这会使代码更具可读性。这个术语来自印刷术:如果我理解正确,缩进规则决定了缩进使用的字符,但与它们的外观无关。这是正确的。我没有听到你说的只是想让文本缩进,或者在我回答的时候文本没有缩进。我只是重申一下,问题是缩进的制表符,而不是空格。此外,缩写不能以空格为条件。这里有“tabstop”。但是,我强烈怀疑你是对的。我要问的更多的是像“tabstop”这样的东西,它会影响缩进的外观。
'autoindent' 'ai'   boolean (default off)
            local to buffer
    Copy indent from current line when starting a new line (typing <CR>
    in Insert mode or when using the "o" or "O" command).  If you do not
    type anything on the new line except <BS> or CTRL-D and then type
    <Esc>, CTRL-O or <CR>, the indent is deleted again.  Moving the cursor
    to another line has the same effect, unless the 'I' flag is included
    in 'cpoptions'.
    When autoindent is on, formatting (with the "gq" command or when you
    reach 'textwidth' in Insert mode) uses the indentation of the first
    line.
    When 'smartindent' or 'cindent' is on the indent is changed in
    a different way.
    The 'autoindent' option is reset when the 'paste' option is set.
    {small difference from Vi: After the indent is deleted when typing
    <Esc> or <CR>, the cursor position when moving up or down is after the
    deleted indent; Vi puts the cursor somewhere in the deleted indent}.