How do I make vim's autoindent not drop trailing spaces?

Posted by Joey Adams on Super User See other posts from Super User or by Joey Adams
Published on 2010-03-16T20:45:40Z Indexed on 2010/03/16 20:51 UTC
Read the original article Hit count: 399

In some text editors (e.g. Kate, gedit), when auto indent is enabled, pressing return twice will leave a trailing whitespace (which I want):

if (code) {
....
....|
}

While others cater to the coding standard where trailing spaces (even in blank lines) aren't allowed:

if (code) {

....|
}

What annoys me about this is that if I arrow up after auto-indenting, the auto-indent is lost:

if (code) {
|
....
}

If I run vim and :set autoindent , I get the latter behavior.

My question is, how do I set vim to keep the trailing spaces rather than automatically removing them if they go unused?

© Super User or respective owner

Related posts about vim

Related posts about text-editors