Vim keeps unindenting the lines I want to keep indented if I don't write anything on them... I'll give an example, where the | is the caret.
Caret is indented and I press enter
if expression: print("hello world") |
Caret is indented on the next line, and now I press the up arrow
if expression: print("hello world") |
Now the caret isn't indented anymore, what happened?
if expression: print("hello world") |
So how do I keep the indent?
As others have pointed out, Vim intentionally removes indent of empty lines if the indent was added automatically. But, this does not happen if you have inserted any text on the line, even if you delete it. So on a case-by-case basis, just insert some text and delete it with backspace if you want to keep the indent of an empty line. A mapping also works, if you always want to keep it: