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

Re: Two search patterns

Expand Messages
  • Bram Moolenaar
    ... Thanks for the patch. Using another search pattern instead of failing probably won t break anything. -- hundred-and-one symptoms of being an internet
    Message 1 of 2 , Jan 25, 2011
    • 0 Attachment
      Christian Brabandt wrote:

      > On So, 23 Jan 2011, Tim Chase wrote:
      > > Per the help at
      > >
      > > :help last-pattern
      > > """
      > > Note that two patterns are remembered: One for 'normal'
      > > search commands and one for the substitute command ":s".
      > > Each time an empty pattern is given, the previously used
      > > pattern is used.
      > > """
      > >
      > >
      > > There seems to be a peculiarly unidirectional defaulting:
      > >
      > > Case #1:
      > >
      > > Start Vim (-u NONE) on a document
      > > Search for a pattern with "/"
      > >
      > > /pattern
      > >
      > > perform an empty substitute:
      > >
      > > :%s//whatever/g
      > >
      > > A blank :s pattern reaches for the most recent "/" pattern. Nice, I use
      > > this regularly.
      > >
      > >
      > > Case #2:
      > >
      > > Start Vim (-u NONE) on a document
      > > Perform a replacement (either a null-op, or just the first-in-a-line with
      > > further matches later in the line, or a replacement that allows for the
      > > pattern to be found again)
      > >
      > > :%s/pattern/&
      > >
      > > Hit "n" to find the next instance of the pattern or use "/" with an empty
      > > pattern. I get
      > >
      > > E35: No previous regular expression
      > >
      > > A blank search *doesn't* reach into the most recent ":s" pattern. I
      > > reach for this occasionally and get stung by it every time.
      > >
      > > However, if I do a
      > >
      > > :%s//whatever
      > >
      > > it manages to find that pattern. Likewise if I ":echo @/" it correctly
      > > returns my :s pattern that I want to use for my n/N command (or "/" with
      > > no regexp).
      > >
      > >
      > > It seems a little inconsistent to find the search pattern in the first
      > > case, but to not find the pattern in the second case.
      > >
      > >
      > > Is this a Vim bug (calling for n/N to use the search register), a
      > > documentation bug (at a minimum requiring clarification), or just a "suck
      > > it up and deal with the oddity" situation?
      > >
      > > -tim
      >
      > Here is a patch:
      > diff --git a/src/search.c b/src/search.c
      > --- a/src/search.c
      > +++ b/src/search.c
      > @@ -1161,9 +1161,13 @@
      > {
      > if (spats[RE_SEARCH].pat == NULL) /* no previous pattern */
      > {
      > - EMSG(_(e_noprevre));
      > - retval = 0;
      > - goto end_do_search;
      > + pat = last_search_pat();
      > + if (pat == NULL)
      > + {
      > + EMSG(_(e_noprevre));
      > + retval = 0;
      > + goto end_do_search;
      > + }
      > }
      > /* make search_regcomp() use spats[RE_SEARCH].pat */
      > searchstr = (char_u *)"";
      >

      Thanks for the patch. Using another search pattern instead of failing
      probably won't break anything.

      --
      hundred-and-one symptoms of being an internet addict:
      149. You find your computer sexier than your girlfriend

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ an exciting new programming language -- http://www.Zimbu.org ///
      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

      --
      You received this message from the "vim_dev" 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
    Your message has been successfully submitted and would be delivered to recipients shortly.