mirror of
https://github.com/cap153/nvim.git
synced 2026-05-02 19:58:10 +08:00
first commit
This commit is contained in:
commit
3b19a9c8a8
29 changed files with 2428 additions and 0 deletions
75
lua/pack/configs/blinkcmp.lua
Normal file
75
lua/pack/configs/blinkcmp.lua
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
-- === 自动补全插件 (Blink.cmp) ===
|
||||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "blink.cmp",
|
||||
module = "blink.cmp",
|
||||
deps = { "friendly-snippets" },
|
||||
-- build_cmd = "cargo build --release",
|
||||
}
|
||||
|
||||
-- PackUtils.setup_listener(P.name, P.build_cmd)
|
||||
|
||||
vim.api.nvim_create_autocmd({ "InsertEnter", "CmdlineEnter", "LspAttach" }, {
|
||||
once = true,
|
||||
callback = function()
|
||||
-- 调用引擎的 load 方法,把 setup 逻辑作为匿名函数传进去
|
||||
PackUtils.load(P, function(plugin)
|
||||
plugin.setup({
|
||||
fuzzy = {
|
||||
prebuilt_binaries = {
|
||||
force_version = 'v*',
|
||||
},
|
||||
},
|
||||
cmdline = {
|
||||
-- keymap = { ["<CR>"] = { "select_and_accept", "fallback" } },
|
||||
completion = {
|
||||
list = { selection = { preselect = false, auto_insert = true } },
|
||||
menu = { auto_show = function() return vim.fn.getcmdtype() == ":" end },
|
||||
ghost_text = { enabled = false },
|
||||
},
|
||||
},
|
||||
keymap = {
|
||||
preset = "none",
|
||||
["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
|
||||
["<CR>"] = { "accept", "fallback" },
|
||||
["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" },
|
||||
["<Tab>"] = { "select_next", "snippet_forward", "fallback" },
|
||||
["<C-b>"] = { "scroll_documentation_up", "fallback" },
|
||||
["<C-f>"] = { "scroll_documentation_down", "fallback" },
|
||||
["<C-e>"] = { "snippet_forward", "select_next", "fallback" },
|
||||
["<C-u>"] = { "snippet_backward", "select_prev", "fallback" },
|
||||
},
|
||||
completion = {
|
||||
keyword = { range = "full" },
|
||||
documentation = { auto_show = true, auto_show_delay_ms = 0 },
|
||||
list = { selection = { preselect = false, auto_insert = false } },
|
||||
},
|
||||
enabled = function()
|
||||
return not vim.tbl_contains({}, vim.bo.filetype)
|
||||
and vim.bo.buftype ~= "prompt"
|
||||
and vim.b.completion ~= false
|
||||
end,
|
||||
appearance = {
|
||||
use_nvim_cmp_as_default = true,
|
||||
nerd_font_variant = "mono",
|
||||
},
|
||||
sources = {
|
||||
default = { "buffer", "lsp", "path", "snippets" },
|
||||
providers = {
|
||||
buffer = { score_offset = 5 },
|
||||
path = { score_offset = 3 },
|
||||
lsp = { score_offset = 2 },
|
||||
snippets = { score_offset = 1 },
|
||||
-- cmdline = { -- 输入超过3个及以上字母才触发补全
|
||||
-- min_keyword_length = function(ctx)
|
||||
-- if ctx.mode == "cmdline" and string.find(ctx.line, " ") == nil then return 3 end
|
||||
-- return 0
|
||||
-- end,
|
||||
-- },
|
||||
},
|
||||
},
|
||||
})
|
||||
end)
|
||||
end
|
||||
})
|
||||
49
lua/pack/configs/bufferline.lua
Normal file
49
lua/pack/configs/bufferline.lua
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
local map = require("core.keymap")
|
||||
-- 新建空缓冲区,neovim自带的
|
||||
map:cmd('tu', 'enew')
|
||||
-- 关闭当前缓冲区,neovim自带的,完整命令bdelete
|
||||
map:cmd('tq', 'bd')
|
||||
|
||||
-- 在缓冲区之间移动
|
||||
map:cmd('tn', 'BufferLineCyclePrev')
|
||||
map:cmd('ti', 'BufferLineCycleNext')
|
||||
|
||||
-- 移动缓冲区的位置
|
||||
map:cmd('tmn', 'BufferLineMovePrev')
|
||||
map:cmd('tmi', 'BufferLineMoveNext')
|
||||
|
||||
-- 关闭缓冲区
|
||||
map:cmd('tN', 'BufferLineCloseLeft')
|
||||
map:cmd('tI', 'BufferLineCloseRight')
|
||||
map:cmd('tQ', 'BufferLineCloseOthers')
|
||||
|
||||
-- === 顶部标签栏 (Bufferline) ===
|
||||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "bufferline.nvim",
|
||||
module = "bufferline",
|
||||
deps = { "nvim-web-devicons" }, -- 确保图标库先加载
|
||||
}
|
||||
|
||||
-- 懒加载触发器:打开或新建文件时触发
|
||||
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
|
||||
once = true,
|
||||
callback = function()
|
||||
PackUtils.load(P, function(plugin)
|
||||
plugin.setup({
|
||||
options = {
|
||||
modified_icon = "",
|
||||
buffer_close_icon = "×",
|
||||
-- show_buffer_close_icons = false,
|
||||
max_name_length = 14,
|
||||
max_prefix_length = 13,
|
||||
tab_size = 10,
|
||||
indicator = {
|
||||
style = "none",
|
||||
},
|
||||
},
|
||||
})
|
||||
end)
|
||||
end
|
||||
})
|
||||
53
lua/pack/configs/coderunner.lua
Normal file
53
lua/pack/configs/coderunner.lua
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "code_runner.nvim",
|
||||
module = "code_runner",
|
||||
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" },
|
||||
}
|
||||
|
||||
-- 只有进入这些文件类型时,才会为当前 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,
|
||||
})
|
||||
end
|
||||
61
lua/pack/configs/conform.lua
Normal file
61
lua/pack/configs/conform.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
-- === 代码格式化 (conform.nvim) ===
|
||||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "conform.nvim",
|
||||
module = "conform",
|
||||
deps = {
|
||||
"mason.nvim",
|
||||
"mason-registry",
|
||||
},
|
||||
}
|
||||
|
||||
-- 提取出统一的配置变量
|
||||
local formatters_by_ft = {
|
||||
python = { "isort", "black" },
|
||||
rust = { "rust-analyzer", lsp_format = "fallback" },
|
||||
toml = { "templ" },
|
||||
html = { "djlint" },
|
||||
sh = { "shfmt" },
|
||||
zsh = { "shfmt" },
|
||||
}
|
||||
|
||||
|
||||
-- 辅助函数:从指定文件类型的配置中提取所有工具名称(去重)
|
||||
local function get_ensure_installed_for_ft(ft, ft_table)
|
||||
local tools = {}
|
||||
local cfg = ft_table[ft]
|
||||
if type(cfg) == "table" then
|
||||
for _, item in ipairs(cfg) do
|
||||
if type(item) == "string" then
|
||||
tools[item] = true
|
||||
end
|
||||
end
|
||||
elseif type(cfg) == "string" then
|
||||
tools[cfg] = true
|
||||
end
|
||||
local list = {}
|
||||
for tool, _ in pairs(tools) do
|
||||
table.insert(list, tool)
|
||||
end
|
||||
return list
|
||||
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
|
||||
formatters_by_ft = formatters_by_ft
|
||||
})
|
||||
end)
|
||||
local registry = require("mason-registry")
|
||||
local ft = vim.bo.filetype
|
||||
local tools = get_ensure_installed_for_ft(ft, formatters_by_ft)
|
||||
for _, tool in ipairs(tools) do
|
||||
if not registry.is_installed(tool) then
|
||||
vim.notify("Installing formatter: " .. tool, vim.log.levels.INFO)
|
||||
registry.get_package(tool):install()
|
||||
end
|
||||
end
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end, { desc = "格式化代码(检测安装缺失工具)" })
|
||||
42
lua/pack/configs/indentblankline.lua
Normal file
42
lua/pack/configs/indentblankline.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
-- === 彩虹缩进 ===
|
||||
|
||||
local P = {
|
||||
name = "indent-blankline.nvim", -- 仓库名
|
||||
module = "ibl", -- require模块名
|
||||
}
|
||||
|
||||
-- 懒加载触发器
|
||||
vim.api.nvim_create_autocmd({
|
||||
"UIEnter", -- vim.schedule(function()
|
||||
}, {
|
||||
callback = function()
|
||||
vim.schedule(function()
|
||||
PackUtils.load(P, function(plugin)
|
||||
local highlight = {
|
||||
"RainbowBlue",
|
||||
"RainbowViolet",
|
||||
"RainbowRed",
|
||||
"RainbowYellow",
|
||||
"RainbowGreen",
|
||||
"RainbowOrange",
|
||||
"RainbowCyan",
|
||||
}
|
||||
local hooks = require("ibl.hooks")
|
||||
-- create the highlight groups in the highlight setup hook, so they are reset
|
||||
-- every time the colorscheme changes
|
||||
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
|
||||
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
|
||||
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
|
||||
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
|
||||
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
|
||||
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
|
||||
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
|
||||
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
|
||||
end)
|
||||
plugin.setup({
|
||||
indent = { highlight = highlight }
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end
|
||||
})
|
||||
26
lua/pack/configs/kommentary.lua
Normal file
26
lua/pack/configs/kommentary.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
-- 注释快捷键
|
||||
local map = require("core.keymap")
|
||||
map:key("n", "<space>cn", "<Plug>kommentary_line_increase")
|
||||
map:key("x", "<space>cn", "<Plug>kommentary_visual_increase<esc>") -- 选择模式下注释/反注释后退出该模式
|
||||
map:key("n", "<space>cu", "<Plug>kommentary_line_decrease")
|
||||
map:key("x", "<space>cu", "<plug>kommentary_visual_decrease<esc>")
|
||||
|
||||
local P = {
|
||||
name = "b3nj5m1n/kommentary", -- 仓库名
|
||||
module = "kommentary.config", -- require模块名
|
||||
}
|
||||
|
||||
-- 懒加载触发器
|
||||
vim.api.nvim_create_autocmd({
|
||||
"UIEnter",
|
||||
}, {
|
||||
callback = function()
|
||||
vim.schedule(function()
|
||||
PackUtils.load(P, function(plugin)
|
||||
plugin.configure_language("default", {
|
||||
prefer_single_line_comments = true,
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end
|
||||
})
|
||||
121
lua/pack/configs/lspconfig.lua
Normal file
121
lua/pack/configs/lspconfig.lua
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
-- === LSP 核心配置 (Lspconfig + Mason) ===
|
||||
if vim.g.vscode then return end
|
||||
|
||||
-- 1. 环境探测:判断 CPU 架构,决定安装哪些 LSP
|
||||
local arch = jit and jit.arch or ""
|
||||
local is_arm = arch:match("arm") or arch:match("aarch64")
|
||||
|
||||
local servers = { "lua_ls", "rust_analyzer", "pylsp" }
|
||||
if not is_arm then
|
||||
vim.list_extend(servers, { "marksman", "ts_ls", "svelte", "cssls", "html" })
|
||||
end
|
||||
|
||||
-- 2. 插件配置清单
|
||||
local P = {
|
||||
name = "nvim-lspconfig",
|
||||
module = "lspconfig",
|
||||
deps = { "mason.nvim", "mason-lspconfig.nvim", "inlay-hints.nvim" },
|
||||
}
|
||||
|
||||
-- 3. 懒加载触发器:当打开文件时触发
|
||||
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
|
||||
callback = function()
|
||||
PackUtils.load(P, function()
|
||||
-- === A. 基础依赖初始化 (Mason) ===
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = servers,
|
||||
})
|
||||
require("inlay-hints").setup()
|
||||
|
||||
-- === B. 全局诊断设置 ===
|
||||
vim.diagnostic.config({
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = "✘",
|
||||
[vim.diagnostic.severity.WARN] = "▲",
|
||||
[vim.diagnostic.severity.HINT] = "⚑",
|
||||
[vim.diagnostic.severity.INFO] = "»",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- === C. 全局快捷键映射 ===
|
||||
-- local opts = { noremap = true, silent = true }
|
||||
vim.keymap.set("n", "<leader>h", vim.lsp.buf.hover, opts) -- <space>h显示提示文档
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) -- gd跳转到定义
|
||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) -- gD跳转到声明(例如c语言中的头文件中的原型、一个变量的extern声明)
|
||||
vim.keymap.set("n", "go", vim.lsp.buf.type_definition, opts) -- go跳转到变量类型定义的位置(例如一些自定义类型)
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- <space>rn变量重命名
|
||||
vim.keymap.set("n", "<leader>aw", vim.lsp.buf.code_action, opts) -- <space>aw可以在出现警告或错误的地方打开建议的修复方法
|
||||
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- <space>d浮动窗口显示所在行警告或错误信息
|
||||
vim.keymap.set("n", "<leader>-", vim.diagnostic.goto_prev, opts) -- <space>-跳转到上一处警告或错误的地方
|
||||
vim.keymap.set("n", "<leader>=", vim.diagnostic.goto_next, opts) -- <space>+跳转到下一处警告或错误的地方
|
||||
-- vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) -- gr跳转到引用了对应变量或函数的位置,改用snacks
|
||||
-- vim.keymap.set({ 'n', 'x' }, '<leader>f', function() vim.lsp.buf.format({ async = true }) end, opts) -- <space>f进行代码格式化
|
||||
|
||||
-- === D. 特定 LSP 配置 (使用 Neovim 0.11+ vim.lsp.config 语法) ===
|
||||
|
||||
-- Python (pylsp) + uv 虚拟环境自适应
|
||||
vim.lsp.config("pylsp", {
|
||||
on_init = function(client)
|
||||
-- 1. 安全获取 root_dir
|
||||
local root_dir = client.config.root_dir
|
||||
-- 2. 只有当 root_dir 不为 nil 时才进行后续探测
|
||||
if root_dir then
|
||||
local venv_python = root_dir .. "/.venv/bin/python"
|
||||
-- 3. 检查虚拟环境文件是否真的存在且可读
|
||||
if vim.fn.filereadable(venv_python) == 1 then
|
||||
client.config.settings.pylsp.plugins.jedi.environment = venv_python
|
||||
-- 只有修改了设置才发送通知
|
||||
client.notify("workspace/didChangeConfiguration", {
|
||||
settings = client.config.settings
|
||||
})
|
||||
end
|
||||
end
|
||||
-- 无论是否找到虚拟环境,都返回 true 让 LSP 继续启动
|
||||
return true
|
||||
end,
|
||||
settings = {
|
||||
pylsp = {
|
||||
plugins = {
|
||||
jedi = { environment = nil }
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
-- Lua (lua_ls)
|
||||
vim.lsp.config("lua_ls", {
|
||||
settings = {
|
||||
["Lua"] = {
|
||||
hint = { enable = true },
|
||||
diagnostics = { globals = { "vim", "require", "opts", "PackUtils", "jit" } },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Go (gopls)
|
||||
vim.lsp.config("gopls", {
|
||||
settings = {
|
||||
["gopls"] = {
|
||||
hints = {
|
||||
rangeVariableTypes = true,
|
||||
parameterNames = true,
|
||||
constantValues = true,
|
||||
assignVariableTypes = true,
|
||||
compositeLiteralFields = true,
|
||||
compositeLiteralTypes = true,
|
||||
functionTypeParameters = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- 遍历列表并正式启用服务器
|
||||
for _, server in ipairs(servers) do
|
||||
vim.lsp.enable(server)
|
||||
end
|
||||
end)
|
||||
end
|
||||
})
|
||||
28
lua/pack/configs/noice.lua
Normal file
28
lua/pack/configs/noice.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
-- === noice ===
|
||||
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
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end
|
||||
})
|
||||
36
lua/pack/configs/peek.lua
Normal file
36
lua/pack/configs/peek.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "peek.nvim",
|
||||
module = "peek",
|
||||
deps = {},
|
||||
-- 编译命令:需要环境中安装了 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)
|
||||
end
|
||||
|
||||
-- 在插件未加载时,这些命令就存在了。一旦被调用,它们会先加载插件,再执行真正的功能。
|
||||
vim.api.nvim_create_user_command("PeekOpen", function()
|
||||
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
|
||||
end, { desc = "Close Peek" })
|
||||
37
lua/pack/configs/snacks.lua
Normal file
37
lua/pack/configs/snacks.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
-- === Snacks ===
|
||||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "snacks.nvim",
|
||||
module = "snacks",
|
||||
}
|
||||
|
||||
PackUtils.load(P, function(plugin)
|
||||
plugin.setup({
|
||||
image = {},
|
||||
lazygit = {},
|
||||
notifier = {}, -- 替代了folke/noice.nvim插件的rcarriga/nvim-notify依赖
|
||||
picker = {
|
||||
win = {
|
||||
input = {
|
||||
keys = { -- Esc直接关闭窗口,不进入normal模式
|
||||
["<Esc>"] = { "close", mode = { "n", "i" } },
|
||||
["<c-e>"] = { "list_down", mode = { "i", "n" } },
|
||||
["<c-u>"] = { "list_up", mode = { "i", "n" } },
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
local map = require("core.keymap")
|
||||
map:lua("<c-g>", "Snacks.lazygit()")
|
||||
map:lua("gr", "Snacks.picker.lsp_references()")
|
||||
|
||||
-- 彻底清除 Neovim 0.10+ 自带的 LSP 默认映射,解除 `gr` 的 1秒等待延迟
|
||||
local default_lsp_keys = { "grr", "grn", "gra", "gri", "grt", "grx" }
|
||||
for _, key in ipairs(default_lsp_keys) do
|
||||
pcall(vim.keymap.del, "n", key) -- 使用 pcall 忽略找不到映射时的报错
|
||||
pcall(vim.keymap.del, "x", key)
|
||||
end
|
||||
53
lua/pack/configs/treesitter.lua
Normal file
53
lua/pack/configs/treesitter.lua
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
if vim.g.vscode then return end
|
||||
|
||||
local P = {
|
||||
name = "nvim-treesitter",
|
||||
module = "nvim-treesitter",
|
||||
build_cmd = ":TSUpdate",
|
||||
}
|
||||
|
||||
PackUtils.setup_listener(P.name, P.build_cmd)
|
||||
|
||||
local ensure_installed = {
|
||||
"json",
|
||||
"rust",
|
||||
"python",
|
||||
"lua",
|
||||
"markdown",
|
||||
"bash",
|
||||
"java",
|
||||
}
|
||||
|
||||
-- 在 FileType 确定时,检查、安装并启动
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = vim.api.nvim_create_augroup("NativeTreesitter", { clear = true }),
|
||||
callback = function(args)
|
||||
local buf = args.buf
|
||||
local ft = vim.bo[buf].filetype
|
||||
-- 过滤无效 buffer, 终端, 以及 yazi
|
||||
if ft == "" or ft == "yazi" or vim.bo[buf].buftype ~= "" then return end
|
||||
-- 过滤大型文件 (大于 100KB 不开启 Treesitter,防止卡顿)
|
||||
local max_filesize = 100 * 1024
|
||||
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||
if ok and stats and stats.size > max_filesize then return end
|
||||
-- 获取标准化的 Parser 名称
|
||||
local lang = vim.treesitter.language.get_lang(ft) or ft
|
||||
-- 检查该语言是否在我们的配置列表中
|
||||
if vim.tbl_contains(ensure_installed, lang) then
|
||||
local no_err, is_added = pcall(vim.treesitter.language.add, lang)
|
||||
if not no_err or not is_added then
|
||||
-- 只有在需要安装时,才把 nvim-treesitter 插件加载进内存
|
||||
PackUtils.load(P, function() end)
|
||||
vim.notify("🌱 Installing " .. lang .. " parser...", vim.log.levels.INFO)
|
||||
local ts = require("nvim-treesitter")
|
||||
if ts.install then
|
||||
ts.install({ lang }):wait(60000)
|
||||
else
|
||||
vim.cmd("TSInstall " .. lang)
|
||||
end
|
||||
end
|
||||
-- 万事俱备,启动高亮
|
||||
pcall(vim.treesitter.start, buf, lang)
|
||||
end
|
||||
end,
|
||||
})
|
||||
47
lua/pack/configs/tv.lua
Normal file
47
lua/pack/configs/tv.lua
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
-- === television模糊查找 ===
|
||||
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({
|
||||
channels = {
|
||||
["git-files"] = {
|
||||
handlers = {
|
||||
["<CR>"] = h.open_as_files,
|
||||
},
|
||||
},
|
||||
files = {
|
||||
handlers = {
|
||||
["<CR>"] = h.open_as_files, -- default: open selected files
|
||||
},
|
||||
},
|
||||
-- `text`: ripgrep search through file contents
|
||||
text = {
|
||||
handlers = {
|
||||
['<CR>'] = h.open_at_line, -- Jump to line:col in file
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<c-t>", function()
|
||||
load_plugin()
|
||||
if vim.fs.root(0, '.git') then
|
||||
vim.cmd('Tv git-files')
|
||||
else
|
||||
vim.cmd('Tv files')
|
||||
end
|
||||
end, { desc = "Smart Tv: git-files or files" })
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<c-f>", function()
|
||||
load_plugin()
|
||||
vim.cmd('Tv text')
|
||||
end, { desc = "模糊查找字符串" })
|
||||
32
lua/pack/configs/yazi.lua
Normal file
32
lua/pack/configs/yazi.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- VSCode 拦截
|
||||
if vim.g.vscode then
|
||||
local vscode = require("vscode")
|
||||
vim.keymap.set("n", "tt", function()
|
||||
vscode.action("yazi-vscode.toggle")
|
||||
end, { noremap = true, silent = true, desc = "Toggle Yazi (VSCode)" })
|
||||
return
|
||||
end
|
||||
|
||||
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({
|
||||
open_for_directories = false,
|
||||
keymaps = { show_help = "<f1>" },
|
||||
})
|
||||
end)
|
||||
-- 提前触发 BufReadPost 的事件钩子,让 LSP 悄悄在后台 require 完毕
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_exec_autocmds("BufReadPost", { modeline = false })
|
||||
end)
|
||||
vim.cmd("Yazi")
|
||||
end, { desc = "Open yazi" })
|
||||
Loading…
Add table
Add a link
Reference in a new issue