how to access parameter of nvim_create_user_command

Viewed 85

I am writing a lua function as custom command for my neovim config.

As the documentation says "The function is called with a single table argument that contains the following keys", but how can i access these keys when the table is not defined to a variable.

I tried calling the function like this:

vim.api.nvim_create_user_command('Build', fn_build(args), { nargs='?' })

and access the values with:

function fn_build(args)
  run = args["args"] or nil
end

but i would get a nil error.


@Ani commented:

Try to see if there is anything close to this, in github.com/nanotee/nvim-lua-guide

I found the guide, but it didn't helped me to fix it. I'm not sure if desc is the right variable to use. And how would i even use it. The guide says:

Two additional attributes are available:

  1. desc allows you to control what gets displayed when you run :command {cmd} on a command defined as a Lua callback. Similarly to keymaps, it is recommended to add a desc key to commands defined as Lua functions.
  2. force is equivalent to calling :command! and replaces a command if one with the same name already exists. It is true by default, unlike its Vimscript equivalent.

Am i blind and overseeing something?

Please point me in the right direction

0 Answers
Related