From: Samir Benmendil Date: Sat, 13 Dec 2025 15:34:53 +0000 (+0000) Subject: nvim: use nvim-origami for folds X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/8989ff1e17ac528e13a64614b669be3fb03b2435 nvim: use nvim-origami for folds It supports syntax highlighting of the folded first line and adds virtual text to show the line numbers and diagnostics. There's some settings that needed disabling though. I'd also like to place the virtual text on the right. So maybe I'll want to roll my own at some point. --- diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index aa69e77..72f9e86 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -53,6 +53,7 @@ "nvim-lspconfig": { "branch": "master", "commit": "a2bd1cf7b0446a7414aaf373cea5e4ca804c9c69" }, "nvim-navic": { "branch": "master", "commit": "7d914a39a1ef8f4e22c2c4381abeef7c556f5a13" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, + "nvim-origami": { "branch": "main", "commit": "ad252be766e7d07e0f1998d84deadb972736db08" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" }, "nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" }, diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua index 31f96b7..d960d60 100644 --- a/nvim/lua/config/options.lua +++ b/nvim/lua/config/options.lua @@ -31,8 +31,6 @@ opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift t opt.updatetime = 200 -- Save swap file and trigger CursorHold opt.splitkeep = "screen" opt.shortmess:append({ C = true }) -opt.foldmethod = "expr" -opt.foldexpr = "v:lua.require'rmz.util'.foldexpr()" -- do not let markdown plugin change indent vim.g.markdown_recommended_style = 0 diff --git a/nvim/lua/plugins/editor.lua b/nvim/lua/plugins/editor.lua index f5bfd74..249ac6d 100644 --- a/nvim/lua/plugins/editor.lua +++ b/nvim/lua/plugins/editor.lua @@ -182,6 +182,23 @@ return { end, }, }, + { "chrisgrieser/nvim-origami", -- fold with elegance + event = "VeryLazy", + opts = { + foldKeymaps = { setup = false }, + foldtext = { + padding = 1, + lineCount = { + template = "… %d lines" + } + } + }, + init = function() + -- disable vim's folding + vim.opt.foldlevel = 99 + vim.opt.foldlevelstart = 99 + end + }, -- TODO: currently unused plugins, check and enable/remove { "MagicDuck/grug-far.nvim", enabled = false, diff --git a/nvim/lua/rmz/util/init.lua b/nvim/lua/rmz/util/init.lua index abf0c21..54d8f6b 100644 --- a/nvim/lua/rmz/util/init.lua +++ b/nvim/lua/rmz/util/init.lua @@ -21,21 +21,4 @@ function M.dedup(list) return ret end -function M.foldexpr() - local buf = vim.api.nvim_get_current_buf() - if vim.b[buf].ts_folds == nil then - -- as long as we don't have a filetype, don't bother - -- checking if treesitter is available (it won't) - if vim.bo[buf].filetype == "" then - return "0" - end - if vim.bo[buf].filetype:find("dashboard") then - vim.b[buf].ts_folds = false - else - vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf) - end - end - return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or "0" -end - return M diff --git a/vim/ftplugin/cpp.vim b/vim/ftplugin/cpp.vim index d24f1ff..a039bac 100644 --- a/vim/ftplugin/cpp.vim +++ b/vim/ftplugin/cpp.vim @@ -76,30 +76,3 @@ function! s:Debug(...) endfunction command! -nargs=* -complete=file -bang Debug call Debug() | Termdebug command! -nargs=+ -complete=file -bang DebugCommand call Debug() | TermdebugCommand - -setlocal foldmethod=syntax -" set foldlevel according to number of matches of 'namespace' and 'class' not -" containing ';' -function! InitialFoldLevel() - let v:errmsg = "" - keepjumps keeppatterns silent! 1,/}/s/^\(namespace\|class\) \+[^;]*$//n - if v:errmsg == "" - let &l:foldlevel=str2nr(split(v:statusmsg)[0]) - endif -endf -call InitialFoldLevel() - -function! MyCppFoldText() - let l:line = getline(v:foldstart) - " expand tabs in line, foldtext does not do it on its own - let l:line = substitute(l:line, "\t", repeat(" ", shiftwidth()), "g") - let l:width = min([&textwidth, winwidth(0)]) - let l:lineinfo = printf("%d", v:foldend - v:foldstart) - let l:ellipsis = "…" - return printf("%.*s%s%*d", - \ l:width - strdisplaywidth(l:ellipsis..l:lineinfo), l:line, - \ l:ellipsis, - \ l:width - strdisplaywidth(l:line..l:ellipsis), l:lineinfo) -endfunction -setlocal foldtext=MyCppFoldText() -setlocal fillchars+=fold:\