forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvim-ufo.lua
More file actions
110 lines (109 loc) · 2.66 KB
/
nvim-ufo.lua
File metadata and controls
110 lines (109 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
local handler = function(virtText, lnum, endLnum, width, truncate)
local newVirtText = {}
local totalLines = vim.api.nvim_buf_line_count(0)
local foldedLines = endLnum - lnum
local suffix = (" %d %d%%"):format(foldedLines, foldedLines / totalLines * 100)
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)
-- str width returned from truncate() may less than 2nd argument, need padding
if curWidth + chunkWidth < targetWidth then
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
end
break
end
curWidth = curWidth + chunkWidth
end
local rAlignAppndx = math.max(math.min(0, width - 1) - curWidth - sufWidth, 0)
suffix = (" "):rep(rAlignAppndx) .. suffix
table.insert(newVirtText, { suffix, "MoreMsg" })
return newVirtText
end
return {
{
"kevinhwang91/nvim-ufo",
event = { 'BufReadPost', 'BufNewFile' },
dependencies = {
"kevinhwang91/promise-async",
"nvim-treesitter/nvim-treesitter",
"neovim/nvim-lspconfig",
{
"luukvbaal/statuscol.nvim",
lazy = false,
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,
},
},
keys = {
{ "zc" },
{ "zo" },
{ "zC" },
{ "zO" },
{ "za" },
{ "zA" },
{
"zr",
function()
require("ufo").openFoldsExceptKinds()
end,
desc = "Open Folds Except Kinds",
},
{
"zR",
function()
require("ufo").openAllFolds()
end,
desc = "Open All Folds",
},
{
"zM",
function()
require("ufo").closeAllFolds()
end,
desc = "Close All Folds",
},
{
"zm",
function()
require("ufo").closeFoldsWith()
end,
desc = "Close Folds With",
},
{
"zp",
function()
local winid = require("ufo").peekFoldedLinesUnderCursor()
if not winid then
vim.lsp.buf.hover()
end
end,
desc = "Peek Fold",
},
},
opts = {
fold_virt_text_handler = handler,
},
config = function(_, opts)
require("ufo").setup(opts)
end,
},
}