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.

In addition to the various regexp solutions you've been given:

if what you want done is actually contiguous linewise as shown, then vis.vim
makes it fairly straightforward (http://mysite.verizon.net/astronaut/vim/index.html#VIS
or http://vim.sourceforge.net/scripts/script.php?script_id=1195):

select pattern with spaces0 ... pattern with spaces5 using ctrl-v and motion.
  :B s/ //g

Regards,
Chip Campbell

Reply via email to