1

I've the following autocmd for stripping trailing whitespace in a buffer, every time the buffer is written to a file:

" trim whitespace
autocmd BufWritePre * %s/\s\+$//e

However, the autocmd has the annoying side effect of moving the cursor, when there are lines that match the substitution: %s/\s\+$//e

How can I prevent the autocmd from moving the cursor?

  • 1
    Shuzeng, I think you’ve already asked this question and had it closed. Please refrain from repeatedly asking the same question. If you can clarify what in the multitude of linked questions doesn’t help you, please edit and we can reopen. – D. Ben Knoble Aug 21 at 13:37