How do I automatically indent lines?

Quick newbie question. Let's say I have the following code in Vim:

void main()

{

    int i = i + 1;

    return i;
}

      

I have a cursor on a blank line between two lines of code. When I press i (or a) to enter text, I want the cursor to be indented to the right (ie below i in "int i ..."). Any ideas how this can be done?

+2


source to share


4 answers


:set cindent

      



+2


source


As @chaos mentioned, cindent

this is probably what you are looking for.

There's also autoindent

, smartindent

and indentexpr

, which are fully customizable and documented in the Vim indentation documentation .



Here's a snippet of how they can be configured:

{N Place opening braces N characters from the prevailing indent.
              This applies only for opening braces that are inside other
              braces. (default 0).

                cino = cino = {. 5s cino = {1s
                  if (cond) if (cond) if (cond)
                  {{{
                      foo; foo; foo;

+6


source


just use cc on blank lines and o for new lines

+2


source


You can try entering 3 -> on the line int i...

. Not entirely automatic, but it saves time.

0


source







All Articles