summaryrefslogtreecommitdiff
path: root/dot-config/nvim/lua/spellcheck.lua
blob: 8ebc8c5ea4f283ed355867e8bcc196af5d1d252e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- To enable spellchecking
--
-- Credits
-- https://www.reddit.com/r/neovim/comments/1fwqc8t/how_to_enable_spell_check_for_only_specific_files/

local M = {}

local default_config = {
	filetypes = { "markdown" },
}

local function enable_spell(config)
	config = config or default_config

	-- Set global spell to false initially for all files
	vim.opt.spell = false

	-- Create augroup
	vim.api.nvim_create_augroup("Spellcheck", { clear = true })

	-- Create autocommand to enable spellcheck
	vim.api.nvim_create_autocmd({ "FileType" }, {
		group = "Spellcheck", -- Grouping for easier management
		pattern = config.filetypes, -- Only for these filetypes
		callback = function()
			vim.opt_local.spell = true -- Enable spellcheck
			vim.opt_local.spelllang = "en_us" -- Set language
		end,
		desc = "Enable spellcheck for defined filetypes",
	})
end

function M.setup(config)
	enable_spell(config)
end

return M