feat: a lot of configs

Signed-off-by: d0zingcat <iamtangli42@gmail.com>
This commit is contained in:
2026-02-12 21:51:05 +08:00
parent 77c245dce2
commit 4eaabf5fb8
22 changed files with 1293 additions and 524 deletions

200
nvim/lua/plugins/avante.lua Normal file
View File

@@ -0,0 +1,200 @@
-- avante.lua - AI 编程助手,类似 Cursor 的体验
-- 基于 OpenAI/Anthropic API 提供智能代码编辑
return {
{
"yetone/avante.nvim",
event = "VeryLazy",
version = false, -- 使用最新版本
build = "make", -- 构建依赖
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
-- 可选: 用于图片粘贴支持
"HakonHarnes/img-clip.nvim",
},
opts = {
-- 默认 AI 提供商
provider = "openai",
-- 提供商配置 (v0.46+ 版本结构)
providers = {
-- OpenAI 配置
openai = {
endpoint = "https://api.openai.com/v1",
model = "gpt-4o",
timeout = 30000,
context_window = 128000,
extra_request_body = {
temperature = 0.75,
max_completion_tokens = 16384,
reasoning_effort = "medium",
},
},
-- Anthropic Claude 配置(备选)
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20241022",
timeout = 30000,
context_window = 200000,
extra_request_body = {
temperature = 0.75,
max_completion_tokens = 8192,
},
},
-- Azure OpenAI 配置(企业用户)
azure = {
endpoint = "", -- 你的 Azure 端点,例如: https://<resource>.openai.azure.com
deployment = "", -- 部署名称
api_version = "2024-12-01-preview",
timeout = 30000,
context_window = 128000,
extra_request_body = {
temperature = 0.75,
max_completion_tokens = 16384,
reasoning_effort = "medium",
},
},
-- Copilot 配置(可选)
copilot = {
endpoint = "https://api.githubcopilot.com",
model = "gpt-4o-copilot",
timeout = 30000,
context_window = 128000,
extra_request_body = {
temperature = 0.75,
max_completion_tokens = 16384,
},
},
},
-- 系统提示词 - 定义 AI 助手的角色
system_prompt = [[
You are an expert coding assistant. Your task is to help users write, refactor, and understand code.
Rules:
1. Always respond with code changes in the specified format
2. Explain your changes clearly
3. Consider code style and best practices
4. If unsure, ask clarifying questions
5. Be concise but thorough
When suggesting code changes:
- Use the diff format if replacing existing code
- Ensure code is syntactically correct
- Follow the existing code style of the project
]],
-- 浮动窗口样式
windows = {
---@type "right" | "left" | "top" | "bottom"
position = "right",
wrap = true,
width = 40,
sidebar_header = {
align = "center",
rounded = true,
},
},
-- 高亮配置
highlights = {
diff = {
current = "DiffText",
incoming = "DiffAdd",
},
},
-- 差异视图配置
diff = {
autojump = true,
list_opener = function()
-- 可以自定义差异列表打开方式
vim.cmd("copen")
end,
},
-- 建议 Provider 配置(用于代码补全)
suggestion_provider = "copilot", -- 或 "default"
-- 上下文窗口配置
context_window = 6000,
-- 行为配置
behaviour = {
-- 是否自动应用建议
auto_apply_suggestion_after_generation = false,
-- 是否支持图片粘贴
support_paste_from_clipboard = false,
},
-- 映射配置(空表示使用默认映射)
mappings = {
-- 默认映射:
-- <leader>aa - 打开侧边栏
-- <leader>ar - 重置对话
-- <leader>af - 切换焦点
-- <leader>ae - 编辑请求
-- <leader>as - 切换侧边栏位置
-- <leader>at - 停止生成
},
},
keys = {
-- 打开 AI 侧边栏
{
"<leader>aa",
function()
require("avante").toggle()
end,
desc = "AI 助手 (avante)",
mode = { "n", "v" },
},
-- 重置对话
{
"<leader>ar",
function()
require("avante").reset()
end,
desc = "重置 AI 对话",
},
-- 快速询问(选中代码)
{
"<leader>ai",
function()
require("avante").ask()
end,
desc = "AI 询问选中的代码",
mode = "v",
},
-- 编辑代码
{
"<leader>ae",
function()
require("avante").edit()
end,
desc = "AI 编辑代码",
mode = "v",
},
},
},
-- 可选依赖: 图片粘贴支持
{
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
opts = {
-- 默认配置即可
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = {
insert_mode = true,
},
},
},
},
}

View File

@@ -67,7 +67,7 @@ return {
},
},
},
-- Python 服务器
pyright = {
settings = {
@@ -89,7 +89,7 @@ return {
},
},
},
-- Go 服务器
gopls = {
settings = {
@@ -131,18 +131,6 @@ return {
},
},
},
-- 自动设置功能
setup = {
ruff_lsp = function()
require("lazyvim.util").lsp.on_attach(function(client, _)
-- 禁用 ruff 格式化功能,由 none-ls 处理
if client.name == "ruff_lsp" then
client.server_capabilities.documentFormattingProvider = false
end
end)
end,
},
},
config = function(_, opts)
-- 设置诊断标志
@@ -259,14 +247,21 @@ return {
local server_opts = vim.tbl_deep_extend("force", {
capabilities = vim.deepcopy(capabilities),
}, opts.servers[server] or {})
-- 特殊设置钩子
if opts.setup[server] then
if opts.setup[server](server, server_opts) then
return
end
if server == "ruff_lsp" then
-- 使用 LspAttach 自动命令来配置 ruff_lsp
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- 禁用 ruff 格式化功能,由 conform 处理
if client and client.name == "ruff_lsp" then
client.server_capabilities.documentFormattingProvider = false
end
end,
})
end
-- 启动服务器
require("lspconfig")[server].setup(server_opts)
end,
@@ -479,6 +474,7 @@ return {
-- UI 相关
{
"rcarriga/nvim-dap-ui",
dependencies = { "nvim-neotest/nvim-nio" },
keys = {
{ "<leader>du", function() require("dapui").toggle() end, desc = "Dap UI" },
},

View File

@@ -1,6 +1,26 @@
-- editor.lua - 编辑器增强插件配置
return {
-- LazyGit 集成
{
"kdheepak/lazygit.nvim",
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
dependencies = {
"nvim-lua/plenary.nvim",
},
keys = {
{ "<leader>gg", "<cmd>LazyGit<cr>", desc = "打开 LazyGit" },
{ "<leader>gf", "<cmd>LazyGitCurrentFile<cr>", desc = "当前文件 Git 历史" },
{ "<leader>gc", "<cmd>LazyGitConfig<cr>", desc = "LazyGit 配置" },
},
},
-- 模糊搜索
{
"nvim-telescope/telescope.nvim",
@@ -95,6 +115,26 @@ return {
end,
},
-- LazyGit 集成
{
"kdheepak/lazygit.nvim",
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
dependencies = {
"nvim-lua/plenary.nvim",
},
keys = {
{ "<leader>gg", "<cmd>LazyGit<cr>", desc = "打开 LazyGit" },
{ "<leader>gf", "<cmd>LazyGitCurrentFile<cr>", desc = "当前文件 Git 历史" },
{ "<leader>gc", "<cmd>LazyGitConfig<cr>", desc = "LazyGit 配置" },
},
},
-- 高级语法高亮
{
"nvim-treesitter/nvim-treesitter",

78
nvim/lua/plugins/lint.lua Normal file
View File

@@ -0,0 +1,78 @@
-- lint.lua - 代码检查配置
-- 使用 nvim-lint 替代 null-ls 的诊断功能
-- 与 conform.nvim 配合conform 负责格式化lint 负责诊断
return {
{
"mfussenegger/nvim-lint",
event = { "BufReadPre", "BufNewFile" },
config = function()
local lint = require("lint")
-- 按文件类型配置 linter
lint.linters_by_ft = {
-- Python: 使用 ruff 替代 flake8/pylint
python = { "ruff" },
-- Lua
lua = { "luacheck" },
-- Go
go = { "golangcilint" },
-- JavaScript/TypeScript
javascript = { "eslint" },
typescript = { "eslint" },
javascriptreact = { "eslint" },
typescriptreact = { "eslint" },
-- 通用
markdown = { "markdownlint" },
yaml = { "yamllint" },
dockerfile = { "hadolint" },
sh = { "shellcheck" },
}
-- 设置自动触发
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
-- 保存后检查
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})
-- 进入缓冲区时检查
vim.api.nvim_create_autocmd({ "BufEnter" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})
-- 插入模式离开后检查(可选,可能较频繁)
vim.api.nvim_create_autocmd({ "InsertLeave" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})
-- 创建用户命令
vim.api.nvim_create_user_command("Lint", function()
lint.try_lint()
end, { desc = "手动触发代码检查" })
vim.api.nvim_create_user_command("LintInfo", function()
local running_linters = lint.get_running()
if #running_linters == 0 then
vim.notify("没有正在运行的 linter", vim.log.levels.INFO)
else
vim.notify("运行中的 linter: " .. table.concat(running_linters, ", "), vim.log.levels.INFO)
end
end, { desc = "显示运行中的 linter" })
end,
},
}

View File

@@ -0,0 +1,5 @@
-- lua.lua - Lua 开发配置
return {
-- Lua 语言支持(已由 neodev 在 coding.lua 中配置)
}

View File

@@ -13,7 +13,6 @@ return {
-- Python
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.isort,
null_ls.builtins.diagnostics.ruff,
},
}
end,

View File

@@ -41,39 +41,30 @@ return {
dependencies = {
"nvim-neotest/neotest-python",
},
opts = {
adapters = {
["neotest-python"] = {
-- 使用项目根目录中的 pytest.ini
runner = "pytest",
-- 可以使用 pytest 或 unittest
-- runner = function()
-- if vim.fn.filereadable("pytest.ini") == 1 then
-- return "pytest"
-- else
-- return "unittest"
-- end
-- end,
-- 额外的 pytest 参数
args = {
"--color=yes",
"-v",
},
-- Python 测试发现模式
python = function()
-- 如果激活了虚拟环境,使用它
if vim.env.VIRTUAL_ENV then
return vim.env.VIRTUAL_ENV .. "/bin/python"
end
-- 否则使用系统的 Python
return "python"
end,
opts = function(_, opts)
-- 确保 adapters 是列表
opts.adapters = opts.adapters or {}
-- 添加 neotest-python 适配器
table.insert(opts.adapters, require("neotest-python")({
-- 使用项目根目录中的 pytest.ini
runner = "pytest",
-- 额外的 pytest 参数
args = {
"--color=yes",
"-v",
},
},
},
-- Python 测试发现模式
python = function()
-- 如果激活了虚拟环境,使用它
if vim.env.VIRTUAL_ENV then
return vim.env.VIRTUAL_ENV .. "/bin/python"
end
-- 否则使用系统的 Python
return "python"
end,
}))
return opts
end,
keys = {
{ "<leader>pt", "<cmd>lua require('neotest').run.run()<cr>", desc = "运行最近的测试" },
{ "<leader>pT", "<cmd>lua require('neotest').run.run(vim.fn.expand('%'))<cr>", desc = "运行文件中的测试" },
@@ -112,13 +103,27 @@ return {
dependencies = {
"mfussenegger/nvim-dap-python",
},
opts = function()
local path = require("mason-registry").get_package("debugpy"):get_install_path()
require("dap-python").setup(path .. "/venv/bin/python")
config = function()
local ok, mason_registry = pcall(require, "mason-registry")
local debugpy_path = nil
if ok then
local ok2, debugpy_pkg = pcall(mason_registry.get_package, "debugpy")
if ok2 and debugpy_pkg then
local ok3, path = pcall(debugpy_pkg.get_install_path, debugpy_pkg)
if ok3 then
debugpy_path = path .. "/venv/bin/python"
end
end
end
-- 如果无法通过 mason 获取路径,使用默认路径
if not debugpy_path then
debugpy_path = vim.fn.exepath("python3") or "python3"
end
require("dap-python").setup(debugpy_path)
-- 设置 pytest 调试
require("dap-python").test_runner = "pytest"
-- 添加自定义配置
table.insert(require("dap").configurations.python, {
type = "python",
@@ -131,7 +136,7 @@ return {
end,
console = "integratedTerminal",
})
-- 添加 FastAPI 配置
table.insert(require("dap").configurations.python, {
type = "python",

View File

@@ -1 +1,68 @@
return {"folke/snacks.nvim", opts={}}
-- snacks.lua - folke's modern utility library
-- Provides: notifications, bigfile handling, quickfile, statuscolumn, word highlighting
return {
{
"folke/snacks.nvim",
priority = 1000,
lazy = false,
opts = {
-- Bigfile optimization
bigfile = {
enabled = true,
notify = true,
line_length = 1000,
},
-- Notifications (replaces nvim-notify)
notifier = {
enabled = true,
timeout = 3000,
history = true,
render = "compact",
level = vim.log.levels.INFO,
},
-- Quick file navigation
quickfile = {
enabled = true,
exclude = { "gitcommit", "gitrebase" },
},
-- Enhanced statuscolumn
statuscolumn = {
enabled = true,
left = { "mark", "sign" },
right = { "fold", "git" },
folds = {
open = true,
git_hl = false,
},
},
-- Word highlighting and jumping
words = {
enabled = true,
debounce = 100,
notify_end = false,
jumplist = true,
mappings = {
["]w"] = "next",
["[w"] = "prev",
},
},
},
keys = {
{ "<leader>un", function() Snacks.notifier.hide() end, desc = "Dismiss All Notifications" },
{ "<leader>q", function() Snacks.quickfile() end, desc = "Quick File" },
{ "]w", function() Snacks.words.jump() end, desc = "Next Word Reference" },
{ "[w", function() Snacks.words.jump(-1) end, desc = "Prev Word Reference" },
},
init = function()
-- Override vim.notify
vim.notify = function(msg, level, opts)
Snacks.notifier.notify(msg, level, opts)
end
end,
},
}

View File

@@ -1 +1,158 @@
return {"folke/which-key.nvim", opts={}}
return {
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
-- 基础配置
preset = "helix", -- 使用 helix 预设,更现代的样式
-- 延迟配置
delay = 500, -- 显示 which-key 的延迟时间(毫秒)
-- 过滤配置
filter = function(mapping)
-- 只显示有描述的映射
return mapping.desc and mapping.desc ~= ""
end,
-- 触发配置
triggers = {
{ "<auto>", mode = "nxso" },
},
-- 窗口配置
win = {
no_overlap = true,
padding = { 1, 2 }, -- 上下, 左右
title = true,
title_pos = "center",
zindex = 1000,
bo = {},
wo = {
winblend = 10,
},
},
-- 布局配置
layout = {
width = { min = 20 }, -- 最小宽度
spacing = 3, -- 列间距
align = "left", -- 对齐方式
},
-- 图标配置
icons = {
breadcrumb = "»", -- 面包屑符号
separator = "", -- 分隔符
group = "+", -- 分组符号
ellipsis = "",
keys = {
Space = "<space>",
Tab = "<tab>",
Return = "<cr>",
Escape = "<esc>",
Backspace = "<bs>",
Delete = "<del>",
Insert = "<ins>",
Home = "<home>",
End = "<end>",
PageUp = "<pageup>",
PageDown = "<pagedown>",
ScrollLock = "<scrolllock>",
NumLock = "<numlock>",
CapsLock = "<capslock>",
Left = "<left>",
Right = "<right>",
Up = "<up>",
Down = "<down>",
F1 = "<f1>",
F2 = "<f2>",
F3 = "<f3>",
F4 = "<f4>",
F5 = "<f5>",
F6 = "<f6>",
F7 = "<f7>",
F8 = "<f8>",
F9 = "<f9>",
F10 = "<f10>",
F11 = "<f11>",
F12 = "<f12>",
Plug = "<plug>",
Action = "<action>",
Alt = "<a-",
Control = "<c-",
Meta = "<m-",
Shift = "<s-",
Super = "<d-",
Leader = "<leader>",
LocalLeader = "<localleader>",
},
},
-- 排序配置
sort = { "alphanum" },
-- 替换配置
replace = {
desc = {
{ "<Plug>%(?(.*)%)?", "%1" },
{ "^[cgls]%[?(.*)%]?$", "%1" },
{ "^ lua%.patterns%.(.+)$", "Pattern: %1" },
{ "^ lua%.snippets%.(.+)$", "Snippet: %1" },
{ "^ which%-key%.(.+)$", "WK: %1" },
{ "^.*%.(.+)$", "%1" },
},
},
-- 通知配置
notify = true,
-- 调试配置
debug = false,
-- 自动注册键组
spec = {},
},
config = function(_, opts)
local wk = require("which-key")
wk.setup(opts)
-- 注册键组
wk.add({
-- 文件操作
{ "<leader>f", group = "文件/查找", icon = { icon = "📁", color = "blue" } },
-- Git 操作
{ "<leader>g", group = "Git", icon = { icon = "🌿", color = "green" } },
-- LSP/Code 操作
{ "<leader>c", group = "代码/LSP", icon = { icon = "💻", color = "cyan" } },
-- 诊断
{ "<leader>x", group = "诊断", icon = { icon = "🚨", color = "red" } },
-- 搜索
{ "<leader>s", group = "搜索", icon = { icon = "🔍", color = "yellow" } },
-- 终端
{ "<leader>t", group = "终端", icon = { icon = "🖥️", color = "magenta" } },
-- 缓冲区
{ "<leader>b", group = "缓冲区", icon = { icon = "📋", color = "blue" } },
-- 通知
{ "<leader>u", group = "UI/通知", icon = { icon = "🎨", color = "purple" } },
-- AI 助手
{ "<leader>a", group = "AI 助手", icon = { icon = "🤖", color = "cyan" } },
-- Python
{ "<leader>p", group = "Python", icon = { icon = "🐍", color = "green" } },
-- 会话
{ "<leader>q", group = "会话/退出", icon = { icon = "🚪", color = "red" } },
-- 窗口
{ "<leader>w", group = "窗口", icon = { icon = "🪟", color = "blue" } },
})
end,
}