neovim
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNeovim Configuration Skill
Neovim配置指南
A comprehensive guide for working with this modular, performance-optimized Neovim configuration built on lazy.nvim.
这份全面指南介绍了基于lazy.nvim构建的模块化、性能优化的Neovim配置。
Quick Reference
快速参考
| Metric | Value |
|---|---|
| Plugin Manager | lazy.nvim |
| Total Plugins | 82 |
| Target Startup | <50ms |
| Module Pattern | |
| Leader Key | |
| 指标 | 数值 |
|---|---|
| 插件管理器 | lazy.nvim |
| 插件总数 | 82 |
| 目标启动时间 | <50ms |
| 模块模式 | |
| 引导键 | |
Architecture Overview
架构概述
~/.config/nvim/
├── init.lua # Entry point
├── lua/
│ ├── config/ # Core configuration (11 modules)
│ │ ├── lazy.lua # Plugin manager bootstrap
│ │ ├── options.lua # Vim options
│ │ ├── keymaps.lua # Key bindings
│ │ ├── autocmds.lua # Autocommands
│ │ └── performance.lua # Startup optimization
│ ├── plugins/specs/ # Plugin specs (9 categories)
│ │ ├── core.lua # Foundation (plenary, nui, devicons)
│ │ ├── ui.lua # UI (lualine, bufferline, noice)
│ │ ├── editor.lua # Editor (autopairs, flash, harpoon)
│ │ ├── lsp.lua # LSP (lspconfig, mason, conform)
│ │ ├── git.lua # Git (fugitive, gitsigns, diffview)
│ │ ├── ai.lua # AI (copilot, ChatGPT)
│ │ ├── debug.lua # DAP (nvim-dap, dap-ui)
│ │ ├── tools.lua # Tools (telescope, neo-tree)
│ │ └── treesitter.lua # Syntax (treesitter, textobjects)
│ ├── kickstart/ # Kickstart-derived modules
│ └── utils/ # Utility functions
└── lazy-lock.json # Plugin version lock~/.config/nvim/
├── init.lua # 入口文件
├── lua/
│ ├── config/ # 核心配置(11个模块)
│ │ ├── lazy.lua # 插件管理器引导文件
│ │ ├── options.lua # Vim选项配置
│ │ ├── keymaps.lua # 按键绑定配置
│ │ ├── autocmds.lua # 自动命令配置
│ │ └── performance.lua # 启动优化配置
│ ├── plugins/specs/ # 插件规格(9个分类)
│ │ ├── core.lua # 基础插件(plenary, nui, devicons)
│ │ ├── ui.lua # UI插件(lualine, bufferline, noice)
│ │ ├── editor.lua # 编辑器增强插件(autopairs, flash, harpoon)
│ │ ├── lsp.lua # LSP相关插件(lspconfig, mason, conform)
│ │ ├── git.lua # Git相关插件(fugitive, gitsigns, diffview)
│ │ ├── ai.lua # AI集成插件(copilot, ChatGPT)
│ │ ├── debug.lua # DAP调试插件(nvim-dap, dap-ui)
│ │ ├── tools.lua # 工具类插件(telescope, neo-tree)
│ │ └── treesitter.lua # 语法解析插件(treesitter, textobjects)
│ ├── kickstart/ # 衍生自Kickstart的模块
│ └── utils/ # 工具函数
└── lazy-lock.json # 插件版本锁定文件Standard Module Pattern
标准模块模式
All configuration modules follow the pattern:
M.setup()lua
local M = {}
M.setup = function()
-- Configuration logic here
end
return M所有配置模块均遵循模式:
M.setup()lua
local M = {}
M.setup = function()
-- 配置逻辑写在这里
end
return MPlugin Management (lazy.nvim)
插件管理(lazy.nvim)
Adding a New Plugin
添加新插件
Add to the appropriate category file in :
lua/plugins/specs/lua
-- lua/plugins/specs/tools.lua
return {
-- Existing plugins...
{
"author/plugin-name",
event = "VeryLazy", -- Loading strategy
dependencies = { "dep/name" }, -- Required plugins
opts = {
-- Plugin options
},
config = function(_, opts)
require("plugin-name").setup(opts)
end,
},
}在下对应的分类文件中添加:
lua/plugins/specs/lua
-- lua/plugins/specs/tools.lua
return {
-- 已有插件...
{
"author/plugin-name",
event = "VeryLazy", -- 加载策略
dependencies = { "dep/name" }, -- 依赖插件
opts = {
-- 插件选项
},
config = function(_, opts)
require("plugin-name").setup(opts)
end,
},
}Loading Strategies
加载策略
| Strategy | When to Use | Example |
|---|---|---|
| Default, load on demand | Most plugins |
| After UI loads | UI enhancements |
| When opening files | Treesitter, gitsigns |
| When typing | Completion, autopairs |
| On command invocation | Heavy tools |
| For specific filetypes | Language plugins |
| On keypress | Motion plugins |
| 策略 | 使用场景 | 示例 |
|---|---|---|
| 默认策略,按需加载 | 大多数插件 |
| UI加载完成后加载 | UI增强插件 |
| 打开文件时加载 | Treesitter, gitsigns |
| 进入插入模式时加载 | 补全插件, autopairs |
| 执行对应命令时加载 | 重型工具插件 |
| 针对特定文件类型加载 | 语言相关插件 |
| 按下对应按键时加载 | 移动类插件 |
Plugin Commands
插件命令
| Command | Description |
|---|---|
| Open lazy.nvim dashboard |
| Update and install plugins |
| Show startup time analysis |
| Remove unused plugins |
| Check plugin health |
| 命令 | 描述 |
|---|---|
| 打开lazy.nvim控制面板 |
| 更新并安装插件 |
| 显示启动时间分析 |
| 移除未使用的插件 |
| 检查插件健康状态 |
LSP Configuration
LSP配置
See references/lsp.md for complete LSP reference.
完整LSP参考请查看references/lsp.md。
LSP Stack
LSP栈
mason.nvim (installer)
├── mason-lspconfig.nvim → nvim-lspconfig
├── mason-tool-installer.nvim (auto-install)
└── mason-nvim-dap.nvim → nvim-dap
nvim-lspconfig
├── blink.cmp (completion)
├── conform.nvim (formatting)
├── nvim-lint (linting)
└── trouble.nvim (diagnostics)mason.nvim (安装器)
├── mason-lspconfig.nvim → nvim-lspconfig
├── mason-tool-installer.nvim (自动安装)
└── mason-nvim-dap.nvim → nvim-dap
nvim-lspconfig
├── blink.cmp (补全)
├── conform.nvim (格式化)
├── nvim-lint (代码检查)
└── trouble.nvim (诊断信息)Adding an LSP Server
添加LSP服务器
lua
-- In lua/plugins/specs/lsp.lua, add to mason-tool-installer list:
ensure_installed = {
"lua_ls",
"pyright",
"your_new_server", -- Add here
}
-- Configure in lspconfig setup:
servers = {
your_new_server = {
settings = {
-- Server-specific settings
},
},
}lua
-- 在lua/plugins/specs/lsp.lua中,添加到mason-tool-installer列表:
ensure_installed = {
"lua_ls",
"pyright",
"your_new_server", -- 在这里添加
}
-- 在lspconfig设置中配置:
servers = {
your_new_server = {
settings = {
-- 服务器特定设置
},
},
}LSP Keybindings
LSP按键绑定
| Key | Action |
|---|---|
| Go to definition |
| Go to references |
| Go to implementation |
| Go to declaration |
| Hover documentation |
| Rename symbol |
| Code action |
| Type definition |
| Document symbols |
| Workspace symbols |
| 按键 | 操作 |
|---|---|
| 跳转到定义 |
| 跳转到引用 |
| 跳转到实现 |
| 跳转到声明 |
| 悬浮文档 |
| 重命名符号 |
| 代码操作 |
| 类型定义 |
| 文档符号 |
| 工作区符号 |
Keybindings
按键绑定
See references/keybindings.md for complete reference.
完整参考请查看references/keybindings.md。
Core Navigation
核心导航
| Key | Action |
|---|---|
| Window navigation |
| Previous/next buffer |
| Search files |
| Search by grep |
| Search buffers |
| Toggle Neo-tree |
| 按键 | 操作 |
|---|---|
| 窗口导航 |
| 上一个/下一个缓冲区 |
| 搜索文件 |
| Grep搜索 |
| 搜索缓冲区 |
| 切换Neo-tree |
Adding Keybindings
添加按键绑定
lua
-- In lua/config/keymaps.lua M.setup():
vim.keymap.set('n', '<leader>xx', function()
-- Your action
end, { desc = 'Description for which-key' })
-- Or in a plugin spec:
keys = {
{ "<leader>xx", "<cmd>Command<CR>", desc = "Description" },
}lua
-- 在lua/config/keymaps.lua的M.setup()中:
vim.keymap.set('n', '<leader>xx', function()
-- 你的操作
end, { desc = 'which-key描述' })
-- 或者在插件规格中:
keys = {
{ "<leader>xx", "<cmd>Command<CR>", desc = "描述" },
}Debugging (DAP)
调试(DAP)
See references/debugging.md for complete reference.
完整调试参考请查看references/debugging.md。
DAP Keybindings
DAP按键绑定
| Key | Action |
|---|---|
| Continue/Start debugging |
| Step over |
| Step into |
| Step out |
| Toggle breakpoint |
| Conditional breakpoint |
| 按键 | 操作 |
|---|---|
| 继续/启动调试 |
| 单步跳过 |
| 单步进入 |
| 单步退出 |
| 切换断点 |
| 条件断点 |
Adding a Debug Adapter
添加调试适配器
lua
-- In lua/plugins/specs/debug.lua
local dap = require("dap")
dap.adapters.your_adapter = {
type = "executable",
command = "path/to/adapter",
}
dap.configurations.your_filetype = {
{
type = "your_adapter",
request = "launch",
name = "Launch",
program = "${file}",
},
}lua
-- 在lua/plugins/specs/debug.lua中
local dap = require("dap")
dap.adapters.your_adapter = {
type = "executable",
command = "path/to/adapter",
}
dap.configurations.your_filetype = {
{
type = "your_adapter",
request = "launch",
name = "启动",
program = "${file}",
},
}Performance Optimization
性能优化
Startup Optimization Layers
启动优化层级
| Layer | Technique | Savings |
|---|---|---|
| 1 | | ~50ms |
| 2 | Skip | ~180ms |
| 3 | Disable providers | ~10ms |
| 4 | Disable builtins | ~20ms |
| 5 | Deferred config | ~30ms |
| 6 | Event-based loading | Variable |
| 层级 | 技术 | 节省时间 |
|---|---|---|
| 1 | | ~50ms |
| 2 | 跳过 | ~180ms |
| 3 | 禁用提供者 | ~10ms |
| 4 | 禁用内置组件 | ~20ms |
| 5 | 延迟配置 | ~30ms |
| 6 | 基于事件的加载 | 可变 |
Profiling Startup
分析启动性能
vim
:Lazy profilevim
:Lazy profileDeferred Loading Pattern
延迟加载模式
lua
-- In init.lua
vim.defer_fn(function()
require('config.options').setup()
require('config.keymaps').setup()
require('config.autocmds').setup()
end, 0)lua
-- 在init.lua中
vim.defer_fn(function()
require('config.options').setup()
require('config.keymaps').setup()
require('config.autocmds').setup()
end, 0)Common Tasks
常见任务
Adding an Autocommand
添加自动命令
lua
-- In lua/config/autocmds.lua M.setup():
vim.api.nvim_create_autocmd("FileType", {
pattern = { "markdown", "text" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})lua
-- 在lua/config/autocmds.lua的M.setup()中:
vim.api.nvim_create_autocmd("FileType", {
pattern = { "markdown", "text" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})Adding Vim Options
添加Vim选项
lua
-- In lua/config/options.lua M.setup():
vim.opt.your_option = valuelua
-- 在lua/config/options.lua的M.setup()中:
vim.opt.your_option = valueCreating a Utility Function
创建工具函数
lua
-- In lua/utils/init.lua
local M = {}
M.your_function = function(args)
-- Implementation
end
return M
-- Usage: require('utils').your_function(args)lua
-- 在lua/utils/init.lua中
local M = {}
M.your_function = function(args)
-- 实现逻辑
end
return M
-- 使用方式:require('utils').your_function(args)Plugin Categories
插件分类
Core (4 plugins)
核心(4个插件)
plenary.nvimnui.nvimnvim-web-deviconslazy.nvimplenary.nvimnui.nvimnvim-web-deviconslazy.nvimUI (11 plugins)
UI(11个插件)
tokyonightalpha-nvimlualinebufferlinenoicenvim-notifywhich-keyindent-blanklinemini.indentscopefidgetnvim-scrollbartokyonightalpha-nvimlualinebufferlinenoicenvim-notifywhich-keyindent-blanklinemini.indentscopefidgetnvim-scrollbarEditor (13 plugins)
编辑器增强(13个插件)
nvim-autopairsflash.nvimclever-fnvim-spectregrug-farharpoonpersistencesmartyankvim-sleuthvim-illuminatetabulartodo-commentstoggletermnvim-autopairsflash.nvimclever-fnvim-spectregrug-farharpoonpersistencesmartyankvim-sleuthvim-illuminatetabulartodo-commentstoggletermLSP (12 plugins)
LSP(12个插件)
nvim-lspconfigmasonmason-lspconfigmason-tool-installerlazydevluvit-metaSchemaStoreconformnvim-linttroubleblink.cmpnvim-cmpLuaSnipnvim-lspconfigmasonmason-lspconfigmason-tool-installerlazydevluvit-metaSchemaStoreconformnvim-linttroubleblink.cmpnvim-cmpLuaSnipGit (7 plugins)
Git(7个插件)
vim-fugitivevim-rhubarbgitsignsdiffviewvim-floggit-conflictoctovim-fugitivevim-rhubarbgitsignsdiffviewvim-floggit-conflictoctoAI (3 plugins)
AI(3个插件)
copilot.vimChatGPT.nvimmcphub.nvimcopilot.vimChatGPT.nvimmcphub.nvimDebug (8 plugins)
调试(8个插件)
nvim-dapnvim-dap-uinvim-dap-virtual-textnvim-dap-pythonnvim-dap-gomason-nvim-daptelescope-dapnvim-nionvim-dapnvim-dap-uinvim-dap-virtual-textnvim-dap-pythonnvim-dap-gomason-nvim-daptelescope-dapnvim-nioTools (14 plugins)
工具(14个插件)
telescopetelescope-fzf-nativetelescope-ui-selectneo-treeoil.nvimnvim-bqfrest.nvimvim-dadbodvim-dadbod-uivim-dadbod-completioniron.nvimmarkdown-previewnvim-puppeteerobsidian.nvimtelescopetelescope-fzf-nativetelescope-ui-selectneo-treeoil.nvimnvim-bqfrest.nvimvim-dadbodvim-dadbod-uivim-dadbod-completioniron.nvimmarkdown-previewnvim-puppeteerobsidian.nvimTreesitter (3 plugins)
语法解析(3个插件)
nvim-treesitternvim-treesitter-contextnvim-treesitter-textobjectsnvim-treesitternvim-treesitter-contextnvim-treesitter-textobjectsTroubleshooting
故障排除
| Issue | Solution |
|---|---|
| Plugins not loading | |
| LSP not starting | |
| Icons missing | Install a Nerd Font |
| Slow startup | |
| Treesitter errors | |
| Keybinding conflicts | |
| 问题 | 解决方案 |
|---|---|
| 插件未加载 | |
| LSP未启动 | |
| 图标缺失 | 安装Nerd Font |
| 启动缓慢 | |
| Treesitter错误 | |
| 按键绑定冲突 | |
Health Check
健康检查
vim
:checkhealthvim
:checkhealthDebug Logging
调试日志
lua
-- Temporarily add to plugin config:
log_level = vim.log.levels.DEBUG,lua
-- 临时添加到插件配置中:
log_level = vim.log.levels.DEBUG,Resources
资源
References
参考文档
- references/configuration.md - Core configuration options
- references/plugins.md - All 82 plugins detailed
- references/plugin-deepdives.md - In-depth plugin guides
- references/lsp.md - LSP server configuration
- references/keybindings.md - Complete keybinding reference
- references/debugging.md - DAP debugging guide
- references/performance.md - Optimization techniques
- references/tools.md - CLI tools, utilities, and workflows
- references/troubleshooting.md - Common issues and solutions
- references/migration-0.11.md - Neovim 0.11 migration guide
- references/configuration.md - 核心配置选项
- references/plugins.md - 所有82个插件详情
- references/plugin-deepdives.md - 插件深度指南
- references/lsp.md - LSP服务器配置
- references/keybindings.md - 完整按键绑定参考
- references/debugging.md - DAP调试指南
- references/performance.md - 优化技巧
- references/tools.md - CLI工具、实用程序与工作流
- references/troubleshooting.md - 常见问题与解决方案
- references/migration-0.11.md - Neovim 0.11迁移指南