diff options
author | Hennadii Chernyshchyk <genaloner@gmail.com> | 2020-05-05 18:15:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 08:15:45 -0700 |
commit | d2766b06c8fc50d06765c5c607744cc6b5f5ef0a (patch) | |
tree | 1b3b1a46c44a9c33163d0ef111d70e3bb3fd5784 /runtime | |
parent | 48c219829786c14b6e511229a59e2fda32ffe352 (diff) | |
download | rneovim-d2766b06c8fc50d06765c5c607744cc6b5f5ef0a.tar.gz rneovim-d2766b06c8fc50d06765c5c607744cc6b5f5ef0a.tar.bz2 rneovim-d2766b06c8fc50d06765c5c607744cc6b5f5ef0a.zip |
vim-patch:8.1.1120: cannot easily get directory entry matches #12222
Problem: Cannot easily get directory entry matches.
Solution: Add the readdir() function. (Yasuhiro Matsumoto, closes vim/vim#2439)
https://github.com/vim/vim/commit/543c9b1921d7605498b54afdef518e312f1b4515
closes #12212
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 4ff6269004..6f13b34876 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -6689,6 +6689,33 @@ range({expr} [, {max} [, {stride}]]) *range()* range(0) " [] range(2, 0) " error! < + *readdir()* +readdir({directory} [, {expr}]) + Return a list with file and directory names in {directory}. + + When {expr} is omitted all entries are included. + When {expr} is given, it is evaluated to check what to do: + If {expr} results in -1 then no further entries will + be handled. + If {expr} results in 0 then this entry will not be + added to the list. + If {expr} results in 1 then this entry will be added + to the list. + Each time {expr} is evaluated |v:val| is set to the entry name. + When {expr} is a function the name is passed as the argument. + For example, to get a list of files ending in ".txt": > + readdir(dirname, {n -> n =~ '.txt$'}) +< To skip hidden and backup files: > + readdir(dirname, {n -> n !~ '^\.\|\~$'}) + +< If you want to get a directory tree: > + function! s:tree(dir) + return {a:dir : map(readdir(a:dir), + \ {_, x -> isdirectory(x) ? + \ {x : s:tree(a:dir . '/' . x)} : x})} + endfunction + echo s:tree(".") +< *readfile()* readfile({fname} [, {binary} [, {max}]]) Read file {fname} and return a |List|, each line of the file @@ -6720,17 +6747,6 @@ readfile({fname} [, {binary} [, {max}]]) the result is an empty list. Also see |writefile()|. - *readdir()* -readdir({directory} [, {expr}]) - Return a list with file and directory names in {directory}. - You can also use |glob()| if you don't need to do complicated - things, such as limiting the number of matches. - - When {expr} is omitted all entries are included. - When {expr} is given, it is evaluated to check what to do: - If {expr} results in -1 then no further entries will - be handled. - reg_executing() *reg_executing()* Returns the single letter name of the register being executed. Returns an empty string when no register is being executed. |