I have a function in my .vimrc file to remove any whitespace at the end of my lines:
" Remove trailing space on write
function! <SID>StripTrailingWhitespaces()
let _s=@/
let l = line(".")
let c = col(".")
%s/\s\+$//e
let @/=_s
call cursor(l, c)
endfu
With this function, the search pattern @/
is saved and restored, so I can continue to search (n
) my previous pattern. But if I was in the middle of a search and replace, using &
, it now search correctly but replace with an empty string.
I read that vim 8 has a :keeppatterns
option that might help me (I didn't check yet) but I'm stuck with vim 7.4 for the time being.
Is is possible to save and restore the 'replacement' part of a :s
command ?