Hi Gary!

On Di, 10 Feb 2015, Gary Johnson wrote:

> On 2015-02-10, Christian Brabandt wrote:
> > Am 2015-02-10 04:15, schrieb Gary Johnson:
> > >Given a file with the following contents,
> > >
> > >ape(x
> > >boy(y
> > >cat(
> > >dog(z
> > >emu(
> > >
> > >and opened with
> > >
> > >    vim -N -u NONE file
> > >
> > >this search command,
> > >
> > >    /(/e+1
> > >
> > >will first move the cursor to the 'x' at the end of the first line,
> > >as expected.  Typing 'n' will then move the cursor to
> > >
> > >    -  the 'y' at the end of the second line (OK)
> > >    -  the 'd' at the start of the fourth line (odd)
> > >    -  the 'z' at the end of the fourth line (OK)
> > >    -  the '(' at the end of the last line (odd)
> > >
> > >Typing 'n' again will not move the cursor (bad).
> > >
> > >It seems odd that the match wraps to the start of line 4, but I can
> > >accept that.  That typing 'n' does not continue the search from the
> > >start of the file is really annoying.
> > 
> > Where should the cursor move for the last line? To line 1 if wrapscan
> > is set?
> 
> I don't know.  Since Vim patterns don't span lines unless the
> newline is accounted for specially, it seems odd to me that the e
> offset spans lines.  I'm not saying it's wrong, it just feels odd to
> me.  That could be because I used vi for so long before using Vim.
> 
> Regardless of where the cursor should be for the last line, it seems
> wrong that the cursor gets stuck there.  It gets stuck at the end of
> the file for any pattern and offset that would place the cursor
> beyond the last character in the buffer.

That happens, because it finds the end over and over again.

> Vim can't place the cursor beyond the last character in the buffer,
> though, so it actually puts the cursor on the last character in the
> buffer.  Typing 'n' at that point should move the cursor to the next
> match, even if that would be some virtual character to the right of
> the cursor location.
> 
> I thought there was a precedent for advancing the cursor to the next
> match if it would otherwise get stuck in some pattern loop, but I
> can't think of exactly what it was.  There is a precedent for

; for when the 't' was used?

> remembering where the cursor _would_ be if a character was there:
> the movement of j and k over lines shorter than the cursor column.
> As long as you only use j and k, the cursor column is remembered.
> There could be something similar for this case:  a cursor character
> location where the cursor would be if a character was there.  As
> long as the only commands typed are n or N, the next search would
> begin from where the cursor would be, not where it actually is.

Here is a patch, that makes 'n'/'N' check, whether the cursor moved and 
if not, retry with an incremented count. That works for your particular 
case. That won't help for the case of the cursor being on the last 
character of a buffer and typing /(/e+1
But pressing n afterwards should work.

Best,
Christian
-- 
Hamburg liegt am Ausflusse der Ostsee in die Elbe.
                -- Johann Georg August Galletti

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/normal.c b/src/normal.c
--- a/src/normal.c
+++ b/src/normal.c
@@ -100,7 +100,7 @@ static void	nv_end __ARGS((cmdarg_T *cap
 static void	nv_dollar __ARGS((cmdarg_T *cap));
 static void	nv_search __ARGS((cmdarg_T *cap));
 static void	nv_next __ARGS((cmdarg_T *cap));
-static void	normal_search __ARGS((cmdarg_T *cap, int dir, char_u *pat, int opt));
+static int	normal_search __ARGS((cmdarg_T *cap, int dir, char_u *pat, int opt));
 static void	nv_csearch __ARGS((cmdarg_T *cap));
 static void	nv_brackets __ARGS((cmdarg_T *cap));
 static void	nv_percent __ARGS((cmdarg_T *cap));
@@ -5765,7 +5765,7 @@ nv_ident(cap)
 	init_history();
 	add_to_history(HIST_SEARCH, buf, TRUE, NUL);
 #endif
-	normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
+	(void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
     }
     else
 	do_cmdline_cmd(buf);
@@ -6301,7 +6301,7 @@ nv_search(cap)
 	return;
     }
 
-    normal_search(cap, cap->cmdchar, cap->searchbuf,
+    (void)normal_search(cap, cap->cmdchar, cap->searchbuf,
 						(cap->arg ? 0 : SEARCH_MARK));
 }
 
@@ -6313,14 +6313,25 @@ nv_search(cap)
 nv_next(cap)
     cmdarg_T	*cap;
 {
-    normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg);
+    pos_T old = curwin->w_cursor;
+    int i;
+    i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg);
+    if (i == 1 && equalpos(old, curwin->w_cursor))
+    {
+	/* avoid getting stuck on the current cursor position
+	 * can happen when offset is given and cursor on last char
+	 * in buffer */
+	cap->count1 += 1;
+	(void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg);
+	cap->count1 -= 1;
+    }
 }
 
 /*
  * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
  * Uses only cap->count1 and cap->oap from "cap".
  */
-    static void
+    static int
 normal_search(cap, dir, pat, opt)
     cmdarg_T	*cap;
     int		dir;
@@ -6354,6 +6365,7 @@ normal_search(cap, dir, pat, opt)
     /* "/$" will put the cursor after the end of the line, may need to
      * correct that here */
     check_cursor();
+    return i;
 }
 
 /*

Raspunde prin e-mail lui