No error with ]s when nowrapscan?

21 views
Skip to first unread message

Tim Chase

unread,
Sep 21, 2026, 1:25:22 PM (3 days ago) Sep 21
to Vim Users
Playing with something recently, I discovered that ]s doesn't seem to
throw any sort of error when wrapscan is off and it hits the end of the
file.

To demonstrate with the following setup (where {one,two,three}.txt are
some files with a couple misspelled words scattered throughout each)

$ vim one.txt two.txt three.txt
:set hidden nowrapscan

I then repeatedly issued

:try | exec 'norm ]s' | catch | n | endtry

(using @: then subsequently @@ makes this easy) which worked for finding
all the misspelled words in the *first* file, but after finding the
last one in that file, the ]s *should* fail because there is no "next"
bad-spelling in the current file and wrapscan is off. So it seems like
the ]s *should* have thrown an exception, get caught, and then go to
the :next file instead where the process can repeat. But it seems to
silently swallow the "no more bad spellings in the current file" without
letting me catch the condition.

AFAICT there's no

:spellnext

type ex command or spellnext() function corresponding to ]s that might
be more error-cooperative.

Is there a better way to go about this?

-tim
--





Doug Kearns

unread,
Sep 22, 2026, 8:07:50 AM (2 days ago) Sep 22
to vim...@googlegroups.com
Hi Tim,

You could leverage temporary use of `:set debug=beep`.

Regards,
Doug 

Tim Chase

unread,
Sep 22, 2026, 8:42:30 AM (2 days ago) Sep 22
to vim...@googlegroups.com
On 2026-09-22 22:06, Doug Kearns wrote:
> > $ vim one.txt two.txt three.txt
> > :set hidden nowrapscan
> >
> > I then repeatedly issued
> >
> > :try | exec 'norm ]s' | catch | n | endtry
> >
> > (using @: then subsequently @@ makes this easy) which worked for
> > finding all the misspelled words in the *first* file, but after
> > finding the last one in that file, the ]s *should* fail because
> > there is no "next" bad-spelling in the current file and wrapscan is
> > off. So it seems like the ]s *should* have thrown an exception, get
> > caught, and then go to the :next file instead where the process can
> > repeat. But it seems to silently swallow the "no more bad spellings
> > in the current file" without letting me catch the condition.
[snip]
> You could leverage temporary use of `:set debug=beep`.

A promising proposition, but I'm not sure that's working for me?

I tried the your suggestion with each of

debug=beep
debug=throw
debug=throw,beep

but none of them change the behavior of the ]s (not) throwing an error
to get caught. I do see "Beep!" text at the bottom of my screen when I
expect the exception/catch, but no catchable error seems to happen.

-tim
--





Doug Kearns

unread,
Sep 22, 2026, 11:05:13 AM (2 days ago) Sep 22
to vim...@googlegroups.com
Yes, I was thinking you could test for that text calling execute().  I also forgot there's an assert_beeps() but you'd probably want to save restore v:errors.

Perhaps just checking for a change in cursor position is good enough?

Regards,
Doug [not in a dev environment]

Reply all
Reply to author
Forward
0 new messages