diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-13 00:27:05 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-13 00:39:30 +0200 |
| commit | 036db1dd17978719d31179550622339afde76c60 (patch) | |
| tree | 3b23311c64ad3ac53260e979dd5a6256ad90f2a3 /.config | |
| parent | 2b065376b0f43010ebd64f49552ab96377504079 (diff) | |
| download | dotfiles-036db1dd17978719d31179550622339afde76c60.tar.gz dotfiles-036db1dd17978719d31179550622339afde76c60.zip | |
fix(nvim): rewrite fold plugin and fix text folding while editing
Diffstat (limited to '.config')
| -rw-r--r-- | .config/nvim/init.lua | 1 | ||||
| -rw-r--r-- | .config/nvim/plugin/50-fold.lua | 23 | ||||
| -rw-r--r-- | .config/nvim/plugin/50-session.lua | 2 |
3 files changed, 13 insertions, 13 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 8073993..0f9d07f 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -229,7 +229,6 @@ end) ------------------------------------------------------------------------------------------------------------------------ vim.opt.shell = "/usr/bin/bash" -vim.opt.foldenable = true -- Folds are closed by default vim.opt.pumheight = 16 -- Popup menu height to 16 lines vim.opt.confirm = true -- Confirm before losing buffer unsaved changes vim.opt.splitbelow = false diff --git a/.config/nvim/plugin/50-fold.lua b/.config/nvim/plugin/50-fold.lua index 27cb5e5..f887614 100644 --- a/.config/nvim/plugin/50-fold.lua +++ b/.config/nvim/plugin/50-fold.lua @@ -1,27 +1,26 @@ -- --- fold plugin +-- 50-fold.lua -- - --- Initialize folds with foldmethod = expr if a treesitter parser is available, then switch back to manual --- This is to have the folds calculated and closed when editing the file initially, but with foldmethod set to manual --- Without foldmethod set to manual folds are created while writing in insert mode which is annoying +-- * Creates an autocommand to fold with treesitter automatically and close all folds on 'FileType'. +-- * Sets 'foldlevel' to 99 so that new text will not fold while editing. -- --- Skip floating windows, because they often are documentation (and thus should be visible by default) -local function init_folds() + +local function fold_with_treesitter() 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" + vim.cmd("silent! %foldclose!") end --- Initial fold setup +---------------------------------------------------------------------------------------------------- + vim.api.nvim_create_autocmd("FileType", { desc = "Initialize folds", group = vim.g.dotfiles.augroup, - callback = init_folds, + callback = fold_with_treesitter, }) -vim.api.nvim_create_user_command("FoldInit", init_folds, { desc = "(Re)initialize folds" }) +vim.opt.foldenable = true +vim.opt.foldlevel = 99 diff --git a/.config/nvim/plugin/50-session.lua b/.config/nvim/plugin/50-session.lua index a297504..7b0061b 100644 --- a/.config/nvim/plugin/50-session.lua +++ b/.config/nvim/plugin/50-session.lua @@ -2,6 +2,8 @@ -- Session plugin -- +vim.opt.sessionoptions:remove("folds") + local session_dir = vim.fn.stdpath("state") .. "/sessions" local session_default = session_dir .. "/default.vim" if not vim.uv.fs_stat(session_dir) then |
