Sunday, September 21, 2014

Re: Searching for any one of a set or words ?

Tim,


On 2014-09-21 06:24, Tim Chase wrote:
> On 2014-09-21 01:10, Philip Rhoades wrote:
>
>> > :new " create an empty buffer > :r words.txt " read your wordlist into it > :%s/\_s\+/\\|/g " convert all whitespace including newlines > " to "\|", the "or" conjunction in a regexp > :y a " yank that into the "a" register > :q > :let @/ = '\<\%(' . @a, '\.[*') . '\)\>' The simple version works fine but there is an error in the complex let statement somewhere - I can see the search register and the "a" register - can you explain how the stuff around the "a" register works or point me to somewhere?
> ... [show rest of quote]
>
> The goal is to have a search expression that would look something like
>
> \<\%(quick\|fox\|lazy\|dog\)\>
>
> The \< and \> enforce word start/end boundaries,


Right.


> and the \%(...\)
> should create a group around the various alternatives that are
> separated by "\|". If it helps, instead of joining them, you can type
> the "/" to search, type the "\<\%(" and then use control+R followed by
> "a" to paste in the contents you yanked into the "a" register, then do
> any cleanup, finally add on the "\)\>" at the end.


OK, I can get that manual method to work, but I still want to know what
was wrong with the original complex let statement:

:let @/ = '\<\%(' . @a, '\.[*') . '\)\>'

- this works:

:let @/ = '\<\%(' . @a . '\)\>'

- what was the extra:

", '\.[*')"

supposed to do?

Thanks,

Phil.

--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: phil@pricom.com.au

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment