comparison runtime/doc/eval.txt @ 9626:172131507c85 v7.4.2090

commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 22 21:50:18 2016 +0200 patch 7.4.2090 Problem: Using submatch() in a lambda passed to substitute() is verbose. Solution: Use a static list and pass it as an optional argument to the function. Fix memory leak.
author Christian Brabandt <cb@256bit.org>
date Fri, 22 Jul 2016 22:00:07 +0200
parents 05a56bbe34a1
children ccbb8e393d80
comparison
equal deleted inserted replaced
9625:4c2524dd2403 9626:172131507c85
1 *eval.txt* For Vim version 7.4. Last change: 2016 Jul 16 1 *eval.txt* For Vim version 7.4. Last change: 2016 Jul 22
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
1533 |json_encode()|. 1533 |json_encode()|.
1534 When used as a string this evaluates to "v:false". > 1534 When used as a string this evaluates to "v:false". >
1535 echo v:false 1535 echo v:false
1536 < v:false ~ 1536 < v:false ~
1537 That is so that eval() can parse the string back to the same 1537 That is so that eval() can parse the string back to the same
1538 value. 1538 value. Read-only.
1539 1539
1540 *v:fcs_reason* *fcs_reason-variable* 1540 *v:fcs_reason* *fcs_reason-variable*
1541 v:fcs_reason The reason why the |FileChangedShell| event was triggered. 1541 v:fcs_reason The reason why the |FileChangedShell| event was triggered.
1542 Can be used in an autocommand to decide what to do and/or what 1542 Can be used in an autocommand to decide what to do and/or what
1543 to set v:fcs_choice to. Possible values: 1543 to set v:fcs_choice to. Possible values:
1680 When used as a number this evaluates to zero. 1680 When used as a number this evaluates to zero.
1681 When used as a string this evaluates to "v:none". > 1681 When used as a string this evaluates to "v:none". >
1682 echo v:none 1682 echo v:none
1683 < v:none ~ 1683 < v:none ~
1684 That is so that eval() can parse the string back to the same 1684 That is so that eval() can parse the string back to the same
1685 value. 1685 value. Read-only.
1686 1686
1687 *v:null* *null-variable* 1687 *v:null* *null-variable*
1688 v:null An empty String. Used to put "null" in JSON. See 1688 v:null An empty String. Used to put "null" in JSON. See
1689 |json_encode()|. 1689 |json_encode()|.
1690 When used as a number this evaluates to zero. 1690 When used as a number this evaluates to zero.
1691 When used as a string this evaluates to "v:null". > 1691 When used as a string this evaluates to "v:null". >
1692 echo v:null 1692 echo v:null
1693 < v:null ~ 1693 < v:null ~
1694 That is so that eval() can parse the string back to the same 1694 That is so that eval() can parse the string back to the same
1695 value. 1695 value. Read-only.
1696 1696
1697 *v:oldfiles* *oldfiles-variable* 1697 *v:oldfiles* *oldfiles-variable*
1698 v:oldfiles List of file names that is loaded from the |viminfo| file on 1698 v:oldfiles List of file names that is loaded from the |viminfo| file on
1699 startup. These are the files that Vim remembers marks for. 1699 startup. These are the files that Vim remembers marks for.
1700 The length of the List is limited by the ' argument of the 1700 The length of the List is limited by the ' argument of the
1888 |json_encode()|. 1888 |json_encode()|.
1889 When used as a string this evaluates to "v:true". > 1889 When used as a string this evaluates to "v:true". >
1890 echo v:true 1890 echo v:true
1891 < v:true ~ 1891 < v:true ~
1892 That is so that eval() can parse the string back to the same 1892 That is so that eval() can parse the string back to the same
1893 value. 1893 value. Read-only.
1894 *v:val* *val-variable* 1894 *v:val* *val-variable*
1895 v:val Value of the current item of a |List| or |Dictionary|. Only 1895 v:val Value of the current item of a |List| or |Dictionary|. Only
1896 valid while evaluating the expression used with |map()| and 1896 valid while evaluating the expression used with |map()| and
1897 |filter()|. Read-only. 1897 |filter()|. Read-only.
1898 1898
7142 7142
7143 When {pat} does not match in {expr}, {expr} is returned 7143 When {pat} does not match in {expr}, {expr} is returned
7144 unmodified. 7144 unmodified.
7145 7145
7146 Example: > 7146 Example: >
7147 :let &path = substitute(&path, ",\\=[^,]*$", "", "") 7147 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
7148 < This removes the last component of the 'path' option. > 7148 < This removes the last component of the 'path' option. >
7149 :echo substitute("testing", ".*", "\\U\\0", "") 7149 :echo substitute("testing", ".*", "\\U\\0", "")
7150 < results in "TESTING". 7150 < results in "TESTING".
7151 7151
7152 When {sub} starts with "\=", the remainder is interpreted as 7152 When {sub} starts with "\=", the remainder is interpreted as
7153 an expression. See |sub-replace-expression|. Example: > 7153 an expression. See |sub-replace-expression|. Example: >
7154 :echo substitute(s, '%\(\x\x\)', 7154 :echo substitute(s, '%\(\x\x\)',
7155 \ '\=nr2char("0x" . submatch(1))', 'g') 7155 \ '\=nr2char("0x" . submatch(1))', 'g')
7156
7157 < When {sub} is a Funcref that function is called, with one
7158 optional argument. Example: >
7159 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
7160 < The optional argument is a list which contains the whole
7161 matched string and up to nine submatches,like what
7162 |submatch()| returns. Example: >
7163 :echo substitute(s, '\(\x\x\)', {m -> '0x' . m[1]}, 'g')
7156 7164
7157 synID({lnum}, {col}, {trans}) *synID()* 7165 synID({lnum}, {col}, {trans}) *synID()*
7158 The result is a Number, which is the syntax ID at the position 7166 The result is a Number, which is the syntax ID at the position
7159 {lnum} and {col} in the current window. 7167 {lnum} and {col} in the current window.
7160 The syntax ID can be used with |synIDattr()| and 7168 The syntax ID can be used with |synIDattr()| and
7544 echo trunc(4.0) 7552 echo trunc(4.0)
7545 < 4.0 7553 < 4.0
7546 {only available when compiled with the |+float| feature} 7554 {only available when compiled with the |+float| feature}
7547 7555
7548 *type()* 7556 *type()*
7549 type({expr}) The result is a Number, depending on the type of {expr}: 7557 type({expr}) The result is a Number representing the type of {expr}.
7550 Number: 0 7558 Instead of using the number directly, it is better to use the
7551 String: 1 7559 v:t_ variable that has the value:
7552 Funcref: 2 7560 Number: 0 |v:t_number|
7553 List: 3 7561 String: 1 |v:t_string|
7554 Dictionary: 4 7562 Funcref: 2 |v:t_func|
7555 Float: 5 7563 List: 3 |v:t_list|
7556 Boolean: 6 (v:false and v:true) 7564 Dictionary: 4 |v:t_dict|
7557 None 7 (v:null and v:none) 7565 Float: 5 |v:t_float|
7558 Job 8 7566 Boolean: 6 |v:t_bool| (v:false and v:true)
7559 Channel 9 7567 None 7 |v:t_none| (v:null and v:none)
7560 To avoid the magic numbers it should be used this way: > 7568 Job 8 |v:t_job|
7569 Channel 9 |v:t_channel|
7570 For backward compatibility, this method can be used: >
7561 :if type(myvar) == type(0) 7571 :if type(myvar) == type(0)
7562 :if type(myvar) == type("") 7572 :if type(myvar) == type("")
7563 :if type(myvar) == type(function("tr")) 7573 :if type(myvar) == type(function("tr"))
7564 :if type(myvar) == type([]) 7574 :if type(myvar) == type([])
7565 :if type(myvar) == type({}) 7575 :if type(myvar) == type({})
7566 :if type(myvar) == type(0.0) 7576 :if type(myvar) == type(0.0)
7567 :if type(myvar) == type(v:false) 7577 :if type(myvar) == type(v:false)
7568 :if type(myvar) == type(v:none) 7578 :if type(myvar) == type(v:none)
7579 < To check if the v:t_ variables exist use this: >
7580 :if exists('v:t_number')
7569 7581
7570 undofile({name}) *undofile()* 7582 undofile({name}) *undofile()*
7571 Return the name of the undo file that would be used for a file 7583 Return the name of the undo file that would be used for a file
7572 with name {name} when writing. This uses the 'undodir' 7584 with name {name} when writing. This uses the 'undodir'
7573 option, finding directories that exist. It does not check if 7585 option, finding directories that exist. It does not check if