Home Explore Blog CI



neovim

50th chunk of `runtime/doc/lua.txt`
dfe43f5c9f5317d23118998e222fef11e9334fe0eb6ee5740000000100000fc2
 given {subject}, returning all
    captures.

    Parameters: ~
      • {subject}  (`string`)
      • {pattern}  (`vim.lpeg.Pattern|string`)
      • {init}     (`integer?`)

    Return: ~
        (`integer|vim.lpeg.Capture?`)

    See also: ~
      • vim.lpeg.match()

vim.re.updatelocale()                                  *vim.re.updatelocale()*
    Updates the pre-defined character classes to the current locale.


==============================================================================
VIM.REGEX                                                          *vim.regex*

Vim regexes can be used directly from Lua. Currently they only allow matching
within a single line.


                                                          *regex:match_line()*
regex:match_line({bufnr}, {line_idx}, {start}, {end_})
    Matches line at `line_idx` (zero-based) in buffer `bufnr`. Match is
    restricted to byte index range `start` and `end_` if given, otherwise see
    |regex:match_str()|. Returned byte indices are relative to `start` if
    given.

    Parameters: ~
      • {bufnr}     (`integer`)
      • {line_idx}  (`integer`)
      • {start}     (`integer?`)
      • {end_}      (`integer?`)

    Return (multiple): ~
        (`integer?`) match start (byte index) relative to `start`, or `nil` if
        no match
        (`integer?`) match end (byte index) relative to `start`, or `nil` if
        no match

regex:match_str({str})                                     *regex:match_str()*
    Matches string `str` against this regex. To match the string precisely,
    surround the regex with "^" and "$". Returns the byte indices for the
    start and end of the match, or `nil` if there is no match. Because any
    integer is "truthy", `regex:match_str()` can be directly used as a
    condition in an if-statement.

    Parameters: ~
      • {str}  (`string`)

    Return (multiple): ~
        (`integer?`) match start (byte index), or `nil` if no match
        (`integer?`) match end (byte index), or `nil` if no match

vim.regex({re})                                                  *vim.regex()*
    Parses the Vim regex `re` and returns a regex object. Regexes are "magic"
    and case-sensitive by default, regardless of 'magic' and 'ignorecase'.
    They can be controlled with flags, see |/magic| and |/ignorecase|.

    Parameters: ~
      • {re}  (`string`)

    Return: ~
        (`vim.regex`)


==============================================================================
Lua module: vim.secure                                            *vim.secure*

vim.secure.read({path})                                    *vim.secure.read()*
    If {path} is a file: attempt to read the file, prompting the user if the
    file should be trusted.

    If {path} is a directory: return true if the directory is trusted
    (non-recursive), prompting the user as necessary.

    The user's choice is persisted in a trust database at
    $XDG_STATE_HOME/nvim/trust.

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {path}  (`string`) Path to a file or directory to read.

    Return: ~
        (`boolean|string?`) If {path} is not trusted or does not exist,
        returns `nil`. Otherwise, returns the contents of {path} if it is a
        file, or true if {path} is a directory.

    See also: ~
      • |:trust|

vim.secure.trust({opts})                                  *vim.secure.trust()*
    Manage the trust database.

    The trust database is located at |$XDG_STATE_HOME|/nvim/trust.

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {opts}  (`table`) A table with the following fields:
                • {action} (`'allow'|'deny'|'remove'`) - `'allow'` to add a
                  file to the trust database and trust it,
                • `'deny'` to add a file to the trust database and deny it,
                • `'remove'` to remove file from the trust database
                • {path}? (`string`) Path to a file to update. Mutually
      

Title: Lua API: vim.regex Functions and vim.secure Module
Summary
This section details the functions within the `vim.regex` module, including `regex:match_line()`, `regex:match_str()`, and `vim.regex()`. `regex:match_line()` matches a line in a buffer with a given regex. `regex:match_str()` matches a string against a regex. `vim.regex()` parses a Vim regex and returns a regex object. The section also introduces the `vim.secure` module, which provides functions for managing file and directory trust. The main functions are `vim.secure.read()` which attempts to read a file or checks if a directory is trusted, prompting the user if necessary, and `vim.secure.trust()` which allows managing the trust database.