๐Ÿ’ YAML toolkit for Neovim users

Adds register as a command argument

Fix #6

+49 -29
+3 -5
README.md
··· 5 5 | Command | Description | 6 6 |:--|:--| 7 7 | `:YAMLView` | Shows the full path and value of the current key/value pair | 8 - | `:YAMLYank` | Yanks the full path and value of the current key/value pair | 9 - | `:YAMLYankKey` | Yanks the full path of the key for the current key/value pair | 10 - | `:YAMLYankValue` | Yanks the value of the current key/value pair | 8 + | `:YAMLYank [register]` | Yanks the full path and value of the current key/value pair. The default register is the unnamed one (`"`) | 9 + | `:YAMLYankKey [register]` | Yanks the full path of the key for the current key/value pair. The default register is the unnamed one (`"`) | 10 + | `:YAMLYankValue [regster]` | Yanks the value of the current key/value pair. The default register is the unnamed one (`"`) | 11 11 | `:YAMLQuickfix` | Generates a quickfix with key/balue pairs | 12 12 | `:YAMLTelescope` | Full path key/value fuzzy finder via [Telescope](https://github.com/nvim-telescope/telescope.nvim) **if installed** | 13 - 14 - By now, it only uses to unnamed register to yank ([**TODO** allow users to choose which register to yank to](https://github.com/cuducos/yaml.nvim/issues/6)). 15 13 16 14 ![Example GIF](doc/demo.gif) 17 15
+15 -10
doc/help.txt
··· 14 14 `root.parent.child.key = value`). It uses Lua's `print` function to output 15 15 the value to the user. 16 16 17 - :YAMLYank *:YAMLYank* 17 + :YAMLYank [register] *:YAMLYank* 18 18 19 19 Yanks the full path and value of the key/value pair under the cursor to 20 - the unnamed register (see |:quotequote|). It collects all nested keys and 21 - outputs them as a dot-case string (e.g.: `root.parent.child.key = 22 - value`). 20 + the selected register. The default register is the unnamed one (see 21 + |:quotequote|). 22 + 23 + It collects all nested keys and outputs them as a dot-case string (e.g.: 24 + `root.parent.child.key = value`). 23 25 24 - :YAMLYankKey *:YAMLYankKey* 26 + :YAMLYankKey [register] *:YAMLYankKey* 25 27 26 28 Yanks the full path of the key of the key/value pair under the cursor to 27 - the unnamed register (see |:quotequote|). It collects all nested keys and 28 - outputs them as a dot-case string (e.g.: `root.parent.child.key`). 29 + the selected register. The default register is the unnamed one (see 30 + |:quotequote|). 29 31 30 - :YAMLYankValue *:YAMLYankValue* 32 + It collects all nested keys and outputs them as a dot-case string (e.g.: 33 + `root.parent.child.key`). 31 34 32 - Yanks the value of the key/value pair under the cursor to the unnamed 33 - register (see |:quotequote|). 35 + :YAMLYankValue [register] *:YAMLYankValue* 36 + 37 + Yanks the value of the key/value pair under the cursor to the selected 38 + register. The default register is the unnamed one (see |:quotequote|). 34 39 35 40 :YAMLQuickfix *YAMLQuickfix* 36 41
+31 -14
lua/yaml_nvim/init.lua
··· 16 16 return lines 17 17 end 18 18 19 - M.view = function() 20 - local node = document.get_key_relevant_to_cursor() 21 - if node == nil then 22 - return 23 - end 24 - 25 - local parsed = pair.parse(node) 26 - print(parsed.human) 27 - end 28 - 29 - M.yank = function(register, key, value) 19 + local yank = function(key, value, register) 20 + register = register or [["]] 30 21 if not key and not value then 31 22 return 32 23 end ··· 50 41 vim.cmd(string.format("call setreg('%s', '%s')", register, contents)) 51 42 end 52 43 44 + M.view = function() 45 + local node = document.get_key_relevant_to_cursor() 46 + if node == nil then 47 + return 48 + end 49 + 50 + local parsed = pair.parse(node) 51 + print(parsed.human) 52 + end 53 + 54 + M.yank_all = function(register) 55 + yank(true, true, register) 56 + end 57 + 58 + M.yank_key = function(register) 59 + yank(true, false, register) 60 + end 61 + 62 + M.yank_value = function(register) 63 + yank(false, true, register) 64 + end 65 + 53 66 M.telescope = function() 54 67 if not has_telescope then 55 68 return ··· 59 72 end 60 73 61 74 vim.cmd("command! YAMLView lua require('yaml_nvim').view()") 62 - vim.cmd("command! YAMLYank lua require('yaml_nvim').yank('\"', true, true)") 63 - vim.cmd("command! YAMLYankKey lua require('yaml_nvim').yank('\"', true, false)") 64 75 vim.cmd( 65 - "command! YAMLYankValue lua require('yaml_nvim').yank('\"', false, true)" 76 + "command! -nargs=? YAMLYank lua require('yaml_nvim').yank_all(<f-args>)" 77 + ) 78 + vim.cmd( 79 + "command! -nargs=? YAMLYankKey lua require('yaml_nvim').yank_key(<f-args>)" 80 + ) 81 + vim.cmd( 82 + "command! -nargs=? YAMLYankValue lua require('yaml_nvim').yank_value(<f-args>)" 66 83 ) 67 84 vim.cmd("command! YAMLQuickfix cex v:lua.create_yaml_quickfix()") 68 85