I am working with python files with filetype indent on
. I like a lot of the default indenting features for python, but I would like vim to keep the tabs, even on empty lines.
For example, using set listchars=space:-,trail:.
and set list
to show whitespace, and using _
to show the cursor, if I begin a for-loop or function definition, and hit <CR>
once, I get this:
for-i-in-range(10):
...._
And if I start typing something, vim converts the whitespace into spaces and keeps them:
for-i-in-range(10):
----print(i)_
However, if I hit <CR>
again, that whitespace is deleted, although vim keeps indenting:
for-i-in-range(10):
...._
What I would like is for vim to keep the whitespace after I hit <CR>
, even if there is nothing written on that line. So typing for i in range(10):<CR><CR>print(i)
would yield:
for-i-in-range(10):
....
----print(i)_
vim leave indent on empty line
. It was the first result. Being more verbose and/or using something closer to a full sentence after the critical keyword (vim) works quite well these days.