Vim: Indent current (blank) line and insert

穿精又带淫゛_ 提交于 2019-12-23 06:58:19

问题


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.


回答1:


Try going back into normal mode and typing S




回答2:


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.



来源:https://stackoverflow.com/questions/3718026/vim-indent-current-blank-line-and-insert

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!