DEV Community

Async hronous
Async hronous

Posted on

Using lazy.nvim ๐Ÿ’ค in our Neovim configuration

๐Ÿ‘‹ Introduction

Alright! If you've been following along, we've configured some options and keymaps.
Next, we're going to use lazy.nvim!
It has:

  • ๐Ÿ’ค Auto-magic lazy loading
  • ๐Ÿ”’ Lock files to keep track of plugin versions
  • ๐Ÿ’ช Modular plugin structure
  • ๐Ÿ˜ฎ ... and more!

๐Ÿ— HOWTO: Bootstrap.

It's quite easy to bootstrap lazy.nvim
Create a new module named lazy.lua and SLAM this code in 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", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)
Enter fullscreen mode Exit fullscreen mode

Just that!
Now quit Neovim (if you can) and, start it back again. It should automatically install lazy.nvim.

โ‰ Question of the day!

Q. ๐Ÿคจ How do I install plugins?
A. Just follow this crash course!

require("lazy").setup(plugins, opts)
Enter fullscreen mode Exit fullscreen mode

plugins would be an table of plugins and, opts would be a table of options.
ok kthxbye/

I meant...

Crash course vII: Install the catppuccin colorscheme.

I love catppuccin. So let's get some mocha!

Create a new directory in lua named plugins. And in /plugins/ make a new module named colorscheme.lua

So, our file thing should look like:

~/.config/nvim/
โ”œโ”€โ”€ init.lua
โ””โ”€โ”€ lua/
    โ”œโ”€โ”€ core/
    โ”‚   โ”œโ”€โ”€ init.lua
    โ”‚   โ””โ”€โ”€ options.lua
    โ””โ”€โ”€ keymaps/
        โ””โ”€โ”€ movement.lua
        โ””โ”€โ”€ ...
    โ””โ”€โ”€ plugins/
        โ””โ”€โ”€ colorscheme.lua
        โ””โ”€โ”€ ...
Enter fullscreen mode Exit fullscreen mode

In colorscheme.lua it should look like:

return {
    "catppuccin/nvim"
}
Enter fullscreen mode Exit fullscreen mode

This code should be self-explanatory but, I'll give you a "high level overview" of it.
It returns a table.

Whoo! Now in lazy.lua replace whatever I gave you (replace("lazy").setup(...)) with...

require("lazy").setup({
  { import = "plugins" }
})
Enter fullscreen mode Exit fullscreen mode

Now we're all done! Now let's go get a cup of mocha.
In our setup/init.lua...

-- Some code here...
vim.cmd.colorscheme "catppuccin"
Enter fullscreen mode Exit fullscreen mode

Now it should show the beautiful catppuccin theme! Let's actually get a cup of mocha now!

(Quick plug: here)

kthxbye :wq

Top comments (4)

Collapse
 
componhead profile image
emiliano • Edited

Hi. Thank you for the good article. Is it possible to add some vim options (i.e. vim.o.nu) in a file in plugins folder instead of at root level (aka init.lua file)?

Collapse
 
asyncedd profile image
Async hronous • Edited

Yes, I think so. As long the vim table is accessible, you can set Neovim options anywhere in your Lua code, including in plugin files. So, it should be possible to set Neovim options like vim.o.nu in a file located in the plugins folder. (TL;DR: it should be, as long the vim table is accessible, which should be the case)

Collapse
 
cozydev profile image
The Cozy Developer

Create a new module named lazy.lua

And how do we do that? Why not starting from the beginning?

Collapse
 
asyncedd profile image
Async hronous

Sorry for my slow response (being 2 months late is no excuse)
But, I've did start from the beginning here