
Neovim là bản fork hiện đại của editor kinh điển Vim, được xây dựng lại với trọng tâm extensibility và usability. Xây dựng trên nền LuaJIT, Neovim hỗ trợ remote plugins, tích hợp native LSP client và hệ sinh thái plugin phong phú — biến editor dòng lệnh thành IDE mạnh mẽ không kém gì VS Code hay IntelliJ.
Tại sao lập trình viên chuyển sang Neovim thay vì Vim truyền thống? Câu trả lời nằm ở cấu hình bằng Lua — ngôn ngữ nhanh, easy to read hơn VimScript gấp nhiều lần. Bạn có thể viết config dạng code thuần túy, import modules, sử dụng libraries — mọi thứ developer quen thuộc đều có.

Cài đặt Neovim
Neovim hỗ trợ hầu hết mọi nền tảng. Trên macOS:
brew install neovim
Trên Ubuntu/Debian:
sudo apt update && sudo apt install neovim
Hoặc build từ source để có bản mới nhất từ GitHub repository github.com/neovim/neovim:
git clone https://github.com/neovim/neovim
cd neovim
make CMAKE_BUILD_TYPE=Release
sudo make install
Kiểm tra phiên bản:
nvim --version
Phiên bản 0.10+ trở lên khuyến nghị cho tất cả tính năng mới nhất, bao gồm vim.lsp.config() built-in và treesitter improvements.
Cấu hình Lua cơ bản
File cấu hình chính nằm ở ~/.config/nvim/init.lua. Đây là điểm khởi đầu:
-- Options cơ bản
vim.o.number = true
vim.o.relativenumber = true
vim.o.tabstop = 4
vim.o.shiftwidth = 4
vim.o.expandtab = true
vim.o.smartindent = true
vim.o.wrap = false
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.termguicolors = true
vim.o.scrolloff = 8
-- Keymaps cơ bản
vim.g.mapleader = " "
vim.keymap.set("n", "<leader>w", ":w<CR>")
vim.keymap.set("n", "<leader>q", ":q<CR>")
vim.keymap.set("n", "<C-h>", "<C-w>h")
vim.keymap.set("n", "<C-j>", "<C-w>j")
vim.keymap.set("n", "<C-k>", "<C-w>k")
vim.keymap.set("n", "<C-l>", "<C-w>l")
-- Autocmd: highlight trailing whitespace
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
command = "%s/\s\+$//e",
})
Điểm quan trọng: vim.o tương đương set trong VimScript, vim.g quản lý global variables, và vim.keymap.set() thay thế nnoremap/vnoremap. Tất cả đều type-safe với annotations từ Lua language server.
Quản lý plugin với lazy.nvim
lazy.nvim là plugin manager phổ biến nhất hiện nay cho Neovim. Tính năng nổi bật:
- Lazy loading — plugin chỉ load khi thực sự cần, giảm startup time đáng kể
- Bytecode compilation — tự động compile Lua scripts thành bytecode
- Lockfile —
lazy-lock.jsonđảm bảo reproducible setup - UI đẹp — dashboard quản lý plugin với thống kê
Bootstrap lazy.nvim trong init.lua:
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup("plugins")
Tạo thư mục ~/.config/nvim/lua/plugins/ và thêm file init.lua hoặc các file .lua riêng cho từng nhóm plugin.
LSP: Biến editor thành IDE thực thụ
Neovim có native LSP client từ phiên bản 0.8. Kết hợp với nvim-lspconfig, bạn có được autocompletion, go-to-definition, hover documentation, rename refactoring và code actions — tất cả bên trong terminal.
-- plugins/lsp.lua
return {
"neovim/nvim-lspconfig",
dependencies = {
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip",
},
config = function()
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp")
.default_capabilities()
local servers = { "lua_ls", "ts_ls", "pyright", "gopls" }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({ capabilities = capabilities })
end
-- Keymaps khi LSP attach
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(event)
local opts = { buffer = event.buf }
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<leader>ca",
vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>rn",
vim.lsp.buf.rename, opts)
end,
})
end,
}
nvim-cmp cung cấp menu autocompletion với nhiều sources: LSP, buffer, path, snippets. Hoạt động real-time, hỗ trợ Tab/S-Tab để navigate, Enter để accept.

nvim-treesitter: Highlighting thông minh
nvim-treesitter thay thế regex-based highlighting truyền thống bằng parser incremental, chính xác hơn nhiều lần. Treesitter phân tích cấu trúc code thực tế, hỗ trợ:
- Incremental parsing — chỉ parse phần thay đổi, cực nhanh
- Context-aware highlighting — phân biệt biến cục bộ vs global
- Textobjects — select function, class, parameter bằng
af,if - Incremental selection — mở rộng/thu hẹp vùng chọn theo AST
require("nvim-treesitter.configs").setup({
ensure_installed = {
"lua", "typescript", "python", "go",
"rust", "javascript", "html", "css",
},
highlight = { enable = true },
indent = { enable = true },
})
Cài parser bằng lệnh :TSInstall <language>. Neovim 0.10+ tích hợp treesitter parser cho các ngôn ngữ chính sẵn.
Telescope và nvim-tree: Fuzzy finder và file explorer
Telescope.nvim là fuzzy finder mạnh mẽ nhất cho Neovim. Tìm files, grep text, search LSP symbols, browse git commits — tất cả trong một UI thống nhất.
vim.keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<CR>")
vim.keymap.set("n", "<leader>fg", "<cmd>Telescope live_grep<CR>")
vim.keymap.set("n", "<leader>fb", "<cmd>Telescope buffers<CR>")
vim.keymap.set("n", "<leader>fh", "<cmd>Telescope help_tags<CR>")
nvim-tree cung cấp file explorer sidebar với icons (qua nvim-web-devicons), git status indicators, và actions như create/delete/rename trực tiếp từ sidebar.
LazyVim: Bắt đầu nhanh cho người mới
Không muốn config từ đầu? LazyVim là distribution sẵn sàng sử dụng, tích hợp sẵn:
- Tất cả plugin cơ bản (Telescope, treesitter, LSP, cmp, nvim-tree, lualine)
- Keymaps hợp lý cho cả normal và insert mode
- Theme catppuccin dark mặc định
- Cấu hình dùng được ngay sau khi clone
# Clone LazyVim starter
git clone https://github.com/LazyVim/starter ~/.config/nvim
# Khởi động nvim — plugin tự cài
nvim
Sau khi quen, bạn có thể tùy chỉnh bằng cách thêm files vào ~/.config/nvim/lua/plugins/ — mỗi file trả về một plugin spec. LazyVim designed for gradual customization, bắt đầu từ ready-to-use rồi dần dần trở thành config riêng.
Tips nâng cao
:Lazy profile— xem thời gian load từng plugin, tìm bottleneck:checkhealth— kiểm tra trạng thái mọi thành phần (LSP, treesitter, clipboard…):LspInfo— xem language server đang attach cho buffer hiện tại- Sử dụng
folke/noice.nvimđể thay thế UI messages/cmdline bằng popup hiện đại - Sử dụng
folke/trouble.nvimcho diagnostics list tập trung
Kết luận
Neovim không còn là editor “chỉ cho người cứng đầu”. Với hệ sinh thái Lua phong phú, lazy loading thông minh và LSP tích hợp sẵn, Neovim mang đến trải nghiệm IDE full-featured ngay trong terminal — nhanh hơn, nhẹ hơn và customizable hơn bất kỳ editor nào khác. Bắt đầu với LazyVim, dần dần tùy chỉnh, và bạn sẽ có một workflow lập trình mà không muốn quay lại.
Xem thêm về terminal tools khác tại chuhung.net.
