Tools

Neovim 现代化配置:从零打造一个高性能 IDE

✎ -- 字 🕐 -- 分钟
字号

为什么 Neovim

VS Code 很棒,但当项目变大、插件变多时,内存占用和响应延迟会逐渐显现。Neovim 基于 Lua 的全新插件生态让终端编辑器焕发新生:启动<50ms,内存<100MB。

Lazy.nvim 插件管理

-- ~/.config/nvim/lua/plugins/init.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  -- 颜色主题
  { "catppuccin/nvim", name = "catppuccin", priority = 1000 },
  -- 文件树
  { "nvim-neo-tree/neo-tree.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
  -- 模糊搜索
  { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
  -- LSP 支持
  { "neovim/nvim-lspconfig" },
  { "hrsh7th/nvim-cmp", dependencies = { "hrsh7th/cmp-nvim-lsp" } },
  -- Treesitter 高亮
  { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
})

LSP 与自动补全

-- 自动安装 language servers
require("mason").setup()
require("mason-lspconfig").setup({
  ensure_installed = { "lua_ls", "tsserver", "rust_analyzer", "gopls", "pyright" }
})

-- nvim-cmp 配置
local cmp = require("cmp")
cmp.setup({
  mapping = cmp.mapping.preset.insert({
    ["<Tab>"] = cmp.mapping.select_next_item(),
    ["<CR>"] = cmp.mapping.confirm({ select = true }),
  }),
  sources = { { name = "nvim_lsp" }, { name = "luasnip" }, { name = "path" } },
})

生产效率 Tips

  • Telescope<leader>ff 搜索文件,<leader>fg 全局搜索文本
  • Which-Key:忘记快捷键时按 <leader> 弹出提示
  • Harpoon:标记常用文件,一键跳转
  • UndoTree:可视化撤销历史
  • Oil.nvim:像编辑文本一样管理文件