I've written a function for removing the excess white space in a file:
let g:trim_whitespace = 1
function! TrimWhitespace()
if g:trim_whitespace
normal :%s/\s\+$//e
endif
endfunction
The issue is that the cursor position is set to [1, 1]
after the substitution command. I don't want the cursor to move at all, so I tried to save the cursor position and reset it after the substitute command:
let a:cursor_pos = getpos(".")
normal :%s/\s\+$//e
exec cursor(a:cursor_pos[1], a:cursor_pos[2])
But still the exact same thing happens, as if the call to cursor
had no effect. Any ideas?
Try placing a mark:
mark `
%s/\s\+$//e
normal ``
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With