Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Smart indent when entering insert mode on blank line?

When I open a new line (via 'o') my cursor jumps to a correctly indented position on the next line. On the other hand, entering insert mode while my cursor is on a blank line doesn't move my cursor to the correctly indented location.

How do I make vim correctly indent my cursor when entering insert mode (via i) on a blank line?

like image 891
Dane O'Connor Avatar asked Jun 09 '10 05:06

Dane O'Connor


People also ask

How do I indent in vim normal mode?

In normal mode, press Tab or Shift-Tab to adjust the indent on the current line and position the cursor on the first nonblank character; in insert mode, press Shift-Tab to unindent; in visual mode, press Tab or Shift-Tab to adjust the indent on selected lines.

What is auto indent Vim?

Vim has four methods of indentation, namely: Autoindent – this method uses indent from the previous line for the file type you are editing. smartindent – smartindent works similarly to autoindent but recognizes the syntax for some languages such as C language.


1 Answers

cc will replace the contents of the current line and enter insert mode at the correct indentation - so on a blank line will do exactly what you're after.

I believe that the behaviour of i you describe is correct because there are many use cases where you want to insert at that specific location on a blank line, rather than jumping to wherever vim guesses you want to insert.

like image 53
sml Avatar answered Oct 12 '22 10:10

sml