diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-05-29 16:08:15 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-05-29 16:08:15 +0200 |
| commit | b875b7f877a08c20c6a903f57a6cb253057e6ab7 (patch) | |
| tree | 30d75fb58bbe92abbfee4ae3fc03685add612c25 /.config/nvim/plugin/50-fold.lua | |
| parent | 0fffabeb114810c846d25fa77cc382f31a9e7b7d (diff) | |
| download | dotfiles-b875b7f877a08c20c6a903f57a6cb253057e6ab7.tar.gz dotfiles-b875b7f877a08c20c6a903f57a6cb253057e6ab7.zip | |
misc(nvim): add user command to (re)initialize folds
A user command to reinitialize folds is the best solution. It's better
than doing it automatically because if folds are recalculated all the
time then when writing code new folds will close on the cursor.
Diffstat (limited to '.config/nvim/plugin/50-fold.lua')
| -rw-r--r-- | .config/nvim/plugin/50-fold.lua | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/.config/nvim/plugin/50-fold.lua b/.config/nvim/plugin/50-fold.lua index c7013bb..27cb5e5 100644 --- a/.config/nvim/plugin/50-fold.lua +++ b/.config/nvim/plugin/50-fold.lua @@ -7,16 +7,21 @@ -- Without foldmethod set to manual folds are created while writing in insert mode which is annoying -- -- Skip floating windows, because they often are documentation (and thus should be visible by default) +local function init_folds() + if vim.api.nvim_win_get_config(0).relative ~= "" or vim.treesitter.get_parser(0) == nil then + return + end + vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()" + vim.opt_local.foldmethod = "expr" + vim.cmd.normal({ "zX", bang = true }) + vim.opt_local.foldmethod = "manual" +end + +-- Initial fold setup vim.api.nvim_create_autocmd("FileType", { desc = "Initialize folds", group = vim.g.dotfiles.augroup, - callback = function(ev) - if vim.api.nvim_win_get_config(0).relative ~= "" or vim.treesitter.get_parser(0) == nil then - return - end - vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()" - vim.opt_local.foldmethod = "expr" - vim.cmd.normal({ "zX", bang = true }) - vim.opt_local.foldmethod = "manual" - end, + callback = init_folds, }) + +vim.api.nvim_create_user_command("FoldInit", init_folds, { desc = "(Re)initialize folds" }) |
