Mercurial > vim
annotate runtime/doc/usr_41.txt @ 27229:6837d2c14dee v8.2.4143
patch 8.2.4143: MS-Windows: IME support for Win9x is obsolete
Commit: https://github.com/vim/vim/commit/b0b2b73dca40c26ff1f4befe5c3aad3fd4bccfad
Author: K.Takata <kentkt@csc.jp>
Date: Wed Jan 19 12:59:21 2022 +0000
patch 8.2.4143: MS-Windows: IME support for Win9x is obsolete
Problem: MS-Windows: IME support for Win9x is obsolete.
Solution: Remove the Win9x code. (Ken Takata, closes https://github.com/vim/vim/issues/9559)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 19 Jan 2022 14:00:04 +0100 |
parents | b94cdb5ef20e |
children | 722db0819111 |
rev | line source |
---|---|
27036 | 1 *usr_41.txt* For Vim version 8.2. Last change: 2022 Jan 01 |
7 | 2 |
3 VIM USER MANUAL - by Bram Moolenaar | |
4 | |
5 Write a Vim script | |
6 | |
7 | |
8 The Vim script language is used for the startup vimrc file, syntax files, and | |
9 many other things. This chapter explains the items that can be used in a Vim | |
10 script. There are a lot of them, thus this is a long chapter. | |
11 | |
12 |41.1| Introduction | |
13 |41.2| Variables | |
14 |41.3| Expressions | |
15 |41.4| Conditionals | |
16 |41.5| Executing an expression | |
17 |41.6| Using functions | |
18 |41.7| Defining a function | |
161 | 19 |41.8| Lists and Dictionaries |
20 |41.9| Exceptions | |
21 |41.10| Various remarks | |
22 |41.11| Writing a plugin | |
23 |41.12| Writing a filetype plugin | |
24 |41.13| Writing a compiler plugin | |
170 | 25 |41.14| Writing a plugin that loads quickly |
26 |41.15| Writing library scripts | |
793 | 27 |41.16| Distributing Vim scripts |
7 | 28 |
29 Next chapter: |usr_42.txt| Add new menus | |
30 Previous chapter: |usr_40.txt| Make new commands | |
31 Table of contents: |usr_toc.txt| | |
32 | |
33 ============================================================================== | |
129 | 34 *41.1* Introduction *vim-script-intro* *script* |
7 | 35 |
36 Your first experience with Vim scripts is the vimrc file. Vim reads it when | |
37 it starts up and executes the commands. You can set options to values you | |
38 prefer. And you can use any colon command in it (commands that start with a | |
39 ":"; these are sometimes referred to as Ex commands or command-line commands). | |
26847 | 40 |
41 Syntax files are also Vim scripts. As are files that set options for a | |
7 | 42 specific file type. A complicated macro can be defined by a separate Vim |
43 script file. You can think of other uses yourself. | |
44 | |
20856 | 45 If you are familiar with Python, you can find a comparison between |
46 Python and Vim script here, with pointers to other documents: | |
47 https://gist.github.com/yegappan/16d964a37ead0979b05e655aa036cad0 | |
21676 | 48 And if you are familiar with JavaScript: |
20856 | 49 https://w0rp.com/blog/post/vim-script-for-the-javascripter/ |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
50 |
26847 | 51 Vim script comes in two flavors: legacy and |Vim9|. Since this help file is |
52 for new users, we'll teach you the newer and more convenient |Vim9| syntax. | |
53 | |
54 To try out Vim script the best way is to edit a script file and source it. | |
55 Basically: > | |
56 :edit test.vim | |
57 [insert the script lines you want] | |
58 :w | |
59 :source % | |
60 | |
7 | 61 Let's start with a simple example: > |
62 | |
26847 | 63 vim9script |
64 var i = 1 | |
65 while i < 5 | |
66 echo "count is" i | |
67 i += 1 | |
68 endwhile | |
7 | 69 < |
161 | 70 The output of the example code is: |
71 | |
72 count is 1 ~ | |
73 count is 2 ~ | |
74 count is 3 ~ | |
75 count is 4 ~ | |
76 | |
26847 | 77 In the first line the `vim9script` command makes clear this is a new, |Vim9| |
78 script file. That matters for how the rest of the file is used. | |
79 | |
80 The `var i = 1` command declares the "i" variable and initializes it. The | |
161 | 81 generic form is: > |
7 | 82 |
26847 | 83 var {name} = {expression} |
7 | 84 |
85 In this case the variable name is "i" and the expression is a simple value, | |
86 the number one. | |
26847 | 87 |
88 The `while` command starts a loop. The generic form is: > | |
89 | |
90 while {condition} | |
91 {statements} | |
92 endwhile | |
93 | |
94 The statements until the matching `endwhile` are executed for as long as the | |
7 | 95 condition is true. The condition used here is the expression "i < 5". This |
96 is true when the variable i is smaller than five. | |
97 Note: | |
98 If you happen to write a while loop that keeps on running, you can | |
99 interrupt it by pressing CTRL-C (CTRL-Break on MS-Windows). | |
161 | 100 |
26847 | 101 The `echo` command prints its arguments. In this case the string "count is" |
161 | 102 and the value of the variable i. Since i is one, this will print: |
103 | |
104 count is 1 ~ | |
105 | |
26847 | 106 Then there is the `i += 1` command. This does the same thing as "i = i + 1", |
107 it adds one to the variable i and assigns the new value to the same variable. | |
161 | 108 |
109 The example was given to explain the commands, but would you really want to | |
11062 | 110 make such a loop, it can be written much more compact: > |
112 | 111 |
26847 | 112 for i in range(1, 4) |
113 echo "count is" i | |
114 endfor | |
115 | |
116 We won't explain how `for` and `range()` work until later. Follow the links | |
161 | 117 if you are impatient. |
112 | 118 |
7 | 119 |
16871 | 120 FOUR KINDS OF NUMBERS |
121 | |
24520 | 122 Numbers can be decimal, hexadecimal, octal or binary. |
123 | |
124 A hexadecimal number starts with "0x" or "0X". For example "0x1f" is decimal | |
125 31. | |
126 | |
26847 | 127 An octal number starts with "0o", "0O". "0o17" is decimal 15. |
24520 | 128 |
129 A binary number starts with "0b" or "0B". For example "0b101" is decimal 5. | |
130 | |
26847 | 131 A decimal number is just digits. Careful: In legacy script don't put a zero |
132 before a decimal number, it will be interpreted as an octal number! | |
133 | |
134 The `echo` command evaluates its argument and always prints decimal numbers. | |
135 Example: > | |
136 | |
137 echo 0x7f 0o36 | |
7 | 138 < 127 30 ~ |
139 | |
16871 | 140 A number is made negative with a minus sign. This also works for hexadecimal, |
26847 | 141 octal and binary numbers: > |
142 | |
143 echo -0x7f | |
144 < -127 ~ | |
145 | |
146 A minus sign is also used for subtraction. This can sometimes lead to | |
147 confusion. If we put a minus sign before both numbers we get an error: > | |
148 | |
149 echo -0x7f -0o36 | |
150 < E1004: White space required before and after '-' at "-0o36" ~ | |
151 | |
152 Note: if you are not using a |Vim9| script to try out these commands but type | |
153 them directly, they will be executed as legacy script. Then the echo command | |
154 sees the second minus sign as subtraction. To get the error, prefix the | |
155 command with `vim9cmd`: > | |
156 | |
157 vim9cmd echo -0x7f -0o36 | |
158 < E1004: White space required before and after '-' at "-0o36" ~ | |
159 | |
160 White space in an expression is often required to make sure it is easy to read | |
161 and avoid errors. Such as thinking that the "-0o36" above makes the number | |
162 negative, while it is actually seen as a subtraction. | |
163 | |
164 To actually have the minus sign be used for negation, you can put the second | |
165 expression in parenthesis: > | |
166 | |
167 echo -0x7f (-0o36) | |
7 | 168 |
169 ============================================================================== | |
170 *41.2* Variables | |
171 | |
172 A variable name consists of ASCII letters, digits and the underscore. It | |
173 cannot start with a digit. Valid variable names are: | |
174 | |
175 counter | |
176 _aap3 | |
177 very_long_variable_name_with_underscores | |
178 FuncLength | |
179 LENGTH | |
180 | |
181 Invalid names are "foo+bar" and "6var". | |
26847 | 182 |
183 Some variables are global. To see a list of currently defined global | |
184 variables type this command: > | |
7 | 185 |
186 :let | |
187 | |
26847 | 188 You can use global variables everywhere. However, it is easy to use the same |
189 name in two unrelated scripts. Therefore variables declared in a script are | |
190 local to that script. For example, if you have this in "script1.vim": > | |
191 | |
192 vim9script | |
193 var counter = 5 | |
194 echo counter | |
195 < 5 ~ | |
196 | |
197 And you try to use the variable in "script2.vim": > | |
198 | |
199 vim9script | |
200 echo counter | |
201 < E121: Undefined variable: counter ~ | |
202 | |
203 Using a script-local variable means you can be sure that it is only changed in | |
204 that script and not elsewhere. | |
205 | |
206 If you do want to share variables between scripts, use the "g:" prefix and | |
207 assign the value directly, do not use `var`. Thus in "script1.vim": > | |
208 | |
209 vim9script | |
210 g:counter = 5 | |
211 echo g:counter | |
212 < 5 ~ | |
213 | |
214 And then in "script2.vim": > | |
215 | |
216 vim9script | |
217 echo g:counter | |
218 < 5 ~ | |
219 | |
220 More about script-local variables here: |script-variable|. | |
7 | 221 |
222 There are more kinds of variables, see |internal-variables|. The most often | |
223 used ones are: | |
224 | |
225 b:name variable local to a buffer | |
226 w:name variable local to a window | |
227 g:name global variable (also in a function) | |
228 v:name variable predefined by Vim | |
229 | |
230 | |
231 DELETING VARIABLES | |
232 | |
26847 | 233 Variables take up memory and show up in the output of the `let` command. To |
234 delete a global variable use the `unlet` command. Example: > | |
235 | |
236 unlet g:counter | |
237 | |
238 This deletes the global variable "g:counter" to free up the memory it uses. | |
239 If you are not sure if the variable exists, and don't want an error message | |
240 when it doesn't, append !: > | |
241 | |
242 unlet! g:counter | |
243 | |
244 You cannot `unlet` script-local variables in |Vim9| script. You can in legacy | |
245 script. | |
246 | |
247 When a script finishes, the local variables declared there will not be | |
248 deleted. Functions defined in the script can use them. Example: | |
249 > | |
250 vim9script | |
251 var counter = 0 | |
252 def g:GetCount(): number | |
253 s:counter += 1 | |
254 return s:counter | |
255 enddef | |
256 | |
257 Every time you call the function it will return the next count: > | |
258 :echo g:GetCount() | |
259 < 1 ~ | |
260 > | |
261 :echo g:GetCount() | |
262 < 2 ~ | |
263 | |
264 If you are worried a script-local variable is consuming too much | |
265 memory, set it to an empty value after you no longer need it. | |
266 | |
267 Note: below we'll leave out the `vim9script` line, so we can concentrate on | |
268 the relevant commands, but you'll still need to put it at the top of your | |
269 script file. | |
7 | 270 |
271 | |
272 STRING VARIABLES AND CONSTANTS | |
273 | |
274 So far only numbers were used for the variable value. Strings can be used as | |
161 | 275 well. Numbers and strings are the basic types of variables that Vim supports. |
26847 | 276 Example: > |
277 | |
278 var name = "Peter" | |
279 echo name | |
27036 | 280 < Peter ~ |
7 | 281 |
26847 | 282 Every variable has a type. Very often, as in this example, the type is |
283 defined by assigning a value. This is called type inference. If you do not | |
284 want to give the variable a value yet, you need to specify the type: > | |
285 | |
286 var name: string | |
287 var age: number | |
288 ... | |
289 name = "Peter" | |
290 age = 42 | |
291 | |
292 If you make a mistake and try to assign the wrong type of value you'll get an | |
293 error: > | |
294 | |
295 age = "Peter" | |
296 < E1012: Type mismatch; expected number but got string ~ | |
297 | |
298 More about types in |41.8|. | |
299 | |
300 To assign a string value to a variable, you need to use a string constant. | |
301 There are two types of these. First the string in double quotes, as we used | |
302 already. If you want to include a double quote inside the string, put a | |
303 backslash in front of it: > | |
304 | |
305 var name = "he is \"Peter\"" | |
306 echo name | |
307 < he is "Peter" ~ | |
7 | 308 |
309 To avoid the need for a backslash, you can use a string in single quotes: > | |
310 | |
26847 | 311 var name = 'he is "Peter"' |
312 echo name | |
313 < he is "Peter" ~ | |
7 | 314 |
161 | 315 Inside a single-quote string all the characters are as they are. Only the |
316 single quote itself is special: you need to use two to get one. A backslash | |
317 is taken literally, thus you can't use it to change the meaning of the | |
26847 | 318 character after it: > |
319 | |
320 var name = 'P\e''ter''' | |
321 echo name | |
322 < P\e'ter' ~ | |
323 | |
324 In double-quote strings it is possible to use special characters. Here are a | |
325 few useful ones: | |
7 | 326 |
327 \t <Tab> | |
328 \n <NL>, line break | |
329 \r <CR>, <Enter> | |
330 \e <Esc> | |
331 \b <BS>, backspace | |
332 \" " | |
333 \\ \, backslash | |
334 \<Esc> <Esc> | |
335 \<C-W> CTRL-W | |
336 | |
337 The last two are just examples. The "\<name>" form can be used to include | |
338 the special key "name". | |
26847 | 339 |
340 See |expr-quote| for the full list of special items in a string. | |
7 | 341 |
342 ============================================================================== | |
343 *41.3* Expressions | |
344 | |
26847 | 345 Vim has a fairly standard way to handle expressions. You can read the |
7 | 346 definition here: |expression-syntax|. Here we will show the most common |
347 items. | |
26847 | 348 |
349 The numbers, strings and variables mentioned above are expressions by | |
7 | 350 themselves. Thus everywhere an expression is expected, you can use a number, |
351 string or variable. Other basic items in an expression are: | |
352 | |
353 $NAME environment variable | |
354 &name option | |
355 @r register | |
356 | |
357 Examples: > | |
358 | |
26847 | 359 echo "The value of 'tabstop' is" &ts |
360 echo "Your home directory is" $HOME | |
361 if @a == 'text' | |
362 | |
363 The &name form can also be used to set an option value, do something and | |
364 restore the old value. Example: > | |
365 | |
366 var save_ic = &ic | |
367 set noic | |
368 s/The Start/The Beginning/ | |
369 &ic = save_ic | |
7 | 370 |
371 This makes sure the "The Start" pattern is used with the 'ignorecase' option | |
161 | 372 off. Still, it keeps the value that the user had set. (Another way to do |
373 this would be to add "\C" to the pattern, see |/\C|.) | |
7 | 374 |
375 | |
376 MATHEMATICS | |
377 | |
378 It becomes more interesting if we combine these basic items. Let's start with | |
379 mathematics on numbers: | |
380 | |
381 a + b add | |
382 a - b subtract | |
383 a * b multiply | |
384 a / b divide | |
385 a % b modulo | |
386 | |
387 The usual precedence is used. Example: > | |
388 | |
26847 | 389 echo 10 + 5 * 2 |
7 | 390 < 20 ~ |
391 | |
2709 | 392 Grouping is done with parentheses. No surprises here. Example: > |
7 | 393 |
26847 | 394 echo (10 + 5) * 2 |
7 | 395 < 30 ~ |
396 | |
22171 | 397 Strings can be concatenated with ".." (see |expr6|). Example: > |
398 | |
26847 | 399 echo "foo" .. "bar" |
7 | 400 < foobar ~ |
401 | |
26847 | 402 When the "echo" command gets multiple arguments, it separates them with a |
7 | 403 space. In the example the argument is a single expression, thus no space is |
404 inserted. | |
405 | |
26847 | 406 Borrowed from the C language is the conditional expression: > |
7 | 407 |
408 a ? b : c | |
409 | |
410 If "a" evaluates to true "b" is used, otherwise "c" is used. Example: > | |
411 | |
26847 | 412 var nr = 4 |
413 echo nr > 5 ? "nr is big" : "nr is small" | |
414 < nr is small ~ | |
7 | 415 |
416 The three parts of the constructs are always evaluated first, thus you could | |
26847 | 417 see it works as: > |
7 | 418 |
419 (a) ? (b) : (c) | |
420 | |
421 ============================================================================== | |
422 *41.4* Conditionals | |
423 | |
26847 | 424 The `if` commands executes the following statements, until the matching |
425 `endif`, only when a condition is met. The generic form is: | |
426 | |
427 if {condition} | |
7 | 428 {statements} |
26847 | 429 endif |
430 | |
431 Only when the expression {condition} evaluates to true or one will the | |
432 {statements} be executed. If they are not executed they must still be valid | |
433 commands. If they contain garbage, Vim won't be able to find the matching | |
434 `endif`. | |
435 | |
436 You can also use `else`. The generic form for this is: | |
437 | |
438 if {condition} | |
7 | 439 {statements} |
26847 | 440 else |
7 | 441 {statements} |
26847 | 442 endif |
443 | |
444 The second {statements} block is only executed if the first one isn't. | |
445 | |
446 Finally, there is `elseif` | |
447 | |
448 if {condition} | |
7 | 449 {statements} |
26847 | 450 elseif {condition} |
7 | 451 {statements} |
26847 | 452 endif |
453 | |
454 This works just like using `else` and then `if`, but without the need for an | |
455 extra `endif`. | |
456 | |
457 A useful example for your vimrc file is checking the 'term' option and doing | |
458 something depending upon its value: > | |
459 | |
460 if &term == "xterm" | |
461 # Do stuff for xterm | |
462 elseif &term == "vt100" | |
463 # Do stuff for a vt100 terminal | |
464 else | |
465 # Do something for other terminals | |
466 endif | |
467 | |
468 This uses "#" to start a comment, more about that later. | |
7 | 469 |
470 | |
471 LOGIC OPERATIONS | |
472 | |
473 We already used some of them in the examples. These are the most often used | |
474 ones: | |
475 | |
476 a == b equal to | |
477 a != b not equal to | |
478 a > b greater than | |
479 a >= b greater than or equal to | |
480 a < b less than | |
481 a <= b less than or equal to | |
482 | |
26847 | 483 The result is true if the condition is met and false otherwise. An example: > |
484 | |
485 if v:version >= 700 | |
486 echo "congratulations" | |
487 else | |
488 echo "you are using an old version, upgrade!" | |
489 endif | |
7 | 490 |
491 Here "v:version" is a variable defined by Vim, which has the value of the Vim | |
26847 | 492 version. 600 is for version 6.0, version 6.1 has the value 601. This is |
7 | 493 very useful to write a script that works with multiple versions of Vim. |
494 |v:version| | |
495 | |
496 The logic operators work both for numbers and strings. When comparing two | |
497 strings, the mathematical difference is used. This compares byte values, | |
498 which may not be right for some languages. | |
26847 | 499 |
500 If you try to compare a string with a number you will get an error. | |
501 | |
502 For strings there are two more useful items: | |
503 | |
504 str =~ pat matches with | |
505 str !~ pat does not match with | |
506 | |
507 The left item "str" is used as a string. The right item "pat" is used as a | |
7 | 508 pattern, like what's used for searching. Example: > |
509 | |
26847 | 510 if str =~ " " |
511 echo "str contains a space" | |
512 endif | |
513 if str !~ '\.$' | |
514 echo "str does not end in a full stop" | |
515 endif | |
7 | 516 |
517 Notice the use of a single-quote string for the pattern. This is useful, | |
161 | 518 because backslashes would need to be doubled in a double-quote string and |
519 patterns tend to contain many backslashes. | |
7 | 520 |
26847 | 521 The match is not anchored, if you want to match the whole string start with |
522 "^" and end with "$". | |
523 | |
524 The 'ignorecase' option is not used when comparing strings. When you do want | |
525 to ignore case append "?". Thus "==?" compares two strings to be equal while | |
526 ignoring case. For the full table see |expr-==|. | |
7 | 527 |
528 | |
529 MORE LOOPING | |
530 | |
26847 | 531 The `while` command was already mentioned. Two more statements can be used in |
532 between the `while` and the `endwhile`: | |
533 | |
534 continue Jump back to the start of the while loop; the | |
7 | 535 loop continues. |
26847 | 536 break Jump forward to the `endwhile`; the loop is |
7 | 537 discontinued. |
538 | |
539 Example: > | |
540 | |
27036 | 541 var counter = 1 |
26847 | 542 while counter < 40 |
27036 | 543 if skip_number(counter) |
26847 | 544 continue |
545 endif | |
27036 | 546 if last_number(counter) |
26847 | 547 break |
548 endif | |
549 sleep 50m | |
27036 | 550 ++counter |
26847 | 551 endwhile |
552 | |
553 The `sleep` command makes Vim take a nap. The "50m" specifies fifty | |
554 milliseconds. Another example is `sleep 4`, which sleeps for four seconds. | |
555 | |
556 Even more looping can be done with the `for` command, see below in |41.8|. | |
161 | 557 |
7 | 558 ============================================================================== |
559 *41.5* Executing an expression | |
560 | |
561 So far the commands in the script were executed by Vim directly. The | |
26847 | 562 `execute` command allows executing the result of an expression. This is a |
7 | 563 very powerful way to build commands and execute them. |
26847 | 564 |
565 An example is to jump to a tag, which is contained in a variable: > | |
566 | |
567 execute "tag " .. tag_name | |
22171 | 568 |
569 The ".." is used to concatenate the string "tag " with the value of variable | |
7 | 570 "tag_name". Suppose "tag_name" has the value "get_cmd", then the command that |
571 will be executed is: > | |
572 | |
26847 | 573 tag get_cmd |
574 | |
575 The `execute` command can only execute Ex commands. The `normal` command | |
7 | 576 executes Normal mode commands. However, its argument is not an expression but |
577 the literal command characters. Example: > | |
578 | |
26847 | 579 normal gg=G |
580 | |
581 This jumps to the first line with "gg" and formats all lines with the "=" | |
582 operator and the "G" movement. | |
583 | |
584 To make `normal` work with an expression, combine `execute` with it. | |
7 | 585 Example: > |
586 | |
26847 | 587 execute "normal " .. count .. "j" |
588 | |
589 This will move the cursor "count" lines down. | |
590 | |
591 Make sure that the argument for `normal` is a complete command. Otherwise | |
7 | 592 Vim will run into the end of the argument and abort the command. For example, |
26847 | 593 if you start the delete operator, you must give the movement command also. |
594 This works: > | |
595 | |
596 normal d$ | |
597 | |
598 This does nothing: > | |
599 | |
600 normal d | |
601 | |
602 If you start Insert mode and do not end it with Esc, it will end anyway. This | |
603 works to insert "new text": > | |
604 | |
605 execute "normal inew text" | |
606 | |
607 If you want to do something after inserting text you do need to end Insert | |
608 mode: > | |
609 | |
610 execute "normal inew text\<Esc>b" | |
611 | |
612 This inserts "new text" and puts the cursor on the first letter of "text". | |
613 Notice the use of the special key "\<Esc>". This avoids having to enter a | |
614 real <Esc> character in your script. That is where `execute` with a | |
615 double-quote string comes in handy. | |
7 | 616 |
161 | 617 If you don't want to execute a string but evaluate it to get its expression |
618 value, you can use the eval() function: > | |
619 | |
26847 | 620 var optname = "path" |
621 var optvalue = eval('&' .. optname) | |
161 | 622 |
623 A "&" character is prepended to "path", thus the argument to eval() is | |
624 "&path". The result will then be the value of the 'path' option. | |
625 | |
7 | 626 ============================================================================== |
627 *41.6* Using functions | |
628 | |
629 Vim defines many functions and provides a large amount of functionality that | |
630 way. A few examples will be given in this section. You can find the whole | |
26847 | 631 list below: |function-list|. |
632 | |
633 A function is called with the `call` command. The parameters are passed in | |
2709 | 634 between parentheses separated by commas. Example: > |
7 | 635 |
26847 | 636 call search("Date: ", "W") |
7 | 637 |
638 This calls the search() function, with arguments "Date: " and "W". The | |
639 search() function uses its first argument as a search pattern and the second | |
640 one as flags. The "W" flag means the search doesn't wrap around the end of | |
641 the file. | |
642 | |
26847 | 643 Using `call` is optional in |Vim9| script, this works the same way: > |
644 | |
645 search("Date: ", "W") | |
646 | |
7 | 647 A function can be called in an expression. Example: > |
648 | |
26847 | 649 var line = getline(".") |
650 var repl = substitute(line, '\a', "*", "g") | |
651 setline(".", repl) | |
7 | 652 |
161 | 653 The getline() function obtains a line from the current buffer. Its argument |
654 is a specification of the line number. In this case "." is used, which means | |
655 the line where the cursor is. | |
26847 | 656 |
657 The substitute() function does something similar to the `substitute` command. | |
658 The first argument is the string on which to perform the substitution. The | |
659 second argument is the pattern, the third the replacement string. Finally, | |
660 the last arguments are the flags. | |
661 | |
662 The setline() function sets the line, specified by the first argument, to a | |
7 | 663 new string, the second argument. In this example the line under the cursor is |
664 replaced with the result of the substitute(). Thus the effect of the three | |
665 statements is equal to: > | |
666 | |
667 :substitute/\a/*/g | |
668 | |
669 Using the functions becomes more interesting when you do more work before and | |
670 after the substitute() call. | |
671 | |
672 | |
673 FUNCTIONS *function-list* | |
674 | |
675 There are many functions. We will mention them here, grouped by what they are | |
26847 | 676 used for. You can find an alphabetical list here: |builtin-function-list|. |
677 Use CTRL-] on the function name to jump to detailed help on it. | |
7 | 678 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
679 String manipulation: *string-functions* |
16235
219c58b3879c
patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents:
16208
diff
changeset
|
680 nr2char() get a character by its number value |
219c58b3879c
patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents:
16208
diff
changeset
|
681 list2str() get a character string from a list of numbers |
219c58b3879c
patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents:
16208
diff
changeset
|
682 char2nr() get number value of a character |
219c58b3879c
patch 8.1.1122: char2nr() does not handle composing characters
Bram Moolenaar <Bram@vim.org>
parents:
16208
diff
changeset
|
683 str2list() get list of numbers from a string |
1620 | 684 str2nr() convert a string to a Number |
685 str2float() convert a string to a Float | |
824 | 686 printf() format a string according to % items |
7 | 687 escape() escape characters in a string with a '\' |
1620 | 688 shellescape() escape a string for use with a shell command |
689 fnameescape() escape a file name for use with a Vim command | |
824 | 690 tr() translate characters from one set to another |
7 | 691 strtrans() translate a string to make it printable |
692 tolower() turn a string to lowercase | |
693 toupper() turn a string to uppercase | |
21973
85add08e6a2d
patch 8.2.1536: cannot get the class of a character; emoji widths are wrong
Bram Moolenaar <Bram@vim.org>
parents:
21971
diff
changeset
|
694 charclass() class of a character |
7 | 695 match() position where a pattern matches in a string |
696 matchend() position where a pattern match ends in a string | |
22232
f22acf6472da
patch 8.2.1665: cannot do fuzzy string matching
Bram Moolenaar <Bram@vim.org>
parents:
22171
diff
changeset
|
697 matchfuzzy() fuzzy matches a string in a list of strings |
22355
0491b9cafd44
patch 8.2.1726: fuzzy matching only works on strings
Bram Moolenaar <Bram@vim.org>
parents:
22232
diff
changeset
|
698 matchfuzzypos() fuzzy matches a string in a list of strings |
7 | 699 matchstr() match of a pattern in a string |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
9464
diff
changeset
|
700 matchstrpos() match and positions of a pattern in a string |
824 | 701 matchlist() like matchstr() and also return submatches |
7 | 702 stridx() first index of a short string in a long string |
703 strridx() last index of a short string in a long string | |
5618 | 704 strlen() length of a string in bytes |
24130
c3d1f65365c4
patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents:
23931
diff
changeset
|
705 strcharlen() length of a string in characters |
c3d1f65365c4
patch 8.2.2606: strchars() defaults to counting composing characters
Bram Moolenaar <Bram@vim.org>
parents:
23931
diff
changeset
|
706 strchars() number of characters in a string |
5618 | 707 strwidth() size of string when displayed |
708 strdisplaywidth() size of string when displayed, deals with tabs | |
21971
0bc43a704f56
patch 8.2.1535: it is not possible to specify cell widths of characters
Bram Moolenaar <Bram@vim.org>
parents:
21825
diff
changeset
|
709 setcellwidths() set character cell width overrides |
7 | 710 substitute() substitute a pattern match with a string |
2908 | 711 submatch() get a specific match in ":s" and substitute() |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
712 strpart() get part of a string using byte index |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
713 strcharpart() get part of a string using char index |
23604
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
714 slice() take a slice of a string, using char index in |
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
715 Vim9 script |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
716 strgetchar() get character from a string using char index |
7 | 717 expand() expand special keywords |
17020
1841c03a9b5e
patch 8.1.1510: a plugin cannot easily expand a command like done internally
Bram Moolenaar <Bram@vim.org>
parents:
16871
diff
changeset
|
718 expandcmd() expand a command like done for `:edit` |
7 | 719 iconv() convert text from one encoding to another |
824 | 720 byteidx() byte index of a character in a string |
5618 | 721 byteidxcomp() like byteidx() but count composing characters |
23380
2351b40af967
patch 8.2.2233: cannot convert a byte index into a character index
Bram Moolenaar <Bram@vim.org>
parents:
23305
diff
changeset
|
722 charidx() character index of a byte in a string |
824 | 723 repeat() repeat a string multiple times |
724 eval() evaluate a string expression | |
9464
be72f4201a1d
commit https://github.com/vim/vim/commit/063b9d15abea041a5bfff3ffc4e219e26fd1d4fa
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
725 execute() execute an Ex command and get the output |
16871 | 726 win_execute() like execute() but in a specified window |
15068 | 727 trim() trim characters from a string |
21989
52e970719f4b
patch 8.2.1544: cannot translate messages in a Vim script
Bram Moolenaar <Bram@vim.org>
parents:
21973
diff
changeset
|
728 gettext() lookup message translation |
7 | 729 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
730 List manipulation: *list-functions* |
112 | 731 get() get an item without error for wrong index |
732 len() number of items in a List | |
733 empty() check if List is empty | |
734 insert() insert an item somewhere in a List | |
735 add() append an item to a List | |
736 extend() append a List to a List | |
23588
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23573
diff
changeset
|
737 extendnew() make a new List and append items |
112 | 738 remove() remove one or more items from a List |
739 copy() make a shallow copy of a List | |
740 deepcopy() make a full copy of a List | |
741 filter() remove selected items from a List | |
742 map() change each List item | |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
743 mapnew() make a new List with changed items |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
744 reduce() reduce a List to a value |
23604
1816ea68c022
patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
745 slice() take a slice of a List |
112 | 746 sort() sort a List |
747 reverse() reverse the order of a List | |
5763 | 748 uniq() remove copies of repeated adjacent items |
112 | 749 split() split a String into a List |
750 join() join List items into a String | |
824 | 751 range() return a List with a sequence of numbers |
112 | 752 string() String representation of a List |
753 call() call a function with List as arguments | |
323 | 754 index() index of a value in a List |
112 | 755 max() maximum value in a List |
756 min() minimum value in a List | |
757 count() count number of times a value appears in a List | |
824 | 758 repeat() repeat a List multiple times |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
20743
diff
changeset
|
759 flatten() flatten a List |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
23666
diff
changeset
|
760 flattennew() flatten a copy of a List |
112 | 761 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
762 Dictionary manipulation: *dict-functions* |
323 | 763 get() get an entry without an error for a wrong key |
112 | 764 len() number of entries in a Dictionary |
765 has_key() check whether a key appears in a Dictionary | |
766 empty() check if Dictionary is empty | |
767 remove() remove an entry from a Dictionary | |
768 extend() add entries from one Dictionary to another | |
23588
510088f8c66f
patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents:
23573
diff
changeset
|
769 extendnew() make a new Dictionary and append items |
112 | 770 filter() remove selected entries from a Dictionary |
771 map() change each Dictionary entry | |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22355
diff
changeset
|
772 mapnew() make a new Dictionary with changed items |
112 | 773 keys() get List of Dictionary keys |
774 values() get List of Dictionary values | |
775 items() get List of Dictionary key-value pairs | |
776 copy() make a shallow copy of a Dictionary | |
777 deepcopy() make a full copy of a Dictionary | |
778 string() String representation of a Dictionary | |
779 max() maximum value in a Dictionary | |
780 min() minimum value in a Dictionary | |
781 count() count number of times a value appears | |
782 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
783 Floating point computation: *float-functions* |
1620 | 784 float2nr() convert Float to Number |
785 abs() absolute value (also works for Number) | |
786 round() round off | |
787 ceil() round up | |
788 floor() round down | |
789 trunc() remove value after decimal point | |
5618 | 790 fmod() remainder of division |
791 exp() exponential | |
792 log() natural logarithm (logarithm to base e) | |
1620 | 793 log10() logarithm to base 10 |
794 pow() value of x to the exponent y | |
795 sqrt() square root | |
796 sin() sine | |
797 cos() cosine | |
2725 | 798 tan() tangent |
799 asin() arc sine | |
800 acos() arc cosine | |
1620 | 801 atan() arc tangent |
2725 | 802 atan2() arc tangent |
803 sinh() hyperbolic sine | |
804 cosh() hyperbolic cosine | |
805 tanh() hyperbolic tangent | |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
806 isinf() check for infinity |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
807 isnan() check for not a number |
1620 | 808 |
25806
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
809 Blob manipulation: *blob-functions* |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
810 blob2list() get a list of numbers from a blob |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
811 list2blob() get a blob from a list of numbers |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
812 |
3237 | 813 Other computation: *bitwise-function* |
814 and() bitwise AND | |
815 invert() bitwise invert | |
816 or() bitwise OR | |
817 xor() bitwise XOR | |
5618 | 818 sha256() SHA-256 hash |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
819 rand() get a pseudo-random number |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
820 srand() initialize seed used by rand() |
3237 | 821 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
822 Variables: *var-functions* |
23594
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
823 type() type of a variable as a number |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23588
diff
changeset
|
824 typename() type of a variable as text |
824 | 825 islocked() check if a variable is locked |
11062 | 826 funcref() get a Funcref for a function reference |
824 | 827 function() get a Funcref for a function name |
828 getbufvar() get a variable value from a specific buffer | |
829 setbufvar() set a variable in a specific buffer | |
831 | 830 getwinvar() get a variable from specific window |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
831 gettabvar() get a variable from specific tab page |
831 | 832 gettabwinvar() get a variable from specific window & tab page |
824 | 833 setwinvar() set a variable in a specific window |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
834 settabvar() set a variable in a specific tab page |
831 | 835 settabwinvar() set a variable in a specific window & tab page |
824 | 836 garbagecollect() possibly free memory |
837 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
838 Cursor and mark position: *cursor-functions* *mark-functions* |
7 | 839 col() column number of the cursor or a mark |
840 virtcol() screen column of the cursor or a mark | |
841 line() line number of the cursor or mark | |
842 wincol() window column number of the cursor | |
843 winline() window line number of the cursor | |
844 cursor() position the cursor at a line/column | |
5618 | 845 screencol() get screen column of the cursor |
846 screenrow() get screen row of the cursor | |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17257
diff
changeset
|
847 screenpos() screen row and col of a text character |
5968 | 848 getcurpos() get position of the cursor |
824 | 849 getpos() get position of cursor, mark, etc. |
850 setpos() set position of cursor, mark, etc. | |
20615
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
19721
diff
changeset
|
851 getmarklist() list of global/local marks |
824 | 852 byte2line() get line number at a specific byte count |
853 line2byte() byte count at a specific line | |
854 diff_filler() get the number of filler lines above a line | |
5618 | 855 screenattr() get attribute at a screen line/row |
856 screenchar() get character code at a screen line/row | |
16133
eb087f8a26a8
patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
857 screenchars() get character codes at a screen line/row |
eb087f8a26a8
patch 8.1.1071: cannot get composing characters from the screen
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
858 screenstring() get string of characters at a screen line/row |
23563
87671ccc6c6b
patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents:
23380
diff
changeset
|
859 charcol() character number of the cursor or a mark |
87671ccc6c6b
patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents:
23380
diff
changeset
|
860 getcharpos() get character position of cursor, mark, etc. |
87671ccc6c6b
patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents:
23380
diff
changeset
|
861 setcharpos() set character position of cursor, mark, etc. |
87671ccc6c6b
patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents:
23380
diff
changeset
|
862 getcursorcharpos() get character position of the cursor |
87671ccc6c6b
patch 8.2.2324: not easy to get mark en cursor posotion by character count
Bram Moolenaar <Bram@vim.org>
parents:
23380
diff
changeset
|
863 setcursorcharpos() set character position of the cursor |
824 | 864 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
865 Working with text in the current buffer: *text-functions* |
161 | 866 getline() get a line or list of lines from the buffer |
7 | 867 setline() replace a line in the buffer |
161 | 868 append() append line or list of lines in the buffer |
7 | 869 indent() indent of a specific line |
870 cindent() indent according to C indenting | |
871 lispindent() indent according to Lisp indenting | |
872 nextnonblank() find next non-blank line | |
873 prevnonblank() find previous non-blank line | |
874 search() find a match for a pattern | |
667 | 875 searchpos() find a match for a pattern |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
876 searchcount() get number of matches before/after the cursor |
7 | 877 searchpair() find the other end of a start/skip/end |
667 | 878 searchpairpos() find the other end of a start/skip/end |
824 | 879 searchdecl() search for the declaration of a name |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
880 getcharsearch() return character search information |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
881 setcharsearch() set character search information |
7 | 882 |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
883 Working with text in another buffer: |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
884 getbufline() get a list of lines from the specified buffer |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
885 setbufline() replace a line in the specified buffer |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
886 appendbufline() append a list of lines in the specified buffer |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
887 deletebufline() delete lines from a specified buffer |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
888 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
889 *system-functions* *file-functions* |
7 | 890 System functions and manipulation of files: |
891 glob() expand wildcards | |
892 globpath() expand wildcards in a number of directories | |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
893 glob2regpat() convert a glob pattern into a search pattern |
824 | 894 findfile() find a file in a list of directories |
895 finddir() find a directory in a list of directories | |
7 | 896 resolve() find out where a shortcut points to |
897 fnamemodify() modify a file name | |
824 | 898 pathshorten() shorten directory names in a path |
899 simplify() simplify a path without changing its meaning | |
7 | 900 executable() check if an executable program exists |
5814 | 901 exepath() full path of an executable program |
7 | 902 filereadable() check if a file can be read |
903 filewritable() check if a file can be written to | |
824 | 904 getfperm() get the permissions of a file |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
905 setfperm() set the permissions of a file |
824 | 906 getftype() get the kind of a file |
7 | 907 isdirectory() check if a directory exists |
908 getfsize() get the size of a file | |
824 | 909 getcwd() get the current working directory |
16427
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
16267
diff
changeset
|
910 haslocaldir() check if current window used |:lcd| or |:tcd| |
7 | 911 tempname() get the name of a temporary file |
824 | 912 mkdir() create a new directory |
16576
bcc343175103
patch 8.1.1291: not easy to change directory and restore
Bram Moolenaar <Bram@vim.org>
parents:
16517
diff
changeset
|
913 chdir() change current working directory |
7 | 914 delete() delete a file |
915 rename() rename a file | |
5814 | 916 system() get the result of a shell command as a string |
917 systemlist() get the result of a shell command as a list | |
16604
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
16576
diff
changeset
|
918 environ() get all environment variables |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
16576
diff
changeset
|
919 getenv() get one environment variable |
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
16576
diff
changeset
|
920 setenv() set an environment variable |
7 | 921 hostname() name of the system |
158 | 922 readfile() read a file into a List of lines |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23594
diff
changeset
|
923 readblob() read a file into a Blob |
16267 | 924 readdir() get a List of file names in a directory |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20615
diff
changeset
|
925 readdirex() get a List of file information in a directory |
15729 | 926 writefile() write a List of lines or Blob into a file |
7 | 927 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
928 Date and Time: *date-functions* *time-functions* |
824 | 929 getftime() get last modification time of a file |
930 localtime() get current time in seconds | |
931 strftime() convert time to a string | |
18669
9007e9896303
patch 8.1.2326: cannot parse a date/time string
Bram Moolenaar <Bram@vim.org>
parents:
18639
diff
changeset
|
932 strptime() convert a date/time string to time |
824 | 933 reltime() get the current or elapsed time accurately |
934 reltimestr() convert reltime() result to a string | |
8876
47f17f66da3d
commit https://github.com/vim/vim/commit/03413f44167c4b5cd0012def9bb331e2518c83cf
Christian Brabandt <cb@256bit.org>
parents:
8795
diff
changeset
|
935 reltimefloat() convert reltime() result to a Float |
824 | 936 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
937 *buffer-functions* *window-functions* *arg-functions* |
7 | 938 Buffers, windows and the argument list: |
939 argc() number of entries in the argument list | |
940 argidx() current position in the argument list | |
5942 | 941 arglistid() get id of the argument list |
7 | 942 argv() get one entry from the argument list |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
943 bufadd() add a file to the list of buffers |
7 | 944 bufexists() check if a buffer exists |
945 buflisted() check if a buffer exists and is listed | |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
946 bufload() ensure a buffer is loaded |
7 | 947 bufloaded() check if a buffer exists and is loaded |
948 bufname() get the name of a specific buffer | |
949 bufnr() get the buffer number of a specific buffer | |
824 | 950 tabpagebuflist() return List of buffers in a tab page |
951 tabpagenr() get the number of a tab page | |
952 tabpagewinnr() like winnr() for a specified tab page | |
7 | 953 winnr() get the window number for the current window |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
8876
diff
changeset
|
954 bufwinid() get the window ID of a specific buffer |
7 | 955 bufwinnr() get the window number of a specific buffer |
956 winbufnr() get the buffer number of a specific window | |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16610
diff
changeset
|
957 listener_add() add a callback to listen to changes |
16808 | 958 listener_flush() invoke listener callbacks |
16638
4790302965fc
patch 8.1.1321: no docs or tests for listener functions
Bram Moolenaar <Bram@vim.org>
parents:
16610
diff
changeset
|
959 listener_remove() remove a listener callback |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
960 win_findbuf() find windows containing a buffer |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
961 win_getid() get window ID of a window |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
962 win_gettype() get type of window |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
963 win_gotoid() go to window with ID |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
964 win_id2tabwin() get tab and window nr from window ID |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
965 win_id2win() get window nr from window ID |
27047
b94cdb5ef20e
patch 8.2.4052: not easy to resize a window from a plugin
Bram Moolenaar <Bram@vim.org>
parents:
27036
diff
changeset
|
966 win_move_separator() move window vertical separator |
b94cdb5ef20e
patch 8.2.4052: not easy to resize a window from a plugin
Bram Moolenaar <Bram@vim.org>
parents:
27036
diff
changeset
|
967 win_move_statusline() move window status line |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
968 win_splitmove() move window to a split of another window |
9858
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9644
diff
changeset
|
969 getbufinfo() get a list with buffer information |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9644
diff
changeset
|
970 gettabinfo() get a list with tab page information |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9644
diff
changeset
|
971 getwininfo() get a list with window information |
13280
fbda23eb0996
patch 8.0.1514: getting the list of changes is not easy
Christian Brabandt <cb@256bit.org>
parents:
13246
diff
changeset
|
972 getchangelist() get a list of change list entries |
13246
dd3b2ecf91f6
patch 8.0.1497: getting the jump list requires parsing the output of :jumps
Christian Brabandt <cb@256bit.org>
parents:
13051
diff
changeset
|
973 getjumplist() get a list of jump list entries |
14637 | 974 swapinfo() information about a swap file |
15068 | 975 swapname() get the swap file path of a buffer |
824 | 976 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
977 Command line: *command-line-functions* |
824 | 978 getcmdline() get the current command line |
979 getcmdpos() get position of the cursor in the command line | |
980 setcmdpos() set position of the cursor in the command line | |
981 getcmdtype() return the current command-line type | |
6153 | 982 getcmdwintype() return the current command-line window type |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
9464
diff
changeset
|
983 getcompletion() list of command-line completion matches |
23853
a9ed31ab85c3
patch 8.2.2468: not easy to get the full command name from a shortened one
Bram Moolenaar <Bram@vim.org>
parents:
23816
diff
changeset
|
984 fullcommand() get full command name |
824 | 985 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
986 Quickfix and location lists: *quickfix-functions* |
824 | 987 getqflist() list of quickfix errors |
988 setqflist() modify a quickfix list | |
989 getloclist() list of location list items | |
990 setloclist() modify a location list | |
991 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
992 Insert mode completion: *completion-functions* |
824 | 993 complete() set found matches |
994 complete_add() add to found matches | |
995 complete_check() check if completion should be aborted | |
16127
0375e54f0adc
patch 8.1.1068: cannot get all the information about current completion
Bram Moolenaar <Bram@vim.org>
parents:
15729
diff
changeset
|
996 complete_info() get current completion information |
824 | 997 pumvisible() check if the popup menu is displayed |
18186 | 998 pum_getpos() position and size of popup menu if visible |
7 | 999 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1000 Folding: *folding-functions* |
7 | 1001 foldclosed() check for a closed fold at a specific line |
1002 foldclosedend() like foldclosed() but return the last line | |
1003 foldlevel() check for the fold level at a specific line | |
1004 foldtext() generate the line displayed for a closed fold | |
824 | 1005 foldtextresult() get the text displayed for a closed fold |
1006 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1007 Syntax and highlighting: *syntax-functions* *highlighting-functions* |
1326 | 1008 clearmatches() clear all matches defined by |matchadd()| and |
1009 the |:match| commands | |
1010 getmatches() get all matches defined by |matchadd()| and | |
1011 the |:match| commands | |
7 | 1012 hlexists() check if a highlight group exists |
26089
c544eacaf066
patch 8.2.3578: manipulating highlighting is complicated
Bram Moolenaar <Bram@vim.org>
parents:
25836
diff
changeset
|
1013 hlget() get highlight group attributes |
c544eacaf066
patch 8.2.3578: manipulating highlighting is complicated
Bram Moolenaar <Bram@vim.org>
parents:
25836
diff
changeset
|
1014 hlset() set highlight group attributes |
7 | 1015 hlID() get ID of a highlight group |
1016 synID() get syntax ID at a specific position | |
1017 synIDattr() get a specific attribute of a syntax ID | |
1018 synIDtrans() get translated syntax ID | |
2642 | 1019 synstack() get list of syntax IDs at a specific position |
2662 | 1020 synconcealed() get info about concealing |
824 | 1021 diff_hlID() get highlight ID for diff mode at a position |
1326 | 1022 matchadd() define a pattern to highlight (a "match") |
5979 | 1023 matchaddpos() define a list of positions to highlight |
824 | 1024 matcharg() get info about |:match| arguments |
1326 | 1025 matchdelete() delete a match defined by |matchadd()| or a |
1026 |:match| command | |
1027 setmatches() restore a list of matches saved by | |
1028 |getmatches()| | |
824 | 1029 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1030 Spelling: *spell-functions* |
824 | 1031 spellbadword() locate badly spelled word at or after cursor |
1032 spellsuggest() return suggested spelling corrections | |
1033 soundfold() return the sound-a-like equivalent of a word | |
7 | 1034 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1035 History: *history-functions* |
7 | 1036 histadd() add an item to a history |
1037 histdel() delete an item from a history | |
1038 histget() get an item from a history | |
1039 histnr() get highest index of a history list | |
1040 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1041 Interactive: *interactive-functions* |
824 | 1042 browse() put up a file requester |
1043 browsedir() put up a directory requester | |
7 | 1044 confirm() let the user make a choice |
1045 getchar() get a character from the user | |
24840
c7aa7acb23bb
patch 8.2.2958: function list test fails
Bram Moolenaar <Bram@vim.org>
parents:
24520
diff
changeset
|
1046 getcharstr() get a character from the user as a string |
7 | 1047 getcharmod() get modifiers for the last typed character |
18639 | 1048 getmousepos() get last known mouse position |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1049 echoraw() output characters as-is |
1620 | 1050 feedkeys() put characters in the typeahead queue |
7 | 1051 input() get a line from the user |
824 | 1052 inputlist() let the user pick an entry from a list |
7 | 1053 inputsecret() get a line from the user without showing it |
1054 inputdialog() get a line from the user in a dialog | |
230 | 1055 inputsave() save and clear typeahead |
7 | 1056 inputrestore() restore typeahead |
1057 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1058 GUI: *gui-functions* |
824 | 1059 getfontname() get name of current font being used |
13437 | 1060 getwinpos() position of the Vim window |
1061 getwinposx() X position of the Vim window | |
1062 getwinposy() Y position of the Vim window | |
11062 | 1063 balloon_show() set the balloon content |
12909 | 1064 balloon_split() split a message for a balloon |
16604
1e0a5f09fdf1
patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
16576
diff
changeset
|
1065 balloon_gettext() get the text in the balloon |
824 | 1066 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1067 Vim server: *server-functions* |
7 | 1068 serverlist() return the list of server names |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
12254
diff
changeset
|
1069 remote_startserver() run a server |
7 | 1070 remote_send() send command characters to a Vim server |
1071 remote_expr() evaluate an expression in a Vim server | |
1072 server2client() send a reply to a client of a Vim server | |
1073 remote_peek() check if there is a reply from a Vim server | |
1074 remote_read() read a reply from a Vim server | |
1075 foreground() move the Vim window to the foreground | |
1076 remote_foreground() move the Vim server window to the foreground | |
1077 | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1078 Window size and position: *window-size-functions* |
824 | 1079 winheight() get height of a specific window |
1080 winwidth() get width of a specific window | |
13051 | 1081 win_screenpos() get screen position of a window |
15068 | 1082 winlayout() get layout of windows in a tab page |
824 | 1083 winrestcmd() return command to restore window sizes |
1084 winsaveview() get view of current window | |
1085 winrestview() restore saved view of current window | |
1086 | |
19657
da791e5c0139
patch 8.2.0385: menu functionality insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
1087 Mappings and Menus: *mapping-functions* |
25378
890fd8211202
patch 8.2.3226: new digraph functions use old naming scheme
Bram Moolenaar <Bram@vim.org>
parents:
25294
diff
changeset
|
1088 digraph_get() get |digraph| |
890fd8211202
patch 8.2.3226: new digraph functions use old naming scheme
Bram Moolenaar <Bram@vim.org>
parents:
25294
diff
changeset
|
1089 digraph_getlist() get all |digraph|s |
890fd8211202
patch 8.2.3226: new digraph functions use old naming scheme
Bram Moolenaar <Bram@vim.org>
parents:
25294
diff
changeset
|
1090 digraph_set() register |digraph| |
890fd8211202
patch 8.2.3226: new digraph functions use old naming scheme
Bram Moolenaar <Bram@vim.org>
parents:
25294
diff
changeset
|
1091 digraph_setlist() register multiple |digraph|s |
4159 | 1092 hasmapto() check if a mapping exists |
1093 mapcheck() check if a matching mapping exists | |
1094 maparg() get rhs of a mapping | |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1095 mapset() restore a mapping |
19657
da791e5c0139
patch 8.2.0385: menu functionality insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
1096 menu_info() get information about a menu item |
4159 | 1097 wildmenumode() check if the wildmode is active |
1098 | |
7279
b5e9810b389d
commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents:
6153
diff
changeset
|
1099 Testing: *test-functions* |
8673
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
1100 assert_equal() assert that two expressions values are equal |
15068 | 1101 assert_equalfile() assert that two file contents are equal |
8876
47f17f66da3d
commit https://github.com/vim/vim/commit/03413f44167c4b5cd0012def9bb331e2518c83cf
Christian Brabandt <cb@256bit.org>
parents:
8795
diff
changeset
|
1102 assert_notequal() assert that two expressions values are not equal |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
9464
diff
changeset
|
1103 assert_inrange() assert that an expression is inside a range |
8795
aba2d0a01290
commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents:
8793
diff
changeset
|
1104 assert_match() assert that a pattern matches the value |
8876
47f17f66da3d
commit https://github.com/vim/vim/commit/03413f44167c4b5cd0012def9bb331e2518c83cf
Christian Brabandt <cb@256bit.org>
parents:
8795
diff
changeset
|
1105 assert_notmatch() assert that a pattern does not match the value |
7279
b5e9810b389d
commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents:
6153
diff
changeset
|
1106 assert_false() assert that an expression is false |
b5e9810b389d
commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents:
6153
diff
changeset
|
1107 assert_true() assert that an expression is true |
8673
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
1108 assert_exception() assert that a command throws an exception |
13341
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
13280
diff
changeset
|
1109 assert_beeps() assert that a command beeps |
24313
10c39822f496
patch 8.2.2697: function list test fails
Bram Moolenaar <Bram@vim.org>
parents:
24278
diff
changeset
|
1110 assert_nobeep() assert that a command does not cause a beep |
13341
acd7eaa13d2b
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
13280
diff
changeset
|
1111 assert_fails() assert that a command fails |
11229
146a1e213b60
Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
11160
diff
changeset
|
1112 assert_report() report a test failure |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1113 test_alloc_fail() make memory allocation fail |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
9464
diff
changeset
|
1114 test_autochdir() enable 'autochdir' during startup |
11160 | 1115 test_override() test with Vim internal overrides |
1116 test_garbagecollect_now() free memory right now | |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1117 test_garbagecollect_soon() set a flag to free memory soon |
16808 | 1118 test_getvalue() get value of an internal variable |
25006
496221916885
patch 8.2.3040: GUI: dropping files not tested
Bram Moolenaar <Bram@vim.org>
parents:
24982
diff
changeset
|
1119 test_gui_drop_files() drop file(s) in a window |
24982
4cb423b9250d
patch 8.2.3028: GUI mouse events not tested
Bram Moolenaar <Bram@vim.org>
parents:
24911
diff
changeset
|
1120 test_gui_mouse_event() add a GUI mouse event to the input buffer |
11062 | 1121 test_ignore_error() ignore a specific error message |
15729 | 1122 test_null_blob() return a null Blob |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1123 test_null_channel() return a null Channel |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1124 test_null_dict() return a null Dict |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1125 test_null_function() return a null Funcref |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1126 test_null_job() return a null Job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1127 test_null_list() return a null List |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1128 test_null_partial() return a null Partial function |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1129 test_null_string() return a null String |
11062 | 1130 test_settime() set the time Vim uses internally |
16517
9484fc00ac6b
patch 8.1.1262: cannot simulate a mouse click in a test
Bram Moolenaar <Bram@vim.org>
parents:
16427
diff
changeset
|
1131 test_setmouse() set the mouse position |
15068 | 1132 test_feedinput() add key sequence to input buffer |
1133 test_option_not_set() reset flag indicating option was set | |
1134 test_scrollbar() simulate scrollbar movement in the GUI | |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1135 test_refcount() return an expression's reference count |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1136 test_srand_seed() set the seed value for srand() |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1137 test_unknown() return a value with unknown type |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1138 test_void() return a value with void type |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1139 |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1140 Inter-process communication: *channel-functions* |
10449
222b1432814e
commit https://github.com/vim/vim/commit/5162822914372fc916a93f85848c0c82209e7cec
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
1141 ch_canread() check if there is something to read |
7924
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7790
diff
changeset
|
1142 ch_open() open a channel |
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7790
diff
changeset
|
1143 ch_close() close a channel |
10140
b11ceef7116e
commit https://github.com/vim/vim/commit/64d8e25bf6efe5f18b032563521c3ce278c316ab
Christian Brabandt <cb@256bit.org>
parents:
9858
diff
changeset
|
1144 ch_close_in() close the in part of a channel |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1145 ch_read() read a message from a channel |
15512 | 1146 ch_readblob() read a Blob from a channel |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1147 ch_readraw() read a raw message from a channel |
7924
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7790
diff
changeset
|
1148 ch_sendexpr() send a JSON message over a channel |
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7790
diff
changeset
|
1149 ch_sendraw() send a raw message over a channel |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1150 ch_evalexpr() evaluate an expression over channel |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1151 ch_evalraw() evaluate a raw string over channel |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1152 ch_status() get status of a channel |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1153 ch_getbufnr() get the buffer number of a channel |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1154 ch_getjob() get the job associated with a channel |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1155 ch_info() get channel information |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1156 ch_log() write a message in the channel log file |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1157 ch_logfile() set the channel log file |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1158 ch_setoptions() set the options for a channel |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
1159 json_encode() encode an expression to a JSON string |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
1160 json_decode() decode a JSON string to Vim types |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1161 js_encode() encode an expression to a JSON string |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1162 js_decode() decode a JSON string to Vim types |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1163 |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1164 Jobs: *job-functions* |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1165 job_start() start a job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1166 job_stop() stop a job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1167 job_status() get the status of a job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1168 job_getchannel() get the channel used by a job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1169 job_info() get information about a job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1170 job_setoptions() set options for a job |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1171 |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1172 Signs: *sign-functions* |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1173 sign_define() define or update a sign |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1174 sign_getdefined() get a list of defined signs |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1175 sign_getplaced() get a list of placed signs |
15418
51b3c36b0523
patch 8.1.0717: there is no function for the ":sign jump" command
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
1176 sign_jump() jump to a sign |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1177 sign_place() place a sign |
17366
9843fbfa0ee5
patch 8.1.1682: placing a larger number of signs is slow
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1178 sign_placelist() place a list of signs |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1179 sign_undefine() undefine a sign |
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1180 sign_unplace() unplace a sign |
17366
9843fbfa0ee5
patch 8.1.1682: placing a larger number of signs is slow
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1181 sign_unplacelist() unplace a list of signs |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
15194
diff
changeset
|
1182 |
12254 | 1183 Terminal window: *terminal-functions* |
1184 term_start() open a terminal window and run a job | |
1185 term_list() get the list of terminal buffers | |
1186 term_sendkeys() send keystrokes to a terminal | |
1187 term_wait() wait for screen to be updated | |
1188 term_getjob() get the job associated with a terminal | |
1189 term_scrape() get row of a terminal screen | |
1190 term_getline() get a line of text from a terminal | |
1191 term_getattr() get the value of attribute {what} | |
1192 term_getcursor() get the cursor position of a terminal | |
1193 term_getscrolled() get the scroll count of a terminal | |
1194 term_getaltscreen() get the alternate screen flag | |
1195 term_getsize() get the size of a terminal | |
1196 term_getstatus() get the status of a terminal | |
1197 term_gettitle() get the title of a terminal | |
1198 term_gettty() get the tty name of a terminal | |
13735 | 1199 term_setansicolors() set 16 ANSI colors, used for GUI |
1200 term_getansicolors() get 16 ANSI colors, used for GUI | |
15068 | 1201 term_dumpdiff() display difference between two screen dumps |
1202 term_dumpload() load a terminal screen dump in a window | |
1203 term_dumpwrite() dump contents of a terminal screen to a file | |
1204 term_setkill() set signal to stop job in a terminal | |
1205 term_setrestore() set command to restore a terminal | |
1206 term_setsize() set the size of a terminal | |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1207 term_setapi() set terminal JSON API function name prefix |
12254 | 1208 |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1209 Popup window: *popup-window-functions* |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1210 popup_create() create popup centered in the screen |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1211 popup_atcursor() create popup just above the cursor position, |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1212 closes when the cursor moves away |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17257
diff
changeset
|
1213 popup_beval() at the position indicated by v:beval_ |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17257
diff
changeset
|
1214 variables, closes when the mouse moves away |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1215 popup_notification() show a notification for three seconds |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1216 popup_dialog() create popup centered with padding and border |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1217 popup_menu() prompt for selecting an item from a list |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1218 popup_hide() hide a popup temporarily |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1219 popup_show() show a previously hidden popup |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1220 popup_move() change the position and size of a popup |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1221 popup_setoptions() override options of a popup |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1222 popup_settext() replace the popup buffer contents |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1223 popup_close() close one popup |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1224 popup_clear() close all popups |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1225 popup_filter_menu() select from a list of items |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1226 popup_filter_yesno() block until 'y' or 'n' is pressed |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1227 popup_getoptions() get current options for a popup |
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1228 popup_getpos() get actual position and size of a popup |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1229 popup_findinfo() get window ID for popup info window |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1230 popup_findpreview() get window ID for popup preview window |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1231 popup_list() get list of all popup window IDs |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1232 popup_locate() get popup window ID from its screen position |
17257
cb0ca75f0c26
patch 8.1.1628: popup window functions not in list of functions
Bram Moolenaar <Bram@vim.org>
parents:
17020
diff
changeset
|
1233 |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1234 Timers: *timer-functions* |
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1235 timer_start() create a timer |
9858
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9644
diff
changeset
|
1236 timer_pause() pause or unpause a timer |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
9227
diff
changeset
|
1237 timer_stop() stop a timer |
9858
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9644
diff
changeset
|
1238 timer_stopall() stop all timers |
3e96d9ed2ca1
commit https://github.com/vim/vim/commit/b5ae48e9ffd3b8eb6ca4057de11f1bddcde8ce6f
Christian Brabandt <cb@256bit.org>
parents:
9644
diff
changeset
|
1239 timer_info() get information about timers |
7790
ca19726d5e83
commit https://github.com/vim/vim/commit/298b440930ecece38d6ea0505a3e582dc817e79b
Christian Brabandt <cb@256bit.org>
parents:
7651
diff
changeset
|
1240 |
15068 | 1241 Tags: *tag-functions* |
1242 taglist() get list of matching tags | |
1243 tagfiles() get a list of tags files | |
1244 gettagstack() get the tag stack of a window | |
1245 settagstack() modify the tag stack of a window | |
1246 | |
1247 Prompt Buffer: *promptbuffer-functions* | |
22077
335365fcbb60
patch 8.2.1588: cannot read back the prompt of a prompt buffer
Bram Moolenaar <Bram@vim.org>
parents:
21991
diff
changeset
|
1248 prompt_getprompt() get the effective prompt text for a buffer |
15068 | 1249 prompt_setcallback() set prompt callback for a buffer |
1250 prompt_setinterrupt() set interrupt callback for a buffer | |
1251 prompt_setprompt() set the prompt text for a buffer | |
1252 | |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1253 Text Properties: *text-property-functions* |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1254 prop_add() attach a property at a position |
25640
78ef12e0ce8c
patch 8.2.3356: adding many text properties requires a lot of function calls
Bram Moolenaar <Bram@vim.org>
parents:
25619
diff
changeset
|
1255 prop_add_list() attach a property at multiple positions |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1256 prop_clear() remove all properties from a line or lines |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1257 prop_find() search for a property |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1258 prop_list() return a list of all properties in a line |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1259 prop_remove() remove a property from a line |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1260 prop_type_add() add/define a property type |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1261 prop_type_change() change properties of a type |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1262 prop_type_delete() remove a text property type |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1263 prop_type_get() return the properties of a type |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1264 prop_type_list() return a list of all property types |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1265 |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1266 Sound: *sound-functions* |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1267 sound_clear() stop playing all sounds |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1268 sound_playevent() play an event's sound |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1269 sound_playfile() play a sound file |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1270 sound_stop() stop playing a sound |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1271 |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
1272 Various: *various-functions* |
7 | 1273 mode() get current editing mode |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1274 state() get current busy state |
7 | 1275 visualmode() last visual mode used |
1276 exists() check if a variable, function, etc. exists | |
25555
446f478d6fb1
patch 8.2.3314: behavior of exists() in a :def function is unpredictable
Bram Moolenaar <Bram@vim.org>
parents:
25402
diff
changeset
|
1277 exists_compiled() like exists() but check at compile time |
7 | 1278 has() check if a feature is supported in Vim |
824 | 1279 changenr() return number of most recent change |
7 | 1280 cscope_connection() check if a cscope connection exists |
1281 did_filetype() check if a FileType autocommand was used | |
1282 eventhandler() check if invoked by an event handler | |
1620 | 1283 getpid() get process ID of Vim |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1284 getimstatus() check if IME status is active |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1285 interrupt() interrupt script execution |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1286 windowsversion() get MS-Windows version |
20836
2616c5a337e0
patch 8.2.0970: terminal properties are not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
1287 terminalprops() properties of the terminal |
824 | 1288 |
7 | 1289 libcall() call a function in an external library |
1290 libcallnr() idem, returning a number | |
824 | 1291 |
5618 | 1292 undofile() get the name of the undo file |
1293 undotree() return the state of the undo tree | |
1294 | |
7 | 1295 getreg() get contents of a register |
20743
a672feb8fc4f
patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents:
20687
diff
changeset
|
1296 getreginfo() get information about a register |
7 | 1297 getregtype() get type of a register |
1298 setreg() set contents and type of a register | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13963
diff
changeset
|
1299 reg_executing() return the name of the register being executed |
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13963
diff
changeset
|
1300 reg_recording() return the name of the register being recorded |
824 | 1301 |
5618 | 1302 shiftwidth() effective value of 'shiftwidth' |
1303 | |
9464
be72f4201a1d
commit https://github.com/vim/vim/commit/063b9d15abea041a5bfff3ffc4e219e26fd1d4fa
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
1304 wordcount() get byte/word/char count of buffer |
be72f4201a1d
commit https://github.com/vim/vim/commit/063b9d15abea041a5bfff3ffc4e219e26fd1d4fa
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
1305 |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1306 luaeval() evaluate |Lua| expression |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
1307 mzeval() evaluate |MzScheme| expression |
7651
c7575b07de98
commit https://github.com/vim/vim/commit/e9b892ebcd8596bf813793a1eed5a460a9495a28
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
1308 perleval() evaluate Perl expression (|+perl|) |
5618 | 1309 py3eval() evaluate Python expression (|+python3|) |
1310 pyeval() evaluate Python expression (|+python|) | |
10734 | 1311 pyxeval() evaluate |python_x| expression |
20687
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1312 rubyeval() evaluate |Ruby| expression |
770a8e9c4781
patch 8.2.0897: list of functions in patched version is outdated
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
1313 |
15194 | 1314 debugbreak() interrupt a program being debugged |
2050
afcf9db31561
updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
1315 |
7 | 1316 ============================================================================== |
1317 *41.7* Defining a function | |
1318 | |
1319 Vim enables you to define your own functions. The basic function declaration | |
1320 begins as follows: > | |
1321 | |
26847 | 1322 def {name}({var1}, {var2}, ...): return-type |
1323 {body} | |
1324 enddef | |
7 | 1325 < |
1326 Note: | |
1327 Function names must begin with a capital letter. | |
1328 | |
1329 Let's define a short function to return the smaller of two numbers. It starts | |
1330 with this line: > | |
1331 | |
26847 | 1332 def Min(num1: number, num2: number): number |
1333 | |
1334 This tells Vim that the function is named "Min", it takes two arguments that | |
1335 are numbers: "num1" and "num2" and returns a number. | |
1336 | |
1337 The first thing you need to do is to check to see which number is smaller: | |
7 | 1338 > |
26847 | 1339 if num1 < num2 |
1340 | |
7 | 1341 Let's assign the variable "smaller" the value of the smallest number: > |
1342 | |
26847 | 1343 var smaller: number |
1344 if num1 < num2 | |
1345 smaller = num1 | |
1346 else | |
1347 smaller = num2 | |
1348 endif | |
7 | 1349 |
1350 The variable "smaller" is a local variable. Variables used inside a function | |
26847 | 1351 are local unless prefixed by something like "g:", "w:", or "s:". |
7 | 1352 |
1353 Note: | |
1354 To access a global variable from inside a function you must prepend | |
1620 | 1355 "g:" to it. Thus "g:today" inside a function is used for the global |
1356 variable "today", and "today" is another variable, local to the | |
26847 | 1357 function or the script. |
1358 | |
1359 You now use the `return` statement to return the smallest number to the user. | |
7 | 1360 Finally, you end the function: > |
1361 | |
26847 | 1362 return smaller |
1363 enddef | |
7 | 1364 |
1365 The complete function definition is as follows: > | |
1366 | |
26847 | 1367 def Min(num1: number, num2: number): number |
1368 var smaller: number | |
1369 if num1 < num2 | |
1370 smaller = num1 | |
1371 else | |
1372 smaller = num2 | |
1373 endif | |
1374 return smaller | |
1375 enddef | |
1376 | |
1377 Obviously this is a verbose example. You can make it shorter by using two | |
1378 return commands: > | |
1379 | |
1380 def Min(num1: number, num2: number): number | |
1381 if num1 < num2 | |
1382 return num1 | |
1383 endif | |
1384 return num2 | |
1385 enddef | |
1386 | |
1387 And if you remember the conditional expression, you need only one line: > | |
1388 | |
1389 def Min(num1: number, num2: number): number | |
1390 return num1 < num2 ? num1 : num2 | |
1391 enddef | |
161 | 1392 |
681 | 1393 A user defined function is called in exactly the same way as a built-in |
7 | 1394 function. Only the name is different. The Min function can be used like |
1395 this: > | |
1396 | |
26847 | 1397 echo Min(5, 8) |
1398 | |
1399 Only now will the function be executed and the lines be parsed by Vim. | |
7 | 1400 If there are mistakes, like using an undefined variable or function, you will |
1401 now get an error message. When defining the function these errors are not | |
26847 | 1402 detected. To get the errors sooner you can tell Vim to compile all the |
1403 functions in the script: > | |
1404 | |
1405 defcompile | |
1406 | |
1407 For a function that does not return anything leave out the return type: > | |
1408 | |
1409 def SayIt(text: string) | |
1410 echo text | |
1411 enddef | |
1412 | |
1413 It is also possible to define a legacy function with `function` and | |
1414 `endfunction`. These do not have types and are not compiled. They execute | |
1415 much slower. | |
7 | 1416 |
1417 | |
1418 USING A RANGE | |
1419 | |
26847 | 1420 A line range can be used with a function call. The function will be called |
1421 once for every line in the range, with the cursor in that line. Example: > | |
1422 | |
1423 def Number() | |
1424 echo "line " .. line(".") .. " contains: " .. getline(".") | |
1425 enddef | |
7 | 1426 |
1427 If you call this function with: > | |
1428 | |
1429 :10,15call Number() | |
1430 | |
26847 | 1431 The function will be called six times, starting on line 10 and ending on line |
1432 15. | |
7 | 1433 |
1434 | |
1435 VARIABLE NUMBER OF ARGUMENTS | |
1436 | |
1437 Vim enables you to define functions that have a variable number of arguments. | |
1438 The following command, for instance, defines a function that must have 1 | |
1439 argument (start) and can have up to 20 additional arguments: > | |
1440 | |
26847 | 1441 def Show(start: string, ...items: list<string>) |
1442 | |
1443 The variable "items" will be a list containing the extra arguments. You can | |
1444 use it like any list, for example: > | |
1445 | |
1446 def Show(start: string, ...items: list<string>) | |
1447 echohl Title | |
1448 echo "start is " .. start | |
1449 echohl None | |
1450 for index in range(len(items)) | |
1451 echon " Arg " .. index .. " is " .. items[index] | |
1452 endfor | |
1453 echo | |
1454 enddef | |
1455 | |
1456 You can call it like this: > | |
1457 | |
1458 Show('Title', 'one', 'two', 'three') | |
1459 < start is Title Arg 0 is one Arg 1 is two Arg 2 is three ~ | |
1460 | |
1461 This uses the `echohl` command to specify the highlighting used for the | |
1462 following `echo` command. `echohl None` stops it again. The `echon` command | |
1463 works like `echo`, but doesn't output a line break. | |
1464 | |
1465 If you call it with one argument the "items" list will be empty. | |
1466 `range(len(items))` returns a list with the indexes, what `for` loops over, | |
1467 we'll explain that further down. | |
161 | 1468 |
7 | 1469 |
1470 LISTING FUNCTIONS | |
1471 | |
26847 | 1472 The `function` command lists the names and arguments of all user-defined |
7 | 1473 functions: > |
1474 | |
1475 :function | |
26847 | 1476 < def <SNR>86_Show(start: string, ...items: list<string>) ~ |
7 | 1477 function GetVimIndent() ~ |
1478 function SetSyn(name) ~ | |
1479 | |
26847 | 1480 The "<SNR>" prefix means that a function is script-local. |Vim9| functions |
1481 wil start with "def" and include argument and return types. Legacy functions | |
1482 are listed with "function". | |
1483 | |
1484 To see what a function does, use its name as an argument for `function`: > | |
7 | 1485 |
1486 :function SetSyn | |
1487 < 1 if &syntax == '' ~ | |
1488 2 let &syntax = a:name ~ | |
1489 3 endif ~ | |
1490 endfunction ~ | |
1491 | |
26847 | 1492 To see the "Show" function you need to include the script prefix, since a |
1493 "Show" function can be defined multiple times in different scripts. To find | |
1494 the exact name you can use `function`, but the result may be a very long list. | |
1495 To only get the functions matching a pattern you can use the `filter` prefix: | |
1496 > | |
1497 | |
1498 :filter Show function | |
1499 < def <SNR>86_Show(start: string, ...items: list<string>) ~ | |
1500 > | |
1501 :function <SNR>86_Show | |
1502 < 1 echohl Title ~ | |
1503 2 echo "start is " .. start ~ | |
1504 etc. | |
1505 | |
7 | 1506 |
1507 DEBUGGING | |
1508 | |
1509 The line number is useful for when you get an error message or when debugging. | |
1510 See |debug-scripts| about debugging mode. | |
26847 | 1511 |
1512 You can also set the 'verbose' option to 12 or higher to see all function | |
7 | 1513 calls. Set it to 15 or higher to see every executed line. |
1514 | |
1515 | |
1516 DELETING A FUNCTION | |
1517 | |
26847 | 1518 To delete the SetSyn() function: > |
1519 | |
1520 :delfunction SetSyn | |
1521 | |
1522 Deleting only works for global functions and functions in legacy script, not | |
1523 for functions defined in a |Vim9| script. | |
1524 | |
1525 You get an error when the function doesn't exist or cannot be deleted. | |
7 | 1526 |
161 | 1527 |
1528 FUNCTION REFERENCES | |
1529 | |
1530 Sometimes it can be useful to have a variable point to one function or | |
26847 | 1531 another. You can do it with function reference variable. Often shortened to |
1532 "funcref". Example: > | |
1533 | |
1534 def Right() | |
1535 return 'Right!' | |
1536 enddef | |
1537 def Wrong() | |
1538 return 'Wrong!' | |
1539 enddef | |
1540 | |
1541 var Afunc = g:result == 1 ? Right : Wrong | |
1542 Afunc() | |
161 | 1543 < Wrong! ~ |
1544 | |
26847 | 1545 This assumes "g:result" is not one. |
1546 | |
161 | 1547 Note that the name of a variable that holds a function reference must start |
1548 with a capital. Otherwise it could be confused with the name of a builtin | |
1549 function. | |
1550 | |
25806
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1551 More information about defining your own functions here: |user-functions|. |
8d55e978f95b
patch 8.2.3438: cannot manipulate blobs
Bram Moolenaar <Bram@vim.org>
parents:
25640
diff
changeset
|
1552 |
7 | 1553 ============================================================================== |
161 | 1554 *41.8* Lists and Dictionaries |
1555 | |
1556 So far we have used the basic types String and Number. Vim also supports two | |
1557 composite types: List and Dictionary. | |
1558 | |
26847 | 1559 A List is an ordered sequence of items. The items can be any kind of value, |
161 | 1560 thus you can make a List of numbers, a List of Lists and even a List of mixed |
1561 items. To create a List with three strings: > | |
1562 | |
26847 | 1563 var alist = ['aap', 'mies', 'noot'] |
161 | 1564 |
1565 The List items are enclosed in square brackets and separated by commas. To | |
1566 create an empty List: > | |
1567 | |
26847 | 1568 var alist = [] |
161 | 1569 |
1570 You can add items to a List with the add() function: > | |
1571 | |
26847 | 1572 var alist = [] |
1573 add(alist, 'foo') | |
1574 add(alist, 'bar') | |
1575 echo alist | |
161 | 1576 < ['foo', 'bar'] ~ |
1577 | |
1578 List concatenation is done with +: > | |
1579 | |
26847 | 1580 var alist = ['foo', 'bar'] |
1581 alist = alist + ['and', 'more'] | |
1582 echo alist | |
1583 < ['foo', 'bar', 'and', 'more'] ~ | |
1584 | |
1585 Or, if you want to extend a List with a function: > | |
1586 | |
1587 var alist = ['one'] | |
1588 extend(alist, ['two', 'three']) | |
1589 echo alist | |
161 | 1590 < ['one', 'two', 'three'] ~ |
1591 | |
26847 | 1592 Notice that using `add()` will have a different effect: > |
1593 | |
1594 var alist = ['one'] | |
1595 add(alist, ['two', 'three']) | |
1596 echo alist | |
161 | 1597 < ['one', ['two', 'three']] ~ |
1598 | |
26847 | 1599 The second argument of add() is added as an item, now you have a nested list. |
161 | 1600 |
1601 | |
1602 FOR LOOP | |
1603 | |
1604 One of the nice things you can do with a List is iterate over it: > | |
1605 | |
26847 | 1606 var alist = ['one', 'two', 'three'] |
1607 for n in alist | |
1608 echo n | |
1609 endfor | |
161 | 1610 < one ~ |
1611 two ~ | |
1612 three ~ | |
1613 | |
26847 | 1614 This will loop over each element in List "alist", assigning each value to |
161 | 1615 variable "n". The generic form of a for loop is: > |
1616 | |
26847 | 1617 for {varname} in {listexpression} |
1618 {commands} | |
1619 endfor | |
161 | 1620 |
1621 To loop a certain number of times you need a List of a specific length. The | |
1622 range() function creates one for you: > | |
1623 | |
26847 | 1624 for a in range(3) |
1625 echo a | |
1626 endfor | |
161 | 1627 < 0 ~ |
1628 1 ~ | |
1629 2 ~ | |
1630 | |
1631 Notice that the first item of the List that range() produces is zero, thus the | |
1632 last item is one less than the length of the list. | |
26847 | 1633 |
1634 You can also specify the maximum value, the stride and even go backwards: > | |
1635 | |
1636 for a in range(8, 4, -2) | |
1637 echo a | |
1638 endfor | |
161 | 1639 < 8 ~ |
1640 6 ~ | |
1641 4 ~ | |
1642 | |
1643 A more useful example, looping over lines in the buffer: > | |
1644 | |
26847 | 1645 for line in getline(1, 20) |
1646 if line =~ "Date: " | |
1647 echo line | |
1648 endif | |
1649 endfor | |
161 | 1650 |
1651 This looks into lines 1 to 20 (inclusive) and echoes any date found in there. | |
1652 | |
1653 | |
1654 DICTIONARIES | |
1655 | |
1656 A Dictionary stores key-value pairs. You can quickly lookup a value if you | |
1657 know the key. A Dictionary is created with curly braces: > | |
856 | 1658 |
26847 | 1659 var uk2nl = {one: 'een', two: 'twee', three: 'drie'} |
161 | 1660 |
164 | 1661 Now you can lookup words by putting the key in square brackets: > |
161 | 1662 |
26847 | 1663 echo uk2nl['two'] |
1664 < twee ~ | |
1665 | |
1666 If the key does not have special characters, you can use the dot notation: > | |
1667 | |
1668 echo uk2nl.two | |
161 | 1669 < twee ~ |
1670 | |
1671 The generic form for defining a Dictionary is: > | |
1672 | |
1673 {<key> : <value>, ...} | |
1674 | |
1675 An empty Dictionary is one without any keys: > | |
1676 | |
1677 {} | |
1678 | |
1679 The possibilities with Dictionaries are numerous. There are various functions | |
1680 for them as well. For example, you can obtain a list of the keys and loop | |
1681 over them: > | |
1682 | |
26847 | 1683 for key in keys(uk2nl) |
1684 echo key | |
1685 endfor | |
161 | 1686 < three ~ |
1687 one ~ | |
1688 two ~ | |
1689 | |
1620 | 1690 You will notice the keys are not ordered. You can sort the list to get a |
161 | 1691 specific order: > |
1692 | |
26847 | 1693 for key in sort(keys(uk2nl)) |
1694 echo key | |
1695 endfor | |
161 | 1696 < one ~ |
1697 three ~ | |
1698 two ~ | |
1699 | |
1700 But you can never get back the order in which items are defined. For that you | |
1701 need to use a List, it stores items in an ordered sequence. | |
1702 | |
1703 | |
1704 For further reading see |Lists| and |Dictionaries|. | |
1705 | |
1706 ============================================================================== | |
1707 *41.9* Exceptions | |
7 | 1708 |
1709 Let's start with an example: > | |
1710 | |
26847 | 1711 try |
1712 read ~/templates/pascal.tmpl | |
1713 catch /E484:/ | |
1714 echo "Sorry, the Pascal template file cannot be found." | |
1715 endtry | |
1716 | |
1717 The `read` command will fail if the file does not exist. Instead of | |
7 | 1718 generating an error message, this code catches the error and gives the user a |
2709 | 1719 nice message. |
7 | 1720 |
26847 | 1721 For the commands in between `try` and `endtry` errors are turned into |
7 | 1722 exceptions. An exception is a string. In the case of an error the string |
1723 contains the error message. And every error message has a number. In this | |
1724 case, the error we catch contains "E484:". This number is guaranteed to stay | |
1725 the same (the text may change, e.g., it may be translated). | |
1726 | |
26847 | 1727 Besides being able to give a nice error message, Vim will also continue |
1728 executing commands. Otherwise, once an uncaught error is encountered, | |
1729 execution will be aborted. | |
1730 | |
1731 When the `read` command causes another error, the pattern "E484:" will not | |
7 | 1732 match in it. Thus this exception will not be caught and result in the usual |
1733 error message. | |
1734 | |
1735 You might be tempted to do this: > | |
1736 | |
26847 | 1737 try |
1738 read ~/templates/pascal.tmpl | |
1739 catch | |
1740 echo "Sorry, the Pascal template file cannot be found." | |
1741 endtry | |
1742 | |
1743 This means all errors are caught. But then you will not see an error that | |
1744 would indicate a completely different problem, such as "E21: Cannot make | |
1745 changes, 'modifiable' is off". | |
1746 | |
1747 Another useful mechanism is the `finally` command: > | |
1748 | |
1749 var tmp = tempname() | |
1750 try | |
1751 exe ":.,$write " .. tmp | |
1752 exe "!filter " .. tmp | |
1753 :.,$delete | |
1754 exe ":$read " .. tmp | |
1755 finally | |
1756 call delete(tmp) | |
1757 endtry | |
7 | 1758 |
1759 This filters the lines from the cursor until the end of the file through the | |
1760 "filter" command, which takes a file name argument. No matter if the | |
26847 | 1761 filtering works, something goes wrong in between `try` and `finally` or the |
1762 user cancels the filtering by pressing CTRL-C, the `call delete(tmp)` is | |
7 | 1763 always executed. This makes sure you don't leave the temporary file behind. |
1764 | |
1765 More information about exception handling can be found in the reference | |
1766 manual: |exception-handling|. | |
1767 | |
1768 ============================================================================== | |
161 | 1769 *41.10* Various remarks |
7 | 1770 |
26847 | 1771 Here is a summary of items that are useful to know when writing Vim scripts. |
1772 | |
1773 The end-of-line character depends on the system. For Vim scripts it is | |
1774 recommended to always use the Unix fileformat, this also works on any other | |
1775 system. That way you can copy your Vim scripts from MS-Windows to Unix and | |
1776 they still work. See |:source_crnl|. To be sure it is set right, do this | |
1777 before writing the file: > | |
1778 | |
1779 :setlocal fileformat=unix | |
7 | 1780 |
1781 | |
1782 WHITE SPACE | |
1783 | |
1784 Blank lines are allowed and ignored. | |
1785 | |
26847 | 1786 Leading whitespace characters (blanks and TABs) are always ignored. |
1787 | |
1788 Trailing whitespace is often ignored, but not always. One command that | |
1789 includes it is `map`. | |
7 | 1790 |
1791 To include a whitespace character in the value of an option, it must be | |
1792 escaped by a "\" (backslash) as in the following example: > | |
1793 | |
1794 :set tags=my\ nice\ file | |
1795 | |
2709 | 1796 The same example written as: > |
7 | 1797 |
1798 :set tags=my nice file | |
1799 | |
1800 will issue an error, because it is interpreted as: > | |
1801 | |
1802 :set tags=my | |
1803 :set nice | |
1804 :set file | |
1805 | |
26847 | 1806 |Vim9| script is very picky when it comes to white space. This was done |
1807 intentionally to make sure scripts are easy to read and to avoid mistakes. | |
1808 | |
7 | 1809 |
1810 COMMENTS | |
1811 | |
26847 | 1812 In |Vim9| script the character # starts a comment. Everything after |
7 | 1813 and including this character until the end-of-line is considered a comment and |
1814 is ignored, except for commands that don't consider comments, as shown in | |
26847 | 1815 examples below. A comment can start on any character position on the line, |
1816 but not when it is part of the command, e.g. in a string. | |
1817 | |
1818 The character " (the double quote mark) starts a comment in legacy script. | |
7 | 1819 |
1820 There is a little "catch" with comments for some commands. Examples: > | |
1821 | |
26847 | 1822 abbrev dev development # shorthand |
1823 map <F3> o#include # insert include | |
1824 execute cmd # do it | |
1825 !ls *.c # list C files | |
1826 | |
1827 The abbreviation 'dev' will be expanded to 'development # shorthand'. The | |
7 | 1828 mapping of <F3> will actually be the whole line after the 'o# ....' including |
26847 | 1829 the '# insert include'. The `execute` command will give an error. The `!` |
1830 command will send everything after it to the shell, most likely causing an | |
1831 error. | |
1832 | |
1833 There can be no comment after `map`, `abbreviate`, `execute` and `!` commands | |
1834 (there are a few more commands with this restriction). For the `map`, | |
1835 `abbreviate` and `execute` commands there is a trick: > | |
1836 | |
1837 abbrev dev development|# shorthand | |
1838 map <F3> o#include|# insert include | |
1839 execute '!ls *.c' |# do it | |
7 | 1840 |
1841 With the '|' character the command is separated from the next one. And that | |
26847 | 1842 next command is only a comment. The last command, using `execute` is a |
1843 general solution, it works for all commands that do not accept a comment or a | |
1844 '|' to separate the next command. | |
7 | 1845 |
1846 Notice that there is no white space before the '|' in the abbreviation and | |
1847 mapping. For these commands, any character until the end-of-line or '|' is | |
1848 included. As a consequence of this behavior, you don't always see that | |
1849 trailing whitespace is included: > | |
1850 | |
26847 | 1851 map <F4> o#include |
1852 | |
1853 To spot these problems, you can highlight trailing spaces: > | |
1854 match Search /\s\+$/ | |
7 | 1855 |
1146 | 1856 For Unix there is one special way to comment a line, that allows making a Vim |
26847 | 1857 script executable, and it also works in legacy script: > |
1146 | 1858 #!/usr/bin/env vim -S |
1859 echo "this is a Vim script" | |
1860 quit | |
1861 | |
7 | 1862 |
1863 PITFALLS | |
1864 | |
26847 | 1865 An even bigger problem arises in the following example: > |
1866 | |
1867 map ,ab o#include | |
1868 unmap ,ab | |
7 | 1869 |
1870 Here the unmap command will not work, because it tries to unmap ",ab ". This | |
1871 does not exist as a mapped sequence. An error will be issued, which is very | |
26847 | 1872 hard to identify, because the ending whitespace character in `unmap ,ab ` is |
7 | 1873 not visible. |
1874 | |
1875 And this is the same as what happens when one uses a comment after an 'unmap' | |
1876 command: > | |
1877 | |
26847 | 1878 unmap ,ab # comment |
7 | 1879 |
1880 Here the comment part will be ignored. However, Vim will try to unmap | |
1881 ',ab ', which does not exist. Rewrite it as: > | |
1882 | |
26847 | 1883 unmap ,ab| # comment |
7 | 1884 |
1885 | |
1886 RESTORING THE VIEW | |
1887 | |
3893 | 1888 Sometimes you want to make a change and go back to where the cursor was. |
7 | 1889 Restoring the relative position would also be nice, so that the same line |
1890 appears at the top of the window. | |
26847 | 1891 |
1892 This example yanks the current line, puts it above the first line in the file | |
1893 and then restores the view: > | |
7 | 1894 |
1895 map ,p ma"aYHmbgg"aP`bzt`a | |
1896 | |
1897 What this does: > | |
1898 ma"aYHmbgg"aP`bzt`a | |
1899 < ma set mark a at cursor position | |
1900 "aY yank current line into register a | |
1901 Hmb go to top line in window and set mark b there | |
1902 gg go to first line in file | |
1903 "aP put the yanked line above it | |
1904 `b go back to top line in display | |
1905 zt position the text in the window as before | |
1906 `a go back to saved cursor position | |
1907 | |
1908 | |
1909 PACKAGING | |
1910 | |
26847 | 1911 Sometimes you will want to use global variables or functions, so that they can |
1912 be used anywhere. A good example is a global variable that passes a | |
1913 preference to a plugin. To avoid other scripts using the same name, use a | |
1914 prefix that is very unlikely to be used elsewhere. For example, if you have a | |
1915 "mytags" plugin, you could use: > | |
1916 | |
1917 g:mytags_location = '$HOME/project' | |
1918 g:mytags_style = 'fast' | |
1919 | |
1920 To minimize interference between plugins keep as much as possible local to the | |
1921 script. |Vim9| script helps you with that, by default functions and variables | |
1922 are script-local. | |
1923 | |
1924 If you split your plugin into parts, you can use `import` and `export` to | |
1925 share items between those parts. See `:export` for the details. | |
7 | 1926 |
1927 ============================================================================== | |
161 | 1928 *41.11* Writing a plugin *write-plugin* |
7 | 1929 |
1930 You can write a Vim script in such a way that many people can use it. This is | |
1931 called a plugin. Vim users can drop your script in their plugin directory and | |
1932 use its features right away |add-plugin|. | |
1933 | |
1934 There are actually two types of plugins: | |
1935 | |
1936 global plugins: For all types of files. | |
1937 filetype plugins: Only for files of a specific type. | |
1938 | |
1939 In this section the first type is explained. Most items are also relevant for | |
1940 writing filetype plugins. The specifics for filetype plugins are in the next | |
1941 section |write-filetype-plugin|. | |
1942 | |
1943 | |
1944 NAME | |
1945 | |
1946 First of all you must choose a name for your plugin. The features provided | |
1947 by the plugin should be clear from its name. And it should be unlikely that | |
1948 someone else writes a plugin with the same name but which does something | |
26847 | 1949 different. |
1950 | |
1951 A script that corrects typing mistakes could be called "typecorrect.vim". We | |
7 | 1952 will use it here as an example. |
1953 | |
1954 For the plugin to work for everybody, it should follow a few guidelines. This | |
1955 will be explained step-by-step. The complete example plugin is at the end. | |
1956 | |
1957 | |
1958 BODY | |
1959 | |
1960 Let's start with the body of the plugin, the lines that do the actual work: > | |
1961 | |
1962 14 iabbrev teh the | |
1963 15 iabbrev otehr other | |
1964 16 iabbrev wnat want | |
1965 17 iabbrev synchronisation | |
1966 18 \ synchronization | |
1967 | |
1968 The actual list should be much longer, of course. | |
1969 | |
1970 The line numbers have only been added to explain a few things, don't put them | |
1971 in your plugin file! | |
1972 | |
1973 | |
26847 | 1974 FIRST LINE |
1975 > | |
1976 1 vim9script noclear | |
1977 | |
1978 You need to use `vimscript` as the very first command. Best is to put it in | |
1979 the very first line. | |
1980 | |
1981 The script we are writing will have a `finish` command to bail out when it is | |
1982 loaded a second time. To avoid the items defined in the script are lost the | |
1983 "noclear" argument is used. More info about this at |vim9-reload|. | |
1984 | |
1985 | |
7 | 1986 HEADER |
1987 | |
1988 You will probably add new corrections to the plugin and soon have several | |
3830 | 1989 versions lying around. And when distributing this file, people will want to |
7 | 1990 know who wrote this wonderful plugin and where they can send remarks. |
1991 Therefore, put a header at the top of your plugin: > | |
1992 | |
26847 | 1993 2 # Vim global plugin for correcting typing mistakes |
1994 3 # Last Change: 2021 Dec 30 | |
1995 4 # Maintainer: Bram Moolenaar <Bram@vim.org> | |
7 | 1996 |
1997 About copyright and licensing: Since plugins are very useful and it's hardly | |
1998 worth restricting their distribution, please consider making your plugin | |
1999 either public domain or use the Vim |license|. A short note about this near | |
2000 the top of the plugin should be sufficient. Example: > | |
2001 | |
26847 | 2002 5 # License: This file is placed in the public domain. |
2003 | |
2004 | |
2005 LINE CONTINUATION AND AVOIDING SIDE EFFECTS *use-cpo-save* | |
7 | 2006 |
2007 In line 18 above, the line-continuation mechanism is used |line-continuation|. | |
2008 Users with 'compatible' set will run into trouble here, they will get an error | |
2009 message. We can't just reset 'compatible', because that has a lot of side | |
26847 | 2010 effects. Instead, we will set the 'cpoptions' option to its Vim default |
7 | 2011 value and restore it later. That will allow the use of line-continuation and |
2012 make the script work for most people. It is done like this: > | |
2013 | |
26847 | 2014 11 var save_cpo = &cpo |
7 | 2015 12 set cpo&vim |
2016 .. | |
26847 | 2017 42 &cpo = save_cpo |
2018 | |
2019 We first store the old value of 'cpoptions' in the "save_cpo" variable. At | |
7 | 2020 the end of the plugin this value is restored. |
2021 | |
26847 | 2022 Notice that "save_cpo" is a script-local variable. A global variable could |
7 | 2023 already be in use for something else. Always use script-local variables for |
2024 things that are only used in the script. | |
2025 | |
2026 | |
2027 NOT LOADING | |
2028 | |
26847 | 2029 It is possible that a user doesn't always want to load this plugin. Or the |
7 | 2030 system administrator has dropped it in the system-wide plugin directory, but a |
2031 user has his own plugin he wants to use. Then the user must have a chance to | |
26847 | 2032 disable loading this specific plugin. These lines will make it possible: > |
2033 | |
2034 7 if exists("g:loaded_typecorrect") | |
2035 8 finish | |
2036 9 endif | |
2037 10 g:loaded_typecorrect = 1 | |
2038 | |
2039 This also avoids that when the script is loaded twice it would pointlessly | |
2040 redefine functions and cause trouble for autocommands that are added twice. | |
2041 | |
2042 The name is recommended to start with "g:loaded_" and then the file name of | |
2043 the plugin, literally. The "g:" is prepended to make the variable global, so | |
2044 that other places can check whether its functionality is available. Without | |
2045 "g:" it would be local to the script. | |
2046 | |
2047 Using `finish` stops Vim from reading the rest of the file, it's much quicker | |
2048 than using if-endif around the whole file, since Vim would still need to parse | |
2049 the commands to find the `endif`. | |
2325
f177a6431514
Better implementation of creating the Color Scheme menu. (Juergen Kraemer)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
2050 |
7 | 2051 |
2052 MAPPING | |
2053 | |
2054 Now let's make the plugin more interesting: We will add a mapping that adds a | |
2055 correction for the word under the cursor. We could just pick a key sequence | |
2056 for this mapping, but the user might already use it for something else. To | |
2057 allow the user to define which keys a mapping in a plugin uses, the <Leader> | |
2058 item can be used: > | |
2059 | |
21825 | 2060 22 map <unique> <Leader>a <Plug>TypecorrAdd; |
2061 | |
2062 The "<Plug>TypecorrAdd;" thing will do the work, more about that further on. | |
7 | 2063 |
26847 | 2064 The user can set the "g:mapleader" variable to the key sequence that he wants |
2065 plugin mappings to start with. Thus if the user has done: > | |
2066 | |
2067 g:mapleader = "_" | |
7 | 2068 |
2069 the mapping will define "_a". If the user didn't do this, the default value | |
2070 will be used, which is a backslash. Then a map for "\a" will be defined. | |
2071 | |
2072 Note that <unique> is used, this will cause an error message if the mapping | |
2073 already happened to exist. |:map-<unique>| | |
2074 | |
2075 But what if the user wants to define his own key sequence? We can allow that | |
2076 with this mechanism: > | |
2077 | |
21825 | 2078 21 if !hasmapto('<Plug>TypecorrAdd;') |
2079 22 map <unique> <Leader>a <Plug>TypecorrAdd; | |
7 | 2080 23 endif |
2081 | |
21991 | 2082 This checks if a mapping to "<Plug>TypecorrAdd;" already exists, and only |
7 | 2083 defines the mapping from "<Leader>a" if it doesn't. The user then has a |
2084 chance of putting this in his vimrc file: > | |
2085 | |
21825 | 2086 map ,c <Plug>TypecorrAdd; |
7 | 2087 |
2088 Then the mapped key sequence will be ",c" instead of "_a" or "\a". | |
2089 | |
2090 | |
2091 PIECES | |
2092 | |
2093 If a script gets longer, you often want to break up the work in pieces. You | |
2094 can use functions or mappings for this. But you don't want these functions | |
2095 and mappings to interfere with the ones from other scripts. For example, you | |
2096 could define a function Add(), but another script could try to define the same | |
26847 | 2097 function. To avoid this, we define the function local to the script. |
2098 Fortunately, in |Vim9| script this is the default. In a legacy script you | |
2099 would need to prefix the name with "s:". | |
7 | 2100 |
2101 We will define a function that adds a new typing correction: > | |
2102 | |
26847 | 2103 30 def Add(from: string, correct: bool) |
2104 31 var to = input("type the correction for " .. from .. ": ") | |
2105 32 exe ":iabbrev " .. from .. " " .. to | |
7 | 2106 .. |
26847 | 2107 36 enddef |
2108 | |
2109 Now we can call the function Add() from within this script. If another | |
2110 script also defines Add(), it will be local to that script and can only | |
2111 be called from that script. There can also be a global g:Add() function, | |
2112 which is again another function. | |
7 | 2113 |
2114 <SID> can be used with mappings. It generates a script ID, which identifies | |
2115 the current script. In our typing correction plugin we use it like this: > | |
2116 | |
21825 | 2117 24 noremap <unique> <script> <Plug>TypecorrAdd; <SID>Add |
7 | 2118 .. |
26847 | 2119 28 noremap <SID>Add :call <SID>Add(expand("<cword>"), true)<CR> |
7 | 2120 |
2121 Thus when a user types "\a", this sequence is invoked: > | |
2122 | |
26847 | 2123 \a -> <Plug>TypecorrAdd; -> <SID>Add -> :call <SID>Add(...) |
21825 | 2124 |
2125 If another script also maps <SID>Add, it will get another script ID and | |
7 | 2126 thus define another mapping. |
2127 | |
26847 | 2128 Note that instead of Add() we use <SID>Add() here. That is because the |
2129 mapping is typed by the user, thus outside of the script context. The <SID> | |
2130 is translated to the script ID, so that Vim knows in which script to look for | |
7 | 2131 the Add() function. |
2132 | |
2133 This is a bit complicated, but it's required for the plugin to work together | |
2134 with other plugins. The basic rule is that you use <SID>Add() in mappings and | |
26847 | 2135 Add() in other places (the script itself, autocommands, user commands). |
7 | 2136 |
2137 We can also add a menu entry to do the same as the mapping: > | |
2138 | |
2139 26 noremenu <script> Plugin.Add\ Correction <SID>Add | |
2140 | |
2141 The "Plugin" menu is recommended for adding menu items for plugins. In this | |
2142 case only one item is used. When adding more items, creating a submenu is | |
2143 recommended. For example, "Plugin.CVS" could be used for a plugin that offers | |
2144 CVS operations "Plugin.CVS.checkin", "Plugin.CVS.checkout", etc. | |
2145 | |
2146 Note that in line 28 ":noremap" is used to avoid that any other mappings cause | |
2147 trouble. Someone may have remapped ":call", for example. In line 24 we also | |
2148 use ":noremap", but we do want "<SID>Add" to be remapped. This is why | |
2149 "<script>" is used here. This only allows mappings which are local to the | |
2150 script. |:map-<script>| The same is done in line 26 for ":noremenu". | |
2151 |:menu-<script>| | |
2152 | |
2153 | |
2154 <SID> AND <Plug> *using-<Plug>* | |
2155 | |
2156 Both <SID> and <Plug> are used to avoid that mappings of typed keys interfere | |
2157 with mappings that are only to be used from other mappings. Note the | |
2158 difference between using <SID> and <Plug>: | |
2159 | |
2160 <Plug> is visible outside of the script. It is used for mappings which the | |
2161 user might want to map a key sequence to. <Plug> is a special code | |
2162 that a typed key will never produce. | |
2163 To make it very unlikely that other plugins use the same sequence of | |
2164 characters, use this structure: <Plug> scriptname mapname | |
2165 In our example the scriptname is "Typecorr" and the mapname is "Add". | |
21825 | 2166 We add a semicolon as the terminator. This results in |
2167 "<Plug>TypecorrAdd;". Only the first character of scriptname and | |
2168 mapname is uppercase, so that we can see where mapname starts. | |
7 | 2169 |
2170 <SID> is the script ID, a unique identifier for a script. | |
2171 Internally Vim translates <SID> to "<SNR>123_", where "123" can be any | |
2172 number. Thus a function "<SID>Add()" will have a name "<SNR>11_Add()" | |
2173 in one script, and "<SNR>22_Add()" in another. You can see this if | |
2174 you use the ":function" command to get a list of functions. The | |
2175 translation of <SID> in mappings is exactly the same, that's how you | |
2176 can call a script-local function from a mapping. | |
2177 | |
2178 | |
2179 USER COMMAND | |
2180 | |
2181 Now let's add a user command to add a correction: > | |
2182 | |
2183 38 if !exists(":Correct") | |
26847 | 2184 39 command -nargs=1 Correct :call Add(<q-args>, false) |
7 | 2185 40 endif |
2186 | |
2187 The user command is defined only if no command with the same name already | |
2188 exists. Otherwise we would get an error here. Overriding the existing user | |
2189 command with ":command!" is not a good idea, this would probably make the user | |
2190 wonder why the command he defined himself doesn't work. |:command| | |
26847 | 2191 If it did happen you can find out who to blame with: > |
2192 | |
2193 verbose command Correct | |
7 | 2194 |
2195 | |
2196 SCRIPT VARIABLES | |
2197 | |
2198 When a variable starts with "s:" it is a script variable. It can only be used | |
2199 inside a script. Outside the script it's not visible. This avoids trouble | |
2200 with using the same variable name in different scripts. The variables will be | |
2201 kept as long as Vim is running. And the same variables are used when sourcing | |
2202 the same script again. |s:var| | |
2203 | |
26847 | 2204 The nice thing about |Vim9| script is that variables are local to the script |
2205 by default. You can prepend "s:" if you like, but you do not need to. And | |
2206 functions in the script can also use the script variables without a prefix. | |
2207 | |
2208 Script-local variables can also be used in functions, autocommands and user | |
2209 commands that are defined in the script. Thus they are the perfect way to | |
2210 share information between parts of your plugin, without it leaking out. In | |
2211 our example we can add a few lines to count the number of corrections: > | |
2212 | |
2213 19 var count = 4 | |
7 | 2214 .. |
26847 | 2215 30 def Add(from: string, correct: bool) |
7 | 2216 .. |
26847 | 2217 34 count += 1 |
2218 35 echo "you now have " .. count .. " corrections" | |
2219 36 enddef | |
2220 | |
2221 "count" is declared and initialized to 4 in the script itself. When later | |
2222 the Add() function is called, it increments "count". It doesn't matter from | |
7 | 2223 where the function was called, since it has been defined in the script, it |
2224 will use the local variables from this script. | |
2225 | |
2226 | |
2227 THE RESULT | |
2228 | |
2229 Here is the resulting complete example: > | |
2230 | |
26847 | 2231 1 vim9script noclear |
2232 2 # Vim global plugin for correcting typing mistakes | |
2233 3 # Last Change: 2021 Dec 30 | |
2234 4 # Maintainer: Bram Moolenaar <Bram@vim.org> | |
2235 5 # License: This file is placed in the public domain. | |
2236 6 | |
2237 7 if exists("g:loaded_typecorrect") | |
2238 8 finish | |
2239 9 endif | |
2240 10 g:loaded_typecorrect = 1 | |
2241 11 var save_cpo = &cpo | |
7 | 2242 12 set cpo&vim |
2243 13 | |
2244 14 iabbrev teh the | |
2245 15 iabbrev otehr other | |
2246 16 iabbrev wnat want | |
2247 17 iabbrev synchronisation | |
2248 18 \ synchronization | |
26847 | 2249 19 var count = 4 |
7 | 2250 20 |
21825 | 2251 21 if !hasmapto('<Plug>TypecorrAdd;') |
2252 22 map <unique> <Leader>a <Plug>TypecorrAdd; | |
7 | 2253 23 endif |
21825 | 2254 24 noremap <unique> <script> <Plug>TypecorrAdd; <SID>Add |
7 | 2255 25 |
2256 26 noremenu <script> Plugin.Add\ Correction <SID>Add | |
2257 27 | |
26847 | 2258 28 noremap <SID>Add :call <SID>Add(expand("<cword>"), true)<CR> |
7 | 2259 29 |
26847 | 2260 30 def Add(from: string, correct: bool) |
2261 31 var to = input("type the correction for " .. from .. ": ") | |
2262 32 exe ":iabbrev " .. from .. " " .. to | |
2263 33 if correct | exe "normal viws\<C-R>\" \b\e" | endif | |
2264 34 count += 1 | |
2265 35 echo "you now have " .. count .. " corrections" | |
2266 36 enddef | |
7 | 2267 37 |
2268 38 if !exists(":Correct") | |
26847 | 2269 39 command -nargs=1 Correct call Add(<q-args>, false) |
7 | 2270 40 endif |
2271 41 | |
26847 | 2272 42 &cpo = save_cpo |
7 | 2273 |
2274 Line 33 wasn't explained yet. It applies the new correction to the word under | |
2275 the cursor. The |:normal| command is used to use the new abbreviation. Note | |
2276 that mappings and abbreviations are expanded here, even though the function | |
2277 was called from a mapping defined with ":noremap". | |
2278 | |
2279 | |
2280 DOCUMENTATION *write-local-help* | |
2281 | |
2282 It's a good idea to also write some documentation for your plugin. Especially | |
2283 when its behavior can be changed by the user. See |add-local-help| for how | |
2284 they are installed. | |
2285 | |
26847 | 2286 Here is a simple example for a plugin help file, called "typecorrect.txt": > |
2287 | |
2288 1 *typecorrect.txt* Plugin for correcting typing mistakes | |
7 | 2289 2 |
2290 3 If you make typing mistakes, this plugin will have them corrected | |
2291 4 automatically. | |
2292 5 | |
2293 6 There are currently only a few corrections. Add your own if you like. | |
2294 7 | |
2295 8 Mappings: | |
21825 | 2296 9 <Leader>a or <Plug>TypecorrAdd; |
7 | 2297 10 Add a correction for the word under the cursor. |
2298 11 | |
2299 12 Commands: | |
2300 13 :Correct {word} | |
2301 14 Add a correction for {word}. | |
2302 15 | |
26847 | 2303 16 *typecorrect-settings* |
7 | 2304 17 This plugin doesn't have any settings. |
2305 | |
2306 The first line is actually the only one for which the format matters. It will | |
2307 be extracted from the help file to be put in the "LOCAL ADDITIONS:" section of | |
2308 help.txt |local-additions|. The first "*" must be in the first column of the | |
2309 first line. After adding your help file do ":help" and check that the entries | |
2310 line up nicely. | |
2311 | |
2312 You can add more tags inside ** in your help file. But be careful not to use | |
2313 existing help tags. You would probably use the name of your plugin in most of | |
26847 | 2314 them, like "typecorrect-settings" in the example. |
7 | 2315 |
2316 Using references to other parts of the help in || is recommended. This makes | |
2317 it easy for the user to find associated help. | |
2318 | |
2319 | |
2320 FILETYPE DETECTION *plugin-filetype* | |
2321 | |
2322 If your filetype is not already detected by Vim, you should create a filetype | |
2323 detection snippet in a separate file. It is usually in the form of an | |
2324 autocommand that sets the filetype when the file name matches a pattern. | |
2325 Example: > | |
2326 | |
26847 | 2327 au BufNewFile,BufRead *.foo setlocal filetype=foofoo |
7 | 2328 |
2329 Write this single-line file as "ftdetect/foofoo.vim" in the first directory | |
2330 that appears in 'runtimepath'. For Unix that would be | |
2331 "~/.vim/ftdetect/foofoo.vim". The convention is to use the name of the | |
2332 filetype for the script name. | |
2333 | |
2334 You can make more complicated checks if you like, for example to inspect the | |
2335 contents of the file to recognize the language. Also see |new-filetype|. | |
2336 | |
2337 | |
2338 SUMMARY *plugin-special* | |
2339 | |
2340 Summary of special things to use in a plugin: | |
2341 | |
26847 | 2342 var name Variable local to the script. |
7 | 2343 |
2344 <SID> Script-ID, used for mappings and functions local to | |
2345 the script. | |
2346 | |
2347 hasmapto() Function to test if the user already defined a mapping | |
2348 for functionality the script offers. | |
2349 | |
2350 <Leader> Value of "mapleader", which the user defines as the | |
2351 keys that plugin mappings start with. | |
2352 | |
26847 | 2353 map <unique> Give a warning if a mapping already exists. |
2354 | |
2355 noremap <script> Use only mappings local to the script, not global | |
7 | 2356 mappings. |
2357 | |
2358 exists(":Cmd") Check if a user command already exists. | |
2359 | |
2360 ============================================================================== | |
161 | 2361 *41.12* Writing a filetype plugin *write-filetype-plugin* *ftplugin* |
7 | 2362 |
2363 A filetype plugin is like a global plugin, except that it sets options and | |
2364 defines mappings for the current buffer only. See |add-filetype-plugin| for | |
2365 how this type of plugin is used. | |
2366 | |
161 | 2367 First read the section on global plugins above |41.11|. All that is said there |
7 | 2368 also applies to filetype plugins. There are a few extras, which are explained |
2369 here. The essential thing is that a filetype plugin should only have an | |
2370 effect on the current buffer. | |
2371 | |
2372 | |
2373 DISABLING | |
2374 | |
2375 If you are writing a filetype plugin to be used by many people, they need a | |
2376 chance to disable loading it. Put this at the top of the plugin: > | |
2377 | |
26847 | 2378 # Only do this when not done yet for this buffer |
7 | 2379 if exists("b:did_ftplugin") |
2380 finish | |
2381 endif | |
26847 | 2382 b:did_ftplugin = 1 |
7 | 2383 |
2384 This also needs to be used to avoid that the same plugin is executed twice for | |
2385 the same buffer (happens when using an ":edit" command without arguments). | |
2386 | |
2387 Now users can disable loading the default plugin completely by making a | |
26847 | 2388 filetype plugin with only these lines: > |
2389 | |
2390 vim9script | |
2391 b:did_ftplugin = 1 | |
7 | 2392 |
2393 This does require that the filetype plugin directory comes before $VIMRUNTIME | |
2394 in 'runtimepath'! | |
2395 | |
2396 If you do want to use the default plugin, but overrule one of the settings, | |
2397 you can write the different setting in a script: > | |
2398 | |
2399 setlocal textwidth=70 | |
2400 | |
2401 Now write this in the "after" directory, so that it gets sourced after the | |
2402 distributed "vim.vim" ftplugin |after-directory|. For Unix this would be | |
2403 "~/.vim/after/ftplugin/vim.vim". Note that the default plugin will have set | |
2404 "b:did_ftplugin", but it is ignored here. | |
2405 | |
2406 | |
2407 OPTIONS | |
2408 | |
2409 To make sure the filetype plugin only affects the current buffer use the > | |
2410 | |
26847 | 2411 setlocal |
7 | 2412 |
2413 command to set options. And only set options which are local to a buffer (see | |
26847 | 2414 the help for the option to check that). When using `:setlocal` for global |
7 | 2415 options or options local to a window, the value will change for many buffers, |
2416 and that is not what a filetype plugin should do. | |
2417 | |
2418 When an option has a value that is a list of flags or items, consider using | |
2419 "+=" and "-=" to keep the existing value. Be aware that the user may have | |
2420 changed an option value already. First resetting to the default value and | |
2698
b6471224d2af
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2662
diff
changeset
|
2421 then changing it is often a good idea. Example: > |
7 | 2422 |
26847 | 2423 setlocal formatoptions& formatoptions+=ro |
7 | 2424 |
2425 | |
2426 MAPPINGS | |
2427 | |
2428 To make sure mappings will only work in the current buffer use the > | |
2429 | |
26847 | 2430 map <buffer> |
7 | 2431 |
2432 command. This needs to be combined with the two-step mapping explained above. | |
2433 An example of how to define functionality in a filetype plugin: > | |
2434 | |
21825 | 2435 if !hasmapto('<Plug>JavaImport;') |
2436 map <buffer> <unique> <LocalLeader>i <Plug>JavaImport; | |
7 | 2437 endif |
21825 | 2438 noremap <buffer> <unique> <Plug>JavaImport; oimport ""<Left><Esc> |
7 | 2439 |
2440 |hasmapto()| is used to check if the user has already defined a map to | |
21825 | 2441 <Plug>JavaImport;. If not, then the filetype plugin defines the default |
7 | 2442 mapping. This starts with |<LocalLeader>|, which allows the user to select |
2443 the key(s) he wants filetype plugin mappings to start with. The default is a | |
2444 backslash. | |
2445 "<unique>" is used to give an error message if the mapping already exists or | |
2446 overlaps with an existing mapping. | |
2447 |:noremap| is used to avoid that any other mappings that the user has defined | |
2448 interferes. You might want to use ":noremap <script>" to allow remapping | |
2449 mappings defined in this script that start with <SID>. | |
2450 | |
2451 The user must have a chance to disable the mappings in a filetype plugin, | |
2452 without disabling everything. Here is an example of how this is done for a | |
2453 plugin for the mail filetype: > | |
2454 | |
26847 | 2455 # Add mappings, unless the user didn't want this. |
2456 if !exists("g:no_plugin_maps") && !exists("g:no_mail_maps") | |
2457 # Quote text by inserting "> " | |
21825 | 2458 if !hasmapto('<Plug>MailQuote;') |
2459 vmap <buffer> <LocalLeader>q <Plug>MailQuote; | |
2460 nmap <buffer> <LocalLeader>q <Plug>MailQuote; | |
7 | 2461 endif |
21825 | 2462 vnoremap <buffer> <Plug>MailQuote; :s/^/> /<CR> |
2463 nnoremap <buffer> <Plug>MailQuote; :.,$s/^/> /<CR> | |
7 | 2464 endif |
2465 | |
2466 Two global variables are used: | |
26847 | 2467 |g:no_plugin_maps| disables mappings for all filetype plugins |
2468 |g:no_mail_maps| disables mappings for the "mail" filetype | |
7 | 2469 |
2470 | |
2471 USER COMMANDS | |
2472 | |
2473 To add a user command for a specific file type, so that it can only be used in | |
2474 one buffer, use the "-buffer" argument to |:command|. Example: > | |
2475 | |
26847 | 2476 command -buffer Make make %:r.s |
7 | 2477 |
2478 | |
2479 VARIABLES | |
2480 | |
2481 A filetype plugin will be sourced for each buffer of the type it's for. Local | |
26847 | 2482 script variables will be shared between all invocations. Use local buffer |
2483 variables |b:var| if you want a variable specifically for one buffer. | |
7 | 2484 |
2485 | |
2486 FUNCTIONS | |
2487 | |
2488 When defining a function, this only needs to be done once. But the filetype | |
2489 plugin will be sourced every time a file with this filetype will be opened. | |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2490 This construct makes sure the function is only defined once: > |
7 | 2491 |
26847 | 2492 if !exists("*Func") |
2493 def Func(arg) | |
2494 ... | |
2495 enddef | |
2496 endif | |
7 | 2497 < |
2498 | |
8061
abd64cf67bcf
commit https://github.com/vim/vim/commit/38a55639d603823efcf2d2fdf542dbffdeb60b75
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
2499 UNDO *undo_indent* *undo_ftplugin* |
7 | 2500 |
2501 When the user does ":setfiletype xyz" the effect of the previous filetype | |
2502 should be undone. Set the b:undo_ftplugin variable to the commands that will | |
2503 undo the settings in your filetype plugin. Example: > | |
2504 | |
26847 | 2505 b:undo_ftplugin = "setlocal fo< com< tw< commentstring<" |
22171 | 2506 \ .. "| unlet b:match_ignorecase b:match_words b:match_skip" |
7 | 2507 |
2508 Using ":setlocal" with "<" after the option name resets the option to its | |
2509 global value. That is mostly the best way to reset the option value. | |
2510 | |
2511 This does require removing the "C" flag from 'cpoptions' to allow line | |
2512 continuation, as mentioned above |use-cpo-save|. | |
2513 | |
8061
abd64cf67bcf
commit https://github.com/vim/vim/commit/38a55639d603823efcf2d2fdf542dbffdeb60b75
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
2514 For undoing the effect of an indent script, the b:undo_indent variable should |
abd64cf67bcf
commit https://github.com/vim/vim/commit/38a55639d603823efcf2d2fdf542dbffdeb60b75
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
2515 be set accordingly. |
abd64cf67bcf
commit https://github.com/vim/vim/commit/38a55639d603823efcf2d2fdf542dbffdeb60b75
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
2516 |
7 | 2517 |
2518 FILE NAME | |
2519 | |
2520 The filetype must be included in the file name |ftplugin-name|. Use one of | |
2521 these three forms: | |
2522 | |
2523 .../ftplugin/stuff.vim | |
2524 .../ftplugin/stuff_foo.vim | |
2525 .../ftplugin/stuff/bar.vim | |
2526 | |
2527 "stuff" is the filetype, "foo" and "bar" are arbitrary names. | |
2528 | |
2529 | |
2530 SUMMARY *ftplugin-special* | |
2531 | |
2532 Summary of special things to use in a filetype plugin: | |
2533 | |
2534 <LocalLeader> Value of "maplocalleader", which the user defines as | |
2535 the keys that filetype plugin mappings start with. | |
2536 | |
26847 | 2537 map <buffer> Define a mapping local to the buffer. |
2538 | |
2539 noremap <script> Only remap mappings defined in this script that start | |
7 | 2540 with <SID>. |
2541 | |
26847 | 2542 setlocal Set an option for the current buffer only. |
2543 | |
2544 command -buffer Define a user command local to the buffer. | |
7 | 2545 |
2546 exists("*s:Func") Check if a function was already defined. | |
2547 | |
2548 Also see |plugin-special|, the special things used for all plugins. | |
2549 | |
2550 ============================================================================== | |
161 | 2551 *41.13* Writing a compiler plugin *write-compiler-plugin* |
7 | 2552 |
2553 A compiler plugin sets options for use with a specific compiler. The user can | |
2554 load it with the |:compiler| command. The main use is to set the | |
2555 'errorformat' and 'makeprg' options. | |
2556 | |
2557 Easiest is to have a look at examples. This command will edit all the default | |
2558 compiler plugins: > | |
2559 | |
26847 | 2560 next $VIMRUNTIME/compiler/*.vim |
2561 | |
2562 Type `:next` to go to the next plugin file. | |
7 | 2563 |
2564 There are two special items about these files. First is a mechanism to allow | |
2565 a user to overrule or add to the default file. The default files start with: > | |
2566 | |
26847 | 2567 if exists("g:current_compiler") |
2568 finish | |
2569 endif | |
2570 g:current_compiler = "mine" | |
7 | 2571 |
2572 When you write a compiler file and put it in your personal runtime directory | |
2573 (e.g., ~/.vim/compiler for Unix), you set the "current_compiler" variable to | |
2574 make the default file skip the settings. | |
570 | 2575 *:CompilerSet* |
7 | 2576 The second mechanism is to use ":set" for ":compiler!" and ":setlocal" for |
2577 ":compiler". Vim defines the ":CompilerSet" user command for this. However, | |
2578 older Vim versions don't, thus your plugin should define it then. This is an | |
2579 example: > | |
2580 | |
2581 if exists(":CompilerSet") != 2 | |
2582 command -nargs=* CompilerSet setlocal <args> | |
2583 endif | |
2584 CompilerSet errorformat& " use the default 'errorformat' | |
2585 CompilerSet makeprg=nmake | |
2586 | |
2587 When you write a compiler plugin for the Vim distribution or for a system-wide | |
2588 runtime directory, use the mechanism mentioned above. When | |
2589 "current_compiler" was already set by a user plugin nothing will be done. | |
2590 | |
2591 When you write a compiler plugin to overrule settings from a default plugin, | |
2592 don't check "current_compiler". This plugin is supposed to be loaded | |
2593 last, thus it should be in a directory at the end of 'runtimepath'. For Unix | |
2594 that could be ~/.vim/after/compiler. | |
2595 | |
2596 ============================================================================== | |
170 | 2597 *41.14* Writing a plugin that loads quickly *write-plugin-quickload* |
2598 | |
2599 A plugin may grow and become quite long. The startup delay may become | |
1620 | 2600 noticeable, while you hardly ever use the plugin. Then it's time for a |
170 | 2601 quickload plugin. |
2602 | |
2603 The basic idea is that the plugin is loaded twice. The first time user | |
2604 commands and mappings are defined that offer the functionality. The second | |
2605 time the functions that implement the functionality are defined. | |
2606 | |
2607 It may sound surprising that quickload means loading a script twice. What we | |
2608 mean is that it loads quickly the first time, postponing the bulk of the | |
2609 script to the second time, which only happens when you actually use it. When | |
2610 you always use the functionality it actually gets slower! | |
2611 | |
26847 | 2612 This uses a FuncUndefined autocommand. Since Vim 7 there is an alternative: |
2613 use the |autoload| functionality |41.15|. That will also use |Vim9| script | |
2614 instead of legacy script that is used here. | |
793 | 2615 |
170 | 2616 The following example shows how it's done: > |
2617 | |
2618 " Vim global plugin for demonstrating quick loading | |
2619 " Last Change: 2005 Feb 25 | |
2620 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
2621 " License: This file is placed in the public domain. | |
2622 | |
2623 if !exists("s:did_load") | |
2624 command -nargs=* BNRead call BufNetRead(<f-args>) | |
2625 map <F19> :call BufNetWrite('something')<CR> | |
2626 | |
2627 let s:did_load = 1 | |
22171 | 2628 exe 'au FuncUndefined BufNet* source ' .. expand('<sfile>') |
170 | 2629 finish |
2630 endif | |
2631 | |
2632 function BufNetRead(...) | |
22171 | 2633 echo 'BufNetRead(' .. string(a:000) .. ')' |
170 | 2634 " read functionality here |
2635 endfunction | |
2636 | |
2637 function BufNetWrite(...) | |
22171 | 2638 echo 'BufNetWrite(' .. string(a:000) .. ')' |
170 | 2639 " write functionality here |
2640 endfunction | |
2641 | |
2642 When the script is first loaded "s:did_load" is not set. The commands between | |
2643 the "if" and "endif" will be executed. This ends in a |:finish| command, thus | |
2644 the rest of the script is not executed. | |
2645 | |
2646 The second time the script is loaded "s:did_load" exists and the commands | |
2647 after the "endif" are executed. This defines the (possible long) | |
2648 BufNetRead() and BufNetWrite() functions. | |
2649 | |
2650 If you drop this script in your plugin directory Vim will execute it on | |
2651 startup. This is the sequence of events that happens: | |
2652 | |
2653 1. The "BNRead" command is defined and the <F19> key is mapped when the script | |
2654 is sourced at startup. A |FuncUndefined| autocommand is defined. The | |
2655 ":finish" command causes the script to terminate early. | |
2656 | |
2657 2. The user types the BNRead command or presses the <F19> key. The | |
2658 BufNetRead() or BufNetWrite() function will be called. | |
856 | 2659 |
170 | 2660 3. Vim can't find the function and triggers the |FuncUndefined| autocommand |
2661 event. Since the pattern "BufNet*" matches the invoked function, the | |
2662 command "source fname" will be executed. "fname" will be equal to the name | |
2663 of the script, no matter where it is located, because it comes from | |
2664 expanding "<sfile>" (see |expand()|). | |
2665 | |
2666 4. The script is sourced again, the "s:did_load" variable exists and the | |
2667 functions are defined. | |
2668 | |
2669 Notice that the functions that are loaded afterwards match the pattern in the | |
2670 |FuncUndefined| autocommand. You must make sure that no other plugin defines | |
2671 functions that match this pattern. | |
2672 | |
2673 ============================================================================== | |
2674 *41.15* Writing library scripts *write-library-script* | |
2675 | |
2676 Some functionality will be required in several places. When this becomes more | |
2677 than a few lines you will want to put it in one script and use it from many | |
2678 scripts. We will call that one script a library script. | |
2679 | |
2680 Manually loading a library script is possible, so long as you avoid loading it | |
2681 when it's already done. You can do this with the |exists()| function. | |
2682 Example: > | |
2683 | |
2684 if !exists('*MyLibFunction') | |
2685 runtime library/mylibscript.vim | |
2686 endif | |
26847 | 2687 MyLibFunction(arg) |
170 | 2688 |
2689 Here you need to know that MyLibFunction() is defined in a script | |
2690 "library/mylibscript.vim" in one of the directories in 'runtimepath'. | |
2691 | |
2692 To make this a bit simpler Vim offers the autoload mechanism. Then the | |
2693 example looks like this: > | |
2694 | |
26847 | 2695 mylib#myfunction(arg) |
2696 | |
2697 That's a lot simpler, isn't it? Vim will recognize the function name by the | |
2698 embedded "#" character and when it's not defined search for the script | |
2699 "autoload/mylib.vim" in 'runtimepath'. That script must define the | |
2700 "mylib#myfunction()" function. | |
170 | 2701 |
2702 You can put many other functions in the mylib.vim script, you are free to | |
2703 organize your functions in library scripts. But you must use function names | |
323 | 2704 where the part before the '#' matches the script name. Otherwise Vim would |
2705 not know what script to load. | |
170 | 2706 |
681 | 2707 If you get really enthusiastic and write lots of library scripts, you may |
170 | 2708 want to use subdirectories. Example: > |
2709 | |
26847 | 2710 netlib#ftp#read('somefile') |
170 | 2711 |
2712 For Unix the library script used for this could be: | |
2713 | |
2714 ~/.vim/autoload/netlib/ftp.vim | |
2715 | |
2716 Where the function is defined like this: > | |
2717 | |
26847 | 2718 def netlib#ftp#read(fname: string) |
2719 # Read the file fname through ftp | |
2720 enddef | |
170 | 2721 |
2722 Notice that the name the function is defined with is exactly the same as the | |
323 | 2723 name used for calling the function. And the part before the last '#' |
170 | 2724 exactly matches the subdirectory and script name. |
2725 | |
2726 You can use the same mechanism for variables: > | |
2727 | |
26847 | 2728 var weekdays = dutch#weekdays |
170 | 2729 |
2730 This will load the script "autoload/dutch.vim", which should contain something | |
2731 like: > | |
2732 | |
26847 | 2733 var dutch#weekdays = ['zondag', 'maandag', 'dinsdag', 'woensdag', |
170 | 2734 \ 'donderdag', 'vrijdag', 'zaterdag'] |
2735 | |
2736 Further reading: |autoload|. | |
2737 | |
2738 ============================================================================== | |
793 | 2739 *41.16* Distributing Vim scripts *distribute-script* |
2740 | |
2741 Vim users will look for scripts on the Vim website: http://www.vim.org. | |
2742 If you made something that is useful for others, share it! | |
2743 | |
26847 | 2744 Another place is github. But there you need to know where to find it! The |
2745 advantage is that most plugin managers fetch plugins from github. You'll have | |
2746 to use your favorite search engine to find them. | |
2747 | |
2748 Vim scripts can be used on any system. However, there might not be a tar or | |
2749 gzip command. If you want to pack files together and/or compress them the | |
2750 "zip" utility is recommended. | |
793 | 2751 |
2752 For utmost portability use Vim itself to pack scripts together. This can be | |
2753 done with the Vimball utility. See |vimball|. | |
2754 | |
799 | 2755 It's good if you add a line to allow automatic updating. See |glvs-plugins|. |
2756 | |
793 | 2757 ============================================================================== |
7 | 2758 |
2759 Next chapter: |usr_42.txt| Add new menus | |
2760 | |
14519 | 2761 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: |