mmap.page

Spell Checking in Vim

Vim has built-in support for spell checking. This built-in function provides basic spell checking. For example, it does not recognize 'localhost', 'Lua' or 'Node.js'. However, new words can be added quickly via zg in normal mode.

LunarVim, the Neovim distribution I use, enables spell checking for commit messages and markdown by default.

To exclude East Asian characters from spell checking, I add the following to my ~/.config/lvim/config.lua:

vim.opt.spelllang = vim.opt.spelllang + "cjk"

To check grammar and stylish errors, Grammarly or LanguageTool can be used.

I prefer LanguageTool because it is open source. All the errors can be checked with ltex-ls locally, without making any network requests.

Unfortunately, ltex-ls does not support adding unknown words to dictionary. Thus, I disabled the spell checking rule from ltex-ls. Neovim's built-in spell checking is used instead.

local ltex_options = {
  settings = {
    ltex = {
      disabledRules = {
        ["en-US"] = { "MORFOLOGIK_RULE_EN_US" }
      },
    },
  },
}
require("lvim.lsp.manager").setup("ltex", ltex_options)

Alternatively, ltex-ls can be configured to use the normal vim user dictionary. The downside is a restart of Neovim is required for ltex-ls to recognize newly added words. Vim autocmd may be used to update the word list automatically, but this adds complexity to the configuration.

BTW, the grammarly LSP does not support this, either.