neovim 配置 (100%lua)
pre-acquisition
- neovim
brew install neovim
- 在 neovim 中使用 Lua
- lua语法
配置文件
入口文件
neovim 从 init.lua
文件加载配置。该文件位于 runtimepath
中。
runtimapath: 在 *nix 系统上为 ~/.config/nvim/lua
,在 Windows 系统上为 ~/appdata/Local/nvim/lua
)。
模块
Lua 模块通常位于您的 runtimepath
中的 lua/
文件夹中这意味着您可以 require()
这些文件作为 Lua 模块
动手做
1. 快捷键模块
- 创建
runtimepath
:在~/.config/
路径下创建nvim/
文件夹。 - 在
runtimepath
中创建lua/
文件夹,init.lua
入口文件,在lua/
文件夹中创建keymaps.lua
快捷键模块文件。 - 编辑
keymaps.lua
快捷键模块文件 ➤➤➤ - 在
init.lua
入口文件中导入快捷键模块。
2. 插件管理器
使用 Packer 作为插件管理器
packer.nvim: A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
安装
Unix, Linux Installation
在
lua/
文件夹中创建并编辑plugins.lua
文件。在
init.lua
入口文件中导入插件管理器模块。在
neovim
中使用:PackerSync
命令安装插件。此步骤需要网络能正常访问github
3. 主题模块
安装主题 catppuccin
编辑plugins.lua
文件在
pcall() 用于捕获异常,当主题加载失败时,不至于 neovim 启动失败 vim.cmd(colorscheme .. colorscheme),等同于执行 :colorscheme catppuccin 命令lua/
文件夹中创建并编辑colorscheme.lua
文件。在
init.lua
入口文件中导入主题模块。保存退出后,运行
:PackerSync
命令。
4. 文件浏览器模块
使用 nvim-tree.lua 作为文件浏览器。
nvim-tree: A file explorer tree for neovim written in lua
⚠️ nvim-tree 依赖 Nerd Fonts
Nerd Fonts ➤➤➤
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
lua/
文件夹中创建conf/
文件夹 - 在
conf/
文件夹中创建init.lua
文件 - 在
conf/
文件夹中创建nvim-tree.lua
文件
在 init.lua
入口文件中导入 conf
模块
编辑 conf/init.lua
文件
编辑 nvim-tree.lua
文件
5. Buffer 管理模块
使用 bufferline 作为 Buffer 管理模块。
bufferline.nvim: A snazzy 💅 buffer line (with tabpage integration) for Neovim built using lua.
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
conf/
文件夹中创建bufferline.lua
文件
编辑 conf/init.lua
文件
编辑 bufferline.lua
文件
🚗 保存退出后,运行:PackerSync
⌨️ 快捷键设置
6. 搜索模块
使用 telescope 作为搜索模块。
telescope.nvim is a highly extendable fuzzy finder over lists. Built on the latest awesome features from neovim core. Telescope is centered around modularity, allowing for easy customization. %}
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
conf/
文件夹中创建telescope.lua
文件
编辑 conf/init.lua
文件
编辑 telescope.lua
文件
🌟 使用 fzf
搜索引擎 telescope-fzf-native
🚗 保存退出后,运行:PackerSync
⌨️ 快捷键设置
7. 语法高亮
使用 nvim-treesitter 实现语法高亮。
nvim-treesitter: Nvim Treesitter configurations and abstraction layer.
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
conf/
文件夹中创建treesitter.lua
文件
编辑 conf/init.lua
文件
编辑 treesitter.lua
文件
8. 状态栏模块
使用 lualine 作为状态栏。
lualine.nvim: A blazing fast and easy to configure Neovim statusline written in Lua.
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
conf/
文件夹中创建lualine.lua
文件
编辑 conf/init.lua
文件
编辑 lualine.lua
文件
🚗 保存退出后,运行:PackerSync
⌨️ 快捷键设置
9. 欢迎页
使用 alpha-nvim 作为欢迎页。
alpha-nvim: a lua powered greeter like vim-startify / dashboard-nvim.
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
conf/
文件夹中创建alpha.lua
文件
编辑 conf/init.lua
文件
编辑 alpha.lua
文件
🚗 保存退出后,运行:PackerSync
⌨️ 快捷键设置
10. lsp 模块
neovim lsp 文档 ➤➤➤ 📚📚📚
语言服务器协议(LSP)定义了编辑器或IDE与语言服务器之间使用的协议,该协议提供自动补全、转到定义、查找所有引用等语言功能。
Nvim提供了一个LSP客户端,但服务器由第三方提供。
- 安装 Nvim LSP 客户端:nvim-lspconfig
- 安装 LSP 服务器管理器:mason.nvim
mason.nvim: Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
- 安装 LSP 服务器
💾 安装插件
编辑 plugins.lua
文件
📃 配置文件
- 在
lua/
文件夹中创建lsp/
文件夹 - 在
lsp/
文件夹中创建init.lua
文件 - 在
lsp/
文件夹中创建mason.lua
文件
在 init.lua
入口文件中导入 lsp
模块
编辑 lsp/init.lua
文件
编辑 mason.lua
文件
🚗 执行:PackerSync命令
🩻 执行 :checkhealth mason 检查 maosn 安装情况
🚀 执行 :mason 安装相应的 LSP
11. dap 模块
安装字体(用于显示图标)
Nerd Fonts 是一个使用大量字体图标来解决程序员在开发过程中缺少合适字体的问题的项目。
Referance
[1] jjmyag,从Goland转到Neovim