Hi
Attached patch makes those changes to runtime/doc/vim9.txt:
- change " into # in vim9 script examples, since " is not
valid for comments in vim9
- fixes a typo: Of -> Or
- make spaces/tabs more consistent in vim9 code examples
Regards
Dominique
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/CAON-T_hAynKmCnK_Jnxz-qPfsK7o9CpymL8FpQP3%2BbsfVEY0PQ%40mail.gmail.com.
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt
index 8eb60be26..63404ceba 100644
--- a/runtime/doc/vim9.txt
+++ b/runtime/doc/vim9.txt
@@ -114,7 +114,7 @@ There is no "a:" dictionary or "a:000" list.
Variable arguments are defined as the last argument, with a name and have a
list type, similar to TypeScript. For example, a list of numbers: >
- def MyFunc(...itemlist: list<number>)
+ def MyFunc(...itemlist: list<number>)
for item in itemlist
...
@@ -128,8 +128,8 @@ function or variable the "g:" prefix should be used. For functions in an
autoload script the "name#" prefix is sufficient. >
def ThisFunction() # script-local
def s:ThisFunction() # script-local
- def g:ThatFunction() # global
- def ThatFunction() # global if no local ThatFunction()
+ def g:ThatFunction() # global
+ def ThatFunction() # global if no local ThatFunction()
def scriptname#function() # autoload
When using `:function` or `:def` to specify a new function inside a function,
@@ -173,7 +173,7 @@ blocks. Once the block ends the variable is no longer accessible: >
else
let inner = 0
endif
- echo inner " Error!
+ echo inner # Error!
The declaration must be done earlier: >
let inner: number
@@ -190,7 +190,7 @@ To intentionally avoid a variable being available later, a block can be used:
let temp = 'temp'
...
}
- echo temp " Error!
+ echo temp # Error!
An existing variable cannot be assigned to with `:let`, since that implies a
declaration. Global, window, tab, buffer and Vim variables can only be used
@@ -222,7 +222,7 @@ isn't that easy.
Omitting :call and :eval ~
Functions can be called without `:call`: >
- writefile(lines, 'file')
+ writefile(lines, 'file')
Using `:call` is still possible, but this is discouraged.
A method call without `eval` is possible, so long as the start is an
@@ -329,26 +329,26 @@ Notes:
current function.
- No line break is allowed in the LHS of an assignment. Specifically when
unpacking a list |:let-unpack|. This is OK: >
- [var1, var2] =
+ [var1, var2] =
Func()
< This does not work: >
- [var1,
+ [var1,
var2] =
Func()
- No line break is allowed in between arguments of an `:echo`, `:execute` and
similar commands. This is OK: >
- echo [1,
+ echo [1,
2] [3,
4]
< This does not work: >
- echo [1, 2]
+ echo [1, 2]
[3, 4]
- No line break is allowed in the arguments of a lambda, between the "{" and
"->". This is OK: >
- filter(list, {k, v ->
+ filter(list, {k, v ->
v > 0})
< This does not work: >
- filter(list, {k,
+ filter(list, {k,
v -> v > 0})
@@ -372,11 +372,11 @@ The 'ignorecase' option is not used for comparators that use strings.
White space ~
Vim9 script enforces proper use of white space. This is no longer allowed: >
- let var=234 " Error!
- let var= 234 " Error!
- let var =234 " Error!
+ let var=234 # Error!
+ let var= 234 # Error!
+ let var =234 # Error!
There must be white space before and after the "=": >
- let var = 234 " OK
+ let var = 234 # OK
White space must also be put before the # that starts a comment after a
command: >
let var = 234# Error!
@@ -386,14 +386,14 @@ White space is required around most operators.
White space is not allowed:
- Between a function name and the "(": >
- call Func (arg) " Error!
- call Func
- \ (arg) " Error!
- call Func(arg) " OK
- call Func(
- \ arg) " OK
- call Func(
- \ arg " OK
+ call Func (arg) # Error!
+ call Func
+ \ (arg) # Error!
+ call Func(arg) # OK
+ call Func(
+ \ arg) # OK
+ call Func(
+ \ arg # OK
\ )
@@ -455,16 +455,16 @@ same time tries to support the legacy Vim commands. Some compromises had to
be made. Here is a summary of what might be unexpected.
Ex command ranges need to be prefixed with a colon. >
- -> " legacy Vim: shifts the previous line to the right
- ->func() " Vim9: method call in continuation line
- :-> " Vim9: shifts the previous line to the right
+ -> # legacy Vim: shifts the previous line to the right
+ ->func() # Vim9: method call in continuation line
+ :-> # Vim9: shifts the previous line to the right
- %s/a/b " legacy Vim: substitute on all lines
+ %s/a/b # legacy Vim: substitute on all lines
x = alongname
- % another " Vim9: line continuation without a backslash
- :%s/a/b " Vim9: substitute on all lines
- 'text'->func() " Vim9: method call
- :'t " legacy Vim: jump to mark m
+ % another # Vim9: line continuation without a backslash
+ :%s/a/b # Vim9: substitute on all lines
+ 'text'->func() # Vim9: method call
+ :'t # legacy Vim: jump to mark m
Some Ex commands can be confused with assignments in Vim9 script: >
g:name = value # assignment
@@ -484,7 +484,7 @@ Vim9 functions are compiled as a whole: >
if !has('feature')
return
endif
- use-feature " May give compilation error
+ use-feature # May give compilation error
enddef
For a workaround, split it in two functions: >
func Maybe()
@@ -497,7 +497,7 @@ For a workaround, split it in two functions: >
use-feature
enddef
endif
-Of put the unsupported code inside an `if` with a constant expression that
+Or put the unsupported code inside an `if` with a constant expression that
evaluates to false: >
def Maybe()
if has('feature')
@@ -699,8 +699,8 @@ Type inference *type-inference*
In general: Whenever the type is clear it can be omitted. For example, when
declaring a variable and giving it a value: >
- let var = 0 " infers number type
- let var = 'hello' " infers string type
+ let var = 0 # infers number type
+ let var = 'hello' # infers string type
The type of a list and dictionary comes from the common type of the values.
If the values all have the same type, that type is used for the list or
@@ -846,7 +846,7 @@ actually needed. A recommended mechanism:
items and any private items. >
vim9script
let localVar = 'local'
- export def FilterFunc(arg: string): string
+ export def FilterFunc(arg: string): string
...
< This goes in .../import/someother.vim.
@@ -935,7 +935,7 @@ the well-known parts of legacy Vim script.
Since Vim already uses `:let` and `:const` and optional type checking is
desirable, the JavaScript/TypeScript syntax fits best for variable
declarations. >
- const greeting = 'hello' " string type is inferred
+ const greeting = 'hello' # string type is inferred
let name: string
...
name = 'John'
@@ -945,12 +945,12 @@ are doing. Some details are unexpected and can be fixed. For example how the
|| and && operators work. Legacy Vim script: >
let result = 44
...
- return result || 0 " returns 1
+ return result || 0 # returns 1
Vim9 script works like JavaScript/TypeScript, keep the value: >
let result = 44
...
- return result || 0 " returns 44
+ return result || 0 # returns 44
On the other hand, overloading "+" to use both for addition and string
concatenation goes against legacy Vim script and often leads to mistakes.