Hanging statements in Vim

Is there a way to have dangling operators when tabbed indentation in Vim? For example, if I have a code:

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

I want it to look like this:

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

The question is about the appearance of the gap, and not about its composition. Thus, abbreviations and indentation rules will not be followed.

+3
source share
4 answers

I think he asks if he will ~move back one space if vim can detect that it is an operator, thereby β€œhanging” to the left of some_class().

The answer, as far as I know, is possible, but it will not be easy. Insert abbreviations are always heterogeneous, and more complex solutions ... are more complex.

, , .

EDIT:

, , . , , , . , vim , , . . Vim , , , .

+3

, " ", , , .

expandtab tabstop:

:set expandtab
:set tabstop=8

, , 8 .

- , retab:

:retab
0

It looks like you will have to write your own indentation file for this, examples of which are in $VIMRUNTIME/indent. But, as Sykora says, this is probably not worth the effort.

0
source

I think what you want is called "autoindent". See: help ai

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

Source: https://habr.com/ru/post/1708032/


All Articles