diff options
Diffstat (limited to '.config/nvim/lua/plugins/nvim-ufo.lua')
-rw-r--r-- | .config/nvim/lua/plugins/nvim-ufo.lua | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/nvim-ufo.lua b/.config/nvim/lua/plugins/nvim-ufo.lua new file mode 100644 index 0000000..a3d69ba --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-ufo.lua | |||
@@ -0,0 +1,78 @@ | |||
1 | return { | ||
2 | { | ||
3 | "kevinhwang91/nvim-ufo", | ||
4 | event = "BufEnter", | ||
5 | keys = { | ||
6 | { | ||
7 | "zR", | ||
8 | function() | ||
9 | require("ufo").openAllFolds() | ||
10 | end, | ||
11 | desc = "ufo: open all folds", | ||
12 | }, | ||
13 | { | ||
14 | "zM", | ||
15 | function() | ||
16 | require("ufo").closeAllFolds() | ||
17 | end, | ||
18 | desc = "ufo: close all folds", | ||
19 | }, | ||
20 | { | ||
21 | "zr", | ||
22 | function() | ||
23 | require("ufo").openFoldsExceptKinds() | ||
24 | end, | ||
25 | desc = "ufo: open folds except kinds", | ||
26 | }, | ||
27 | { | ||
28 | "zm", | ||
29 | function() | ||
30 | require("ufo").closeFoldsWith() | ||
31 | end, | ||
32 | desc = "ufo: close folds with" | ||
33 | }, | ||
34 | { | ||
35 | "zp", | ||
36 | function() | ||
37 | require("ufo").peekFoldedLinesUnderCursor() | ||
38 | end, | ||
39 | desc = "ufo: peek fold" | ||
40 | }, | ||
41 | }, | ||
42 | dependencies = { | ||
43 | "kevinhwang91/promise-async", | ||
44 | }, | ||
45 | opts = { | ||
46 | preview = { | ||
47 | mappings = { | ||
48 | scrollB = "<C-b>", | ||
49 | scrollF = "<C-f>", | ||
50 | scrollU = "<C-u>", | ||
51 | scrollD = "<C-d>", | ||
52 | }, | ||
53 | }, | ||
54 | provider_selector = function(_, filetype, buftype) | ||
55 | local function handleFallbackException(bufnr, err, providerName) | ||
56 | if type(err) == "string" and err:match("UfoFallbackException") then | ||
57 | return require("ufo").getFolds(bufnr, providerName) | ||
58 | else | ||
59 | return require("promise").reject(err) | ||
60 | end | ||
61 | end | ||
62 | |||
63 | return (filetype == "" or buftype == "nofile") and | ||
64 | "indent" -- only use indent until a file is opened | ||
65 | or function(bufnr) | ||
66 | return require("ufo") | ||
67 | .getFolds(bufnr, "lsp") | ||
68 | :catch(function(err) | ||
69 | return handleFallbackException(bufnr, err, "treesitter") | ||
70 | end) | ||
71 | :catch(function(err) | ||
72 | return handleFallbackException(bufnr, err, "indent") | ||
73 | end) | ||
74 | end | ||
75 | end, | ||
76 | }, | ||
77 | } | ||
78 | } | ||