14

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.

strager
  • 88,763
  • 26
  • 134
  • 176

2 Answers2

30

Try going back into normal mode and typing S

Eugene M
  • 1,307
  • 2
  • 15
  • 22
  • Yes! That was it! Thanks a lot. (I was already in normal mode; in insert mode I sometimes spam .) – strager Sep 15 '10 at 13:47
  • 4
    Looking at `:help S`, `cc` does the same thing. (I never use `cc`, so that's probably why I didn't even consider using that (nor `S`, which I never even knew about).) – strager Sep 15 '10 at 13:50
8

If I'm on a blank line, but at the wrong insertion point, I tend to use CTRL-f (while in insert mode) to indent to the correct place.

This is useful when I've hit ESC to get out of insert mode, and I've then lost the proper indentation. Hitting i followed by CTRL-f does the trick.

Mike Seplowitz
  • 9,785
  • 1
  • 24
  • 23