Skip to content

Commit 650e63a

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 0aa5bef + 08e51f4 commit 650e63a

79 files changed

Lines changed: 2799 additions & 1239 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

runtime/doc/eval.txt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,6 +2653,7 @@ matcharg({nr}) List arguments of |:match|
26532653
matchdelete({id} [, {win}]) Number delete match identified by {id}
26542654
matchend({expr}, {pat} [, {start} [, {count}]])
26552655
Number position where {pat} ends in {expr}
2656+
matchfuzzy({list}, {str}) List fuzzy match {str} in {list}
26562657
matchlist({expr}, {pat} [, {start} [, {count}]])
26572658
List match and submatches of {pat} in {expr}
26582659
matchstr({expr}, {pat} [, {start} [, {count}]])
@@ -7319,6 +7320,29 @@ matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
73197320
Can also be used as a |method|: >
73207321
GetText()->matchend('word')
73217322

7323+
7324+
matchfuzzy({list}, {str}) *matchfuzzy()*
7325+
Returns a list with all the strings in {list} that fuzzy
7326+
match {str}. The strings in the returned list are sorted
7327+
based on the matching score. {str} is treated as a literal
7328+
string and regular expression matching is NOT supported.
7329+
The maximum supported {str} length is 256.
7330+
7331+
If there are no matching strings or there is an error, then an
7332+
empty list is returned. If length of {str} is greater than
7333+
256, then returns an empty list.
7334+
7335+
Example: >
7336+
:echo matchfuzzy(["clay", "crow"], "cay")
7337+
< results in ["clay"]. >
7338+
:echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7339+
< results in a list of buffer names fuzzy matching "ndl". >
7340+
:echo v:oldfiles->matchfuzzy("test")
7341+
< results in a list of file names fuzzy matching "test". >
7342+
:let l = readfile("buffer.c")->matchfuzzy("str")
7343+
< results in a list of lines in "buffer.c" fuzzy matching "str".
7344+
7345+
73227346
matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
73237347
Same as |match()|, but return a |List|. The first item in the
73247348
list is the matched string, same as what matchstr() would
@@ -12357,7 +12381,9 @@ text...
1235712381
< is equivalent to: >
1235812382
:let x = 1
1235912383
:lockvar! x
12360-
< This is useful if you want to make sure the variable
12384+
< NOTE: in Vim9 script `:const` works differently, see
12385+
|vim9-const|
12386+
This is useful if you want to make sure the variable
1236112387
is not modified. If the value is a List or Dictionary
1236212388
literal then the items also cannot be changed: >
1236312389
const ll = [1, 2, 3]
@@ -12397,6 +12423,8 @@ text...
1239712423

1239812424
[depth] is relevant when locking a |List| or
1239912425
|Dictionary|. It specifies how deep the locking goes:
12426+
0 Lock the variable {name} but not its
12427+
value.
1240012428
1 Lock the |List| or |Dictionary| itself,
1240112429
cannot add or remove items, but can
1240212430
still change their values.
@@ -12410,7 +12438,14 @@ text...
1241012438
|Dictionary|, one level deeper.
1241112439
The default [depth] is 2, thus when {name} is a |List|
1241212440
or |Dictionary| the values cannot be changed.
12413-
*E743*
12441+
12442+
Example with [depth] 0: >
12443+
let mylist = [1, 2, 3]
12444+
lockvar 0 mylist
12445+
let mylist[0] = 77 " OK
12446+
call add(mylist, 4] " OK
12447+
let mylist = [7, 8, 9] " Error!
12448+
< *E743*
1241412449
For unlimited depth use [!] and omit [depth].
1241512450
However, there is a maximum depth of 100 to catch
1241612451
loops.

runtime/doc/usr_41.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ String manipulation: *string-functions*
603603
charclass() class of a character
604604
match() position where a pattern matches in a string
605605
matchend() position where a pattern match ends in a string
606+
matchfuzzy() fuzzy matches a string in a list of strings
606607
matchstr() match of a pattern in a string
607608
matchstrpos() match and positions of a pattern in a string
608609
matchlist() like matchstr() and also return submatches

runtime/doc/vim9.txt

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9.txt* For Vim version 8.2. Last change: 2020 Sep 07
1+
*vim9.txt* For Vim version 8.2. Last change: 2020 Sep 13
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -192,6 +192,9 @@ To intentionally avoid a variable being available later, a block can be used:
192192
}
193193
echo temp # Error!
194194
195+
Declaring a variable with a type but without an initializer will initialize to
196+
zero, false or empty.
197+
195198
An existing variable cannot be assigned to with `:let`, since that implies a
196199
declaration. Global, window, tab, buffer and Vim variables can only be used
197200
without `:let`, because they are not really declared, they can also be deleted
@@ -210,6 +213,40 @@ at the script level. >
210213
211214
Since "&opt = value" is now assigning a value to option "opt", ":&" cannot be
212215
used to repeat a `:substitute` command.
216+
*vim9-const*
217+
In legacy Vim script "const list = []" would make the variable "list"
218+
immutable and also the value. Thus you cannot add items to the list. This
219+
differs from what many languages do. Vim9 script does it like TypeScript: only
220+
"list" is immutable, the value can be changed.
221+
222+
One can use `:const!` to make both the variable and the value immutable. Use
223+
this for composite structures that you want to make sure will not be modified.
224+
225+
How this works: >
226+
vim9script
227+
const list = [1, 2]
228+
list = [3, 4] # Error!
229+
list[0] = 2 # OK
230+
231+
const! LIST = [1, 2]
232+
LIST = [3, 4] # Error!
233+
LIST[0] = 2 # Error!
234+
It is common to write constants as ALL_CAPS, but you don't have to.
235+
236+
The constant only applies to the value itself, not what it refers to. >
237+
cont females = ["Mary"]
238+
const! NAMES = [["John", "Peter"], females]
239+
NAMES[0] = ["Jack"] # Error!
240+
NAMES[0][0] = ["Jack"] # Error!
241+
NAMES[1] = ["Emma"] # Error!
242+
Names[1][0] = "Emma" # OK, now females[0] == "Emma"
243+
244+
Rationale: TypeScript has no way to make the value immutable. One can use
245+
immutable types, but that quickly gets complicated for nested values. And
246+
with a type cast the value can be made mutable again, which means there is no
247+
guarantee the value won't change. Vim supports immutable values, in legacy
248+
script this was done with `:lockvar`. But that is an extra statement and also
249+
applies to nested values. Therefore the solution to use `:const!`.
213250

214251
*E1092*
215252
Declaring more than one variable at a time, using the unpack notation, is
@@ -408,7 +445,7 @@ for using a list or job. This is very much like JavaScript, but there are a
408445
few exceptions.
409446

410447
type TRUE when ~
411-
bool v:true
448+
bool v:true or 1
412449
number non-zero
413450
float non-zero
414451
string non-empty
@@ -946,26 +983,41 @@ declarations: >
946983
Expression evaluation was already close to what JavaScript and other languages
947984
are doing. Some details are unexpected and can be fixed. For example how the
948985
|| and && operators work. Legacy Vim script: >
949-
let result = 44
986+
let value = 44
950987
...
951-
return result || 0 # returns 1
988+
let result = value || 0 # result == 1
952989
953990
Vim9 script works like JavaScript/TypeScript, keep the value: >
954-
let result = 44
991+
let value = 44
955992
...
956-
return result || 0 # returns 44
957-
958-
On the other hand, overloading "+" to use both for addition and string
959-
concatenation goes against legacy Vim script and often leads to mistakes.
960-
For that reason we will keep using ".." for string concatenation. Lua also
961-
uses ".." this way.
993+
let result = value || 0 # result == 44
962994
963995
There is no intention to completely match TypeScript syntax and semantics. We
964996
just want to take those parts that we can use for Vim and we expect Vim users
965-
are happy with. TypeScript is a complex language with its own advantages and
966-
disadvantages. People used to other languages (Java, Python, etc.) will also
967-
find things in TypeScript that they do not like or do not understand. We'll
968-
try to avoid those things.
997+
will be happy with. TypeScript is a complex language with its own advantages
998+
and disadvantages. To get an idea of the disadvantages read the book:
999+
"JavaScript: The Good Parts". Or find the article "TypeScript: the good
1000+
parts" and read the "Things to avoid" section.
1001+
1002+
People used to other languages (Java, Python, etc.) will also find things in
1003+
TypeScript that they do not like or do not understand. We'll try to avoid
1004+
those things.
1005+
1006+
Specific items from TypeScript we avoid:
1007+
- Overloading "+", using it both for addition and string concatenation. This
1008+
goes against legacy Vim script and often leads to mistakes. For that reason
1009+
we will keep using ".." for string concatenation. Lua also uses ".." this
1010+
way. And it allows for conversion to string for more values.
1011+
- TypeScript can use an expression like "99 || 'yes'" in a condition, but
1012+
cannot assign the value to a boolean. That is inconsistent and can be
1013+
annoying. Vim recognizes an expression with && or || and allows using the
1014+
result as a bool.
1015+
- TypeScript considers an empty string as Falsy, but an empty list or dict as
1016+
Truthy. That is inconsistent. In Vim an empty list and dict are also
1017+
Falsy.
1018+
- TypeScript has various "Readonly" types, which have limited usefulness,
1019+
since a type cast can remove the immutable nature. Vim locks the value,
1020+
which is more flexible, but is only checked at runtime.
9691021

9701022

9711023
Import and Export ~

0 commit comments

Comments
 (0)