dotfiles/mzte-nv/conf/lua/pluginconf/nvim_ufo.lua

44 lines
1.2 KiB
Lua
Raw Normal View History

2022-10-24 22:52:58 +02:00
local ufo = require "ufo"
local ts_parsers = require "nvim-treesitter.parsers"
local map = vim.api.nvim_set_keymap
2022-11-03 21:39:27 +01:00
local function has_lsp_folds(bufnr)
local clients = vim.lsp.get_active_clients { bufnr = bufnr }
for _, client in ipairs(clients) do
if client.server_capabilities.foldingRangeProvider then
return true
end
end
return false
end
2022-10-24 22:52:58 +02:00
ufo.setup {
open_fold_hl_timeout = 0, -- disable blinky thingy when opening fold
2022-11-03 21:39:27 +01:00
provider_selector = function(bufnr, ft, _)
if has_lsp_folds(bufnr) then
2022-10-24 22:52:58 +02:00
return { "lsp", "indent" }
2022-11-03 21:39:27 +01:00
elseif ts_parsers.has_parser(ft) then
return { "treesitter", "indent" }
else
return { "indent" }
2022-10-24 22:52:58 +02:00
end
end,
}
-- https://github.com/neovim/neovim/pull/17446
2022-10-24 23:50:40 +02:00
--vim.o.foldcolumn = "1"
--vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
vim.o.foldcolumn = "0"
2022-10-24 22:52:58 +02:00
vim.o.foldlevel = 256
vim.o.foldlevelstart = 256
vim.o.foldenable = true
local map_opts = {
noremap = true,
silent = true,
}
map("n", "t", "za", map_opts) -- toggle fold
map("n", "zO", [[<cmd>lua require("ufo").openAllFolds()<CR>]], map_opts)
map("n", "zC", [[<cmd>lua require("ufo").closeAllFolds()<CR>]], map_opts)