Loading ...
Sorry, an error occurred while loading the content.
 

RE: Searching for words that are repeated more than once consecutively

Expand Messages
  • Yegappan Lakshmanan
    ... Yes. This works. I didn t try using 1 in the search pattern. I didn t realize that the sub-expression 1, 2, etc can be used in the same search pattern.
    Message 1 of 10 , Jul 2, 2002
      --- Scott LaBounty <slabounty@...> wrote:
      > Yegappan,
      >
      > How about:
      >
      > /\(\<.*\>\) \1
      >
      > It worked on my 1 example case ;-).

      Yes. This works. I didn't try using \1 in the search pattern.
      I didn't realize that the sub-expression \1, \2, etc can
      be used in the same search pattern. I thought they can be
      used only in replacement strings. Now I see that there is
      an example for using \1 in a search pattern under ":help /\1"

      Thanks,
      Yegappan

      >
      > Scott LaBounty
      > Nexa Technologies
      >
      > -----Original Message-----
      > From: Yegappan Lakshmanan [mailto:yegappan@...]
      > Sent: Tuesday, July 02, 2002 10:20 AM
      > To: vim@...
      > Subject: Searching for words that are repeated more than once
      > consecutively
      >
      >
      > Hi all,
      >
      > How do I search for words that are repeated consecutively more than
      > once? For example, search for "the the" or "a a", etc. Note that the
      > word is an arbitrary word (i.e. I cannot just search for /the the or /a
      > a).
      >
      > - Yegappan
      >
      >
      > __________________________________________________
      > Do You Yahoo!?
      > Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com
      >


      __________________________________________________
      Do You Yahoo!?
      Sign up for SBC Yahoo! Dial - First Month Free
      http://sbc.yahoo.com
    • tmusall@attbi.com
      Yegappan, I m pretty new to vim script, but I think this one does what you need. -Todd function! DubWordSearch() while 1 normal ye let x = @ normal wye if x
      Message 2 of 10 , Jul 2, 2002
        Yegappan,

        I'm pretty new to vim script, but I think this one does
        what you need.

        -Todd

        function! DubWordSearch()
        while 1
        normal ye
        let x = @"
        normal wye
        if x == @"
        normal b
        break
        endif
        endwhile
        endfunction
        > Hi all,
        >
        > How do I search for words that are repeated consecutively more
        > than once? For example, search for "the the" or "a a", etc.
        > Note that the word is an arbitrary word (i.e. I cannot just
        > search for /the the or /a a).
        >
        > - Yegappan
        >
        >
        > __________________________________________________
        > Do You Yahoo!?
        > Sign up for SBC Yahoo! Dial - First Month Free
        > http://sbc.yahoo.com
      • Bram Moolenaar
        ... / ( ) s + 1 -- Q: What do you call a fish without an eye? A: fsh! /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net ///
        Message 3 of 10 , Jul 2, 2002
          Yegappan Lakshmanan wrote:

          > How do I search for words that are repeated consecutively more
          > than once? For example, search for "the the" or "a a", etc.
          > Note that the word is an arbitrary word (i.e. I cannot just
          > search for /the the or /a a).

          /\(\<\k\+\>\)\s\+\1

          --
          Q: What do you call a fish without an eye?
          A: fsh!

          /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
          /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
          \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
          \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
        • Preben Peppe Guldberg
          ... I d say that should be / ( ) s + 1 or an anchor will be matched, too. Peppe -- Before you criticize someone, walk Preben Peppe Guldberg
          Message 4 of 10 , Jul 2, 2002
            Thus wrote Bram Moolenaar (Bram@...) on [020702]:

            > Yegappan Lakshmanan wrote:

            > > How do I search for words that are repeated consecutively more
            > > than once? For example, search for "the the" or "a a", etc.
            > > Note that the word is an arbitrary word (i.e. I cannot just
            > > search for /the the or /a a).

            > /\(\<\k\+\>\)\s\+\1

            I'd say that should be

            /\(\<\k\+\>\)\s\+\1\>

            or "an anchor" will be matched, too.

            Peppe
            --
            "Before you criticize someone, walk
            Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
            c928400@... (o o) he gets angry, he'll be a mile away
            ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
          • Gary Holloway
            / FROM: Preben Peppe Guldberg , Jul 2 20:51 2002 ... Actually, I d use: / ( ) ( _s + ) + After all, you wanna find the
            Message 5 of 10 , Jul 2, 2002
              / FROM: Preben Peppe Guldberg <c928400@...>, Jul 2 20:51 2002
              | ABOUT: Re: Searching for words that are repeated more than once consecutively
              |
              | Thus wrote Bram Moolenaar (Bram@...) on [020702]:
              |
              | > Yegappan Lakshmanan wrote:
              |
              | > > How do I search for words that are repeated consecutively more
              | > > than once? For example, search for "the the" or "a a", etc.
              | > > Note that the word is an arbitrary word (i.e. I cannot just
              | > > search for /the the or /a a).
              |
              | > /\(\<\k\+\>\)\s\+\1
              |
              | I'd say that should be
              |
              | /\(\<\k\+\>\)\s\+\1\>

              Actually, I'd use:

              /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+

              After all, you wanna find "the the the", right? :)
              (and of course,
              the
              the
              the
              )

              Now, is there a way to skip a comment leader?
              To find something like:

              /* This comment repeats the
              * the word, "the" consecutively.
              */

              Which would be one of the more common cases of a repeated word you'd miss. :)

              -gary

              |
              | or "an anchor" will be matched, too.
              |
              | Peppe
              | --
              | "Before you criticize someone, walk
              | Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
              | c928400@... (o o) he gets angry, he'll be a mile away
              | ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
              |
              \ END: Preben Peppe Guldberg
            • Gary Holloway
              / FROM: Gary Holloway , Jul 2 17:29 2002 ... Well, ok, I guess this d work: / ( ) ( ( _s + | s* n s* * s* ) ) + ... [snip]
              Message 6 of 10 , Jul 2, 2002
                / FROM: Gary Holloway <gary@...>, Jul 2 17:29 2002
                | ABOUT: Re: Searching for words that are repeated more than once consecutively
                |
                | / FROM: Preben Peppe Guldberg <c928400@...>, Jul 2 20:51 2002
                | | ABOUT: Re: Searching for words that are repeated more than once consecutively
                | |
                | | Thus wrote Bram Moolenaar (Bram@...) on [020702]:
                | |
                | | > Yegappan Lakshmanan wrote:
                | |
                | | > > How do I search for words that are repeated consecutively more
                | | > > than once? For example, search for "the the" or "a a", etc.
                | | > > Note that the word is an arbitrary word (i.e. I cannot just
                | | > > search for /the the or /a a).
                | |
                | | > /\(\<\k\+\>\)\s\+\1
                | |
                | | I'd say that should be
                | |
                | | /\(\<\k\+\>\)\s\+\1\>
                |
                | Actually, I'd use:
                |
                | /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+
                |
                | After all, you wanna find "the the the", right? :)
                | (and of course,
                | the
                | the
                | the
                | )
                |
                | Now, is there a way to skip a comment leader?
                | To find something like:
                |
                | /* This comment repeats the
                | * the word, "the" consecutively.
                | */
                |
                | Which would be one of the more common cases of a repeated word you'd miss. :)

                Well, ok, I guess this'd work:

                /\(\<\k\+\>\)\(\(\_s\+\|\s*\n\s*\*\s*\)\<\1\>\)\+

                |
                | -gary
                |
                | |
                [snip]
                | |
                | \ END: Preben Peppe Guldberg
                |
                |
                \ END: Gary Holloway
              • Robert Montante
                ... Ummm... why are you guys all using the k atom? Wouldn t w make more sense? So here s my entry: / ( ) _s* 1 (This should match the first
                Message 7 of 10 , Jul 3, 2002
                  >Bram Moolenaar:
                  > /\(\<\k\+\>\)\s\+\1
                  >
                  >Preben Peppe Guldberg:
                  > /\(\<\k\+\>\)\s\+\1\>
                  >
                  >Gary Holloway:
                  > /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+

                  Ummm... why are you guys all using the "\k" atom? Wouldn't "\w" make
                  more sense?
                  So here's my entry:
                  /\(\<\w\+\>\)\_s*\1\>

                  (This should match the first two words of a three-word repetition.)

                  -bob,mon.
                • Gary Holloway
                  / FROM: Robert Montante , Jul 3 9:04 2002 ... It really depends what you consider a word that you re looking for. w Will only find
                  Message 8 of 10 , Jul 3, 2002
                    / FROM: Robert Montante <bobmon@...>, Jul 3 9:04 2002
                    | ABOUT: Re: Searching for words that are repeated more than once consecutively
                    |
                    | >Bram Moolenaar:
                    | > /\(\<\k\+\>\)\s\+\1
                    | >
                    | >Preben Peppe Guldberg:
                    | > /\(\<\k\+\>\)\s\+\1\>
                    | >
                    | >Gary Holloway:
                    | > /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+
                    |
                    | Ummm... why are you guys all using the "\k" atom? Wouldn't "\w" make
                    | more sense?

                    It really depends what you consider a "word" that you're looking for.

                    \w Will only find [0-9A-Za-z_]
                    \k Is dependent upon your 'iskeyword' setting.

                    It's really a matter of preference.

                    -gary

                    | So here's my entry:
                    | /\(\<\w\+\>\)\_s*\1\>
                    |
                    | (This should match the first two words of a three-word repetition.)
                    |
                    | -bob,mon.
                    |
                    \ END: Robert Montante
                  Your message has been successfully submitted and would be delivered to recipients shortly.