添加对字符相关插件

This commit is contained in:
caprain 2026-04-13 16:33:11 +08:00
parent bbc8152ed9
commit 51ee1aebf5
18 changed files with 200 additions and 162 deletions

View file

@ -0,0 +1,22 @@
-- === 对字符自动补全另一半 ===
if vim.g.vscode then return end
local P = {
name = "nvim-autopairs", -- 仓库名
}
-- 懒加载触发器
vim.api.nvim_create_autocmd({
"InsertEnter", "CmdlineEnter", -- 补全/命令行
}, {
callback = function()
PackUtils.load(P, function()
require('nvim-autopairs').setup({
-- 在写markdown时禁用括号补全
disable_filetype = { "markdown" },
-- can use treesitter to check for a pair.
check_ts = true,
})
end)
end
})

View file

@ -3,7 +3,6 @@ if vim.g.vscode then return end
local P = {
name = "blink.cmp",
module = "blink.cmp",
deps = { "friendly-snippets" },
-- build_cmd = "cargo build --release",
}
@ -14,8 +13,8 @@ vim.api.nvim_create_autocmd({ "InsertEnter", "CmdlineEnter", "LspAttach" }, {
once = true,
callback = function()
-- 调用引擎的 load 方法,把 setup 逻辑作为匿名函数传进去
PackUtils.load(P, function(plugin)
plugin.setup({
PackUtils.load(P, function()
require("blink.cmp").setup({
fuzzy = {
prebuilt_binaries = {
force_version = 'v*',

View file

@ -9,7 +9,6 @@ if vim.g.vscode then return end
local P = {
name = "bufferline.nvim",
module = "bufferline",
deps = { "nvim-web-devicons" }, -- 确保图标库先加载
}
@ -17,7 +16,7 @@ local P = {
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
once = true,
callback = function()
PackUtils.load(P, function(plugin)
PackUtils.load(P, function()
-- 在缓冲区之间移动
map:cmd('tn', 'BufferLineCyclePrev')
map:cmd('ti', 'BufferLineCycleNext')
@ -30,7 +29,7 @@ vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
map:cmd('tN', 'BufferLineCloseLeft')
map:cmd('tI', 'BufferLineCloseRight')
map:cmd('tQ', 'BufferLineCloseOthers')
plugin.setup({
require("bufferline").setup({
options = {
modified_icon = "",
buffer_close_icon = "×",

View file

@ -1,53 +1,52 @@
if vim.g.vscode then return end
local P = {
name = "code_runner.nvim",
module = "code_runner",
deps = {},
name = "code_runner.nvim",
deps = {},
}
-- 定义映射配置表
local mappings = {
{ ft = { "rust", "python" }, cmd = "RunCode", desc = "Save and Run Code" },
{ ft = "markdown", cmd = "PeekClose;PeekOpen", desc = "Reload Markdown Preview" },
{ ft = "dart", cmd = "Telescope flutter commands", desc = "Open Flutter Commands" },
{ ft = "go", cmd = "set splitbelow;sp;term go run %", desc = "Run Go file" },
{ ft = { "rust", "python" }, cmd = "RunCode", desc = "Save and Run Code" },
{ ft = "markdown", cmd = "PeekClose;PeekOpen", desc = "Reload Markdown Preview" },
{ ft = "dart", cmd = "Telescope flutter commands", desc = "Open Flutter Commands" },
{ ft = "go", cmd = "set splitbelow;sp;term go run %", desc = "Run Go file" },
}
-- 只有进入这些文件类型时,才会为当前 buffer 绑定 r 键
local ft_group = vim.api.nvim_create_augroup("CodeRunnerLazy", { clear = true })
for _, entry in ipairs(mappings) do
vim.api.nvim_create_autocmd("FileType", {
pattern = entry.ft,
group = ft_group,
callback = function(args)
-- 为当前 buffer 绑定 r 键
vim.keymap.set("n", "r", function()
if vim.bo.modified then vim.cmd("wall") end
-- 只有命令中包含 "RunCode" 时,才加载代码运行器插件
if string.find(entry.cmd, "RunCode") then
PackUtils.load(P, function(plugin)
plugin.setup({
-- project = {
-- ["~/sixsixsix"] = {
-- name = "sixsixsix",
-- description = "六爻网页排盘",
-- command = "cargo run --release"
-- },
-- },
filetype = {
python = "uv run $fileName",
rust = { "cargo run --release" },
},
})
end)
end
-- 处理多条命令的情况 (用分号分隔)
for c in string.gmatch(entry.cmd, "[^;]+") do
vim.cmd(c)
end
end, { buffer = args.buf, desc = entry.desc, silent = true })
end,
})
vim.api.nvim_create_autocmd("FileType", {
pattern = entry.ft,
group = ft_group,
callback = function(args)
-- 为当前 buffer 绑定 r 键
vim.keymap.set("n", "r", function()
if vim.bo.modified then vim.cmd("wall") end
-- 只有命令中包含 "RunCode" 时,才加载代码运行器插件
if string.find(entry.cmd, "RunCode") then
PackUtils.load(P, function()
require("code_runner").setup({
-- project = {
-- ["~/sixsixsix"] = {
-- name = "sixsixsix",
-- description = "六爻网页排盘",
-- command = "cargo run --release"
-- },
-- },
filetype = {
python = "uv run $fileName",
rust = { "cargo run --release" },
},
})
end)
end
-- 处理多条命令的情况 (用分号分隔)
for c in string.gmatch(entry.cmd, "[^;]+") do
vim.cmd(c)
end
end, { buffer = args.buf, desc = entry.desc, silent = true })
end,
})
end

View file

@ -3,7 +3,6 @@ if vim.g.vscode then return end
local P = {
name = "conform.nvim",
module = "conform",
deps = {
"mason.nvim",
"mason-registry",
@ -43,8 +42,8 @@ end
-- 快捷键纯懒加载:只在按下快捷键时激活
vim.keymap.set({ "n", "v" }, "<leader>f", function()
PackUtils.load(P, function(plugin)
plugin.setup({ -- At a minimum, you will need to set up some formatters by filetype
PackUtils.load(P, function()
require("conform").setup({ -- At a minimum, you will need to set up some formatters by filetype
formatters_by_ft = formatters_by_ft
})
end)

View file

@ -2,7 +2,6 @@
local P = {
name = "indent-blankline.nvim", -- 仓库名
module = "ibl", -- require模块名
}
-- 懒加载触发器
@ -11,7 +10,7 @@ vim.api.nvim_create_autocmd({
}, {
callback = function()
vim.schedule(function()
PackUtils.load(P, function(plugin)
PackUtils.load(P, function()
local highlight = {
"RainbowBlue",
"RainbowViolet",
@ -33,7 +32,7 @@ vim.api.nvim_create_autocmd({
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end)
plugin.setup({
require("ibl").setup({
indent = { highlight = highlight }
})
end)

View file

@ -13,7 +13,6 @@ end
-- 2. 插件配置清单
local P = {
name = "nvim-lspconfig",
module = "lspconfig",
deps = { "mason.nvim", "mason-lspconfig.nvim", "inlay-hints.nvim" },
}

38
lua/pack/configs/mini.lua Normal file
View file

@ -0,0 +1,38 @@
-- === mini ===
local P = {
name = "mini.nvim", -- 仓库名
}
-- 懒加载触发器
vim.api.nvim_create_autocmd({
"UIEnter", -- vim.schedule(function()
}, {
callback = function()
vim.schedule(function()
PackUtils.load(P, function()
require('mini.surround').setup {
mappings = {
add = 's', -- Add surrounding
delete = 'sd', -- Delete surrounding
find = 'sf', -- Find surrounding (to the right)
find_left = 'sF', -- Find surrounding (to the left)
highlight = 'sh', -- Highlight surrounding
replace = 'cs', -- Replace surrounding/change sround
update_n_lines = 'sn', -- Update `n_lines`
},
}
end)
end)
end
})
-- 懒加载触发器
-- vim.api.nvim_create_autocmd({
-- "InsertEnter", "CmdlineEnter", -- 补全/命令行
-- }, {
-- callback = function()
-- PackUtils.load(P, function()
-- require('mini.pairs').setup {}
-- end)
-- end
-- })

View file

@ -3,47 +3,39 @@ if vim.g.vscode then return end
local P = {
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
},
-- 需要过滤的信息
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
})
-- 比其他插件更早启动才能捕获错误、警告等信息,这里不配置懒加载
PackUtils.load(P, function()
require("noice").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)

View file

@ -1,36 +1,34 @@
if vim.g.vscode then return end
local P = {
name = "peek.nvim",
module = "peek",
deps = {},
-- 编译命令:需要环境中安装了 deno
build_cmd = { "deno", "task", "--quiet", "build:fast" },
name = "peek.nvim",
-- 编译命令:需要环境中安装了 deno
build_cmd = { "deno", "task", "--quiet", "build:fast" },
}
PackUtils.setup_listener(P.name, P.build_cmd)
-- 2. 封装加载逻辑
local function load_peek()
PackUtils.load(P, function(plugin)
plugin.setup({
port = 9000,
app = { "zen", "-private-window" },
-- app = { "firefox-esr", "-private-window" },
-- app = { "google-chrome-stable", "--app=http://localhost:9000/?theme=dark", "--incognito" },
})
end)
PackUtils.load(P, function()
require("peek").setup({
port = 9000,
app = { "zen", "-private-window" },
-- app = { "firefox-esr", "-private-window" },
-- app = { "google-chrome-stable", "--app=http://localhost:9000/?theme=dark", "--incognito" },
})
end)
end
-- 在插件未加载时,这些命令就存在了。一旦被调用,它们会先加载插件,再执行真正的功能。
vim.api.nvim_create_user_command("PeekOpen", function()
load_peek() -- 触发 PackUtils.load (包含构建检查)
require("peek").open()
load_peek() -- 触发 PackUtils.load (包含构建检查)
require("peek").open()
end, { desc = "Lazy load and open Peek" })
vim.api.nvim_create_user_command("PeekClose", function()
-- 如果插件没加载Close 命令通常不需要做任何事,或者也触发加载
if PackUtils.is_initialized[P.name] then
require("peek").close()
end
-- 如果插件没加载Close 命令通常不需要做任何事,或者也触发加载
if PackUtils.is_initialized[P.name] then
require("peek").close()
end
end, { desc = "Close Peek" })

View file

@ -3,11 +3,10 @@ if vim.g.vscode then return end
local P = {
name = "snacks.nvim",
module = "snacks",
}
PackUtils.load(P, function(plugin)
plugin.setup({
PackUtils.load(P, function()
require("snacks").setup({
image = {},
lazygit = {},
notifier = {}, -- 替代了folke/noice.nvim插件的rcarriga/nvim-notify依赖

View file

@ -2,7 +2,6 @@ if vim.g.vscode then return end
local P = {
name = "nvim-treesitter",
module = "nvim-treesitter",
build_cmd = ":TSUpdate",
}

View file

@ -3,13 +3,12 @@ if vim.g.vscode then return end
local P = {
name = "tv.nvim", -- 仓库名
module = "tv", -- require模块名
}
local function load_plugin()
PackUtils.load(P, function(plugin)
local h = plugin.handlers
plugin.setup({
PackUtils.load(P, function()
local h = require("tv").handlers
require("tv").setup({
channels = {
["git-files"] = {
handlers = {

View file

@ -9,7 +9,6 @@ vim.o.foldenable = true
local P = {
name = "nvim-ufo", -- 仓库名
module = "ufo", -- require模块名
deps = { "promise-async" },
}
@ -19,7 +18,7 @@ vim.api.nvim_create_autocmd({
}, {
callback = function()
vim.schedule(function()
PackUtils.load(P, function(plugin)
PackUtils.load(P, function()
-- Option 2: nvim lsp as LSP client
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
@ -32,9 +31,9 @@ vim.api.nvim_create_autocmd({
capabilities = capabilities,
})
end
plugin.setup({})
require("ufo").setup({})
-- Option 3: treesitter as a main provider instead
-- plugin.setup({
-- require("ufo").setup({
-- provider_selector = function()
-- return { "treesitter", "indent" }
-- end

View file

@ -11,15 +11,14 @@ vim.g.loaded_netrwPlugin = 1
local P = {
name = "yazi.nvim",
module = "yazi",
deps = { "plenary.nvim" },
}
-- 快捷键触发懒加载
vim.keymap.set({ "n", "v" }, "tt", function()
-- 核心:直接调用引擎,把配置逻辑传进去
PackUtils.load(P, function(plugin)
plugin.setup({
PackUtils.load(P, function()
require("yazi").setup({
open_for_directories = false,
keymaps = { show_help = "<f1>" },
})

View file

@ -28,6 +28,10 @@ local specs = {
"https://github.com/MunifTanjim/nui.nvim",
-- snacks.lua 图片预览、lazygit、lsp_references模糊查找
"https://github.com/folke/snacks.nvim",
-- mini.lua 各种对字符的surround包裹{} [] ''
"https://github.com/echasnovski/mini.nvim",
-- autopairs.lua 对字符自动补全另一半
"https://github.com/windwp/nvim-autopairs",
-- tv.lua 模糊查找television
"https://github.com/alexpasmantier/tv.nvim",
-- coderunner.lua 运行代码
@ -263,45 +267,37 @@ 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
-- 检查插件是否存在于磁盘,如果找不到,说明它正在后台被 vim.pack 异步克隆下载,直接静默退出
if not PackUtils.get_root(P.name) then return end
-- 走到这里,说明插件绝对在硬盘上了,执行常规准备工作
PackUtils.check_health(P.name, P.build_cmd)
-- 强制将主插件挂载到 runtimepath
pcall(vim.cmd.packadd, P.name)
-- 保护依赖加载 (防止 dependencies 里的插件没下载)
if P.deps then
for _, dep in ipairs(P.deps) do
local dep_ok = pcall(vim.cmd.packadd, dep)
if not dep_ok then
vim.notify("Warning: " .. P.name .. " dependency [" .. dep .. "] missing", vim.log.levels.WARN)
vim.notify("Warning: " .. P.name .. " dependency[" .. dep .. "] missing", vim.log.levels.WARN)
end
end
end
-- 保护 require (防止插件文件夹还没下载完)
local req_ok, plugin = pcall(require, P.module)
-- 如果失败,说明插件还没下载好或者路径不对,优雅退出
if not req_ok then
-- 经过上面强制挂载后还是失败,且硬盘上确实有这个文件夹,那绝对是 module 填错了
if PackUtils.get_root(P.name) then
vim.notify("Error: Plugin [" .. P.name .. "] module not found", vim.log.levels.ERROR)
end
return
end
-- 保护 Setup 执行:使用 pcall 包裹传进来的匿名函数,防止 setup 里的参数写错导致崩溃
-- 保护 Setup 执行:自由地 require如有拼写错误这里的 pcall 会完美捕获并报错
if config_fn then
local setup_ok, err = pcall(config_fn, plugin)
local setup_ok, err = pcall(config_fn)
if not setup_ok then
vim.notify("Error: " .. P.name .. " setup failed: " .. tostring(err), vim.log.levels.ERROR)
vim.notify("Error: " .. P.name .. " setup failed: \n" .. tostring(err), vim.log.levels.ERROR)
return
end
end