mirror of
https://github.com/cap153/nvim.git
synced 2026-05-01 10:55:49 +08:00
添加折叠插件
This commit is contained in:
parent
3b19a9c8a8
commit
ba406e9e0e
5 changed files with 113 additions and 19 deletions
|
|
@ -2,27 +2,48 @@
|
|||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "noice.nvim",
|
||||
module = "noice",
|
||||
deps = { "nui.nvim" },
|
||||
name = "noice.nvim",
|
||||
module = "noice",
|
||||
deps = { "nui.nvim" },
|
||||
}
|
||||
|
||||
-- 复刻 "VeryLazy" 策略
|
||||
vim.api.nvim_create_autocmd("UIEnter", {
|
||||
callback = function()
|
||||
-- vim.schedule 的作用是:别卡住界面的渲染,等 UI 画完了、闲下来了,再偷偷加载
|
||||
vim.schedule(function()
|
||||
PackUtils.load(P, function(plugin)
|
||||
plugin.setup({
|
||||
presets = {
|
||||
bottom_search = true, -- use a classic bottom cmdline for search
|
||||
command_palette = true, -- position the cmdline and popupmenu together
|
||||
long_message_to_split = true, -- long messages will be sent to a split
|
||||
inc_rename = false, -- enables an input dialog for inc-rename.nvim
|
||||
lsp_doc_border = false, -- add a border to hover docs and signature help
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end
|
||||
callback = function()
|
||||
-- vim.schedule 的作用是:别卡住界面的渲染,等 UI 画完了、闲下来了,再偷偷加载
|
||||
vim.schedule(function()
|
||||
PackUtils.load(P, function(plugin)
|
||||
plugin.setup({
|
||||
presets = {
|
||||
bottom_search = true, -- use a classic bottom cmdline for search
|
||||
command_palette = true, -- position the cmdline and popupmenu together
|
||||
long_message_to_split = true, -- long messages will be sent to a split
|
||||
inc_rename = false, -- enables an input dialog for inc-rename.nvim
|
||||
lsp_doc_border = false, -- add a border to hover docs and signature help
|
||||
},
|
||||
-- 需要过滤的信息
|
||||
routes = {
|
||||
{
|
||||
-- 过滤翻译插件的成功提示
|
||||
filter = {
|
||||
event = "msg_show",
|
||||
find = "Translate success",
|
||||
},
|
||||
-- opts.skip = true 会告诉 Noice 完全忽略这条消息
|
||||
opts = { skip = true },
|
||||
},
|
||||
{
|
||||
-- 过滤打开rust文件不影响使用的错误提示
|
||||
filter = {
|
||||
event = "msg_show",
|
||||
kind = "emsg",
|
||||
find = "Error in decoration provider",
|
||||
},
|
||||
opts = { skip = true },
|
||||
},
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end
|
||||
})
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ local function load_plugin()
|
|||
},
|
||||
})
|
||||
end)
|
||||
-- 提前触发 BufReadPost 的事件钩子,让 LSP 悄悄在后台 require 完毕
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_exec_autocmds("BufReadPost", { modeline = false })
|
||||
end)
|
||||
end
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<c-t>", function()
|
||||
|
|
|
|||
48
lua/pack/configs/ufo.lua
Normal file
48
lua/pack/configs/ufo.lua
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
-- === 折叠插件 ===
|
||||
if vim.g.vscode then return end
|
||||
|
||||
-- ufo关于折叠的设置
|
||||
vim.o.foldcolumn = "0" -- '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
|
||||
|
||||
local P = {
|
||||
name = "nvim-ufo", -- 仓库名
|
||||
module = "ufo", -- require模块名
|
||||
deps = { "promise-async" },
|
||||
}
|
||||
|
||||
-- 懒加载触发器
|
||||
vim.api.nvim_create_autocmd({
|
||||
"UIEnter", -- vim.schedule(function()
|
||||
}, {
|
||||
callback = function()
|
||||
vim.schedule(function()
|
||||
PackUtils.load(P, function(plugin)
|
||||
-- Option 2: nvim lsp as LSP client
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.foldingRange = {
|
||||
dynamicRegistration = false,
|
||||
lineFoldingOnly = true,
|
||||
}
|
||||
local language_servers = vim.lsp.get_clients() -- or list servers manually like {'gopls', 'clangd'}
|
||||
for _, ls in ipairs(language_servers) do
|
||||
require("lspconfig")[ls].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end
|
||||
plugin.setup({})
|
||||
-- Option 3: treesitter as a main provider instead
|
||||
-- plugin.setup({
|
||||
-- provider_selector = function()
|
||||
-- return { "treesitter", "indent" }
|
||||
-- end
|
||||
-- })
|
||||
-- 键盘映射,这里的按键会打开或折叠全部的可折叠位置
|
||||
vim.keymap.set("n", "zr", require("ufo").openAllFolds)
|
||||
vim.keymap.set("n", "zm", require("ufo").closeAllFolds)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
})
|
||||
|
|
@ -18,6 +18,9 @@ local specs = {
|
|||
'https://github.com/nvim-treesitter/nvim-treesitter',
|
||||
-- indentblankline.lua 彩虹缩进
|
||||
"https://github.com/lukas-reineke/indent-blankline.nvim",
|
||||
-- ufo.lua 折叠插件
|
||||
"https://github.com/kevinhwang91/nvim-ufo",
|
||||
"https://github.com/kevinhwang91/promise-async",
|
||||
-- conform.lua 格式化工具formatter
|
||||
"https://github.com/stevearc/conform.nvim",
|
||||
-- kommentary.lua 注释插件
|
||||
|
|
@ -156,6 +159,7 @@ end
|
|||
|
||||
-- [动态路径] 获取插件根目录
|
||||
function PackUtils.get_root(name)
|
||||
name = PackUtils.get_name(name)
|
||||
local paths = vim.api.nvim_get_runtime_file("pack/*/*/" .. name, true)
|
||||
if #paths > 0 then return paths[1] end
|
||||
local glob = vim.fn.globpath(vim.o.packpath, "pack/*/*/" .. name, 0, 1)
|
||||
|
|
@ -164,6 +168,7 @@ end
|
|||
|
||||
-- [构建执行] 执行编译任务
|
||||
function PackUtils.run_build(name, build_cmd)
|
||||
name = PackUtils.get_name(name)
|
||||
if PackUtils.disabled_plugins[name] then return end
|
||||
if not build_cmd or PackUtils.is_building[name] then return end
|
||||
local path = PackUtils.get_root(name)
|
||||
|
|
@ -227,6 +232,7 @@ end
|
|||
|
||||
-- [监听器] 注册安装/更新监听
|
||||
function PackUtils.setup_listener(name, build_cmd)
|
||||
name = PackUtils.get_name(name)
|
||||
if PackUtils.disabled_plugins[name] then return end
|
||||
if not build_cmd then return end
|
||||
vim.api.nvim_create_autocmd('PackChanged', {
|
||||
|
|
@ -243,6 +249,7 @@ end
|
|||
|
||||
-- [健康检查] 如果没标记且有构建命令,则触发构建
|
||||
function PackUtils.check_health(name, build_cmd)
|
||||
name = PackUtils.get_name(name)
|
||||
if PackUtils.disabled_plugins[name] then return end
|
||||
if not build_cmd then return end
|
||||
local path = PackUtils.get_root(name)
|
||||
|
|
@ -256,6 +263,12 @@ end
|
|||
|
||||
-- 全方位防崩加载引擎
|
||||
function PackUtils.load(P, config_fn)
|
||||
P.name = PackUtils.get_name(P.name)
|
||||
if P.deps then
|
||||
for i, dep in ipairs(P.deps) do
|
||||
P.deps[i] = PackUtils.get_name(dep)
|
||||
end
|
||||
end
|
||||
if PackUtils.disabled_plugins[P.name] then return end
|
||||
if PackUtils.is_initialized[P.name] then return end
|
||||
PackUtils.check_health(P.name, P.build_cmd)
|
||||
|
|
|
|||
|
|
@ -60,6 +60,10 @@
|
|||
"rev": "4916d6592ede8c07973490d9322f187e07dfefac",
|
||||
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
|
||||
},
|
||||
"nvim-ufo": {
|
||||
"rev": "ab3eb124062422d276fae49e0dd63b3ad1062cfc",
|
||||
"src": "https://github.com/kevinhwang91/nvim-ufo"
|
||||
},
|
||||
"nvim-web-devicons": {
|
||||
"rev": "6e76c5e47e957fbf080b1fdac165c66dbd2e7cfb",
|
||||
"src": "https://github.com/nvim-tree/nvim-web-devicons"
|
||||
|
|
@ -72,6 +76,10 @@
|
|||
"rev": "b9fd5226c2f76c951fc8ed5923d85e4de065e509",
|
||||
"src": "https://github.com/nvim-lua/plenary.nvim"
|
||||
},
|
||||
"promise-async": {
|
||||
"rev": "119e8961014c9bfaf1487bf3c2a393d254f337e2",
|
||||
"src": "https://github.com/kevinhwang91/promise-async"
|
||||
},
|
||||
"snacks.nvim": {
|
||||
"rev": "ad9ede6a9cddf16cedbd31b8932d6dcdee9b716e",
|
||||
"src": "https://github.com/folke/snacks.nvim"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue