Skip to main content

YAML

info

You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed.

Alternatively, you can add it to your lazy.nvim imports
lua/config/lazy.lua
require("lazy").setup({
spec = {
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "lazyvim.plugins.extras.lang.yaml" },
{ import = "plugins" },
},
})

Below you can find a list of included plugins and their default settings.

caution

You don't need to copy the default settings to your config. They are only shown here for reference.

SchemaStore.nvim

yaml schema support

opts = nil

nvim-lspconfig

correctly setup lspconfig

opts = {
-- make sure mason installs the server
servers = {
yamlls = {
-- Have to add this for yamlls to understand that we support line folding
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
},
},
-- lazy-load schemastore when needed
on_new_config = function(new_config)
new_config.settings.yaml.schemas = vim.tbl_deep_extend(
"force",
new_config.settings.yaml.schemas or {},
require("schemastore").yaml.schemas()
)
end,
settings = {
redhat = { telemetry = { enabled = false } },
yaml = {
keyOrdering = false,
format = {
enable = true,
},
validate = true,
schemaStore = {
-- Must disable built-in schemaStore support to use
-- schemas from SchemaStore.nvim plugin
enable = false,
-- Avoid TypeError: Cannot read properties of undefined (reading 'length')
url = "",
},
},
},
},
},
setup = {
yamlls = function()
-- Neovim < 0.10 does not have dynamic registration for formatting
if vim.fn.has("nvim-0.10") == 0 then
LazyVim.lsp.on_attach(function(client, _)
client.server_capabilities.documentFormattingProvider = true
end, "yamlls")
end
end,
},
}