···11# yaml.nvim [](https://github.com/cuducos/yaml.nvim/actions/workflows/tests.yml)
2233-Simple tools to help developers working YAML in [Neovim](https://neovim.io):
33+Simple tools to help developers working YAML in [Neovim](https://neovim.io).
44+55+Assuming `yaml = require("yaml_nvim")` for the Lua API:
4655-| Command | Description |
66-|:--|:--|
77-| `:YAMLView` | Shows the full path and value of the current key/value pair |
88-| `:YAMLYank [register]` | Yanks the full path and value of the current key/value pair. The default register is the unnamed one (`"`) |
99-| `:YAMLYankKey [register]` | Yanks the full path of the key for the current key/value pair. The default register is the unnamed one (`"`) |
1010-| `:YAMLYankValue [regster]` | Yanks the value of the current key/value pair. The default register is the unnamed one (`"`) |
1111-| `:YAMLQuickfix` | Generates a quickfix with key/value pairs |
1212-| `:YAMLTelescope` | Full path key/value fuzzy finder via [Telescope](https://github.com/nvim-telescope/telescope.nvim) **if installed** |
77+| Command | Lua API | Description |
88+|:--|:--|:--|
99+| `:YAMLView` | `yaml.view()` | Shows the full path and value of the current key/value pair |
1010+| `: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 (`"`) |
1111+| `: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 (`"`) |
1212+| `:YAMLYankValue [regster]` | `yaml.yank_value([register])` | Yanks the value of the current key/value pair. The default register is the unnamed one (`"`) |
1313+| `:YAMLQuickfix` | `yaml.quickfix()` | Generates a quickfix with key/value pairs |
1414+| `:YAMLTelescope` | `yaml.telescope()` | Full path key/value fuzzy finder via [Telescope](https://github.com/nvim-telescope/telescope.nvim) **if installed** |
13151416
15171616-It requires **Neovim 0.9** or newer, [`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter) with [YAML support](https://github.com/ikatyang/tree-sitter-yaml). Telescope is **optional**.
1818+## Requirements
1919+2020+* **Neovim 0.9** or newer
2121+* [`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter) with [YAML support](https://github.com/ikatyang/tree-sitter-yaml)
2222+2323+Telescope is **optional**.
17241825<details>
1926···3138```lua
3239use {
3340 "cuducos/yaml.nvim",
3434- ft = {"yaml"}, -- optional
4141+ ft = { "yaml" }, -- optional
3542 requires = {
3643 "nvim-treesitter/nvim-treesitter",
3744 "nvim-telescope/telescope.nvim" -- optional
+20-20
lua/yaml_nvim/init.lua
···2929 restore_filetype(restore_to)
3030end
31313232--- created in _G so we can call it with v:lua
3333-_G.create_yaml_quickfix = function()
3434- local restore_to = set_yaml_as_filetype()
3535- local lines = {}
3636-3737- for _, key in pairs(document.all_keys()) do
3838- if not document.is_value_a_block(key) then
3939- local parsed = pair.parse(key)
4040- table.insert(lines, parsed.errorformat)
4141- end
4242- end
4343-4444- restore_filetype(restore_to)
4545- return lines
4646-end
4747-4832local yank = function(key, value, register)
4933 register = register or [["]]
5034 if not key and not value then
···8468 end)
8569end
86708787-M.yank_all = function(register)
7171+M.yank = function(register)
8872 assure_yaml_filetype(yank, true, true, register)
8973end
9074···9680 assure_yaml_filetype(yank, false, true, register)
9781end
98828383+M.quickfix = function()
8484+ local restore_to = set_yaml_as_filetype()
8585+ local lines = {}
8686+8787+ for _, key in pairs(document.all_keys()) do
8888+ if not document.is_value_a_block(key) then
8989+ local parsed = pair.parse(key)
9090+ table.insert(lines, parsed.quickfix)
9191+ end
9292+ end
9393+9494+ restore_filetype(restore_to)
9595+ vim.fn.setqflist(lines)
9696+end
9797+9998M.telescope = function()
10099 if not has_telescope then
101100 return
102101 end
103103- vim.cmd("cex v:lua.create_yaml_quickfix()")
102102+103103+ M.quickfix()
104104 require("telescope.builtin").quickfix()
105105end
106106107107vim.cmd("command! YAMLView lua require('yaml_nvim').view()")
108108-vim.cmd("command! -nargs=? YAMLYank lua require('yaml_nvim').yank_all(<f-args>)")
108108+vim.cmd("command! -nargs=? YAMLYank lua require('yaml_nvim').yank(<f-args>)")
109109vim.cmd("command! -nargs=? YAMLYankKey lua require('yaml_nvim').yank_key(<f-args>)")
110110vim.cmd("command! -nargs=? YAMLYankValue lua require('yaml_nvim').yank_value(<f-args>)")
111111-vim.cmd("command! YAMLQuickfix cex v:lua.create_yaml_quickfix()")
111111+vim.cmd("command! YAMLQuickfix lua require('yaml_nvim').quickfix()")
112112113113if has_telescope then
114114 vim.cmd("command! YAMLTelescope lua require('yaml_nvim').telescope()")
+8-3
lua/yaml_nvim/pair.lua
···8989 local bufnr = vim.api.nvim_get_current_buf()
9090 local key = get_keys(node, bufnr)
9191 local value = get_value(node, bufnr)
9292- local line, _ = node:start()
9393- local path = vim.api.nvim_buf_get_name(bufnr)
9292+ local line, col = node:start()
9493 local cleaned_value = clean_up_block_value(value)
9594 local human = string.format("%s = %s", key, cleaned_value)
9695···9897 key = key,
9998 cleaned_value = cleaned_value,
10099 human = human,
101101- errorformat = string.format("%s:%d: %s", path, line + 1, human),
100100+ quickfix = {
101101+ bufnr = bufnr,
102102+ col = col,
103103+ lnum = line,
104104+ text = human,
105105+ valid = 1,
106106+ },
102107 }
103108end
104109