neovim-config/lua/plugins/folding.lua

64 lines
2.1 KiB
Lua

return {
-- add folding range to capabilities
{
"neovim/nvim-lspconfig",
opts = {
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
},
},
},
},
-- add nvim-ufo
{
"kevinhwang91/nvim-ufo",
dependencies = {
"kevinhwang91/promise-async",
-- This looks awful, so leaving it disabled
-- {
-- "luukvbaal/statuscol.nvim",
-- config = function()
-- local builtin = require("statuscol.builtin")
-- require("statuscol").setup({
-- relculright = true,
-- segments = {
-- { text = { builtin.foldfunc }, click = "v:lua.ScFa" },
-- { text = { "%s" }, click = "v:lua.ScSa" },
-- { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
-- },
-- })
-- end,
-- },
},
event = "BufReadPost",
opts = {
provider_selector = function()
return { "treesitter", "indent" }
end,
},
init = function()
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 = 99
vim.o.foldenable = true
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
-- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself
vim.keymap.set("n", "zR", function()
require("ufo").openAllFolds()
end)
vim.keymap.set("n", "zM", function()
require("ufo").closeAllFolds()
end)
end,
},
-- Folding preview, by default h and l keys are used.
-- On first press of h key, when cursor is on a closed fold, the preview will be shown.
-- On second press the preview will be closed and fold will be opened.
-- When preview is opened, the l key will close it and open fold. In all other cases these keys will work as usual.
{ "anuvyklack/fold-preview.nvim", dependencies = "anuvyklack/keymap-amend.nvim", config = true },
}