Skip to content

Commit 6f93106

Browse files
committed
usr_{41,51,52}.txt: Update Vim 8.2.5048
1 parent a9fb7c9 commit 6f93106

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

en/usr_41.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*usr_41.txt* For Vim version 8.2. Last change: 2022 May 13
1+
*usr_41.txt* For Vim version 8.2. Last change: 2022 May 21
22

33
VIM USER MANUAL - by Bram Moolenaar
44

@@ -835,6 +835,7 @@ Cursor and mark position: *cursor-functions* *mark-functions*
835835
screencol() get screen column of the cursor
836836
screenrow() get screen row of the cursor
837837
screenpos() screen row and col of a text character
838+
virtcol2col() byte index of a text character on screen
838839
getcurpos() get position of the cursor
839840
getpos() get position of cursor, mark, etc.
840841
setpos() set position of cursor, mark, etc.
@@ -925,6 +926,11 @@ Date and Time: *date-functions* *time-functions*
925926
reltimestr() convert reltime() result to a string
926927
reltimefloat() convert reltime() result to a Float
927928

929+
Autocmds: *autocmd-functions*
930+
autocmd_add() add a list of autocmds and groups
931+
autocmd_delete() delete a list of autocmds and groups
932+
autocmd_get() return a list of autocmds
933+
928934
*buffer-functions* *window-functions* *arg-functions*
929935
Buffers, windows and the argument list:
930936
argc() number of entries in the argument list
@@ -1918,6 +1924,8 @@ are script-local.
19181924
If you split your plugin into parts, you can use `import` and `export` to
19191925
share items between those parts. See `:export` for the details.
19201926

1927+
More information about writing plugins is in |usr_51.txt|.
1928+
19211929
==============================================================================
19221930

19231931
Next chapter: |usr_42.txt| Add new menus

en/usr_51.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*usr_51.txt* For Vim version 8.2. Last change: 2022 May 13
1+
*usr_51.txt* For Vim version 8.2. Last change: 2022 May 14
22

33
VIM USER MANUAL - by Bram Moolenaar
44

@@ -197,8 +197,8 @@ would need to prefix the name with "s:".
197197
We will define a function that adds a new typing correction: >
198198
199199
30 def Add(from: string, correct: bool)
200-
31 var to = input("type the correction for " .. from .. ": ")
201-
32 exe ":iabbrev " .. from .. " " .. to
200+
31 var to = input($"type the correction for {from}: ")
201+
32 exe $":iabbrev {from} {to}"
202202
..
203203
36 enddef
204204

en/usr_52.txt

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*usr_52.txt* For Vim version 8.2. Last change: 2022 May 13
1+
*usr_52.txt* For Vim version 8.2. Last change: 2022 May 21
22

33
VIM USER MANUAL - by Bram Moolenaar
44

@@ -110,35 +110,36 @@ Although it's shorter to do: >
110110
==============================================================================
111111
*52.3* Functions and types
112112

113-
Legacy Vim script does have type checking, but this happens at runtime, when
114-
the code is executed. And it's permissive, often a computation gives an
115-
unexpected value instead of reporting an error. Thus you can define a
116-
function and think it's fine, but see a problem only later when it is called: >
117-
let s:collected = ''
118-
func ExtendAndReturn(add)
119-
let s:collected += a:add
120-
return s:collected
113+
Legacy Vim script only checks types at runtime, when the code is executed.
114+
And it's permissive, often a computation gives an unexpected value instead of
115+
reporting an error. Thus you can define a function and think it's fine, but
116+
notice a problem only later when the function is called: >
117+
func Concatenate(base, add)
118+
return a:base + a:add
121119
endfunc
122120
123121
Can you spot the error? Try this: >
124-
echo ExtendAndReturn('text')
125-
And you'll see zero. Why? Because in legacy Vim script "+=" will convert the
126-
arguments to numbers, and any string without a number results in zero!
127-
128-
With `:def` the type checking happens when compiling the function. For that
129-
you need to specify the argument types and the return type. Also notice that
130-
the argument is used without the "a:" prefix: >
131-
let s:collected = ''
132-
def ExtendAndReturn(add: string): string
133-
s:collected += add
134-
return s:collected
122+
echo Concatenate('base', 'text')
123+
And you'll see zero. Why? Because in legacy Vim script "+" will convert the
124+
arguments to numbers, and any string without a number results in zero! That's
125+
not what you expected.
126+
127+
With `:def` the type checking happens when compiling the function. You need
128+
to specify the argument types and the return type to make that possible. Also
129+
notice that the argument names are used without the "a:" prefix: >
130+
def Concatenate(base: string, add: string): string
131+
return base + add
135132
enddef
136-
defcompile
133+
defcompile Concatenate
137134
138135
Here we use `:defcompile` to do the compilation right away, without it the
139-
compilation would happen when the function is called. Vim will tell you what
140-
you did wrong: >
141-
E1013: type mismatch, expected number but got string
136+
compilation would happen when the function is first called. Vim will tell you
137+
what you did wrong: >
138+
E1051: Wrong argument type for +
139+
140+
Side note: here the context is legacy script. When using Vim9 script you
141+
would put `:defcompile` at the end of the script to check for errors in all
142+
the functions defined in it.
142143

143144
Vim9 script is strict, it uses the "+" operator only for numbers and floats.
144145
For string concatenation ".." must be used. This avoids mistakes and avoids

0 commit comments

Comments
 (0)