#28692·neovim

`E490: no fold found` with tree-sitter

Author: adrian5Created May 10, 2024Updated Sep 30, 2026
Labelstreesitterfolds

Problem

Tree-sitter computed folds don't work on files opened through commands. This breaks session restore functionality.

Related:

Steps to reproduce

minimal.lua:

lua
for name, url in pairs {
  ts = "https://github.com/nvim-treesitter/nvim-treesitter/",
} do
  local install_path = vim.fn.fnamemodify('nvim_issue/' .. name, ':p')
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.opt.runtimepath:append(install_path)
end

require("nvim-treesitter.configs").setup({
  ensure_installed = { "c" }
})

vim.opt.foldmethod = "expr"
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.opt.foldlevelstart = 99

vim.cmd("e hello-world.c")
vim.cmd("setf c")

helloworld.c:

c
#include <stdio.h>

int main() {
    printf("Hello, world!");
    return 0;
}

Steps:

  • nvim --clean -u minimal.lua
  • Press za on foldable section
  • message: E490: no fold found

Entering insert mode or pressing zx seems to restore fold functionality. Not working without these actions breaks a complete session restore.

Expected behavior

Folds should always work, including those restored via sessions.

Neovim version (nvim -v)

NVIM v0.10.0-dev-3103+gca735c755

Vim (not Nvim) behaves the same?

not applicable

Operating system/version

Arch Linux x86_64

Terminal name/version

Alacritty 0.13.2-2

$TERM environment variable

alacritty

Installation

GitHub nightly tarball