comparison runtime/doc/eval.txt @ 16231:0761a4c111a7 v8.1.1120

patch 8.1.1120: cannot easily get directory entry matches commit https://github.com/vim/vim/commit/543c9b1921d7605498b54afdef518e312f1b4515 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Apr 5 22:50:40 2019 +0200 patch 8.1.1120: cannot easily get directory entry matches Problem: Cannot easily get directory entry matches. Solution: Add the readdir() function. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/2439)
author Bram Moolenaar <Bram@vim.org>
date Fri, 05 Apr 2019 23:00:06 +0200
parents abb67309c1ca
children 219c58b3879c
comparison
equal deleted inserted replaced
16230:55efca92c30f 16231:0761a4c111a7
2505 pyeval({expr}) any evaluate |Python| expression 2505 pyeval({expr}) any evaluate |Python| expression
2506 py3eval({expr}) any evaluate |python3| expression 2506 py3eval({expr}) any evaluate |python3| expression
2507 pyxeval({expr}) any evaluate |python_x| expression 2507 pyxeval({expr}) any evaluate |python_x| expression
2508 range({expr} [, {max} [, {stride}]]) 2508 range({expr} [, {max} [, {stride}]])
2509 List items from {expr} to {max} 2509 List items from {expr} to {max}
2510 readdir({directory} [, {expr}])
2511 List file names on {dir} with evalating
2512 {expr}
2510 readfile({fname} [, {type} [, {max}]]) 2513 readfile({fname} [, {type} [, {max}]])
2511 List get list of lines from file {fname} 2514 List get list of lines from file {fname}
2512 reg_executing() String get the executing register name 2515 reg_executing() String get the executing register name
2513 reg_recording() String get the recording register name 2516 reg_recording() String get the recording register name
2514 reltime([{start} [, {end}]]) List get time value 2517 reltime([{start} [, {end}]]) List get time value
7254 range(2, 9, 3) " [2, 5, 8] 7257 range(2, 9, 3) " [2, 5, 8]
7255 range(2, -2, -1) " [2, 1, 0, -1, -2] 7258 range(2, -2, -1) " [2, 1, 0, -1, -2]
7256 range(0) " [] 7259 range(0) " []
7257 range(2, 0) " error! 7260 range(2, 0) " error!
7258 < 7261 <
7262 *readdir()*
7263 readdir({directory} [, {expr}])
7264 Return a list with file and directory names in {directory}.
7265
7266 When {expr} is omitted all entries are included.
7267 When {expr} is given, it is evaluated to check what to do:
7268 If {expr} results in -1 then no further entries will
7269 be handled.
7270 If {expr} results in 0 then this entry will not be
7271 added to the list.
7272 If {expr} results in 1 then this entry will be added
7273 to the list.
7274 Each time {expr} is evaluated |v:val| is set to the entry name.
7275 When {expr} is a function the name is passed as the argument.
7276 For example, to get a list of files ending in ".txt": >
7277 readdir(dirname, {n -> n =~ '.txt$'})
7278 < To skip hidden and backup files: >
7279 readdir(dirname, {n -> n !~ '^\.\|\~$'})
7280
7281 < If you want to get a directory tree: >
7282 function! s:tree(dir)
7283 return {a:dir : map(readdir(a:dir),
7284 \ {_, x -> isdirectory(x) ?
7285 \ {x : s:tree(a:dir . '/' . x)} : x})}
7286 endfunction
7287 echo s:tree(".")
7288 <
7259 *readfile()* 7289 *readfile()*
7260 readfile({fname} [, {type} [, {max}]]) 7290 readfile({fname} [, {type} [, {max}]])
7261 Read file {fname} and return a |List|, each line of the file 7291 Read file {fname} and return a |List|, each line of the file
7262 as an item. Lines are broken at NL characters. Macintosh 7292 as an item. Lines are broken at NL characters. Macintosh
7263 files separated with CR will result in a single long line 7293 files separated with CR will result in a single long line