mirror of
https://github.com/tomru/vim.git
synced 2026-03-03 06:27:18 +01:00
add nvim-ufo for improved folding
This commit is contained in:
61
lua/custom/plugins/folding.lua
Normal file
61
lua/custom/plugins/folding.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
-- local foldIcon = ''
|
||||
-- local hlgroup = 'NonText'
|
||||
-- local function foldTextFormatter(virtText, lnum, endLnum, width, truncate)
|
||||
-- local newVirtText = {}
|
||||
-- local suffix = ' ' .. foldIcon .. ' ' .. tostring(endLnum - lnum)
|
||||
-- local sufWidth = vim.fn.strdisplaywidth(suffix)
|
||||
-- local targetWidth = width - sufWidth
|
||||
-- local curWidth = 0
|
||||
-- for _, chunk in ipairs(virtText) do
|
||||
-- local chunkText = chunk[1]
|
||||
-- local chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||
-- if targetWidth > curWidth + chunkWidth then
|
||||
-- table.insert(newVirtText, chunk)
|
||||
-- else
|
||||
-- chunkText = truncate(chunkText, targetWidth - curWidth)
|
||||
-- local hlGroup = chunk[2]
|
||||
-- table.insert(newVirtText, { chunkText, hlGroup })
|
||||
-- chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||
-- if curWidth + chunkWidth < targetWidth then
|
||||
-- suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth)
|
||||
-- end
|
||||
-- break
|
||||
-- end
|
||||
-- curWidth = curWidth + chunkWidth
|
||||
-- end
|
||||
-- table.insert(newVirtText, { suffix, hlgroup })
|
||||
-- return newVirtText
|
||||
-- end
|
||||
|
||||
return {
|
||||
'kevinhwang91/nvim-ufo',
|
||||
dependencies = 'kevinhwang91/promise-async',
|
||||
event = 'BufReadPost',
|
||||
init = function()
|
||||
-- INFO fold commands usually change the foldlevel, which fixes folds, e.g.
|
||||
-- auto-closing them after leaving insert mode, however ufo does not seem to
|
||||
-- have equivalents for zr and zm because there is no saved fold level.
|
||||
-- Consequently, the vim-internal fold levels need to be disabled by setting
|
||||
-- them to 99
|
||||
vim.opt.foldlevel = 99
|
||||
vim.opt.foldlevelstart = 99
|
||||
vim.opt.foldcolumn = 'auto'
|
||||
end,
|
||||
opts = {
|
||||
provider_selector = function(_, ft, _)
|
||||
local lspWithOutFolding = { 'markdown' }
|
||||
if vim.tbl_contains(lspWithOutFolding, ft) then
|
||||
return { 'treesitter', 'indent' }
|
||||
elseif ft == 'html' then
|
||||
return { 'indent' } -- lsp & treesitter do not provide folds
|
||||
else
|
||||
return { 'lsp', 'indent' }
|
||||
end
|
||||
end,
|
||||
-- open opening the buffer, close these fold kinds
|
||||
-- use `:UfoInspect` to get available fold kinds from the LSP
|
||||
close_fold_kinds = { 'imports' },
|
||||
open_fold_hl_timeout = 500,
|
||||
-- fold_virt_text_handler = foldTextFormatter,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user