Wikia

Vim Tips Wiki

Restoring indent after typing hash

Talk0
1,610pages on
this wiki
Revision as of 02:54, July 20, 2009 by JohnBot (Talk | contribs)

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1327 Printable Monobook Previous Next

created September 10, 2006 · complexity basic · author Decker · version 5.7


The default behavior of the 'autoindent' option is as follow:

Copy indent from current line when starting a new line (typing <CR> in Insert mode or when using the "o" or "O" command). If you do not type anything on the new line except <BS> or CTRL-D and then type <Esc> or <CR>, the indent is deleted again.

I find that behavior quite annoying since the cursor jumps to the left when empty lines are inserted and 'escape' is pressed. Fortunately, it is possible to force Vim to keep the indentation with the following lines in your vimrc:

inoremap <CR> <CR><Space><BS>
nnoremap o o<Space><BS>
nnoremap O O<Space><BS>

Comments

Around Wikia's network

Random Wiki