Skip to main content
1 of 5
Luc Hermitte
  • 17.8k
  • 1
  • 33
  • 50

I'd count the number of space characters before the cursor at the moment <cr> is hit and produce as many <BS>. It can be done with substitute also:

:inoremap <expr> <cr> substitute(matchstr(getline('.')[: col('.')-2], '\s*$'), '.', "<bs>", 'g')."<cr>"

or

:inoremap <expr> <cr> repeat("<bs>", len(matchstr(getline('.')[: col('.')-2], '\s*$')))."<cr>"
Luc Hermitte
  • 17.8k
  • 1
  • 33
  • 50