diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 6652b22..e628756 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -221,7 +221,11 @@ if !has('nvim') setlocal foldmethod=expr setlocal foldexpr=nuwiki#folding#expr() setlocal foldtext=nuwiki#folding#foldtext() - let b:undo_ftplugin .= ' | setlocal foldmethod< foldexpr< foldtext<' + " Start with every heading-block fold open; the user can still close + " them with `zc` and that state survives because `foldlevel` only + " controls the initial state, not subsequent manual fold operations. + setlocal foldlevel=99 + let b:undo_ftplugin .= ' | setlocal foldmethod< foldexpr< foldtext< foldlevel<' endif " Text objects — vimwiki parity (matches lua/nuwiki/textobjects.lua). diff --git a/lua/nuwiki/ftplugin.lua b/lua/nuwiki/ftplugin.lua index 26d117a..f729560 100644 --- a/lua/nuwiki/ftplugin.lua +++ b/lua/nuwiki/ftplugin.lua @@ -35,6 +35,10 @@ local function setup_folding(bufnr, folding_mode) -- ftplugin). Also re-apply on any future split that views this -- buffer, so `v` / `:split` preserves the fold method. apply() + -- Start with every heading-block fold open. `foldlevel` is window-local + -- but only sets the initial state; once the user closes folds with `zc` + -- those stay closed, so we don't re-apply this on BufWinEnter. + vim.opt_local.foldlevel = 99 vim.api.nvim_create_autocmd('BufWinEnter', { buffer = bufnr, group = vim.api.nvim_create_augroup('nuwiki_folding_' .. bufnr, { clear = true }), diff --git a/scripts/test-keymaps-vim.vim b/scripts/test-keymaps-vim.vim index 328f6bd..5b7c401 100644 --- a/scripts/test-keymaps-vim.vim +++ b/scripts/test-keymaps-vim.vim @@ -300,6 +300,12 @@ call s:record( \ foldlevel(2) > 0 ? 1 : 0, \ 'folding.body_inherits_fold', \ 'foldlevel(2)=' . foldlevel(2)) +" ftplugin sets `foldlevel=99` so every heading-block fold starts open +" rather than collapsed on file open. +call s:record( + \ &l:foldlevel == 99 ? 1 : 0, + \ 'folding.starts_with_all_folds_open', + \ '&l:foldlevel=' . &l:foldlevel) " ===== Wrap up =====