feat: 上传我的配置

This commit is contained in:
2026-02-06 17:17:48 +08:00
parent 5ae578a012
commit ac517ad717
126 changed files with 15159 additions and 0 deletions

8
.config/nvim/init.lua Normal file
View File

@@ -0,0 +1,8 @@
require("config.lazy")
-- 基础缩进设置
vim.opt.tabstop = 4 -- 1个Tab显示为4个空格
vim.opt.shiftwidth = 4 -- 自动缩进时缩进4个空格
vim.opt.expandtab = true -- 把Tab键变成空格现代编程通用习惯
vim.opt.softtabstop = 4 -- 编辑模式下按退格键退回4个空格
-- 显示行数
vim.opt.number = true

View File

@@ -0,0 +1,16 @@
{
"cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" },
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },
"lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "4cfe411526a7a99c18281135e8b4765ae6330d15" },
"mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" },
"nvim-autopairs": { "branch": "master", "commit": "c2a0dd0d931d0fb07665e1fedb1ea688da3b80b4" },
"nvim-cmp": { "branch": "main", "commit": "85bbfad83f804f11688d1ab9486b459e699292d6" },
"nvim-lspconfig": { "branch": "master", "commit": "ac04ec3c2af08e9821b4eb64ede86072b9b213bf" },
"nvim-tree.lua": { "branch": "master", "commit": "321bc61580fd066b76861c32de3319c3a6d089e7" },
"nvim-treesitter": { "branch": "main", "commit": "31fc7e10cd7c1fd7717b439050d0f91c2c4f0a4b" },
"nvim-web-devicons": { "branch": "master", "commit": "6788013bb9cb784e606ada44206b0e755e4323d7" },
"ouroboros": { "branch": "master", "commit": "f528c0baf0b872b37036c166a144abcfc4752ec9" },
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" }
}

View File

@@ -0,0 +1,35 @@
-- 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"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
-- Setup lazy.nvim
require("lazy").setup({
spec = {
-- import your plugins
{ import = "plugins" },
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "habamax" } },
-- automatically check for plugin updates
checker = { enabled = false },
})

View File

@@ -0,0 +1,5 @@
return {
"windwp/nvim-autopairs",
event = "InsertEnter", -- 只有进入插入模式时才加载,节省性能
config = true -- 相当于调用 require("nvim-autopairs").setup({})
}

View File

@@ -0,0 +1,11 @@
-- ~/.config/nvim/lua/plugins/colorscheme.lua
return {
{
"folke/tokyonight.nvim",
lazy = false, -- 我们希望启动就加载
priority = 1000, -- 高优先级,确保先于其他插件加载
config = function()
vim.cmd.colorscheme("tokyonight-night") -- 加载后,立即设置这个主题
end,
}
}

View File

@@ -0,0 +1,131 @@
return {
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
},
config = function()
-- 1. 初始化 Mason (包管理器)
require("mason").setup({
ui = { border = "rounded" }
})
-- 2. 配置 mason-lspconfig (自动安装LSP服务器)
require("mason-lspconfig").setup({
ensure_installed = { "clangd", "lua_ls" },
-- 【重要】新框架下mason-lspconfig 会自动处理安装和配置
-- 你不再需要手动调用 `require('lspconfig').xxx.setup()`
})
-- 3. 通用配置:快捷键与能力集
local on_attach = function(client, bufnr)
local opts = { buffer = bufnr, noremap = true, silent = true }
-- 按键映射
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
end
-- 获取自动补全的能力集
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- 4. 【核心修改】新版 LSP 配置框架
-- 全局配置表mason-lspconfig 会自动将这里定义的配置应用到对应服务器
vim.lsp.config = vim.lsp.config or {}
-- 导入工具函数(用于根目录检测)
local util = require("lspconfig.util")
-- ========== 配置 clangd (C/C++) ==========
vim.lsp.config.clangd = {
default_config = {
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--header-insertion=never",
"--completion-style=detailed",
"--all-scopes-completion",
"--cross-file-rename",
"--completion-parse=auto"
},
filetypes = { "c", "cpp", "objc", "objcpp", "cuda" },
root_dir = function(fname)
local root_markers = { '.git', 'compile_commands.json', 'compile_flags.txt', '.clangd', 'Makefile', 'build' }
local root = util.root_pattern(unpack(root_markers))(fname)
if not root then
root = util.find_git_ancestor(fname) or vim.fs.dirname(fname)
end
return root
end,
single_file_support = true,
capabilities = capabilities,
on_attach = on_attach, -- 【重要】在这里绑定快捷键
}
}
-- ========== 配置 lua_ls (Lua) ==========
vim.lsp.config.lua_ls = {
default_config = {
settings = {
Lua = {
runtime = { version = 'LuaJIT' },
diagnostics = { globals = { 'vim' } },
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
telemetry = { enable = false },
},
},
capabilities = capabilities,
on_attach = on_attach, -- 【重要】在这里绑定快捷键
}
}
-- 5. 美化UI设置
-- 悬浮文档窗口使用圆角边框
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = "rounded",
}
)
-- 【注意】在新框架下,通常不需要手动创建 LspAttach 自动命令
-- 因为每个服务器的 on_attach 已在 default_config 中定义
-- mason-lspconfig 会自动处理服务器启动和配置应用
end,
},
-- 6. 自动补全配置 (nvim-cmp) - 保持不变,与新旧框架都兼容
{
"hrsh7th/nvim-cmp",
config = function()
local cmp = require("cmp")
cmp.setup({
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
view = {
entries = { name = 'custom', selection_order = 'near_cursor' }
},
mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<Tab>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'path' },
})
})
end,
},
}

View File

@@ -0,0 +1,14 @@
return {
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
config = function()
require('lualine').setup({
options = {
theme = 'auto',
icons_enabled = true, -- 确保图标功能已启用
},
})
end,
}

View File

@@ -0,0 +1,38 @@
return {
"nvim-tree/nvim-tree.lua",
version = "*",
lazy = false,
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("nvim-tree").setup({
-- 这里可以放自定义设置,初始用默认即可
})
-- 设置一个常用快捷键:空格+e 打开/关闭文件树
-- 为 nvim-tree 设置一组实用快捷键
vim.keymap.set('n', '<leader>e', ':NvimTreeToggle<CR>', { desc = 'Toggle file tree' })
vim.keymap.set('n', '<leader>f', function()
local current_win = vim.api.nvim_get_current_win()
local current_buf = vim.api.nvim_win_get_buf(current_win)
local buf_ft = vim.api.nvim_buf_get_option(current_buf, 'filetype')
if buf_ft == 'NvimTree' then
-- 从文件树返回时,尝试回到之前编辑的窗口
vim.cmd('wincmd p')
-- 如果上一个窗口还是文件树(可能只有一个文件树窗口),就关闭它
local new_win = vim.api.nvim_get_current_win()
local new_buf = vim.api.nvim_win_get_buf(new_win)
local new_buf_ft = vim.api.nvim_buf_get_option(new_buf, 'filetype')
if new_buf_ft == 'NvimTree' then
vim.cmd('NvimTreeClose')
end
else
-- 保存当前窗口ID以便从文件树返回时能准确回来
vim.g.last_normal_win = current_win
vim.cmd('NvimTreeFindFile')
end
end, { desc = '智能切换: 文件⇄树' })
vim.keymap.set('n', '<leader>t', ':NvimTreeFocus<CR>', { desc = 'Focus on the file tree' })
end,
}

View File

@@ -0,0 +1,84 @@
-- 在你的 Lazy 插件配置文件中例如lua/plugins/cpp.lua
return {
{
"jakemason/ouroboros",
ft = { "c", "cpp", "h", "hpp" }, -- 可选:按文件类型懒加载
dependencies = {
"nvim-lua/plenary.nvim" -- 明确声明依赖[citation:8]
},
config = function()
require("ouroboros").setup({
-- 基本配置
open_all_alternates = false,
-- 查找策略(按顺序尝试)
strategies = {
"directory", -- 同一目录
"underscore", -- main_window.cpp -> main_window.h
"basename", -- 相同基名
"subdirectory", -- 在 include/ 或 src/ 中查找
"cabal", -- Cabal 项目结构
"complement", -- 互补扩展名
},
-- 扩展名映射
extension_map = {
h = { "cpp", "c", "cc", "cxx", "c++", "m", "mm" },
hpp = { "cpp", "cc", "cxx", "c++" },
hxx = { "cxx", "cpp" },
hh = { "cc", "cpp" },
c = { "h" },
cc = { "h", "hh" },
cpp = { "h", "hpp" },
cxx = { "h", "hxx", "hpp" },
m = { "h" },
mm = { "h" },
},
-- 目录映射(适用于标准项目结构)
directory_map = {
["include/(.*)%.h$"] = "src/%1.cpp",
["src/(.*)%.cpp$"] = "include/%1.h",
["inc/(.*)%.hpp$"] = "src/%1.cpp",
["lib/(.*)%.c$"] = "include/%1.h",
["source/(.*)%.cxx$"] = "headers/%1.hxx",
},
-- 自定义匹配函数
match_callback = function(filepath, strategies, bufnr)
-- 获取文件扩展名
local extension = filepath:match("%.(%w+)$") or ""
-- 如果是测试文件,寻找对应的源文件
if filepath:match("_test%.cpp$") then
local source_file = filepath:gsub("_test%.cpp$", ".cpp")
if vim.fn.filereadable(source_file) == 1 then
return { source_file }
end
end
-- 返回默认策略
return strategies
end,
})
-- 键位映射
vim.keymap.set("n", "<leader>oh", "<cmd>Ouroboros<cr>", {
desc = "切换头文件/源文件",
noremap = true,
silent = true,
})
vim.keymap.set("n", "<leader>oa", "<cmd>OuroborosAll<cr>", {
desc = "打开所有匹配文件",
noremap = true,
silent = true,
})
-- 可以添加更多命令
vim.api.nvim_create_user_command("AltFile", function()
require("ouroboros").switch()
end, {})
end,
},
}

View File

@@ -0,0 +1,19 @@
return {
"nvim-treesitter/nvim-treesitter",
version = false, -- 建议使用 master 分支
build = ":TSUpdate",
event = { "BufReadPost", "BufNewFile" }, -- 只有打开文件时才加载,防止启动报错
config = function()
-- 增加一个保护性检测
local status_ok, configs = pcall(require, "nvim-treesitter.configs")
if not status_ok then
return
end
configs.setup({
ensure_installed = { "lua", "vim", "vimdoc", "query", "c", "cpp" }, -- 基础必装
highlight = { enable = true },
indent = { enable = true }, -- 建议开启C++ 缩进会更准确
})
end,
}