vim 7.4 saving substitution pattern and replacement -


i have function in .vimrc file remove whitespace @ end of 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 function, search pattern @/ saved , restored, can continue search (n) previous pattern. if in middle of search , replace, using &, search correctly replace empty string.

i read vim 8 has :keeppatterns option might me (i didn't check yet) i'm stuck vim 7.4 time being.

is possible save , restore 'replacement' part of :s command ?

as mentioned :s command not search, if want retrieve need access command history: : , up

( according vim help:keeppatterns {command} allows execute command without adding search pattern, don't believe useful if understand correctly use case)

if want still use "column command" :@: still work after function run.

when re-run & vim re-run last search last substitute. since search history has been restored in function use previous search still apply replace last replace (the 1 in function) resulting in replace empty string.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -