vim tip: How to configure vim autoindent

vim autoindent FAQ: How do I configure the vim editor to automatically indent newlines? That is, if my current line is indented three spaces, and I hit [Enter], I want the next line to automatically be indented three spaces as well.

To configure vim autoindent, just use this command in vim’s last-line mode:

:set autoindent

This tells vim to automatically indent the next line. You can either type this vim autoindent command while you’re in vim, or if you want this to be the default behavior, you can add this line to your .vimrc configuration file:

set autoindent

(For more information on vimrc configuration files, see my example vim vimrc configuration file tutorial.)

vim autoindent: How to un-indent a line in vim

On a related note, if the vim autoindent feature has indented a line, but you really want to move the cursor back to the first column, you don’t have to press the backspace key several times to move back. Just use this keystroke to move back to the first column:

^d

This [control][d] keystroke moves the vim cursor back to the first column, and then you can keep typing from there.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.