Saturday, September 20, 2014

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

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?

The goal is to have a search expression that would look something like

\<\%(quick\|fox\|lazy\|dog\)\>

The \< and \> enforce word start/end boundaries, 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.

-tim


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