What you can do is modify the
[s motions to skip over
SpellBad highlighted words. This is actually not very hard. With the
spellbadword() function we can get information about the spell status of the current word:
Example outputs of
- behavior (with en-gb locale):
So what we need to make is a mapping which:
- Checks if the word under the cursor has the status
- If so, stop.
- If the cursor position is unchanged, there are no more misspelled words and we stop.
- All else: go to the next word and back to 1.
And here is exactly such a function:
fun! SpellLocal() abort
let l:start_pos = getpos('.')
" Store the cursor position
let l:cursor = getpos('.')
" Run ]s
" The cursor position hasn't changed, this means ]s didn't find
" anything else.
if getpos('.') == l:cursor
" Restore cursor position to match default ]s behaviour
call setpos('.', l:start_pos)
" We found a SpellLocal; stop.
if spellbadword() == 'local'
" Something else; continue to next word
nnoremap <silent> <Leader>]s :call SpellLocal()<CR>
You can expand this by passing an argument which specifies the direction (
[s). This is left as an exercise for the reader :-)