Home Explore Blog CI



neovim

41th chunk of `runtime/doc/lua.txt`
231c223da7096e1b902a90bea03092115b642c40929060b70000000100000fc8
 search after
                   finding this many matches. Use `math.huge` to place no
                   limit on the number of matches.
                 • {follow}? (`boolean`, default: `false`) Follow symbolic
                   links.

    Return: ~
        (`string[]`) Normalized paths |vim.fs.normalize()| of all matching
        items

vim.fs.joinpath({...})                                     *vim.fs.joinpath()*
    Concatenates partial paths (one absolute or relative path followed by zero
    or more relative paths). Slashes are normalized: redundant slashes are
    removed, and (on Windows) backslashes are replaced with forward-slashes.

    Examples:
    • "foo/", "/bar" => "foo/bar"
    • Windows: "a\foo\", "\bar" => "a/foo/bar"

    Attributes: ~
        Since: 0.10.0

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

    Return: ~
        (`string`)

vim.fs.normalize({path}, {opts})                          *vim.fs.normalize()*
    Normalize a path to a standard format. A tilde (~) character at the
    beginning of the path is expanded to the user's home directory and
    environment variables are also expanded. "." and ".." components are also
    resolved, except when the path is relative and trying to resolve it would
    result in an absolute path.
    • "." as the only part in a relative path:
      • "." => "."
      • "././" => "."
    • ".." when it leads outside the current directory
      • "foo/../../bar" => "../bar"
      • "../../foo" => "../../foo"
    • ".." in the root directory returns the root directory.
      • "/../../" => "/"

    On Windows, backslash (\) characters are converted to forward slashes (/).

    Examples: >lua
        [[C:\Users\jdoe]]                         => "C:/Users/jdoe"
        "~/src/neovim"                            => "/home/jdoe/src/neovim"
        "$XDG_CONFIG_HOME/nvim/init.vim"          => "/Users/jdoe/.config/nvim/init.vim"
        "~/src/nvim/api/../tui/./tui.c"           => "/home/jdoe/src/nvim/tui/tui.c"
        "./foo/bar"                               => "foo/bar"
        "foo/../../../bar"                        => "../../bar"
        "/home/jdoe/../../../bar"                 => "/bar"
        "C:foo/../../baz"                         => "C:../baz"
        "C:/foo/../../baz"                        => "C:/baz"
        [[\\?\UNC\server\share\foo\..\..\..\bar]] => "//?/UNC/server/share/bar"
<

    Attributes: ~
        Since: 0.8.0

    Parameters: ~
      • {path}  (`string`) Path to normalize
      • {opts}  (`table?`) A table with the following fields:
                • {expand_env}? (`boolean`, default: `true`) Expand
                  environment variables.
                • {win}? (`boolean`, default: `true` in Windows, `false`
                  otherwise) Path is a Windows path.

    Return: ~
        (`string`) Normalized path

vim.fs.parents({start})                                     *vim.fs.parents()*
    Iterate over all the parents of the given path (not 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

  

Title: Lua API: vim.fs (joinpath, normalize, parents, relpath)
Summary
This section details functions within the `vim.fs` Lua API, specifically `joinpath` (concatenates partial paths), `normalize` (converts path to standard format, expands '~' and environment variables), `parents` (iterates over parent directories of given path), and `relpath` (gets `target` path relative to `base` path).