To use NeoVim with style, you'll want to configure it for both productivity and aesthetics. Below is a step-by-step tutorial to set up a stylish NeoVim environment.
First, make sure you have NeoVim installed. You can install it by following the instructions for your system:
- Linux:
sudo apt update && sudo apt install neovim
- macOS:
brew install neovim
- Windows: Use [Windows Subsystem for Linux (WSL)] or install NeoVim directly via Chocolatey or Scoop.
A plugin manager will help you install plugins for customization. We'll use Packer here.
-
Open a terminal and run:
git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim
-
Create the
init.lua
configuration file for NeoVim:mkdir -p ~/.config/nvim touch ~/.config/nvim/init.lua
Open the init.lua
file (nvim ~/.config/nvim/init.lua
) and add the following sections step by step:
-- Basic Settings
vim.opt.number = true -- Show line numbers
vim.opt.relativenumber = true -- Relative line numbers
vim.opt.tabstop = 4 -- Number of spaces for tab
vim.opt.shiftwidth = 4 -- Spaces for auto-indenting
vim.opt.expandtab = true -- Use spaces instead of tabs
vim.opt.mouse = "a" -- Enable mouse support
vim.opt.termguicolors = true -- Enable true color support
Add the following configuration for Packer and some stylish plugins:
-- Packer configuration
require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- Add a theme
use 'folke/tokyonight.nvim' -- TokyoNight theme
-- Fuzzy finder (like VSCode's quick open)
use 'nvim-telescope/telescope.nvim'
-- File explorer
use 'kyazdani42/nvim-tree.lua'
-- Status line
use 'nvim-lualine/lualine.nvim'
-- Autocompletion and Snippets
use 'hrsh7th/nvim-cmp' -- Completion plugin
use 'L3MON4D3/LuaSnip' -- Snippet engine
-- LSP and syntax highlighting
use 'neovim/nvim-lspconfig' -- Collection of LSP configurations
use 'nvim-treesitter/nvim-treesitter' -- Better syntax highlighting
end)
In NeoVim, run:
:PackerInstall
Next, let's set up the tokyonight
theme and configure the status line for a stylish look.
-- TokyoNight theme configuration
vim.cmd[[colorscheme tokyonight]]
-- Lualine status bar setup
require('lualine').setup {
options = {
theme = 'tokyonight'
}
}
-- nvim-tree setup
require('nvim-tree').setup{}
-
nvim-tree (File Explorer): You can toggle the file explorer with
<leader>e
. Here’s how to configure key bindings:vim.api.nvim_set_keymap('n', '<leader>e', ':NvimTreeToggle<CR>', { noremap = true, silent = true })
-
Telescope (Fuzzy Finder): Telescope is a powerful fuzzy finder. You can search files, grep text, and more. Add this to your key bindings:
vim.api.nvim_set_keymap('n', '<leader>f', ':Telescope find_files<CR>', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '<leader>g', ':Telescope live_grep<CR>', { noremap = true, silent = true })
To set up LSP (Language Server Protocol) for code completion and linting, install an LSP server for your language:
-
Install
nvim-lspconfig
::PackerInstall
-
Configure LSP in your
init.lua
:local lspconfig = require('lspconfig') -- Example for Python lspconfig.pyright.setup{} -- TypeScript LSP configuration lspconfig.ts_ls.setup{}
-
Add key bindings for LSP:
vim.api.nvim_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', { noremap = true, silent = true })
You can set up nvim-cmp
for autocompletion:
-- Setup nvim-cmp
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<Tab>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}
})
-
Dashboard: A minimalist startup screen.
use 'glepnir/dashboard-nvim'
-
Git Integration:
use 'lewis6991/gitsigns.nvim'
-
Indentation Guides:
use 'lukas-reineke/indent-blankline.nvim'
Add some custom key mappings to improve your workflow:
vim.api.nvim_set_keymap('n', '<leader>s', ':w<CR>', { noremap = true, silent = true }) -- Save
vim.api.nvim_set_keymap('n', '<leader>q', ':q<CR>', { noremap = true, silent = true }) -- Quit
vim.api.nvim_set_keymap('n', '<leader>x', ':x<CR>', { noremap = true, silent = true }) -- Save and quit
If you want stylish fonts with programming ligatures, install FiraCode or another similar font.
- Install the font from FiraCode GitHub and set it in your terminal emulator.
After following these steps, your NeoVim setup will be both stylish and highly functional. Enjoy coding with a modern and elegant experience!