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.
Press Enter to insert a blank line below current, Shift + Enter to insert it above.
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.
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.
Try going back into normal mode and typing S
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With