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 *)""; regards, Christian -- 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