Home Explore Blog CI



neovim

42th chunk of `runtime/doc/lua.txt`
5454628d7893e22f71f93ca90ce5ea467f828e5be49c10710000000100000fc6
 expanded/resolved, the
    caller must do that).

    Example: >lua
        local root_dir
        for dir in vim.fs.parents(vim.api.nvim_buf_get_name(0)) do
          if vim.fn.isdirectory(dir .. '/.git') == 1 then
            root_dir = dir
            break
          end
        end

        if root_dir then
          print('Found git repository at', root_dir)
        end
<

    Attributes: ~
        Since: 0.8.0

    Parameters: ~
      • {start}  (`string`) Initial path.

    Return (multiple): ~
        (`fun(_, dir: string): string?`) Iterator
        (`nil`)
        (`string?`)

vim.fs.relpath({base}, {target}, {opts})                    *vim.fs.relpath()*
    Gets `target` path relative to `base`, or `nil` if `base` is not an
    ancestor.

    Example: >lua
        vim.fs.relpath('/var', '/var/lib') -- 'lib'
        vim.fs.relpath('/var', '/usr/bin') -- nil
<

    Parameters: ~
      • {base}    (`string`)
      • {target}  (`string`)
      • {opts}    (`table?`) Reserved for future use

    Return: ~
        (`string?`)

vim.fs.rm({path}, {opts})                                        *vim.fs.rm()*
    Remove files or directories

    Attributes: ~
        Since: 0.11.0

    Parameters: ~
      • {path}  (`string`) Path to remove
      • {opts}  (`table?`) A table with the following fields:
                • {recursive}? (`boolean`) Remove directories and their
                  contents recursively
                • {force}? (`boolean`) Ignore nonexistent files and arguments

vim.fs.root({source}, {marker})                                *vim.fs.root()*
    Find the first parent directory containing a specific "marker", relative
    to a file path or buffer.

    If the buffer is unnamed (has no backing file) or has a non-empty
    'buftype' then the search begins from Nvim's |current-directory|.

    Example: >lua
        -- Find the root of a Python project, starting from file 'main.py'
        vim.fs.root(vim.fs.joinpath(vim.env.PWD, 'main.py'), {'pyproject.toml', 'setup.py' })

        -- Find the root of a git repository
        vim.fs.root(0, '.git')

        -- Find the parent directory containing any file with a .csproj extension
        vim.fs.root(0, function(name, path)
          return name:match('%.csproj$') ~= nil
        end)
<

    Attributes: ~
        Since: 0.10.0

    Parameters: ~
      • {source}  (`integer|string`) Buffer number (0 for current buffer) or
                  file path (absolute or relative to the |current-directory|)
                  to begin the search from.
      • {marker}  (`string|string[]|fun(name: string, path: string): boolean`)
                  A marker, or list of markers, to search for. If a function,
                  the function is called for each evaluated item and should
                  return true if {name} and {path} are a match.

    Return: ~
        (`string?`) Directory path containing one of the given markers, or nil
        if no directory was found.


==============================================================================
Lua module: vim.glob                                                *vim.glob*

Glob-to-LPeg Converter (Peglob) This module converts glob patterns to LPeg
patterns according to the LSP 3.17 specification:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#pattern

Glob grammar overview:
• `*` to match zero or more characters in a path segment
• `?` to match on one character in a path segment
• `**` to match any number of path segments, including none
• `{}` to group conditions (e.g. `*.{ts,js}` matches TypeScript and JavaScript
  files)
• `[]` to declare a range of characters to match in a path segment (e.g.,
  `example.[0-9]` to match on `example.0`, `example.1`, …)
• `[!...]` to negate a range of characters to match in a path segment (e.g.,
  `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)

Additional constraints:
• A Glob pattern must match an entire path,

Title: Lua API: vim.fs (relpath, rm, root) and vim.glob
Summary
This section details the `vim.fs` Lua API, including: `relpath` (gets relative path), `rm` (removes files or directories), and `root` (finds parent directory containing a marker). It also introduces `vim.glob`, a module for converting glob patterns to LPeg patterns, outlining supported glob grammar (e.g., `*`, `?`, `**`, `{}`, `[]`, `[!...]`) and constraints.