Configuring Neovim with Lua
Setting up your text editor to make it suitable for programming is the most interesting and never-ending part of using Vim or Neovim. You’ll constantly see new plugins online and a whole community is working towards making things better with new features day by day. Maybe one day, you’ll write your own plugin just because why not? It is fun and faster to script your plugin in Vim/Neovim.
But which one to choose? Vim? Or Neovim?
Well, I’d suggest Neovim because it uses LuaJIT which is a well-known programming language. It is very lightweight and also very performant which makes it suitable for embedded system programming and also game development. It is way simpler than Vimscript and therefore I feel using Neovim is much simpler than using Vim.
That’s all good but where should I start?
The very first thing to know is that every time Neovim starts, it reads through a file called init.vim or init.lua if either one of them is present in the directories listed in the help section. So that’s where you’ll have to start. You’ll find a lot of neovim config tutorial videos on youtube and also I’ll link some good configs which you can refer to while creating your own.
It is always better to create your configs even if you are referring to others’ config files. This helps to understand better about writing a lua script and makes it easier when you’ll write Lua plugins later if you ever need to make one for work or as a hobby.
The best resource I can recommend is the nvim-lua-guide by nanotree in GitHub. It explains everything from scratch and also helps you understand the concepts better. This will make you confident enough to write your own plugins in the future. I wrote my custom status bar with the help of the guide linked above. And I started watching the streams of one of the core developers of Neovim, TJDevries. His youtube videos show us new cool features and also teach us a lot about neovim.
How do I add plugins and which ones should I use?
There are mainly two ways to add a plugin to Neovim. Either you can clone the
github repo to the location ~/.local/share/nvim/site/pack/*/start/
.
The other way is to use a proper plugin manager. I prefer using a plugin manager because that’s easier to manage and track all the plugins all at once.
There are a few very popular ones:
Out of these, I use packer because it is written in lua and also its simple to set up.
And now let us talk about choosing the right plugins. Note that all the plugins available are cool but you can choose the best one that suits your need.
This is the list of plugins I use and a short description of them.
- lewis6991/gitsigns.nvim - A super fast git decoration plugin.
- nvim-lua/plenary.nvim - A library plugin used by most other plugins out there.
- nvim-lua/popup.nvim - A plugin that implements the popup API as implemented in VIM.
- neovim/nvim-lspconfig - This plugin consists of the config files used for enabling the built-in lsp client.
- hrsh7th/nvim-cmp - A plugin that provides LSP code completion.
- hrsh7th/cmp-nvim-lsp - A plugin that provides LSP client recommendations in the completion plugin.
- hrsh7th/cmp-path - A plugin that provides local path suggestions in the completion plugin.
- hrsh7th/cmp-buffer - A plugin that provides completion options from the open buffer.
- hrsh7th/cmp-nvim-lua - A plugin that provides completion options with respect to neovim lua config.
- onsails/lspkind-nvim - VSCode like pictograms to nvim built-in lsp.
- glepnir/lspsaga.nvim - A better UI for the built-in LSP Client.
- L3MON4D3/LuaSnip - A snippet engine written in lua.
- saadparwaiz1/cmp_luasnip - A plugin that provides completion options from the snippet engine.
- windwp/nvim-autopairs - A plugin that provides pairing of brackets and parentheses that is essential for a code editor.
- numToStr/Comment.nvim - A plugin that has intelligent code commenting functionality.
- nvim-treesitter/nvim-treesitter - A plugin that provides a simple and easy way to interact with the treesitter inside neovim. Treesitter is an incremental parsing system for programming tools.
- nvim-telescope/telescope.nvim - An advanced fuzzy finder tool with many other features.
- ThePrimeagen/harpoon - A simple plugin that makes file navigation inside a project easier and faster.
- folke/tokyonight.nvim - A color scheme plugin.
- kyazdani42/nvim-web-devicons - A plugin that provides the dev icons.
Have fun hacking!
Useful links: