-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
usr_41.txt
2782 lines (2141 loc) · 95.7 KB
/
usr_41.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*usr_41.txt* For Vim version 8.2. Last change: 2021 Aug 08
VIM USER MANUAL - by Bram Moolenaar
Write a Vim script
The Vim script language is used for the startup vimrc file, syntax files, and
many other things. This chapter explains the items that can be used in a Vim
script. There are a lot of them, thus this is a long chapter.
|41.1| Introduction
|41.2| Variables
|41.3| Expressions
|41.4| Conditionals
|41.5| Executing an expression
|41.6| Using functions
|41.7| Defining a function
|41.8| Lists and Dictionaries
|41.9| Exceptions
|41.10| Various remarks
|41.11| Writing a plugin
|41.12| Writing a filetype plugin
|41.13| Writing a compiler plugin
|41.14| Writing a plugin that loads quickly
|41.15| Writing library scripts
|41.16| Distributing Vim scripts
Next chapter: |usr_42.txt| Add new menus
Previous chapter: |usr_40.txt| Make new commands
Table of contents: |usr_toc.txt|
==============================================================================
*41.1* Introduction *vim-script-intro* *script*
Your first experience with Vim scripts is the vimrc file. Vim reads it when
it starts up and executes the commands. You can set options to values you
prefer. And you can use any colon command in it (commands that start with a
":"; these are sometimes referred to as Ex commands or command-line commands).
Syntax files are also Vim scripts. As are files that set options for a
specific file type. A complicated macro can be defined by a separate Vim
script file. You can think of other uses yourself.
If you are familiar with Python, you can find a comparison between
Python and Vim script here, with pointers to other documents:
https://gist.github.com/yegappan/16d964a37ead0979b05e655aa036cad0
And if you are familiar with JavaScript:
https://w0rp.com/blog/post/vim-script-for-the-javascripter/
Let's start with a simple example: >
:let i = 1
:while i < 5
: echo "count is" i
: let i += 1
:endwhile
<
Note:
The ":" characters are not really needed here. You only need to use
them when you type a command. In a Vim script file they can be left
out. We will use them here anyway to make clear these are colon
commands and make them stand out from Normal mode commands.
Note:
You can try out the examples by yanking the lines from the text here
and executing them with :@"
The output of the example code is:
count is 1 ~
count is 2 ~
count is 3 ~
count is 4 ~
In the first line the ":let" command assigns a value to a variable. The
generic form is: >
:let {variable} = {expression}
In this case the variable name is "i" and the expression is a simple value,
the number one.
The ":while" command starts a loop. The generic form is: >
:while {condition}
: {statements}
:endwhile
The statements until the matching ":endwhile" are executed for as long as the
condition is true. The condition used here is the expression "i < 5". This
is true when the variable i is smaller than five.
Note:
If you happen to write a while loop that keeps on running, you can
interrupt it by pressing CTRL-C (CTRL-Break on MS-Windows).
The ":echo" command prints its arguments. In this case the string "count is"
and the value of the variable i. Since i is one, this will print:
count is 1 ~
Then there is the ":let i += 1" command. This does the same thing as
":let i = i + 1". This adds one to the variable i and assigns the new value
to the same variable.
Note: this is how it works in legacy Vim script, which is what we discuss in
this file. In Vim9 script it's a bit different, see |usr_46.txt|.
The example was given to explain the commands, but would you really want to
make such a loop, it can be written much more compact: >
:for i in range(1, 4)
: echo "count is" i
:endfor
We won't explain how |:for| and |range()| work until later. Follow the links
if you are impatient.
FOUR KINDS OF NUMBERS
Numbers can be decimal, hexadecimal, octal or binary.
A hexadecimal number starts with "0x" or "0X". For example "0x1f" is decimal
31.
An octal number starts with "0o", "0O" or a zero and another digit. "0o17" is
decimal 15. Using just a zero prefix is not supported in Vim9 script.
A binary number starts with "0b" or "0B". For example "0b101" is decimal 5.
A decimal number is just digits. Careful: don't put a zero before a decimal
number, it will be interpreted as an octal number in legacy script!
The ":echo" command always prints decimal numbers. Example: >
:echo 0x7f 0o36
< 127 30 ~
A number is made negative with a minus sign. This also works for hexadecimal,
octal and binary numbers. A minus sign is also used for subtraction. Compare
this with the previous example: >
:echo 0x7f -0o36
< 97 ~
White space in an expression is ignored. However, it's recommended to use it
for separating items, to make the expression easier to read. For example, to
avoid the confusion with a negative number above, put a space between the
minus sign and the following number: >
:echo 0x7f - 0o36
==============================================================================
*41.2* Variables
A variable name consists of ASCII letters, digits and the underscore. It
cannot start with a digit. Valid variable names are:
counter
_aap3
very_long_variable_name_with_underscores
FuncLength
LENGTH
Invalid names are "foo+bar" and "6var".
These variables are global. To see a list of currently defined variables
use this command: >
:let
You can use global variables everywhere. This also means that when the
variable "count" is used in one script file, it might also be used in another
file. This leads to confusion at least, and real problems at worst. To avoid
this, you can use a variable local to a script file by prepending "s:". For
example, one script contains this code: >
:let s:count = 1
:while s:count < 5
: source other.vim
: let s:count += 1
:endwhile
Since "s:count" is local to this script, you can be sure that sourcing the
"other.vim" script will not change this variable. If "other.vim" also uses an
"s:count" variable, it will be a different copy, local to that script. More
about script-local variables here: |script-variable|.
There are more kinds of variables, see |internal-variables|. The most often
used ones are:
b:name variable local to a buffer
w:name variable local to a window
g:name global variable (also in a function)
v:name variable predefined by Vim
DELETING VARIABLES
Variables take up memory and show up in the output of the ":let" command. To
delete a variable use the ":unlet" command. Example: >
:unlet s:count
This deletes the script-local variable "s:count" to free up the memory it
uses. If you are not sure if the variable exists, and don't want an error
message when it doesn't, append !: >
:unlet! s:count
When a script finishes, the local variables used there will not be
automatically freed. The next time the script executes, it can still use the
old value. Example: >
:if !exists("s:call_count")
: let s:call_count = 0
:endif
:let s:call_count = s:call_count + 1
:echo "called" s:call_count "times"
The "exists()" function checks if a variable has already been defined. Its
argument is the name of the variable you want to check. Not the variable
itself! If you would do this: >
:if !exists(s:call_count)
Then the value of s:call_count will be used as the name of the variable that
exists() checks. That's not what you want.
The exclamation mark ! negates a value. When the value was true, it
becomes false. When it was false, it becomes true. You can read it as "not".
Thus "if !exists()" can be read as "if not exists()".
What Vim calls true is anything that is not zero. Zero is false.
Note:
Vim automatically converts a string to a number when it is looking for
a number. When using a string that doesn't start with a digit the
resulting number is zero. Thus look out for this: >
:if "true"
< The "true" will be interpreted as a zero, thus as false!
STRING VARIABLES AND CONSTANTS
So far only numbers were used for the variable value. Strings can be used as
well. Numbers and strings are the basic types of variables that Vim supports.
The type is dynamic, it is set each time when assigning a value to the
variable with ":let". More about types in |41.8|.
To assign a string value to a variable, you need to use a string constant.
There are two types of these. First the string in double quotes: >
:let name = "peter"
:echo name
< peter ~
If you want to include a double quote inside the string, put a backslash in
front of it: >
:let name = "\"peter\""
:echo name
< "peter" ~
To avoid the need for a backslash, you can use a string in single quotes: >
:let name = '"peter"'
:echo name
< "peter" ~
Inside a single-quote string all the characters are as they are. Only the
single quote itself is special: you need to use two to get one. A backslash
is taken literally, thus you can't use it to change the meaning of the
character after it.
In double-quote strings it is possible to use special characters. Here are
a few useful ones:
\t <Tab>
\n <NL>, line break
\r <CR>, <Enter>
\e <Esc>
\b <BS>, backspace
\" "
\\ \, backslash
\<Esc> <Esc>
\<C-W> CTRL-W
The last two are just examples. The "\<name>" form can be used to include
the special key "name".
See |expr-quote| for the full list of special items in a string.
==============================================================================
*41.3* Expressions
Vim has a rich, yet simple way to handle expressions. You can read the
definition here: |expression-syntax|. Here we will show the most common
items.
The numbers, strings and variables mentioned above are expressions by
themselves. Thus everywhere an expression is expected, you can use a number,
string or variable. Other basic items in an expression are:
$NAME environment variable
&name option
@r register
Examples: >
:echo "The value of 'tabstop' is" &ts
:echo "Your home directory is" $HOME
:if @a > 5
The &name form can be used to save an option value, set it to a new value,
do something and restore the old value. Example: >
:let save_ic = &ic
:set noic
:/The Start/,$delete
:let &ic = save_ic
This makes sure the "The Start" pattern is used with the 'ignorecase' option
off. Still, it keeps the value that the user had set. (Another way to do
this would be to add "\C" to the pattern, see |/\C|.)
MATHEMATICS
It becomes more interesting if we combine these basic items. Let's start with
mathematics on numbers:
a + b add
a - b subtract
a * b multiply
a / b divide
a % b modulo
The usual precedence is used. Example: >
:echo 10 + 5 * 2
< 20 ~
Grouping is done with parentheses. No surprises here. Example: >
:echo (10 + 5) * 2
< 30 ~
Strings can be concatenated with ".." (see |expr6|). Example: >
:echo "foo" .. "bar"
< foobar ~
When the ":echo" command gets multiple arguments, it separates them with a
space. In the example the argument is a single expression, thus no space is
inserted.
Borrowed from the C language is the conditional expression:
a ? b : c
If "a" evaluates to true "b" is used, otherwise "c" is used. Example: >
:let i = 4
:echo i > 5 ? "i is big" : "i is small"
< i is small ~
The three parts of the constructs are always evaluated first, thus you could
see it work as:
(a) ? (b) : (c)
==============================================================================
*41.4* Conditionals
The ":if" commands executes the following statements, until the matching
":endif", only when a condition is met. The generic form is:
:if {condition}
{statements}
:endif
Only when the expression {condition} evaluates to true (non-zero) will the
{statements} be executed. These must still be valid commands. If they
contain garbage, Vim won't be able to find the ":endif".
You can also use ":else". The generic form for this is:
:if {condition}
{statements}
:else
{statements}
:endif
The second {statements} is only executed if the first one isn't.
Finally, there is ":elseif":
:if {condition}
{statements}
:elseif {condition}
{statements}
:endif
This works just like using ":else" and then "if", but without the need for an
extra ":endif".
A useful example for your vimrc file is checking the 'term' option and
doing something depending upon its value: >
:if &term == "xterm"
: " Do stuff for xterm
:elseif &term == "vt100"
: " Do stuff for a vt100 terminal
:else
: " Do something for other terminals
:endif
LOGIC OPERATIONS
We already used some of them in the examples. These are the most often used
ones:
a == b equal to
a != b not equal to
a > b greater than
a >= b greater than or equal to
a < b less than
a <= b less than or equal to
The result is one if the condition is met and zero otherwise. An example: >
:if v:version >= 700
: echo "congratulations"
:else
: echo "you are using an old version, upgrade!"
:endif
Here "v:version" is a variable defined by Vim, which has the value of the Vim
version. 600 is for version 6.0. Version 6.1 has the value 601. This is
very useful to write a script that works with multiple versions of Vim.
|v:version|
The logic operators work both for numbers and strings. When comparing two
strings, the mathematical difference is used. This compares byte values,
which may not be right for some languages.
When comparing a string with a number, the string is first converted to a
number. This is a bit tricky, because when a string doesn't look like a
number, the number zero is used. Example: >
:if 0 == "one"
: echo "yes"
:endif
This will echo "yes", because "one" doesn't look like a number, thus it is
converted to the number zero.
For strings there are two more items:
a =~ b matches with
a !~ b does not match with
The left item "a" is used as a string. The right item "b" is used as a
pattern, like what's used for searching. Example: >
:if str =~ " "
: echo "str contains a space"
:endif
:if str !~ '\.$'
: echo "str does not end in a full stop"
:endif
Notice the use of a single-quote string for the pattern. This is useful,
because backslashes would need to be doubled in a double-quote string and
patterns tend to contain many backslashes.
The 'ignorecase' option is used when comparing strings. When you don't want
that, append "#" to match case and "?" to ignore case. Thus "==?" compares
two strings to be equal while ignoring case. And "!~#" checks if a pattern
doesn't match, also checking the case of letters. For the full table see
|expr-==|.
MORE LOOPING
The ":while" command was already mentioned. Two more statements can be used
in between the ":while" and the ":endwhile":
:continue Jump back to the start of the while loop; the
loop continues.
:break Jump forward to the ":endwhile"; the loop is
discontinued.
Example: >
:while counter < 40
: call do_something()
: if skip_flag
: continue
: endif
: if finished_flag
: break
: endif
: sleep 50m
:endwhile
The ":sleep" command makes Vim take a nap. The "50m" specifies fifty
milliseconds. Another example is ":sleep 4", which sleeps for four seconds.
Even more looping can be done with the ":for" command, see below in |41.8|.
==============================================================================
*41.5* Executing an expression
So far the commands in the script were executed by Vim directly. The
":execute" command allows executing the result of an expression. This is a
very powerful way to build commands and execute them.
An example is to jump to a tag, which is contained in a variable: >
:execute "tag " .. tag_name
The ".." is used to concatenate the string "tag " with the value of variable
"tag_name". Suppose "tag_name" has the value "get_cmd", then the command that
will be executed is: >
:tag get_cmd
The ":execute" command can only execute colon commands. The ":normal" command
executes Normal mode commands. However, its argument is not an expression but
the literal command characters. Example: >
:normal gg=G
This jumps to the first line and formats all lines with the "=" operator.
To make ":normal" work with an expression, combine ":execute" with it.
Example: >
:execute "normal " .. normal_commands
The variable "normal_commands" must contain the Normal mode commands.
Make sure that the argument for ":normal" is a complete command. Otherwise
Vim will run into the end of the argument and abort the command. For example,
if you start Insert mode, you must leave Insert mode as well. This works: >
:execute "normal Inew text \<Esc>"
This inserts "new text " in the current line. Notice the use of the special
key "\<Esc>". This avoids having to enter a real <Esc> character in your
script.
If you don't want to execute a string but evaluate it to get its expression
value, you can use the eval() function: >
:let optname = "path"
:let optval = eval('&' .. optname)
A "&" character is prepended to "path", thus the argument to eval() is
"&path". The result will then be the value of the 'path' option.
The same thing can be done with: >
:exe 'let optval = &' .. optname
==============================================================================
*41.6* Using functions
Vim defines many functions and provides a large amount of functionality that
way. A few examples will be given in this section. You can find the whole
list here: |functions|.
A function is called with the ":call" command. The parameters are passed in
between parentheses separated by commas. Example: >
:call search("Date: ", "W")
This calls the search() function, with arguments "Date: " and "W". The
search() function uses its first argument as a search pattern and the second
one as flags. The "W" flag means the search doesn't wrap around the end of
the file.
A function can be called in an expression. Example: >
:let line = getline(".")
:let repl = substitute(line, '\a', "*", "g")
:call setline(".", repl)
The getline() function obtains a line from the current buffer. Its argument
is a specification of the line number. In this case "." is used, which means
the line where the cursor is.
The substitute() function does something similar to the ":substitute"
command. The first argument is the string on which to perform the
substitution. The second argument is the pattern, the third the replacement
string. Finally, the last arguments are the flags.
The setline() function sets the line, specified by the first argument, to a
new string, the second argument. In this example the line under the cursor is
replaced with the result of the substitute(). Thus the effect of the three
statements is equal to: >
:substitute/\a/*/g
Using the functions becomes more interesting when you do more work before and
after the substitute() call.
FUNCTIONS *function-list*
There are many functions. We will mention them here, grouped by what they are
used for. You can find an alphabetical list here: |functions|. Use CTRL-] on
the function name to jump to detailed help on it.
String manipulation: *string-functions*
nr2char() get a character by its number value
list2str() get a character string from a list of numbers
char2nr() get number value of a character
str2list() get list of numbers from a string
str2nr() convert a string to a Number
str2float() convert a string to a Float
printf() format a string according to % items
escape() escape characters in a string with a '\'
shellescape() escape a string for use with a shell command
fnameescape() escape a file name for use with a Vim command
tr() translate characters from one set to another
strtrans() translate a string to make it printable
tolower() turn a string to lowercase
toupper() turn a string to uppercase
charclass() class of a character
match() position where a pattern matches in a string
matchend() position where a pattern match ends in a string
matchfuzzy() fuzzy matches a string in a list of strings
matchfuzzypos() fuzzy matches a string in a list of strings
matchstr() match of a pattern in a string
matchstrpos() match and positions of a pattern in a string
matchlist() like matchstr() and also return submatches
stridx() first index of a short string in a long string
strridx() last index of a short string in a long string
strlen() length of a string in bytes
strcharlen() length of a string in characters
strchars() number of characters in a string
strwidth() size of string when displayed
strdisplaywidth() size of string when displayed, deals with tabs
setcellwidths() set character cell width overrides
substitute() substitute a pattern match with a string
submatch() get a specific match in ":s" and substitute()
strpart() get part of a string using byte index
strcharpart() get part of a string using char index
slice() take a slice of a string, using char index in
Vim9 script
strgetchar() get character from a string using char index
expand() expand special keywords
expandcmd() expand a command like done for `:edit`
iconv() convert text from one encoding to another
byteidx() byte index of a character in a string
byteidxcomp() like byteidx() but count composing characters
charidx() character index of a byte in a string
repeat() repeat a string multiple times
eval() evaluate a string expression
execute() execute an Ex command and get the output
win_execute() like execute() but in a specified window
trim() trim characters from a string
gettext() lookup message translation
List manipulation: *list-functions*
get() get an item without error for wrong index
len() number of items in a List
empty() check if List is empty
insert() insert an item somewhere in a List
add() append an item to a List
extend() append a List to a List
extendnew() make a new List and append items
remove() remove one or more items from a List
copy() make a shallow copy of a List
deepcopy() make a full copy of a List
filter() remove selected items from a List
map() change each List item
mapnew() make a new List with changed items
reduce() reduce a List to a value
slice() take a slice of a List
sort() sort a List
reverse() reverse the order of a List
uniq() remove copies of repeated adjacent items
split() split a String into a List
join() join List items into a String
range() return a List with a sequence of numbers
string() String representation of a List
call() call a function with List as arguments
index() index of a value in a List
max() maximum value in a List
min() minimum value in a List
count() count number of times a value appears in a List
repeat() repeat a List multiple times
flatten() flatten a List
flattennew() flatten a copy of a List
Dictionary manipulation: *dict-functions*
get() get an entry without an error for a wrong key
len() number of entries in a Dictionary
has_key() check whether a key appears in a Dictionary
empty() check if Dictionary is empty
remove() remove an entry from a Dictionary
extend() add entries from one Dictionary to another
extendnew() make a new Dictionary and append items
filter() remove selected entries from a Dictionary
map() change each Dictionary entry
mapnew() make a new Dictionary with changed items
keys() get List of Dictionary keys
values() get List of Dictionary values
items() get List of Dictionary key-value pairs
copy() make a shallow copy of a Dictionary
deepcopy() make a full copy of a Dictionary
string() String representation of a Dictionary
max() maximum value in a Dictionary
min() minimum value in a Dictionary
count() count number of times a value appears
Floating point computation: *float-functions*
float2nr() convert Float to Number
abs() absolute value (also works for Number)
round() round off
ceil() round up
floor() round down
trunc() remove value after decimal point
fmod() remainder of division
exp() exponential
log() natural logarithm (logarithm to base e)
log10() logarithm to base 10
pow() value of x to the exponent y
sqrt() square root
sin() sine
cos() cosine
tan() tangent
asin() arc sine
acos() arc cosine
atan() arc tangent
atan2() arc tangent
sinh() hyperbolic sine
cosh() hyperbolic cosine
tanh() hyperbolic tangent
isinf() check for infinity
isnan() check for not a number
Other computation: *bitwise-function*
and() bitwise AND
invert() bitwise invert
or() bitwise OR
xor() bitwise XOR
sha256() SHA-256 hash
rand() get a pseudo-random number
srand() initialize seed used by rand()
Variables: *var-functions*
type() type of a variable as a number
typename() type of a variable as text
islocked() check if a variable is locked
funcref() get a Funcref for a function reference
function() get a Funcref for a function name
getbufvar() get a variable value from a specific buffer
setbufvar() set a variable in a specific buffer
getwinvar() get a variable from specific window
gettabvar() get a variable from specific tab page
gettabwinvar() get a variable from specific window & tab page
setwinvar() set a variable in a specific window
settabvar() set a variable in a specific tab page
settabwinvar() set a variable in a specific window & tab page
garbagecollect() possibly free memory
Cursor and mark position: *cursor-functions* *mark-functions*
col() column number of the cursor or a mark
virtcol() screen column of the cursor or a mark
line() line number of the cursor or mark
wincol() window column number of the cursor
winline() window line number of the cursor
cursor() position the cursor at a line/column
screencol() get screen column of the cursor
screenrow() get screen row of the cursor
screenpos() screen row and col of a text character
getcurpos() get position of the cursor
getpos() get position of cursor, mark, etc.
setpos() set position of cursor, mark, etc.
getmarklist() list of global/local marks
byte2line() get line number at a specific byte count
line2byte() byte count at a specific line
diff_filler() get the number of filler lines above a line
screenattr() get attribute at a screen line/row
screenchar() get character code at a screen line/row
screenchars() get character codes at a screen line/row
screenstring() get string of characters at a screen line/row
charcol() character number of the cursor or a mark
getcharpos() get character position of cursor, mark, etc.
setcharpos() set character position of cursor, mark, etc.
getcursorcharpos() get character position of the cursor
setcursorcharpos() set character position of the cursor
Working with text in the current buffer: *text-functions*
getline() get a line or list of lines from the buffer
setline() replace a line in the buffer
append() append line or list of lines in the buffer
indent() indent of a specific line
cindent() indent according to C indenting
lispindent() indent according to Lisp indenting
nextnonblank() find next non-blank line
prevnonblank() find previous non-blank line
search() find a match for a pattern
searchpos() find a match for a pattern
searchcount() get number of matches before/after the cursor
searchpair() find the other end of a start/skip/end
searchpairpos() find the other end of a start/skip/end
searchdecl() search for the declaration of a name
getcharsearch() return character search information
setcharsearch() set character search information
Working with text in another buffer:
getbufline() get a list of lines from the specified buffer
setbufline() replace a line in the specified buffer
appendbufline() append a list of lines in the specified buffer
deletebufline() delete lines from a specified buffer
*system-functions* *file-functions*
System functions and manipulation of files:
glob() expand wildcards
globpath() expand wildcards in a number of directories
glob2regpat() convert a glob pattern into a search pattern
findfile() find a file in a list of directories
finddir() find a directory in a list of directories
resolve() find out where a shortcut points to
fnamemodify() modify a file name
pathshorten() shorten directory names in a path
simplify() simplify a path without changing its meaning
executable() check if an executable program exists
exepath() full path of an executable program
filereadable() check if a file can be read
filewritable() check if a file can be written to
getfperm() get the permissions of a file
setfperm() set the permissions of a file
getftype() get the kind of a file
isdirectory() check if a directory exists
getfsize() get the size of a file
getcwd() get the current working directory
haslocaldir() check if current window used |:lcd| or |:tcd|
tempname() get the name of a temporary file
mkdir() create a new directory
chdir() change current working directory
delete() delete a file
rename() rename a file
system() get the result of a shell command as a string
systemlist() get the result of a shell command as a list
environ() get all environment variables
getenv() get one environment variable
setenv() set an environment variable
hostname() name of the system
readfile() read a file into a List of lines
readblob() read a file into a Blob
readdir() get a List of file names in a directory
readdirex() get a List of file information in a directory
writefile() write a List of lines or Blob into a file
Date and Time: *date-functions* *time-functions*
getftime() get last modification time of a file
localtime() get current time in seconds
strftime() convert time to a string
strptime() convert a date/time string to time
reltime() get the current or elapsed time accurately
reltimestr() convert reltime() result to a string
reltimefloat() convert reltime() result to a Float
*buffer-functions* *window-functions* *arg-functions*
Buffers, windows and the argument list:
argc() number of entries in the argument list
argidx() current position in the argument list
arglistid() get id of the argument list
argv() get one entry from the argument list
bufadd() add a file to the list of buffers
bufexists() check if a buffer exists
buflisted() check if a buffer exists and is listed
bufload() ensure a buffer is loaded
bufloaded() check if a buffer exists and is loaded
bufname() get the name of a specific buffer
bufnr() get the buffer number of a specific buffer
tabpagebuflist() return List of buffers in a tab page
tabpagenr() get the number of a tab page
tabpagewinnr() like winnr() for a specified tab page
winnr() get the window number for the current window
bufwinid() get the window ID of a specific buffer
bufwinnr() get the window number of a specific buffer
winbufnr() get the buffer number of a specific window
listener_add() add a callback to listen to changes
listener_flush() invoke listener callbacks
listener_remove() remove a listener callback
win_findbuf() find windows containing a buffer
win_getid() get window ID of a window
win_gettype() get type of window
win_gotoid() go to window with ID
win_id2tabwin() get tab and window nr from window ID
win_id2win() get window nr from window ID
win_splitmove() move window to a split of another window
getbufinfo() get a list with buffer information
gettabinfo() get a list with tab page information
getwininfo() get a list with window information
getchangelist() get a list of change list entries
getjumplist() get a list of jump list entries
swapinfo() information about a swap file
swapname() get the swap file path of a buffer
Command line: *command-line-functions*
getcmdline() get the current command line
getcmdpos() get position of the cursor in the command line
setcmdpos() set position of the cursor in the command line
getcmdtype() return the current command-line type
getcmdwintype() return the current command-line window type
getcompletion() list of command-line completion matches
fullcommand() get full command name
Quickfix and location lists: *quickfix-functions*
getqflist() list of quickfix errors
setqflist() modify a quickfix list
getloclist() list of location list items
setloclist() modify a location list
Insert mode completion: *completion-functions*
complete() set found matches
complete_add() add to found matches
complete_check() check if completion should be aborted
complete_info() get current completion information
pumvisible() check if the popup menu is displayed
pum_getpos() position and size of popup menu if visible
Folding: *folding-functions*
foldclosed() check for a closed fold at a specific line
foldclosedend() like foldclosed() but return the last line
foldlevel() check for the fold level at a specific line
foldtext() generate the line displayed for a closed fold
foldtextresult() get the text displayed for a closed fold
Syntax and highlighting: *syntax-functions* *highlighting-functions*
clearmatches() clear all matches defined by |matchadd()| and
the |:match| commands
getmatches() get all matches defined by |matchadd()| and
the |:match| commands
hlexists() check if a highlight group exists
hlID() get ID of a highlight group
synID() get syntax ID at a specific position
synIDattr() get a specific attribute of a syntax ID
synIDtrans() get translated syntax ID
synstack() get list of syntax IDs at a specific position
synconcealed() get info about concealing
diff_hlID() get highlight ID for diff mode at a position
matchadd() define a pattern to highlight (a "match")
matchaddpos() define a list of positions to highlight
matcharg() get info about |:match| arguments
matchdelete() delete a match defined by |matchadd()| or a
|:match| command
setmatches() restore a list of matches saved by
|getmatches()|
Spelling: *spell-functions*
spellbadword() locate badly spelled word at or after cursor
spellsuggest() return suggested spelling corrections
soundfold() return the sound-a-like equivalent of a word
History: *history-functions*
histadd() add an item to a history
histdel() delete an item from a history
histget() get an item from a history
histnr() get highest index of a history list
Interactive: *interactive-functions*
browse() put up a file requester
browsedir() put up a directory requester
confirm() let the user make a choice
getchar() get a character from the user
getcharstr() get a character from the user as a string
getcharmod() get modifiers for the last typed character
getmousepos() get last known mouse position
echoraw() output characters as-is
feedkeys() put characters in the typeahead queue
input() get a line from the user
inputlist() let the user pick an entry from a list
inputsecret() get a line from the user without showing it
inputdialog() get a line from the user in a dialog
inputsave() save and clear typeahead
inputrestore() restore typeahead
GUI: *gui-functions*
getfontname() get name of current font being used
getwinpos() position of the Vim window
getwinposx() X position of the Vim window
getwinposy() Y position of the Vim window
balloon_show() set the balloon content
balloon_split() split a message for a balloon
balloon_gettext() get the text in the balloon
Vim server: *server-functions*
serverlist() return the list of server names
remote_startserver() run a server
remote_send() send command characters to a Vim server
remote_expr() evaluate an expression in a Vim server
server2client() send a reply to a client of a Vim server
remote_peek() check if there is a reply from a Vim server
remote_read() read a reply from a Vim server
foreground() move the Vim window to the foreground
remote_foreground() move the Vim server window to the foreground
Window size and position: *window-size-functions*
winheight() get height of a specific window
winwidth() get width of a specific window
win_screenpos() get screen position of a window
winlayout() get layout of windows in a tab page
winrestcmd() return command to restore window sizes
winsaveview() get view of current window
winrestview() restore saved view of current window
Mappings and Menus: *mapping-functions*
digraph_get() get |digraph|
digraph_getlist() get all |digraph|s
digraph_set() register |digraph|
digraph_setlist() register multiple |digraph|s