Neovim spellcheck - quick tips
Note
Apr 11, 2024In neovim, when a word is marked as misspelled, you can add it to the dictionary
by typing zg while the cursor is on the word. To correct a word from
a list of suggestions, you can type z=. This is great, but what if
you want to add a custom spelling suggestion? For example, I want to add the
word neovim
to the dictionary, but I don’t want to add it to the dictionary as
neovim
, I want to add it as Neovim
, with a capital N
.
Configuration
Here’s how you do it:
-
Create a custom spelling suggestion file in your neovim configuration directory. I called mine
~/.config/nvim/spell/sugg
. You might notice files in that folder that end in.add
— the words in these files are ignored by spellcheck.neovim / Neovim;------If
Neovim
is marked as a misspelled word, type zg to add it to the dictionary.
Note: If the word to the right of the/
is mispelled, the suggestion will be ignored by neovim. Make sure all words on the right are added as “goodwords”.The file should now look like this:
-
Add the following to your vim options:
vim.opt.sps = "file:/Users/aaron/.config/nvim/spell/sugg,best"
Now, when editing a file, if neovim
is marked as a misspelled word, typing
z= will show Neovim
as the first suggestion.
Disabling for syntax
Another thing to note is that there is a configuration option for spellchecking syntax. Generally, we do not want to spell check function and class names, etc - the whole page would start to turn red! To ignore certain syntax, add the following to your vim options:
vim.cmd("set spell syntax=off")
Setting up Vale
Here’s how you do it:
- On OSX,
brew install vale
. - Create a
.vale.ini
file in your project root. Many projects on github have great examples of vale configurations tailored for technical writing. Here’s mine for some inspiration. with the following content:
StylesPath = .vale/stylesMinAlertLevel = suggestionPackages = write-good, proselint, Microsoft # `vale sync` will download these packages for you.Vocab = Me[*]IgnoredScopes = code, tt, table, tr, td # ignore HTMLBlockIgnores = (?s) *({< output >}.*?{< ?/ ?output >}), \(?s) *({< highlight .* >}.*?{< ?/ ?highlight >})[*md]BasedOnStyles = Vale, Microsoft, write-good # also check out `proselint`; Vale.Spelling = NOVale.Spelling=warningVale.Terms = NOwrite-good.E-Prime = NO # E-prime is too aggressive and not best suited for blog or tutorial writing.write-good.ThereIs = suggestion# I've sen many configs that disable these, but I'm still testing them out. If i# update my vale configuration, I can reload the file in Neovim with `:e` to# refresh the diagnostics.; write-good.TooWordy = NO; write-good.Weasel = NOMicrosoft.GeneralURL = NOMicrosoft.HeadingAcronyms = NOMicrosoft.Auto = NOMicrosoft.Acronyms = NOMicrosoft.Wordiness = NO # Postman.TooWordy, which was based on WriteGood, is better.Microsoft.Passive = NOMicrosoft.Vocab = NOMicrosoft.ComplexWords = NOMicrosoft.We = YESMicrosoft.Adverbs = NO # Postman.Weasel now has every unique word from this added to it.Microsoft.Terms = NOMicrosoft.Avoid = NO[formats]mdx = md
- Vale will automatically fetch the Style rules for you and save them into your
StylesPath
. - Set up a keybinding in Neovim to append
<cword>
, the word under the cursor, to the custom spell file. Since this configuration specifiesVocab = Me
, the spellfile should be created at./vale/styles/config/vocabularies/accept.txt
, and it will simply be a list of words to ignore separated by newlines.