stopping vim from removing indentation on empty lines

前端 未结 2 1330
日久生厌
日久生厌 2020-12-06 01:01

When the cursor is placed at the end of a line containing nothing but withspace characters, vim will, when i press enter, remove that whitespace. I find this irritating, as

相关标签:
2条回答
  • 2020-12-06 01:22

    The Vim wiki suggests this:

    inoremap <CR> <CR>x<BS>
    

    because the indenting is not removed if some text has been entered on the line, even if it has been deleted.

    [EDIT - milimetric]

    Just a couple of pieces missing from a full solution. You also need remaps for o and O and whatever else you use to add lines:

    inoremap <CR> <CR>x<BS>
    nnoremap o ox<BS>
    nnoremap O Ox<BS>
    

    Same idea but people newer to vim might not figure it out quickly.

    0 讨论(0)
  • 2020-12-06 01:35

    For me this code works:

    inoremap <silent> <Esc> <C-O>:stopinsert<CR>
    
    0 讨论(0)
提交回复
热议问题