Home Explore Blog CI



neovim

23th chunk of `runtime/doc/api.txt`
56b037d4c836ca56c143aaa6c143e76dd1d3c7fe123698460000000100000fdb
 arguments.

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

    Attributes: ~
        Since: 0.3.0

    Parameters: ~
      • {dict}  Dict, or String evaluating to a Vimscript |self| dict
      • {fn}    Name of the function defined on the Vimscript dict
      • {args}  Function arguments packed in an Array

    Return: ~
        Result of the function call

nvim_call_function({fn}, {args})                        *nvim_call_function()*
    Calls a Vimscript function with the given arguments.

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

    Attributes: ~
        Since: 0.1.0

    Parameters: ~
      • {fn}    Function to call
      • {args}  Function arguments packed in an Array

    Return: ~
        Result of the function call

nvim_command({command})                                       *nvim_command()*
    Executes an Ex command.

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

    Prefer |nvim_cmd()| or |nvim_exec2()| instead. To modify an Ex command in
    a structured way before executing it, modify the result of
    |nvim_parse_cmd()| then pass it to |nvim_cmd()|.

    Attributes: ~
        Since: 0.1.0

    Parameters: ~
      • {command}  Ex command string

nvim_eval({expr})                                                *nvim_eval()*
    Evaluates a Vimscript |expression|. Dicts and Lists are recursively
    expanded.

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

    Attributes: ~
        Since: 0.1.0

    Parameters: ~
      • {expr}  Vimscript expression string

    Return: ~
        Evaluation result or expanded object

nvim_exec2({src}, {opts})                                       *nvim_exec2()*
    Executes Vimscript (multiline block of Ex commands), like anonymous
    |:source|.

    Unlike |nvim_command()| this function supports heredocs, script-scope
    (s:), etc.

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

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {src}   Vimscript code
      • {opts}  Optional parameters.
                • output: (boolean, default false) Whether to capture and
                  return all (non-error, non-shell |:!|) output.

    Return: ~
        Dict containing information about execution, with these keys:
        • output: (string|nil) Output if `opts.output` is true.

    See also: ~
      • |execute()|
      • |nvim_command()|
      • |nvim_cmd()|

                                                     *nvim_parse_expression()*
nvim_parse_expression({expr}, {flags}, {highlight})
    Parse a Vimscript expression.

    Attributes: ~
        |api-fast|
        Since: 0.3.0

    Parameters: ~
      • {expr}       Expression to parse. Always treated as a single line.
      • {flags}      Flags:
                     • "m" if multiple expressions in a row are allowed (only
                       the first one will be parsed),
                     • "E" if EOC tokens are not allowed (determines whether
                       they will stop parsing process or be recognized as an
                       operator/space, though also yielding an error).
                     • "l" when needing to start parsing with lvalues for
                       ":let" or ":for". Common flag sets:
                     • "m" to parse like for `":echo"`.
                     • "E" to parse like for `"<C-r>="`.
                     • empty string for ":call".
                     • "lm" to parse for ":let".
      • {highlight}  If true, return value will also include "highlight" key
                     containing array of 4-tuples (arrays) (Integer, Integer,
                     Integer, String), where first three numbers define the
                     highlighted region and represent line, starting column
                     and ending column (latter exclusive: one should highlight
                     region [start_col, end_col)).

    Return: ~
        • AST: top-level

Title: Nvim API: Vimscript Execution and Expression Parsing
Summary
This section describes Nvim API functions for interacting with Vimscript, including calling functions (`nvim_call_dict_function`, `nvim_call_function`), executing Ex commands (`nvim_command`), evaluating expressions (`nvim_eval`), and executing multiline Vimscript blocks (`nvim_exec2`). It also details `nvim_parse_expression` for parsing Vimscript expressions and obtaining their abstract syntax tree (AST).