Setting Up Neovim: An Easy and Beginner’s Guide
Neovim is a modern and extensible text editor that enhances Vim’s capabilities. If you’re using Linux, setting up Neovim can be a rewarding experience, allowing you to customize it for an efficient workflow. In this guide, we’ll cover installing Neovim, setting up a basic configuration, and enhancing it with essential plugins to turn it into a full-fledged IDE.
1. Installing Neovim
sudo pacman -S neovim
2. Setting Up Neovim Configuration
Neovim’s configuration is stored in ~/.config/nvim/. Create the directory and initialize a basic configuration:
mkdir -p ~/.config/nvim
nvim ~/.config/nvim/init.lua
Minimal Configuration (init.lua)
Add the following settings to your init.lua file:
-- Enable line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- Set tab size
vim.opt.expandtab = true
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4
-- Enable mouse support
vim.opt.mouse = "a"
-- Set clipboard to system clipboard
vim.opt.clipboard = "unnamedplus"
Save and exit Neovim.
3. Installing a Plugin Manager
The best plugin manager for Neovim is lazy.nvim. Install it by running:
git clone --depth 1 https://github.com/folke/lazy.nvim.git \
~/.local/share/nvim/lazy/lazy.nvim
Then, update your init.lua to load it:
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", lazypath
})
end
vim.opt.rtp:prepend(lazypath)
4. Installing Essential Plugins
With lazy.nvim installed, you can add plugins in init.lua:
require("lazy").setup({
"nvim-treesitter/nvim-treesitter", -- Syntax highlighting
"nvim-telescope/telescope.nvim", -- Fuzzy finder
"neovim/nvim-lspconfig", -- LSP support
"hrsh7th/nvim-cmp", -- Auto-completion
"hrsh7th/cmp-nvim-lsp", -- LSP completion source
"hrsh7th/cmp-buffer", -- Buffer completion
"hrsh7th/cmp-path", -- Path completion
"hrsh7th/cmp-nvim-lua", -- Neovim Lua API completion
"L3MON4D3/LuaSnip", -- Snippet engine
"saadparwaiz1/cmp_luasnip", -- Snippet completion
"nvim-lualine/lualine.nvim", -- Status line
"nvim-tree/nvim-tree.lua", -- File explorer
"tpope/vim-surround", -- Surround text objects
"tpope/vim-commentary", -- Commenting shortcuts
"lewis6991/gitsigns.nvim", -- Git integration
"akinsho/toggleterm.nvim", -- Terminal management
})
Save and exit Neovim, then open it and run:
:Lazy sync
This will install the plugins automatically.
5. Setting Up Treesitter
Treesitter provides better syntax highlighting and code parsing. Install it by adding the following to your init.lua:
require'nvim-treesitter.configs'.setup {
ensure_installed = "all",
highlight = {
enable = true,
},
indent = {
enable = true,
},
}
Then, update Treesitter by running:
:TSUpdate
6. Setting Up LSP (Language Server Protocol)
LSP enables features like code completion and linting. Install LSP servers for your language:
# Python
sudo pacman -S python-lsp-server
# C++
sudo pacman -S clang
# JavaScript/TypeScript
npm install -g typescript-language-server
Then, enable LSP support in Neovim:
local lspconfig = require("lspconfig")
lspconfig.pyright.setup({}) -- Python
lspconfig.ts_ls.setup({}) -- JavaScript/TypeScript
lspconfig.clangd.setup({}) -- C++
Restart Neovim and check LSP status:
:LspInfo
7. Enhancing Auto-Completion with nvim-cmp
To enable code auto-completion, update your init.lua:
local cmp = require'cmp'
cmp.setup({
mapping = {
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'nvim_lua' },
}
})
9. Final Thoughts
Congratulations! You now have a powerful, customized Neovim setup that functions as a full-fledged IDE. With features like Treesitter, LSP support, auto-completion, syntax highlighting, Git integration, and a file explorer, your development workflow will be much smoother.
If you’d like to further improve your Neovim experience, explore more plugins and tweak your settings. Good luck with that!