I have the following function to remove every trailing white space from the document, without changing my cursor position
function! StripTrailingWhitespaces()
let l = line('.')
let c = col('.')
%s/\s\+$//e
call cursor(l, c)
endfunction
I'd like to change it so that it doesn't remove any whitespace to the left of my current cursor position. For example consider this situation, (a _
stands for a space and |
is the cursor position)
test__|_
there's the string test
followed by three spaces, and the cursor is between the second and the third space. If I execute that function, I end up with
test|
and all the spaces have been removed, instead I'd like to end up with
test__|
where only the space to the right of the current cursor position has been removed (all the other trailing whitespaces throughout the document should be removed in both cases, I only want to change the behaviour on the current line).
How can this be done?