1- *eval.txt* For Vim version 7.4. Last change: 2016 Jul 09
1+ *eval.txt* For Vim version 7.4. Last change: 2016 Jul 16
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -140,9 +140,10 @@ You will not get an error if you try to change the type of a variable.
140140
1411411.2 Function references ~
142142 *Funcref* *E695* *E718*
143- A Funcref variable is obtained with the | function() | function. It can be used
144- in an expression in the place of a function name, before the parenthesis
145- around the arguments, to invoke the function it refers to. Example: >
143+ A Funcref variable is obtained with the | function() | function or created with
144+ the lambda expression | expr-lambda | . It can be used in an expression in the
145+ place of a function name, before the parenthesis around the arguments, to
146+ invoke the function it refers to. Example: >
146147
147148 :let Fn = function("MyFunc")
148149 :echo Fn()
@@ -694,6 +695,7 @@ Expression syntax summary, from least to most significant:
694695 @r contents of register 'r'
695696 function(expr1, ...) function call
696697 func{ti} on(expr1, ...) function call with curly braces
698+ {args -> expr1} lambda expression
697699
698700
699701".." indicates that the operations in this level can be concatenated.
@@ -1207,6 +1209,42 @@ function(expr1, ...) function call
12071209See below | functions | .
12081210
12091211
1212+ lambda expression *expr-lambda* *lambda*
1213+ -----------------
1214+ {args -> expr1} lambda expression
1215+
1216+ A lambda expression creates a new unnamed function which returns the result of
1217+ evaluating | expr1 | . Lambda expressions differ from | user-functions | in
1218+ the following ways:
1219+
1220+ 1. The body of the lambda expression is an | expr1 | and not a sequence of | Ex |
1221+ commands.
1222+ 2. The prefix "a:" is optional for arguments. E.g.: >
1223+ :let F = {arg1, arg2 -> arg1 - arg2}
1224+ :echo F(5, 2)
1225+ < 3
1226+
1227+ The arguments are optional. Example: >
1228+ :let F = {-> 'error function'}
1229+ :echo F()
1230+ < error function
1231+
1232+ Examples for using a lambda expression with | sort() | , | map() | and | filter() | : >
1233+ :echo map([1, 2, 3], {idx, val -> val + 1})
1234+ < [2, 3, 4] >
1235+ :echo sort([3,7,2,1,4], {a, b -> a - b})
1236+ < [1, 2, 3, 4, 7]
1237+
1238+ The lambda expression is also useful for Channel, Job and timer: >
1239+ :let timer = timer_start(500,
1240+ \ {-> execute("echo 'Handler called'", "")},
1241+ \ {'repeat': 3})
1242+ < Handler called
1243+ Handler called
1244+ Handler called
1245+
1246+ Note how execute() is used to execute an Ex command. That's ugly though.
1247+
12101248==============================================================================
121112493. Internal variable *internal-variables* *E461*
12121250
@@ -1876,7 +1914,7 @@ USAGE RESULT DESCRIPTION ~
18761914abs({expr} ) Float or Number absolute value of {expr}
18771915acos({expr} ) Float arc cosine of {expr}
18781916add({list} , {item} ) List append {item} to | List | {list}
1879- and({expr} , {expr} ) Number bitwise AND
1917+ and({expr} , {expr} ) Number bitwise AND
18801918append({lnum} , {string} ) Number append {string} below line {lnum}
18811919append({lnum} , {list} ) Number append lines {list} below line {lnum}
18821920argc() Number number of files in the argument list
@@ -1894,7 +1932,7 @@ assert_notmatch({pat}, {text} [, {msg}]) none assert {pat} not matches {text}
18941932assert_true({actual} [, {msg} ]) none assert {actual} is true
18951933asin({expr} ) Float arc sine of {expr}
18961934atan({expr} ) Float arc tangent of {expr}
1897- atan2({expr} , {expr} ) Float arc tangent of {expr1} / {expr2}
1935+ atan2({expr} , {expr} ) Float arc tangent of {expr1} / {expr2}
18981936browse({save} , {title} , {initdir} , {default} )
18991937 String put up a file requester
19001938browsedir({title} , {initdir} ) String put up a directory requester
@@ -1918,21 +1956,21 @@ ch_evalraw({handle}, {string} [, {options}])
19181956 any evaluate {string} on raw {handle}
19191957ch_getbufnr({handle} , {what} ) Number get buffer number for {handle} /{what}
19201958ch_getjob({channel} ) Job get the Job of {channel}
1921- ch_info({handle} ) String info about channel {handle}
1959+ ch_info({handle} ) String info about channel {handle}
19221960ch_log({msg} [, {handle} ]) none write {msg} in the channel log file
19231961ch_logfile({fname} [, {mode} ]) none start logging channel activity
19241962ch_open({address} [, {options} ])
1925- Channel open a channel to {address}
1926- ch_read({handle} [, {options} ]) String read from {handle}
1963+ Channel open a channel to {address}
1964+ ch_read({handle} [, {options} ]) String read from {handle}
19271965ch_readraw({handle} [, {options} ])
1928- String read raw from {handle}
1966+ String read raw from {handle}
19291967ch_sendexpr({handle} , {expr} [, {options} ])
19301968 any send {expr} over JSON {handle}
19311969ch_sendraw({handle} , {string} [, {options} ])
19321970 any send {string} over raw {handle}
19331971ch_setoptions({handle} , {options} )
19341972 none set options for {handle}
1935- ch_status({handle} ) String status of channel {handle}
1973+ ch_status({handle} ) String status of channel {handle}
19361974changenr() Number current change number
19371975char2nr({expr} [, {utf8} ]) Number ASCII/UTF8 value of first char in {expr}
19381976cindent({lnum} ) Number C indent for line {lnum}
@@ -1947,7 +1985,7 @@ copy({expr}) any make a shallow copy of {expr}
19471985cos({expr} ) Float cosine of {expr}
19481986cosh({expr} ) Float hyperbolic cosine of {expr}
19491987count({list} , {expr} [, {ic} [, {start} ]])
1950- Number count how many {expr} are in {list}
1988+ Number count how many {expr} are in {list}
19511989cscope_connection([{num} , {dbpath} [, {prepend} ]])
19521990 Number checks existence of cscope connection
19531991cursor({lnum} , {col} [, {off} ])
@@ -1964,7 +2002,7 @@ eval({string}) any evaluate {string} into its value
19642002eventhandler() Number | TRUE | if inside an event handler
19652003executable({expr} ) Number 1 if executable {expr} exists
19662004execute({command} ) String execute {command} and get the output
1967- exepath({expr} ) String full path of the command {expr}
2005+ exepath({expr} ) String full path of the command {expr}
19682006exists({expr} ) Number | TRUE | if {expr} exists
19692007extend({expr1} , {expr2} [, {expr3} ])
19702008 List/Dict insert items of {expr2} into {expr1}
@@ -1992,7 +2030,7 @@ foldtext() String line displayed for closed fold
19922030foldtextresult({lnum} ) String text for closed fold at {lnum}
19932031foreground() Number bring the Vim window to the foreground
19942032function({name} [, {arglist} ] [, {dict} ])
1995- Funcref reference to function {name}
2033+ Funcref reference to function {name}
19962034garbagecollect([{atexit} ]) none free memory, breaking cyclic references
19972035get({list} , {idx} [, {def} ]) any get item {idx} from {list} or {def}
19982036get({dict} , {key} [, {def} ]) any get item {key} from {dict} or {def}
@@ -2036,7 +2074,7 @@ getwinvar({nr}, {varname} [, {def}])
20362074 any variable {varname} in window {nr}
20372075glob({expr} [, {nosuf} [, {list} [, {alllinks} ]]])
20382076 any expand file wildcards in {expr}
2039- glob2regpat({expr} ) String convert a glob pat into a search pat
2077+ glob2regpat({expr} ) String convert a glob pat into a search pat
20402078globpath({path} , {expr} [, {nosuf} [, {list} [, {alllinks} ]]])
20412079 String do glob({expr} ) for all dirs in {path}
20422080has({feature} ) Number | TRUE | if feature {feature} supported
@@ -2059,22 +2097,22 @@ index({list}, {expr} [, {start} [, {ic}]])
20592097input({prompt} [, {text} [, {completion} ]])
20602098 String get input from the user
20612099inputdialog({prompt} [, {text} [, {completion} ]]])
2062- String like input() but in a GUI dialog
2100+ String like input() but in a GUI dialog
20632101inputlist({textlist} ) Number let the user pick from a choice list
20642102inputrestore() Number restore typeahead
20652103inputsave() Number save and clear typeahead
2066- inputsecret({prompt} [, {text} ]) String like input() but hiding the text
2104+ inputsecret({prompt} [, {text} ]) String like input() but hiding the text
20672105insert({list} , {item} [, {idx} ]) List insert {item} in {list} [before {idx} ]
2068- invert({expr} ) Number bitwise invert
2106+ invert({expr} ) Number bitwise invert
20692107isdirectory({directory} ) Number | TRUE | if {directory} is a directory
20702108islocked({expr} ) Number | TRUE | if {expr} is locked
2071- isnan({expr} ) Number | TRUE | if {expr} is NaN
2109+ isnan({expr} ) Number | TRUE | if {expr} is NaN
20722110items({dict} ) List key-value pairs in {dict}
20732111job_getchannel({job} ) Channel get the channel handle for {job}
20742112job_info({job} ) Dict get information about {job}
20752113job_setoptions({job} , {options} ) none set options for {job}
20762114job_start({command} [, {options} ])
2077- Job start a job
2115+ Job start a job
20782116job_status({job} ) String get the status of {job}
20792117job_stop({job} [, {how} ]) Number stop {job}
20802118join({list} [, {sep} ]) String join {list} items into one String
@@ -2085,7 +2123,7 @@ json_encode({expr}) String encode JSON
20852123keys({dict} ) List keys in {dict}
20862124len({expr} ) Number the length of {expr}
20872125libcall({lib} , {func} , {arg} ) String call {func} in library {lib} with {arg}
2088- libcallnr({lib} , {func} , {arg} ) Number idem, but return a Number
2126+ libcallnr({lib} , {func} , {arg} ) Number idem, but return a Number
20892127line({expr} ) Number line nr of cursor, last line or mark
20902128line2byte({lnum} ) Number byte count of line {lnum}
20912129lispindent({lnum} ) Number Lisp indent for line {lnum}
@@ -2123,7 +2161,7 @@ mode([expr]) String current editing mode
21232161mzeval({expr} ) any evaluate | MzScheme | expression
21242162nextnonblank({lnum} ) Number line nr of non-blank line >= {lnum}
21252163nr2char({expr} [, {utf8} ]) String single char with ASCII/UTF8 value {expr}
2126- or({expr} , {expr} ) Number bitwise OR
2164+ or({expr} , {expr} ) Number bitwise OR
21272165pathshorten({expr} ) String shorten directory names in a path
21282166perleval({expr} ) any evaluate | Perl | expression
21292167pow({x} , {y} ) Float {x} to the power of {y}
@@ -2231,7 +2269,7 @@ synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
22312269synIDattr({synID} , {what} [, {mode} ])
22322270 String attribute {what} of syntax ID {synID}
22332271synIDtrans({synID} ) Number translated syntax ID of {synID}
2234- synconcealed({lnum} , {col} ) List info about concealing
2272+ synconcealed({lnum} , {col} ) List info about concealing
22352273synstack({lnum} , {col} ) List stack of syntax IDs at {lnum} and {col}
22362274system({expr} [, {input} ]) String output of shell command/filter {expr}
22372275systemlist({expr} [, {input} ]) List output of shell command/filter {expr}
@@ -2288,7 +2326,7 @@ winwidth({nr}) Number width of window {nr}
22882326wordcount() Dict get byte/char/word statistics
22892327writefile({list} , {fname} [, {flags} ])
22902328 Number write list of lines to file {fname}
2291- xor({expr} , {expr} ) Number bitwise XOR
2329+ xor({expr} , {expr} ) Number bitwise XOR
22922330
22932331
22942332abs({expr} ) *abs()*
@@ -3278,7 +3316,8 @@ execute({command} [, {silent}]) *execute()*
32783316 "silent" `:silent ` used
32793317 "silent!" `:silent ! ` used
32803318 The default is 'silent' . Note that with "silent!", unlike
3281- `:redir ` , error messages are dropped.
3319+ `:redir ` , error messages are dropped. When using an external
3320+ command the screen may be messed up, use `system ()` instead.
32823321 *E930*
32833322 It is not possible to use `:redir ` anywhere in {command} .
32843323
@@ -7202,7 +7241,8 @@ system({expr} [, {input}]) *system()* *E677*
72027241 in a way | writefile() | does with {binary} set to "b" (i.e.
72037242 with a newline between each list item with newlines inside
72047243 list items converted to NULs).
7205- Pipes are not used.
7244+
7245+ Pipes are not used, the 'shelltemp' option is not used.
72067246
72077247 When prepended by | :silent | the shell will not be set to
72087248 cooked mode. This is meant to be used for commands that do
@@ -7894,8 +7934,6 @@ diff Compiled with |vimdiff| and 'diff' support.
78947934digraphs Compiled with support for digraphs.
78957935directx Compiled with support for Direct-X and 'renderoptions' .
78967936dnd Compiled with support for the "~ register | quote_~ | .
7897- dos16 16 bits DOS version of Vim.
7898- dos32 32 bits DOS (DJGPP) version of Vim.
78997937ebcdic Compiled on a machine with ebcdic character set.
79007938emacs_tags Compiled with support for Emacs tags.
79017939eval Compiled with expression evaluation support. Always
@@ -7971,7 +8009,6 @@ netbeans_intg Compiled with support for |netbeans|.
79718009num64 Compiled with 64-bit | Number | support.
79728010odbeditor Compiled with | odbeditor | support.
79738011ole Compiled with OLE automation support for Win32.
7974- os2 OS/2 version of Vim.
79758012packages Compiled with | packages | support.
79768013path_extra Compiled with up/downwards search in 'path' and 'tags'
79778014perl Compiled with Perl interface.
@@ -8208,10 +8245,10 @@ can be 0). "a:000" is set to a |List| that contains these arguments. Note
82088245that "a:1" is the same as "a:000[0]".
82098246 *E742*
82108247The a: scope and the variables in it cannot be changed, they are fixed.
8211- However, if a | List | or | Dictionary | is used , you can change their contents.
8212- Thus you can pass a | List | to a function and have the function add an item to
8213- it. If you want to make sure the function cannot change a | List | or
8214- | Dictionary | use | :lockvar | .
8248+ However, if a composite type is used, such as | List | or | Dictionary | , you can
8249+ change their contents. Thus you can pass a | List | to a function and have the
8250+ function add an item to it. If you want to make sure the function cannot
8251+ change a | List | or | Dictionary | use | :lockvar | .
82158252
82168253When not using "...", the number of arguments in a function call must be equal
82178254to the number of named arguments. When using "...", the number of arguments
@@ -8223,9 +8260,8 @@ until the matching |:endfunction|. It is allowed to define another function
82238260inside a function body.
82248261
82258262 *local-variables*
8226- Inside a function variables can be used. These are local variables, which
8227- will disappear when the function returns. Global variables need to be
8228- accessed with "g:".
8263+ Inside a function local variables can be used. These will disappear when the
8264+ function returns. Global variables need to be accessed with "g:".
82298265
82308266Example: >
82318267 :function Table(title, ...)
0 commit comments