comparison runtime/doc/vim9.txt @ 20115:bd021eb62e73

Update runtime files Commit: https://github.com/vim/vim/commit/2c7f8c574f1f8723d59adca3fec8fb89c41cf8c9 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 20 19:52:53 2020 +0200 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 Apr 2020 20:00:05 +0200
parents c85d4e173cc9
children 56265f711890
comparison
equal deleted inserted replaced
20114:80e88fbca4ea 20115:bd021eb62e73
1 *vim9.txt* For Vim version 8.2. Last change: 2020 Apr 09 1 *vim9.txt* For Vim version 8.2. Last change: 2020 Apr 19
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
63 In Vim script comments normally start with double quote. That can also be the 63 In Vim script comments normally start with double quote. That can also be the
64 start of a string, thus in many places it cannot be used. In Vim9 script a 64 start of a string, thus in many places it cannot be used. In Vim9 script a
65 comment can also start with #. Normally this is a command to list text with 65 comment can also start with #. Normally this is a command to list text with
66 numbers, but you can also use `:number` for that. > 66 numbers, but you can also use `:number` for that. >
67 let count = 0 # number of occurences of Ni! 67 let count = 0 # number of occurences of Ni!
68
69 To improve readability there must be a space between the command and the #
70 that starts a comment. Note that #{ is the start of a dictionary, therefore
71 it cannot start a comment.
68 72
69 73
70 Vim9 functions ~ 74 Vim9 functions ~
71 75
72 `:def` has no extra arguments like `:function` does: "range", "abort", "dict" 76 `:def` has no extra arguments like `:function` does: "range", "abort", "dict"
78 - There is no "a:" dictionary or "a:000" list. Variable arguments are defined 82 - There is no "a:" dictionary or "a:000" list. Variable arguments are defined
79 with a name and have a list type: > 83 with a name and have a list type: >
80 def MyFunc(...itemlist: list<type>) 84 def MyFunc(...itemlist: list<type>)
81 for item in itemlist 85 for item in itemlist
82 ... 86 ...
87
88
89 Functions are script-local by default ~
90
91 When using `:function` or `:def` to specify a new function at the script level
92 in a Vim9 script, the function is local to the script, as if "s:" was
93 prefixed. To define a global function the "g:" prefix must be used.
94
95 When using `:function` or `:def` to specify a new function inside a function,
96 the function is local to the function. It is not possible to define a
97 script-local function inside a function. To define a global function the "g:"
98 prefix must be used.
99
100 When referring to a function and no "s:" or "g:" prefix is used, Vim will
101 search for the function in this order:
102 - Local to the current function scope.
103 - Local to the current script file.
104 - Imported functions, see `:import`.
105 - Global.
106
107 Global functions can be defined and deleted at nearly any time. In Vim9
108 script script-local functions are defined once when the script is sourced and
109 cannot be deleted.
83 110
84 111
85 Variable declarations with :let and :const ~ 112 Variable declarations with :let and :const ~
86 113
87 Local variables need to be declared with `:let`. Local constants need to be 114 Local variables need to be declared with `:let`. Local constants need to be
466 let myvar = 'yes' 493 let myvar = 'yes'
467 Then "myvar" will only exist in this file. While without `vim9script` it would 494 Then "myvar" will only exist in this file. While without `vim9script` it would
468 be available as `g:myvar` from any other script and function. 495 be available as `g:myvar` from any other script and function.
469 496
470 The variables at the file level are very much like the script-local "s:" 497 The variables at the file level are very much like the script-local "s:"
471 variables in legacy Vim script, but the "s:" is omitted. 498 variables in legacy Vim script, but the "s:" is omitted. And they cannot be
472 499 deleted.
473 In Vim9 script the global "g:" namespace can still be used as before. 500
501 In Vim9 script the global "g:" namespace can still be used as before. And the
502 "w:", "b:" and "t:" namespaces. These have in common that variables are not
503 declared and they can be deleted.
474 504
475 A side effect of `:vim9script` is that the 'cpoptions' option is set to the 505 A side effect of `:vim9script` is that the 'cpoptions' option is set to the
476 Vim default value, like with: > 506 Vim default value, like with: >
477 :set cpo&vim 507 :set cpo&vim
478 One of the effects is that |line-continuation| is always enabled. 508 One of the effects is that |line-continuation| is always enabled.