Neovim 配置
当前使用最多的 Neovim 配置,是基于 Josean Martinez 的 YouTube 视频,一步一步,照虎画猫,依葫芦画瓢,慢慢搭建起来的。后面又结合 Mr Jakob 的 nvim-from-scrach 系列,借鉴和优化了部分配置文件。
配置结构
因为是最常用的配置版本,所以配置文件放置在 ~/AppData/Local/nvim/
内,相当于是配置文件的根目录。本配置使用了 lazy.nvim 作为插件管理器,采用了结构化的配置方法。以下是配置结构:
C:\Users\Lenovo\AppData\Local\nvim
├── init.lua
├── lazy-lock.json
├── lazyvim.json
├── lua
| └── alowree
| ├── core
| | ├── init.lua
| | ├── keymaps.lua
| | └── options.lua
| ├── lazy.lua
| └── plugins
| ├── alpha-alpha.lua
| ├── auto-session.lua
| ├── blink-cmp.lua
| ├── bufferline.lua
| ├── bullets.lua
| ├── colorscheme.lua
| ├── comment.lua
| ├── conform.lua
| ├── dressing.lua
| ├── fzflua.lua
| ├── gitsigns.lua
| ├── indent-blankline.lua
| ├── init.lua
| ├── lazygit.lua
| ├── lsp.lua
| ├── lualine.lua
| ├── nvim-tree.lua
| ├── pangu.lua
| ├── sleuth-vim.lua
| ├── surround.lua
| ├── treesitter.lua
| └── which-key.lua
└── spell
├── en.utf-8.add
└── en.utf-8.add.spl
1、init.lua
是主配置文件,导入了两组文件:
require("alowree.core")
require("alowree.lazy")
2、alowree/core/init.lua
导入了 keymaps.lua
和 options.lua
两个文件
3、alowree/lazy.lua
做了两件事情:加载 lazy
自己,加载 alowree.plugins
下的所有文件
4、alowree/plugins/init.lua
, 引入这两个插件作何用途?
return {
"nvim-lua/plenary.nvim", -- lua functions that many plugins use
"christoomey/vim-tmux-navigator", -- tmux & split window navigation
-- works for PowerShell on Windows too
}
插件管理
使用 lazy.nvim 做为插件管理器,然后所有的插件文件都使用 Lua 进行配置。
lazy.nvim is a modern plugin manager for Neovim.
按照 lazy.nvim —— Installation 官方文档调整了一下 alowree/lazy.lua
内的配置,将 leader 键的配置位置由原先的 alowree/core/keymaps.lua
转移至 alowree/lazy.lua
当中,然后对调二者在主配置文件中的导入顺序:保证 leader 键先定义,后使用的原则。也就是在 alowree/lazy.lua
中定义 leader 键,在 alowree/core/options.lua
和 alowree/core/keymaps.lua
使用。
require("alowree.lazy")
require("alowree.core")
使用 Lua 配置
全部的配置使用 Lua 语言,所以新手需要学习一点点 Lua 的编程知识。
关于 Lua
When configuring Neovim using Lua, do I need to install any Lua interpreter on my computer? Or Does Neovim ship with a built-in Lua related interpreter already?
Neovim has a built-in Lua interpreter (specifically LuaJIT, which is Lua 5.1-compatible with some 5.2 extensions). This means:
You don't need to install Lua separately for basic Neovim configuration.
- The Lua runtime is embedded directly into Neovim.
- Your
init.lua
and other Lua config files are executed by Neovim's built-in LuaJIT.
When external Lua is needed (rare cases):
- If you use plugins or tools that call
lua
from the command line (e.g.,:!lua script.lua
), you’ll need a system-wide Lua installation. - Some plugins may require newer Lua features (e.g., Lua 5.3+), but this is uncommon since most Neovim plugins target LuaJIT (5.1).
- If you use plugins or tools that call
Key Notes:
- Neovim’s Lua API (
vim.*
,nvim_*
) is only available in the embedded Lua runtime. - For
require
to work, ensure your Lua files are in Neovim’s runtimepath (e.g.,~/.config/nvim/lua/
or~/AppData/Local/nvim/lua/
). - To check the Lua version Neovim uses, run
:lua print(_VERSION)
in Neovim (should output "Lua 5.1" or similar).
Summary:
- Default configs: No extra Lua install needed.
- Edge cases: Only install Lua system-wide if a plugin/tool explicitly requires it outside Neovim’s runtime.
For most users, Neovim’s built-in Lua is sufficient. 🚀