-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
vimfn.lua
10978 lines (10506 loc) · 400 KB
/
vimfn.lua
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
--- @meta _
-- THIS FILE IS GENERATED
-- DO NOT EDIT
error('Cannot require a meta file')
--- Return the absolute value of {expr}. When {expr} evaluates to
--- a |Float| abs() returns a |Float|. When {expr} can be
--- converted to a |Number| abs() returns a |Number|. Otherwise
--- abs() gives an error message and returns -1.
--- Examples: >vim
--- echo abs(1.456)
--- < 1.456 >vim
--- echo abs(-5.456)
--- < 5.456 >vim
--- echo abs(-4)
--- < 4
---
--- @param expr any
--- @return number
function vim.fn.abs(expr) end
--- Return the arc cosine of {expr} measured in radians, as a
--- |Float| in the range of [0, pi].
--- {expr} must evaluate to a |Float| or a |Number| in the range
--- [-1, 1].
--- Returns NaN if {expr} is outside the range [-1, 1]. Returns
--- 0.0 if {expr} is not a |Float| or a |Number|.
--- Examples: >vim
--- echo acos(0)
--- < 1.570796 >vim
--- echo acos(-0.5)
--- < 2.094395
---
--- @param expr any
--- @return number
function vim.fn.acos(expr) end
--- Append the item {expr} to |List| or |Blob| {object}. Returns
--- the resulting |List| or |Blob|. Examples: >vim
--- let alist = add([1, 2, 3], item)
--- call add(mylist, "woodstock")
--- <Note that when {expr} is a |List| it is appended as a single
--- item. Use |extend()| to concatenate |Lists|.
--- When {object} is a |Blob| then {expr} must be a number.
--- Use |insert()| to add an item at another position.
--- Returns 1 if {object} is not a |List| or a |Blob|.
---
--- @param object any
--- @param expr any
--- @return any
function vim.fn.add(object, expr) end
--- Bitwise AND on the two arguments. The arguments are converted
--- to a number. A List, Dict or Float argument causes an error.
--- Also see `or()` and `xor()`.
--- Example: >vim
--- let flag = and(bits, 0x80)
--- <
---
--- @param expr any
--- @param expr1 any
--- @return integer
vim.fn['and'] = function(expr, expr1) end
--- Returns Dictionary of |api-metadata|.
---
--- View it in a nice human-readable format: >vim
--- lua vim.print(vim.fn.api_info())
--- <
---
--- @return table
function vim.fn.api_info() end
--- When {text} is a |List|: Append each item of the |List| as a
--- text line below line {lnum} in the current buffer.
--- Otherwise append {text} as one text line below line {lnum} in
--- the current buffer.
--- Any type of item is accepted and converted to a String.
--- {lnum} can be zero to insert a line before the first one.
--- {lnum} is used like with |getline()|.
--- Returns 1 for failure ({lnum} out of range or out of memory),
--- 0 for success. When {text} is an empty list zero is returned,
--- no matter the value of {lnum}. Example: >vim
--- let failed = append(line('$'), "# THE END")
--- let failed = append(0, ["Chapter 1", "the beginning"])
--- <
---
--- @param lnum integer
--- @param text any
--- @return 0|1
function vim.fn.append(lnum, text) end
--- Like |append()| but append the text in buffer {expr}.
---
--- This function works only for loaded buffers. First call
--- |bufload()| if needed.
---
--- For the use of {buf}, see |bufname()|.
---
--- {lnum} is the line number to append below. Note that using
--- |line()| would use the current buffer, not the one appending
--- to. Use "$" to append at the end of the buffer. Other string
--- values are not supported.
---
--- On success 0 is returned, on failure 1 is returned.
---
--- If {buf} is not a valid buffer or {lnum} is not valid, an
--- error message is given. Example: >vim
--- let failed = appendbufline(13, 0, "# THE START")
--- <However, when {text} is an empty list then no error is given
--- for an invalid {lnum}, since {lnum} isn't actually used.
---
--- @param buf any
--- @param lnum integer
--- @param text string
--- @return 0|1
function vim.fn.appendbufline(buf, lnum, text) end
--- The result is the number of files in the argument list. See
--- |arglist|.
--- If {winid} is not supplied, the argument list of the current
--- window is used.
--- If {winid} is -1, the global argument list is used.
--- Otherwise {winid} specifies the window of which the argument
--- list is used: either the window number or the window ID.
--- Returns -1 if the {winid} argument is invalid.
---
--- @param winid? integer
--- @return integer
function vim.fn.argc(winid) end
--- The result is the current index in the argument list. 0 is
--- the first file. argc() - 1 is the last one. See |arglist|.
---
--- @return integer
function vim.fn.argidx() end
--- Return the argument list ID. This is a number which
--- identifies the argument list being used. Zero is used for the
--- global argument list. See |arglist|.
--- Returns -1 if the arguments are invalid.
---
--- Without arguments use the current window.
--- With {winnr} only use this window in the current tab page.
--- With {winnr} and {tabnr} use the window in the specified tab
--- page.
--- {winnr} can be the window number or the |window-ID|.
---
--- @param winnr? integer
--- @param tabnr? integer
--- @return integer
function vim.fn.arglistid(winnr, tabnr) end
--- The result is the {nr}th file in the argument list. See
--- |arglist|. "argv(0)" is the first one. Example: >vim
--- let i = 0
--- while i < argc()
--- let f = escape(fnameescape(argv(i)), '.')
--- exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
--- let i = i + 1
--- endwhile
--- <Without the {nr} argument, or when {nr} is -1, a |List| with
--- the whole |arglist| is returned.
---
--- The {winid} argument specifies the window ID, see |argc()|.
--- For the Vim command line arguments see |v:argv|.
---
--- Returns an empty string if {nr}th argument is not present in
--- the argument list. Returns an empty List if the {winid}
--- argument is invalid.
---
--- @param nr? integer
--- @param winid? integer
--- @return string|string[]
function vim.fn.argv(nr, winid) end
--- Return the arc sine of {expr} measured in radians, as a |Float|
--- in the range of [-pi/2, pi/2].
--- {expr} must evaluate to a |Float| or a |Number| in the range
--- [-1, 1].
--- Returns NaN if {expr} is outside the range [-1, 1]. Returns
--- 0.0 if {expr} is not a |Float| or a |Number|.
--- Examples: >vim
--- echo asin(0.8)
--- < 0.927295 >vim
--- echo asin(-0.5)
--- < -0.523599
---
--- @param expr any
--- @return number
function vim.fn.asin(expr) end
--- Run {cmd} and add an error message to |v:errors| if it does
--- NOT produce a beep or visual bell.
--- Also see |assert_fails()|, |assert_nobeep()| and
--- |assert-return|.
---
--- @param cmd any
--- @return 0|1
function vim.fn.assert_beeps(cmd) end
--- When {expected} and {actual} are not equal an error message is
--- added to |v:errors| and 1 is returned. Otherwise zero is
--- returned. |assert-return|
--- The error is in the form "Expected {expected} but got
--- {actual}". When {msg} is present it is prefixed to that.
---
--- There is no automatic conversion, the String "4" is different
--- from the Number 4. And the number 4 is different from the
--- Float 4.0. The value of 'ignorecase' is not used here, case
--- always matters.
--- Example: >vim
--- assert_equal('foo', 'bar')
--- <Will result in a string to be added to |v:errors|:
--- test.vim line 12: Expected 'foo' but got 'bar' ~
---
--- @param expected any
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_equal(expected, actual, msg) end
--- When the files {fname-one} and {fname-two} do not contain
--- exactly the same text an error message is added to |v:errors|.
--- Also see |assert-return|.
--- When {fname-one} or {fname-two} does not exist the error will
--- mention that.
---
--- @return 0|1
function vim.fn.assert_equalfile() end
--- When v:exception does not contain the string {error} an error
--- message is added to |v:errors|. Also see |assert-return|.
--- This can be used to assert that a command throws an exception.
--- Using the error number, followed by a colon, avoids problems
--- with translations: >vim
--- try
--- commandthatfails
--- call assert_false(1, 'command should have failed')
--- catch
--- call assert_exception('E492:')
--- endtry
--- <
---
--- @param error any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_exception(error, msg) end
--- Run {cmd} and add an error message to |v:errors| if it does
--- NOT produce an error or when {error} is not found in the
--- error message. Also see |assert-return|.
---
--- When {error} is a string it must be found literally in the
--- first reported error. Most often this will be the error code,
--- including the colon, e.g. "E123:". >vim
--- assert_fails('bad cmd', 'E987:')
--- <
--- When {error} is a |List| with one or two strings, these are
--- used as patterns. The first pattern is matched against the
--- first reported error: >vim
--- assert_fails('cmd', ['E987:.*expected bool'])
--- <The second pattern, if present, is matched against the last
--- reported error. To only match the last error use an empty
--- string for the first error: >vim
--- assert_fails('cmd', ['', 'E987:'])
--- <
--- If {msg} is empty then it is not used. Do this to get the
--- default message when passing the {lnum} argument.
---
--- When {lnum} is present and not negative, and the {error}
--- argument is present and matches, then this is compared with
--- the line number at which the error was reported. That can be
--- the line number in a function or in a script.
---
--- When {context} is present it is used as a pattern and matched
--- against the context (script name or function name) where
--- {lnum} is located in.
---
--- Note that beeping is not considered an error, and some failing
--- commands only beep. Use |assert_beeps()| for those.
---
--- @param cmd any
--- @param error? any
--- @param msg? any
--- @param lnum? integer
--- @param context? any
--- @return 0|1
function vim.fn.assert_fails(cmd, error, msg, lnum, context) end
--- When {actual} is not false an error message is added to
--- |v:errors|, like with |assert_equal()|.
--- The error is in the form "Expected False but got {actual}".
--- When {msg} is present it is prepended to that.
--- Also see |assert-return|.
---
--- A value is false when it is zero. When {actual} is not a
--- number the assert fails.
---
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_false(actual, msg) end
--- This asserts number and |Float| values. When {actual} is lower
--- than {lower} or higher than {upper} an error message is added
--- to |v:errors|. Also see |assert-return|.
--- The error is in the form "Expected range {lower} - {upper},
--- but got {actual}". When {msg} is present it is prefixed to
--- that.
---
--- @param lower any
--- @param upper any
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_inrange(lower, upper, actual, msg) end
--- When {pattern} does not match {actual} an error message is
--- added to |v:errors|. Also see |assert-return|.
--- The error is in the form "Pattern {pattern} does not match
--- {actual}". When {msg} is present it is prefixed to that.
---
--- {pattern} is used as with |expr-=~|: The matching is always done
--- like 'magic' was set and 'cpoptions' is empty, no matter what
--- the actual value of 'magic' or 'cpoptions' is.
---
--- {actual} is used as a string, automatic conversion applies.
--- Use "^" and "$" to match with the start and end of the text.
--- Use both to match the whole text.
---
--- Example: >vim
--- assert_match('^f.*o$', 'foobar')
--- <Will result in a string to be added to |v:errors|:
--- test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
---
--- @param pattern any
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_match(pattern, actual, msg) end
--- Run {cmd} and add an error message to |v:errors| if it
--- produces a beep or visual bell.
--- Also see |assert_beeps()|.
---
--- @param cmd any
--- @return 0|1
function vim.fn.assert_nobeep(cmd) end
--- The opposite of `assert_equal()`: add an error message to
--- |v:errors| when {expected} and {actual} are equal.
--- Also see |assert-return|.
---
--- @param expected any
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_notequal(expected, actual, msg) end
--- The opposite of `assert_match()`: add an error message to
--- |v:errors| when {pattern} matches {actual}.
--- Also see |assert-return|.
---
--- @param pattern any
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_notmatch(pattern, actual, msg) end
--- Report a test failure directly, using String {msg}.
--- Always returns one.
---
--- @param msg any
--- @return 0|1
function vim.fn.assert_report(msg) end
--- When {actual} is not true an error message is added to
--- |v:errors|, like with |assert_equal()|.
--- Also see |assert-return|.
--- A value is |TRUE| when it is a non-zero number or |v:true|.
--- When {actual} is not a number or |v:true| the assert fails.
--- When {msg} is given it precedes the default message.
---
--- @param actual any
--- @param msg? any
--- @return 0|1
function vim.fn.assert_true(actual, msg) end
--- Return the principal value of the arc tangent of {expr}, in
--- the range [-pi/2, +pi/2] radians, as a |Float|.
--- {expr} must evaluate to a |Float| or a |Number|.
--- Returns 0.0 if {expr} is not a |Float| or a |Number|.
--- Examples: >vim
--- echo atan(100)
--- < 1.560797 >vim
--- echo atan(-4.01)
--- < -1.326405
---
--- @param expr any
--- @return number
function vim.fn.atan(expr) end
--- Return the arc tangent of {expr1} / {expr2}, measured in
--- radians, as a |Float| in the range [-pi, pi].
--- {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
--- Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
--- |Number|.
--- Examples: >vim
--- echo atan2(-1, 1)
--- < -0.785398 >vim
--- echo atan2(1, -1)
--- < 2.356194
---
--- @param expr1 any
--- @param expr2 any
--- @return number
function vim.fn.atan2(expr1, expr2) end
--- Return a List containing the number value of each byte in Blob
--- {blob}. Examples: >vim
--- blob2list(0z0102.0304) " returns [1, 2, 3, 4]
--- blob2list(0z) " returns []
--- <Returns an empty List on error. |list2blob()| does the
--- opposite.
---
--- @param blob any
--- @return any[]
function vim.fn.blob2list(blob) end
--- Put up a file requester. This only works when "has("browse")"
--- returns |TRUE| (only in some GUI versions).
--- The input fields are:
--- {save} when |TRUE|, select file to write
--- {title} title for the requester
--- {initdir} directory to start browsing in
--- {default} default file name
--- An empty string is returned when the "Cancel" button is hit,
--- something went wrong, or browsing is not possible.
---
--- @param save any
--- @param title any
--- @param initdir any
--- @param default any
--- @return 0|1
function vim.fn.browse(save, title, initdir, default) end
--- Put up a directory requester. This only works when
--- "has("browse")" returns |TRUE| (only in some GUI versions).
--- On systems where a directory browser is not supported a file
--- browser is used. In that case: select a file in the directory
--- to be used.
--- The input fields are:
--- {title} title for the requester
--- {initdir} directory to start browsing in
--- When the "Cancel" button is hit, something went wrong, or
--- browsing is not possible, an empty string is returned.
---
--- @param title any
--- @param initdir any
--- @return 0|1
function vim.fn.browsedir(title, initdir) end
--- Add a buffer to the buffer list with name {name} (must be a
--- String).
--- If a buffer for file {name} already exists, return that buffer
--- number. Otherwise return the buffer number of the newly
--- created buffer. When {name} is an empty string then a new
--- buffer is always created.
--- The buffer will not have 'buflisted' set and not be loaded
--- yet. To add some text to the buffer use this: >vim
--- let bufnr = bufadd('someName')
--- call bufload(bufnr)
--- call setbufline(bufnr, 1, ['some', 'text'])
--- <Returns 0 on error.
---
--- @param name string
--- @return integer
function vim.fn.bufadd(name) end
--- The result is a Number, which is |TRUE| if a buffer called
--- {buf} exists.
--- If the {buf} argument is a number, buffer numbers are used.
--- Number zero is the alternate buffer for the current window.
---
--- If the {buf} argument is a string it must match a buffer name
--- exactly. The name can be:
--- - Relative to the current directory.
--- - A full path.
--- - The name of a buffer with 'buftype' set to "nofile".
--- - A URL name.
--- Unlisted buffers will be found.
--- Note that help files are listed by their short name in the
--- output of |:buffers|, but bufexists() requires using their
--- long name to be able to find them.
--- bufexists() may report a buffer exists, but to use the name
--- with a |:buffer| command you may need to use |expand()|. Esp
--- for MS-Windows 8.3 names in the form "c:\DOCUME~1"
--- Use "bufexists(0)" to test for the existence of an alternate
--- file name.
---
--- @param buf any
--- @return 0|1
function vim.fn.bufexists(buf) end
--- @deprecated
--- Obsolete name for |bufexists()|.
---
--- @param ... any
--- @return 0|1
function vim.fn.buffer_exists(...) end
--- @deprecated
--- Obsolete name for |bufname()|.
---
--- @param ... any
--- @return string
function vim.fn.buffer_name(...) end
--- @deprecated
--- Obsolete name for |bufnr()|.
---
--- @param ... any
--- @return integer
function vim.fn.buffer_number(...) end
--- The result is a Number, which is |TRUE| if a buffer called
--- {buf} exists and is listed (has the 'buflisted' option set).
--- The {buf} argument is used like with |bufexists()|.
---
--- @param buf any
--- @return 0|1
function vim.fn.buflisted(buf) end
--- Ensure the buffer {buf} is loaded. When the buffer name
--- refers to an existing file then the file is read. Otherwise
--- the buffer will be empty. If the buffer was already loaded
--- then there is no change. If the buffer is not related to a
--- file then no file is read (e.g., when 'buftype' is "nofile").
--- If there is an existing swap file for the file of the buffer,
--- there will be no dialog, the buffer will be loaded anyway.
--- The {buf} argument is used like with |bufexists()|.
---
--- @param buf any
function vim.fn.bufload(buf) end
--- The result is a Number, which is |TRUE| if a buffer called
--- {buf} exists and is loaded (shown in a window or hidden).
--- The {buf} argument is used like with |bufexists()|.
---
--- @param buf any
--- @return 0|1
function vim.fn.bufloaded(buf) end
--- The result is the name of a buffer. Mostly as it is displayed
--- by the `:ls` command, but not using special names such as
--- "[No Name]".
--- If {buf} is omitted the current buffer is used.
--- If {buf} is a Number, that buffer number's name is given.
--- Number zero is the alternate buffer for the current window.
--- If {buf} is a String, it is used as a |file-pattern| to match
--- with the buffer names. This is always done like 'magic' is
--- set and 'cpoptions' is empty. When there is more than one
--- match an empty string is returned.
--- "" or "%" can be used for the current buffer, "#" for the
--- alternate buffer.
--- A full match is preferred, otherwise a match at the start, end
--- or middle of the buffer name is accepted. If you only want a
--- full match then put "^" at the start and "$" at the end of the
--- pattern.
--- Listed buffers are found first. If there is a single match
--- with a listed buffer, that one is returned. Next unlisted
--- buffers are searched for.
--- If the {buf} is a String, but you want to use it as a buffer
--- number, force it to be a Number by adding zero to it: >vim
--- echo bufname("3" + 0)
--- <If the buffer doesn't exist, or doesn't have a name, an empty
--- string is returned. >vim
--- echo bufname("#") " alternate buffer name
--- echo bufname(3) " name of buffer 3
--- echo bufname("%") " name of current buffer
--- echo bufname("file2") " name of buffer where "file2" matches.
--- <
---
--- @param buf? integer|string
--- @return string
function vim.fn.bufname(buf) end
--- The result is the number of a buffer, as it is displayed by
--- the `:ls` command. For the use of {buf}, see |bufname()|
--- above.
--- If the buffer doesn't exist, -1 is returned. Or, if the
--- {create} argument is present and TRUE, a new, unlisted,
--- buffer is created and its number is returned.
--- bufnr("$") is the last buffer: >vim
--- let last_buffer = bufnr("$")
--- <The result is a Number, which is the highest buffer number
--- of existing buffers. Note that not all buffers with a smaller
--- number necessarily exist, because ":bwipeout" may have removed
--- them. Use bufexists() to test for the existence of a buffer.
---
--- @param buf? integer|string
--- @param create? any
--- @return integer
function vim.fn.bufnr(buf, create) end
--- The result is a Number, which is the |window-ID| of the first
--- window associated with buffer {buf}. For the use of {buf},
--- see |bufname()| above. If buffer {buf} doesn't exist or
--- there is no such window, -1 is returned. Example: >vim
---
--- echo "A window containing buffer 1 is " .. (bufwinid(1))
--- <
--- Only deals with the current tab page. See |win_findbuf()| for
--- finding more.
---
--- @param buf any
--- @return integer
function vim.fn.bufwinid(buf) end
--- Like |bufwinid()| but return the window number instead of the
--- |window-ID|.
--- If buffer {buf} doesn't exist or there is no such window, -1
--- is returned. Example: >vim
---
--- echo "A window containing buffer 1 is " .. (bufwinnr(1))
---
--- <The number can be used with |CTRL-W_w| and ":wincmd w"
--- |:wincmd|.
---
--- @param buf any
--- @return integer
function vim.fn.bufwinnr(buf) end
--- Return the line number that contains the character at byte
--- count {byte} in the current buffer. This includes the
--- end-of-line character, depending on the 'fileformat' option
--- for the current buffer. The first character has byte count
--- one.
--- Also see |line2byte()|, |go| and |:goto|.
---
--- Returns -1 if the {byte} value is invalid.
---
--- @param byte any
--- @return integer
function vim.fn.byte2line(byte) end
--- Return byte index of the {nr}th character in the String
--- {expr}. Use zero for the first character, it then returns
--- zero.
--- If there are no multibyte characters the returned value is
--- equal to {nr}.
--- Composing characters are not counted separately, their byte
--- length is added to the preceding base character. See
--- |byteidxcomp()| below for counting composing characters
--- separately.
--- When {utf16} is present and TRUE, {nr} is used as the UTF-16
--- index in the String {expr} instead of as the character index.
--- The UTF-16 index is the index in the string when it is encoded
--- with 16-bit words. If the specified UTF-16 index is in the
--- middle of a character (e.g. in a 4-byte character), then the
--- byte index of the first byte in the character is returned.
--- Refer to |string-offset-encoding| for more information.
--- Example : >vim
--- echo matchstr(str, ".", byteidx(str, 3))
--- <will display the fourth character. Another way to do the
--- same: >vim
--- let s = strpart(str, byteidx(str, 3))
--- echo strpart(s, 0, byteidx(s, 1))
--- <Also see |strgetchar()| and |strcharpart()|.
---
--- If there are less than {nr} characters -1 is returned.
--- If there are exactly {nr} characters the length of the string
--- in bytes is returned.
--- See |charidx()| and |utf16idx()| for getting the character and
--- UTF-16 index respectively from the byte index.
--- Examples: >vim
--- echo byteidx('a😊😊', 2) " returns 5
--- echo byteidx('a😊😊', 2, 1) " returns 1
--- echo byteidx('a😊😊', 3, 1) " returns 5
--- <
---
--- @param expr any
--- @param nr integer
--- @param utf16? any
--- @return integer
function vim.fn.byteidx(expr, nr, utf16) end
--- Like byteidx(), except that a composing character is counted
--- as a separate character. Example: >vim
--- let s = 'e' .. nr2char(0x301)
--- echo byteidx(s, 1)
--- echo byteidxcomp(s, 1)
--- echo byteidxcomp(s, 2)
--- <The first and third echo result in 3 ('e' plus composing
--- character is 3 bytes), the second echo results in 1 ('e' is
--- one byte).
---
--- @param expr any
--- @param nr integer
--- @param utf16? any
--- @return integer
function vim.fn.byteidxcomp(expr, nr, utf16) end
--- Call function {func} with the items in |List| {arglist} as
--- arguments.
--- {func} can either be a |Funcref| or the name of a function.
--- a:firstline and a:lastline are set to the cursor line.
--- Returns the return value of the called function.
--- {dict} is for functions with the "dict" attribute. It will be
--- used to set the local variable "self". |Dictionary-function|
---
--- @param func any
--- @param arglist any
--- @param dict? any
--- @return any
function vim.fn.call(func, arglist, dict) end
--- Return the smallest integral value greater than or equal to
--- {expr} as a |Float| (round up).
--- {expr} must evaluate to a |Float| or a |Number|.
--- Examples: >vim
--- echo ceil(1.456)
--- < 2.0 >vim
--- echo ceil(-5.456)
--- < -5.0 >vim
--- echo ceil(4.0)
--- < 4.0
---
--- Returns 0.0 if {expr} is not a |Float| or a |Number|.
---
--- @param expr any
--- @return number
function vim.fn.ceil(expr) end
--- Close a channel or a specific stream associated with it.
--- For a job, {stream} can be one of "stdin", "stdout",
--- "stderr" or "rpc" (closes stdin/stdout for a job started
--- with `"rpc":v:true`) If {stream} is omitted, all streams
--- are closed. If the channel is a pty, this will then close the
--- pty master, sending SIGHUP to the job process.
--- For a socket, there is only one stream, and {stream} should be
--- omitted.
---
--- @param id any
--- @param stream? any
--- @return 0|1
function vim.fn.chanclose(id, stream) end
--- Return the number of the most recent change. This is the same
--- number as what is displayed with |:undolist| and can be used
--- with the |:undo| command.
--- When a change was made it is the number of that change. After
--- redo it is the number of the redone change. After undo it is
--- one less than the number of the undone change.
--- Returns 0 if the undo list is empty.
---
--- @return integer
function vim.fn.changenr() end
--- Send data to channel {id}. For a job, it writes it to the
--- stdin of the process. For the stdio channel |channel-stdio|,
--- it writes to Nvim's stdout. Returns the number of bytes
--- written if the write succeeded, 0 otherwise.
--- See |channel-bytes| for more information.
---
--- {data} may be a string, string convertible, |Blob|, or a list.
--- If {data} is a list, the items will be joined by newlines; any
--- newlines in an item will be sent as NUL. To send a final
--- newline, include a final empty string. Example: >vim
--- call chansend(id, ["abc", "123\n456", ""])
--- <will send "abc<NL>123<NUL>456<NL>".
---
--- chansend() writes raw data, not RPC messages. If the channel
--- was created with `"rpc":v:true` then the channel expects RPC
--- messages, use |rpcnotify()| and |rpcrequest()| instead.
---
--- @param id any
--- @param data any
--- @return 0|1
function vim.fn.chansend(id, data) end
--- Return Number value of the first char in {string}.
--- Examples: >vim
--- echo char2nr(" ") " returns 32
--- echo char2nr("ABC") " returns 65
--- echo char2nr("á") " returns 225
--- echo char2nr("á"[0]) " returns 195
--- echo char2nr("\<M-x>") " returns 128
--- <Non-ASCII characters are always treated as UTF-8 characters.
--- {utf8} is ignored, it exists only for backwards-compatibility.
--- A combining character is a separate character.
--- |nr2char()| does the opposite.
---
--- Returns 0 if {string} is not a |String|.
---
--- @param string string
--- @param utf8? any
--- @return 0|1
function vim.fn.char2nr(string, utf8) end
--- Return the character class of the first character in {string}.
--- The character class is one of:
--- 0 blank
--- 1 punctuation
--- 2 word character
--- 3 emoji
--- other specific Unicode class
--- The class is used in patterns and word motions.
--- Returns 0 if {string} is not a |String|.
---
--- @param string string
--- @return 0|1|2|3|'other'
function vim.fn.charclass(string) end
--- Same as |col()| but returns the character index of the column
--- position given with {expr} instead of the byte position.
---
--- Example:
--- With the cursor on '세' in line 5 with text "여보세요": >vim
--- echo charcol('.') " returns 3
--- echo col('.') " returns 7
---
--- @param expr any
--- @param winid? integer
--- @return integer
function vim.fn.charcol(expr, winid) end
--- Return the character index of the byte at {idx} in {string}.
--- The index of the first character is zero.
--- If there are no multibyte characters the returned value is
--- equal to {idx}.
---
--- When {countcc} is omitted or |FALSE|, then composing characters
--- are not counted separately, their byte length is added to the
--- preceding base character.
--- When {countcc} is |TRUE|, then composing characters are
--- counted as separate characters.
---
--- When {utf16} is present and TRUE, {idx} is used as the UTF-16
--- index in the String {expr} instead of as the byte index.
---
--- Returns -1 if the arguments are invalid or if there are less
--- than {idx} bytes. If there are exactly {idx} bytes the length
--- of the string in characters is returned.
---
--- An error is given and -1 is returned if the first argument is
--- not a string, the second argument is not a number or when the
--- third argument is present and is not zero or one.
---
--- See |byteidx()| and |byteidxcomp()| for getting the byte index
--- from the character index and |utf16idx()| for getting the
--- UTF-16 index from the character index.
--- Refer to |string-offset-encoding| for more information.
--- Examples: >vim
--- echo charidx('áb́ć', 3) " returns 1
--- echo charidx('áb́ć', 6, 1) " returns 4
--- echo charidx('áb́ć', 16) " returns -1
--- echo charidx('a😊😊', 4, 0, 1) " returns 2
--- <
---
--- @param string string
--- @param idx integer
--- @param countcc? any
--- @param utf16? any
--- @return integer
function vim.fn.charidx(string, idx, countcc, utf16) end
--- Change the current working directory to {dir}. The scope of
--- the directory change depends on the directory of the current
--- window:
--- - If the current window has a window-local directory
--- (|:lcd|), then changes the window local directory.
--- - Otherwise, if the current tabpage has a local
--- directory (|:tcd|) then changes the tabpage local
--- directory.
--- - Otherwise, changes the global directory.
--- {dir} must be a String.
--- If successful, returns the previous working directory. Pass
--- this to another chdir() to restore the directory.
--- On failure, returns an empty string.
---
--- Example: >vim
--- let save_dir = chdir(newdir)
--- if save_dir != ""
--- " ... do some work
--- call chdir(save_dir)
--- endif
---
--- @param dir string
--- @return string
function vim.fn.chdir(dir) end
--- Get the amount of indent for line {lnum} according the C
--- indenting rules, as with 'cindent'.
--- The indent is counted in spaces, the value of 'tabstop' is
--- relevant. {lnum} is used just like in |getline()|.
--- When {lnum} is invalid -1 is returned.
--- See |C-indenting|.
---
--- @param lnum integer
--- @return integer
function vim.fn.cindent(lnum) end
--- Clears all matches previously defined for the current window
--- by |matchadd()| and the |:match| commands.
--- If {win} is specified, use the window with this number or
--- window ID instead of the current window.
---
--- @param win? any
function vim.fn.clearmatches(win) end
--- The result is a Number, which is the byte index of the column
--- position given with {expr}.
--- For accepted positions see |getpos()|.
--- When {expr} is "$", it means the end of the cursor line, so
--- the result is the number of bytes in the cursor line plus one.
--- Additionally {expr} can be [lnum, col]: a |List| with the line
--- and column number. Most useful when the column is "$", to get
--- the last column of a specific line. When "lnum" or "col" is
--- out of range then col() returns zero.
---
--- With the optional {winid} argument the values are obtained for
--- that window instead of the current window.
---
--- To get the line number use |line()|. To get both use
--- |getpos()|.
---
--- For the screen column position use |virtcol()|. For the
--- character position use |charcol()|.
---
--- Note that only marks in the current file can be used.
---
--- Examples: >vim
--- echo col(".") " column of cursor
--- echo col("$") " length of cursor line plus one
--- echo col("'t") " column of mark t
--- echo col("'" .. markname) " column of mark markname
--- <
--- The first column is 1. Returns 0 if {expr} is invalid or when
--- the window with ID {winid} is not found.
--- For an uppercase mark the column may actually be in another
--- buffer.
--- For the cursor position, when 'virtualedit' is active, the
--- column is one higher if the cursor is after the end of the
--- line. Also, when using a <Cmd> mapping the cursor isn't
--- moved, this can be used to obtain the column in Insert mode: >vim
--- imap <F2> <Cmd>echo col(".").."\n"<CR>
---
--- @param expr any
--- @param winid? integer
--- @return integer
function vim.fn.col(expr, winid) end
--- Set the matches for Insert mode completion.
--- Can only be used in Insert mode. You need to use a mapping
--- with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
--- or with an expression mapping.
--- {startcol} is the byte offset in the line where the completed
--- text start. The text up to the cursor is the original text
--- that will be replaced by the matches. Use col('.') for an
--- empty string. "col('.') - 1" will replace one character by a
--- match.
--- {matches} must be a |List|. Each |List| item is one match.
--- See |complete-items| for the kind of items that are possible.
--- "longest" in 'completeopt' is ignored.
--- Note that the after calling this function you need to avoid
--- inserting anything that would cause completion to stop.
--- The match can be selected with CTRL-N and CTRL-P as usual with
--- Insert mode completion. The popup menu will appear if
--- specified, see |ins-completion-menu|.
--- Example: >vim
--- inoremap <F5> <C-R>=ListMonths()<CR>
---
--- func ListMonths()
--- call complete(col('.'), ['January', 'February', 'March',
--- \ 'April', 'May', 'June', 'July', 'August', 'September',
--- \ 'October', 'November', 'December'])
--- return ''
--- endfunc
--- <This isn't very useful, but it shows how it works. Note that
--- an empty string is returned to avoid a zero being inserted.
---
--- @param startcol any
--- @param matches any
function vim.fn.complete(startcol, matches) end
--- Add {expr} to the list of matches. Only to be used by the
--- function specified with the 'completefunc' option.
--- Returns 0 for failure (empty string or out of memory),
--- 1 when the match was added, 2 when the match was already in
--- the list.
--- See |complete-functions| for an explanation of {expr}. It is
--- the same as one item in the list that 'omnifunc' would return.
---
--- @param expr any
--- @return 0|1|2
function vim.fn.complete_add(expr) end
--- Check for a key typed while looking for completion matches.