kevinhwang91 / nvim-ufo

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

are fold status get saved? #115

Closed luxus closed 1 year ago

luxus commented 1 year ago

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 commented 1 year ago

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
]]
kevinhwang91 commented 1 year ago

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

yizhenAllen commented 10 months ago

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]]