1- *eval.txt* For Vim version 7.4. Last change: 2016 Feb 05
1+ *eval.txt* For Vim version 7.4. Last change: 2016 Feb 07
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -37,7 +37,7 @@ done, the features in this document are not available. See |+eval| and
3737
38381.1 Variable types ~
3939 *E712*
40- There are six types of variables:
40+ There are eight types of variables:
4141
4242Number A 32 or 64 bit signed number. | expr-number | *Number*
4343 Examples: -123 0x10 0177
@@ -49,16 +49,20 @@ Float A floating point number. |floating-point-format| *Float*
4949String A NUL terminated string of 8-bit unsigned characters (bytes).
5050 | expr-string | Examples: "ab\txx\"--" 'x-z''a,c'
5151
52- Funcref A reference to a function | Funcref | .
53- Example: function("strlen")
54-
5552List An ordered sequence of items | List | .
5653 Example: [1, 2, ['a', 'b']]
5754
5855Dictionary An associative, unordered array: Each entry has a key and a
5956 value. | Dictionary |
6057 Example: {'blue' : "#0000ff", 'red' : "#ff0000"}
6158
59+ Funcref A reference to a function | Funcref | .
60+ Example: function("strlen")
61+
62+ Special v:false, v:true, v:none and v:null
63+
64+ Job Used for job control, see | job_start() | .
65+
6266The Number and String types are converted automatically, depending on how they
6367are used.
6468
@@ -95,15 +99,16 @@ Note that in the command >
9599 "foo" is converted to 0, which means FALSE. To test for a non-empty string,
96100use empty(): >
97101 :if !empty("foo")
98- < *E745* *E728* *E703* *E729* *E730* *E731*
99- List, Dictionary and Funcref types are not automatically converted.
102+ <
103+ *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910*
104+ List, Dictionary, Funcref and Job types are not automatically converted.
100105
101106 *E805* *E806* *E808*
102107When mixing Number and Float the Number is converted to Float. Otherwise
103108there is no automatic conversion of Float. You can use str2float() for String
104109to Float, printf() for Float to String and float2nr() for Float to Number.
105110
106- *E891* *E892* *E893* *E894*
111+ *E891* *E892* *E893* *E894* *E907* *E911 *
107112When expecting a Float a Number can also be used, but nothing else.
108113
109114 *E706* *sticky-type-checking*
@@ -864,7 +869,7 @@ These three can be repeated and mixed. Examples:
864869expr8 *expr8*
865870-----
866871expr8[expr1] item of String or | List | *expr-[]* *E111*
867-
872+ *E909*
868873If expr8 is a Number or String this results in a String that contains the
869874expr1'th single byte from expr8. expr8 is used as a String, expr1 as a
870875Number. This doesn't recognize multi-byte encodings, see | byteidx() | for
@@ -1947,6 +1952,9 @@ invert( {expr}) Number bitwise invert
19471952isdirectory( {directory} ) Number TRUE if {directory} is a directory
19481953islocked( {expr} ) Number TRUE if {expr} is locked
19491954items( {dict} ) List key-value pairs in {dict}
1955+ job_start({command} [, {options} ]) Job start a job
1956+ job_status({job} ) String get the status of a job
1957+ job_stop({job} [, {how} ]) Number stop a job
19501958join( {list} [, {sep} ]) String join {list} items into one String
19511959jsondecode( {string} ) any decode JSON
19521960jsonencode( {expr} ) String encode JSON
@@ -2668,6 +2676,7 @@ confirm({msg} [, {choices} [, {default} [, {type}]]])
26682676
26692677ch_close({handle} ) *ch_close()*
26702678 Close channel {handle} . See | channel | .
2679+ {only available when compiled with the | +channel | feature}
26712680
26722681ch_open({address} [, {argdict} ]) *ch_open()*
26732682 Open a channel to {address} . See | channel | .
@@ -2677,7 +2686,7 @@ ch_open({address} [, {argdict}]) *ch_open()*
26772686 {address} has the form "hostname:port", e.g.,
26782687 "localhost:8765".
26792688
2680- If {argdict} is given it must be a | Directory | . The optional
2689+ If {argdict} is given it must be a | Dictionary | . The optional
26812690 items are:
26822691 mode "raw" or "json".
26832692 Default "json".
@@ -2686,10 +2695,11 @@ ch_open({address} [, {argdict}]) *ch_open()*
26862695 Default: none.
26872696 waittime Specify connect timeout as milliseconds.
26882697 Negative means forever.
2689- Default: 0.
2698+ Default: 0 (don't wait)
26902699 timeout Specify response read timeout value as
26912700 milliseconds.
26922701 Default: 2000.
2702+ {only available when compiled with the | +channel | feature}
26932703
26942704ch_sendexpr({handle} , {expr} [, {callback} ]) *ch_sendexpr()*
26952705 Send {expr} over JSON channel {handle} . See | channel-use | .
@@ -2704,10 +2714,14 @@ ch_sendexpr({handle}, {expr} [, {callback}]) *ch_sendexpr()*
27042714 function. It is called when the response is received. See
27052715 | channel-callback | .
27062716
2717+ {only available when compiled with the | +channel | feature}
2718+
27072719ch_sendraw({handle} , {string} [, {callback} ]) *ch_sendraw()*
27082720 Send {string} over raw channel {handle} . See | channel-raw | .
27092721 Works like | ch_sendexpr() | , but does not decode the response.
27102722
2723+ {only available when compiled with the | +channel | feature}
2724+
27112725 *copy()*
27122726copy({expr} ) Make a copy of {expr} . For Numbers and Strings this isn't
27132727 different from using {expr} directly.
@@ -2888,9 +2902,12 @@ diff_hlID({lnum}, {col}) *diff_hlID()*
28882902
28892903empty({expr} ) *empty()*
28902904 Return the Number 1 if {expr} is empty, zero otherwise.
2891- A | List | or | Dictionary | is empty when it does not have any
2892- items. A Number is empty when its value is zero.
2893- | v:false | , | v:none | and | v:null | are empty, | v:true | is not.
2905+ - A | List | or | Dictionary | is empty when it does not have any
2906+ items.
2907+ - A Number and Float is empty when its value is zero.
2908+ - | v:false | , | v:none | and | v:null | are empty, | v:true | is not.
2909+ - A Job is empty when it failed to start.
2910+
28942911 For a long | List | this is much faster than comparing the
28952912 length with zero.
28962913
@@ -4286,6 +4303,73 @@ items({dict}) *items()*
42864303 order.
42874304
42884305
4306+ job_start({command} [, {options} ]) *job_start()*
4307+ Start a job and return a Job object. Unlike | system() | and
4308+ | :!cmd | this does not wait for the job to finish.
4309+
4310+ {command} can be a string. This works best on MS-Windows. On
4311+ Unix it is split up in white-separated parts to be passed to
4312+ execvp(). Arguments in double quotes can contain white space.
4313+
4314+ {command} can be a list, where the first item is the executable
4315+ and further items are the arguments. All items are converted
4316+ to String. This works best on Unix.
4317+
4318+ The command is executed directly, not through a shell, the
4319+ 'shell' option is not used. To use the shell: >
4320+ let job = job_start(["/bin/sh", "-c", "echo hello"])
4321+ < Or: >
4322+ let job = job_start('/bin/sh -c "echo hello"')
4323+ < However, the status of the job will now be the status of the
4324+ shell, and stopping the job means stopping the shell and the
4325+ command may continue to run.
4326+
4327+ On Unix $PATH is used to search for the executable only when
4328+ the command does not contain a slash.
4329+
4330+ The job will use the same terminal as Vim. If it reads from
4331+ stdin the job and Vim will be fighting over input, that
4332+ doesn't work. Redirect stdin and stdout to avoid problems: >
4333+ let job = job_start(['sh', '-c', "myserver </dev/null >/dev/null"])
4334+ <
4335+ The returned Job object can be used to get the status with
4336+ | job_status() | and stop the job with | job_stop() | .
4337+
4338+ {options} must be a Dictionary. It can contain these optional
4339+ items:
4340+ killonexit When non-zero kill the job when Vim
4341+ exits. (default: 0, don't kill)
4342+
4343+ {only available when compiled with the | +channel | feature}
4344+
4345+ job_status({job} ) *job_status()*
4346+ Returns a String with the status of {job} :
4347+ "run" job is running
4348+ "fail" job failed to start
4349+ "dead" job died or was stopped after running
4350+
4351+ {only available when compiled with the | +channel | feature}
4352+
4353+ job_stop({job} [, {how} ]) *job_stop()*
4354+ Stop the {job} . This can also be used to signal the job.
4355+
4356+ When {how} is omitted or is "term" the job will be terminated
4357+ normally. For Unix SIGTERM is sent.
4358+ Other values:
4359+ "hup" Unix: SIGHUP
4360+ "quit" Unix: SIGQUIT
4361+ "kill" Unix: SIGKILL (strongest way to stop)
4362+ number Unix: signal with that number
4363+
4364+ The result is a Number: 1 if the operation could be executed,
4365+ 0 if "how" is not supported on the system.
4366+ Note that even when the operation was executed, whether the
4367+ job was actually stopped needs to be checked with
4368+ job_status().
4369+ The operation will even be done when the job wasn't running.
4370+
4371+ {only available when compiled with the | +channel | feature}
4372+
42894373join({list} [, {sep} ]) *join()*
42904374 Join the items in {list} together into one String.
42914375 When {sep} is specified it is put in between the items. If
@@ -6692,6 +6776,7 @@ type({expr}) The result is a Number, depending on the type of {expr}:
66926776 Float: 5
66936777 Boolean: 6 (v:false and v:true)
66946778 None 7 (v:null and v:none)
6779+ Job 8
66956780 To avoid the magic numbers it should be used this way: >
66966781 :if type(myvar) == type(0)
66976782 :if type(myvar) == type("")
0 commit comments