0

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)_
3
  • 1
    Yeah that helps. I did a lot of searching, I didnt realize the keyword I should have used was "unindent". Thanks Apr 21, 2021 at 1:33
  • Well, even if you didn't think of "unindent", kudos for trying to find it yourself first. :) If only more people did that.
    – B Layer
    Apr 21, 2021 at 2:04
  • 1
    BTW, and just FYI, the way I found the linked answer was with google search term 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.
    – B Layer
    Apr 21, 2021 at 3:07

0

Browse other questions tagged or ask your own question.