Dudley Fox wrote:
Hello Vim List,
I have used vim for a while, and though no expert I am fairly
comfortable with the common commands. Recently I ran into a situation
where I just couldn't find a way to do a search and replace. I was
hoping some of you experts could help me out.
Starting text:
nameTable[pattern with spaces0] = ("pattern with spaces0", 12345)
nameTable[pattern with spaces1] = ("pattern with spaces1", 67890)
nameTable[pattern with spaces2] = ("pattern with spaces2", 243)
nameTable[pattern with spaces3] = ("pattern with spaces3", 421)
nameTable[pattern with spaces4] = ("pattern with spaces4", 3455)
nameTable[pattern with spaces5] = ("pattern with spaces5", 2222)
Desired Text:
nameTable[patternwithspaces0] = ("pattern with spaces0", 12345)
nameTable[patternwithspaces1] = ("pattern with spaces1", 67890)
nameTable[patternwithspaces2] = ("pattern with spaces2", 243)
nameTable[patternwithspaces3] = ("pattern with spaces3", 421)
nameTable[patternwithspaces4] = ("pattern with spaces4", 3455)
nameTable[patternwithspaces5] = ("pattern with spaces5", 2222)
Notice that the only difference is that the spaces are removed from
the pattern in between the square brackets. I think I want to use \zs
and \ze, but I couldn't wrap my head around the syntax. Any help would
be appreciated.
Sincerely,
Dudley
(untested)
:%s/\[.{-}\]/\=substitute('\0','\s','','g')
see
:help sub-replace-expression
:help substitute()
Best regards,
Tony.
--
Infancy, n.:
The period of our lives when, according to Wordsworth, "Heaven
lies about us." The world begins lying about us pretty soon
afterward.
-- Ambrose Bierce