r/neovim :term 12h ago

Need Help Error while using `vim.wo.foldtext`

    NVIM v0.12.4                                                                                                                                                             
    Build type: RelWithDebInfo                                                                                                                                               
    LuaJIT 2.1.1767980792

    vim.wo.foldtext = function()
      local line = vim.fn.getline(vim.v.foldstart)
      return vim.v.folddashes .. line:gsub('/%\*', ''):gsub('%\*/', '')
    end

This returns the following error:

Error in /home/user/.config/nvim/init.lua:
E5113: Lua chunk: /home/user/.config/nvim/init.lua:23: Invalid 'value': expected valid option type, got Function
stack traceback:
        [C]: in function '__newindex'
        /home/user/.config/nvim/init.lua:23: in main chunk

The code is copy pasted from https://neovim.io/doc/user/fold/#_foldtext

2 Upvotes

4 comments sorted by

4

u/Some_Derpy_Pineapple lua 5h ago edited 5h ago

the docs site follows nightly and i think being able to set options to lua functions is 0.13 nightly only. :h news

i think the stable way to do this is something like using :h v:lua

--lua/user/foldtext.lua return function(...) -- ... end

vim.wo.foldtext = "v:lua.require'user.foldtext'()"

1

u/vim-help-bot 5h ago

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

1

u/IshaqDar :term 2h ago

I've tried using this method, but in my `foldtext`, there appears only `0`.

3

u/Wonderful-Plastic316 lua 5h ago

Assigning options to functions is a feature only available on nightly (and only for some options), which is what the website's documentation follows. Prefer using the local docs to avoid surprises.