epanda wrote:
>>      My first thought would be to do fewer substitutes, which could be done
>>      if your hashes are nested, so you have a double-dereferencing.
>>      Something like
>>
>>
>>              :%s/TSWK1\|TSWK2\|TSWK3/\=s:hash[submatch(0)]/g
>>
>>
>>      or, if you have a bunch of keys, you might be able to do something like
>>
>>
>>              :let @/=join(keys(s:hash), '\|')
>>              :%s//\=s:hash[submatch[0]]/g
>>
>>
>>      (you might have to escape the keys if there are funky regexp
>>      metacharacter values in the hash keys)
> 
> I think your first idea was the best even if I don't understand how it
> works and so can help to my pb.

The two are similar, as they create a chained list of possible matches 
all separated by "\|", and then the replacement uses submatch(0) (the 
text that was found) to index into the hash/map.  You could also do 
something like

   %s/\w\+/\=get(s:hash, submatch(0), submatch(0))/g

which is a sneaky way of replacing every "word" (\w\+) with either its 
match in your hash, or, if it's not in the hash, just use the original 
as the replacement (thus making "no" change).

If you can tighten up your search for only "things that look like your 
magic replacement constants", it may be faster, something like

   %s/\<\w\{-1,}_\w\+/\=get(s:hash, submatch(0), submatch(0))/g

(which would match things with at least one underscore in it, if you 
knew all your map-keys contained underscores).

-tim



-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to