Closed foil-hat-guy closed 1 year ago
Do you mean require('ufo').closeAllFolds()
doesn't work for you ? Maybe some issues with your config, please use a minimal config. foldlevel
and foldlevelstart
are both set to a large value like 99
may help.
I made a demo of this issue. Should I open a new one? There are different discussions elsewhere on that.
https://user-images.githubusercontent.com/8136158/216767149-e59ee6f7-ba17-4d00-9af7-4ede6c24d251.mp4
insert
-ing and then hitting the <ESC>
(escape) closes folds back.lua
, sh
, cmake
, c/c++
).foldopen
option.nvim --clean
modezx
zM
(z shift+m
)NVIM v0.9.0-dev-d3355ad
Build type: MinSizeRel
LuaJIT 2.1.0-beta3
~/.config/nvim/lua/options.lua
...
local opt = vim.opt
opt.foldopen:append("insert")
opt.foldmethod="expr"
opt.foldlevel=1
opt.foldlevelstart=99 -- 0 to close all folds upon opening file
opt.foldminlines=4
opt.foldcolumn="auto"
opt.foldenable=true
set foldlevel?
say what, maybe it was changed by another script.
foldlevel
is default for me. In my setup the only plugin that affects folding currently is the nvim-treesitter
. I've disbled nvim-ufo
because of this quirk.
This happens to me as well. It has something to do with the zM
command specifically. Because if I go to foldlevel
0 by using zm
instead, the BufWritePost
and InsertLeave
autocommands do not cause all folds to be closed.
Whenever I use zM
, (the builtin zM
, not ufo.closeAllFolds
), once I leave insert mode or save the buffer, the corresponding autocommand from mentioned above trigger all folds to be closed.
If I use the zm
command and then run zx
or zX
, the autocommand will trigger all folds to be closed as well.
Thank you! I just fixed it by remapping zM to ufo.closeAllFolds
.
Dear kevinhwang91 and nvim-ufo users,
In the issue list there are several issues about unwanted behavior of zR and zM commands: unwanted automatic folding/unfolding triggered by insert mode exit. See issues #7, #49, #57 and #62. I have the same problem and none of solutions at metioned issues works for me. So I made my own one. I made another implementation of zM command "closeAllFolds" on top of zC command witch is not causing unwanted behaviour.
New implementation of "closeAllFolds" command.
Press F9 key and the following script will walk the buffer top to bottom and invoke zC command at each line:
Result
All parts of code are folded. Exiting from insert mode not triggering any automatic folding/unfolding, everything stays the same as before insert mode entrance.
I hope it will be useful for people with the same issue.
System setup
Operating system: Linux Debian 11. Neovim version: v0.7.2 nvim-ufo version(commit): ad4ecb6 LSP server: gopls LSP client: nvim LSP (option 2 from minimal config) nvim-ufo config: