This expression, run interactively within Vim:
:%s/ \v(\w+('\w+)*)\_s\1/ \1/gi It removes needless repetition of words.
In this way it turns this:
the the it it them them it's it's then then and this too into this:
the it them it's then and this too as intended.
However the same expression used within vimscript, like this,
silent! exe ':%s/ \v(\w+('\w+)*)\_s\1/ \1/gi' fails to replace any repeated words.
I have tried:
- escaping the
'with a preceeding' - escaping the
'with a preceeding\ - enclosing the expression in double quotes
":%s .... "and not escaping the'
but none of these worked.
I also tried:
silent! exe ':%s/ \v(\w+('\''\w+)*)\_s\1/ \1/gi' This did not work either.
:help :executeto begin with?:help :sis perfectly valid in vimscript on its own.:exestring.