I often write code, and sometimes I check comments with z=
when I am not sure of a spelling of some word. Vim then presents a list of suggestions. However, when I got the spelling right and the word is correct, then the word is not in the suggest list, so I do not know if I spelled it correctly or not. For me, as the word is correctly spelled, the same word has the "best" match for spellchecking suggestion, so the same word should be the best suggestion.
[
Above is a screenshot after running z=
on Word
. The best suggestion for changing a correct word Word
is Ward
. Would it be possible for vim to suggest the same word when the word is correct? I usually replace the word for anything, and then re-run suggestion and find the same word in suggestion list, just to make sure it is correct.
I tried reading :h spell spellsuggest spelloptions
etc. but I did not find such option. The behavior stays the same in neovim and vim, with and without (-U NONE
) plugins. The behavior most probably depends on spellsuggest()
that has a description that:
spellsuggest()
spellsuggest({word} [, {max} [, {capital}]])
...
{word} may also be a good word. Similar words will then be
returned. {word} itself is not included in the suggestions,
although it may appear capitalized.
Is my only option to add spellsuggest^=expr:MySuggest()
where in pseudocode function MySuggest() if v:val is correctly spelled; then return [v:val, 0] endfunction
? So I did just that:
function Kc_spell_suggest_correct_word()
if len(spellbadword(v:val)[0]) == 0
" return [['is correct '.v:val, 1]
return [[v:val, 1]
endif
return []
endfunction
set spellsuggest^=expr:Kc_spell_suggest_correct_word()
But the word still does not show up in the suggest list and the list stays the same as in the first screenshot. If however the 'is correct '
part is uncommented, it does show up in the result list! Based on that, the function works as it should and there's some else place that filters the word. No errors show up in set verbose=1
:
What can I do to make it show up the same word in completion list if the word is good?
:set spell
and your colorscheme supports it, you should have highlighting when a word is misspelled, so you needn't guess in this way. There's also]s
and[s
to navigate between misspelled words.