Mercurial > vim
comparison runtime/doc/eval.txt @ 20856:83cfa1ef1bf2
Update runtime files
Commit: https://github.com/vim/vim/commit/65e0d77a66b7e50beb562ad554ace46c32ef8f0f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 14 17:29:55 2020 +0200
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 14 Jun 2020 17:45:04 +0200 |
parents | 2616c5a337e0 |
children | 69055d27e85e |
comparison
equal
deleted
inserted
replaced
20855:6390b8b611fb | 20856:83cfa1ef1bf2 |
---|---|
1 *eval.txt* For Vim version 8.2. Last change: 2020 Jun 07 | 1 *eval.txt* For Vim version 8.2. Last change: 2020 Jun 14 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
1531 An internal variable is explicitly destroyed with the ":unlet" command | 1531 An internal variable is explicitly destroyed with the ":unlet" command |
1532 |:unlet|. | 1532 |:unlet|. |
1533 Using a name that is not an internal variable or refers to a variable that has | 1533 Using a name that is not an internal variable or refers to a variable that has |
1534 been destroyed results in an error. | 1534 been destroyed results in an error. |
1535 | 1535 |
1536 *variable-scope* | |
1536 There are several name spaces for variables. Which one is to be used is | 1537 There are several name spaces for variables. Which one is to be used is |
1537 specified by what is prepended: | 1538 specified by what is prepended: |
1538 | 1539 |
1539 (nothing) In a function: local to a function; otherwise: global | 1540 (nothing) In a function: local to a function; otherwise: global |
1540 |buffer-variable| b: Local to the current buffer. | 1541 |buffer-variable| b: Local to the current buffer. |
1549 The scope name by itself can be used as a |Dictionary|. For example, to | 1550 The scope name by itself can be used as a |Dictionary|. For example, to |
1550 delete all script-local variables: > | 1551 delete all script-local variables: > |
1551 :for k in keys(s:) | 1552 :for k in keys(s:) |
1552 : unlet s:[k] | 1553 : unlet s:[k] |
1553 :endfor | 1554 :endfor |
1554 < | 1555 |
1556 Note: in Vim9 script this is different, see |vim9-scopes|. | |
1557 | |
1555 *buffer-variable* *b:var* *b:* | 1558 *buffer-variable* *b:var* *b:* |
1556 A variable name that is preceded with "b:" is local to the current buffer. | 1559 A variable name that is preceded with "b:" is local to the current buffer. |
1557 Thus you can have several "b:foo" variables, one for each buffer. | 1560 Thus you can have several "b:foo" variables, one for each buffer. |
1558 This kind of variable is deleted when the buffer is wiped out or deleted with | 1561 This kind of variable is deleted when the buffer is wiped out or deleted with |
1559 |:bdelete|. | 1562 |:bdelete|. |
4521 Flatten {list} up to {maxdepth} levels. Without {maxdepth} | 4524 Flatten {list} up to {maxdepth} levels. Without {maxdepth} |
4522 the result is a |List| without nesting, as if {maxdepth} is | 4525 the result is a |List| without nesting, as if {maxdepth} is |
4523 a very large number. | 4526 a very large number. |
4524 The {list} is changed in place, make a copy first if you do | 4527 The {list} is changed in place, make a copy first if you do |
4525 not want that. | 4528 not want that. |
4526 *E964* | 4529 *E900* |
4527 {maxdepth} means how deep in nested lists changes are made. | 4530 {maxdepth} means how deep in nested lists changes are made. |
4528 {list} is not modified when {maxdepth} is 0. | 4531 {list} is not modified when {maxdepth} is 0. |
4529 {maxdepth} must be positive number. | 4532 {maxdepth} must be positive number. |
4530 | 4533 |
4531 If there is an error the number zero is returned. | 4534 If there is an error the number zero is returned. |
6276 inputlist({textlist}) *inputlist()* | 6279 inputlist({textlist}) *inputlist()* |
6277 {textlist} must be a |List| of strings. This |List| is | 6280 {textlist} must be a |List| of strings. This |List| is |
6278 displayed, one string per line. The user will be prompted to | 6281 displayed, one string per line. The user will be prompted to |
6279 enter a number, which is returned. | 6282 enter a number, which is returned. |
6280 The user can also select an item by clicking on it with the | 6283 The user can also select an item by clicking on it with the |
6281 mouse. For the first string 0 is returned. When clicking | 6284 mouse, if the mouse is enabled in the command line ('mouse' is |
6282 above the first item a negative number is returned. When | 6285 "a" or includes "c"). For the first string 0 is returned. |
6283 clicking on the prompt one more than the length of {textlist} | 6286 When clicking above the first item a negative number is |
6284 is returned. | 6287 returned. When clicking on the prompt one more than the |
6288 length of {textlist} is returned. | |
6285 Make sure {textlist} has less than 'lines' entries, otherwise | 6289 Make sure {textlist} has less than 'lines' entries, otherwise |
6286 it won't work. It's a good idea to put the entry number at | 6290 it won't work. It's a good idea to put the entry number at |
6287 the start of the string. And put a prompt in the first item. | 6291 the start of the string. And put a prompt in the first item. |
6288 Example: > | 6292 Example: > |
6289 let color = inputlist(['Select color:', '1. red', | 6293 let color = inputlist(['Select color:', '1. red', |
11781 exactly the right file name. A function that can be autoloaded has a name | 11785 exactly the right file name. A function that can be autoloaded has a name |
11782 like this: > | 11786 like this: > |
11783 | 11787 |
11784 :call filename#funcname() | 11788 :call filename#funcname() |
11785 | 11789 |
11790 These functions are always global, in Vim9 script "g:" needs to be used: > | |
11791 :call g:filename#funcname() | |
11792 | |
11786 When such a function is called, and it is not defined yet, Vim will search the | 11793 When such a function is called, and it is not defined yet, Vim will search the |
11787 "autoload" directories in 'runtimepath' for a script file called | 11794 "autoload" directories in 'runtimepath' for a script file called |
11788 "filename.vim". For example "~/.vim/autoload/filename.vim". That file should | 11795 "filename.vim". For example "~/.vim/autoload/filename.vim". That file should |
11789 then define the function like this: > | 11796 then define the function like this: > |
11790 | 11797 |
11792 echo "Done!" | 11799 echo "Done!" |
11793 endfunction | 11800 endfunction |
11794 | 11801 |
11795 The file name and the name used before the # in the function must match | 11802 The file name and the name used before the # in the function must match |
11796 exactly, and the defined function must have the name exactly as it will be | 11803 exactly, and the defined function must have the name exactly as it will be |
11797 called. | 11804 called. In Vim9 script the "g:" prefix must be used: > |
11805 function g:filename#funcname() | |
11806 | |
11807 or for a compiled function: > | |
11808 def g:filename#funcname() | |
11798 | 11809 |
11799 It is possible to use subdirectories. Every # in the function name works like | 11810 It is possible to use subdirectories. Every # in the function name works like |
11800 a path separator. Thus when calling a function: > | 11811 a path separator. Thus when calling a function: > |
11801 | 11812 |
11802 :call foo#bar#func() | 11813 :call foo#bar#func() |
11874 :let @{i} = '' " error | 11885 :let @{i} = '' " error |
11875 :echo @{i} " error | 11886 :echo @{i} " error |
11876 | 11887 |
11877 ============================================================================== | 11888 ============================================================================== |
11878 7. Commands *expression-commands* | 11889 7. Commands *expression-commands* |
11890 | |
11891 Note: in Vim9 script `:let` is used for variable declaration, not assignment. | |
11892 An assignment leaves out the `:let` command. |vim9-declaration| | |
11879 | 11893 |
11880 :let {var-name} = {expr1} *:let* *E18* | 11894 :let {var-name} = {expr1} *:let* *E18* |
11881 Set internal variable {var-name} to the result of the | 11895 Set internal variable {var-name} to the result of the |
11882 expression {expr1}. The variable will get the type | 11896 expression {expr1}. The variable will get the type |
11883 from the {expr}. If {var-name} didn't exist yet, it | 11897 from the {expr}. If {var-name} didn't exist yet, it |
12097 w: local window variables | 12111 w: local window variables |
12098 t: local tab page variables | 12112 t: local tab page variables |
12099 s: script-local variables | 12113 s: script-local variables |
12100 l: local function variables | 12114 l: local function variables |
12101 v: Vim variables. | 12115 v: Vim variables. |
12116 This does not work in Vim9 script. |vim9-declaration| | |
12102 | 12117 |
12103 :let List the values of all variables. The type of the | 12118 :let List the values of all variables. The type of the |
12104 variable is indicated before the value: | 12119 variable is indicated before the value: |
12105 <nothing> String | 12120 <nothing> String |
12106 # Number | 12121 # Number |
12107 * Funcref | 12122 * Funcref |
12123 This does not work in Vim9 script. |vim9-declaration| | |
12108 | 12124 |
12109 :unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795* | 12125 :unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795* |
12110 Remove the internal variable {name}. Several variable | 12126 Remove the internal variable {name}. Several variable |
12111 names can be given, they are all removed. The name | 12127 names can be given, they are all removed. The name |
12112 may also be a |List| or |Dictionary| item. | 12128 may also be a |List| or |Dictionary| item. |