Open tkapias opened 2 years ago
For now I use this setup:
autocmd FileType sh,toml,yaml,python noremap <buffer><silent> <Leader>fc :set foldmethod=expr<CR>
\:set foldexpr=getline(v:lnum)=~'^\\s#'?1
\:getline(prevnonblank(v:lnum))=~'^\\s#'?1
\:getline(nextnonblank(v:lnum))=~'^\\s*#'?1
\:0<CR>
autocmd FileType vim noremap <buffer><silent> <Leader>fc :set foldmethod=expr<CR>
\:set foldexpr=getline(v:lnum)=~'^\\s\"'?1
\:getline(prevnonblank(v:lnum))=~'^\\s\"'?1
\:getline(nextnonblank(v:lnum))=~'^\\s*\"'?1
\:0<CR>
I would help facilitate a PR if somebody wanted to contribute this as a new feature. I would suggest in needs to be behind a default-off feature flag so as to not mess up other fold expression enabled plugins, and we need some way to derive the expression to use for all block/multiline comments. Preferably we wouldn't be matching inline or even single line comments.
Apparently, there is no plugin that supports comments folding for major filetypes. Those that I found are deprecated, or really limited. Most of the plugins dedicated to syntax and filetypes don't offer it either.
I currently use custom fold expressions for Unix-like comments, like the one found here:
Would nerdcommenter be a good place to add such a functionality?