diff --git a/nvim/.config/nvim/lua/core/commands.lua b/nvim/.config/nvim/lua/core/commands.lua index 1a3906b..289cd36 100644 --- a/nvim/.config/nvim/lua/core/commands.lua +++ b/nvim/.config/nvim/lua/core/commands.lua @@ -24,3 +24,20 @@ vim.api.nvim_create_autocmd({ "TermOpen" }, { pattern = "*", command = "setlocal nonumber norelativenumber", }) + +-- Custom spell enable which fires an event that other things can +-- hook into. +-- Toggles off and on by default, only turns on if called with bang. +vim.api.nvim_create_user_command("SpellToggle", function(opt) + vim.opt.spell = opt.bang or not vim.opt.spell:get() + if vim.opt.spell:get() then + if next(opt.fargs) ~= nil then + vim.opt.spelllang = opt.fargs + end + vim.api.nvim_exec_autocmds("User", { pattern = "SpellEnable" }) + vim.notify("Spellcheck enabled") + else + vim.api.nvim_exec_autocmds("User", { pattern = "SpellDisable" }) + vim.notify("Spellcheck disabled") + end +end, { nargs = "*", bang = true }) diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index a4d3028..5f61ba8 100644 --- a/nvim/.config/nvim/lua/core/mappings.lua +++ b/nvim/.config/nvim/lua/core/mappings.lua @@ -127,10 +127,11 @@ map("n", "Q", "vapJgqap", { silent = true, desc = "Unformat then fo -- SPELL CHECKING -- Move to the prev/next spelling error with [S ]S -- Move to the prev/next spelling error or suggestion with [s ]s -map("n", "ZZ", ":setlocal spell! spelllang=en_us,en_gb,de_de", { desc = "Toggle spellcheck" }) -map("n", "ZE", ":setlocal spell! spelllang=en_us", { desc = "Toggle EN_US spellcheck" }) -map("n", "ZB", ":setlocal spell! spelllang=en_gb", { desc = "Toggle EN_GB spellcheck" }) -map("n", "ZD", ":setlocal spell! spelllang=de_de", { desc = "Toggle DE_DE spellcheck" }) +map("n", "ZZ", "SpellToggle en_us en_gb de_de", { desc = "Toggle spellcheck" }) +map("n", "ZA", "SpellToggle! en_us en_gb de_de", { desc = "Enable spellcheck" }) +map("n", "ZE", "SpellToggle en_us", { desc = "Toggle EN_US spellcheck" }) +map("n", "ZB", "SpellToggle en_gb", { desc = "Toggle EN_GB spellcheck" }) +map("n", "ZD", "SpellToggle de_de", { desc = "Toggle DE_DE spellcheck" }) -- undo last spelling mistake from insert and normal mode map("i", "", "ue[s1z=`]au") map("n", "z", "mse[s1z=`s", { desc = "Fix last spell error" })