neovim: config and enhance
Preface #
I believe the reason why people choose to use neovim is person to person. As for me, neovim give me a lightweight and fast edit environment in terminal which i used to connect to my nixOS server.
The more detail about the architecture about neovim you can check DESOSA 20171.
And there are some material maybe you can use during the configuration:
- Lua tutorial: Learn Lua in Y minutes2
Basic Configuration #
On the very beginning, you’d better follow the official guide3 to install neovim, and then create the config directory located in ~/.config/nvim on Unix-like systems.
And the best practice about the organization of config files is put them separately45. Therefore, The article will do such thing as well but more simple and easy to debug.
.
├── init.lua // the entry file for neovim
└── lua // the directory for lua files using to configure neovim separately
├── keymaps.lua
├── options.lua
├── pluginator.lua
├── ...
└── ...Neovim behavior #
We put the basic behavior configuration of neovim into options.lua including these features:
- using osc52 to copy to system clipboard
- fix the tab behavior
- enhance ui logic and search behavior
-- system
vim.opt.clipboard = 'unnamedplus' -- uses the + register to cooperate with system
vim.g.clipboard = 'osc52' -- copy to the system clipboard using OSC 52
vim.opt.mouse = 'a' -- allow the mouse to be used in Nvim
-- Tab
vim.opt.tabstop = 4 -- number of visual spaces per TAB
vim.opt.softtabstop = 4 -- number of spacesin tab when editing
vim.opt.shiftwidth = 4 -- insert 4 spaces on a tab
vim.opt.expandtab = true -- tabs are spaces, mainly because of python
-- UI config
vim.opt.number = true -- show absolute number
vim.opt.relativenumber = true -- add numbers to each line on the left side
vim.opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
vim.opt.splitbelow = true -- open new vertical split bottom
vim.opt.splitright = true -- open new horizontal splits right
vim.opt.termguicolors = true -- enabl 24-bit RGB color in the TUI
-- Searching
vim.opt.incsearch = true -- search as characters are entered
vim.opt.ignorecase = true -- ignore case in searches by default
vim.opt.hlsearch = true -- highlight all matches
vim.opt.smartcase = true -- make it case sensitive if an uppercase is enteredand then we can load this file in the init.lua:
require('options') -- load the options fileNeovim keymaps #
create a new lua file named keymaps.lua in the lua directory, and put the following configuration in it which is including these features:
- resize windows with arrows
- move cursor word-by-word
- exit terminal mode with Esc
- enter command-line mode with Option + P
- set leader key to space
local opts = {
noremap = true, -- non-recursive
silent = true, -- do not show message
}
vim.g.mapleader = ' '
-- Resize windows size with arrows
vim.keymap.set('n', '<leader><Up>', ':resize +2<CR>', opts)
vim.keymap.set('n', '<leader><Down>', ':resize -2<CR>', opts)
vim.keymap.set('n', '<leader><Left>', ':vertical resize -2<CR>', opts)
vim.keymap.set('n', '<leader><Right>', ':vertical resize +2<CR>', opts)
-- Cursor movement
-- Meta/Alt/Option + Left/Right/Up/Down: Move word-by-word
vim.keymap.set('n', '<M-Left>', 'b', opts) -- Previous word
vim.keymap.set('n', '<M-Right>', 'w', opts) -- Next word
vim.keymap.set('i', '<M-Left>', '<C-o>b', opts) -- Previous word in insert mode
vim.keymap.set('i', '<M-Right>', '<C-o>w', opts) -- Next word in insert mode
-- Terminal mode
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>', opts) -- Exit terminal mode with Esc
-- Command-line mode
vim.keymap.set('n', '<M-p>', ':', opts) -- Option + P to enter command-line modeand then we can load this file in the init.lua as well:
require('keymaps') -- load the keymaps filePlugins Manager #
i choose to use lazy.nvim as the plugins manager. You can follow the official guide6 to install it, and then create a new lua file named pluginator.lua in the lua directory.
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- Setup lazy.nvim
require("lazy").setup({
spec = {
-- import your plugins
{ import = "plugins" },
},
install = { colorscheme = { "catppuccin" } },
checker = { enabled = true },
})Neovim themes #
we can create a new lua file named colorscheme.lua in the lua directory to configure neovim theme. It is referred to MartinLwx’s blog7.
-- define your colorscheme here
local colorscheme = 'catppuccin'
local is_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
if not is_ok then
vim.notify('colorscheme ' .. colorscheme .. ' not found!')
return
endAnd then we add catppuccin theme to lazy vim in plugins/catppuccin.lua.
return {
"catppuccin/nvim",
name = "catppuccin",
priority = 1000
}Advanced Neovim Plugins #
There is more plugins you can add to the plugins directory to enhance your neovim experience.
- blink.cmp: completion plugin with support for LSPs, cmdline, signature help, and snippets.
- mason-lspconfig: bridge mason.nvim(LSP manager) with the lspconfig plugin - making it easier to use both plugins together.
- nvim-treesitter: provide a simple and easy way to use the interface for tree-sitter in Neovim and to provide some basic functionality such as highlighting based on it.
- ui
- bufferline.nvim: tabbar for Neovim at the top.
- lualine.nvim: statusline for Neovim at the bottom.
- neo-tree.nvim: file explorer tree for neovim.
- noice.nvim: completely replaces the UI for messages, cmdline and the popupmenu.
-
Delft Students on Software Architecture about Neovim, 2017. ↩︎
-
Learn Lua in Y minutes, a certain year. ↩︎
-
Neovim official guide to install, a certain year. ↩︎
-
The config file tree about LazyVim, a certain year. ↩︎
-
The config file tree about AstroNvim, a certain year. ↩︎
-
Lazy.nvim official guide to install, a certain year. ↩︎
-
MartinLwx’s blog about neovim config, 06 27, 2025. ↩︎