Create your own Neovim configuration
Neovim is a highly customizable text editor that allows you to create your own configuration to suit your workflow and preferences. In this guide, I will walk through the steps to set up a custom Neovim configuration.
Step 1: Install Neovim
First, ensure that you have Neovim installed on your system. We should use most latest version which is 0.11.4 at the time of writing. It can downloaded from the official Neovim website or use a package manager like brew, apt, or chocolatey etc depending on our operating system.
Step 2: $NVIM_APPNAME
Neovim uses a specific directory for its configuration files. By default, it looks for configuration files in the ~/.config/nvim directory on Unix-like systems and %APPDATA%\nvim on Windows. We can also set the NVIM_APPNAME environment variable to change the configuration directory. For example, to set it to rdev, we can add the following line to our shell configuration file (e.g., .bashrc, .zshrc):
|
|
After setting this variable, Neovim will look for configuration files in ~/.config/rdev on Unix-like systems. Starting new neovim will use this directory for configuration and we can start from clean slate without affecting our existing neovim setup.
We can verify that the variable is set correctly by running:
:echo stdpath("config") inside Neovim, which should return the path to our custom configuration directory.
Step 3: Create the Configuration Directory
Let’s create the configuration directory if it doesn’t already exist. We can do this using the following command in the terminal:
|
|
We can also create it directly inside neovim using :!mkdir -p ~/.config/rdev or :call mkdir(stdpath("config"), "p"). Now we have the configuration directory ready and we can start adding Lua configuration files.
Step 4: Create the init.lua File
The main configuration file for Neovim is init.lua. Let’s create this file inside our configuration directory:
|
|
or inside neovim using :e ~/.config/rdev/init.lua or :exe "edit" stdpath("config") . "/init.lua". After creating the file, we can start adding our custom configurations using Lua but let’s first start by saving the file by running :w. This init.lua file will be automatically loaded when you start Neovim and will be the entry point for our custom configuration.
Step 5: Add Basic Directory Structure
To keep our configuration organized, we will create a basic directory structure inside our configuration directory.
|
|
Step 6: Add configuration for lua formatting
To ensure that our Lua files are properly formatted, we will install and add a configuration for stylua, which is Lua formatter. Create a file named .stylua.toml inside the configuration directory:
|
|
Step 7: Add Lazy.nvim plugin manager
To manage our Neovim plugins, we will use lazy.nvim, a modern plugin manager. First, we need to install it by cloning the repository into the appropriate directory:
|
|
Step 8: Add plugins
Now we can add our plugins to the! Create a directory named plugins inside the lua/rdev directory:
|
|
Now we can add our plugins to the plugins directory. Create a file per plugin named plugin-name.lua inside the plugins directory:
|
|
In order to allow lazy.nvim to load our plugins we need to return lua-table in each plugin file. The table should have the following structure:
|
|
Here we instructed lazy.nvim to load the nvim-treesitter plugin and configure it to automatically install TreeSitter parsers for some languages.
This process should be repeated for each plugin we want to install. For example my settings look like the following:
|
|