diff options
author | Christian Clason <c.clason@uni-graz.at> | 2025-02-22 13:07:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-22 13:07:21 +0100 |
commit | 2e5b560482fb76342387e7183283efe9d431f114 (patch) | |
tree | 1c9df3791d2262098977a3da39912c18808ec7a3 /runtime/ftplugin/markdown.lua | |
parent | 5cead869fb6ddc57594c0dc7e6e575f9427630c8 (diff) | |
download | rneovim-2e5b560482fb76342387e7183283efe9d431f114.tar.gz rneovim-2e5b560482fb76342387e7183283efe9d431f114.tar.bz2 rneovim-2e5b560482fb76342387e7183283efe9d431f114.zip |
feat(treesitter): table of contents for checkhealth, markdown (#32282)
Problem: It's difficult to navigate large structured text files (vim
help, checkhealth, Markdown).
Solution: Support `gO` for table of contents and `]]`/`[[` for moving
between headings for all these filetypes using treesitter queries.
Refactor: colorization of highlight groups is moved to the `help` ftplugin
while headings-related functionality is implemented in a private
`vim.treesitter` module for possible future use for other filetypes.
Diffstat (limited to 'runtime/ftplugin/markdown.lua')
-rw-r--r-- | runtime/ftplugin/markdown.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/ftplugin/markdown.lua b/runtime/ftplugin/markdown.lua new file mode 100644 index 0000000000..9319ca7757 --- /dev/null +++ b/runtime/ftplugin/markdown.lua @@ -0,0 +1,14 @@ +vim.keymap.set('n', 'gO', function() + require('vim.treesitter._headings').show_toc() +end, { buffer = 0, silent = true, desc = 'Show table of contents for current buffer' }) + +vim.keymap.set('n', ']]', function() + require('vim.treesitter._headings').jump({ count = 1 }) +end, { buffer = 0, silent = false, desc = 'Jump to next section' }) +vim.keymap.set('n', '[[', function() + require('vim.treesitter._headings').jump({ count = -1 }) +end, { buffer = 0, silent = false, desc = 'Jump to previous section' }) + +vim.b.undo_ftplugin = (vim.b.undo_ftplugin or '') + .. '\n exe "nunmap <buffer> gO"' + .. '\n exe "nunmap <buffer> ]]" | exe "nunmap <buffer> [["' |