现在各种AI编辑器层出不穷,每天都在有新的AI推出,也有新的IDE推出,说实话有点追累了,回想起10多年前在大学里,一个人在图书馆,用着简单的编辑器,一个字一个字的敲代码,顺利运行出结果,那份快乐是无法形容的;
所以虽然工作中用cursor、kiro、claude code,但是自己一个人的时候还是想安静的写代码;所以nvim又捡了起来:
1.安装:
# 安装nvim brew install neovim # 安装Node.js brew install node # 安装riggrep brew install ripgrep # 安装LazyVim git clone https://github.com/LazyVim/starter ~/.config/nvim rm -rf ~/.config/nvim/.git
2.启动并安装
nvim
⚡ 首次启动
- LazyVim 会自动安装所有插件
- 等待安装完成(可能需要几分钟)
- 按
q
退出安装界面
3.安装必要的LSP服务器
在 Neovim 中运行:
<VIM命令> :Mason
然后安装以下语言服务器:
typescript-language-server
(必须)
eslint-lsp
(推荐)
prettier
(推荐)
css-lsp
(CSS 支持)
按键j和k用来上下选择插件,i安装
4.Next.js的lua配置
-- ~/.config/nvim/lua/plugins/nextjs.lua return { -- TypeScript/JavaScript 语法高亮和解析 { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) if type(opts.ensure_installed) == "table" then vim.list_extend(opts.ensure_installed, { "javascript", "typescript", "tsx", "jsx", "json", "css", "scss", "html", "markdown", "yaml", }) end end, }, -- LSP 配置 { "neovim/nvim-lspconfig", opts = { servers = { -- TypeScript Language Server tsserver = { settings = { typescript = { preferences = { importModuleSpecifier = "relative", }, }, javascript = { preferences = { importModuleSpecifier = "relative", }, }, }, }, -- Tailwind CSS (Next.js 项目常用) tailwindcss = { filetypes = { "html", "css", "scss", "javascript", "javascriptreact", "typescript", "typescriptreact", }, }, -- CSS Language Server cssls = {}, -- JSON Language Server jsonls = {}, }, }, }, -- Emmet 支持,对于 JSX/TSX 很有用 { "mattn/emmet-vim", ft = { "html", "css", "javascript", "javascriptreact", "typescript", "typescriptreact" }, init = function() vim.g.user_emmet_leader_key = "<C-z>" vim.g.user_emmet_settings = { javascript = { extends = "jsx", }, typescript = { extends = "tsx", }, } end, }, -- 自动补全括号和标签 { "windwp/nvim-autopairs", event = "InsertEnter", opts = { check_ts = true, ts_config = { lua = { "string", "source" }, javascript = { "string", "template_string" }, typescript = { "string", "template_string" }, }, }, }, -- 注释掉有问题的代码片段插件 -- { -- "dsznajder/vscode-es6-javascript-snippets", -- build = "yarn install --frozen-lockfile && yarn compile", -- event = { "BufReadPre", "BufNewFile" }, -- ft = { -- "javascript", -- "javascriptreact", -- "typescript", -- "typescriptreact", -- }, -- }, -- 自动标签关闭和重命名 { "windwp/nvim-ts-autotag", event = { "BufReadPre", "BufNewFile" }, ft = { "html", "javascript", "javascriptreact", "typescript", "typescriptreact", "xml", }, config = function() require("nvim-ts-autotag").setup() end, }, -- 文件图标 { "nvim-tree/nvim-web-devicons", opts = { override = { js = { icon = "", color = "#f1e05a", name = "Js", }, ts = { icon = "", color = "#3178c6", name = "Ts", }, jsx = { icon = "", color = "#61dafb", name = "Jsx", }, tsx = { icon = "", color = "#61dafb", name = "Tsx", }, }, }, }, -- Package.json 支持 { "vuki656/package-info.nvim", ft = "json", config = function() require("package-info").setup() end, }, }
5.开始编程
cd 项目目录 nvim .