Customizing your init.lua

Up to this point, we have located our configuration folder and backed up any existing files into a safe location. Now it is time to start building our configuration.

Lets start by creating the configuration file:

nvim init.lua

Plugin Manager

The first step is to install a plugin manager. Like kickstart.nvim we will use lazy.nvim to manage our plugins.

To begin, we need to ensure that the dependencies, most notably git, are installed. If git is not already installed on your system, follow the instructions for your OS to install it.

Next, let's set install lazy.nvim. The lazy.nvim website contains all of the details about how to use it, so we will focus on just the basics to get things up and running quickly.

Following lazy.nvim's installation instructions, we start with the following bootstrap script:

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)

-- mapleader configuration should go here

local opts = {}

require("lazy").setup("plugins", opts)

As with any code we find on the internet, let's take a look to understand what is going on here. First, this code defines lazypath to be in a sub-directory under the data base directory. Next, the code checks to see that path exists, and if not it clone's the lazy.nvim github repository into that path. Next, lazypath is added to the front of runtime paths.

Next, there is a comment stating that any mapleader configuration should be located at that place. If you have configured your mapleader to a non-default value, it needs to be set before we require lazy.nvim. If you use the default leader or aren't sure what we are even talking about, then just ignore this comment.

In the next step we create an empty table and assign it to the opts variable. We will keep lazy.nvim's default configuration, but the table is here to if any configuration changes need to be made in the future.

Next, require the "lazy" module and call it's setup method. The first argument to this method is the string "plugins", and the second argument is the opts table we just created.

lazy.nvim supports two plugin spec formats. The first format supports single-file configurations, such as kickstart.nvim. When this format is used each of the specs is organized into a list which is passed as the first argument to the setup method. The second format supports multi-file configurations, where each plugin (or group of plugins) are located in separate files, which are all located under a sub-directory of the lua configuration folder. When this format is used the name of the sub-directory (in our case, "plugins") is passed to the setup function. Since kickstart.nvim already provides an example of a single-file configuration, we will set up a multi-file configuration, with specs located under the "plugins" directory.

Lets create the init.lua file:

nvim init.lua

the paste the bootstrap script into it and save and exit, using :wq.

Now, it is time to make sure that these directories exist. Navigate to your configuration folder, and make sure that a lua directory is located at the root level, then there should be a sub-directory named plugins within the lua directory. The directory tree should contain the following files and directories:

~/.config/nvim/ ($XDG_CONFIG_HOME)
|
+-lua/
| |
| +-plugins/
|
+-init.lua

Now, start up Neovim one more time:

nvim

and the boostrap script should clone the lazy.nvim github repo and install itself.

Now we should be ready to proceed with the configuration.