diff options
Diffstat (limited to 'runtime/doc/lua.txt')
-rw-r--r-- | runtime/doc/lua.txt | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 8ae1c6dc40..e3e0665025 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2359,12 +2359,37 @@ find({names}, {opts}) *vim.fs.find()* The search can be narrowed to find only files or only directories by specifying {type} to be "file" or "directory", respectively. + Examples: >lua + + -- location of Cargo.toml from the current buffer's path + local cargo = vim.fs.find('Cargo.toml', { + upward = true, + stop = vim.loop.os_homedir(), + path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)), + }) + + -- list all test directories under the runtime directory + local test_dirs = vim.fs.find( + {'test', 'tst', 'testdir'}, + {limit = math.huge, type = 'directory', path = './runtime/'} + ) + + -- get all files ending with .cpp or .hpp inside lib/ + local cpp_hpp = vim.fs.find(function(name, path) + return name:match('.*%.[ch]pp$') and path:match('[/\\]lib$') + end, {limit = math.huge, type = 'file'}) +< + Parameters: ~ - • {names} (string|table|fun(name: string): boolean) Names of the files - and directories to find. Must be base names, paths and globs - are not supported. The function is called per file and - directory within the traversed directories to test if they - match {names}. + • {names} (string|table|fun(name: string, path: string): boolean) Names + of the files and directories to find. Must be base names, + paths and globs are not supported when {names} is a string or + a table. If {names} is a function, it is called for each + traversed file and directory with args: + • name: base name of the current item + • path: full path of the current item The function should + return `true` if the given file or directory is considered + a match. • {opts} (table) Optional keyword arguments: • path (string): Path to begin searching from. If omitted, the |current-directory| is used. |