kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.26k stars 47 forks source link

Folds opened by `za` or `zo` close recursively when leaving insertmode #18

Closed ranjithshegde closed 2 years ago

ranjithshegde commented 2 years ago

Neovim version (nvim -v | head -n1)

NVIM v0.8.0-dev+452-gb2ed439bd5

Operating system/version

Linux 5.18.5-arch1-1 #1 SMP PREEMPT_DYNAMIC (arch linux)

How to reproduce the issue

local function level1()
    local function level2()
        |
    end
end
  1. Place cursor on line 2 local function level2()
  2. Press either za (toggle fold under cursor) or zo (open fold under cursor)
  3. Do edits in insert mode and hit <esc> to go to normal mode ...

Expected behavior

local function level1()
    local function level2()
        -- whatever edits I made
    end
end

Folds under the cursor that are opened manually with za or zo remain open (so that i can inspect what I just changed, or any other purpose)

Actual behavior

all folds have been closed

local function level1() -- folds here
end
xiyaowong commented 2 years ago

this is nvim's expected behavior. :h foldlevel foldlevelstart

ranjithshegde commented 2 years ago

I am not sure that it’s updated this way when you exit insert mode. As I don’t have this issue when I use built in indent or treesitter as my fold method

xiyaowong commented 2 years ago

I may have made a mistake in my understanding. Wait for someone with more experience to explain

kevinhwang91 commented 2 years ago

You should increase the foldlevel and trace the value after you go back normal mode verb set foldlevel

ranjithshegde commented 2 years ago

Sorry for my ignorance, but how do I do that? shouldnt za or zo do that automatically?

kevinhwang91 commented 2 years ago

set foldlevel=99 foldlevelstart=-1

ranjithshegde commented 2 years ago

set foldlevel=99 foldlevelstart=-1

This fixes the collapse problem but all folds are always open until I manually close them, even at BufEnter also require("ufo").closeAllFolds() has no affect until I first manually close all folds - was my mistake

xiyaowong commented 2 years ago

You can create some autocmds to implement your requirements, but these are not related to this plugin

kevinhwang91 commented 2 years ago

set foldlevel=99 foldlevelstart=-1

This fixes the collapse problem but all folds are always open until I manually close them, even at BufEnter also require("ufo").closeAllFolds() has no affect until I first manually close all folds

Create folds is async, your event can't work is expected. I think you should write the function yourself. It's not the normal workflow, sorry.

ranjithshegde commented 2 years ago

Create folds is async, your event can't work is expected. I think you should write the function yourself. It's not the normal workflow, sorry.

I understand that this might not be the plugin focus, but using za or zo which is basically opening a specifc fold (also what you do in your intro video, just with mouse) is a very common workflow.

But I fully appreciate if you dont want to support this. I will give it a shot.

thanks for the plugin and the excellent work!

kevinhwang91 commented 2 years ago

Create folds is async, your event can't work is expected. I think you should write the function yourself. It's not the normal workflow, sorry.

I understand that this might not be the plugin focus, but using za or zo which is basically opening a specifc fold (also what you do in your intro video, just with mouse) is a very common workflow.

But I fully appreciate if you dont want to support this. I will give it a shot.

thanks for the plugin and the excellent work!

Every time update folding, vim respect the fold level. I suggest you set the value as large enough, otherwise, it's buggy for ufo while you are editing buffer because the level may change a lot.

ranjithshegde commented 2 years ago

Every time update folding, vim respect the fold level. I suggest you set the value as large enough, otherwise, it's buggy for ufo while you are editing buffer because the level may change a lot.

Are you referring to foldlevelstart?

kevinhwang91 commented 2 years ago

No, foldlevel, you should RTFM before customizing or hacking any plugins.