gn
is a very useful command that selects the next search result. For example, if I insert
foo bar baz
into a file, move to the beginning, type /[aeiou].
, and press gn
, it would select oo
in a visual selection. Pressing dgn
would delete that and then select ar
in a visual selection.
However, let's say I have the following file (where [x]
represents the cursor):
This is some text. Blah blah blah. Lorem ipsum. Foo bar b[a]z quux.
and I've searched for . .
(any character, a space, then any character). Pressing dgn
would delete the z q
, since it's the first search result after my cursor. However, pressing gn
from here now has no effect, since this motion does not "wrap around" back to the beginning of the file like n
does.
How can I make gn
wrap to the first search result if there are no results after the cursor (but still have no effect (or give an error, without moving the cursor) if there are no more results in the entire file), just like the n
command?
After discussion in the comments: This may be system-specific. I'm running Vim 7.4.52 on Ubuntu 14.04.
gn
wraps for me. Now I have to figure out what enables it. Ok - this wraps even with-u NONE
.-u NONE
for me. What platform/version? I'm on Vim 7.4.52 on Ubuntu 14.04.ggdgn
? Or:%s/. ./gc
?