lewis6991/spellsitter.nvim

github github
spellcheck
star 431
stars
alert-circle 8
open issues
users 10
subscribers
git-branch 26
forks
CREATED

2021-02-21

UPDATED

last month


spellsitter.nvim

CI License: MIT

Enable Neovim's builtin spellchecker for buffers with tree-sitter highlighting.

What this plugin does

With set spell:

Settings Result
syntax off, Treesitter disabled syntax off no treesitter
syntax on, Treesitter disabled syntax_on_no_treesitter
Treesitter enabled ts_no_spellsitter
Treesitter (with spellsitter), ts_plus_spellsitter

Requirements

Neovim >= 0.5.0

Installation

use { -- Optional but recommended -- 'nvim-treesitter/nvim-treesitter', 'lewis6991/spellsitter.nvim', }


[vim-plug](https://github.com/junegunn/vim-plug):
```vim
" Optional but recommended
" Plug 'nvim-treesitter/nvim-treesitter'
Plug 'lewis6991/spellsitter.nvim'

NOTE: This plugin does not depend on nvim-treesitter however it is recommended in order to easily install tree-sitter parsers.

Usage

For basic setup with all batteries included:

require('spellsitter').setup()

If using packer.nvim spellsitter can be setup directly in the plugin spec:

use {
  'lewis6991/spellsitter.nvim',
  config = function()
    require('spellsitter').setup()
  end
}

NOTE: If you are running this with nvim-treesitter (which will be 99% of users), then you must make sure additional_vim_regex_highlighting is either not set or disabled. Enabling this option will likely break this plugin. Example:

require'nvim-treesitter.configs'.setup {
  highlight = {
    enable = true,
    -- additional_vim_regex_highlighting = true, -- DO NOT SET THIS
  },
}

Configuration

Configuration can be passed to the setup function. Here is an example with all the default settings:

require('spellsitter').setup {
  -- Whether enabled, can be a list of filetypes, e.g. {'python', 'lua'}
  enable = true,
  debug = false
}

You can selectively disable spellchecking based on certain criterion by writing custom autocommands using the setlocal nospell command in your init.lua like this:

local my_augroup = vim.api.nvim_create_augroup("my_augroup", { clear = true })

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "python", "lua" }, -- disable spellchecking for these filetypes
  command = "setlocal nospell",
  group = my_augroup,
})
vim.api.nvim_create_autocmd("TermOpen", {
  pattern = "*", -- disable spellchecking in the embeded terminal
  command = "setlocal nospell",
  group = my_augroup,
})

Languages Supported

Spellsitter uses several methods for looking for spelling regions:

  1. It first looks for a specific spell query file. These can be found here.

  2. If there is no language specific spell query file available, then Spellsitter will try to define an inline query to capture comment nodes. As some parsers don't have this specific node name (some have comment_block, inline_comment, etc), then this might fail.

  3. Finally Spellsitter will load the highlights query which nvim-treesitter defines for most languages. From this Spellsitter will use the @comment capture. This is a standard capture name (as it maps to the TSComment highlight), so this should always succeeds, but the same time provides the most limited spellchecking experience.

If you want better spellchecking support for a specific language then please open a pull request adding a spell query file for said language.

Non-Goals

  • Support external spellchecker backends.