mirror of
https://github.com/d0zingcat/dotfiles.git
synced 2026-05-14 07:26:44 +00:00
feat: a lot of configs
Signed-off-by: d0zingcat <iamtangli42@gmail.com>
This commit is contained in:
@@ -1,26 +1,116 @@
|
||||
-- Autocmds are automatically loaded on the VeryLazy event
|
||||
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
|
||||
--
|
||||
-- Add any additional autocmds here
|
||||
-- with `vim.api.nvim_create_autocmd`
|
||||
--
|
||||
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
|
||||
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")
|
||||
-- autocmds.lua - 自动命令配置
|
||||
|
||||
vim.cmd('filetype plugin indent on')
|
||||
-- 创建自动命令组
|
||||
local augroup = vim.api.nvim_create_augroup("MyCustomGroup", { clear = true })
|
||||
|
||||
-- Create a group for our autocommands
|
||||
local augroup = vim.api.nvim_create_augroup("CustomSettings", { clear = true })
|
||||
-- 自动设置光标行
|
||||
vim.api.nvim_create_autocmd({ "InsertLeave", "WinEnter" }, {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
if vim.bo.buftype ~= "terminal" then
|
||||
vim.opt_local.cursorline = true
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- FileType autocommands
|
||||
vim.api.nvim_create_autocmd({ "InsertEnter", "WinLeave" }, {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
if vim.bo.buftype ~= "terminal" then
|
||||
vim.opt_local.cursorline = false
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- 高亮复制文本
|
||||
vim.api.nvim_create_autocmd("TextYankPost", {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.highlight.on_yank({ higroup = "IncSearch", timeout = 200 })
|
||||
end,
|
||||
})
|
||||
|
||||
-- 自动切换工作目录
|
||||
vim.api.nvim_create_autocmd({ "BufEnter" }, {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
desc = "自动切换到文件所在目录",
|
||||
callback = function()
|
||||
local buftype = vim.bo.buftype
|
||||
if buftype ~= "terminal" and buftype ~= "nofile" and buftype ~= "prompt" then
|
||||
vim.cmd("silent! lcd %:p:h")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- 自动恢复光标位置
|
||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
||||
group = augroup,
|
||||
desc = "恢复光标位置",
|
||||
callback = function()
|
||||
local mark = vim.api.nvim_buf_get_mark(0, '"')
|
||||
local lcount = vim.api.nvim_buf_line_count(0)
|
||||
if mark[1] > 0 and mark[1] <= lcount then
|
||||
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- 自动关闭某些窗口的 q 键
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = {
|
||||
"qf",
|
||||
"help",
|
||||
"man",
|
||||
"notify",
|
||||
"lspinfo",
|
||||
"startuptime",
|
||||
"tsplayground",
|
||||
"spectre_panel",
|
||||
"PlenaryTestPopup",
|
||||
},
|
||||
group = augroup,
|
||||
callback = function(event)
|
||||
vim.bo[event.buf].buflisted = false
|
||||
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
|
||||
end,
|
||||
})
|
||||
|
||||
-- 在保存时自动删除行尾空白字符
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
desc = "删除行尾空白字符",
|
||||
callback = function()
|
||||
-- 保存当前位置
|
||||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||
-- 保存搜索寄存器
|
||||
local search = vim.fn.getreg("/")
|
||||
|
||||
-- 替换所有行尾空白字符
|
||||
vim.cmd([[%s/\s\+$//e]])
|
||||
|
||||
-- 恢复搜索寄存器
|
||||
vim.fn.setreg("/", search)
|
||||
-- 恢复光标位置
|
||||
vim.api.nvim_win_set_cursor(0, cursor_pos)
|
||||
end,
|
||||
})
|
||||
|
||||
-- 自动设置文件类型的选项
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "python",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 4
|
||||
vim.opt_local.expandtab = true
|
||||
vim.opt_local.shiftwidth = 4
|
||||
vim.opt_local.tabstop = 4
|
||||
vim.opt_local.softtabstop = 4
|
||||
vim.opt_local.textwidth = 120
|
||||
vim.opt_local.textwidth = 88 -- 符合 black 格式化
|
||||
vim.opt_local.colorcolumn = "88"
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -28,112 +118,20 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "go",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 4
|
||||
vim.opt_local.shiftwidth = 4
|
||||
vim.opt_local.softtabstop = 4
|
||||
vim.opt_local.textwidth = 120
|
||||
vim.opt_local.expandtab = false
|
||||
vim.opt_local.shiftwidth = 4
|
||||
vim.opt_local.tabstop = 4
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "json", "jsonnet" },
|
||||
pattern = { "javascript", "typescript", "javascriptreact", "typescriptreact", "json", "html", "css", "yaml", "markdown" },
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "yaml",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 0
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "gotmpl",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 0
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "php",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 120
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "html", "htmldjango", "xhtml", "haml" },
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 0
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "ruby",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 120
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "less", "sass", "scss", "css" },
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 120
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "javascript", "javascript.jsx", "javascriptreact", "typescript", "typescriptreact" },
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "NvimTree",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.softtabstop = 2
|
||||
vim.opt_local.textwidth = 0
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -142,23 +140,73 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.expandtab = false
|
||||
vim.opt_local.shiftwidth = 8
|
||||
vim.opt_local.softtabstop = 0
|
||||
end,
|
||||
})
|
||||
|
||||
-- File pattern autocommands
|
||||
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
|
||||
pattern = "*.proto",
|
||||
group = augroup,
|
||||
command = "setfiletype proto",
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "proto",
|
||||
-- 为新文件创建模板
|
||||
vim.api.nvim_create_autocmd("BufNewFile", {
|
||||
pattern = "*.py",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.expandtab = true
|
||||
local lines = {
|
||||
"#!/usr/bin/env python3",
|
||||
"# -*- coding: utf-8 -*-",
|
||||
"\"\"\"",
|
||||
"Description: ",
|
||||
"\"\"\"",
|
||||
"",
|
||||
"",
|
||||
"def main():",
|
||||
" pass",
|
||||
"",
|
||||
"",
|
||||
"if __name__ == \"__main__\":",
|
||||
" main()",
|
||||
"",
|
||||
}
|
||||
vim.api.nvim_buf_set_lines(0, 0, 0, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, { 4, 13 })
|
||||
end,
|
||||
})
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("BufNewFile", {
|
||||
pattern = "*.go",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
local package_name = vim.fn.fnamemodify(vim.fn.expand("%:p:h:t"), ":r")
|
||||
|
||||
local lines = {
|
||||
"package " .. package_name,
|
||||
"",
|
||||
"import (",
|
||||
"\t\"fmt\"",
|
||||
")",
|
||||
"",
|
||||
"// TODO: Add description here",
|
||||
"",
|
||||
"",
|
||||
}
|
||||
vim.api.nvim_buf_set_lines(0, 0, 0, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, { 7, 27 })
|
||||
end,
|
||||
})
|
||||
|
||||
-- 在外部更改时自动重新加载文件
|
||||
vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHoldI" }, {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
if vim.fn.mode() ~= "c" and not vim.bo.readonly then
|
||||
vim.cmd("checktime")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- 当 checktime 检测到文件已更改时通知
|
||||
vim.api.nvim_create_autocmd("FileChangedShellPost", {
|
||||
pattern = "*",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.notify("File changed on disk. Buffer reloaded!", vim.log.levels.WARN)
|
||||
end,
|
||||
})
|
||||
@@ -1,3 +1,117 @@
|
||||
-- Keymaps are automatically loaded on the VeryLazy event
|
||||
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
|
||||
-- Add any additional keymaps here
|
||||
-- keymaps.lua - 键位映射配置
|
||||
|
||||
-- 设置局部变量
|
||||
local map = vim.keymap.set
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
--[[
|
||||
模式说明:
|
||||
n: 普通模式
|
||||
i: 插入模式
|
||||
v: 可视模式
|
||||
x: 可视块模式
|
||||
t: 终端模式
|
||||
c: 命令行模式
|
||||
]]--
|
||||
|
||||
-----------------
|
||||
-- 基础键位映射 --
|
||||
-----------------
|
||||
|
||||
-- 使用 jk 从插入模式返回普通模式
|
||||
map("i", "jk", "<ESC>", opts)
|
||||
|
||||
-- 保存和退出
|
||||
map("n", "<leader>w", "<cmd>w<cr>", { desc = "保存文件" })
|
||||
map("n", "<leader>q", "<cmd>q<cr>", { desc = "退出" })
|
||||
map("n", "<leader>Q", "<cmd>qa<cr>", { desc = "退出全部" })
|
||||
|
||||
-- 清除搜索高亮
|
||||
map("n", "<leader>h", "<cmd>nohlsearch<cr>", { desc = "清除搜索高亮" })
|
||||
|
||||
-- 更好的缩进
|
||||
map("v", "<", "<gv", opts)
|
||||
map("v", ">", ">gv", opts)
|
||||
|
||||
-- 上下移动选中的文本
|
||||
map("v", "J", ":m '>+1<CR>gv=gv", { desc = "向下移动选中文本" })
|
||||
map("v", "K", ":m '<-2<CR>gv=gv", { desc = "向上移动选中文本" })
|
||||
|
||||
-- 保持复制内容在粘贴后
|
||||
map("x", "p", [["_dP]], { desc = "粘贴不覆盖寄存器" })
|
||||
|
||||
-- 删除到黑洞寄存器
|
||||
map({ "n", "v" }, "<leader>d", [["_d]], { desc = "删除到黑洞寄存器" })
|
||||
|
||||
-- 快速移动
|
||||
map("n", "J", "mzJ`z", { desc = "连接行保持光标位置" })
|
||||
map("n", "<C-d>", "<C-d>zz", { desc = "向下移动保持光标居中" })
|
||||
map("n", "<C-u>", "<C-u>zz", { desc = "向上移动保持光标居中" })
|
||||
map("n", "n", "nzzzv", { desc = "下一个搜索结果并居中" })
|
||||
map("n", "N", "Nzzzv", { desc = "上一个搜索结果并居中" })
|
||||
|
||||
-------------------------
|
||||
-- 窗口和缓冲区管理 --
|
||||
-------------------------
|
||||
|
||||
-- 窗口间导航
|
||||
map("n", "<C-h>", "<C-w>h", { desc = "移动到左窗口" })
|
||||
map("n", "<C-j>", "<C-w>j", { desc = "移动到下窗口" })
|
||||
map("n", "<C-k>", "<C-w>k", { desc = "移动到上窗口" })
|
||||
map("n", "<C-l>", "<C-w>l", { desc = "移动到右窗口" })
|
||||
|
||||
-- 缓冲区导航
|
||||
map("n", "<S-h>", "<cmd>bprevious<cr>", { desc = "上一个缓冲区" })
|
||||
map("n", "<S-l>", "<cmd>bnext<cr>", { desc = "下一个缓冲区" })
|
||||
map("n", "<leader>bd", "<cmd>bdelete<cr>", { desc = "关闭当前缓冲区" })
|
||||
map("n", "<leader>ba", "<cmd>bufdo bd<cr>", { desc = "关闭所有缓冲区" })
|
||||
|
||||
-- 窗口分割
|
||||
map("n", "<leader>sv", "<cmd>vsplit<cr>", { desc = "垂直分割" })
|
||||
map("n", "<leader>sh", "<cmd>split<cr>", { desc = "水平分割" })
|
||||
map("n", "<leader>se", "<C-w>=", { desc = "使所有窗口等宽" })
|
||||
map("n", "<leader>sx", "<cmd>close<cr>", { desc = "关闭当前窗口" })
|
||||
|
||||
-- 调整窗口大小
|
||||
map("n", "<C-Up>", "<cmd>resize +2<cr>", { desc = "增加窗口高度" })
|
||||
map("n", "<C-Down>", "<cmd>resize -2<cr>", { desc = "减小窗口高度" })
|
||||
map("n", "<C-Left>", "<cmd>vertical resize -2<cr>", { desc = "减小窗口宽度" })
|
||||
map("n", "<C-Right>", "<cmd>vertical resize +2<cr>", { desc = "增加窗口宽度" })
|
||||
|
||||
-------------------------
|
||||
-- 终端模式映射 --
|
||||
-------------------------
|
||||
|
||||
-- 退出终端模式
|
||||
map("t", "<Esc>", "<C-\\><C-n>", { desc = "退出终端模式" })
|
||||
map("t", "jk", "<C-\\><C-n>", { desc = "退出终端模式" })
|
||||
|
||||
-- 终端窗口导航
|
||||
map("t", "<C-h>", "<C-\\><C-n><C-w>h", { desc = "终端模式下向左移动" })
|
||||
map("t", "<C-j>", "<C-\\><C-n><C-w>j", { desc = "终端模式下向下移动" })
|
||||
map("t", "<C-k>", "<C-\\><C-n><C-w>k", { desc = "终端模式下向上移动" })
|
||||
map("t", "<C-l>", "<C-\\><C-n><C-w>l", { desc = "终端模式下向右移动" })
|
||||
|
||||
-------------------------
|
||||
-- 实用功能 --
|
||||
-------------------------
|
||||
|
||||
-- 全文快速替换当前单词
|
||||
map("n", "<leader>r", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]], { desc = "替换当前单词" })
|
||||
|
||||
-- 使当前文件可执行
|
||||
map("n", "<leader>x", "<cmd>!chmod +x %<CR>", { desc = "使当前文件可执行", silent = true })
|
||||
|
||||
-- 打开一个新的终端
|
||||
map("n", "<leader>t", "<cmd>terminal<cr>", { desc = "打开终端" })
|
||||
|
||||
-- 快速编辑配置文件
|
||||
map("n", "<leader>ev", "<cmd>e $MYVIMRC<cr>", { desc = "编辑init.lua" })
|
||||
map("n", "<leader>sv", "<cmd>source $MYVIMRC<cr>", { desc = "重新加载配置" })
|
||||
|
||||
-- 更简单的命令行历史导航
|
||||
map("c", "<C-j>", "<Down>", { desc = "下一个命令历史" })
|
||||
map("c", "<C-k>", "<Up>", { desc = "上一个命令历史" })
|
||||
|
||||
-- 更好的搜索
|
||||
map("n", "g/", "/\\<\\><Left><Left>", { desc = "搜索单词" })
|
||||
@@ -1,3 +1,6 @@
|
||||
-- lazy.lua - lazy.nvim 插件管理器配置
|
||||
|
||||
-- Bootstrap lazy.nvim
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
||||
@@ -14,40 +17,75 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
-- 配置 lazy.nvim
|
||||
require("lazy").setup({
|
||||
-- 插件列表
|
||||
spec = {
|
||||
-- add LazyVim and import its plugins
|
||||
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
|
||||
-- import/override with your plugins
|
||||
-- 导入插件模块
|
||||
{ import = "plugins" },
|
||||
},
|
||||
|
||||
-- 默认配置
|
||||
defaults = {
|
||||
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
|
||||
-- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
|
||||
lazy = false,
|
||||
-- It's recommended to leave version=false for now, since a lot the plugin that support versioning,
|
||||
-- have outdated releases, which may break your Neovim install.
|
||||
version = false, -- always use the latest git commit
|
||||
-- version = "*", -- try installing the latest stable version for plugins that support semver
|
||||
lazy = false, -- 默认不延迟加载
|
||||
version = false, -- 使用最新版本
|
||||
},
|
||||
install = { colorscheme = { "tokyonight", "habamax" } },
|
||||
checker = {
|
||||
enabled = true, -- check for plugin updates periodically
|
||||
notify = false, -- notify on update
|
||||
}, -- automatically check for plugin updates
|
||||
|
||||
-- 安装配置
|
||||
install = {
|
||||
colorscheme = { "tokyonight", "habamax" }, -- 安装时使用的主题
|
||||
missing = true, -- 自动安装缺失的插件
|
||||
},
|
||||
|
||||
-- 性能配置
|
||||
performance = {
|
||||
rtp = {
|
||||
-- disable some rtp plugins
|
||||
-- 禁用一些内置插件
|
||||
disabled_plugins = {
|
||||
"gzip",
|
||||
-- "matchit",
|
||||
-- "matchparen",
|
||||
-- "netrwPlugin",
|
||||
"tarPlugin",
|
||||
"tohtml",
|
||||
"tutor",
|
||||
"zipPlugin",
|
||||
"gzip", -- 不需要在编辑器内处理 gzip 文件
|
||||
"matchit", -- 使用 treesitter 代替
|
||||
"matchparen", -- 使用 treesitter 代替
|
||||
"netrwPlugin", -- 使用 nvim-tree 代替
|
||||
"tarPlugin", -- 不需要在编辑器内处理 tar 文件
|
||||
"tohtml", -- 不需要转换为 HTML
|
||||
"tutor", -- 不需要内置教程
|
||||
"zipPlugin", -- 不需要在编辑器内处理 zip 文件
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- UI 配置
|
||||
ui = {
|
||||
-- 自定义图标
|
||||
icons = {
|
||||
cmd = "⌘",
|
||||
config = "🛠",
|
||||
event = "📅",
|
||||
ft = "📂",
|
||||
init = "⚙",
|
||||
keys = "🔑",
|
||||
plugin = "🔌",
|
||||
runtime = "💻",
|
||||
source = "📄",
|
||||
start = "🚀",
|
||||
task = "📌",
|
||||
lazy = "💤 ",
|
||||
},
|
||||
size = { width = 0.8, height = 0.8 }, -- 窗口大小
|
||||
wrap = true, -- 自动换行
|
||||
border = "rounded", -- 边框样式
|
||||
},
|
||||
|
||||
-- 检查更新配置
|
||||
checker = {
|
||||
enabled = true, -- 启用自动检查更新
|
||||
frequency = 3600, -- 检查频率(秒)
|
||||
notify = false, -- 禁用更新通知
|
||||
},
|
||||
|
||||
-- 更新配置
|
||||
change_detection = {
|
||||
enabled = true, -- 启用自动重载
|
||||
notify = false, -- 禁用更改通知
|
||||
},
|
||||
})
|
||||
@@ -1,55 +1,89 @@
|
||||
-- Options are automatically loaded before lazy.nvim startup
|
||||
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
|
||||
-- Add any additional options here
|
||||
-- options.lua - 基本编辑器选项设置
|
||||
|
||||
local opt = vim.opt
|
||||
local o = vim.o
|
||||
local g = vim.g
|
||||
|
||||
g.loaded_netrw = 1
|
||||
g.loaded_netrwPlugin = 1
|
||||
o.termguicolors = true
|
||||
-- UI设置
|
||||
opt.termguicolors = true -- 使用终端真彩色
|
||||
opt.number = true -- 显示行号
|
||||
opt.relativenumber = true -- 相对行号
|
||||
opt.cursorline = true -- 高亮当前行
|
||||
opt.cursorcolumn = true -- 高亮当前列
|
||||
opt.signcolumn = "auto:1" -- 显示标记列
|
||||
opt.showmatch = true -- 高亮匹配的括号
|
||||
opt.showmode = false -- 不显示模式,由状态栏插件替代
|
||||
opt.laststatus = 3 -- 全局状态栏
|
||||
opt.cmdheight = 1 -- 命令行高度
|
||||
opt.scrolloff = 10 -- 光标上下保留的行数
|
||||
opt.sidescrolloff = 10 -- 光标左右保留的列数
|
||||
opt.wrap = false -- 不自动换行
|
||||
opt.linebreak = true -- 如果wrap开启,在单词边界处换行
|
||||
opt.list = true -- 显示不可见字符
|
||||
opt.listchars = { -- 设置不可见字符的显示方式
|
||||
tab = "» ",
|
||||
trail = "·",
|
||||
extends = "›",
|
||||
precedes = "‹",
|
||||
nbsp = "␣",
|
||||
eol = "↴"
|
||||
}
|
||||
opt.fillchars:append({ -- 分隔符符号设置
|
||||
vert = "│", -- 窗口分隔符
|
||||
fold = "⠀", -- 折叠
|
||||
eob = " ", -- 缓冲区末尾的空行
|
||||
diff = "╱", -- 差异模式的删除行
|
||||
})
|
||||
|
||||
g.mapleader = ' ' -- Make sure to set `mapleader` before lazy so your mappings are correct
|
||||
g.maplocalleader = '\\' -- Same for `maplocalleader`
|
||||
-- 编辑设置
|
||||
opt.tabstop = 4 -- Tab宽度
|
||||
opt.softtabstop = 4 -- 编辑时的Tab宽度
|
||||
opt.shiftwidth = 4 -- 缩进宽度
|
||||
opt.expandtab = true -- 使用空格替代Tab
|
||||
opt.smartindent = true -- 智能缩进
|
||||
opt.autoindent = true -- 自动缩进
|
||||
opt.cindent = true -- C语言缩进规则
|
||||
opt.textwidth = 120 -- 文本宽度
|
||||
opt.formatoptions = "jcroqlnt" -- 格式化选项
|
||||
opt.foldenable = false -- 默认不折叠
|
||||
opt.foldmethod = "expr" -- 使用表达式进行折叠
|
||||
opt.foldexpr = "nvim_treesitter#foldexpr()" -- 使用treesitter进行折叠
|
||||
|
||||
o.encoding = 'utf-8'
|
||||
o.fileencoding = 'utf-8'
|
||||
o.fencs = 'utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936'
|
||||
o.hidden = true
|
||||
o.wildmenu = true
|
||||
o.hlsearch = true
|
||||
o.incsearch = true
|
||||
o.matchtime = 1
|
||||
o.showmatch = true
|
||||
o.updatetime = 100
|
||||
o.ignorecase = true
|
||||
o.smarttab = true
|
||||
o.expandtab = true
|
||||
o.laststatus = 2
|
||||
o.showcmd = true
|
||||
o.ruler = true
|
||||
o.history = 300
|
||||
o.backup = false
|
||||
o.swapfile = false
|
||||
o.foldenable = false
|
||||
o.autoread = true
|
||||
o.autowrite = true
|
||||
o.mouse = 'a'
|
||||
-- 搜索设置
|
||||
opt.ignorecase = true -- 搜索忽略大小写
|
||||
opt.smartcase = true -- 如果搜索包含大写字母,则区分大小写
|
||||
opt.hlsearch = true -- 高亮搜索结果
|
||||
opt.incsearch = true -- 增量搜索
|
||||
|
||||
o.number = true
|
||||
o.cursorline = true
|
||||
o.relativenumber = true
|
||||
o.cursorcolumn = true
|
||||
o.signcolumn = 'auto:1'
|
||||
-- o.cmdheight = 0
|
||||
opt.list = true
|
||||
opt.listchars:append('eol:↴')
|
||||
opt.fillchars:append { diff = '╱' }
|
||||
-- 性能设置
|
||||
opt.hidden = true -- 允许切换未保存的缓冲区
|
||||
opt.history = 500 -- 历史记录数
|
||||
opt.updatetime = 100 -- 更新时间(ms)
|
||||
opt.timeout = true -- 启用超时
|
||||
opt.timeoutlen = 300 -- 键映射超时时间(ms)
|
||||
opt.ttimeoutlen = 10 -- 键码超时时间(ms)
|
||||
opt.synmaxcol = 240 -- 最大语法分析列数
|
||||
|
||||
o.textwidth = 120
|
||||
o.smartindent = true
|
||||
o.autoindent = true
|
||||
o.cindent = true
|
||||
o.shiftwidth = 4
|
||||
o.softtabstop = 4
|
||||
o.tabstop = 4
|
||||
-- 文件设置
|
||||
opt.fileencoding = "utf-8" -- 文件编码
|
||||
opt.backup = false -- 不创建备份文件
|
||||
opt.swapfile = false -- 不创建交换文件
|
||||
opt.undofile = true -- 启用持久撤销
|
||||
opt.undodir = vim.fn.stdpath("data") .. "/undo" -- 撤销文件目录
|
||||
|
||||
-- 鼠标设置
|
||||
opt.mouse = "a" -- 启用鼠标
|
||||
|
||||
-- 分隔符设置
|
||||
opt.splitbelow = true -- 新的水平分割窗口在下面
|
||||
opt.splitright = true -- 新的垂直分割窗口在右边
|
||||
|
||||
-- 通用设置
|
||||
opt.clipboard = "unnamedplus" -- 使用系统剪贴板
|
||||
opt.completeopt = "menu,menuone,noselect" -- 补全选项
|
||||
opt.pumheight = 10 -- 弹出菜单高度
|
||||
opt.confirm = true -- 显示确认对话框
|
||||
opt.autoread = true -- 自动重新加载文件
|
||||
|
||||
-- 加载 .nvimrc, .exrc 等本地配置
|
||||
opt.exrc = true -- 启用 .exrc
|
||||
opt.secure = true -- 限制本地配置中的命令
|
||||
200
nvim/lua/plugins/avante.lua
Normal file
200
nvim/lua/plugins/avante.lua
Normal 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -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" },
|
||||
},
|
||||
|
||||
@@ -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
78
nvim/lua/plugins/lint.lua
Normal 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,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
-- lua.lua - Lua 开发配置
|
||||
|
||||
return {
|
||||
-- Lua 语言支持(已由 neodev 在 coding.lua 中配置)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ return {
|
||||
-- Python
|
||||
null_ls.builtins.formatting.black,
|
||||
null_ls.builtins.formatting.isort,
|
||||
null_ls.builtins.diagnostics.ruff,
|
||||
},
|
||||
}
|
||||
end,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user