Now we add a plugin manager to extend the functionalities of Neovim. Using a plugin manager to download, install and manage our plugins makes work easier and more productive. Follow along as we make Neovim customized to our tastes.

1. Adding A Plugin Manager

For my configuration we will use Lazy.nvim. It is a plugin manager created by Folke and written in lua. It has a UI to help manage the plugin, loads quickly and keep track of the installed plugin.
The main selling point for me is the ability to reduce the init.lua file size by breaking the plugins and configurations into seperate files that will be loaded and used by Lazy.

Adding Lazy.nvim

To start, set a global map leader and combine with other mappings to call plugin functions:
vim.g.mapleader = " "
This makes it so that when the spacebar key on the keyboard is pressed it waits for the combination key to call a plugin. Simply put instead of
calling for instance, Lazy plugin by typing the command Lazy you can now press the Spacebar key and the letter l, to activate the plugin.
So after setting the leader key, add Lazy config using the following code in the created init.lua file

-- set the mapleader first
vim.g.mapleader = " "
vim.g.maplocalleader = " "
--
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", -- latest stable release
    lazypath,
  })
end
--- This points lazy.nvim to our plugin folder to load plugins
plugins = {
import="plugins"
}

vim.opt.rtp:prepend(lazypath)

require("lazy").setup(plugins)

Lazy.nvim will have a default colorscheme included when it installs and is made the default colorscheme after installation completes.

2. Adding Plugins

So at this point we will create a lua folder to contain the plugin and config folders, these folders will hold the configurations for our plugins and
Neovim options we specify.The structure will look like this:

lua/
    config/
    plugins/

This is relative to the init.lua we have in the nvim directory.So from here we can now add our plugins to our plugins folder to install and configure them.

Adding a Colorscheme – (Solarized-Osaka.nvim)

Let us add a new colorscheme since i have a preferred colorscheme i use. You can use the VimColorSchemes website to preview the colorschemes for Neovim.
At the moment i like the solarized-osaka colorscheme from craftzdog, it fits my aesthetic. So to add this plugin i create a new file in the plugins folder called colorscheme.lua.

Visiting craftzdog/solarized-osaka.nvim, scroll down and add the following code to the file.

return -- Add the code with a return statement so lazy.nvim can read the file
{
  "craftzdog/solarized-osaka.nvim",
  lazy = false,
  priority = 1000,
  opts = {
    transparent = false,
    },
 config = function()
    vim.cmd[[colorscheme solarized-osaka]]
 end
}

All plugin files must return a table spec, so as seen in the code above the return statement is required so any
code must be in placed like this

return 
{ 
    -- code goes here
}

So after adding the code to the colorscheme.lua file, save the file and quit Neovim. Reopen it and you will see some changes to the UI.

Solarized osaka color scheme in the editor window

With this we have added our own touch of color to the editor window. To find the rest of my posts on Neovim, click here. Thanks.

Categorized in:

Neovim, Programming,

Last Update: June 8, 2024

Tagged in:

, ,