Search code examples
vimindentationauto-indent

Is there a way to tell Vim not to remove indent that was automatically added when I moving the cursor?


For example: I write a line and press ENTER. Then if auto indent turn on cursor moves to the next line with the same indent like current line. If then I move the cursor sonewhere else and then return to this place there will be no indent. But I want to save indent that was added automatically.


Solution

  • If you insert any text on the line, even if you delete it, Vim will keep the indent. So just type xBackspace on the new line to keep the indent after leaving it. Or do it automatically with a mapping:

    inoremap <Enter> <Enter>x<BS>