Promote/demote Markdown headings and list items using Treesitter.
- Neovim with
nvim-treesitter markdownparser installed (:TSInstall markdown)
Check health with:
:checkhealth markdown-mote
require("markdown-mote").setup()vim.pack.add({
src = "https://github.com/albertoCaroM/markdown-mote.nvim",
}){ "albertoCaroM/markdown-mote.nvim" }use("albertoCaroM/markdown-mote.nvim")require("markdown-mote").setup()
require("markdown-mote").promote()
require("markdown-mote").demote()markdown-mote.nvim does not define keymaps by default. The mappings below are
examples you can change to any keys you prefer.
Recommended setup in after/ftplugin/markdown.lua:
local mote = require("markdown-mote")
vim.keymap.set("n", "<Tab>", mote.demote, { buffer = true })
vim.keymap.set("n", "<S-Tab>", mote.promote, { buffer = true })
vim.keymap.set("v", "<Tab>", mote.demote, { buffer = true })
vim.keymap.set("v", "<S-Tab>", mote.promote, { buffer = true })
vim.api.nvim_buf_create_user_command(0, "MarkdownPromote", mote.promote, {})
vim.api.nvim_buf_create_user_command(0, "MarkdownDemote", mote.demote, {})Available in Markdown buffers:
:MarkdownPromote:MarkdownDemote
If you prefer defining this from init.lua, use a FileType autocmd with
vim.api.nvim_buf_create_user_command(args.buf, ...) so commands stay Markdown-local.
Heading subtree demote (with the example <Tab> mapping on ## Parent):
## Parent
### Childbecomes:
### Parent
#### ChildList item promote (with the example <S-Tab> mapping on - child):
- item
- childbecomes:
- item
- child- Headings: promote/demote the whole subtree (children included).
- Lists: indent/outdent the entire list item (children included).
- Visual mode: respects the selected range exactly.
- Limits: headings stay between levels 1 and 6.
- No-op: if no compatible node is found.
- Indentation: respects
expandtab,shiftwidth, andtabstop.
- Parser missing: run
:TSInstall markdownand re-open the file. - No effect: ensure the buffer is
filetype=markdownand Treesitter is enabled.
Run tests with the plenary harness:
nvim --headless -u tests/minimal_init.lua \
-c "lua require('plenary.test_harness').test_directory('tests', { minimal_init = './tests/minimal_init.lua' })" \
-c "qa"
Or use the Makefile helper:
make test
MIT. See LICENSE.