blob: c7013bb22da741a499df94adb7e230814b24d54b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
--
-- fold plugin
--
-- Initialize folds with foldmethod = expr if a treesitter parser is available, then switch back to manual
-- This is to have the folds calculated and closed when editing the file initially, but with foldmethod set to manual
-- Without foldmethod set to manual folds are created while writing in insert mode which is annoying
--
-- Skip floating windows, because they often are documentation (and thus should be visible by default)
vim.api.nvim_create_autocmd("FileType", {
desc = "Initialize folds",
group = vim.g.dotfiles.augroup,
callback = function(ev)
if vim.api.nvim_win_get_config(0).relative ~= "" or vim.treesitter.get_parser(0) == nil then
return
end
vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.opt_local.foldmethod = "expr"
vim.cmd.normal({ "zX", bang = true })
vim.opt_local.foldmethod = "manual"
end,
})
|