nvim-ufo icon indicating copy to clipboard operation
nvim-ufo copied to clipboard

are fold status get saved?

Open luxus opened this issue 3 years ago • 4 comments

Neovim version (nvim -v | head -n1)

0.9

Operating system/version

macOS

How to reproduce the issue

      vim.o.foldcolumn = "1" -- '0' is not bad
      vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
      vim.o.foldlevelstart = -1
      vim.o.foldenable = true
      vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]

when i open a file, fold some lines, closing the file and reopen it (or a :e) i thought the folds stays closed.

Expected behavior

after saving a file and reloading still have the same fold and unfold state

Actual behavior

everything is unfolded again

luxus avatar Feb 19 '23 18:02 luxus

okay i learned that mkview and loadview needs to be used. https://github.com/neovim/neovim/blob/bfe6b49447744cea1cd941660b2a3a501a0701cb/runtime/doc/fold.txt#L42-L43 is this the best way?

-- remember folds
vim.cmd [[
augroup remember_folds
  autocmd!
  autocmd BufWinLeave *.* mkview
  autocmd BufWinEnter *.* silent! loadview
augroup END
]]

luxus avatar Feb 19 '23 18:02 luxus

No bad, some save session plugins also solve this issue.

kevinhwang91 avatar Feb 20 '23 05:02 kevinhwang91

In some cases, the snippet above would change the cwd when you enter a buffer, and the following command can solve this problem:

vim.cmd [[set viewoptions-=curdir]]

yizhenAllen avatar Aug 26 '23 10:08 yizhenAllen

mkview and loadview are fired by events frequently, which read and write the file IO. Should add this feature in ufo.

kevinhwang91 avatar Nov 11 '24 08:11 kevinhwang91