feat: change nvim config to AstroNvim

This commit is contained in:
2026-03-25 09:19:31 +08:00
parent d868f4ec4c
commit 3be61685ff
25 changed files with 580 additions and 354 deletions

3
.config/nvim/.luarc.json Normal file
View File

@@ -0,0 +1,3 @@
{
"format.enable": false
}

View File

@@ -0,0 +1,20 @@
{
"neodev": {
"library": {
"enabled": true,
"plugins": true
}
},
"neoconf": {
"plugins": {
"lua_ls": {
"enabled": true
}
}
},
"lspconfig": {
"lua_ls": {
"Lua.format.enable": false
}
}
}

View File

@@ -0,0 +1,7 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses = "None"
collapse_simple_statement = "Always"

34
.config/nvim/README.md Normal file
View File

@@ -0,0 +1,34 @@
# AstroNvim Template
**NOTE:** This is for AstroNvim v5+
A template for getting started with [AstroNvim](https://github.com/AstroNvim/AstroNvim)
## 🛠️ Installation
#### Make a backup of your current nvim and shared folder
```shell
mv ~/.config/nvim ~/.config/nvim.bak
mv ~/.local/share/nvim ~/.local/share/nvim.bak
mv ~/.local/state/nvim ~/.local/state/nvim.bak
mv ~/.cache/nvim ~/.cache/nvim.bak
```
#### Create a new user repository from this template
Press the "Use this template" button above to create a new repository to store your user configuration.
You can also just clone this repository directly if you do not want to track your user configuration in GitHub.
#### Clone the repository
```shell
git clone https://github.com/<your_user>/<your_repository> ~/.config/nvim
```
#### Start Neovim
```shell
nvim
```

View File

@@ -1,8 +1,27 @@
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
-- This file simply bootstraps the installation of Lazy.nvim and then calls other files for execution
-- This file doesn't necessarily need to be touched, BE CAUTIOUS editing this file and proceed at your own risk.
local lazypath = vim.env.LAZY or vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not (vim.env.LAZY or (vim.uv or vim.loop).fs_stat(lazypath)) then
-- stylua: ignore
local result = vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
if vim.v.shell_error ~= 0 then
-- stylua: ignore
vim.api.nvim_echo({ { ("Error cloning lazy.nvim:\n%s\n"):format(result), "ErrorMsg" }, { "Press any key to exit...", "MoreMsg" } }, true, {})
vim.fn.getchar()
vim.cmd.quit()
end
end
vim.opt.rtp:prepend(lazypath)
-- validate that lazy is available
if not pcall(require, "lazy") then
-- stylua: ignore
vim.api.nvim_echo({ { ("Unable to load lazy from: %s\n"):format(lazypath), "ErrorMsg" }, { "Press any key to exit...", "MoreMsg" } }, true, {})
vim.fn.getchar()
vim.cmd.quit()
end
require "lazy_setup"
require "polish"

View File

@@ -1,16 +1,47 @@
{
"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" },
"AstroNvim": { "branch": "main", "commit": "7fd58328e2bc91d5cad606ee48fdf924fca6ea3e" },
"LuaSnip": { "branch": "master", "commit": "5a1e39223db9a0498024a77b8441169d260c8c25" },
"aerial.nvim": { "branch": "master", "commit": "5c4e2da4486da5f9b798ea9a0f1fc5c6bcd3d9cf" },
"astrocore": { "branch": "main", "commit": "41e7e7208102d95409aa2632b9dc6f7ece9f8abf" },
"astrolsp": { "branch": "main", "commit": "0befe28a4ea96e46b7f7c01e4a634c04225ba55a" },
"astrotheme": { "branch": "main", "commit": "cf0e65a7b3ce2f830b052f4da937729eee1e7a7d" },
"astroui": { "branch": "main", "commit": "4943abbd42674b43249313afe83b91065a40e4be" },
"better-escape.nvim": { "branch": "master", "commit": "199dcc2643dec5d8dbdab4ec672cf405224dcb3b" },
"blink.cmp": { "branch": "main", "commit": "451168851e8e2466bc97ee3e026c3dcb9141ce07" },
"blink.compat": { "branch": "main", "commit": "2ed6d9a28b07fa6f3bface818470605f8896408c" },
"cmp-dap": { "branch": "master", "commit": "ea92773e84c0ad3288c3bc5e452ac91559669087" },
"friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" },
"gitsigns.nvim": { "branch": "main", "commit": "7010000889bfb6c26065e0b0f7f1e6aa9163edd9" },
"guess-indent.nvim": { "branch": "main", "commit": "84a4987ff36798c2fc1169cbaff67960aed9776f" },
"heirline.nvim": { "branch": "master", "commit": "fae936abb5e0345b85c3a03ecf38525b0828b992" },
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
"lazydev.nvim": { "branch": "main", "commit": "01bc2aacd51cf9021eb19d048e70ce3dd09f7f93" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "a676ab7282da8d651e175118bcf54483ca11e46d" },
"mason-null-ls.nvim": { "branch": "main", "commit": "2b8433f76598397fcc97318d410e0c4f7a4bea6a" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "e51f9b259f066c4347f9a79ffde54c29a0619384" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "443f1ef8b5e6bf47045cb2217b6f748a223cf7dc" },
"mason.nvim": { "branch": "main", "commit": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65" },
"mini.icons": { "branch": "main", "commit": "397ed3807e96b59709ef3292f0a3e253d5c1dc0a" },
"neo-tree.nvim": { "branch": "main", "commit": "ba6871d15528e36657d19a3112cc1697c59da19a" },
"neoconf.nvim": { "branch": "main", "commit": "bbe36f4d60ed096282f564ddae4e781e420a8270" },
"none-ls.nvim": { "branch": "main", "commit": "3c206dfedf5f1385e9d29f85ffaec7874358592a" },
"nui.nvim": { "branch": "main", "commit": "f535005e6ad1016383f24e39559833759453564e" },
"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" },
"nvim-dap": { "branch": "master", "commit": "085386b9359ddf8d76ad89b98973b8e332dc5ba3" },
"nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" },
"nvim-highlight-colors": { "branch": "main", "commit": "e2cb22089cc2358b2b995c09578224f142de6039" },
"nvim-lspconfig": { "branch": "master", "commit": "fa2662510d30b06168b6e2e6915518decde6bbac" },
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
"nvim-treesitter-textobjects": { "branch": "main", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" },
"nvim-ts-autotag": { "branch": "main", "commit": "db15f2e0df2f5db916e511e3fffb682ef2f6354f" },
"nvim-window-picker": { "branch": "main", "commit": "6382540b2ae5de6c793d4aa2e3fe6dbb518505ec" },
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" }
"resession.nvim": { "branch": "master", "commit": "cc819b0489938d03e4f3532a583354f0287c015b" },
"smart-splits.nvim": { "branch": "master", "commit": "ddb23c1a1cf1507bda487cda7f6e4690965ef9f5" },
"snacks.nvim": { "branch": "main", "commit": "a4e46becca45eb65c73a388634b1ce8aad629ae0" },
"todo-comments.nvim": { "branch": "main", "commit": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668" },
"toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" },
"vim-illuminate": { "branch": "master", "commit": "0d1e93684da00ab7c057410fecfc24f434698898" },
"which-key.nvim": { "branch": "main", "commit": "fcbf4eea17cb299c02557d576f0d568878e354a4" }
}

View File

@@ -0,0 +1,12 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- AstroCommunity: import any community modules here
-- We import this file in `lazy_setup.lua` before the `plugins/` folder.
-- This guarantees that the specs are processed before any user plugins.
---@type LazySpec
return {
"AstroNvim/astrocommunity",
{ import = "astrocommunity.pack.lua" },
-- import/override with your plugins folder
}

View File

@@ -1,35 +0,0 @@
-- 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,32 @@
require("lazy").setup({
{
"AstroNvim/AstroNvim",
version = "^5", -- Remove version tracking to elect for nightly AstroNvim
import = "astronvim.plugins",
opts = { -- AstroNvim options must be set here with the `import` key
mapleader = " ", -- This ensures the leader key must be configured before Lazy is set up
maplocalleader = ",", -- This ensures the localleader key must be configured before Lazy is set up
icons_enabled = true, -- Set to false to disable icons (if no Nerd Font is available)
pin_plugins = nil, -- Default will pin plugins when tracking `version` of AstroNvim, set to true/false to override
update_notifications = true, -- Enable/disable notification about running `:Lazy update` twice to update pinned plugins
},
},
{ import = "community" },
{ import = "plugins" },
} --[[@as LazySpec]], {
-- Configure any other `lazy.nvim` configuration options here
install = { colorscheme = { "astrotheme", "habamax" } },
ui = { backdrop = 100 },
performance = {
rtp = {
-- disable some rtp plugins, add more to your liking
disabled_plugins = {
"gzip",
"netrwPlugin",
"tarPlugin",
"tohtml",
"zipPlugin",
},
},
},
} --[[@as LazyConfig]])

View File

@@ -0,0 +1,85 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- AstroCore provides a central place to modify mappings, vim options, autocommands, and more!
-- Configuration documentation can be found with `:h astrocore`
-- NOTE: We highly recommend setting up the Lua Language Server (`:LspInstall lua_ls`)
-- as this provides autocomplete and documentation while editing
---@type LazySpec
return {
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = {
-- Configure core features of AstroNvim
features = {
large_buf = { size = 1024 * 256, lines = 10000 }, -- set global limits for large files for disabling features like treesitter
autopairs = true, -- enable autopairs at start
cmp = true, -- enable completion at start
diagnostics = { virtual_text = true, virtual_lines = false }, -- diagnostic settings on startup
highlighturl = true, -- highlight URLs at start
notifications = true, -- enable notifications at start
},
-- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on
diagnostics = {
virtual_text = true,
underline = true,
},
-- passed to `vim.filetype.add`
filetypes = {
-- see `:h vim.filetype.add` for usage
extension = {
foo = "fooscript",
},
filename = {
[".foorc"] = "fooscript",
},
pattern = {
[".*/etc/foo/.*"] = "fooscript",
},
},
-- vim options can be configured here
options = {
opt = { -- vim.opt.<key>
relativenumber = true, -- sets vim.opt.relativenumber
number = true, -- sets vim.opt.number
spell = false, -- sets vim.opt.spell
signcolumn = "yes", -- sets vim.opt.signcolumn to yes
wrap = false, -- sets vim.opt.wrap
},
g = { -- vim.g.<key>
-- configure global vim variables (vim.g)
-- NOTE: `mapleader` and `maplocalleader` must be set in the AstroNvim opts or before `lazy.setup`
-- This can be found in the `lua/lazy_setup.lua` file
},
},
-- Mappings can be configured through AstroCore as well.
-- NOTE: keycodes follow the casing in the vimdocs. For example, `<Leader>` must be capitalized
mappings = {
-- first key is the mode
n = {
-- second key is the lefthand side of the map
-- navigate buffer tabs
["]b"] = { function() require("astrocore.buffer").nav(vim.v.count1) end, desc = "Next buffer" },
["[b"] = { function() require("astrocore.buffer").nav(-vim.v.count1) end, desc = "Previous buffer" },
-- mappings seen under group name "Buffer"
["<Leader>bd"] = {
function()
require("astroui.status.heirline").buffer_picker(
function(bufnr) require("astrocore.buffer").close(bufnr) end
)
end,
desc = "Close buffer from tabline",
},
-- tables with just a `desc` key will be registered with which-key if it's installed
-- this is useful for naming menus
-- ["<Leader>b"] = { desc = "Buffers" },
-- setting a mapping to false will disable it
-- ["<C-S>"] = false,
},
},
},
}

View File

@@ -0,0 +1,105 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- AstroLSP allows you to customize the features in AstroNvim's LSP configuration engine
-- Configuration documentation can be found with `:h astrolsp`
-- NOTE: We highly recommend setting up the Lua Language Server (`:LspInstall lua_ls`)
-- as this provides autocomplete and documentation while editing
---@type LazySpec
return {
"AstroNvim/astrolsp",
---@type AstroLSPOpts
opts = {
-- Configuration table of features provided by AstroLSP
features = {
codelens = true, -- enable/disable codelens refresh on start
inlay_hints = false, -- enable/disable inlay hints on start
semantic_tokens = true, -- enable/disable semantic token highlighting
},
-- customize lsp formatting options
formatting = {
-- control auto formatting on save
format_on_save = {
enabled = true, -- enable or disable format on save globally
allow_filetypes = { -- enable format on save for specified filetypes only
-- "go",
},
ignore_filetypes = { -- disable format on save for specified filetypes
-- "python",
},
},
disabled = { -- disable formatting capabilities for the listed language servers
-- disable lua_ls formatting capability if you want to use StyLua to format your lua code
-- "lua_ls",
},
timeout_ms = 1000, -- default format timeout
-- filter = function(client) -- fully override the default formatting function
-- return true
-- end
},
-- enable servers that you already have installed without mason
servers = {
-- "pyright"
},
-- customize language server configuration options passed to `lspconfig`
---@diagnostic disable: missing-fields
config = {
-- clangd = { capabilities = { offsetEncoding = "utf-8" } },
},
-- customize how language servers are attached
handlers = {
-- a function without a key is simply the default handler, functions take two parameters, the server name and the configured options table for that server
-- function(server, opts) require("lspconfig")[server].setup(opts) end
-- the key is the server that is being setup with `lspconfig`
-- rust_analyzer = false, -- setting a handler to false will disable the set up of that language server
-- pyright = function(_, opts) require("lspconfig").pyright.setup(opts) end -- or a custom handler function can be passed
},
-- Configure buffer local auto commands to add when attaching a language server
autocmds = {
-- first key is the `augroup` to add the auto commands to (:h augroup)
lsp_codelens_refresh = {
-- Optional condition to create/delete auto command group
-- can either be a string of a client capability or a function of `fun(client, bufnr): boolean`
-- condition will be resolved for each client on each execution and if it ever fails for all clients,
-- the auto commands will be deleted for that buffer
cond = "textDocument/codeLens",
-- cond = function(client, bufnr) return client.name == "lua_ls" end,
-- list of auto commands to set
{
-- events to trigger
event = { "InsertLeave", "BufEnter" },
-- the rest of the autocmd options (:h nvim_create_autocmd)
desc = "Refresh codelens (buffer)",
callback = function(args)
if require("astrolsp").config.features.codelens then vim.lsp.codelens.refresh { bufnr = args.buf } end
end,
},
},
},
-- mappings to be set up on attaching of a language server
mappings = {
n = {
-- a `cond` key can provided as the string of a server capability to be required to attach, or a function with `client` and `bufnr` parameters from the `on_attach` that returns a boolean
gD = {
function() vim.lsp.buf.declaration() end,
desc = "Declaration of current symbol",
cond = "textDocument/declaration",
},
["<Leader>uY"] = {
function() require("astrolsp.toggles").buffer_semantic_tokens() end,
desc = "Toggle LSP semantic highlight (buffer)",
cond = function(client)
return client.supports_method "textDocument/semanticTokens/full" and vim.lsp.semantic_tokens ~= nil
end,
},
},
},
-- A custom `on_attach` function to be run after the default `on_attach` function
-- takes two parameters `client` and `bufnr` (`:h lspconfig-setup`)
on_attach = function(client, bufnr)
-- this would disable semanticTokensProvider for all clients
-- client.server_capabilities.semanticTokensProvider = nil
end,
},
}

View File

@@ -0,0 +1,39 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- AstroUI provides the basis for configuring the AstroNvim User Interface
-- Configuration documentation can be found with `:h astroui`
-- NOTE: We highly recommend setting up the Lua Language Server (`:LspInstall lua_ls`)
-- as this provides autocomplete and documentation while editing
---@type LazySpec
return {
"AstroNvim/astroui",
---@type AstroUIOpts
opts = {
-- change colorscheme
colorscheme = "astrodark",
-- AstroUI allows you to easily modify highlight groups easily for any and all colorschemes
highlights = {
init = { -- this table overrides highlights in all themes
-- Normal = { bg = "#000000" },
},
astrodark = { -- a table of overrides/changes when applying the astrotheme theme
-- Normal = { bg = "#000000" },
},
},
-- Icons can be configured throughout the interface
icons = {
-- configure the loading of the lsp in the status line
LSPLoading1 = "",
LSPLoading2 = "",
LSPLoading3 = "",
LSPLoading4 = "",
LSPLoading5 = "",
LSPLoading6 = "",
LSPLoading7 = "",
LSPLoading8 = "",
LSPLoading9 = "",
LSPLoading10 = "",
},
},
}

View File

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

View File

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

View File

@@ -1,131 +0,0 @@
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

@@ -1,14 +0,0 @@
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,28 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- Customize Mason
---@type LazySpec
return {
-- use mason-tool-installer for automatically installing Mason packages
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
-- overrides `require("mason-tool-installer").setup(...)`
opts = {
-- Make sure to use the names found in `:Mason`
ensure_installed = {
-- install language servers
"lua-language-server",
-- install formatters
"stylua",
-- install debuggers
"debugpy",
-- install any other package
"tree-sitter-cli",
},
},
},
}

View File

@@ -0,0 +1,24 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- Customize None-ls sources
---@type LazySpec
return {
"nvimtools/none-ls.nvim",
opts = function(_, opts)
-- opts variable is the default configuration table for the setup function call
-- local null_ls = require "null-ls"
-- Check supported formatters and linters
-- https://github.com/nvimtools/none-ls.nvim/tree/main/lua/null-ls/builtins/formatting
-- https://github.com/nvimtools/none-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
-- Only insert new sources, do not replace the existing ones
-- (If you wish to replace, use `opts.sources = {}` instead of the `list_insert_unique` function)
opts.sources = require("astrocore").list_insert_unique(opts.sources, {
-- Set a formatter
-- null_ls.builtins.formatting.stylua,
-- null_ls.builtins.formatting.prettier,
})
end,
}

View File

@@ -1,38 +0,0 @@
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

@@ -1,84 +0,0 @@
-- 在你的 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

@@ -1,19 +1,15 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- Customize Treesitter
---@type LazySpec
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,
opts = {
ensure_installed = {
"lua",
"vim",
-- add more arguments for adding more treesitter parsers
},
},
}

View File

@@ -0,0 +1,90 @@
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- You can also add or configure plugins by creating files in this `plugins/` folder
-- PLEASE REMOVE THE EXAMPLES YOU HAVE NO INTEREST IN BEFORE ENABLING THIS FILE
-- Here are some examples:
---@type LazySpec
return {
-- == Examples of Adding Plugins ==
"andweeb/presence.nvim",
{
"ray-x/lsp_signature.nvim",
event = "BufRead",
config = function() require("lsp_signature").setup() end,
},
-- == Examples of Overriding Plugins ==
-- customize dashboard options
{
"folke/snacks.nvim",
opts = {
dashboard = {
preset = {
header = table.concat({
" █████ ███████ ████████ ██████ ██████ ",
"██ ██ ██ ██ ██ ██ ██ ██",
"███████ ███████ ██ ██████ ██ ██",
"██ ██ ██ ██ ██ ██ ██ ██",
"██ ██ ███████ ██ ██ ██ ██████ ",
"",
"███  ██ ██  ██ ██ ███  ███",
"████  ██ ██  ██ ██ ████  ████",
"██ ██  ██ ██  ██ ██ ██ ████ ██",
"██  ██ ██  ██  ██  ██ ██  ██  ██",
"██   ████   ████   ██ ██  ██",
}, "\n"),
},
},
},
},
-- You can disable default plugins as follows:
{ "max397574/better-escape.nvim", enabled = false },
-- You can also easily customize additional setup of plugins that is outside of the plugin's setup call
{
"L3MON4D3/LuaSnip",
config = function(plugin, opts)
-- add more custom luasnip configuration such as filetype extend or custom snippets
local luasnip = require "luasnip"
luasnip.filetype_extend("javascript", { "javascriptreact" })
-- include the default astronvim config that calls the setup call
require "astronvim.plugins.configs.luasnip"(plugin, opts)
end,
},
{
"windwp/nvim-autopairs",
config = function(plugin, opts)
require "astronvim.plugins.configs.nvim-autopairs"(plugin, opts) -- include the default astronvim config that calls the setup call
-- add more custom autopairs configuration such as custom rules
local npairs = require "nvim-autopairs"
local Rule = require "nvim-autopairs.rule"
local cond = require "nvim-autopairs.conds"
npairs.add_rules(
{
Rule("$", "$", { "tex", "latex" })
-- don't add a pair if the next character is %
:with_pair(cond.not_after_regex "%%")
-- don't add a pair if the previous character is xxx
:with_pair(
cond.not_before_regex("xxx", 3)
)
-- don't move right when repeat character
:with_move(cond.none())
-- don't delete if the next character is xx
:with_del(cond.not_after_regex "xx")
-- disable adding a newline when you press <cr>
:with_cr(cond.none()),
},
-- disable for .vim files, but it work for another filetypes
Rule("a", "a", "-vim")
)
end,
},
}

View File

@@ -0,0 +1,5 @@
if true then return end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
-- This will run last in the setup process.
-- This is just pure lua so anything that doesn't
-- fit in the normal config locations above can go here

6
.config/nvim/neovim.yml Normal file
View File

@@ -0,0 +1,6 @@
---
base: lua51
globals:
vim:
any: true

8
.config/nvim/selene.toml Normal file
View File

@@ -0,0 +1,8 @@
std = "neovim"
[rules]
global_usage = "allow"
if_same_then_else = "allow"
incorrect_standard_library_use = "allow"
mixed_table = "allow"
multiple_statements = "allow"