Home Explore Blog CI



neovim

39th chunk of `runtime/doc/lua.txt`
66be1b0ae9a1592cb151ffc2e9c2a2fe6ff58fbe8cfd21e50000000100000fc1
 Right-hand side |{rhs}| of the mapping,
                can be a Lua function.
      • {opts}  (`table?`) Table of |:map-arguments|. Same as
                |nvim_set_keymap()| {opts}, except:
                • {replace_keycodes} defaults to `true` if "expr" is `true`.

                Also accepts:
                • {buffer}? (`integer|boolean`) Creates buffer-local mapping,
                  `0` or `true` for current buffer.
                • {remap}? (`boolean`, default: `false`) Make the mapping
                  recursive. Inverse of {noremap}.

    See also: ~
      • |nvim_set_keymap()|
      • |maparg()|
      • |mapcheck()|
      • |mapset()|


==============================================================================
Lua module: vim.fs                                                    *vim.fs*


                                                             *vim.fs.exists()*
Use |uv.fs_stat()| to check a file's type, and whether it exists.

Example: >lua
  if vim.uv.fs_stat(file) then
    vim.print('file exists')
  end
<


vim.fs.abspath({path})                                      *vim.fs.abspath()*
    Convert path to an absolute path. A tilde (~) character at the beginning
    of the path is expanded to the user's home directory. Does not check if
    the path exists, normalize the path, resolve symlinks or hardlinks
    (including `.` and `..`), or expand environment variables. If the path is
    already absolute, it is returned unchanged. Also converts `\` path
    separators to `/`.

    Parameters: ~
      • {path}  (`string`) Path

    Return: ~
        (`string`) Absolute path

vim.fs.basename({file})                                    *vim.fs.basename()*
    Return the basename of the given path

    Attributes: ~
        Since: 0.8.0

    Parameters: ~
      • {file}  (`string?`) Path

    Return: ~
        (`string?`) Basename of {file}

vim.fs.dir({path}, {opts})                                      *vim.fs.dir()*
    Return an iterator over the items located in {path}

    Attributes: ~
        Since: 0.8.0

    Parameters: ~
      • {path}  (`string`) An absolute or relative path to the directory to
                iterate over. The path is first normalized
                |vim.fs.normalize()|.
      • {opts}  (`table?`) Optional keyword arguments:
                • depth: integer|nil How deep the traverse (default 1)
                • skip: (fun(dir_name: string): boolean)|nil Predicate to
                  control traversal. Return false to stop searching the
                  current directory. Only useful when depth > 1
                • follow: boolean|nil Follow symbolic links. (default: false)

    Return: ~
        (`Iterator`) over items in {path}. Each iteration yields two values:
        "name" and "type". "name" is the basename of the item relative to
        {path}. "type" is one of the following: "file", "directory", "link",
        "fifo", "socket", "char", "block", "unknown".

vim.fs.dirname({file})                                      *vim.fs.dirname()*
    Gets the parent directory of the given path (not expanded/resolved, the
    caller must do that).

    Attributes: ~
        Since: 0.8.0

    Parameters: ~
      • {file}  (`string?`) Path

    Return: ~
        (`string?`) Parent directory of {file}

vim.fs.find({names}, {opts})                                   *vim.fs.find()*
    Find files or directories (or other items as specified by `opts.type`) in
    the given path.

    Finds items given in {names} starting from {path}. If {upward} is "true"
    then the search traverses upward through parent directories; otherwise,
    the search traverses downward. Note that downward searches are recursive
    and may search through many directories! If {stop} is non-nil, then the
    search stops when the directory given in {stop} is reached. The search
    terminates when {limit} (default 1) matches are found. You can set {type}
    to "file", "directory", "link", "socket", "char",

Title: Lua API: vim.fs (exists, abspath, basename, dir, dirname, find)
Summary
The section describes functions within the `vim.fs` Lua API. It covers `exists` to check if a file exists using `uv.fs_stat()`, `abspath` to convert a path to an absolute path, `basename` to retrieve the basename of a path, `dir` to iterate over items in a directory, `dirname` to get the parent directory of a path, and `find` to locate files or directories based on specified criteria and search direction (upward or downward).