OXY2DEV/markview.nvim

✨ Feature: Fold bullet lists

Closed this issue · 5 comments

The nature of the feature:

  • Parser(syntax, conceal etc. related)
  • Renderer(style, options etc. related)
  • Support(plugin support, language support etc. related)
  • Other

Description:

Since markview.nvim is becoming the default markdown plugin for neovim , i gonna suggest here (dont know if im doing wrong) a way to properly fold bullet lists in neovim .
Treesitter have a known bug to not work properly with bullet lists folding. And fold bullets is a thing that i miss a lot from standard markdown editors

Create a file named folds.scm in ~/.config/nvim/queries/markdown/.

Add this to the file.

((list) @fold)

Use this in your config.

vim.o.foldmethod = "expr";
vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()";

-- Optional, This gets rid of the fold text and shows the actual line.
vim.o.foldtext = "";

Tip

Put the options in ~/.config/nvim/after/ftplugin/markdown.lua to only use them in markdown files.

Screenshot_2024-11-20-01-21-43-811_com termux-edit
Screenshot_2024-11-20-01-21-58-385_com termux-edit

Also, you don't even need to do this.

Just this should be enough,

vim.o.foldmethod = "expr";
vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()";

-- Optional, This gets rid of the fold text and shows the actual line.
vim.o.foldtext = "";

could you nest sublists, like in your last image, could you nest "1. Nest 4" into "Nest 3" without folding all the list ?

You mean something like this?

Fold closed Fold open
Screenshot_2024-11-20-07-01-27-303_com termux-edit Screenshot_2024-11-20-07-01-43-392_com termux-edit

Use this,

((list) @fold
  (#offset! 0 0 -1 0))

You mean something like this?

exactly this , mine is folding wrong

if im in line of the Nest 3:
image

and hit fold (zc) it does
image

or hit fold (zm) it does
image

it dont do like yours (the correct way)

i have this im my init.lua :

vim.o.foldmethod = "expr";
vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()";
vim.opt_local.foldtext = "getline(v:foldstart)"
vim.opt_local.foldlevel = 99 

where do i add this ?

((list) @fold
  (#offset! 0 0 -1 0))