Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Indent current (blank) line and insert

Say I have the current text in the buffer, where _ marks the cursor

int main(int argc, char **argv) {
    printf("Hello, world!\n");

_
}

I have indentexpr on (though a solution with cindent or autoindent will probably work, too).

How do I begin inserting so my cursor is placed at the appropriate column to follow the indention rules, i.e.:

int main(int argc, char **argv) {
    printf("Hello, world!\n");

    _
}

Currently I find myself using ddO often (or ddo at the end of the buffer), but it seems there should be a better way. Using == or even >> or v> do not seem to work because the line is blank.

like image 387
strager Avatar asked Sep 15 '10 13:09

strager


People also ask

How do I insert a blank line in Vim?

Press Enter to insert a blank line below current, Shift + Enter to insert it above.

How do I indent a whole block in Vim?

Put the cursor anywhere in the first line. Press V then jj to visually select the three lines. Press > to indent (shift text one ' shiftwidth ' to the right), or press < to shift left. Press . to repeat the indent, or u to undo if you have shifted too far.

What is smart indent in Vim?

autoindent essentially tells vim to apply the indentation of the current line to the next (created by pressing enter in insert mode or with O or o in normal mode. smartindent reacts to the syntax/style of the code you are editing (especially for C). When having it on you also should have autoindent on.


1 Answers

Try going back into normal mode and typing S

like image 143
Eugene M Avatar answered Oct 26 '22 03:10

Eugene M