neovim

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Neovim Configuration Skill

Neovim配置指南

A comprehensive guide for working with this modular, performance-optimized Neovim configuration built on lazy.nvim.
这份全面指南介绍了基于lazy.nvim构建的模块化、性能优化的Neovim配置。

Quick Reference

快速参考

MetricValue
Plugin Managerlazy.nvim
Total Plugins82
Target Startup<50ms
Module Pattern
M.setup()
Leader Key
<Space>
指标数值
插件管理器lazy.nvim
插件总数82
目标启动时间<50ms
模块模式
M.setup()
引导键
<Space>

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
M.setup()
pattern:
lua
local M = {}

M.setup = function()
  -- Configuration logic here
end

return M
所有配置模块均遵循
M.setup()
模式:
lua
local M = {}

M.setup = function()
  -- 配置逻辑写在这里
end

return M

Plugin 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

加载策略

StrategyWhen to UseExample
lazy = true
Default, load on demandMost plugins
event = "VeryLazy"
After UI loadsUI enhancements
event = "BufReadPre"
When opening filesTreesitter, gitsigns
event = "InsertEnter"
When typingCompletion, autopairs
cmd = "CommandName"
On command invocationHeavy tools
ft = "filetype"
For specific filetypesLanguage plugins
keys = {...}
On keypressMotion plugins
策略使用场景示例
lazy = true
默认策略,按需加载大多数插件
event = "VeryLazy"
UI加载完成后加载UI增强插件
event = "BufReadPre"
打开文件时加载Treesitter, gitsigns
event = "InsertEnter"
进入插入模式时加载补全插件, autopairs
cmd = "CommandName"
执行对应命令时加载重型工具插件
ft = "filetype"
针对特定文件类型加载语言相关插件
keys = {...}
按下对应按键时加载移动类插件

Plugin Commands

插件命令

CommandDescription
:Lazy
Open lazy.nvim dashboard
:Lazy sync
Update and install plugins
:Lazy profile
Show startup time analysis
:Lazy clean
Remove unused plugins
:Lazy health
Check plugin health
命令描述
:Lazy
打开lazy.nvim控制面板
:Lazy sync
更新并安装插件
:Lazy profile
显示启动时间分析
:Lazy clean
移除未使用的插件
:Lazy health
检查插件健康状态

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按键绑定

KeyAction
gd
Go to definition
gr
Go to references
gI
Go to implementation
gD
Go to declaration
K
Hover documentation
<leader>rn
Rename symbol
<leader>ca
Code action
<leader>D
Type definition
<leader>ds
Document symbols
<leader>ws
Workspace symbols
按键操作
gd
跳转到定义
gr
跳转到引用
gI
跳转到实现
gD
跳转到声明
K
悬浮文档
<leader>rn
重命名符号
<leader>ca
代码操作
<leader>D
类型定义
<leader>ds
文档符号
<leader>ws
工作区符号

Keybindings

按键绑定

See references/keybindings.md for complete reference.
完整参考请查看references/keybindings.md

Core Navigation

核心导航

KeyAction
<C-h/j/k/l>
Window navigation
<S-h>
/
<S-l>
Previous/next buffer
<leader>sf
Search files
<leader>sg
Search by grep
<leader><space>
Search buffers
\\
Toggle Neo-tree
按键操作
<C-h/j/k/l>
窗口导航
<S-h>
/
<S-l>
上一个/下一个缓冲区
<leader>sf
搜索文件
<leader>sg
Grep搜索
<leader><space>
搜索缓冲区
\\
切换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按键绑定

KeyAction
<F5>
Continue/Start debugging
<F10>
Step over
<F11>
Step into
<F12>
Step out
<leader>b
Toggle breakpoint
<leader>B
Conditional breakpoint
按键操作
<F5>
继续/启动调试
<F10>
单步跳过
<F11>
单步进入
<F12>
单步退出
<leader>b
切换断点
<leader>B
条件断点

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

启动优化层级

LayerTechniqueSavings
1
vim.loader.enable()
~50ms
2Skip
vim._defaults
~180ms
3Disable providers~10ms
4Disable builtins~20ms
5Deferred config~30ms
6Event-based loadingVariable
层级技术节省时间
1
vim.loader.enable()
~50ms
2跳过
vim._defaults
~180ms
3禁用提供者~10ms
4禁用内置组件~20ms
5延迟配置~30ms
6基于事件的加载可变

Profiling Startup

分析启动性能

vim
:Lazy profile
vim
:Lazy profile

Deferred 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 = value
lua
-- 在lua/config/options.lua的M.setup()中:
vim.opt.your_option = value

Creating 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.nvim
,
nui.nvim
,
nvim-web-devicons
,
lazy.nvim
plenary.nvim
,
nui.nvim
,
nvim-web-devicons
,
lazy.nvim

UI (11 plugins)

UI(11个插件)

tokyonight
,
alpha-nvim
,
lualine
,
bufferline
,
noice
,
nvim-notify
,
which-key
,
indent-blankline
,
mini.indentscope
,
fidget
,
nvim-scrollbar
tokyonight
,
alpha-nvim
,
lualine
,
bufferline
,
noice
,
nvim-notify
,
which-key
,
indent-blankline
,
mini.indentscope
,
fidget
,
nvim-scrollbar

Editor (13 plugins)

编辑器增强(13个插件)

nvim-autopairs
,
flash.nvim
,
clever-f
,
nvim-spectre
,
grug-far
,
harpoon
,
persistence
,
smartyank
,
vim-sleuth
,
vim-illuminate
,
tabular
,
todo-comments
,
toggleterm
nvim-autopairs
,
flash.nvim
,
clever-f
,
nvim-spectre
,
grug-far
,
harpoon
,
persistence
,
smartyank
,
vim-sleuth
,
vim-illuminate
,
tabular
,
todo-comments
,
toggleterm

LSP (12 plugins)

LSP(12个插件)

nvim-lspconfig
,
mason
,
mason-lspconfig
,
mason-tool-installer
,
lazydev
,
luvit-meta
,
SchemaStore
,
conform
,
nvim-lint
,
trouble
,
blink.cmp
/
nvim-cmp
,
LuaSnip
nvim-lspconfig
,
mason
,
mason-lspconfig
,
mason-tool-installer
,
lazydev
,
luvit-meta
,
SchemaStore
,
conform
,
nvim-lint
,
trouble
,
blink.cmp
/
nvim-cmp
,
LuaSnip

Git (7 plugins)

Git(7个插件)

vim-fugitive
,
vim-rhubarb
,
gitsigns
,
diffview
,
vim-flog
,
git-conflict
,
octo
vim-fugitive
,
vim-rhubarb
,
gitsigns
,
diffview
,
vim-flog
,
git-conflict
,
octo

AI (3 plugins)

AI(3个插件)

copilot.vim
,
ChatGPT.nvim
,
mcphub.nvim
copilot.vim
,
ChatGPT.nvim
,
mcphub.nvim

Debug (8 plugins)

调试(8个插件)

nvim-dap
,
nvim-dap-ui
,
nvim-dap-virtual-text
,
nvim-dap-python
,
nvim-dap-go
,
mason-nvim-dap
,
telescope-dap
,
nvim-nio
nvim-dap
,
nvim-dap-ui
,
nvim-dap-virtual-text
,
nvim-dap-python
,
nvim-dap-go
,
mason-nvim-dap
,
telescope-dap
,
nvim-nio

Tools (14 plugins)

工具(14个插件)

telescope
,
telescope-fzf-native
,
telescope-ui-select
,
neo-tree
,
oil.nvim
,
nvim-bqf
,
rest.nvim
,
vim-dadbod
,
vim-dadbod-ui
,
vim-dadbod-completion
,
iron.nvim
,
markdown-preview
,
nvim-puppeteer
,
obsidian.nvim
telescope
,
telescope-fzf-native
,
telescope-ui-select
,
neo-tree
,
oil.nvim
,
nvim-bqf
,
rest.nvim
,
vim-dadbod
,
vim-dadbod-ui
,
vim-dadbod-completion
,
iron.nvim
,
markdown-preview
,
nvim-puppeteer
,
obsidian.nvim

Treesitter (3 plugins)

语法解析(3个插件)

nvim-treesitter
,
nvim-treesitter-context
,
nvim-treesitter-textobjects
nvim-treesitter
,
nvim-treesitter-context
,
nvim-treesitter-textobjects

Troubleshooting

故障排除

IssueSolution
Plugins not loading
:Lazy sync
LSP not starting
:LspInfo
,
:Mason
Icons missingInstall a Nerd Font
Slow startup
:Lazy profile
Treesitter errors
:TSUpdate
Keybinding conflicts
:verbose map <key>
问题解决方案
插件未加载
:Lazy sync
LSP未启动
:LspInfo
,
:Mason
图标缺失安装Nerd Font
启动缓慢
:Lazy profile
Treesitter错误
:TSUpdate
按键绑定冲突
:verbose map <key>

Health Check

健康检查

vim
:checkhealth
vim
:checkhealth

Debug 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迁移指南