The functionality of this plugin has now been merged into Neovim core as of neovim/neovim#19419 and will be available in the upcoming v0.8 release of Neovim.
This repository will be archived.
Enable Neovim's builtin spellchecker for buffers with tree-sitter highlighting.
With set spell
:
Settings | Result |
---|---|
syntax off , Treesitter disabled |
|
syntax on , Treesitter disabled |
|
Treesitter enabled | |
Treesitter (with spellsitter), |
Neovim >= 0.5.0
use {
-- Optional but recommended
-- 'nvim-treesitter/nvim-treesitter',
'lewis6991/spellsitter.nvim',
}
" 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.
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 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,
})
Spellsitter uses several methods for looking for spelling regions:
-
It first looks for a specific spell query file. These can be found here.
-
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 havecomment_block
,inline_comment
, etc), then this might fail. -
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 theTSComment
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.
- Support external spellchecker backends.