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

RE: regex repetition quantifier * in vim

Expand Messages
  • Bowie Bailey
    From: qlerner@netvision.net.il [mailto:qlerner@netvision.net.il] ... This sounds interesting, but it doesn t seem to work for me. I opened this email in vim
    Message 1 of 7 , Mar 30, 2004
    • 0 Attachment
      From: qlerner@... [mailto:qlerner@...]
      >
      > You can refer specifically to the match at which
      > cursor is positioned. The command is:
      > v//e
      > This turns the match under cursor into visual selection. You can
      > then operate on the resulting visual selection.
      >
      > This is useful when there are several matches on the
      > line and you want to operate on the match at which cursor is
      > positioned.

      This sounds interesting, but it doesn't seem to work for me.

      I opened this email in vim and did a test:
      /the match/

      This highlighted a few matches. I moved my cursor to one of them and
      typed 'v//e'. What it seems to do for me is highlight everything from
      where the cursor currently is to one character from the end of the
      match. For example, if the cursor is on the 'e' in 'the', then the
      selected portion looks like this:

      the match
      ^^^^^^

      Also, in order to do anything to just one part of the line, I had to use
      <ctrl-v> to do the selection and vis.vim's ':B' command.

      Bowie
    • qlerner@netvision.net.il
      ... That s right; v//e assumes that cursor is on the 1st character of the match. Here is the mapping that selects whole current match no matter where the
      Message 2 of 7 , Mar 30, 2004
      • 0 Attachment
        Bowie Bailey wrote:
        > From: qlerner@... [mailto:qlerner@...]
        >>You can refer specifically to the match at which
        >>cursor is positioned. The command is:
        >> v//e
        > This sounds interesting, but it doesn't seem to work for me.
        .... What it seems to do for me is highlight everything from
        > where the cursor currently is to one character from the end of the
        > match.

        That's right; v//e assumes that cursor is on the 1st character
        of the match.

        Here is the mapping that selects whole current match no matter
        where the cursor is inside the match:

        map <F9> l??b<CR>v//e<CR>

        This visual-selects the whole current match no matter where the cursor is
        inside it. If the cursor is not inside match, it selects the previous match.

        This mapping still has couple of problems/limitations:

        (1) when the match is at the end of the line and the cursor is
        at the end of the match.
        This mapping will work at the end of line if either
        (a) 'whichwrap' includes 'l' (set ww+=l), or
        (b) 'set virtualedit' is on

        (2) when he match is single-character long.

        It's possible to write the longer solution (function)
        that fixes these limitations independently of
        current user settings.

        Yakov

        --------------------------------------------------------------------
        mail2web - Check your email from the web at
        http://mail2web.com/ .
      • Bowie Bailey
        From: qlerner@netvision.net.il [mailto:qlerner@netvision.net.il] ... This still doesn t get it all. It misses the last character of the match. Using the same
        Message 3 of 7 , Mar 30, 2004
        • 0 Attachment
          From: qlerner@... [mailto:qlerner@...]
          > Bowie Bailey wrote:
          > > From: qlerner@... [mailto:qlerner@...]
          > > >You can refer specifically to the match at which
          > > >cursor is positioned. The command is:
          > > > v//e
          > >
          > > This sounds interesting, but it doesn't seem to work for me.
          > > .... What it seems to do for me is highlight everything from
          > > where the cursor currently is to one character from the end of the
          > > match.
          >
          > That's right; v//e assumes that cursor is on the 1st character
          > of the match.
          >
          > Here is the mapping that selects whole current match no matter
          > where the cursor is inside the match:
          >
          > map <F9> l??b<CR>v//e<CR>

          This still doesn't get it all. It misses the last character of the
          match.

          Using the same example:

          the match
          ^^^^^^^^

          In order to get it to work properly, I needed this map:

          map <F9> l??b<CR>v//e<CR>l


          Ahh...after poking around a bit, I found the problem:

          set selection=exclusive

          Your map only works properly if selection is set to "inclusive" (which
          is the default).

          Thanks for the tip. I didn't know you could extend a visual block by
          searching this way. With Vim, there's always something new.

          Bowie
        Your message has been successfully submitted and would be delivered to recipients shortly.