I wrote a function to remove extra space in a file:
let g:trim_whitespace = 1 function! TrimWhitespace() if g:trim_whitespace normal :%s/\s\+$//e endif endfunction
The problem is that the cursor position is set to [1, 1] after the substitution command. I do not want the cursor to move at all, so I tried to keep the cursor position and reset after the substitute command:
let a:cursor_pos = getpos(".") normal :%s/\s\+$
But still the same thing happens, as if the cursor call had no effect. Any ideas?
source share