From c9a7b3b6948f06328fd8ee49d793962fb695c86d Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 5 Jan 2026 20:05:21 +0000 Subject: [PATCH] Add markdown linting commands and update keymaps - Introduced commands to enable/disable automatic markdown linting. - Updated keymaps to reflect changes in markdown linting behavior. --- KEYMAPS.md | 13 ++++++++++--- lua/autocmds.lua | 3 ++- lua/plugins/nvim-lint.lua | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/KEYMAPS.md b/KEYMAPS.md index 8af3087..733ae12 100644 --- a/KEYMAPS.md +++ b/KEYMAPS.md @@ -46,6 +46,13 @@ Living reference of every explicit keymap defined in this config. Use `:KeymapsG | n | `lf` | Format current buffer (synchronous) | | v | `lf` | Format visual selection | +## `lua/plugins/nvim-lint.lua` + +| Command | Description | +| --- | --- | +| `:LintMarkdownEnable` | Enable automatic markdown linting (runs on BufEnter, BufWritePost, InsertLeave) | +| `:LintMarkdownDisable` | Disable automatic markdown linting and clear diagnostics | + ## `lua/plugins/gitsigns.lua` *(buffer-local when inside a git repo)* | Mode | Key | Description | @@ -160,9 +167,9 @@ Living reference of every explicit keymap defined in this config. Use `:KeymapsG | Key | Description | | --- | --- | -| `` | Initialize/expand selection | -| `` | Expand to scope | -| `` | Shrink selection | +| `+` | Initialize/expand selection | +| `g+` | Expand to scope | +| `-` | Shrink selection | ### Textobject selection (`select.keymaps`) diff --git a/lua/autocmds.lua b/lua/autocmds.lua index 240d169..39fee4c 100644 --- a/lua/autocmds.lua +++ b/lua/autocmds.lua @@ -52,7 +52,7 @@ vim.api.nvim_create_autocmd("FileType", { end, }) --- Markdown: Prettier defaults (2 spaces) +-- Markdown: Prettier defaults (2 spaces) + spellcheck vim.api.nvim_create_autocmd("FileType", { group = aug, pattern = "markdown", @@ -61,6 +61,7 @@ vim.api.nvim_create_autocmd("FileType", { vim.opt_local.tabstop = 2 -- Display as 2 spaces vim.opt_local.shiftwidth = 2 -- Indent by 2 vim.opt_local.softtabstop = 2 + vim.opt_local.spell = true -- Enable spellcheck for markdown end, }) diff --git a/lua/plugins/nvim-lint.lua b/lua/plugins/nvim-lint.lua index 63c9423..f68ef49 100644 --- a/lua/plugins/nvim-lint.lua +++ b/lua/plugins/nvim-lint.lua @@ -13,7 +13,7 @@ return { javascriptreact = { "eslint_d" }, typescript = { "eslint_d" }, typescriptreact = { "eslint_d" }, - markdown = { "markdownlint" }, + -- markdown linting: manual only (see keymap below) php = { "phpcs" }, -- Python: ruff LSP handles linting } @@ -78,5 +78,24 @@ return { lint.try_lint() end, }) + + -- Commands to enable/disable automatic markdown linting + vim.api.nvim_create_user_command("LintMarkdownEnable", function() + lint.linters_by_ft.markdown = { "markdownlint" } + vim.notify("Markdown linting enabled (automatic)", vim.log.levels.INFO) + -- Lint immediately + if vim.bo.filetype == "markdown" then + lint.try_lint() + end + end, { desc = "Enable automatic markdown linting" }) + + vim.api.nvim_create_user_command("LintMarkdownDisable", function() + lint.linters_by_ft.markdown = nil + vim.notify("Markdown linting disabled", vim.log.levels.INFO) + -- Clear existing diagnostics for markdown buffers + if vim.bo.filetype == "markdown" then + vim.diagnostic.reset(lint.get_namespace("markdownlint")) + end + end, { desc = "Disable automatic markdown linting" }) end, }