Basic Configuration
Let’s start with some basic settings that affect file encoding and syntax highlighting.
vim.scriptencoding = "utf-8"
vim.opt.encoding = "utf-8"
vim.opt.fileencoding = "utf-8"
vim.opt.syntax = "enable"
These settings ensure that Neovim handles UTF-8 characters properly and enables syntax highlighting.
Backups
It's important to manage how Neovim handles file backups to avoid creating unnecessary files. Setting these options can help:
vim.opt.backup = false
vim.opt.swapfile = false
vim.opt.writebackup = false
This disables the creation of backup and swap files, which can help keep your workspace clean.
Keybindings
Creating custom keybindings can greatly enhance your efficiency in Neovim. Here are some useful mappings:
local options = { noremap = true }
-- Set the leader key to space
vim.g.mapleader = " "
-- Switch between windows using Ctrl + h/j/k/l
vim.api.nvim_set_keymap("n", "<C-h>", "<C-w>h", options)
vim.api.nvim_set_keymap("n", "<C-j>", "<C-w>j", options)
vim.api.nvim_set_keymap("n", "<C-k>", "<C-w>k", options)
vim.api.nvim_set_keymap("n", "<C-l>", "<C-w>l", options)
-- Split window vertically with <leader>sv
vim.api.nvim_set_keymap("n", "<leader>sv", ":vsplit<CR>", options)
-- Exit insert mode with ',,'
vim.api.nvim_set_keymap("i", ",,", "<ESC>", options)
-- Save and quit with <leader>w and <leader>q
vim.api.nvim_set_keymap("n", "<leader>w", ":w<CR>", options)
vim.api.nvim_set_keymap("n", "<leader>q", ":q<CR>", options)
vim.api.nvim_set_keymap("n", "<leader>wq", ":wq<CR>", options)
Plugin Setup
Finally, consider using the lazy.nvim library to load your plugins lazily and optimize Neovim’s startup time. Here’s how to configure 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",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
spec = {
{ import = "plugins" },
},
debug = false
})
With lazy.nvim, your plugins will only load when needed, which can significantly improve Neovim’s startup performance.
You can visit the following repository where this configuration is hosted: https://github.com/byandrev/minimal-neovim-config.
Conclusion
Customizing Neovim can take time and experimentation, but with a minimal setup like this, you can quickly improve your workflow and productivity.