On Thu, Feb 17, 2011 at 10:31 AM, Andrew Long <andrew.l...@mac.com> wrote:
> > On 17 Feb 2011, at 16:05, DK wrote: > > > This should be straight forward but I can't readily find an answer: > > > > If I have a search: > > > > :%s/search_text.*more_text/replace_text/gc > > > > How can I access the matched text (note above the regex in the > > middle). > > > > For example I would want to do something like (coming from TextMate I > > could use the $0 value to access the match and use it in the replace): > > > > :%s/search_text.*more_text/replace_text$0more_replace_text/gc > > > > Where $0 would be the match and I would be appending to it. > > Vim uses '&' as the $0 string in your question. So, > > :%s/search_text.*more_text/replace_text$0more_replace_text/gc > becomes > > :%s/search_text.*more_text/replace_text&more_replace_text/gc > > More generally, if you want to apture parts of a match, use \( & \) to > surround each part, then you can substitue '\1' (or some other number) to > insert the matched substring. Fpr example:- > > :s/\(abcd\)\(efgh\)/\2\1 > > reverses the order of the substrings 'abcd' and 'efgh' in the current line. > Thanks Andy and Israel.... this works great... and so much fun! > > Regards, Andy > > -- > Andrew Long > andrew dot long at mac dot com > > > > > > -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php