Home

Awesome

yaml.nvim Tests status

Simple tools to help developers working YAML in Neovim.

Assuming yaml = require("yaml_nvim") for the Lua API:

CommandLua APIDescription
:YAMLViewyaml.view()Shows the full path and value of the current key/value pair
:YAMLYank [register]yaml.yank_all([register])Yanks the full path and value of the current key/value pair. The default register is the unnamed one (")
:YAMLYankKey [register]yaml.yank_key([register])Yanks the full path of the key for the current key/value pair. The default register is the unnamed one (")
:YAMLYankValue [register]yaml.yank_value([register])Yanks the value of the current key/value pair. The default register is the unnamed one (")
:YAMLQuickfixyaml.quickfix()Generates a quickfix with key/value pairs
:YAMLTelescopeyaml.telescope()Full path key/value fuzzy finder via Telescope if installed

Example GIF

Requirements

Telescope is optional.

<details> <summary>What about older versions of Neovim?</summary> </details>

Install

With lazy.nvim

{
  "cuducos/yaml.nvim",
  ft = { "yaml" }, -- optional
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-telescope/telescope.nvim", -- optional
  },
}

With packer.nvim:

use {
  "cuducos/yaml.nvim",
  ft = { "yaml" }, -- optional
  requires = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-telescope/telescope.nvim" -- optional
  },
}

With vim-plug:

Plug 'nvim-telescope/telescope.nvim' " optional
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'cuducos/yaml.nvim'

Configuration

File types

The plugin ignores other file types than YAML. By now the list of YAML file types includes yaml and eruby.yaml — we're are open to enhance this list, so PRs are welcomed.

If you want to manually change this list, you can pass a custom config:

require("yaml_nvim").setup({ ft = { "yaml",  "other yaml filetype" } })

Showing the YAML path and value

Neovim's winbar

vim.api.nvim_create_autocmd({ "BufEnter", "CursorMoved" }, {
	pattern = { "*.yaml" },
	callback = function()
		vim.opt_local.winbar = require("yaml_nvim").get_yaml_key_and_value()
	end,
})

You can also call get_yaml_key() instead of get_yaml_key_and_value() to show only the YAML key.

Neovim's statusline (with lualine.nvim)

require("lualine").setup({
	sections = {
		lualine_x = { require("yaml_nvim").get_yaml_key_and_value },
		-- etc
    }
})

Reporting bugs and contributing

There is a mini toolchain to help you test the plugin in isolation using a container. It requires:

CommandDescription
./manage buildBuilds the container
./manage testRuns the tests inside the container
./manage nvimOpens the container's Neovim with a sample YAML file