If you have already mastered the basics of Vim from our previous tutorials, you might be wondering: Is there something better? Something that keeps the incredible speed of Vim, but adds modern IDE features like intelligent autocomplete, seamless code refactoring, and real-time error checking?
Enter Neovim.
Forked from Vim in 2014, Neovim was created to aggressively modernize the codebase, fix legacy issues, and most importantly, introduce a first-class plugin ecosystem using the incredibly fast Lua programming language.
In this comprehensive guide, we will explore exactly why you should switch to Neovim, and how to configure it into a fully-fledged IDE from scratch.
Why Switch from Vim to Neovim?
Neovim is 100% compatible with your old Vim muscle memory. Every command you know—ciw, yy, dd—works perfectly. But under the hood, Neovim brings massive improvements:
- Lua Configuration: Instead of the archaic and slow “Vimscript”, Neovim is configured using Lua. Lua is incredibly fast, easy to learn, and allows developers to write insanely powerful plugins.
- Built-in LSP (Language Server Protocol): You no longer need heavy, external plugins like CoC to get VS Code-level autocomplete. Neovim speaks natively to language servers.
- Treesitter: Instead of using slow Regular Expressions to color your code, Neovim uses Treesitter to parse your code into a real-time Abstract Syntax Tree, resulting in lightning-fast and perfectly accurate syntax highlighting.
- Asynchronous Architecture: In old Vim, if a plugin ran a heavy task, your entire editor would freeze. Neovim’s architecture is fully async, meaning your UI never locks up.
Installation
Installing Neovim is just as easy as installing Vim. We highly recommend grabbing the latest version (0.9+).
For Linux (Ubuntu/Debian):
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt update
sudo apt install neovim
For macOS:
brew install neovim
Note: The command to start Neovim is nvim, not vim.
The Lua Revolution: Your First init.lua
In Vim, you configured your settings in ~/.vimrc.
In Neovim, you configure your settings in ~/.config/nvim/init.lua.
Let’s create it:
mkdir -p ~/.config/nvim
nvim ~/.config/nvim/init.lua
Paste the following basic Lua configuration to get started:
-- Basic Settings
vim.opt.number = true -- Show line numbers
vim.opt.relativenumber = true -- Relative line numbers for easy jumping
vim.opt.tabstop = 4 -- 4 spaces for tabs
vim.opt.shiftwidth = 4
vim.opt.expandtab = true -- Convert tabs to spaces
vim.opt.termguicolors = true -- True color support!
-- Set Leader Key to Spacebar
vim.g.mapleader = ' '
-- Easy Save and Quit shortcuts
vim.keymap.set('n', '<leader>w', ':w<CR>')
vim.keymap.set('n', '<leader>q', ':q<CR>')
Save and restart Neovim. Notice how clean and readable the Lua syntax is compared to old Vimscript!
Transforming Neovim into an IDE
To truly unleash Neovim, you need a plugin manager. The modern standard is lazy.nvim.
Add this code to the top of your init.lua to automatically install lazy.nvim when you start Neovim:
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)
Now, we can tell lazy.nvim to install the three most critical plugins for modern development.
1. Telescope (The Ultimate Fuzzy Finder)
Telescope allows you to instantly search for any file, string, or command across your entire project instantly.
require("lazy").setup({
{
'nvim-telescope/telescope.nvim',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) -- Find File
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) -- Search inside files
end
}
})
2. Native LSP Configuration
This gives you the intelligent autocomplete, “Go to Definition”, and error checking you expect from VS Code.
First, install your language servers on your machine (e.g., npm install -g typescript-language-server). Then add this to your lazy.nvim setup block:
{
'neovim/nvim-lspconfig',
config = function()
local lspconfig = require('lspconfig')
-- Setup your languages here:
lspconfig.ts_ls.setup({}) -- TypeScript/JavaScript
lspconfig.pylsp.setup({}) -- Python
-- Set up keymaps for LSP
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) -- Go to Definition
vim.keymap.set('n', 'K', vim.lsp.buf.hover, {}) -- Show Documentation
vim.keymap.set('n', 'rn', vim.lsp.buf.rename, {}) -- Rename variable globally
end
}
3. Treesitter Highlighting
Add this to ensure your code has beautiful, semantically accurate coloring:
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
config = function()
require('nvim-treesitter.configs').setup({
ensure_installed = { "lua", "javascript", "python", "html", "css" },
highlight = { enable = true },
})
end
}
Neovim vs VS Code
If you spend 8 hours a day typing code, your editor is your most important tool.
VS Code is fantastic out of the box, but it is heavy, consumes massive amounts of RAM (thanks to Electron), and relies heavily on the mouse.
Neovim requires an upfront investment of your time to configure init.lua, learn the keybindings, and choose your plugins. But once you cross that learning curve, you will have an editor that opens instantly, uses barely any memory, and allows you to edit code at the speed of thought without ever taking your hands off the home row.
Welcome to the future of editing!
Discussion
Loading comments...