Home Explore Blog CI



neovim

26th chunk of `runtime/doc/api.txt`
4b0b3031c762768d258a68569de4cb9331a1ffd8dcfd13d80000000100000fe4
 example, instead of `vim.cmd.bdelete{ count = 2 }`, you may do
    `vim.cmd.bdelete(2)`.

    On execution error: fails with Vimscript error, updates v:errmsg.

    Attributes: ~
        Since: 0.8.0

    Parameters: ~
      • {cmd}   Command to execute. Must be a Dict that can contain the same
                values as the return value of |nvim_parse_cmd()| except
                "addr", "nargs" and "nextcmd" which are ignored if provided.
                All values except for "cmd" are optional.
      • {opts}  Optional parameters.
                • output: (boolean, default false) Whether to return command
                  output.

    Return: ~
        Command output (non-error, non-shell |:!|) if `output` is true, else
        empty string.

    See also: ~
      • |nvim_exec2()|
      • |nvim_command()|

                                                  *nvim_create_user_command()*
nvim_create_user_command({name}, {command}, {opts})
    Creates a global |user-commands| command.

    For Lua usage see |lua-guide-commands-create|.

    Example: >vim
        :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {'bang': v:true})
        :SayHello
        Hello world!
<

    Attributes: ~
        Since: 0.7.0

    Parameters: ~
      • {name}     Name of the new user command. Must begin with an uppercase
                   letter.
      • {command}  Replacement command to execute when this user command is
                   executed. When called from Lua, the command can also be a
                   Lua function. The function is called with a single table
                   argument that contains the following keys:
                   • name: (string) Command name
                   • args: (string) The args passed to the command, if any
                     <args>
                   • fargs: (table) The args split by unescaped whitespace
                     (when more than one argument is allowed), if any <f-args>
                   • nargs: (string) Number of arguments |:command-nargs|
                   • bang: (boolean) "true" if the command was executed with a
                     ! modifier <bang>
                   • line1: (number) The starting line of the command range
                     <line1>
                   • line2: (number) The final line of the command range
                     <line2>
                   • range: (number) The number of items in the command range:
                     0, 1, or 2 <range>
                   • count: (number) Any count supplied <count>
                   • reg: (string) The optional register, if specified <reg>
                   • mods: (string) Command modifiers, if any <mods>
                   • smods: (table) Command modifiers in a structured format.
                     Has the same structure as the "mods" key of
                     |nvim_parse_cmd()|.
      • {opts}     Optional |command-attributes|.
                   • Set boolean attributes such as |:command-bang| or
                     |:command-bar| to true (but not |:command-buffer|, use
                     |nvim_buf_create_user_command()| instead).
                   • "complete" |:command-complete| also accepts a Lua
                     function which works like
                     |:command-completion-customlist|.
                   • Other parameters:
                     • desc: (string) Used for listing the command when a Lua
                       function is used for {command}.
                     • force: (boolean, default true) Override any previous
                       definition.
                     • preview: (function) Preview callback for 'inccommand'
                       |:command-preview|

nvim_del_user_command({name})                        *nvim_del_user_command()*
    Delete a user-defined command.

    Attributes: ~
        Since: 0.7.0

    Parameters: ~
      • {name}  Name of the command to delete.

nvim_get_commands({opts})                                *nvim_get_commands()*

Title: API Command Functions: nvim_create_user_command and nvim_del_user_command
Summary
This section details the `nvim_create_user_command` function, which creates a global user command in Neovim. It describes the parameters including the command name, the replacement command (which can be a string or a Lua function), and optional attributes. The function allows setting command attributes like `:command-bang`, and accepting a Lua function for completion. It also describes the `nvim_del_user_command` function, which deletes a user-defined command.