I am curious to know how I can find the next instance of a SpellLocal mistake (either by a motion key or via a search command) in vim.
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('.') while 1 " Store the cursor position let l:cursor = getpos('.') " Run ]s normal ]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) break endif " We found a SpellLocal; stop. if spellbadword() == 'local' break " Something else; continue to next word else normal w endif endwhile endfun 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 :-)
You could try SrchRplcHiGrp.vim: this plugin creates a command
SRSearch which allows to search for the occurrences of an highlight group. As
hl-SpellLocal is an highlight group that should do the trick.
To use it you'll have to find a word highlighted as a SpellLocal error, put your cursor on this word and use
SRChooseHiGrp to select the group you're looking for. Then you can use
SRSearch to go to the next word of the group.