summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-05-29 16:08:15 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-05-29 16:08:15 +0200
commit4c8b0576c6984cbc83006fbd0c78064f4895bc60 (patch)
treeccf71a30b1d223a24fa636752d7b3fc9e5304c0e /plugin
parentfdb83989036516c1c23e45e86f0e2a6ea6dffa78 (diff)
downloadnvim-config-4c8b0576c6984cbc83006fbd0c78064f4895bc60.tar.gz
nvim-config-4c8b0576c6984cbc83006fbd0c78064f4895bc60.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 'plugin')
-rw-r--r--plugin/50-fold.lua23
1 files changed, 14 insertions, 9 deletions
diff --git a/plugin/50-fold.lua b/plugin/50-fold.lua
index c7013bb..27cb5e5 100644
--- a/plugin/50-fold.lua
+++ b/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" })