Course Lessons
Installation and Setup!
none-ls ... or should I say null-ls? has a ton of built-in formatting and diagnostic tooling that we can take advantage of.
To install none-ls, we want to create a new file in our configuration. Lets call it none-ls.lua
pretty straightforward. Then, to initialize none-ls in our config, lets return a lua table fromm this file, that has none-ls's url, like this
return {
"nvimtools/none-ls.nvim",
}
Now, when we restart neovim, we see that non-ls is being installed. great.
Next, lets setup none-ls to use stylua
the formatting tool for lua. stylua
is a built-in for none-ls, meaning none-ls has pre-defined configurations for this plugin. To reference all the builtins for none-ls, check out this link: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md
You can reference☝️to check what builtins none-ls has for your formatting/linting needs. There are a lot there!
To use a formatter or linter in none-ls, there are two things you have to do:
- install the linter/formatter through mason
- ensure you configure that linter/formatter to be used by builtin configuration for none-ls.
In order to use stylua
, we need to install it first with Mason
by opening up :Mason
and installing it there. Once installed via mason, we can edit our file like so:
return {
"nvimtools/none-ls.nvim",
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
},
})
vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, {})
end,
}
As you can see, we also added a line to set a keymap to actually format our files with our configured formatters. Now, you just have to type <leader>gf
to format any file that you've configured!
You've completed this lesson!
You completed this lesson less than a minute ago.