代码之家  ›  专栏  ›  技术社区  ›  Don Reba

Vim中的悬挂操作器

vim
  •  3
  • Don Reba  · 技术社区  · 17 年前

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

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

    我希望它看起来像这样:

    class some_class
    {
            some_class();
           ~some_class();
    };
    

    4 回复  |  直到 17 年前
        1
  •  3
  •   sykora    17 年前

    ~ 如果vim能够检测到它是一名操作员,则将向后移动一个空间,从而将~“悬挂”到机器左侧 some_class() .

    编辑:

        2
  •  0
  •   pythonquick    17 年前

    您可以设置expandtab和tabstop选项:

    :set expandtab
    :set tabstop=8
    

    这将把您键入的所有新制表符扩展为8个空格。

    :retab
    
        3
  •  0
  •   heijp06    17 年前

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

        4
  •  0
  •   Brad Cox    17 年前

    我想你想要的是“自动缩进”。看:救命啊

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