Home Explore Blog CI



neovim

30th chunk of `runtime/doc/lua.txt`
a100fc5fe9c5279786dcd62f6513cd1388d67d52af9563f80000000100000fd4
 'b', 'c' })
        end, { predicate = true })
        -- true
<

    Parameters: ~
      • {t}      (`table`) Table to check
      • {value}  (`any`) Value to compare or predicate function reference
      • {opts}   (`table?`) Keyword arguments |kwargs|:
                 • {predicate}? (`boolean`) `value` is a function reference to
                   be checked (default false)

    Return: ~
        (`boolean`) `true` if `t` contains `value`

    See also: ~
      • |vim.list_contains()| for checking values in list-like tables

vim.tbl_count({t})                                           *vim.tbl_count()*
    Counts the number of non-nil values in table `t`. >lua
        vim.tbl_count({ a=1, b=2 })  --> 2
        vim.tbl_count({ 1, 2 })      --> 2
<

    Parameters: ~
      • {t}  (`table`) Table

    Return: ~
        (`integer`) Number of non-nil values in table

    See also: ~
      • https://github.com/Tieske/Penlight/blob/master/lua/pl/tablex.lua

vim.tbl_deep_extend({behavior}, {...})                 *vim.tbl_deep_extend()*
    Merges recursively two or more tables.

    Only values that are empty tables or tables that are not |lua-list|s
    (indexed by consecutive integers starting from 1) are merged recursively.
    This is useful for merging nested tables like default and user
    configurations where lists should be treated as literals (i.e., are
    overwritten instead of merged).

    Parameters: ~
      • {behavior}  (`'error'|'keep'|'force'|fun(key:any, prev_value:any?, value:any): any`)
                    Decides what to do if a key is found in more than one map:
                    • "error": raise an error
                    • "keep": use value from the leftmost map
                    • "force": use value from the rightmost map
                    • If a function, it receives the current key, the previous
                      value in the currently merged table (if present), the
                      current value and should return the value for the given
                      key in the merged table.
      • {...}       (`table`) Two or more tables

    Return: ~
        (`table`) Merged table

    See also: ~
      • |vim.tbl_extend()|

vim.tbl_extend({behavior}, {...})                           *vim.tbl_extend()*
    Merges two or more tables.

    Parameters: ~
      • {behavior}  (`'error'|'keep'|'force'|fun(key:any, prev_value:any?, value:any): any`)
                    Decides what to do if a key is found in more than one map:
                    • "error": raise an error
                    • "keep": use value from the leftmost map
                    • "force": use value from the rightmost map
                    • If a function, it receives the current key, the previous
                      value in the currently merged table (if present), the
                      current value and should return the value for the given
                      key in the merged table.
      • {...}       (`table`) Two or more tables

    Return: ~
        (`table`) Merged table

    See also: ~
      • |extend()|

vim.tbl_filter({func}, {t})                                 *vim.tbl_filter()*
    Filter a table using a predicate function

    Parameters: ~
      • {func}  (`function`) Function
      • {t}     (`table`) Table

    Return: ~
        (`any[]`) Table of filtered values

vim.tbl_get({o}, {...})                                        *vim.tbl_get()*
    Index into a table (first argument) via string keys passed as subsequent
    arguments. Return `nil` if the key does not exist.

    Examples: >lua
        vim.tbl_get({ key = { nested_key = true }}, 'key', 'nested_key') == true
        vim.tbl_get({ key = {}}, 'key', 'nested_key') == nil
<

    Parameters: ~
      • {o}    (`table`) Table to index
      • {...}  (`any`) Optional keys (0 or more, variadic) via which to index
               the table

    Return: ~
        (`any`) Nested value indexed by key (if it exists), else nil

vim.tbl_isempty({t})

Title: Lua API: vim.tbl_deep_extend(), vim.tbl_extend(), vim.tbl_filter(), vim.tbl_get()
Summary
This section describes several table manipulation functions within the Neovim Lua API. It details `vim.tbl_deep_extend()` for recursively merging two or more tables, `vim.tbl_extend()` for merging two or more tables based on a defined behavior, `vim.tbl_filter()` for filtering a table using a predicate function, and `vim.tbl_get()` for indexing into a table via string keys passed as arguments, returning nil if the key does not exist.