Whenever I open a line using o or O, the cursor starts at the correct indentation (I'm not sure if vim uses syntax hints for this or just mimics the position of first character of the neighboring lines). Same happens when opening a line in insert mode with Enter keypress.

Is there a quick way to similarly auto-indent an empty line? Currently I'm just getting into insert mode and pressing tab manually to manually indent.

I most likely want to map this functionality to when A (append to line) is pressed on an empty line.

EDIT: I've seen How do I prevent vim from unindenting empty lines. This question is however different since I don't want to prevent vim from unindenting empty lines. I just want to be able to "revive indentation of emptied lines" so not all answers to that question apply to this question.


The solution is to use S on the empty line in normal mode.

If you search for documentation on it via :help S, you'll find

["x]S Delete [count] lines [into register x] and start insert. Synonym for "cc" linewise.

So merely typing S deletes the present line and starts insert (at the correct indentation).

Thanks to StandardEyre's comment, which led me to this answer.

| improve this answer | |

As indicated on this related question, you cannot indent an empty line.

Your options are:

  1. to use S on the empty line in normal mode.
    • This deletes your empty line and starts a new line at the correct indentation
  2. to write something on the line then delete it
  3. to map CR to something that inserts white space and then deletes it right away
  4. to insert a line with white space characters (and redefine your idea of 'useless whitespace') ;-) instead of an empty line (no characters).
    • Note that this depends on (a) your use case and (b) your coding style.
    • When I use python I don't have a lot of constraints on coding style. Because I like to copy & paste python code I favor a line with white space, as supported by this answer

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.