Re: Matching JUST the nth occurence of a text in a line
On Fri 1-Dec-06 7:19pm -0600, Yakov Lerner wrote: > On 12/1/06, Bill McCarthy <[EMAIL PROTECTED]> wrote: >> One might think so, but also note: >> >> :help non-greedy > I don't have tag 'non-greedy' in the help. I have vim 7.9.164 > from svn. Where do I get more updated helpfiles ? I see Tony already provided the an approach for unix. To update your directories on Windows (using 4nt): copy /[!*~]/u/s "ftp://ftp.vim.org/pub/vim/runtime/dos"; c:\vim\vim70 adjusting the target as appropriate. This copies only files that are newer or didn't exist on the target. It skips files ending with a tilde. And if any help files were updated: vim -nes "+helpt c:\vim\vim70\doc|q" -- Best regards, Bill
Re: Matching JUST the nth occurence of a text in a line
Yakov Lerner wrote: On 12/1/06, Bill McCarthy <[EMAIL PROTECTED]> wrote: One might think so, but also note: :help non-greedy I don't have tag 'non-greedy' in the help. I have vim 7.9.164 from svn. Where do I get more updated helpfiles ? Yakov By ftp: ftp://ftp.vim.org/pub/vim/runtime/ and all its contents except its dos/ subdirectory. By rsync: the following assumes that you compile vim yourself, and that the current directory is the top of your building tree: src/.. if you will. The two additional lines copy (on Unix) the updated files to where you'll be using them (such as /usr/local/share/vim/vim70/). rsync -avzcP --delete --exclude="/dos/" ftp.nluug.nl::Vim/runtime/ ./runtime/ cd src make installruntime Either method updates all your runtime files. In addition, rsync removes outdated files which don't exist anymore in the latest version of the files, and it doesn't touch the files which are already up-to-date. Best regards, Tony.
Re: Matching JUST the nth occurence of a text in a line
On 12/2/06, Yakov Lerner <[EMAIL PROTECTED]> wrote: On 12/1/06, Bill McCarthy <[EMAIL PROTECTED]> wrote: > One might think so, but also note: > > :help non-greedy I don't have tag 'non-greedy' in the help. I have vim 7.9.164 7.0.164, sorry, not 7.9.164. Still, where do I get more updated helpfiles like yours ? Yakov
Re: Matching JUST the nth occurence of a text in a line
On 12/1/06, Bill McCarthy <[EMAIL PROTECTED]> wrote: One might think so, but also note: :help non-greedy I don't have tag 'non-greedy' in the help. I have vim 7.9.164 from svn. Where do I get more updated helpfiles ? Yakov
Re: Matching JUST the nth occurence of a text in a line
On Fri, Dec 01, 2006 at 04:41:37PM -0500, Charles E Campbell Jr wrote: > >>>I am puzzled by a slightly more complicated version: > >>> how to match a '%' character following the 2nd occurrence of "home"? > >>/^.\{-}\%(home.\{-1,}\)\{N}home.\{-}\zs% > >This pattern doesn't work. Try it on this line: > >"home home home home home home% home" > But it *does* work! You didn't specify avoiding the % if matches to the > home pattern intervened. I can rephrase: "how to match a '%' character following the 2nd occurrence of "home"?" to "how to match a '%' character directly following the 2nd occurrence of "home"?" I am pretty sure everyone else knew what I meant. --Matt P.S. Does adding "directly" change the meaning for you? And if so, do you know the regular expression I want? > Try > :set hls > and the following two lines: > > home % home home home home home% home > home home %home home home% home > > and you'll only see %s match after the 2nd home, exactly as specified. > Now, if you change > the requirement, a different regex is needed. > > Regards, > Chip Campbell >
Re: Matching JUST the nth occurence of a text in a line
[EMAIL PROTECTED] wrote: On Fri, Dec 01, 2006 at 10:34:14AM -0500, Charles E Campbell Jr wrote: [EMAIL PROTECTED] wrote: I am puzzled by a slightly more complicated version: how to match a '%' character following the 2nd occurrence of "home"? /^.\{-}\%(home.\{-1,}\)\{N}home.\{-}\zs% This pattern doesn't work. Try it on this line: "home home home home home home% home" It should match nothing on that line, because the '%' doesn't follow the 2nd occurrence as desired. But it *does* work! You didn't specify avoiding the % if matches to the home pattern intervened. Try :set hls and the following two lines: home % home home home home home% home home home %home home home% home and you'll only see %s match after the 2nd home, exactly as specified. Now, if you change the requirement, a different regex is needed. Regards, Chip Campbell
Re: Matching JUST the nth occurence of a text in a line
On Fri, Dec 01, 2006 at 10:34:14AM -0500, Charles E Campbell Jr wrote: > [EMAIL PROTECTED] wrote: > > >I am puzzled by a slightly more complicated version: > > how to match a '%' character following the 2nd occurrence of "home"? > > > > > /^.\{-}\%(home.\{-1,}\)\{N}home.\{-}\zs% This pattern doesn't work. Try it on this line: "home home home home home home% home" It should match nothing on that line, because the '%' doesn't follow the 2nd occurrence as desired. --Matt > > where N is 1 for the "2nd occurrence" (N is 2 for the third occurrence, > etc). > > This pattern matches up to and including the 2nd home, extends past a > minimal amount of anything up to but not including a %, whereupon the > pattern matching starts. > > Regards, > Chip Campbell >
Re: Matching JUST the nth occurence of a text in a line
On Fri 1-Dec-06 1:59am -0600, A.J.Mechelynck wrote: > He gave it. In the above case, you highlight not only the 2nd occurrence but > also the 4th, 6th, etc. Of course. I was so focused on (1) the "second on the line" and (2) the "shortest match first algorithm" of non-greedy constructs (which surprises many users) that I completely ignored matches starting elsewhere :-( That is: :%s/home.\{-}\zshome/alone only changes the second home - no matter how many are on a line.. Peter's solution to find only the second works everywhere. To the person who didn't like the \{-} form, use \v: /\v^.{-}home.{-}\zshome Sorry Peter and zzapper for the confusion. -- Best regards, Bill
Re: Matching JUST the nth occurence of a text in a line
[EMAIL PROTECTED] wrote: I am puzzled by a slightly more complicated version: how to match a '%' character following the 2nd occurrence of "home"? /^.\{-}\%(home.\{-1,}\)\{N}home.\{-}\zs% where N is 1 for the "2nd occurrence" (N is 2 for the third occurrence, etc). This pattern matches up to and including the 2nd home, extends past a minimal amount of anything up to but not including a %, whereupon the pattern matching starts. Regards, Chip Campbell
Re: Matching JUST the nth occurence of a text in a line
All, I am puzzled by a slightly more complicated version: how to match a '%' character following the 2nd occurrence of "home"? --Matt On Fri, Dec 01, 2006 at 09:09:17AM -0500, Charles E Campbell Jr wrote: > Peter Hodge wrote: > > >Try: > > > > /^.\{-}home.\{-}\zshome > > > > > >for your reference: > > > > \{-} makes the '.' match as little as possible > > \zs makes the search match begin at this point in the pattern > > > > > > > To generalize to the n-th occurrence: (put the qty of skipped matches in N) > > /^.\{-}\%(home.\{-1,}\)\{N}\zshome > > So, for the 2nd home: let N=1. > > Regards, > Chip Campbell >
Re: Matching JUST the nth occurence of a text in a line
Peter Hodge wrote: Try: /^.\{-}home.\{-}\zshome for your reference: \{-} makes the '.' match as little as possible \zs makes the search match begin at this point in the pattern To generalize to the n-th occurrence: (put the qty of skipped matches in N) /^.\{-}\%(home.\{-1,}\)\{N}\zshome So, for the 2nd home: let N=1. Regards, Chip Campbell
Re: Matching JUST the nth occurence of a text in a line
"A.J.Mechelynck" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Bill McCarthy wrote: >> On Thu 30-Nov-06 11:49pm -0600, Peter Hodge wrote: >>> --- Bill McCarthy wrote: On Thu 30-Nov-06 10:24pm -0600, Peter Hodge wrote: > --- Bill McCarthy wrote: >> On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: >> >>> Try: >>> >>> /^.\{-}home.\{-}\zshome >>> /^.\{-}home.\{-}\zshome/e Was the solution I was looking for (BTW the /e indicates where the match ends) Thanks -- http://successtheory.com/tips/ Vim, Zsh, MySQL Tips
Re: Matching JUST the nth occurence of a text in a line
Chuck Mason wrote: Am I the only one amused that /homen does nearly the same thing? I mean, I suppose you could be doing operations on your search but couldn't you equally just "ayw and do stuff there? Besides \{-}\zs takes too long to type :) To go to the 2nd occurrence from the cursor, you can use 2/home (or 2/\ if you want to exclude "homeless" etc.) but all occurrences will be highlighted. Best regards, Tony.
Re: Matching JUST the nth occurence of a text in a line
Bill McCarthy wrote: On Thu 30-Nov-06 11:49pm -0600, Peter Hodge wrote: --- Bill McCarthy wrote: On Thu 30-Nov-06 10:24pm -0600, Peter Hodge wrote: --- Bill McCarthy wrote: On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: Try: /^.\{-}home.\{-}\zshome for your reference: \{-} makes the '.' match as little as possible \zs makes the search match begin at this point in the pattern One might think so, but also note: :help non-greedy In particular, ready the sentence starting with "BUT". All that is needed is: /home.\{-}\zshome Earliest is preferred to shortest. Yes, but that could also match a 3rd or 4th or 5th occurance of 'home' in one line, so it's slightly safer to anchor the pattern to the start of the line. Given the use of the "shortest match first algorithm" I don't see how that's possible. Please give an example. '/home.\{-}\zshome' will match every 2nd home in the following text: home home home home home home home home home home home home home home home home home Yes, I know it works. You stated that it was "safer to anchor the pattern to the start of the line." I was asking for a example of a failure of '/home.\{-}\zshome' that would require such an anchor. He gave it. In the above case, you highlight not only the 2nd occurrence but also the 4th, 6th, etc. Best regards, Tony.
RE: Matching JUST the nth occurence of a text in a line
Am I the only one amused that /homen does nearly the same thing? I mean, I suppose you could be doing operations on your search but couldn't you equally just "ayw and do stuff there? Besides \{-}\zs takes too long to type :) -Original Message- From: Bill McCarthy [mailto:[EMAIL PROTECTED] Sent: Thursday, November 30, 2006 4:56 PM To: zzapper Cc: vim@vim.org Subject: Re: Matching JUST the nth occurence of a text in a line On Thu 30-Nov-06 6:31pm -0600, zzapper wrote: > Hi given a sample text below > > home > > home gg home xxx > > home ggg ggg home home > > home home > > How do you match JUST the second "home" in any of the above lines (ie avoid > greediness) /home.\{-}\zshome -- Best regards, Bill
Re: Matching JUST the nth occurence of a text in a line
On Thu 30-Nov-06 11:49pm -0600, Peter Hodge wrote: > --- Bill McCarthy wrote: >> On Thu 30-Nov-06 10:24pm -0600, Peter Hodge wrote: >>> --- Bill McCarthy wrote: On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: > Try: > > /^.\{-}home.\{-}\zshome > > for your reference: > > \{-} makes the '.' match as little as possible > \zs makes the search match begin at this point in the pattern One might think so, but also note: :help non-greedy In particular, ready the sentence starting with "BUT". All that is needed is: /home.\{-}\zshome Earliest is preferred to shortest. >>> Yes, but that could also match a 3rd or 4th or 5th >>> occurance of 'home' in one line, so it's slightly safer >>> to anchor the pattern to the start of the line. >> Given the use of the "shortest match first algorithm" I >> don't see how that's possible. Please give an example. > '/home.\{-}\zshome' will match every 2nd home in the > following text: > > home home home home > home home home home home home home home > home home home home home Yes, I know it works. You stated that it was "safer to anchor the pattern to the start of the line." I was asking for a example of a failure of '/home.\{-}\zshome' that would require such an anchor. -- Best regards, Bill
Re: Matching JUST the nth occurence of a text in a line
--- Bill McCarthy <[EMAIL PROTECTED]> wrote: > On Thu 30-Nov-06 10:24pm -0600, you wrote: > > > --- Bill McCarthy <[EMAIL PROTECTED]> wrote: > > >> On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: > >> > >> > Try: > >> > > >> > /^.\{-}home.\{-}\zshome > >> > > >> > > >> > for your reference: > >> > > >> > \{-} makes the '.' match as little as possible > >> > \zs makes the search match begin at this point in the pattern > >> > >> One might think so, but also note: > >> > >> :help non-greedy > >> > >> In particular, ready the sentence starting with "BUT". All > >> that is needed is: > >> > >> /home.\{-}\zshome > >> > >> Earliest is preferred to shortest. > > > Yes, but that could also match a 3rd or 4th or 5th occurance of 'home' in > one > > line, so it's slightly safer to anchor the pattern to the start of the > line. > > Given the use of the "shortest match first algorithm" I > don't see how that's possible. Please give an example. '/home.\{-}\zshome' will match every 2nd home in the following text: home home home home home home home home home home home home home home home home home This is assuming you are doing a normal search using '/', not using a command like ':g' or ':s' with the 'g' flag. regards, Peter Send instant messages to your online friends http://au.messenger.yahoo.com
Re: Matching JUST the nth occurence of a text in a line
On Thu 30-Nov-06 10:24pm -0600, you wrote: > --- Bill McCarthy <[EMAIL PROTECTED]> wrote: >> On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: >> >> > Try: >> > >> > /^.\{-}home.\{-}\zshome >> > >> > >> > for your reference: >> > >> > \{-} makes the '.' match as little as possible >> > \zs makes the search match begin at this point in the pattern >> >> One might think so, but also note: >> >> :help non-greedy >> >> In particular, ready the sentence starting with "BUT". All >> that is needed is: >> >> /home.\{-}\zshome >> >> Earliest is preferred to shortest. > Yes, but that could also match a 3rd or 4th or 5th occurance of 'home' in one > line, so it's slightly safer to anchor the pattern to the start of the line. Given the use of the "shortest match first algorithm" I don't see how that's possible. Please give an example. -- Best regards, Bill
Re: Matching JUST the nth occurence of a text in a line
--- Bill McCarthy <[EMAIL PROTECTED]> wrote: > On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: > > > Try: > > > > /^.\{-}home.\{-}\zshome > > > > > > for your reference: > > > > \{-} makes the '.' match as little as possible > > \zs makes the search match begin at this point in the pattern > > One might think so, but also note: > > :help non-greedy > > In particular, ready the sentence starting with "BUT". All > that is needed is: > > /home.\{-}\zshome > > Earliest is preferred to shortest. Yes, but that could also match a 3rd or 4th or 5th occurance of 'home' in one line, so it's slightly safer to anchor the pattern to the start of the line. regards, Peter Send instant messages to your online friends http://au.messenger.yahoo.com
Re: Matching JUST the nth occurence of a text in a line
On Thu 30-Nov-06 9:20pm -0600, Peter Hodge wrote: > Try: > > /^.\{-}home.\{-}\zshome > > > for your reference: > > \{-} makes the '.' match as little as possible > \zs makes the search match begin at this point in the pattern One might think so, but also note: :help non-greedy In particular, ready the sentence starting with "BUT". All that is needed is: /home.\{-}\zshome Earliest is preferred to shortest. -- Best regards, Bill
Re: Matching JUST the nth occurence of a text in a line
Hello, Try: /^.\{-}home.\{-}\zshome for your reference: \{-} makes the '.' match as little as possible \zs makes the search match begin at this point in the pattern regards, Peter --- zzapper <[EMAIL PROTECTED]> wrote: > Hi given a sample text below > > home > > home gg home xxx > > home ggg ggg home home > > home home > > How do you match JUST the second "home" in any of the above lines (ie avoid > greediness) > > > -- > zzapper > http://successtheory.com/tips/ Vim, Zsh, MySQL Tips > > Send instant messages to your online friends http://au.messenger.yahoo.com
Re: Matching JUST the nth occurence of a text in a line
On Thu 30-Nov-06 6:31pm -0600, zzapper wrote: > Hi given a sample text below > > home > > home gg home xxx > > home ggg ggg home home > > home home > > How do you match JUST the second "home" in any of the above lines (ie avoid > greediness) /home.\{-}\zshome -- Best regards, Bill
Matching JUST the nth occurence of a text in a line
Hi given a sample text below home home gg home xxx home ggg ggg home home home home How do you match JUST the second "home" in any of the above lines (ie avoid greediness) -- zzapper http://successtheory.com/tips/ Vim, Zsh, MySQL Tips