vimfn.txt (459912B)
1 *vimfn.txt* Nvim 2 3 4 NVIM REFERENCE MANUAL 5 6 7 Vimscript functions *vimscript-functions* *builtin.txt* 8 9 For functions grouped by what they are used for see |function-list|. 10 11 Type |gO| to see the table of contents. 12 ============================================================================== 13 1. Details *vimscript-functions-details* 14 15 abs({expr}) *abs()* 16 Return the absolute value of {expr}. When {expr} evaluates to 17 a |Float| abs() returns a |Float|. When {expr} can be 18 converted to a |Number| abs() returns a |Number|. Otherwise 19 abs() gives an error message and returns -1. 20 Examples: >vim 21 echo abs(1.456) 22 < 1.456 >vim 23 echo abs(-5.456) 24 < 5.456 >vim 25 echo abs(-4) 26 < 4 27 28 Parameters: ~ 29 • {expr} (`number`) 30 31 Return: ~ 32 (`number`) 33 34 acos({expr}) *acos()* 35 Return the arc cosine of {expr} measured in radians, as a 36 |Float| in the range of [0, pi]. 37 {expr} must evaluate to a |Float| or a |Number| in the range 38 [-1, 1]. 39 Returns NaN if {expr} is outside the range [-1, 1]. Returns 40 0.0 if {expr} is not a |Float| or a |Number|. 41 Examples: >vim 42 echo acos(0) 43 < 1.570796 >vim 44 echo acos(-0.5) 45 < 2.094395 46 47 Parameters: ~ 48 • {expr} (`number`) 49 50 Return: ~ 51 (`number`) 52 53 add({object}, {expr}) *add()* 54 Append the item {expr} to |List| or |Blob| {object}. Returns 55 the resulting |List| or |Blob|. Examples: >vim 56 let alist = add([1, 2, 3], item) 57 call add(mylist, "woodstock") 58 < Note that when {expr} is a |List| it is appended as a single 59 item. Use |extend()| to concatenate |Lists|. 60 When {object} is a |Blob| then {expr} must be a number. 61 Use |insert()| to add an item at another position. 62 Returns 1 if {object} is not a |List| or a |Blob|. 63 64 Parameters: ~ 65 • {object} (`any`) 66 • {expr} (`any`) 67 68 Return: ~ 69 (`any`) Resulting |List| or |Blob|, or 1 if {object} is not 70 a |List| or a |Blob|. 71 72 and({expr}, {expr}) *and()* 73 Bitwise AND on the two arguments. The arguments are converted 74 to a number. A List, Dict or Float argument causes an error. 75 Also see |or()| and |xor()|. 76 Example: >vim 77 let flag = and(bits, 0x80) 78 < 79 80 Parameters: ~ 81 • {expr} (`number`) 82 • {expr1} (`number`) 83 84 Return: ~ 85 (`integer`) 86 87 api_info() *api_info()* 88 Returns Dictionary of |api-metadata|. 89 90 View it in a nice human-readable format: >vim 91 lua vim.print(vim.fn.api_info()) 92 < 93 94 Return: ~ 95 (`table`) 96 97 append({lnum}, {text}) *append()* 98 When {text} is a |List|: Append each item of the |List| as a 99 text line below line {lnum} in the current buffer. 100 Otherwise append {text} as one text line below line {lnum} in 101 the current buffer. 102 Any type of item is accepted and converted to a String. 103 {lnum} can be zero to insert a line before the first one. 104 {lnum} is used like with |getline()|. 105 Returns 1 for failure ({lnum} out of range or out of memory), 106 0 for success. When {text} is an empty list zero is returned, 107 no matter the value of {lnum}. Example: >vim 108 let failed = append(line('$'), "# THE END") 109 let failed = append(0, ["Chapter 1", "the beginning"]) 110 < 111 112 Parameters: ~ 113 • {lnum} (`integer|string`) 114 • {text} (`string|string[]`) 115 116 Return: ~ 117 (`0|1`) 118 119 appendbufline({buf}, {lnum}, {text}) *appendbufline()* 120 Like |append()| but append the text in buffer {expr}. 121 122 This function works only for loaded buffers. First call 123 |bufload()| if needed. 124 125 For the use of {buf}, see |bufname()|. 126 127 {lnum} is the line number to append below. Note that using 128 |line()| would use the current buffer, not the one appending 129 to. Use "$" to append at the end of the buffer. Other string 130 values are not supported. 131 132 On success 0 is returned, on failure 1 is returned. 133 134 If {buf} is not a valid buffer or {lnum} is not valid, an 135 error message is given. Example: >vim 136 let failed = appendbufline(13, 0, "# THE START") 137 < However, when {text} is an empty list then no error is given 138 for an invalid {lnum}, since {lnum} isn't actually used. 139 140 Parameters: ~ 141 • {buf} (`integer|string`) 142 • {lnum} (`integer`) 143 • {text} (`string`) 144 145 Return: ~ 146 (`0|1`) 147 148 argc([{winid}]) *argc()* 149 The result is the number of files in the argument list. See 150 |arglist|. 151 If {winid} is not supplied, the argument list of the current 152 window is used. 153 If {winid} is -1, the global argument list is used. 154 Otherwise {winid} specifies the window of which the argument 155 list is used: either the window number or the window ID. 156 Returns -1 if the {winid} argument is invalid. 157 158 Parameters: ~ 159 • {winid} (`integer?`) 160 161 Return: ~ 162 (`integer`) 163 164 argidx() *argidx()* 165 The result is the current index in the argument list. 0 is 166 the first file. |argc()| - 1 is the last one. See |arglist|. 167 168 Return: ~ 169 (`integer`) 170 171 arglistid([{winnr} [, {tabnr}]]) *arglistid()* 172 Return the argument list ID. This is a number which 173 identifies the argument list being used. Zero is used for the 174 global argument list. See |arglist|. 175 Returns -1 if the arguments are invalid. 176 177 Without arguments use the current window. 178 With {winnr} only use this window in the current tab page. 179 With {winnr} and {tabnr} use the window in the specified tab 180 page. 181 {winnr} can be the window number or the |window-ID|. 182 183 Parameters: ~ 184 • {winnr} (`integer?`) 185 • {tabnr} (`integer?`) 186 187 Return: ~ 188 (`integer`) 189 190 argv([{nr} [, {winid}]]) *argv()* 191 The result is the {nr}th file in the argument list. See 192 |arglist|. "argv(0)" is the first one. Example: >vim 193 let i = 0 194 while i < argc() 195 let f = escape(fnameescape(argv(i)), '.') 196 exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>' 197 let i = i + 1 198 endwhile 199 < Without the {nr} argument, or when {nr} is -1, a |List| with 200 the whole |arglist| is returned. 201 202 The {winid} argument specifies the window ID, see |argc()|. 203 For the Vim command line arguments see |v:argv|. 204 205 Returns an empty string if {nr}th argument is not present in 206 the argument list. Returns an empty List if the {winid} 207 argument is invalid. 208 209 Parameters: ~ 210 • {nr} (`integer?`) 211 • {winid} (`integer?`) 212 213 Return: ~ 214 (`string|string[]`) 215 216 asin({expr}) *asin()* 217 Return the arc sine of {expr} measured in radians, as a |Float| 218 in the range of [-pi/2, pi/2]. 219 {expr} must evaluate to a |Float| or a |Number| in the range 220 [-1, 1]. 221 Returns NaN if {expr} is outside the range [-1, 1]. Returns 222 0.0 if {expr} is not a |Float| or a |Number|. 223 Examples: >vim 224 echo asin(0.8) 225 < 0.927295 >vim 226 echo asin(-0.5) 227 < -0.523599 228 229 Parameters: ~ 230 • {expr} (`any`) 231 232 Return: ~ 233 (`number`) 234 235 assert_beeps({cmd}) *assert_beeps()* 236 Run {cmd} and add an error message to |v:errors| if it does 237 NOT produce a beep or visual bell. 238 Also see |assert_fails()|, |assert_nobeep()| and 239 |assert-return|. 240 241 Parameters: ~ 242 • {cmd} (`string`) 243 244 Return: ~ 245 (`0|1`) 246 247 assert_equal({expected}, {actual} [, {msg}]) *assert_equal()* 248 When {expected} and {actual} are not equal an error message is 249 added to |v:errors| and 1 is returned. Otherwise zero is 250 returned. |assert-return| 251 The error is in the form "Expected {expected} but got 252 {actual}". When {msg} is present it is prefixed to that, 253 along with the location of the assert when run from a script. 254 255 There is no automatic conversion, the String "4" is different 256 from the Number 4. And the number 4 is different from the 257 Float 4.0. The value of 'ignorecase' is not used here, case 258 always matters. 259 Example: >vim 260 call assert_equal('foo', 'bar', 'baz') 261 < Will add the following to |v:errors|: > 262 test.vim line 12: baz: Expected 'foo' but got 'bar' 263 < 264 265 Parameters: ~ 266 • {expected} (`any`) 267 • {actual} (`any`) 268 • {msg} (`any?`) 269 270 Return: ~ 271 (`0|1`) 272 273 assert_equalfile({fname_one}, {fname_two}) *assert_equalfile()* 274 When the files {fname_one} and {fname_two} do not contain 275 exactly the same text an error message is added to |v:errors|. 276 Also see |assert-return|. 277 When {fname_one} or {fname_two} does not exist the error will 278 mention that. 279 280 Parameters: ~ 281 • {fname_one} (`string`) 282 • {fname_two} (`string`) 283 284 Return: ~ 285 (`0|1`) 286 287 assert_exception({error} [, {msg}]) *assert_exception()* 288 When v:exception does not contain the string {error} an error 289 message is added to |v:errors|. Also see |assert-return|. 290 This can be used to assert that a command throws an exception. 291 Using the error number, followed by a colon, avoids problems 292 with translations: >vim 293 try 294 commandthatfails 295 call assert_false(1, 'command should have failed') 296 catch 297 call assert_exception('E492:') 298 endtry 299 < 300 301 Parameters: ~ 302 • {error} (`any`) 303 • {msg} (`any?`) 304 305 Return: ~ 306 (`0|1`) 307 308 *assert_fails()* 309 assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]]) 310 Run {cmd} and add an error message to |v:errors| if it does 311 NOT produce an error or when {error} is not found in the 312 error message. Also see |assert-return|. 313 314 When {error} is a string it must be found literally in the 315 first reported error. Most often this will be the error code, 316 including the colon, e.g. "E123:". >vim 317 call assert_fails('bad cmd', 'E987:') 318 < 319 When {error} is a |List| with one or two strings, these are 320 used as patterns. The first pattern is matched against the 321 first reported error: >vim 322 call assert_fails('cmd', ['E987:.*expected bool']) 323 < The second pattern, if present, is matched against the last 324 reported error. To only match the last error use an empty 325 string for the first error: >vim 326 call assert_fails('cmd', ['', 'E987:']) 327 < 328 If {msg} is empty then it is not used. Do this to get the 329 default message when passing the {lnum} argument. 330 *E1115* 331 When {lnum} is present and not negative, and the {error} 332 argument is present and matches, then this is compared with 333 the line number at which the error was reported. That can be 334 the line number in a function or in a script. 335 *E1116* 336 When {context} is present it is used as a pattern and matched 337 against the context (script name or function name) where 338 {lnum} is located in. 339 340 Note that beeping is not considered an error, and some failing 341 commands only beep. Use |assert_beeps()| for those. 342 343 Parameters: ~ 344 • {cmd} (`string`) 345 • {error} (`any?`) 346 • {msg} (`any?`) 347 • {lnum} (`integer?`) 348 • {context} (`any?`) 349 350 Return: ~ 351 (`0|1`) 352 353 assert_false({actual} [, {msg}]) *assert_false()* 354 When {actual} is not false an error message is added to 355 |v:errors|, like with |assert_equal()|. 356 The error is in the form "Expected False but got {actual}". 357 When {msg} is present it is prefixed to that, along with the 358 location of the assert when run from a script. 359 Also see |assert-return|. 360 361 A value is false when it is zero. When {actual} is not a 362 number the assert fails. 363 364 Parameters: ~ 365 • {actual} (`any`) 366 • {msg} (`any?`) 367 368 Return: ~ 369 (`0|1`) 370 371 assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* 372 This asserts number and |Float| values. When {actual} is lower 373 than {lower} or higher than {upper} an error message is added 374 to |v:errors|. Also see |assert-return|. 375 The error is in the form "Expected range {lower} - {upper}, 376 but got {actual}". When {msg} is present it is prefixed to 377 that. 378 379 Parameters: ~ 380 • {lower} (`number`) 381 • {upper} (`number`) 382 • {actual} (`number`) 383 • {msg} (`string?`) 384 385 Return: ~ 386 (`0|1`) 387 388 assert_match({pattern}, {actual} [, {msg}]) *assert_match()* 389 When {pattern} does not match {actual} an error message is 390 added to |v:errors|. Also see |assert-return|. 391 The error is in the form "Pattern {pattern} does not match 392 {actual}". When {msg} is present it is prefixed to that, 393 along with the location of the assert when run from a script. 394 395 {pattern} is used as with |expr-=~|: The matching is always done 396 like 'magic' was set and 'cpoptions' is empty, no matter what 397 the actual value of 'magic' or 'cpoptions' is. 398 399 {actual} is used as a string, automatic conversion applies. 400 Use "^" and "$" to match with the start and end of the text. 401 Use both to match the whole text. 402 403 Example: >vim 404 call assert_match('^f.*o$', 'foobar') 405 < Will result in a string to be added to |v:errors|: > 406 test.vim line 12: Pattern '^f.*o$' does not match 'foobar' 407 < 408 409 Parameters: ~ 410 • {pattern} (`string`) 411 • {actual} (`string`) 412 • {msg} (`string?`) 413 414 Return: ~ 415 (`0|1`) 416 417 assert_nobeep({cmd}) *assert_nobeep()* 418 Run {cmd} and add an error message to |v:errors| if it 419 produces a beep or visual bell. 420 Also see |assert_beeps()|. 421 422 Parameters: ~ 423 • {cmd} (`string`) 424 425 Return: ~ 426 (`0|1`) 427 428 assert_notequal({expected}, {actual} [, {msg}]) *assert_notequal()* 429 The opposite of `assert_equal()`: add an error message to 430 |v:errors| when {expected} and {actual} are equal. 431 Also see |assert-return|. 432 433 Parameters: ~ 434 • {expected} (`any`) 435 • {actual} (`any`) 436 • {msg} (`any?`) 437 438 Return: ~ 439 (`0|1`) 440 441 assert_notmatch({pattern}, {actual} [, {msg}]) *assert_notmatch()* 442 The opposite of `assert_match()`: add an error message to 443 |v:errors| when {pattern} matches {actual}. 444 Also see |assert-return|. 445 446 Parameters: ~ 447 • {pattern} (`string`) 448 • {actual} (`string`) 449 • {msg} (`string?`) 450 451 Return: ~ 452 (`0|1`) 453 454 assert_report({msg}) *assert_report()* 455 Report a test failure directly, using String {msg}. 456 Always returns one. 457 458 Parameters: ~ 459 • {msg} (`string`) 460 461 Return: ~ 462 (`0|1`) 463 464 assert_true({actual} [, {msg}]) *assert_true()* 465 When {actual} is not true an error message is added to 466 |v:errors|, like with |assert_equal()|. 467 Also see |assert-return|. 468 A value is |TRUE| when it is a non-zero number or |v:true|. 469 When {actual} is not a number or |v:true| the assert fails. 470 When {msg} is given it is prefixed to the default message, 471 along with the location of the assert when run from a script. 472 473 Parameters: ~ 474 • {actual} (`any`) 475 • {msg} (`string?`) 476 477 Return: ~ 478 (`0|1`) 479 480 atan({expr}) *atan()* 481 Return the principal value of the arc tangent of {expr}, in 482 the range [-pi/2, +pi/2] radians, as a |Float|. 483 {expr} must evaluate to a |Float| or a |Number|. 484 Returns 0.0 if {expr} is not a |Float| or a |Number|. 485 Examples: >vim 486 echo atan(100) 487 < 1.560797 >vim 488 echo atan(-4.01) 489 < -1.326405 490 491 Parameters: ~ 492 • {expr} (`number`) 493 494 Return: ~ 495 (`number`) 496 497 atan2({expr1}, {expr2}) *atan2()* 498 Return the arc tangent of {expr1} / {expr2}, measured in 499 radians, as a |Float| in the range [-pi, pi]. 500 {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 501 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a 502 |Number|. 503 Examples: >vim 504 echo atan2(-1, 1) 505 < -0.785398 >vim 506 echo atan2(1, -1) 507 < 2.356194 508 509 Parameters: ~ 510 • {expr1} (`number`) 511 • {expr2} (`number`) 512 513 Return: ~ 514 (`number`) 515 516 blob2list({blob}) *blob2list()* 517 Return a List containing the number value of each byte in Blob 518 {blob}. Examples: >vim 519 blob2list(0z0102.0304) " returns [1, 2, 3, 4] 520 blob2list(0z) " returns [] 521 < Returns an empty List on error. |list2blob()| does the 522 opposite. 523 524 Parameters: ~ 525 • {blob} (`any`) 526 527 Return: ~ 528 (`any[]`) 529 530 browse({save}, {title}, {initdir}, {default}) *browse()* 531 Put up a file requester. This only works when "has("browse")" 532 returns |TRUE| (only in some GUI versions). 533 The input fields are: 534 {save} when |TRUE|, select file to write 535 {title} title for the requester 536 {initdir} directory to start browsing in 537 {default} default file name 538 An empty string is returned when the "Cancel" button is hit, 539 something went wrong, or browsing is not possible. 540 541 Parameters: ~ 542 • {save} (`any`) 543 • {title} (`string`) 544 • {initdir} (`string`) 545 • {default} (`string`) 546 547 Return: ~ 548 (`0|1`) 549 550 browsedir({title}, {initdir}) *browsedir()* 551 Put up a directory requester. This only works when 552 "has("browse")" returns |TRUE| (only in some GUI versions). 553 On systems where a directory browser is not supported a file 554 browser is used. In that case: select a file in the directory 555 to be used. 556 The input fields are: 557 {title} title for the requester 558 {initdir} directory to start browsing in 559 When the "Cancel" button is hit, something went wrong, or 560 browsing is not possible, an empty string is returned. 561 562 Parameters: ~ 563 • {title} (`string`) 564 • {initdir} (`string`) 565 566 Return: ~ 567 (`0|1`) 568 569 bufadd({name}) *bufadd()* 570 Add a buffer to the buffer list with name {name} (must be a 571 String). 572 If a buffer for file {name} already exists, return that buffer 573 number. Otherwise return the buffer number of the newly 574 created buffer. When {name} is an empty string then a new 575 buffer is always created. 576 The buffer will not have 'buflisted' set and not be loaded 577 yet. To add some text to the buffer use this: >vim 578 let bufnr = bufadd('someName') 579 call bufload(bufnr) 580 call setbufline(bufnr, 1, ['some', 'text']) 581 < Returns 0 on error. 582 583 Parameters: ~ 584 • {name} (`string`) 585 586 Return: ~ 587 (`integer`) 588 589 bufexists({buf}) *bufexists()* 590 The result is a Number, which is |TRUE| if a buffer called 591 {buf} exists. 592 If the {buf} argument is a number, buffer numbers are used. 593 Number zero is the alternate buffer for the current window. 594 595 If the {buf} argument is a string it must match a buffer name 596 exactly. The name can be: 597 - Relative to the current directory. 598 - A full path. 599 - The name of a buffer with 'buftype' set to "nofile". 600 - A URL name. 601 Unlisted buffers will be found. 602 Note that help files are listed by their short name in the 603 output of |:buffers|, but bufexists() requires using their 604 long name to be able to find them. 605 bufexists() may report a buffer exists, but to use the name 606 with a |:buffer| command you may need to use |expand()|. Esp 607 for MS-Windows 8.3 names in the form "c:\DOCUME~1" 608 Use "bufexists(0)" to test for the existence of an alternate 609 file name. 610 611 Parameters: ~ 612 • {buf} (`any`) 613 614 Return: ~ 615 (`0|1`) 616 617 buflisted({buf}) *buflisted()* 618 The result is a Number, which is |TRUE| if a buffer called 619 {buf} exists and is listed (has the 'buflisted' option set). 620 The {buf} argument is used like with |bufexists()|. 621 622 Parameters: ~ 623 • {buf} (`any`) 624 625 Return: ~ 626 (`0|1`) 627 628 bufload({buf}) *bufload()* 629 Ensure the buffer {buf} is loaded. When the buffer name 630 refers to an existing file then the file is read. Otherwise 631 the buffer will be empty. If the buffer was already loaded 632 then there is no change. If the buffer is not related to a 633 file then no file is read (e.g., when 'buftype' is "nofile"). 634 If there is an existing swap file for the file of the buffer, 635 there will be no dialog, the buffer will be loaded anyway. 636 The {buf} argument is used like with |bufexists()|. 637 638 Parameters: ~ 639 • {buf} (`any`) 640 641 bufloaded({buf}) *bufloaded()* 642 The result is a Number, which is |TRUE| if a buffer called 643 {buf} exists and is loaded (shown in a window or hidden). 644 The {buf} argument is used like with |bufexists()|. 645 646 Parameters: ~ 647 • {buf} (`any`) 648 649 Return: ~ 650 (`0|1`) 651 652 bufname([{buf}]) *bufname()* 653 The result is the name of a buffer. Mostly as it is displayed 654 by the `:ls` command, but not using special names such as 655 "[No Name]". 656 If {buf} is omitted the current buffer is used. 657 If {buf} is a Number, that buffer number's name is given. 658 Number zero is the alternate buffer for the current window. 659 If {buf} is a String, it is used as a |file-pattern| to match 660 with the buffer names. This is always done like 'magic' is 661 set and 'cpoptions' is empty. When there is more than one 662 match an empty string is returned. 663 "" or "%" can be used for the current buffer, "#" for the 664 alternate buffer. 665 A full match is preferred, otherwise a match at the start, end 666 or middle of the buffer name is accepted. If you only want a 667 full match then put "^" at the start and "$" at the end of the 668 pattern. 669 Listed buffers are found first. If there is a single match 670 with a listed buffer, that one is returned. Next unlisted 671 buffers are searched for. 672 If the {buf} is a String, but you want to use it as a buffer 673 number, force it to be a Number by adding zero to it: >vim 674 echo bufname("3" + 0) 675 < If the buffer doesn't exist, or doesn't have a name, an empty 676 string is returned. >vim 677 echo bufname("#") " alternate buffer name 678 echo bufname(3) " name of buffer 3 679 echo bufname("%") " name of current buffer 680 echo bufname("file2") " name of buffer where "file2" matches. 681 < 682 683 Parameters: ~ 684 • {buf} (`integer|string?`) 685 686 Return: ~ 687 (`string`) 688 689 bufnr([{buf} [, {create}]]) *bufnr()* 690 The result is the number of a buffer, as it is displayed by 691 the `:ls` command. For the use of {buf}, see |bufname()| 692 above. 693 If the buffer doesn't exist, -1 is returned. Or, if the 694 {create} argument is present and TRUE, a new, unlisted, 695 buffer is created and its number is returned. Example: >vim 696 let newbuf = bufnr('Scratch001', 1) 697 < Using an empty name uses the current buffer. To create a new 698 buffer with an empty name use |bufadd()|. 699 700 bufnr("$") is the last buffer: >vim 701 let last_buffer = bufnr("$") 702 < The result is a Number, which is the highest buffer number 703 of existing buffers. Note that not all buffers with a smaller 704 number necessarily exist, because ":bwipeout" may have removed 705 them. Use |bufexists()| to test for the existence of a buffer. 706 707 Parameters: ~ 708 • {buf} (`integer|string?`) 709 • {create} (`any?`) 710 711 Return: ~ 712 (`integer`) 713 714 bufwinid({buf}) *bufwinid()* 715 The result is a Number, which is the |window-ID| of the first 716 window associated with buffer {buf}. For the use of {buf}, 717 see |bufname()| above. If buffer {buf} doesn't exist or 718 there is no such window, -1 is returned. Example: >vim 719 720 echo "A window containing buffer 1 is " .. (bufwinid(1)) 721 < 722 Only deals with the current tab page. See |win_findbuf()| for 723 finding more. 724 725 Parameters: ~ 726 • {buf} (`any`) 727 728 Return: ~ 729 (`integer`) 730 731 bufwinnr({buf}) *bufwinnr()* 732 Like |bufwinid()| but return the window number instead of the 733 |window-ID|. 734 If buffer {buf} doesn't exist or there is no such window, -1 735 is returned. Example: >vim 736 737 echo "A window containing buffer 1 is " .. (bufwinnr(1)) 738 739 < The number can be used with |CTRL-W_w| and ":wincmd w" 740 |:wincmd|. 741 742 Parameters: ~ 743 • {buf} (`any`) 744 745 Return: ~ 746 (`integer`) 747 748 byte2line({byte}) *byte2line()* 749 Return the line number that contains the character at byte 750 count {byte} in the current buffer. This includes the 751 end-of-line character, depending on the 'fileformat' option 752 for the current buffer. The first character has byte count 753 one. 754 Also see |line2byte()|, |go| and |:goto|. 755 756 Returns -1 if the {byte} value is invalid. 757 758 Parameters: ~ 759 • {byte} (`any`) 760 761 Return: ~ 762 (`integer`) 763 764 byteidx({expr}, {nr} [, {utf16}]) *byteidx()* 765 Return byte index of the {nr}th character in the String 766 {expr}. Use zero for the first character, it then returns 767 zero. 768 If there are no multibyte characters the returned value is 769 equal to {nr}. 770 Composing characters are not counted separately, their byte 771 length is added to the preceding base character. See 772 |byteidxcomp()| below for counting composing characters 773 separately. 774 When {utf16} is present and TRUE, {nr} is used as the UTF-16 775 index in the String {expr} instead of as the character index. 776 The UTF-16 index is the index in the string when it is encoded 777 with 16-bit words. If the specified UTF-16 index is in the 778 middle of a character (e.g. in a 4-byte character), then the 779 byte index of the first byte in the character is returned. 780 Refer to |string-offset-encoding| for more information. 781 Example : >vim 782 echo matchstr(str, ".", byteidx(str, 3)) 783 < will display the fourth character. Another way to do the 784 same: >vim 785 let s = strpart(str, byteidx(str, 3)) 786 echo strpart(s, 0, byteidx(s, 1)) 787 < Also see |strgetchar()| and |strcharpart()|. 788 789 If there are less than {nr} characters -1 is returned. 790 If there are exactly {nr} characters the length of the string 791 in bytes is returned. 792 See |charidx()| and |utf16idx()| for getting the character and 793 UTF-16 index respectively from the byte index. 794 Examples: >vim 795 echo byteidx('a😊😊', 2) " returns 5 796 echo byteidx('a😊😊', 2, 1) " returns 1 797 echo byteidx('a😊😊', 3, 1) " returns 5 798 < 799 800 Parameters: ~ 801 • {expr} (`any`) 802 • {nr} (`integer`) 803 • {utf16} (`any?`) 804 805 Return: ~ 806 (`integer`) 807 808 byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()* 809 Like |byteidx()|, except that a composing character is counted 810 as a separate character. Example: >vim 811 let s = 'e' .. nr2char(0x301) 812 echo byteidx(s, 1) 813 echo byteidxcomp(s, 1) 814 echo byteidxcomp(s, 2) 815 < The first and third echo result in 3 ('e' plus composing 816 character is 3 bytes), the second echo results in 1 ('e' is 817 one byte). 818 819 Parameters: ~ 820 • {expr} (`any`) 821 • {nr} (`integer`) 822 • {utf16} (`any?`) 823 824 Return: ~ 825 (`integer`) 826 827 call({func}, {arglist} [, {dict}]) *call()* *E699* 828 Call function {func} with the items in |List| {arglist} as 829 arguments. 830 {func} can either be a |Funcref| or the name of a function. 831 a:firstline and a:lastline are set to the cursor line. 832 Returns the return value of the called function. 833 {dict} is for functions with the "dict" attribute. It will be 834 used to set the local variable "self". |Dictionary-function| 835 836 Parameters: ~ 837 • {func} (`any`) 838 • {arglist} (`any`) 839 • {dict} (`any?`) 840 841 Return: ~ 842 (`any`) 843 844 ceil({expr}) *ceil()* 845 Return the smallest integral value greater than or equal to 846 {expr} as a |Float| (round up). 847 {expr} must evaluate to a |Float| or a |Number|. 848 Examples: >vim 849 echo ceil(1.456) 850 < 2.0 >vim 851 echo ceil(-5.456) 852 < -5.0 >vim 853 echo ceil(4.0) 854 < 4.0 855 856 Returns 0.0 if {expr} is not a |Float| or a |Number|. 857 858 Parameters: ~ 859 • {expr} (`number`) 860 861 Return: ~ 862 (`number`) 863 864 chanclose({id} [, {stream}]) *chanclose()* 865 Close a channel or a specific stream associated with it. 866 For a job, {stream} can be one of "stdin", "stdout", 867 "stderr" or "rpc" (closes stdin/stdout for a job started 868 with `"rpc":v:true`) If {stream} is omitted, all streams 869 are closed. If the channel is a pty, this will then close the 870 pty master, sending SIGHUP to the job process. 871 For a socket, there is only one stream, and {stream} should be 872 omitted. 873 874 Parameters: ~ 875 • {id} (`integer`) 876 • {stream} (`string?`) 877 878 Return: ~ 879 (`0|1`) 880 881 changenr() *changenr()* 882 Return the number of the most recent change. This is the same 883 number as what is displayed with |:undolist| and can be used 884 with the |:undo| command. 885 When a change was made it is the number of that change. After 886 redo it is the number of the redone change. After undo it is 887 one less than the number of the undone change. 888 Returns 0 if the undo list is empty. 889 890 Return: ~ 891 (`integer`) 892 893 chansend({id}, {data}) *chansend()* 894 Send data to channel {id}. For a job, it writes it to the 895 stdin of the process. For the stdio channel |channel-stdio|, 896 it writes to Nvim's stdout. Returns the number of bytes 897 written if the write succeeded, 0 otherwise. 898 See |channel-bytes| for more information. 899 900 {data} may be a string, string convertible, |Blob|, or a list. 901 If {data} is a list, the items will be joined by newlines; any 902 newlines in an item will be sent as NUL. To send a final 903 newline, include a final empty string. Example: >vim 904 call chansend(id, ["abc", "123\n456", ""]) 905 < will send "abc<NL>123<NUL>456<NL>". 906 907 chansend() writes raw data, not RPC messages. If the channel 908 was created with `"rpc":v:true` then the channel expects RPC 909 messages, use |rpcnotify()| and |rpcrequest()| instead. 910 911 Parameters: ~ 912 • {id} (`number`) 913 • {data} (`string|string[]`) 914 915 Return: ~ 916 (`0|1`) 917 918 char2nr({string} [, {utf8}]) *char2nr()* 919 Return Number value of the first char in {string}. 920 Examples: >vim 921 echo char2nr(" ") " returns 32 922 echo char2nr("ABC") " returns 65 923 echo char2nr("á") " returns 225 924 echo char2nr("á"[0]) " returns 195 925 echo char2nr("\<M-x>") " returns 128 926 < Non-ASCII characters are always treated as UTF-8 characters. 927 {utf8} is ignored, it exists only for backwards-compatibility. 928 A combining character is a separate character. 929 |nr2char()| does the opposite. 930 931 Returns 0 if {string} is not a |String|. 932 933 Parameters: ~ 934 • {string} (`string`) 935 • {utf8} (`any?`) 936 937 Return: ~ 938 (`0|1`) 939 940 charclass({string}) *charclass()* 941 Return the character class of the first character in {string}. 942 The character class is one of: 943 0 blank 944 1 punctuation 945 2 word character (depends on 'iskeyword') 946 3 emoji 947 other specific Unicode class 948 The class is used in patterns and word motions. 949 Returns 0 if {string} is not a |String|. 950 951 Parameters: ~ 952 • {string} (`string`) 953 954 Return: ~ 955 (`0|1|2|3|'other'`) 956 957 charcol({expr} [, {winid}]) *charcol()* 958 Same as |col()| but returns the character index of the column 959 position given with {expr} instead of the byte position. 960 961 Example: 962 With the cursor on '세' in line 5 with text "여보세요": >vim 963 echo charcol('.') " returns 3 964 echo col('.') " returns 7 965 < 966 967 Parameters: ~ 968 • {expr} (`string|any[]`) 969 • {winid} (`integer?`) 970 971 Return: ~ 972 (`integer`) 973 974 charidx({string}, {idx} [, {countcc} [, {utf16}]]) *charidx()* 975 Return the character index of the byte at {idx} in {string}. 976 The index of the first character is zero. 977 If there are no multibyte characters the returned value is 978 equal to {idx}. 979 980 When {countcc} is omitted or |FALSE|, then composing characters 981 are not counted separately, their byte length is added to the 982 preceding base character. 983 When {countcc} is |TRUE|, then composing characters are 984 counted as separate characters. 985 986 When {utf16} is present and TRUE, {idx} is used as the UTF-16 987 index in the String {expr} instead of as the byte index. 988 989 Returns -1 if the arguments are invalid or if there are less 990 than {idx} bytes. If there are exactly {idx} bytes the length 991 of the string in characters is returned. 992 993 An error is given and -1 is returned if the first argument is 994 not a string, the second argument is not a number or when the 995 third argument is present and is not zero or one. 996 997 See |byteidx()| and |byteidxcomp()| for getting the byte index 998 from the character index and |utf16idx()| for getting the 999 UTF-16 index from the character index. 1000 Refer to |string-offset-encoding| for more information. 1001 Examples: >vim 1002 echo charidx('áb́ć', 3) " returns 1 1003 echo charidx('áb́ć', 6, 1) " returns 4 1004 echo charidx('áb́ć', 16) " returns -1 1005 echo charidx('a😊😊', 4, 0, 1) " returns 2 1006 < 1007 1008 Parameters: ~ 1009 • {string} (`string`) 1010 • {idx} (`integer`) 1011 • {countcc} (`boolean?`) 1012 • {utf16} (`boolean?`) 1013 1014 Return: ~ 1015 (`integer`) 1016 1017 chdir({dir} [, {scope}]) *chdir()* 1018 Changes the current working directory to {dir}. The scope of 1019 the change is determined as follows: 1020 If {scope} is not present, the current working directory is 1021 changed to the scope of the current directory: 1022 - If the window local directory (|:lcd|) is set, it 1023 changes the current working directory for that scope. 1024 - Otherwise, if the tab page local directory (|:tcd|) is 1025 set, it changes the current directory for that scope. 1026 - Otherwise, changes the global directory for that scope. 1027 1028 If {scope} is present, changes the current working directory 1029 for the specified scope: 1030 "window" Changes the window local directory. |:lcd| 1031 "tabpage" Changes the tab page local directory. |:tcd| 1032 "global" Changes the global directory. |:cd| 1033 1034 {dir} must be a String. 1035 If successful, returns the previous working directory. Pass 1036 this to another chdir() to restore the directory. 1037 On failure, returns an empty string. 1038 1039 Example: >vim 1040 let save_dir = chdir(newdir) 1041 if save_dir != "" 1042 " ... do some work 1043 call chdir(save_dir) 1044 endif 1045 < 1046 1047 Parameters: ~ 1048 • {dir} (`string`) 1049 • {scope} (`string?`) 1050 1051 Return: ~ 1052 (`string`) 1053 1054 cindent({lnum}) *cindent()* 1055 Get the amount of indent for line {lnum} according the 1056 |C-indenting| rules, as with 'cindent'. 1057 The indent is counted in spaces, the value of 'tabstop' is 1058 relevant. {lnum} is used just like in |getline()|. 1059 When {lnum} is invalid -1 is returned. 1060 1061 To get or set indent of lines in a string, see |vim.text.indent()|. 1062 1063 Parameters: ~ 1064 • {lnum} (`integer|string`) 1065 1066 Return: ~ 1067 (`integer`) 1068 1069 clearmatches([{win}]) *clearmatches()* 1070 Clears all matches previously defined for the current window 1071 by |matchadd()| and the |:match| commands. 1072 If {win} is specified, use the window with this number or 1073 window ID instead of the current window. 1074 1075 Parameters: ~ 1076 • {win} (`integer?`) 1077 1078 cmdcomplete_info() *cmdcomplete_info()* 1079 Returns a |Dictionary| with information about cmdline 1080 completion. See |cmdline-completion|. 1081 The items are: 1082 cmdline_orig The original command-line string before 1083 completion began. 1084 pum_visible |TRUE| if popup menu is visible. 1085 See |pumvisible()|. 1086 matches List of all completion candidates. Each item 1087 is a string. 1088 selected Selected item index. First index is zero. 1089 Index is -1 if no item is selected (showing 1090 typed text only, or the last completion after 1091 no item is selected when using the <Up> or 1092 <Down> keys) 1093 1094 Returns an empty |Dictionary| if no completion was attempted, 1095 if there was only one candidate and it was fully completed, or 1096 if an error occurred. 1097 1098 Return: ~ 1099 (`table<string,any>`) 1100 1101 col({expr} [, {winid}]) *col()* 1102 The result is a Number, which is the byte index of the column 1103 position given with {expr}. 1104 For accepted positions see |getpos()|. 1105 When {expr} is "$", it means the end of the cursor line, so 1106 the result is the number of bytes in the cursor line plus one. 1107 Additionally {expr} can be [lnum, col]: a |List| with the line 1108 and column number. Most useful when the column is "$", to get 1109 the last column of a specific line. When "lnum" or "col" is 1110 out of range then col() returns zero. 1111 1112 With the optional {winid} argument the values are obtained for 1113 that window instead of the current window. 1114 1115 To get the line number use |line()|. To get both use 1116 |getpos()|. 1117 1118 For the screen column position use |virtcol()|. For the 1119 character position use |charcol()|. 1120 1121 Note that only marks in the current file can be used. 1122 1123 Examples: >vim 1124 echo col(".") " column of cursor 1125 echo col("$") " length of cursor line plus one 1126 echo col("'t") " column of mark t 1127 echo col("'" .. markname) " column of mark markname 1128 < 1129 The first column is 1. Returns 0 if {expr} is invalid or when 1130 the window with ID {winid} is not found. 1131 For an uppercase mark the column may actually be in another 1132 buffer. 1133 For the cursor position, when 'virtualedit' is active, the 1134 column is one higher if the cursor is after the end of the 1135 line. Also, when using a <Cmd> mapping the cursor isn't 1136 moved, this can be used to obtain the column in Insert mode: >vim 1137 imap <F2> <Cmd>echo col(".").."\n"<CR> 1138 < 1139 1140 Parameters: ~ 1141 • {expr} (`string|any[]`) 1142 • {winid} (`integer?`) 1143 1144 Return: ~ 1145 (`integer`) 1146 1147 complete({startcol}, {matches}) *complete()* *E785* 1148 Set the matches for Insert mode completion. Can only be used 1149 in Insert mode. Typically invoked from a mapping with 1150 CTRL-R = (see |i_CTRL-R|), but may also be called from a 1151 |<Cmd>| mapping. It does not work after CTRL-O or with an 1152 expression mapping. 1153 {startcol} is the byte offset in the line where the completed 1154 text start. The text up to the cursor is the original text 1155 that will be replaced by the matches. Use col('.') for an 1156 empty string. "col('.') - 1" will replace one character by a 1157 match. 1158 {matches} must be a |List|. Each |List| item is one match. 1159 See |complete-items| for the kind of items that are possible. 1160 "longest" in 'completeopt' is ignored. 1161 Note that the after calling this function you need to avoid 1162 inserting anything that would cause completion to stop. 1163 The match can be selected with CTRL-N and CTRL-P as usual with 1164 Insert mode completion. The popup menu will appear if 1165 specified, see |ins-completion-menu|. 1166 Example: >vim 1167 1168 inoremap <F5> <C-R>=ListMonths()<CR> 1169 1170 func ListMonths() 1171 call complete(col('.'), ['January', 'February', 'March', 1172 \ 'April', 'May', 'June', 'July', 'August', 1173 \ 'September', 'October', 'November', 'December']) 1174 return '' 1175 endfunc 1176 1177 < This isn't very useful, but it shows how it works. Note that 1178 an empty string is returned to avoid a zero being inserted. 1179 1180 Parameters: ~ 1181 • {startcol} (`integer`) 1182 • {matches} (`any[]`) 1183 1184 complete_add({expr}) *complete_add()* 1185 Add {expr} to the list of matches. Only to be used by the 1186 function specified with the 'completefunc' option. 1187 Returns 0 for failure (empty string or out of memory), 1188 1 when the match was added, 2 when the match was already in 1189 the list. 1190 See |complete-functions| for an explanation of {expr}. It is 1191 the same as one item in the list that 'omnifunc' would return. 1192 1193 Parameters: ~ 1194 • {expr} (`any`) 1195 1196 Return: ~ 1197 (`0|1|2`) 1198 1199 complete_check() *complete_check()* 1200 Check for a key typed while looking for completion matches. 1201 This is to be used when looking for matches takes some time. 1202 Returns |TRUE| when searching for matches is to be aborted, 1203 zero otherwise. 1204 Only to be used by the function specified with the 1205 'completefunc' option. 1206 1207 Return: ~ 1208 (`0|1`) 1209 1210 complete_info([{what}]) *complete_info()* 1211 Returns a |Dictionary| with information about Insert mode 1212 completion. See |ins-completion|. 1213 The items are: 1214 completed Return a dictionary containing the entries of 1215 the currently selected index item. 1216 items List of all completion candidates. Each item 1217 is a dictionary containing the entries "word", 1218 "abbr", "menu", "kind", "info" and 1219 "user_data". 1220 See |complete-items|. 1221 matches Same as "items", but only returns items that 1222 are matching current query. If both "matches" 1223 and "items" are in "what", the returned list 1224 will still be named "items", but each item 1225 will have an additional "match" field. 1226 mode Current completion mode name string. 1227 See |complete_info_mode| for the values. 1228 preinserted_text 1229 The actual text that is pre-inserted, see 1230 |preinserted()|. 1231 pum_visible |TRUE| if popup menu is visible. 1232 See |pumvisible()|. 1233 selected Selected item index. First index is zero. 1234 Index is -1 if no item is selected (showing 1235 typed text only, or the last completion after 1236 no item is selected when using the <Up> or 1237 <Down> keys) 1238 preview_winid Info floating preview window id. 1239 preview_bufnr Info floating preview buffer id. 1240 1241 *complete_info_mode* 1242 mode values are: 1243 "" Not in completion mode 1244 "keyword" Keyword completion |i_CTRL-X_CTRL-N| 1245 "ctrl_x" Just pressed CTRL-X |i_CTRL-X| 1246 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or 1247 |i_CTRL-X_CTRL-Y| 1248 "whole_line" Whole lines |i_CTRL-X_CTRL-L| 1249 "files" File names |i_CTRL-X_CTRL-F| 1250 "tags" Tags |i_CTRL-X_CTRL-]| 1251 "path_defines" Definition completion |i_CTRL-X_CTRL-D| 1252 "path_patterns" Include completion |i_CTRL-X_CTRL-I| 1253 "dictionary" Dictionary |i_CTRL-X_CTRL-K| 1254 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T| 1255 "cmdline" Vim Command line |i_CTRL-X_CTRL-V| 1256 "function" User defined completion |i_CTRL-X_CTRL-U| 1257 "omni" Omni completion |i_CTRL-X_CTRL-O| 1258 "spell" Spelling suggestions |i_CTRL-X_s| 1259 "eval" |complete()| completion 1260 "register" Words from registers |i_CTRL-X_CTRL-R| 1261 "unknown" Other internal modes 1262 1263 If the optional {what} list argument is supplied, then only 1264 the items listed in {what} are returned. Unsupported items in 1265 {what} are silently ignored. 1266 1267 To get the position and size of the popup menu, see 1268 |pum_getpos()|. It's also available in |v:event| during the 1269 |CompleteChanged| event. 1270 1271 Returns an empty |Dictionary| on error. 1272 1273 Examples: >vim 1274 " Get all items 1275 call complete_info() 1276 " Get only 'mode' 1277 call complete_info(['mode']) 1278 " Get only 'mode' and 'pum_visible' 1279 call complete_info(['mode', 'pum_visible']) 1280 < 1281 1282 Parameters: ~ 1283 • {what} (`any[]?`) 1284 1285 Return: ~ 1286 (`table`) 1287 1288 confirm({msg} [, {choices} [, {default} [, {type}]]]) *confirm()* 1289 confirm() offers the user a dialog, from which a choice can be 1290 made. It returns the number of the choice. For the first 1291 choice this is 1. 1292 1293 {msg} is displayed in a dialog with {choices} as the 1294 alternatives. When {choices} is missing or empty, "&OK" is 1295 used (and translated). 1296 {msg} is a String, use '\n' to include a newline. Only on 1297 some systems the string is wrapped when it doesn't fit. 1298 1299 {choices} is a String, with the individual choices separated 1300 by '\n', e.g. >vim 1301 confirm("Save changes?", "&Yes\n&No\n&Cancel") 1302 < The letter after the '&' is the shortcut key for that choice. 1303 Thus you can type 'c' to select "Cancel". The shortcut does 1304 not need to be the first letter: >vim 1305 confirm("file has been modified", "&Save\nSave &All") 1306 < For the console, the first letter of each choice is used as 1307 the default shortcut key. Case is ignored. 1308 1309 The optional {type} String argument gives the type of dialog. 1310 It can be one of these values: "Error", "Question", "Info", 1311 "Warning" or "Generic". Only the first character is relevant. 1312 When {type} is omitted, "Generic" is used. 1313 1314 The optional {type} argument gives the type of dialog. This 1315 is only used for the icon of the Win32 GUI. It can be one of 1316 these values: "Error", "Question", "Info", "Warning" or 1317 "Generic". Only the first character is relevant. 1318 When {type} is omitted, "Generic" is used. 1319 1320 If the user aborts the dialog by pressing <Esc>, CTRL-C, 1321 or another valid interrupt key, confirm() returns 0. 1322 1323 An example: >vim 1324 let choice = confirm("What do you want?", 1325 \ "&Apples\n&Oranges\n&Bananas", 2) 1326 if choice == 0 1327 echo "make up your mind!" 1328 elseif choice == 3 1329 echo "tasteful" 1330 else 1331 echo "I prefer bananas myself." 1332 endif 1333 < In a GUI dialog, buttons are used. The layout of the buttons 1334 depends on the 'v' flag in 'guioptions'. If it is included, 1335 the buttons are always put vertically. Otherwise, confirm() 1336 tries to put the buttons in one horizontal line. If they 1337 don't fit, a vertical layout is used anyway. For some systems 1338 the horizontal layout is always used. 1339 1340 Parameters: ~ 1341 • {msg} (`string`) 1342 • {choices} (`string?`) 1343 • {default} (`integer?`) 1344 • {type} (`string?`) 1345 1346 Return: ~ 1347 (`integer`) 1348 1349 copy({expr}) *copy()* 1350 Make a copy of {expr}. For Numbers and Strings this isn't 1351 different from using {expr} directly. 1352 When {expr} is a |List| a shallow copy is created. This means 1353 that the original |List| can be changed without changing the 1354 copy, and vice versa. But the items are identical, thus 1355 changing an item changes the contents of both |Lists|. 1356 A |Dictionary| is copied in a similar way as a |List|. 1357 Also see |deepcopy()|. 1358 1359 Parameters: ~ 1360 • {expr} (`T`) 1361 1362 Return: ~ 1363 (`T`) 1364 1365 cos({expr}) *cos()* 1366 Return the cosine of {expr}, measured in radians, as a |Float|. 1367 {expr} must evaluate to a |Float| or a |Number|. 1368 Returns 0.0 if {expr} is not a |Float| or a |Number|. 1369 Examples: >vim 1370 echo cos(100) 1371 < 0.862319 >vim 1372 echo cos(-4.01) 1373 < -0.646043 1374 1375 Parameters: ~ 1376 • {expr} (`number`) 1377 1378 Return: ~ 1379 (`number`) 1380 1381 cosh({expr}) *cosh()* 1382 Return the hyperbolic cosine of {expr} as a |Float| in the range 1383 [1, inf]. 1384 {expr} must evaluate to a |Float| or a |Number|. 1385 Returns 0.0 if {expr} is not a |Float| or a |Number|. 1386 Examples: >vim 1387 echo cosh(0.5) 1388 < 1.127626 >vim 1389 echo cosh(-0.5) 1390 < -1.127626 1391 1392 Parameters: ~ 1393 • {expr} (`number`) 1394 1395 Return: ~ 1396 (`number`) 1397 1398 count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706* 1399 Return the number of times an item with value {expr} appears 1400 in |String|, |List| or |Dictionary| {comp}. 1401 1402 If {start} is given then start with the item with this index. 1403 {start} can only be used with a |List|. 1404 1405 When {ic} is given and it's |TRUE| then case is ignored. 1406 1407 When {comp} is a string then the number of not overlapping 1408 occurrences of {expr} is returned. Zero is returned when 1409 {expr} is an empty string. 1410 1411 Parameters: ~ 1412 • {comp} (`string|table|any[]`) 1413 • {expr} (`any`) 1414 • {ic} (`boolean?`) 1415 • {start} (`integer?`) 1416 1417 Return: ~ 1418 (`integer`) 1419 1420 ctxget([{index}]) *ctxget()* 1421 Returns a |Dictionary| representing the |context| at {index} 1422 from the top of the |context-stack| (see |context-dict|). 1423 If {index} is not given, it is assumed to be 0 (i.e.: top). 1424 1425 Parameters: ~ 1426 • {index} (`integer?`) 1427 1428 Return: ~ 1429 (`table`) 1430 1431 ctxpop() *ctxpop()* 1432 Pops and restores the |context| at the top of the 1433 |context-stack|. 1434 1435 Return: ~ 1436 (`any`) 1437 1438 ctxpush([{types}]) *ctxpush()* 1439 Pushes the current editor state (|context|) on the 1440 |context-stack|. 1441 If {types} is given and is a |List| of |String|s, it specifies 1442 which |context-types| to include in the pushed context. 1443 Otherwise, all context types are included. 1444 1445 Parameters: ~ 1446 • {types} (`string[]?`) 1447 1448 Return: ~ 1449 (`any`) 1450 1451 ctxset({context} [, {index}]) *ctxset()* 1452 Sets the |context| at {index} from the top of the 1453 |context-stack| to that represented by {context}. 1454 {context} is a Dictionary with context data (|context-dict|). 1455 If {index} is not given, it is assumed to be 0 (i.e.: top). 1456 1457 Parameters: ~ 1458 • {context} (`table`) 1459 • {index} (`integer?`) 1460 1461 Return: ~ 1462 (`integer`) 1463 1464 ctxsize() *ctxsize()* 1465 Returns the size of the |context-stack|. 1466 1467 Return: ~ 1468 (`any`) 1469 1470 cursor({lnum}, {col} [, {off}]) *cursor()* 1471 cursor({list}) 1472 Positions the cursor at the column (byte count) {col} in the 1473 line {lnum}. The first column is one. 1474 1475 When there is one argument {list} this is used as a |List| 1476 with two, three or four item: 1477 [{lnum}, {col}] 1478 [{lnum}, {col}, {off}] 1479 [{lnum}, {col}, {off}, {curswant}] 1480 This is like the return value of |getpos()| or |getcurpos()|, 1481 but without the first item. 1482 1483 To position the cursor using {col} as the character count, use 1484 |setcursorcharpos()|. 1485 1486 Does not change the jumplist. 1487 {lnum} is used like with |getline()|, except that if {lnum} is 1488 zero, the cursor will stay in the current line. 1489 If {lnum} is greater than the number of lines in the buffer, 1490 the cursor will be positioned at the last line in the buffer. 1491 If {col} is greater than the number of bytes in the line, 1492 the cursor will be positioned at the last character in the 1493 line. 1494 If {col} is zero, the cursor will stay in the current column. 1495 If {curswant} is given it is used to set the preferred column 1496 for vertical movement. Otherwise {col} is used. 1497 1498 When 'virtualedit' is used {off} specifies the offset in 1499 screen columns from the start of the character. E.g., a 1500 position within a <Tab> or after the last character. 1501 Returns 0 when the position could be set, -1 otherwise. 1502 1503 Parameters: ~ 1504 • {list} (`integer[]`) 1505 1506 Return: ~ 1507 (`any`) 1508 1509 debugbreak({pid}) *debugbreak()* 1510 Specifically used to interrupt a program being debugged. It 1511 will cause process {pid} to get a SIGTRAP. Behavior for other 1512 processes is undefined. See |terminal-debug|. 1513 (Sends a SIGINT to a process {pid} other than MS-Windows) 1514 1515 Returns |TRUE| if successfully interrupted the program. 1516 Otherwise returns |FALSE|. 1517 1518 Parameters: ~ 1519 • {pid} (`integer`) 1520 1521 Return: ~ 1522 (`any`) 1523 1524 deepcopy({expr} [, {noref}]) *deepcopy()* *E698* 1525 Make a copy of {expr}. For Numbers and Strings this isn't 1526 different from using {expr} directly. 1527 When {expr} is a |List| a full copy is created. This means 1528 that the original |List| can be changed without changing the 1529 copy, and vice versa. When an item is a |List|, a copy for it 1530 is made, recursively. Thus changing an item in the copy does 1531 not change the contents of the original |List|. 1532 1533 When {noref} is omitted or zero a contained |List| or 1534 |Dictionary| is only copied once. All references point to 1535 this single copy. With {noref} set to 1 every occurrence of a 1536 |List| or |Dictionary| results in a new copy. This also means 1537 that a cyclic reference causes deepcopy() to fail. 1538 *E724* 1539 Nesting is possible up to 100 levels. When there is an item 1540 that refers back to a higher level making a deep copy with 1541 {noref} set to 1 will fail. 1542 Also see |copy()|. 1543 1544 Parameters: ~ 1545 • {expr} (`T`) 1546 • {noref} (`boolean?`) 1547 1548 Return: ~ 1549 (`T`) 1550 1551 delete({fname} [, {flags}]) *delete()* 1552 Without {flags} or with {flags} empty: Deletes the file by the 1553 name {fname}. 1554 1555 This also works when {fname} is a symbolic link. The symbolic 1556 link itself is deleted, not what it points to. 1557 1558 When {flags} is "d": Deletes the directory by the name 1559 {fname}. This fails when directory {fname} is not empty. 1560 1561 When {flags} is "rf": Deletes the directory by the name 1562 {fname} and everything in it, recursively. BE CAREFUL! 1563 Note: on MS-Windows it is not possible to delete a directory 1564 that is being used. 1565 1566 The result is a Number, which is 0/false if the delete 1567 operation was successful and -1/true when the deletion failed 1568 or partly failed. 1569 1570 Parameters: ~ 1571 • {fname} (`string`) 1572 • {flags} (`string?`) 1573 1574 Return: ~ 1575 (`integer`) 1576 1577 deletebufline({buf}, {first} [, {last}]) *deletebufline()* 1578 Delete lines {first} to {last} (inclusive) from buffer {buf}. 1579 If {last} is omitted then delete line {first} only. 1580 On success 0 is returned, on failure 1 is returned. 1581 1582 This function works only for loaded buffers. First call 1583 |bufload()| if needed. 1584 1585 For the use of {buf}, see |bufname()| above. 1586 1587 {first} and {last} are used like with |getline()|. Note that 1588 when using |line()| this refers to the current buffer. Use "$" 1589 to refer to the last line in buffer {buf}. 1590 1591 Parameters: ~ 1592 • {buf} (`integer|string`) 1593 • {first} (`integer|string`) 1594 • {last} (`integer|string?`) 1595 1596 Return: ~ 1597 (`any`) 1598 1599 dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()* 1600 Adds a watcher to a dictionary. A dictionary watcher is 1601 identified by three components: 1602 1603 - A dictionary({dict}); 1604 - A key pattern({pattern}). 1605 - A function({callback}). 1606 1607 After this is called, every change on {dict} and on keys 1608 matching {pattern} will result in {callback} being invoked. 1609 1610 For example, to watch all global variables: >vim 1611 silent! call dictwatcherdel(g:, '*', 'OnDictChanged') 1612 function! OnDictChanged(d,k,z) 1613 echomsg string(a:k) string(a:z) 1614 endfunction 1615 call dictwatcheradd(g:, '*', 'OnDictChanged') 1616 < 1617 For now {pattern} only accepts very simple patterns that can 1618 contain a "*" at the end of the string, in which case it will 1619 match every key that begins with the substring before the "*". 1620 That means if "*" is not the last character of {pattern}, only 1621 keys that are exactly equal as {pattern} will be matched. 1622 1623 The {callback} receives three arguments: 1624 1625 - The dictionary being watched. 1626 - The key which changed. 1627 - A dictionary containing the new and old values for the key. 1628 1629 The type of change can be determined by examining the keys 1630 present on the third argument: 1631 1632 - If contains both `old` and `new`, the key was updated. 1633 - If it contains only `new`, the key was added. 1634 - If it contains only `old`, the key was deleted. 1635 1636 This function can be used by plugins to implement options with 1637 validation and parsing logic. 1638 1639 Parameters: ~ 1640 • {dict} (`table`) 1641 • {pattern} (`string`) 1642 • {callback} (`function`) 1643 1644 Return: ~ 1645 (`any`) 1646 1647 dictwatcherdel({dict}, {pattern}, {callback}) *dictwatcherdel()* 1648 Removes a watcher added with |dictwatcheradd()|. All three 1649 arguments must match the ones passed to |dictwatcheradd()| in 1650 order for the watcher to be successfully deleted. 1651 1652 Parameters: ~ 1653 • {dict} (`any`) 1654 • {pattern} (`string`) 1655 • {callback} (`function`) 1656 1657 Return: ~ 1658 (`any`) 1659 1660 did_filetype() *did_filetype()* 1661 Returns |TRUE| when autocommands are being executed and the 1662 FileType event has been triggered at least once. Can be used 1663 to avoid triggering the FileType event again in the scripts 1664 that detect the file type. |FileType| 1665 Returns |FALSE| when `:setf FALLBACK` was used. 1666 When editing another file, the counter is reset, thus this 1667 really checks if the FileType event has been triggered for the 1668 current buffer. This allows an autocommand that starts 1669 editing another buffer to set 'filetype' and load a syntax 1670 file. 1671 1672 Return: ~ 1673 (`integer`) 1674 1675 diff_filler({lnum}) *diff_filler()* 1676 Returns the number of filler lines above line {lnum}. 1677 These are the lines that were inserted at this point in 1678 another diff'ed window. These filler lines are shown in the 1679 display but don't exist in the buffer. 1680 {lnum} is used like with |getline()|. Thus "." is the current 1681 line, "'m" mark m, etc. 1682 Returns 0 if the current window is not in diff mode. 1683 1684 Parameters: ~ 1685 • {lnum} (`integer|string`) 1686 1687 Return: ~ 1688 (`integer`) 1689 1690 diff_hlID({lnum}, {col}) *diff_hlID()* 1691 Returns the highlight ID for diff mode at line {lnum} column 1692 {col} (byte index). When the current line does not have a 1693 diff change zero is returned. 1694 {lnum} is used like with |getline()|. Thus "." is the current 1695 line, "'m" mark m, etc. 1696 {col} is 1 for the leftmost column, {lnum} is 1 for the first 1697 line. 1698 The highlight ID can be used with |synIDattr()| to obtain 1699 syntax information about the highlighting. 1700 1701 Parameters: ~ 1702 • {lnum} (`integer|string`) 1703 • {col} (`integer`) 1704 1705 Return: ~ 1706 (`any`) 1707 1708 digraph_get({chars}) *digraph_get()* *E1214* 1709 Return the digraph of {chars}. This should be a string with 1710 exactly two characters. If {chars} are not just two 1711 characters, or the digraph of {chars} does not exist, an error 1712 is given and an empty string is returned. 1713 1714 Also see |digraph_getlist()|. 1715 1716 Examples: >vim 1717 " Get a built-in digraph 1718 echo digraph_get('00') " Returns '∞' 1719 1720 " Get a user-defined digraph 1721 call digraph_set('aa', 'あ') 1722 echo digraph_get('aa') " Returns 'あ' 1723 < 1724 1725 Parameters: ~ 1726 • {chars} (`string`) 1727 1728 Return: ~ 1729 (`string`) 1730 1731 digraph_getlist([{listall}]) *digraph_getlist()* 1732 Return a list of digraphs. If the {listall} argument is given 1733 and it is TRUE, return all digraphs, including the default 1734 digraphs. Otherwise, return only user-defined digraphs. 1735 1736 Also see |digraph_get()|. 1737 1738 Examples: >vim 1739 " Get user-defined digraphs 1740 echo digraph_getlist() 1741 1742 " Get all the digraphs, including default digraphs 1743 echo digraph_getlist(1) 1744 < 1745 1746 Parameters: ~ 1747 • {listall} (`boolean?`) 1748 1749 Return: ~ 1750 (`string[][]`) 1751 1752 digraph_set({chars}, {digraph}) *digraph_set()* 1753 Add digraph {chars} to the list. {chars} must be a string 1754 with two characters. {digraph} is a string with one UTF-8 1755 encoded character. *E1215* 1756 Be careful, composing characters are NOT ignored. This 1757 function is similar to |:digraphs| command, but useful to add 1758 digraphs start with a white space. 1759 1760 The function result is v:true if |digraph| is registered. If 1761 this fails an error message is given and v:false is returned. 1762 1763 If you want to define multiple digraphs at once, you can use 1764 |digraph_setlist()|. 1765 1766 Example: >vim 1767 call digraph_set(' ', 'あ') 1768 < 1769 1770 Parameters: ~ 1771 • {chars} (`string`) 1772 • {digraph} (`string`) 1773 1774 Return: ~ 1775 (`any`) 1776 1777 digraph_setlist({digraphlist}) *digraph_setlist()* 1778 Similar to |digraph_set()| but this function can add multiple 1779 digraphs at once. {digraphlist} is a list composed of lists, 1780 where each list contains two strings with {chars} and 1781 {digraph} as in |digraph_set()|. *E1216* 1782 Example: >vim 1783 call digraph_setlist([['aa', 'あ'], ['ii', 'い']]) 1784 < 1785 It is similar to the following: >vim 1786 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']] 1787 call digraph_set(chars, digraph) 1788 endfor 1789 < Except that the function returns after the first error, 1790 following digraphs will not be added. 1791 1792 Parameters: ~ 1793 • {digraphlist} (`table<integer,string[]>`) 1794 1795 Return: ~ 1796 (`any`) 1797 1798 empty({expr}) *empty()* 1799 Return the Number 1 if {expr} is empty, zero otherwise. 1800 - A |List| or |Dictionary| is empty when it does not have any 1801 items. 1802 - A |String| is empty when its length is zero. 1803 - A |Number| and |Float| are empty when their value is zero. 1804 - |v:false| and |v:null| are empty, |v:true| is not. 1805 - A |Blob| is empty when its length is zero. 1806 1807 Parameters: ~ 1808 • {expr} (`any`) 1809 1810 Return: ~ 1811 (`integer`) 1812 1813 environ() *environ()* 1814 Return all of environment variables as dictionary. You can 1815 check if an environment variable exists like this: >vim 1816 echo has_key(environ(), 'HOME') 1817 < Note that the variable name may be CamelCase; to ignore case 1818 use this: >vim 1819 echo index(keys(environ()), 'HOME', 0, 1) != -1 1820 < 1821 1822 Return: ~ 1823 (`any`) 1824 1825 escape({string}, {chars}) *escape()* 1826 Escape the characters in {chars} that occur in {string} with a 1827 backslash. Example: >vim 1828 echo escape('c:\program files\vim', ' \') 1829 < results in: > 1830 c:\\program\ files\\vim 1831 < Also see |shellescape()| and |fnameescape()|. 1832 1833 Parameters: ~ 1834 • {string} (`string`) 1835 • {chars} (`string`) 1836 1837 Return: ~ 1838 (`string`) 1839 1840 eval({string}) *eval()* 1841 Evaluate {string} and return the result. Especially useful to 1842 turn the result of |string()| back into the original value. 1843 This works for Numbers, Floats, Strings, Blobs and composites 1844 of them. Also works for |Funcref|s that refer to existing 1845 functions. 1846 1847 Parameters: ~ 1848 • {string} (`string`) 1849 1850 Return: ~ 1851 (`any`) 1852 1853 eventhandler() *eventhandler()* 1854 Returns 1 when inside an event handler. That is that Vim got 1855 interrupted while waiting for the user to type a character, 1856 e.g., when dropping a file on Vim. This means interactive 1857 commands cannot be used. Otherwise zero is returned. 1858 1859 Return: ~ 1860 (`any`) 1861 1862 executable({expr}) *executable()* 1863 This function checks if an executable with the name {expr} 1864 exists. {expr} must be the name of the program without any 1865 arguments. 1866 1867 executable() uses the value of $PATH and/or the normal 1868 searchpath for programs. 1869 *PATHEXT* 1870 On MS-Windows the ".exe", ".bat", etc. can optionally be 1871 included. Then the extensions in $PATHEXT are tried. Thus if 1872 "foo.exe" does not exist, "foo.exe.bat" can be found. If 1873 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot 1874 by itself can be used in $PATHEXT to try using the name 1875 without an extension. When 'shell' looks like a Unix shell, 1876 then the name is also tried without adding an extension. 1877 On MS-Windows it only checks if the file exists and is not a 1878 directory, not if it's really executable. 1879 1880 On MS-Windows an executable in the same directory as the Vim 1881 executable is always found (it's added to $PATH at |startup|). 1882 *$NoDefaultCurrentDirectoryInExePath* 1883 On MS-Windows when using cmd.exe as 'shell' an executable in 1884 Vim's current working directory is also normally found, which 1885 can be disabled by setting the 1886 `$NoDefaultCurrentDirectoryInExePath` environment variable. 1887 This variable is always set by Vim when executing external 1888 commands (e.g., via |:!|, |:make|, or |system()|) for security 1889 reasons. 1890 1891 The result is a Number: 1892 1 exists 1893 0 does not exist 1894 |exepath()| can be used to get the full path of an executable. 1895 1896 Parameters: ~ 1897 • {expr} (`string`) 1898 1899 Return: ~ 1900 (`0|1`) 1901 1902 execute({command} [, {silent}]) *execute()* 1903 Execute {command} and capture its output. 1904 If {command} is a |String|, returns {command} output. 1905 If {command} is a |List|, returns concatenated outputs. 1906 Line continuations in {command} are not recognized. 1907 Examples: >vim 1908 echo execute('echon "foo"') 1909 < foo >vim 1910 echo execute(['echon "foo"', 'echon "bar"']) 1911 < foobar 1912 1913 The optional {silent} argument can have these values: 1914 "" no `:silent` used 1915 "silent" `:silent` used 1916 "silent!" `:silent!` used 1917 The default is "silent". Note that with "silent!", unlike 1918 `:redir`, error messages are dropped. 1919 1920 To get a list of lines use `split()` on the result: >vim 1921 execute('args')->split("\n") 1922 1923 < This function is not available in the |sandbox|. 1924 Note: If nested, an outer execute() will not observe output of 1925 the inner calls. 1926 Note: Text attributes (highlights) are not captured. 1927 To execute a command in another window than the current one 1928 use `win_execute()`. 1929 1930 Parameters: ~ 1931 • {command} (`string|string[]`) 1932 • {silent} (`''|'silent'|'silent!'?`) 1933 1934 Return: ~ 1935 (`string`) 1936 1937 exepath({expr}) *exepath()* 1938 Returns the full path of {expr} if it is an executable and 1939 given as a (partial or full) path or is found in $PATH. 1940 Returns empty string otherwise. 1941 If {expr} starts with "./" the |current-directory| is used. 1942 1943 Parameters: ~ 1944 • {expr} (`string`) 1945 1946 Return: ~ 1947 (`string`) 1948 1949 exists({expr}) *exists()* 1950 The result is a Number, which is |TRUE| if {expr} is 1951 defined, zero otherwise. 1952 1953 For checking for a supported feature use |has()|. 1954 For checking if a file exists use |filereadable()|. 1955 1956 The {expr} argument is a string, which contains one of these: 1957 varname internal variable (see 1958 dict.key |internal-variables|). Also works 1959 list[i] for |curly-braces-names|, |Dictionary| 1960 entries, |List| items, etc. 1961 Beware that evaluating an index may 1962 cause an error message for an invalid 1963 expression. E.g.: >vim 1964 let l = [1, 2, 3] 1965 echo exists("l[5]") 1966 < 0 >vim 1967 echo exists("l[xx]") 1968 < E121: Undefined variable: xx 1969 0 1970 &option-name Vim option (only checks if it exists, 1971 not if it really works) 1972 +option-name Vim option that works. 1973 $ENVNAME environment variable (could also be 1974 done by comparing with an empty 1975 string) 1976 `*funcname` built-in function (see |functions|) 1977 or user defined function (see 1978 |user-function|). Also works for a 1979 variable that is a Funcref. 1980 :cmdname Ex command: built-in command, user 1981 command or command modifier |:command|. 1982 Returns: 1983 1 for match with start of a command 1984 2 full match with a command 1985 3 matches several user commands 1986 To check for a supported command 1987 always check the return value to be 2. 1988 :2match The |:2match| command. 1989 :3match The |:3match| command (but you 1990 probably should not use it, it is 1991 reserved for internal usage) 1992 #event autocommand defined for this event 1993 #event#pattern autocommand defined for this event and 1994 pattern (the pattern is taken 1995 literally and compared to the 1996 autocommand patterns character by 1997 character) 1998 #group autocommand group exists 1999 #group#event autocommand defined for this group and 2000 event. 2001 #group#event#pattern 2002 autocommand defined for this group, 2003 event and pattern. 2004 ##event autocommand for this event is 2005 supported. 2006 2007 Examples: >vim 2008 echo exists("&mouse") 2009 echo exists("$HOSTNAME") 2010 echo exists("*strftime") 2011 echo exists("*s:MyFunc") 2012 echo exists("*MyFunc") 2013 echo exists("*v:lua.Func") 2014 echo exists("bufcount") 2015 echo exists(":Make") 2016 echo exists("#CursorHold") 2017 echo exists("#BufReadPre#*.gz") 2018 echo exists("#filetypeindent") 2019 echo exists("#filetypeindent#FileType") 2020 echo exists("#filetypeindent#FileType#*") 2021 echo exists("##ColorScheme") 2022 < There must be no space between the symbol (&/$/*/#) and the 2023 name. 2024 There must be no extra characters after the name, although in 2025 a few cases this is ignored. That may become stricter in the 2026 future, thus don't count on it! 2027 Working example: >vim 2028 echo exists(":make") 2029 < NOT working example: >vim 2030 echo exists(":make install") 2031 2032 < Note that the argument must be a string, not the name of the 2033 variable itself. For example: >vim 2034 echo exists(bufcount) 2035 < This doesn't check for existence of the "bufcount" variable, 2036 but gets the value of "bufcount", and checks if that exists. 2037 2038 Parameters: ~ 2039 • {expr} (`string`) 2040 2041 Return: ~ 2042 (`0|1`) 2043 2044 exp({expr}) *exp()* 2045 Return the exponential of {expr} as a |Float| in the range 2046 [0, inf]. 2047 {expr} must evaluate to a |Float| or a |Number|. 2048 Returns 0.0 if {expr} is not a |Float| or a |Number|. 2049 Examples: >vim 2050 echo exp(2) 2051 < 7.389056 >vim 2052 echo exp(-1) 2053 < 0.367879 2054 2055 Parameters: ~ 2056 • {expr} (`number`) 2057 2058 Return: ~ 2059 (`any`) 2060 2061 expand({string} [, {nosuf} [, {list}]]) *expand()* 2062 Expand wildcards and the following special keywords in 2063 {string}. 'wildignorecase' applies. 2064 2065 If {list} is given and it is |TRUE|, a List will be returned. 2066 Otherwise the result is a String and when there are several 2067 matches, they are separated by <NL> characters. 2068 2069 If the expansion fails, the result is an empty string. A name 2070 for a non-existing file is not included, unless {string} does 2071 not start with '%', '#' or '<', see below. 2072 2073 When {string} starts with '%', '#' or '<', the expansion is 2074 done like for the |cmdline-special| variables with their 2075 associated modifiers. Here is a short overview: 2076 2077 % Current file name 2078 # Alternate file name 2079 #n Alternate file name n 2080 <cfile> File name under the cursor 2081 <afile> Autocmd file name 2082 <abuf> Autocmd buffer number (as a String!) 2083 <amatch> Autocmd matched name 2084 <cexpr> C expression under the cursor 2085 <sfile> Deprecated, use <script> or <stack> 2086 <slnum> Sourced script line number or function 2087 line number 2088 <sflnum> Script file line number, also when in 2089 a function 2090 <SID> "<SNR>123_" where "123" is the 2091 current script ID |<SID>| 2092 <script> Sourced script file, or script file 2093 where the current function was defined. 2094 For Lua see |lua-script-location|. 2095 <stack> Call stack 2096 <cword> Word under the cursor 2097 <cWORD> WORD under the cursor 2098 <client> The {clientid} of the last received 2099 message 2100 Modifiers: 2101 :p Expand to full path 2102 :h Head (last path component removed) 2103 :t Tail (last path component only) 2104 :r Root (one extension removed) 2105 :e Extension only 2106 2107 More modifiers are supported, for the full list see 2108 |filename-modifiers|. 2109 2110 Example: >vim 2111 let &tags = expand("%:p:h") .. "/tags" 2112 < Note that when expanding a string that starts with '%', '#' or 2113 '<', any following text is ignored. This does NOT work: >vim 2114 let doesntwork = expand("%:h.bak") 2115 < Use this: >vim 2116 let doeswork = expand("%:h") .. ".bak" 2117 < Also note that expanding "<cfile>" and others only returns the 2118 referenced file name without further expansion. If "<cfile>" 2119 is "~/.cshrc", you need to do another expand() to have the 2120 "~/" expanded into the path of the home directory: >vim 2121 echo expand(expand("<cfile>")) 2122 < 2123 There cannot be white space between the variables and the 2124 following modifier. The |fnamemodify()| function can be used 2125 to modify normal file names. 2126 2127 When using '%' or '#', and the current or alternate file name 2128 is not defined, an empty string is used. Using "%:p" in a 2129 buffer with no name, results in the current directory, with a 2130 '/' added. 2131 When 'verbose' is set then expanding '%', '#' and <> items 2132 will result in an error message if the argument cannot be 2133 expanded. 2134 2135 When {string} does not start with '%', '#' or '<', it is 2136 expanded like a file name is expanded on the command line. 2137 'suffixes' and 'wildignore' are used, unless the optional 2138 {nosuf} argument is given and it is |TRUE|. 2139 Names for non-existing files are included. The "**" item can 2140 be used to search in a directory tree. For example, to find 2141 all "README" files in the current directory and below: >vim 2142 echo expand("**/README") 2143 < 2144 expand() can also be used to expand variables and environment 2145 variables that are only known in a shell. But this can be 2146 slow, because a shell may be used to do the expansion. See 2147 |expr-env-expand|. 2148 The expanded variable is still handled like a list of file 2149 names. When an environment variable cannot be expanded, it is 2150 left unchanged. Thus ":echo expand('$FOOBAR')" results in 2151 "$FOOBAR". 2152 2153 See |glob()| for finding existing files. See |system()| for 2154 getting the raw output of an external command. 2155 2156 Parameters: ~ 2157 • {string} (`string`) 2158 • {nosuf} (`boolean?`) 2159 • {list} (`nil|false?`) 2160 2161 Return: ~ 2162 (`string`) 2163 2164 expandcmd({string} [, {options}]) *expandcmd()* 2165 Expand special items in String {string} like what is done for 2166 an Ex command such as `:edit`. This expands special keywords, 2167 like with |expand()|, and environment variables, anywhere in 2168 {string}. "~user" and "~/path" are only expanded at the 2169 start. 2170 2171 The following items are supported in the {options} Dict 2172 argument: 2173 errmsg If set to TRUE, error messages are displayed 2174 if an error is encountered during expansion. 2175 By default, error messages are not displayed. 2176 2177 Returns the expanded string. If an error is encountered 2178 during expansion, the unmodified {string} is returned. 2179 2180 Example: >vim 2181 echo expandcmd('make %<.o') 2182 < > 2183 make /path/runtime/doc/builtin.o 2184 < >vim 2185 echo expandcmd('make %<.o', {'errmsg': v:true}) 2186 < 2187 2188 Parameters: ~ 2189 • {string} (`string`) 2190 • {options} (`table?`) 2191 2192 Return: ~ 2193 (`any`) 2194 2195 extend({expr1}, {expr2} [, {expr3}]) *extend()* 2196 {expr1} and {expr2} must be both |Lists| or both 2197 |Dictionaries|. 2198 2199 If they are |Lists|: Append {expr2} to {expr1}. 2200 If {expr3} is given insert the items of {expr2} before the 2201 item with index {expr3} in {expr1}. When {expr3} is zero 2202 insert before the first item. When {expr3} is equal to 2203 len({expr1}) then {expr2} is appended. 2204 Examples: >vim 2205 echo sort(extend(mylist, [7, 5])) 2206 call extend(mylist, [2, 3], 1) 2207 < When {expr1} is the same List as {expr2} then the number of 2208 items copied is equal to the original length of the List. 2209 E.g., when {expr3} is 1 you get N new copies of the first item 2210 (where N is the original length of the List). 2211 Use |add()| to concatenate one item to a list. To concatenate 2212 two lists into a new list use the + operator: >vim 2213 let newlist = [1, 2, 3] + [4, 5] 2214 < 2215 If they are |Dictionaries|: 2216 Add all entries from {expr2} to {expr1}. 2217 If a key exists in both {expr1} and {expr2} then {expr3} is 2218 used to decide what to do: 2219 {expr3} = "keep": keep the value of {expr1} 2220 {expr3} = "force": use the value of {expr2} 2221 {expr3} = "error": give an error message *E737* 2222 When {expr3} is omitted then "force" is assumed. 2223 2224 {expr1} is changed when {expr2} is not empty. If necessary 2225 make a copy of {expr1} first or use |extendnew()| to return a 2226 new List/Dictionary. 2227 {expr2} remains unchanged. 2228 When {expr1} is locked and {expr2} is not empty the operation 2229 fails. 2230 Returns {expr1}. Returns 0 on error. 2231 2232 Parameters: ~ 2233 • {expr1} (`table`) 2234 • {expr2} (`table`) 2235 • {expr3} (`table?`) 2236 2237 Return: ~ 2238 (`any`) 2239 2240 extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()* 2241 Like |extend()| but instead of adding items to {expr1} a new 2242 List or Dictionary is created and returned. {expr1} remains 2243 unchanged. 2244 2245 Parameters: ~ 2246 • {expr1} (`table`) 2247 • {expr2} (`table`) 2248 • {expr3} (`table?`) 2249 2250 Return: ~ 2251 (`any`) 2252 2253 feedkeys({string} [, {mode}]) *feedkeys()* 2254 Characters in {string} are queued for processing as if they 2255 come from a mapping or were typed by the user. 2256 2257 By default the string is added to the end of the typeahead 2258 buffer, thus if a mapping is still being executed the 2259 characters come after them. Use the 'i' flag to insert before 2260 other characters, they will be executed next, before any 2261 characters from a mapping. 2262 2263 The function does not wait for processing of keys contained in 2264 {string}. 2265 2266 To include special keys into {string}, use double-quotes 2267 and "\..." notation |expr-quote|. For example, 2268 feedkeys("\<CR>") simulates pressing of the <Enter> key. But 2269 feedkeys('\<CR>') pushes 5 characters. 2270 The |<Ignore>| keycode may be used to exit the 2271 wait-for-character without doing anything. 2272 2273 {mode} is a String, which can contain these character flags: 2274 'm' Remap keys. This is default. If {mode} is absent, 2275 keys are remapped. 2276 'n' Do not remap keys. 2277 't' Handle keys as if typed; otherwise they are handled as 2278 if coming from a mapping. This matters for undo, 2279 opening folds, etc. 2280 'L' Lowlevel input. Other flags are not used. 2281 'i' Insert the string instead of appending (see above). 2282 'x' Execute commands until typeahead is empty. This is 2283 similar to using ":normal!". You can call feedkeys() 2284 several times without 'x' and then one time with 'x' 2285 (possibly with an empty {string}) to execute all the 2286 typeahead. Note that when Vim ends in Insert mode it 2287 will behave as if <Esc> is typed, to avoid getting 2288 stuck, waiting for a character to be typed before the 2289 script continues. 2290 Note that if you manage to call feedkeys() while 2291 executing commands, thus calling it recursively, then 2292 all typeahead will be consumed by the last call. 2293 '!' When used with 'x' will not end Insert mode. Can be 2294 used in a test when a timer is set to exit Insert mode 2295 a little later. Useful for testing CursorHoldI. 2296 2297 Return value is always 0. 2298 2299 Parameters: ~ 2300 • {string} (`string`) 2301 • {mode} (`string?`) 2302 2303 Return: ~ 2304 (`any`) 2305 2306 filecopy({from}, {to}) *filecopy()* 2307 Copy the file pointed to by the name {from} to {to}. The 2308 result is a Number, which is |TRUE| if the file was copied 2309 successfully, and |FALSE| when it failed. 2310 If a file with name {to} already exists, it will fail. 2311 Note that it does not handle directories (yet). 2312 2313 This function is not available in the |sandbox|. 2314 2315 Parameters: ~ 2316 • {from} (`string`) 2317 • {to} (`string`) 2318 2319 Return: ~ 2320 (`0|1`) 2321 2322 filereadable({file}) *filereadable()* 2323 The result is a Number, which is |TRUE| when a file with the 2324 name {file} exists, and can be read. If {file} doesn't exist, 2325 or is a directory, the result is |FALSE|. {file} is any 2326 expression, which is used as a String. 2327 If you don't care about the file being readable you can use 2328 |glob()|. 2329 {file} is used as-is, you may want to expand wildcards first: >vim 2330 echo filereadable('~/.vimrc') 2331 < > 2332 0 2333 < >vim 2334 echo filereadable(expand('~/.vimrc')) 2335 < > 2336 1 2337 < 2338 2339 Parameters: ~ 2340 • {file} (`string`) 2341 2342 Return: ~ 2343 (`0|1`) 2344 2345 filewritable({file}) *filewritable()* 2346 The result is a Number, which is 1 when a file with the 2347 name {file} exists, and can be written. If {file} doesn't 2348 exist, or is not writable, the result is 0. If {file} is a 2349 directory, and we can write to it, the result is 2. 2350 2351 Parameters: ~ 2352 • {file} (`string`) 2353 2354 Return: ~ 2355 (`0|1`) 2356 2357 filter({expr1}, {expr2}) *filter()* 2358 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 2359 For each item in {expr1} evaluate {expr2} and when the result 2360 is zero or false remove the item from the |List| or 2361 |Dictionary|. Similarly for each byte in a |Blob| and each 2362 character in a |String|. 2363 2364 {expr2} must be a |string| or |Funcref|. 2365 2366 If {expr2} is a |string|, inside {expr2} |v:val| has the value 2367 of the current item. For a |Dictionary| |v:key| has the key 2368 of the current item and for a |List| |v:key| has the index of 2369 the current item. For a |Blob| |v:key| has the index of the 2370 current byte. For a |String| |v:key| has the index of the 2371 current character. 2372 Examples: >vim 2373 call filter(mylist, 'v:val !~ "OLD"') 2374 < Removes the items where "OLD" appears. >vim 2375 call filter(mydict, 'v:key >= 8') 2376 < Removes the items with a key below 8. >vim 2377 call filter(var, 0) 2378 < Removes all the items, thus clears the |List| or |Dictionary|. 2379 2380 Note that {expr2} is the result of expression and is then 2381 used as an expression again. Often it is good to use a 2382 |literal-string| to avoid having to double backslashes. 2383 2384 If {expr2} is a |Funcref| it must take two arguments: 2385 1. the key or the index of the current item. 2386 2. the value of the current item. 2387 The function must return |TRUE| if the item should be kept. 2388 Example that keeps the odd items of a list: >vim 2389 func Odd(idx, val) 2390 return a:idx % 2 == 1 2391 endfunc 2392 call filter(mylist, function('Odd')) 2393 < It is shorter when using a |lambda|: >vim 2394 call filter(myList, {idx, val -> idx * val <= 42}) 2395 < If you do not use "val" you can leave it out: >vim 2396 call filter(myList, {idx -> idx % 2 == 1}) 2397 < 2398 For a |List| and a |Dictionary| the operation is done 2399 in-place. If you want it to remain unmodified make a copy 2400 first: >vim 2401 let l = filter(copy(mylist), 'v:val =~ "KEEP"') 2402 2403 < Returns {expr1}, the |List| or |Dictionary| that was filtered, 2404 or a new |Blob| or |String|. 2405 When an error is encountered while evaluating {expr2} no 2406 further items in {expr1} are processed. 2407 When {expr2} is a Funcref errors inside a function are 2408 ignored, unless it was defined with the "abort" flag. 2409 2410 Parameters: ~ 2411 • {expr1} (`string|table`) 2412 • {expr2} (`string|function`) 2413 2414 Return: ~ 2415 (`any`) 2416 2417 finddir({name} [, {path} [, {count}]]) *finddir()* 2418 Find directory {name} in {path}. Supports both downwards and 2419 upwards recursive directory searches. See |file-searching| 2420 for the syntax of {path}. 2421 2422 Returns the path of the first found match. When the found 2423 directory is below the current directory a relative path is 2424 returned. Otherwise a full path is returned. 2425 If {path} is omitted or empty then 'path' is used. 2426 2427 If the optional {count} is given, find {count}'s occurrence of 2428 {name} in {path} instead of the first one. 2429 When {count} is negative return all the matches in a |List|. 2430 2431 Returns an empty string if the directory is not found. 2432 2433 This is quite similar to the ex-command `:find`. 2434 2435 Parameters: ~ 2436 • {name} (`string`) 2437 • {path} (`string?`) 2438 • {count} (`integer?`) 2439 2440 Return: ~ 2441 (`string|string[]`) 2442 2443 findfile({name} [, {path} [, {count}]]) *findfile()* 2444 Just like |finddir()|, but find a file instead of a directory. 2445 Uses 'suffixesadd'. 2446 Example: >vim 2447 echo findfile("tags.vim", ".;") 2448 < Searches from the directory of the current file upwards until 2449 it finds the file "tags.vim". 2450 2451 Parameters: ~ 2452 • {name} (`string`) 2453 • {path} (`string?`) 2454 • {count} (`integer?`) 2455 2456 Return: ~ 2457 (`string|string[]`) 2458 2459 flatten({list} [, {maxdepth}]) *flatten()* 2460 Flatten {list} up to {maxdepth} levels. Without {maxdepth} 2461 the result is a |List| without nesting, as if {maxdepth} is 2462 a very large number. 2463 The {list} is changed in place, use |flattennew()| if you do 2464 not want that. 2465 *E900* 2466 {maxdepth} means how deep in nested lists changes are made. 2467 {list} is not modified when {maxdepth} is 0. 2468 {maxdepth} must be positive number. 2469 2470 If there is an error the number zero is returned. 2471 2472 Example: >vim 2473 echo flatten([1, [2, [3, 4]], 5]) 2474 < [1, 2, 3, 4, 5] >vim 2475 echo flatten([1, [2, [3, 4]], 5], 1) 2476 < [1, 2, [3, 4], 5] 2477 2478 Parameters: ~ 2479 • {list} (`any[]`) 2480 • {maxdepth} (`integer?`) 2481 2482 Return: ~ 2483 (`any[]|0`) 2484 2485 flattennew({list} [, {maxdepth}]) *flattennew()* 2486 Like |flatten()| but first make a copy of {list}. 2487 2488 Parameters: ~ 2489 • {list} (`any[]`) 2490 • {maxdepth} (`integer?`) 2491 2492 Return: ~ 2493 (`any[]|0`) 2494 2495 float2nr({expr}) *float2nr()* 2496 Convert {expr} to a Number by omitting the part after the 2497 decimal point. 2498 {expr} must evaluate to a |Float| or a |Number|. 2499 Returns 0 if {expr} is not a |Float| or a |Number|. 2500 When the value of {expr} is out of range for a |Number| the 2501 result is truncated to 0x7fffffff or -0x7fffffff (or when 2502 64-bit Number support is enabled, 0x7fffffffffffffff or 2503 -0x7fffffffffffffff). NaN results in -0x80000000 (or when 2504 64-bit Number support is enabled, -0x8000000000000000). 2505 Examples: >vim 2506 echo float2nr(3.95) 2507 < 3 >vim 2508 echo float2nr(-23.45) 2509 < -23 >vim 2510 echo float2nr(1.0e100) 2511 < 2147483647 (or 9223372036854775807) >vim 2512 echo float2nr(-1.0e150) 2513 < -2147483647 (or -9223372036854775807) >vim 2514 echo float2nr(1.0e-100) 2515 < 0 2516 2517 Parameters: ~ 2518 • {expr} (`number`) 2519 2520 Return: ~ 2521 (`any`) 2522 2523 floor({expr}) *floor()* 2524 Return the largest integral value less than or equal to 2525 {expr} as a |Float| (round down). 2526 {expr} must evaluate to a |Float| or a |Number|. 2527 Returns 0.0 if {expr} is not a |Float| or a |Number|. 2528 Examples: >vim 2529 echo floor(1.856) 2530 < 1.0 >vim 2531 echo floor(-5.456) 2532 < -6.0 >vim 2533 echo floor(4.0) 2534 < 4.0 2535 2536 Parameters: ~ 2537 • {expr} (`number`) 2538 2539 Return: ~ 2540 (`any`) 2541 2542 fmod({expr1}, {expr2}) *fmod()* 2543 Return the remainder of {expr1} / {expr2}, even if the 2544 division is not representable. Returns {expr1} - i * {expr2} 2545 for some integer i such that if {expr2} is non-zero, the 2546 result has the same sign as {expr1} and magnitude less than 2547 the magnitude of {expr2}. If {expr2} is zero, the value 2548 returned is zero. The value returned is a |Float|. 2549 {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 2550 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a 2551 |Number|. 2552 Examples: >vim 2553 echo fmod(12.33, 1.22) 2554 < 0.13 >vim 2555 echo fmod(-12.33, 1.22) 2556 < -0.13 2557 2558 Parameters: ~ 2559 • {expr1} (`number`) 2560 • {expr2} (`number`) 2561 2562 Return: ~ 2563 (`any`) 2564 2565 fnameescape({string}) *fnameescape()* 2566 Escape {string} for use as file name command argument. All 2567 characters that have a special meaning, such as `'%'` and `'|'` 2568 are escaped with a backslash. For most systems the characters 2569 escaped are: > 2570 \t\n *?[{`$\\%#'\"|!< 2571 < For systems where a backslash appears in a filename, it 2572 depends on the value of 'isfname'. A leading '+' and '>' is 2573 also escaped (special after |:edit| and |:write|). And a "-" 2574 by itself (special after |:cd|). 2575 Returns an empty string on error. 2576 Example: >vim 2577 let fname = '+some str%nge|name' 2578 exe "edit " .. fnameescape(fname) 2579 < results in executing: >vim 2580 edit \+some\ str\%nge\|name 2581 < 2582 2583 Parameters: ~ 2584 • {string} (`string`) 2585 2586 Return: ~ 2587 (`string`) 2588 2589 fnamemodify({fname}, {mods}) *fnamemodify()* 2590 Modify file name {fname} according to {mods}. {mods} is a 2591 string of characters like it is used for file names on the 2592 command line. See |filename-modifiers|. 2593 Example: >vim 2594 echo fnamemodify("main.c", ":p:h") 2595 < results in: > 2596 /home/user/vim/vim/src 2597 < If {mods} is empty or an unsupported modifier is used then 2598 {fname} is returned. 2599 When {fname} is empty then with {mods} ":h" returns ".", so 2600 that `:cd` can be used with it. This is different from 2601 expand('%:h') without a buffer name, which returns an empty 2602 string. 2603 Note: Environment variables don't work in {fname}, use 2604 |expand()| first then. 2605 2606 Parameters: ~ 2607 • {fname} (`string`) 2608 • {mods} (`string`) 2609 2610 Return: ~ 2611 (`string`) 2612 2613 foldclosed({lnum}) *foldclosed()* 2614 The result is a Number. If the line {lnum} is in a closed 2615 fold, the result is the number of the first line in that fold. 2616 If the line {lnum} is not in a closed fold, -1 is returned. 2617 {lnum} is used like with |getline()|. Thus "." is the current 2618 line, "'m" mark m, etc. 2619 2620 Parameters: ~ 2621 • {lnum} (`integer|string`) 2622 2623 Return: ~ 2624 (`integer`) 2625 2626 foldclosedend({lnum}) *foldclosedend()* 2627 The result is a Number. If the line {lnum} is in a closed 2628 fold, the result is the number of the last line in that fold. 2629 If the line {lnum} is not in a closed fold, -1 is returned. 2630 {lnum} is used like with |getline()|. Thus "." is the current 2631 line, "'m" mark m, etc. 2632 2633 Parameters: ~ 2634 • {lnum} (`integer|string`) 2635 2636 Return: ~ 2637 (`integer`) 2638 2639 foldlevel({lnum}) *foldlevel()* 2640 The result is a Number, which is the foldlevel of line {lnum} 2641 in the current buffer. For nested folds the deepest level is 2642 returned. If there is no fold at line {lnum}, zero is 2643 returned. It doesn't matter if the folds are open or closed. 2644 When used while updating folds (from 'foldexpr') -1 is 2645 returned for lines where folds are still to be updated and the 2646 foldlevel is unknown. As a special case the level of the 2647 previous line is usually available. 2648 {lnum} is used like with |getline()|. Thus "." is the current 2649 line, "'m" mark m, etc. 2650 2651 Parameters: ~ 2652 • {lnum} (`integer|string`) 2653 2654 Return: ~ 2655 (`integer`) 2656 2657 foldtext() *foldtext()* 2658 Returns a String, to be displayed for a closed fold. This is 2659 the default function used for the 'foldtext' option and should 2660 only be called from evaluating 'foldtext'. It uses the 2661 |v:foldstart|, |v:foldend| and |v:folddashes| variables. 2662 The returned string looks like this: > 2663 +-- 45 lines: abcdef 2664 < The number of leading dashes depends on the foldlevel. The 2665 "45" is the number of lines in the fold. "abcdef" is the text 2666 in the first non-blank line of the fold. Leading white space, 2667 "//" or "/*" and the text from the 'foldmarker' and 2668 'commentstring' options is removed. 2669 When used to draw the actual foldtext, the rest of the line 2670 will be filled with the fold char from the 'fillchars' 2671 setting. 2672 Returns an empty string when there is no fold. 2673 2674 Return: ~ 2675 (`string`) 2676 2677 foldtextresult({lnum}) *foldtextresult()* 2678 Returns the text that is displayed for the closed fold at line 2679 {lnum}. Evaluates 'foldtext' in the appropriate context. 2680 When there is no closed fold at {lnum} an empty string is 2681 returned. 2682 {lnum} is used like with |getline()|. Thus "." is the current 2683 line, "'m" mark m, etc. 2684 Useful when exporting folded text, e.g., to HTML. 2685 2686 Parameters: ~ 2687 • {lnum} (`integer|string`) 2688 2689 Return: ~ 2690 (`string`) 2691 2692 foreach({expr1}, {expr2}) *foreach()* 2693 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 2694 For each item in {expr1} execute {expr2}. {expr1} is not 2695 modified; its values may be, as with |:lockvar| 1. |E741| 2696 See |map()| and |filter()| to modify {expr1}. 2697 2698 {expr2} must be a |string| or |Funcref|. 2699 2700 If {expr2} is a |string|, inside {expr2} |v:val| has the value 2701 of the current item. For a |Dictionary| |v:key| has the key 2702 of the current item and for a |List| |v:key| has the index of 2703 the current item. For a |Blob| |v:key| has the index of the 2704 current byte. For a |String| |v:key| has the index of the 2705 current character. 2706 Examples: >vim 2707 call foreach(mylist, 'let used[v:val] = v:true') 2708 < This records the items that are in the {expr1} list. 2709 2710 Note that {expr2} is the result of expression and is then used 2711 as a command. Often it is good to use a |literal-string| to 2712 avoid having to double backslashes. 2713 2714 If {expr2} is a |Funcref| it must take two arguments: 2715 1. the key or the index of the current item. 2716 2. the value of the current item. 2717 With a lambda you don't get an error if it only accepts one 2718 argument. 2719 If the function returns a value, it is ignored. 2720 2721 Returns {expr1} in all cases. 2722 When an error is encountered while executing {expr2} no 2723 further items in {expr1} are processed. 2724 When {expr2} is a Funcref errors inside a function are 2725 ignored, unless it was defined with the "abort" flag. 2726 2727 Parameters: ~ 2728 • {expr1} (`string|table`) 2729 • {expr2} (`string|function`) 2730 2731 Return: ~ 2732 (`string|table`) 2733 2734 fullcommand({name}) *fullcommand()* 2735 Get the full command name from a short abbreviated command 2736 name; see |20.2| for details on command abbreviations. 2737 2738 The string argument {name} may start with a `:` and can 2739 include a [range], these are skipped and not returned. 2740 Returns an empty string if a command doesn't exist or if it's 2741 ambiguous (for user-defined commands). 2742 2743 For example `fullcommand('s')`, `fullcommand('sub')`, 2744 `fullcommand(':%substitute')` all return "substitute". 2745 2746 Parameters: ~ 2747 • {name} (`string`) 2748 2749 Return: ~ 2750 (`string`) 2751 2752 funcref({name} [, {arglist}] [, {dict}]) *funcref()* 2753 Just like |function()|, but the returned Funcref will lookup 2754 the function by reference, not by name. This matters when the 2755 function {name} is redefined later. 2756 2757 Unlike |function()|, {name} must be an existing user function. 2758 It only works for an autoloaded function if it has already 2759 been loaded (to avoid mistakenly loading the autoload script 2760 when only intending to use the function name, use |function()| 2761 instead). {name} cannot be a builtin function. 2762 Returns 0 on error. 2763 2764 Parameters: ~ 2765 • {name} (`string`) 2766 • {arglist} (`any?`) 2767 • {dict} (`any?`) 2768 2769 Return: ~ 2770 (`any`) 2771 2772 function({name} [, {arglist}] [, {dict}]) *function()* *partial* *E700* *E923* 2773 Return a |Funcref| variable that refers to function {name}. 2774 {name} can be the name of a user defined function or an 2775 internal function. 2776 2777 {name} can also be a Funcref or a partial. When it is a 2778 partial the dict stored in it will be used and the {dict} 2779 argument is not allowed. E.g.: >vim 2780 let FuncWithArg = function(dict.Func, [arg]) 2781 let Broken = function(dict.Func, [arg], dict) 2782 < 2783 When using the Funcref the function will be found by {name}, 2784 also when it was redefined later. Use |funcref()| to keep the 2785 same function. 2786 2787 When {arglist} or {dict} is present this creates a partial. 2788 That means the argument list and/or the dictionary is stored 2789 in the Funcref and will be used when the Funcref is called. 2790 2791 The arguments are passed to the function in front of other 2792 arguments, but after any argument from |method|. Example: >vim 2793 func Callback(arg1, arg2, name) 2794 "... 2795 endfunc 2796 let Partial = function('Callback', ['one', 'two']) 2797 "... 2798 call Partial('name') 2799 < Invokes the function as with: >vim 2800 call Callback('one', 'two', 'name') 2801 2802 < With a |method|: >vim 2803 func Callback(one, two, three) 2804 "... 2805 endfunc 2806 let Partial = function('Callback', ['two']) 2807 "... 2808 eval 'one'->Partial('three') 2809 < Invokes the function as with: >vim 2810 call Callback('one', 'two', 'three') 2811 2812 < The function() call can be nested to add more arguments to the 2813 Funcref. The extra arguments are appended to the list of 2814 arguments. Example: >vim 2815 func Callback(arg1, arg2, name) 2816 "... 2817 endfunc 2818 let Func = function('Callback', ['one']) 2819 let Func2 = function(Func, ['two']) 2820 "... 2821 call Func2('name') 2822 < Invokes the function as with: >vim 2823 call Callback('one', 'two', 'name') 2824 2825 < The Dictionary is only useful when calling a "dict" function. 2826 In that case the {dict} is passed in as "self". Example: >vim 2827 function Callback() dict 2828 echo "called for " .. self.name 2829 endfunction 2830 "... 2831 let context = {"name": "example"} 2832 let Func = function('Callback', context) 2833 "... 2834 call Func() " will echo: called for example 2835 < The use of function() is not needed when there are no extra 2836 arguments, these two are equivalent, if Callback() is defined 2837 as context.Callback(): >vim 2838 let Func = function('Callback', context) 2839 let Func = context.Callback 2840 2841 < The argument list and the Dictionary can be combined: >vim 2842 function Callback(arg1, count) dict 2843 "... 2844 endfunction 2845 let context = {"name": "example"} 2846 let Func = function('Callback', ['one'], context) 2847 "... 2848 call Func(500) 2849 < Invokes the function as with: >vim 2850 call context.Callback('one', 500) 2851 < 2852 Returns 0 on error. 2853 2854 Parameters: ~ 2855 • {name} (`string`) 2856 • {arglist} (`any?`) 2857 • {dict} (`any?`) 2858 2859 Return: ~ 2860 (`any`) 2861 2862 garbagecollect([{atexit}]) *garbagecollect()* 2863 Cleanup unused |Lists| and |Dictionaries| that have circular 2864 references. 2865 2866 There is hardly ever a need to invoke this function, as it is 2867 automatically done when Vim runs out of memory or is waiting 2868 for the user to press a key after 'updatetime'. Items without 2869 circular references are always freed when they become unused. 2870 This is useful if you have deleted a very big |List| and/or 2871 |Dictionary| with circular references in a script that runs 2872 for a long time. 2873 2874 When the optional {atexit} argument is one, garbage 2875 collection will also be done when exiting Vim, if it wasn't 2876 done before. This is useful when checking for memory leaks. 2877 2878 The garbage collection is not done immediately but only when 2879 it's safe to perform. This is when waiting for the user to 2880 type a character. 2881 2882 Parameters: ~ 2883 • {atexit} (`boolean?`) 2884 2885 Return: ~ 2886 (`any`) 2887 2888 get({list}, {idx} [, {default}]) *get()* *get()-list* 2889 Get item {idx} from |List| {list}. When this item is not 2890 available return {default}. Return zero when {default} is 2891 omitted. 2892 2893 Parameters: ~ 2894 • {list} (`any[]`) 2895 • {idx} (`integer`) 2896 • {default} (`any?`) 2897 2898 Return: ~ 2899 (`any`) 2900 2901 get({blob}, {idx} [, {default}]) *get()-blob* 2902 Get byte {idx} from |Blob| {blob}. When this byte is not 2903 available return {default}. Return -1 when {default} is 2904 omitted. 2905 2906 Parameters: ~ 2907 • {blob} (`string`) 2908 • {idx} (`integer`) 2909 • {default} (`any?`) 2910 2911 Return: ~ 2912 (`any`) 2913 2914 get({dict}, {key} [, {default}]) *get()-dict* 2915 Get item with key {key} from |Dictionary| {dict}. When this 2916 item is not available return {default}. Return zero when 2917 {default} is omitted. Useful example: >vim 2918 let val = get(g:, 'var_name', 'default') 2919 < This gets the value of g:var_name if it exists, and uses 2920 "default" when it does not exist. 2921 2922 Parameters: ~ 2923 • {dict} (`table<string,any>`) 2924 • {key} (`string`) 2925 • {default} (`any?`) 2926 2927 Return: ~ 2928 (`any`) 2929 2930 get({func}, {what}) *get()-func* 2931 Get item {what} from |Funcref| {func}. Possible values for 2932 {what} are: 2933 "name" The function name 2934 "func" The function 2935 "dict" The dictionary 2936 "args" The list with arguments 2937 "arity" A dictionary with information about the number of 2938 arguments accepted by the function (minus the 2939 {arglist}) with the following fields: 2940 required the number of positional arguments 2941 optional the number of optional arguments, 2942 in addition to the required ones 2943 varargs |TRUE| if the function accepts a 2944 variable number of arguments |...| 2945 2946 Note: There is no error, if the {arglist} of 2947 the Funcref contains more arguments than the 2948 Funcref expects, it's not validated. 2949 2950 Returns zero on error. 2951 2952 Parameters: ~ 2953 • {func} (`function`) 2954 • {what} (`string`) 2955 2956 Return: ~ 2957 (`any`) 2958 2959 getbufinfo([{buf}]) *getbufinfo()* 2960 getbufinfo([{dict}]) 2961 Get information about buffers as a List of Dictionaries. 2962 2963 Without an argument information about all the buffers is 2964 returned. 2965 2966 When the argument is a |Dictionary| only the buffers matching 2967 the specified criteria are returned. The following keys can 2968 be specified in {dict}: 2969 buflisted include only listed buffers. 2970 bufloaded include only loaded buffers. 2971 bufmodified include only modified buffers. 2972 2973 Otherwise, {buf} specifies a particular buffer to return 2974 information for. For the use of {buf}, see |bufname()| 2975 above. If the buffer is found the returned List has one item. 2976 Otherwise the result is an empty list. 2977 2978 Each returned List item is a dictionary with the following 2979 entries: 2980 bufnr Buffer number. 2981 changed TRUE if the buffer is modified. 2982 changedtick Number of changes made to the buffer. 2983 command TRUE if the buffer belongs to the 2984 command-line window |cmdwin|. 2985 hidden TRUE if the buffer is hidden. 2986 lastused Timestamp in seconds, like 2987 |localtime()|, when the buffer was 2988 last used. 2989 listed TRUE if the buffer is listed. 2990 lnum Line number used for the buffer when 2991 opened in the current window. 2992 Only valid if the buffer has been 2993 displayed in the window in the past. 2994 If you want the line number of the 2995 last known cursor position in a given 2996 window, use |line()|: >vim 2997 echo line('.', {winid}) 2998 < 2999 linecount Number of lines in the buffer (only 3000 valid when loaded) 3001 loaded TRUE if the buffer is loaded. 3002 name Full path to the file in the buffer. 3003 signs List of signs placed in the buffer. 3004 Each list item is a dictionary with 3005 the following fields: 3006 id sign identifier 3007 lnum line number 3008 name sign name 3009 variables A reference to the dictionary with 3010 buffer-local variables. 3011 windows List of |window-ID|s that display this 3012 buffer 3013 3014 Examples: >vim 3015 for buf in getbufinfo() 3016 echo buf.name 3017 endfor 3018 for buf in getbufinfo({'buflisted':1}) 3019 if buf.changed 3020 " .... 3021 endif 3022 endfor 3023 < 3024 To get buffer-local options use: >vim 3025 getbufvar({bufnr}, '&option_name') 3026 < 3027 3028 Parameters: ~ 3029 • {dict} (`vim.fn.getbufinfo.dict?`) 3030 3031 Return: ~ 3032 (`vim.fn.getbufinfo.ret.item[]`) 3033 3034 getbufline({buf}, {lnum} [, {end}]) *getbufline()* 3035 Return a |List| with the lines starting from {lnum} to {end} 3036 (inclusive) in the buffer {buf}. If {end} is omitted, a 3037 |List| with only the line {lnum} is returned. See 3038 `getbufoneline()` for only getting the line. 3039 3040 For the use of {buf}, see |bufname()| above. 3041 3042 For {lnum} and {end} "$" can be used for the last line of the 3043 buffer. Otherwise a number must be used. 3044 3045 When {lnum} is smaller than 1 or bigger than the number of 3046 lines in the buffer, an empty |List| is returned. 3047 3048 When {end} is greater than the number of lines in the buffer, 3049 it is treated as {end} is set to the number of lines in the 3050 buffer. When {end} is before {lnum} an empty |List| is 3051 returned. 3052 3053 This function works only for loaded buffers. For unloaded and 3054 non-existing buffers, an empty |List| is returned. 3055 3056 Example: >vim 3057 let lines = getbufline(bufnr("myfile"), 1, "$") 3058 < 3059 3060 Parameters: ~ 3061 • {buf} (`integer|string`) 3062 • {lnum} (`integer`) 3063 • {end} (`integer?`) 3064 3065 Return: ~ 3066 (`string[]`) 3067 3068 getbufoneline({buf}, {lnum}) *getbufoneline()* 3069 Just like `getbufline()` but only get one line and return it 3070 as a string. 3071 3072 Parameters: ~ 3073 • {buf} (`integer|string`) 3074 • {lnum} (`integer`) 3075 3076 Return: ~ 3077 (`string`) 3078 3079 getbufvar({buf}, {varname} [, {def}]) *getbufvar()* 3080 The result is the value of option or local buffer variable 3081 {varname} in buffer {buf}. Note that the name without "b:" 3082 must be used. 3083 The {varname} argument is a string. 3084 When {varname} is empty returns a |Dictionary| with all the 3085 buffer-local variables. 3086 When {varname} is equal to "&" returns a |Dictionary| with all 3087 the buffer-local options. 3088 Otherwise, when {varname} starts with "&" returns the value of 3089 a buffer-local option. 3090 This also works for a global or buffer-local option, but it 3091 doesn't work for a global variable, window-local variable or 3092 window-local option. 3093 For the use of {buf}, see |bufname()| above. 3094 When the buffer or variable doesn't exist {def} or an empty 3095 string is returned, there is no error message. 3096 Examples: >vim 3097 let bufmodified = getbufvar(1, "&mod") 3098 echo "todo myvar = " .. getbufvar("todo", "myvar") 3099 < 3100 3101 Parameters: ~ 3102 • {buf} (`integer|string`) 3103 • {varname} (`string`) 3104 • {def} (`any?`) 3105 3106 Return: ~ 3107 (`any`) 3108 3109 getcellwidths() *getcellwidths()* 3110 Returns a |List| of cell widths of character ranges overridden 3111 by |setcellwidths()|. The format is equal to the argument of 3112 |setcellwidths()|. If no character ranges have their cell 3113 widths overridden, an empty List is returned. 3114 3115 Return: ~ 3116 (`any`) 3117 3118 getchangelist([{buf}]) *getchangelist()* 3119 Returns the |changelist| for the buffer {buf}. For the use 3120 of {buf}, see |bufname()| above. If buffer {buf} doesn't 3121 exist, an empty list is returned. 3122 3123 The returned list contains two entries: a list with the change 3124 locations and the current position in the list. Each 3125 entry in the change list is a dictionary with the following 3126 entries: 3127 col column number 3128 coladd column offset for 'virtualedit' 3129 lnum line number 3130 If buffer {buf} is the current buffer, then the current 3131 position refers to the position in the list. For other 3132 buffers, it is set to the length of the list. 3133 3134 Parameters: ~ 3135 • {buf} (`integer|string?`) 3136 3137 Return: ~ 3138 (`table[]`) 3139 3140 getchar([{expr} [, {opts}]]) *getchar()* 3141 Get a single character from the user or input stream. 3142 If {expr} is omitted or is -1, wait until a character is 3143 available. 3144 If {expr} is 0, only get a character when one is available. 3145 Return zero otherwise. 3146 If {expr} is 1, only check if a character is available, it is 3147 not consumed. Return zero if no character available. 3148 To always get a string, specify "number" as |FALSE| in {opts}. 3149 3150 Without {expr} and when {expr} is 0 a whole character or 3151 special key is returned. If it is a single character, the 3152 result is a Number. Use |nr2char()| to convert it to a String. 3153 Otherwise a String is returned with the encoded character. 3154 For a special key it's a String with a sequence of bytes 3155 starting with 0x80 (decimal: 128). This is the same value as 3156 the String "\<Key>", e.g., "\<Left>". The returned value is 3157 also a String when a modifier (shift, control, alt) was used 3158 that is not included in the character. |keytrans()| can also 3159 be used to convert a returned String into a readable form. 3160 3161 When {expr} is 0 and Esc is typed, there will be a short delay 3162 while Vim waits to see if this is the start of an escape 3163 sequence. 3164 3165 When {expr} is 1 only the first byte is returned. For a 3166 one-byte character it is the character itself as a number. 3167 Use |nr2char()| to convert it to a String. 3168 3169 Use |getcharmod()| to obtain any additional modifiers. 3170 3171 The optional argument {opts} is a Dict and supports the 3172 following items: 3173 3174 cursor A String specifying cursor behavior 3175 when waiting for a character. 3176 "hide": hide the cursor. 3177 "keep": keep current cursor unchanged. 3178 "msg": move cursor to message area. 3179 (default: automagically decide 3180 between "keep" and "msg") 3181 3182 number If |TRUE|, return a Number when getting 3183 a single character. 3184 If |FALSE|, the return value is always 3185 converted to a String, and an empty 3186 String (instead of 0) is returned when 3187 no character is available. 3188 (default: |TRUE|) 3189 3190 simplify If |TRUE|, include modifiers in the 3191 character if possible. E.g., return 3192 the same value for CTRL-I and <Tab>. 3193 If |FALSE|, don't include modifiers in 3194 the character. 3195 (default: |TRUE|) 3196 3197 When the user clicks a mouse button, the mouse event will be 3198 returned. The position can then be found in |v:mouse_col|, 3199 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. 3200 |getmousepos()| can also be used. Mouse move events will be 3201 ignored. 3202 This example positions the mouse as it would normally happen: >vim 3203 let c = getchar() 3204 if c == "\<LeftMouse>" && v:mouse_win > 0 3205 exe v:mouse_win .. "wincmd w" 3206 exe v:mouse_lnum 3207 exe "normal " .. v:mouse_col .. "|" 3208 endif 3209 < 3210 There is no prompt, you will somehow have to make clear to the 3211 user that a character has to be typed. The screen is not 3212 redrawn, e.g. when resizing the window. 3213 3214 There is no mapping for the character. 3215 Key codes are replaced, thus when the user presses the <Del> 3216 key you get the code for the <Del> key, not the raw character 3217 sequence. Examples: >vim 3218 getchar() == "\<Del>" 3219 getchar() == "\<S-Left>" 3220 < This example redefines "f" to ignore case: >vim 3221 nmap f :call FindChar()<CR> 3222 function FindChar() 3223 let c = nr2char(getchar()) 3224 while col('.') < col('$') - 1 3225 normal l 3226 if getline('.')[col('.') - 1] ==? c 3227 break 3228 endif 3229 endwhile 3230 endfunction 3231 < 3232 3233 Parameters: ~ 3234 • {expr} (`-1|0|1?`) 3235 • {opts} (`table?`) 3236 3237 Return: ~ 3238 (`integer|string`) 3239 3240 getcharmod() *getcharmod()* 3241 The result is a Number which is the state of the modifiers for 3242 the last obtained character with |getchar()| or in another way. 3243 These values are added together: 3244 2 shift 3245 4 control 3246 8 alt (meta) 3247 16 meta (when it's different from ALT) 3248 32 mouse double click 3249 64 mouse triple click 3250 96 mouse quadruple click (== 32 + 64) 3251 128 command (Mac) or super 3252 Only the modifiers that have not been included in the 3253 character itself are obtained. Thus Shift-a results in "A" 3254 without a modifier. Returns 0 if no modifiers are used. 3255 3256 Return: ~ 3257 (`integer`) 3258 3259 getcharpos({expr}) *getcharpos()* 3260 Get the position for String {expr}. Same as |getpos()| but the 3261 column number in the returned List is a character index 3262 instead of a byte index. 3263 If |getpos()| returns a very large column number, equal to 3264 |v:maxcol|, then getcharpos() will return the character index 3265 of the last character. 3266 3267 Example: 3268 With the cursor on '세' in line 5 with text "여보세요": >vim 3269 getcharpos('.') returns [0, 5, 3, 0] 3270 getpos('.') returns [0, 5, 7, 0] 3271 < 3272 3273 Parameters: ~ 3274 • {expr} (`string`) 3275 3276 Return: ~ 3277 (`integer[]`) 3278 3279 getcharsearch() *getcharsearch()* 3280 Return the current character search information as a {dict} 3281 with the following entries: 3282 3283 char character previously used for a character 3284 search (|t|, |f|, |T|, or |F|); empty string 3285 if no character search has been performed 3286 forward direction of character search; 1 for forward, 3287 0 for backward 3288 until type of character search; 1 for a |t| or |T| 3289 character search, 0 for an |f| or |F| 3290 character search 3291 3292 This can be useful to always have |;| and |,| search 3293 forward/backward regardless of the direction of the previous 3294 character search: >vim 3295 nnoremap <expr> ; getcharsearch().forward ? ';' : ',' 3296 nnoremap <expr> , getcharsearch().forward ? ',' : ';' 3297 < Also see |setcharsearch()|. 3298 3299 Return: ~ 3300 (`{ char: string, forward: 1|0, until: 1|0 }`) 3301 3302 getcharstr([{expr} [, {opts}]]) *getcharstr()* 3303 The same as |getchar()|, except that this always returns a 3304 String, and "number" isn't allowed in {opts}. 3305 3306 Parameters: ~ 3307 • {expr} (`-1|0|1?`) 3308 • {opts} (`table?`) 3309 3310 Return: ~ 3311 (`string`) 3312 3313 getcmdcomplpat() *getcmdcomplpat()* 3314 Return completion pattern of the current command-line. 3315 Only works when the command line is being edited, thus 3316 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3317 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3318 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|. 3319 Returns an empty string when completion is not defined. 3320 3321 Return: ~ 3322 (`string`) 3323 3324 getcmdcompltype() *getcmdcompltype()* 3325 Return the type of the current command-line completion. 3326 Only works when the command line is being edited, thus 3327 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3328 See |:command-completion| for the return string. 3329 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3330 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|. 3331 Returns an empty string when completion is not defined. 3332 3333 To get the type of the command-line completion for a specified 3334 string, use |getcompletiontype()|. 3335 3336 Return: ~ 3337 (`string`) 3338 3339 getcmdline() *getcmdline()* 3340 Return the current command-line input. Only works when the 3341 command line is being edited, thus requires use of 3342 |c_CTRL-\_e| or |c_CTRL-R_=|. 3343 Example: >vim 3344 cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> 3345 < Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|, 3346 |getcmdprompt()| and |setcmdline()|. 3347 Returns an empty string when entering a password or using 3348 |inputsecret()|. 3349 3350 Return: ~ 3351 (`string`) 3352 3353 getcmdpos() *getcmdpos()* 3354 Return the position of the cursor in the command line as a 3355 byte count. The first column is 1. 3356 Only works when editing the command line, thus requires use of 3357 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3358 Returns 0 otherwise. 3359 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3360 |getcmdprompt()| and |setcmdline()|. 3361 3362 Return: ~ 3363 (`integer`) 3364 3365 getcmdprompt() *getcmdprompt()* 3366 Return the current command-line prompt when using functions 3367 like |input()| or |confirm()|. 3368 Only works when the command line is being edited, thus 3369 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3370 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|, 3371 |setcmdpos()| and |setcmdline()|. 3372 3373 Return: ~ 3374 (`string`) 3375 3376 getcmdscreenpos() *getcmdscreenpos()* 3377 Return the screen position of the cursor in the command line 3378 as a byte count. The first column is 1. 3379 Instead of |getcmdpos()|, it adds the prompt position. 3380 Only works when editing the command line, thus requires use of 3381 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3382 Returns 0 otherwise. 3383 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and 3384 |setcmdline()|. 3385 3386 Return: ~ 3387 (`integer`) 3388 3389 getcmdtype() *getcmdtype()* 3390 Return the current command-line type. Possible return values 3391 are: 3392 : normal Ex command 3393 > debug mode command |debug-mode| 3394 / forward search command 3395 ? backward search command 3396 @ |input()| command 3397 `-` |:insert| or |:append| command 3398 = |i_CTRL-R_=| 3399 Only works when editing the command line, thus requires use of 3400 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3401 Returns an empty string otherwise. 3402 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|. 3403 3404 Return: ~ 3405 (`':'|'>'|'/'|'?'|'@'|'-'|'='|''`) 3406 3407 getcmdwintype() *getcmdwintype()* 3408 Return the current |command-line-window| type. Possible return 3409 values are the same as |getcmdtype()|. Returns an empty string 3410 when not in the command-line window. 3411 3412 Return: ~ 3413 (`':'|'>'|'/'|'?'|'@'|'-'|'='|''`) 3414 3415 getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* 3416 Return a list of command-line completion matches. The String 3417 {type} argument specifies what for. The following completion 3418 types are supported: 3419 3420 arglist file names in argument list 3421 augroup autocmd groups 3422 buffer buffer names 3423 breakpoint |:breakadd| and |:breakdel| suboptions 3424 cmdline |cmdline-completion| result 3425 color color schemes 3426 command Ex command 3427 compiler compilers 3428 custom,{func} custom completion, defined via {func} 3429 customlist,{func} custom completion, defined via {func} 3430 diff_buffer |:diffget| and |:diffput| completion 3431 dir directory names 3432 dir_in_path directory names in 'cdpath' 3433 environment environment variable names 3434 event autocommand events 3435 expression Vim expression 3436 file file and directory names 3437 file_in_path file and directory names in 'path' 3438 filetype filetype names 'filetype' 3439 filetypecmd |:filetype| suboptions 3440 function function name 3441 help help subjects 3442 highlight highlight groups 3443 history |:history| suboptions 3444 keymap keyboard mappings 3445 locale locale names (as output of locale -a) 3446 mapclear buffer argument 3447 mapping mapping name 3448 menu menus 3449 messages |:messages| suboptions 3450 option options 3451 packadd optional package |pack-add| names 3452 retab |:retab| suboptions 3453 runtime |:runtime| completion 3454 scriptnames sourced script names |:scriptnames| 3455 shellcmd Shell command 3456 shellcmdline Shell command line with filename arguments 3457 sign |:sign| suboptions 3458 syntax syntax file names 'syntax' 3459 syntime |:syntime| suboptions 3460 tag tags 3461 tag_listfiles tags, file names 3462 user user names 3463 var user variables 3464 3465 If {pat} is an empty string, then all the matches are 3466 returned. Otherwise only items matching {pat} are returned. 3467 See |wildcards| for the use of special characters in {pat}. 3468 3469 If the optional {filtered} flag is set to 1, then 'wildignore' 3470 is applied to filter the results. Otherwise all the matches 3471 are returned. The 'wildignorecase' option always applies. 3472 3473 If the 'wildoptions' option contains "fuzzy", then fuzzy 3474 matching is used to get the completion matches. Otherwise 3475 regular expression matching is used. Thus this function 3476 follows the user preference, what happens on the command line. 3477 If you do not want this you can make 'wildoptions' empty 3478 before calling getcompletion() and restore it afterwards. 3479 3480 If {type} is "cmdline", then the |cmdline-completion| result is 3481 returned. For example, to complete the possible values after 3482 a ":call" command: >vim 3483 echo getcompletion('call ', 'cmdline') 3484 < 3485 If there are no matches, an empty list is returned. An 3486 invalid value for {type} produces an error. 3487 3488 Parameters: ~ 3489 • {pat} (`string`) 3490 • {type} (`string`) 3491 • {filtered} (`boolean?`) 3492 3493 Return: ~ 3494 (`string[]`) 3495 3496 getcompletiontype({pat}) *getcompletiontype()* 3497 Return the type of the command-line completion using {pat}. 3498 When no corresponding completion type is found, an empty 3499 string is returned. 3500 To get the current command-line completion type, use 3501 |getcmdcompltype()|. 3502 3503 Parameters: ~ 3504 • {pat} (`string`) 3505 3506 Return: ~ 3507 (`string`) 3508 3509 getcurpos([{winid}]) *getcurpos()* 3510 Get the position of the cursor. This is like getpos('.'), but 3511 includes an extra "curswant" item in the list: 3512 [0, lnum, col, off, curswant] ~ 3513 The "curswant" number is the preferred column when moving the 3514 cursor vertically. After |$| command it will be a very large 3515 number equal to |v:maxcol|. Also see |getcursorcharpos()| and 3516 |getpos()|. 3517 The first "bufnum" item is always zero. The byte position of 3518 the cursor is returned in "col". To get the character 3519 position, use |getcursorcharpos()|. 3520 3521 The optional {winid} argument can specify the window. It can 3522 be the window number or the |window-ID|. The last known 3523 cursor position is returned, this may be invalid for the 3524 current value of the buffer if it is not the current window. 3525 If {winid} is invalid a list with zeroes is returned. 3526 3527 This can be used to save and restore the cursor position: >vim 3528 let save_cursor = getcurpos() 3529 MoveTheCursorAround 3530 call setpos('.', save_cursor) 3531 < Note that this only works within the window. See 3532 |winrestview()| for restoring more state. 3533 3534 Parameters: ~ 3535 • {winid} (`integer?`) 3536 3537 Return: ~ 3538 (`[integer, integer, integer, integer, integer]`) 3539 3540 getcursorcharpos([{winid}]) *getcursorcharpos()* 3541 Same as |getcurpos()| but the column number in the returned 3542 List is a character index instead of a byte index. 3543 3544 Example: 3545 With the cursor on '보' in line 3 with text "여보세요": >vim 3546 getcursorcharpos() " returns [0, 3, 2, 0, 3] 3547 getcurpos() " returns [0, 3, 4, 0, 3] 3548 < 3549 3550 Parameters: ~ 3551 • {winid} (`integer?`) 3552 3553 Return: ~ 3554 (`any`) 3555 3556 getcwd([{winnr} [, {tabnr}]]) *getcwd()* 3557 With no arguments, returns the name of the effective 3558 |current-directory|. With {winnr} or {tabnr} the working 3559 directory of that scope is returned, and 'autochdir' is 3560 ignored. Tabs and windows are identified by their respective 3561 numbers, 0 means current tab or window. Missing tab number 3562 implies 0. Thus the following are equivalent: >vim 3563 getcwd(0) 3564 getcwd(0, 0) 3565 < If {winnr} is -1 it is ignored, only the tab is resolved. 3566 {winnr} can be the window number or the |window-ID|. 3567 If both {winnr} and {tabnr} are -1 the global working 3568 directory is returned. 3569 Note: When {tabnr} is -1 Vim returns an empty string to 3570 signal that it is invalid, whereas Nvim returns either the 3571 global working directory if {winnr} is -1 or the working 3572 directory of the window indicated by {winnr}. 3573 Throw error if the arguments are invalid. |E5000| |E5001| |E5002| 3574 3575 Parameters: ~ 3576 • {winnr} (`integer?`) 3577 • {tabnr} (`integer?`) 3578 3579 Return: ~ 3580 (`string`) 3581 3582 getenv({name}) *getenv()* 3583 Return the value of environment variable {name}. The {name} 3584 argument is a string, without a leading '$'. Example: >vim 3585 myHome = getenv('HOME') 3586 3587 < When the variable does not exist |v:null| is returned. That 3588 is different from a variable set to an empty string. 3589 See also |expr-env|. 3590 3591 Parameters: ~ 3592 • {name} (`string`) 3593 3594 Return: ~ 3595 (`string`) 3596 3597 getfontname([{name}]) *getfontname()* 3598 Without an argument returns the name of the normal font being 3599 used. Like what is used for the Normal highlight group 3600 |hl-Normal|. 3601 With an argument a check is done whether String {name} is a 3602 valid font name. If not then an empty string is returned. 3603 Otherwise the actual font name is returned, or {name} if the 3604 GUI does not support obtaining the real name. 3605 Only works when the GUI is running, thus not in your vimrc or 3606 gvimrc file. Use the |GUIEnter| autocommand to use this 3607 function just after the GUI has started. 3608 3609 Parameters: ~ 3610 • {name} (`string?`) 3611 3612 Return: ~ 3613 (`string`) 3614 3615 getfperm({fname}) *getfperm()* 3616 The result is a String, which is the read, write, and execute 3617 permissions of the given file {fname}. 3618 If {fname} does not exist or its directory cannot be read, an 3619 empty string is returned. 3620 The result is of the form "rwxrwxrwx", where each group of 3621 "rwx" flags represent, in turn, the permissions of the owner 3622 of the file, the group the file belongs to, and other users. 3623 If a user does not have a given permission the flag for this 3624 is replaced with the string "-". Examples: >vim 3625 echo getfperm("/etc/passwd") 3626 echo getfperm(expand("~/.config/nvim/init.vim")) 3627 < This will hopefully (from a security point of view) display 3628 the string "rw-r--r--" or even "rw-------". 3629 3630 For setting permissions use |setfperm()|. 3631 3632 Parameters: ~ 3633 • {fname} (`string`) 3634 3635 Return: ~ 3636 (`string`) 3637 3638 getfsize({fname}) *getfsize()* 3639 The result is a Number, which is the size in bytes of the 3640 given file {fname}. 3641 If {fname} is a directory, 0 is returned. 3642 If the file {fname} can't be found, -1 is returned. 3643 If the size of {fname} is too big to fit in a Number then -2 3644 is returned. 3645 3646 Parameters: ~ 3647 • {fname} (`string`) 3648 3649 Return: ~ 3650 (`integer`) 3651 3652 getftime({fname}) *getftime()* 3653 The result is a Number, which is the last modification time of 3654 the given file {fname}. The value is measured as seconds 3655 since 1st Jan 1970, and may be passed to |strftime()|. See also 3656 |localtime()| and |strftime()|. 3657 If the file {fname} can't be found -1 is returned. 3658 3659 Parameters: ~ 3660 • {fname} (`string`) 3661 3662 Return: ~ 3663 (`integer`) 3664 3665 getftype({fname}) *getftype()* 3666 The result is a String, which is a description of the kind of 3667 file of the given file {fname}. 3668 If {fname} does not exist an empty string is returned. 3669 Here is a table over different kinds of files and their 3670 results: 3671 Normal file "file" 3672 Directory "dir" 3673 Symbolic link "link" 3674 Block device "bdev" 3675 Character device "cdev" 3676 Socket "socket" 3677 FIFO "fifo" 3678 All other "other" 3679 Example: >vim 3680 getftype("/home") 3681 < Note that a type such as "link" will only be returned on 3682 systems that support it. On some systems only "dir" and 3683 "file" are returned. 3684 3685 Parameters: ~ 3686 • {fname} (`string`) 3687 3688 Return: ~ 3689 (`'file'|'dir'|'link'|'bdev'|'cdev'|'socket'|'fifo'|'other'`) 3690 3691 getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* 3692 Returns the |jumplist| for the specified window. 3693 3694 Without arguments use the current window. 3695 With {winnr} only use this window in the current tab page. 3696 {winnr} can also be a |window-ID|. 3697 With {winnr} and {tabnr} use the window in the specified tab 3698 page. If {winnr} or {tabnr} is invalid, an empty list is 3699 returned. 3700 3701 The returned list contains two entries: a list with the jump 3702 locations and the last used jump position number in the list. 3703 Each entry in the jump location list is a dictionary with 3704 the following entries: 3705 bufnr buffer number 3706 col column number 3707 coladd column offset for 'virtualedit' 3708 filename filename if available 3709 lnum line number 3710 3711 Parameters: ~ 3712 • {winnr} (`integer?`) 3713 • {tabnr} (`integer?`) 3714 3715 Return: ~ 3716 (`vim.fn.getjumplist.ret`) 3717 3718 getline({lnum} [, {end}]) *getline()* 3719 Without {end} the result is a String, which is line {lnum} 3720 from the current buffer. Example: >vim 3721 getline(1) 3722 < When {lnum} is a String that doesn't start with a 3723 digit, |line()| is called to translate the String into a Number. 3724 To get the line under the cursor: >vim 3725 getline(".") 3726 < When {lnum} is a number smaller than 1 or bigger than the 3727 number of lines in the buffer, an empty string is returned. 3728 3729 When {end} is given the result is a |List| where each item is 3730 a line from the current buffer in the range {lnum} to {end}, 3731 including line {end}. 3732 {end} is used in the same way as {lnum}. 3733 Non-existing lines are silently omitted. 3734 When {end} is before {lnum} an empty |List| is returned. 3735 Example: >vim 3736 let start = line('.') 3737 let end = search("^$") - 1 3738 let lines = getline(start, end) 3739 3740 < To get lines from another buffer see |getbufline()| and 3741 |getbufoneline()| 3742 3743 Parameters: ~ 3744 • {lnum} (`integer|string`) 3745 • {end} (`nil|false?`) 3746 3747 Return: ~ 3748 (`string`) 3749 3750 getloclist({nr} [, {what}]) *getloclist()* 3751 Returns a |List| with all the entries in the location list for 3752 window {nr}. {nr} can be the window number or the |window-ID|. 3753 When {nr} is zero the current window is used. 3754 3755 For a location list window, the displayed location list is 3756 returned. For an invalid window number {nr}, an empty list is 3757 returned. Otherwise, same as |getqflist()|. 3758 3759 If the optional {what} dictionary argument is supplied, then 3760 returns the items listed in {what} as a dictionary. Refer to 3761 |getqflist()| for the supported items in {what}. 3762 3763 In addition to the items supported by |getqflist()| in {what}, 3764 the following item is supported by |getloclist()|: 3765 3766 filewinid id of the window used to display files 3767 from the location list. This field is 3768 applicable only when called from a 3769 location list window. See 3770 |location-list-file-window| for more 3771 details. 3772 3773 Returns a |Dictionary| with default values if there is no 3774 location list for the window {nr}. 3775 Returns an empty Dictionary if window {nr} does not exist. 3776 3777 Examples (See also |getqflist-examples|): >vim 3778 echo getloclist(3, {'all': 0}) 3779 echo getloclist(5, {'filewinid': 0}) 3780 < 3781 3782 Parameters: ~ 3783 • {nr} (`integer`) 3784 • {what} (`table?`) 3785 3786 Return: ~ 3787 (`any`) 3788 3789 getmarklist([{buf}]) *getmarklist()* 3790 Without the {buf} argument returns a |List| with information 3791 about all the global marks. |mark| 3792 3793 If the optional {buf} argument is specified, returns the 3794 local marks defined in buffer {buf}. For the use of {buf}, 3795 see |bufname()|. If {buf} is invalid, an empty list is 3796 returned. 3797 3798 Each item in the returned List is a |Dict| with the following: 3799 mark name of the mark prefixed by "'" 3800 pos a |List| with the position of the mark: 3801 [bufnum, lnum, col, off] 3802 Refer to |getpos()| for more information. 3803 file file name 3804 3805 Refer to |getpos()| for getting information about a specific 3806 mark. 3807 3808 Parameters: ~ 3809 • {buf} (`integer??`) 3810 3811 Return: ~ 3812 (`vim.fn.getmarklist.ret.item[]`) 3813 3814 getmatches([{win}]) *getmatches()* 3815 Returns a |List| with all matches previously defined for the 3816 current window by |matchadd()| and the |:match| commands. 3817 |getmatches()| is useful in combination with |setmatches()|, 3818 as |setmatches()| can restore a list of matches saved by 3819 |getmatches()|. 3820 If {win} is specified, use the window with this number or 3821 window ID instead of the current window. If {win} is invalid, 3822 an empty list is returned. 3823 Example: >vim 3824 echo getmatches() 3825 < > 3826 [{"group": "MyGroup1", "pattern": "TODO", 3827 "priority": 10, "id": 1}, {"group": "MyGroup2", 3828 "pattern": "FIXME", "priority": 10, "id": 2}] 3829 < >vim 3830 let m = getmatches() 3831 call clearmatches() 3832 echo getmatches() 3833 < > 3834 [] 3835 < >vim 3836 call setmatches(m) 3837 echo getmatches() 3838 < > 3839 [{"group": "MyGroup1", "pattern": "TODO", 3840 "priority": 10, "id": 1}, {"group": "MyGroup2", 3841 "pattern": "FIXME", "priority": 10, "id": 2}] 3842 < >vim 3843 unlet m 3844 < 3845 3846 Parameters: ~ 3847 • {win} (`integer?`) 3848 3849 Return: ~ 3850 (`vim.fn.getmatches.ret.item[]`) 3851 3852 getmousepos() *getmousepos()* 3853 Returns a |Dictionary| with the last known position of the 3854 mouse. This can be used in a mapping for a mouse click. The 3855 items are: 3856 screenrow screen row 3857 screencol screen column 3858 winid Window ID of the click 3859 winrow row inside "winid" 3860 wincol column inside "winid" 3861 line text line inside "winid" 3862 column text column inside "winid" 3863 coladd offset (in screen columns) from the 3864 start of the clicked char 3865 All numbers are 1-based. 3866 3867 If not over a window, e.g. when in the command line, then only 3868 "screenrow" and "screencol" are valid, the others are zero. 3869 3870 When on the status line below a window or the vertical 3871 separator right of a window, the "line" and "column" values 3872 are zero. 3873 3874 When the position is after the text then "column" is the 3875 length of the text in bytes plus one. 3876 3877 If the mouse is over a focusable floating window then that 3878 window is used. 3879 3880 When using |getchar()| the Vim variables |v:mouse_lnum|, 3881 |v:mouse_col| and |v:mouse_winid| also provide these values. 3882 3883 Return: ~ 3884 (`vim.fn.getmousepos.ret`) 3885 3886 getpid() *getpid()* 3887 Return a Number which is the process ID of the Vim process. 3888 This is a unique number, until Vim exits. 3889 3890 Return: ~ 3891 (`integer`) 3892 3893 getpos({expr}) *getpos()* 3894 Gets a position, where {expr} is one of: 3895 . Cursor position. 3896 $ Last line in the current buffer. 3897 'x Position of mark x (if the mark is not set, 0 is 3898 returned for all values). 3899 w0 First line visible in current window (one if the 3900 display isn't updated, e.g. in silent Ex mode). 3901 w$ Last line visible in current window (this is one 3902 less than "w0" if no lines are visible). 3903 v End of the current Visual selection (unlike |'<| 3904 |'>| which give the previous, not current, Visual 3905 selection), or the cursor position if not in Visual 3906 mode. 3907 3908 To get the current selected region: >vim 3909 let region = getregionpos(getpos('v'), getpos('.')) 3910 < 3911 Explanation: in Visual mode "v" and "." complement each 3912 other. While "." refers to the cursor position, "v" 3913 refers to where |v_o| would move the cursor. So you can 3914 use "v" and "." together to get the selected region. 3915 3916 Note that if a mark in another file is used, the line number 3917 applies to that buffer. 3918 3919 The result is a |List| with four numbers: 3920 [bufnum, lnum, col, off] 3921 "bufnum" is zero, unless a mark like '0 or 'A is used, then it 3922 is the buffer number of the mark. 3923 "lnum" and "col" are the position in the buffer. The first 3924 column is 1. 3925 The "off" number is zero, unless 'virtualedit' is used. Then 3926 it is the offset in screen columns from the start of the 3927 character. E.g., a position within a <Tab> or after the last 3928 character. 3929 3930 For getting the cursor position see |getcurpos()|. 3931 The column number in the returned List is the byte position 3932 within the line. To get the character position in the line, 3933 use |getcharpos()|. 3934 3935 The visual marks |'<| and |'>| refer to the beginning and end 3936 of the visual selection relative to the buffer. Note that 3937 this differs from |setpos()|, where they are relative to the 3938 cursor position. 3939 3940 Note that for '< and '> Visual mode matters: when it is "V" 3941 (visual line mode) the column of '< is zero and the column of 3942 '> is a large number equal to |v:maxcol|. 3943 A very large column number equal to |v:maxcol| can be returned, 3944 in which case it means "after the end of the line". 3945 If {expr} is invalid, returns a list with all zeros. 3946 3947 This can be used to save and restore the position of a mark: >vim 3948 let save_a_mark = getpos("'a") 3949 " ... 3950 call setpos("'a", save_a_mark) 3951 < 3952 Also see |getcharpos()|, |getcurpos()| and |setpos()|. 3953 3954 Parameters: ~ 3955 • {expr} (`string`) 3956 3957 Return: ~ 3958 (`[integer, integer, integer, integer]`) 3959 3960 getqflist([{what}]) *getqflist()* 3961 Returns a |List| with all the current quickfix errors. Each 3962 list item is a dictionary with these entries: 3963 bufnr number of buffer that has the file name, use 3964 |bufname()| to get the name 3965 module module name 3966 lnum line number in the buffer (first line is 1) 3967 end_lnum 3968 end of line number if the item is multiline 3969 col column number (first column is 1) 3970 end_col end of column number if the item has range 3971 vcol |TRUE|: "col" is visual column 3972 |FALSE|: "col" is byte index 3973 nr error number 3974 pattern search pattern used to locate the error 3975 text description of the error 3976 type type of the error, 'E', '1', etc. 3977 valid |TRUE|: recognized error message 3978 user_data 3979 custom data associated with the item, can be 3980 any type. 3981 3982 When there is no error list or it's empty, an empty list is 3983 returned. Quickfix list entries with a non-existing buffer 3984 number are returned with "bufnr" set to zero (Note: some 3985 functions accept buffer number zero for the alternate buffer, 3986 you may need to explicitly check for zero). 3987 3988 Useful application: Find pattern matches in multiple files and 3989 do something with them: >vim 3990 vimgrep /theword/jg *.c 3991 for d in getqflist() 3992 echo bufname(d.bufnr) ':' d.lnum '=' d.text 3993 endfor 3994 < 3995 If the optional {what} dictionary argument is supplied, then 3996 returns only the items listed in {what} as a dictionary. The 3997 following string items are supported in {what}: 3998 changedtick get the total number of changes made 3999 to the list |quickfix-changedtick| 4000 context get the |quickfix-context| 4001 efm errorformat to use when parsing "lines". If 4002 not present, then the 'errorformat' option 4003 value is used. 4004 id get information for the quickfix list with 4005 |quickfix-ID|; zero means the id for the 4006 current list or the list specified by "nr" 4007 idx get information for the quickfix entry at this 4008 index in the list specified by "id" or "nr". 4009 If set to zero, then uses the current entry. 4010 See |quickfix-index| 4011 items quickfix list entries 4012 lines parse a list of lines using 'efm' and return 4013 the resulting entries. Only a |List| type is 4014 accepted. The current quickfix list is not 4015 modified. See |quickfix-parse|. 4016 nr get information for this quickfix list; zero 4017 means the current quickfix list and "$" means 4018 the last quickfix list 4019 qfbufnr number of the buffer displayed in the quickfix 4020 window. Returns 0 if the quickfix buffer is 4021 not present. See |quickfix-buffer|. 4022 size number of entries in the quickfix list 4023 title get the list title |quickfix-title| 4024 winid get the quickfix |window-ID| 4025 all all of the above quickfix properties 4026 Non-string items in {what} are ignored. To get the value of a 4027 particular item, set it to zero. 4028 If "nr" is not present then the current quickfix list is used. 4029 If both "nr" and a non-zero "id" are specified, then the list 4030 specified by "id" is used. 4031 To get the number of lists in the quickfix stack, set "nr" to 4032 "$" in {what}. The "nr" value in the returned dictionary 4033 contains the quickfix stack size. 4034 When "lines" is specified, all the other items except "efm" 4035 are ignored. The returned dictionary contains the entry 4036 "items" with the list of entries. 4037 4038 The returned dictionary contains the following entries: 4039 changedtick total number of changes made to the 4040 list |quickfix-changedtick| 4041 context quickfix list context. See |quickfix-context| 4042 If not present, set to "". 4043 id quickfix list ID |quickfix-ID|. If not 4044 present, set to 0. 4045 idx index of the quickfix entry in the list. If 4046 not present, set to 0. 4047 items quickfix list entries. If not present, set to 4048 an empty list. 4049 nr quickfix list number. If not present, set to 4050 0 4051 qfbufnr number of the buffer displayed in the quickfix 4052 window. If not present, set to 0. 4053 size number of entries in the quickfix list. If 4054 not present, set to 0. 4055 title quickfix list title text. If not present, set 4056 to "". 4057 winid quickfix |window-ID|. If not present, set to 0 4058 4059 Examples (See also |getqflist-examples|): >vim 4060 echo getqflist({'all': 1}) 4061 echo getqflist({'nr': 2, 'title': 1}) 4062 echo getqflist({'lines' : ["F1:10:L10"]}) 4063 < 4064 4065 Parameters: ~ 4066 • {what} (`table?`) 4067 4068 Return: ~ 4069 (`any`) 4070 4071 getreg([{regname} [, 1 [, {list}]]]) *getreg()* 4072 The result is a String, which is the contents of register 4073 {regname}. Example: >vim 4074 let cliptext = getreg('*') 4075 < When register {regname} was not set the result is an empty 4076 string. 4077 The {regname} argument must be a string. 4078 4079 getreg('=') returns the last evaluated value of the expression 4080 register. (For use in maps.) 4081 getreg('=', 1) returns the expression itself, so that it can 4082 be restored with |setreg()|. For other registers the extra 4083 argument is ignored, thus you can always give it. 4084 4085 If {list} is present and |TRUE|, the result type is changed 4086 to |List|. Each list item is one text line. Use it if you care 4087 about zero bytes possibly present inside register: without 4088 third argument both NLs and zero bytes are represented as NLs 4089 (see |NL-used-for-Nul|). 4090 When the register was not set an empty list is returned. 4091 4092 If {regname} is not specified, |v:register| is used. 4093 4094 Parameters: ~ 4095 • {regname} (`string?`) 4096 • {expr} (`any?`) 4097 • {list} (`nil|false?`) 4098 4099 Return: ~ 4100 (`string`) 4101 4102 getreginfo([{regname}]) *getreginfo()* 4103 Returns detailed information about register {regname} as a 4104 Dictionary with the following entries: 4105 regcontents List of lines contained in register 4106 {regname}, like 4107 getreg({regname}, 1, 1). 4108 regtype the type of register {regname}, as in 4109 |getregtype()|. 4110 isunnamed Boolean flag, v:true if this register 4111 is currently pointed to by the unnamed 4112 register. 4113 points_to for the unnamed register, gives the 4114 single letter name of the register 4115 currently pointed to (see |quotequote|). 4116 For example, after deleting a line 4117 with `dd`, this field will be "1", 4118 which is the register that got the 4119 deleted text. 4120 4121 The {regname} argument is a string. If {regname} is invalid 4122 or not set, an empty Dictionary will be returned. 4123 If {regname} is not specified, |v:register| is used. 4124 The returned Dictionary can be passed to |setreg()|. 4125 4126 Parameters: ~ 4127 • {regname} (`string?`) 4128 4129 Return: ~ 4130 (`table`) 4131 4132 getregion({pos1}, {pos2} [, {opts}]) *getregion()* 4133 Returns the list of strings from {pos1} to {pos2} from a 4134 buffer. 4135 4136 {pos1} and {pos2} must both be |List|s with four numbers. 4137 See |getpos()| for the format of the list. It's possible 4138 to specify positions from a different buffer, but please 4139 note the limitations at |getregion-notes|. 4140 4141 The optional argument {opts} is a Dict and supports the 4142 following items: 4143 4144 type Specify the region's selection type. 4145 See |getregtype()| for possible values, 4146 except that the width can be omitted 4147 and an empty string cannot be used. 4148 (default: "v") 4149 4150 exclusive If |TRUE|, use exclusive selection 4151 for the end position. 4152 (default: follow 'selection') 4153 4154 You can get the last selection type by |visualmode()|. 4155 If Visual mode is active, use |mode()| to get the Visual mode 4156 (e.g., in a |:vmap|). 4157 This function is useful to get text starting and ending in 4158 different columns, such as a |charwise-visual| selection. 4159 4160 *getregion-notes* 4161 Note that: 4162 - Order of {pos1} and {pos2} doesn't matter, it will always 4163 return content from the upper left position to the lower 4164 right position. 4165 - If 'virtualedit' is enabled and the region is past the end 4166 of the lines, resulting lines are padded with spaces. 4167 - If the region is blockwise and it starts or ends in the 4168 middle of a multi-cell character, it is not included but 4169 its selected part is substituted with spaces. 4170 - If {pos1} and {pos2} are not in the same buffer, an empty 4171 list is returned. 4172 - {pos1} and {pos2} must belong to a |bufloaded()| buffer. 4173 - It is evaluated in current window context, which makes a 4174 difference if the buffer is displayed in a window with 4175 different 'virtualedit' or 'list' values. 4176 - When specifying an exclusive selection and {pos1} and {pos2} 4177 are equal, the returned list contains a single character as 4178 if selection is inclusive, to match the behavior of an empty 4179 exclusive selection in Visual mode. 4180 4181 Examples: >vim 4182 xnoremap <CR> 4183 \ <Cmd>echom getregion( 4184 \ getpos('v'), getpos('.'), #{ type: mode() })<CR> 4185 < 4186 4187 Parameters: ~ 4188 • {pos1} (`[integer, integer, integer, integer]`) 4189 • {pos2} (`[integer, integer, integer, integer]`) 4190 • {opts} (`{type?:string, exclusive?:boolean}?`) 4191 4192 Return: ~ 4193 (`string[]`) 4194 4195 getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()* 4196 Same as |getregion()|, but returns a list of positions 4197 describing the buffer text segments bound by {pos1} and 4198 {pos2}. 4199 The segments are a pair of positions for every line: > 4200 [[{start_pos}, {end_pos}], ...] 4201 < 4202 The position is a |List| with four numbers: 4203 [bufnum, lnum, col, off] 4204 "bufnum" is the buffer number. 4205 "lnum" and "col" are the position in the buffer. The first 4206 column is 1. 4207 If the "off" number of a starting position is non-zero, it is 4208 the offset in screen columns from the start of the character. 4209 E.g., a position within a <Tab> or after the last character. 4210 If the "off" number of an ending position is non-zero, it is 4211 the offset of the character's first cell not included in the 4212 selection, otherwise all its cells are included. 4213 4214 To get the current visual selection: >vim 4215 let region = getregionpos(getpos('v'), getpos('.')) 4216 < 4217 The {opts} Dict supports the following items: 4218 4219 type See |getregion()|. 4220 4221 exclusive See |getregion()|. 4222 4223 eol If |TRUE|, indicate positions beyond 4224 the end of a line with "col" values 4225 one more than the length of the line. 4226 If |FALSE|, positions are limited 4227 within their lines, and if a line is 4228 empty or the selection is entirely 4229 beyond the end of a line, a "col" 4230 value of 0 is used for both positions. 4231 (default: |FALSE|) 4232 4233 Parameters: ~ 4234 • {pos1} (`[integer, integer, integer, integer]`) 4235 • {pos2} (`[integer, integer, integer, integer]`) 4236 • {opts} 4237 (`{type?:string, exclusive?:boolean, eol?:boolean}?`) 4238 4239 Return: ~ 4240 (`[ [integer, integer, integer, integer], [integer, integer, integer, integer] ][]`) 4241 4242 getregtype([{regname}]) *getregtype()* 4243 The result is a String, which is type of register {regname}. 4244 The value will be one of: 4245 "v" for |charwise| text 4246 "V" for |linewise| text 4247 "<CTRL-V>{width}" for |blockwise-visual| text 4248 "" for an empty or unknown register 4249 <CTRL-V> is one character with value 0x16. 4250 The {regname} argument is a string. If {regname} is not 4251 specified, |v:register| is used. 4252 4253 Parameters: ~ 4254 • {regname} (`string?`) 4255 4256 Return: ~ 4257 (`string`) 4258 4259 getscriptinfo([{opts}]) *getscriptinfo()* 4260 Returns a |List| with information about all the sourced Vim 4261 scripts in the order they were sourced, like what 4262 `:scriptnames` shows. 4263 4264 The optional Dict argument {opts} supports the following 4265 optional items: 4266 name Script name match pattern. If specified, 4267 and "sid" is not specified, information about 4268 scripts with a name that match the pattern 4269 "name" are returned. 4270 sid Script ID |<SID>|. If specified, only 4271 information about the script with ID "sid" is 4272 returned and "name" is ignored. 4273 4274 Each item in the returned List is a |Dict| with the following 4275 items: 4276 autoload Always set to FALSE. 4277 functions List of script-local function names defined in 4278 the script. Present only when a particular 4279 script is specified using the "sid" item in 4280 {opts}. 4281 name Vim script file name. 4282 sid Script ID |<SID>|. 4283 variables A dictionary with the script-local variables. 4284 Present only when a particular script is 4285 specified using the "sid" item in {opts}. 4286 Note that this is a copy, the value of 4287 script-local variables cannot be changed using 4288 this dictionary. 4289 version Vim script version, always 1 4290 4291 Examples: >vim 4292 echo getscriptinfo({'name': 'myscript'}) 4293 echo getscriptinfo({'sid': 15})[0].variables 4294 < 4295 4296 Parameters: ~ 4297 • {opts} (`table?`) 4298 4299 Return: ~ 4300 (`vim.fn.getscriptinfo.ret[]`) 4301 4302 getstacktrace() *getstacktrace()* 4303 Returns the current stack trace of Vim scripts. 4304 Stack trace is a |List|, of which each item is a |Dictionary| 4305 with the following items: 4306 funcref The funcref if the stack is at a function, 4307 otherwise this item is omitted. 4308 event The string of the event description if the 4309 stack is at an autocmd event, otherwise this 4310 item is omitted. 4311 lnum The line number in the script on the stack. 4312 filepath The file path of the script on the stack. 4313 4314 Return: ~ 4315 (`table[]`) 4316 4317 gettabinfo([{tabnr}]) *gettabinfo()* 4318 If {tabnr} is not specified, then information about all the 4319 tab pages is returned as a |List|. Each List item is a 4320 |Dictionary|. Otherwise, {tabnr} specifies the tab page 4321 number and information about that one is returned. If the tab 4322 page does not exist an empty List is returned. 4323 4324 Each List item is a |Dictionary| with the following entries: 4325 tabnr tab page number. 4326 variables a reference to the dictionary with 4327 tabpage-local variables 4328 windows List of |window-ID|s in the tab page. 4329 4330 Parameters: ~ 4331 • {tabnr} (`integer?`) 4332 4333 Return: ~ 4334 (`any`) 4335 4336 gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()* 4337 Get the value of a tab-local variable {varname} in tab page 4338 {tabnr}. |t:var| 4339 Tabs are numbered starting with one. 4340 The {varname} argument is a string. When {varname} is empty a 4341 dictionary with all tab-local variables is returned. 4342 Note that the name without "t:" must be used. 4343 When the tab or variable doesn't exist {def} or an empty 4344 string is returned, there is no error message. 4345 4346 Parameters: ~ 4347 • {tabnr} (`integer`) 4348 • {varname} (`string`) 4349 • {def} (`any?`) 4350 4351 Return: ~ 4352 (`any`) 4353 4354 gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()* 4355 Get the value of window-local variable {varname} in window 4356 {winnr} in tab page {tabnr}. 4357 The {varname} argument is a string. When {varname} is empty a 4358 dictionary with all window-local variables is returned. 4359 When {varname} is equal to "&" get the values of all 4360 window-local options in a |Dictionary|. 4361 Otherwise, when {varname} starts with "&" get the value of a 4362 window-local option. 4363 Note that {varname} must be the name without "w:". 4364 Tabs are numbered starting with one. For the current tabpage 4365 use |getwinvar()|. 4366 {winnr} can be the window number or the |window-ID|. 4367 When {winnr} is zero the current window is used. 4368 This also works for a global option, buffer-local option and 4369 window-local option, but it doesn't work for a global variable 4370 or buffer-local variable. 4371 When the tab, window or variable doesn't exist {def} or an 4372 empty string is returned, there is no error message. 4373 Examples: >vim 4374 let list_is_on = gettabwinvar(1, 2, '&list') 4375 echo "myvar = " .. gettabwinvar(3, 1, 'myvar') 4376 < 4377 To obtain all window-local variables use: >vim 4378 gettabwinvar({tabnr}, {winnr}, '&') 4379 < 4380 4381 Parameters: ~ 4382 • {tabnr} (`integer`) 4383 • {winnr} (`integer`) 4384 • {varname} (`string`) 4385 • {def} (`any?`) 4386 4387 Return: ~ 4388 (`any`) 4389 4390 gettagstack([{winnr}]) *gettagstack()* 4391 The result is a Dict, which is the tag stack of window {winnr}. 4392 {winnr} can be the window number or the |window-ID|. 4393 When {winnr} is not specified, the current window is used. 4394 When window {winnr} doesn't exist, an empty Dict is returned. 4395 4396 The returned dictionary contains the following entries: 4397 curidx Current index in the stack. When at 4398 top of the stack, set to (length + 1). 4399 Index of bottom of the stack is 1. 4400 items List of items in the stack. Each item 4401 is a dictionary containing the 4402 entries described below. 4403 length Number of entries in the stack. 4404 4405 Each item in the stack is a dictionary with the following 4406 entries: 4407 bufnr buffer number of the current jump 4408 from cursor position before the tag jump. 4409 See |getpos()| for the format of the 4410 returned list. 4411 matchnr current matching tag number. Used 4412 when multiple matching tags are found 4413 for a name. 4414 tagname name of the tag 4415 4416 See |tagstack| for more information about the tag stack. 4417 4418 Parameters: ~ 4419 • {winnr} (`integer?`) 4420 4421 Return: ~ 4422 (`any`) 4423 4424 gettext({text}) *gettext()* 4425 Translate String {text} if possible. 4426 This is mainly for use in the distributed Vim scripts. When 4427 generating message translations the {text} is extracted by 4428 xgettext, the translator can add the translated message in the 4429 .po file and Vim will lookup the translation when gettext() is 4430 called. 4431 For {text} double quoted strings are preferred, because 4432 xgettext does not understand escaping in single quoted 4433 strings. 4434 4435 Parameters: ~ 4436 • {text} (`string`) 4437 4438 Return: ~ 4439 (`string`) 4440 4441 getwininfo([{winid}]) *getwininfo()* 4442 Returns information about windows as a |List| with Dictionaries. 4443 4444 If {winid} is given Information about the window with that ID 4445 is returned, as a |List| with one item. If the window does not 4446 exist the result is an empty list. 4447 4448 Without {winid} information about all the windows in all the 4449 tab pages is returned. 4450 4451 Each List item is a |Dictionary| with the following entries: 4452 botline last complete displayed buffer line 4453 bufnr number of buffer in the window 4454 height window height (excluding winbar) 4455 leftcol first column displayed; only used when 4456 'wrap' is off 4457 loclist 1 if showing a location list 4458 quickfix 1 if quickfix or location list window 4459 status_height status lines height (0 or 1) 4460 tabnr tab page number 4461 terminal 1 if a terminal window 4462 textoff number of columns occupied by any 4463 'foldcolumn', 'signcolumn' and line 4464 number in front of the text 4465 topline first displayed buffer line 4466 variables a reference to the dictionary with 4467 window-local variables 4468 width window width 4469 winbar 1 if the window has a toolbar, 0 4470 otherwise 4471 wincol leftmost screen column of the window; 4472 "col" from |win_screenpos()| 4473 winid |window-ID| 4474 winnr window number 4475 winrow topmost screen line of the window; 4476 "row" from |win_screenpos()| 4477 4478 Parameters: ~ 4479 • {winid} (`integer?`) 4480 4481 Return: ~ 4482 (`vim.fn.getwininfo.ret.item[]`) 4483 4484 getwinpos([{timeout}]) *getwinpos()* 4485 The result is a |List| with two numbers, the result of 4486 |getwinposx()| and |getwinposy()| combined: 4487 [x-pos, y-pos] 4488 {timeout} can be used to specify how long to wait in msec for 4489 a response from the terminal. When omitted 100 msec is used. 4490 4491 Use a longer time for a remote terminal. 4492 When using a value less than 10 and no response is received 4493 within that time, a previously reported position is returned, 4494 if available. This can be used to poll for the position and 4495 do some work in the meantime: >vim 4496 while 1 4497 let res = getwinpos(1) 4498 if res[0] >= 0 4499 break 4500 endif 4501 " Do some work here 4502 endwhile 4503 < 4504 4505 Parameters: ~ 4506 • {timeout} (`integer?`) 4507 4508 Return: ~ 4509 (`any`) 4510 4511 getwinposx() *getwinposx()* 4512 The result is a Number, which is the X coordinate in pixels of 4513 the left hand side of the GUI Vim window. The result will be 4514 -1 if the information is not available. 4515 The value can be used with `:winpos`. 4516 4517 Return: ~ 4518 (`integer`) 4519 4520 getwinposy() *getwinposy()* 4521 The result is a Number, which is the Y coordinate in pixels of 4522 the top of the GUI Vim window. The result will be -1 if the 4523 information is not available. 4524 The value can be used with `:winpos`. 4525 4526 Return: ~ 4527 (`integer`) 4528 4529 getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* 4530 Like |gettabwinvar()| for the current tabpage. 4531 Examples: >vim 4532 let list_is_on = getwinvar(2, '&list') 4533 echo "myvar = " .. getwinvar(1, 'myvar') 4534 < 4535 4536 Parameters: ~ 4537 • {winnr} (`integer`) 4538 • {varname} (`string`) 4539 • {def} (`any?`) 4540 4541 Return: ~ 4542 (`any`) 4543 4544 glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* 4545 Expand the file wildcards in {expr}. See |wildcards| for the 4546 use of special characters. 4547 4548 Unless the optional {nosuf} argument is given and is |TRUE|, 4549 the 'suffixes' and 'wildignore' options apply: Names matching 4550 one of the patterns in 'wildignore' will be skipped and 4551 'suffixes' affect the ordering of matches. 4552 'wildignorecase' always applies. 4553 4554 When {list} is present and it is |TRUE| the result is a |List| 4555 with all matching files. The advantage of using a List is, 4556 you also get filenames containing newlines correctly. 4557 Otherwise the result is a String and when there are several 4558 matches, they are separated by <NL> characters. 4559 4560 If the expansion fails, the result is an empty String or List. 4561 4562 You can also use |readdir()| if you need to do complicated 4563 things, such as limiting the number of matches. 4564 4565 A name for a non-existing file is not included. A symbolic 4566 link is only included if it points to an existing file. 4567 However, when the {alllinks} argument is present and it is 4568 |TRUE| then all symbolic links are included. 4569 4570 For most systems backticks can be used to get files names from 4571 any external command. Example: >vim 4572 let tagfiles = glob("`find . -name tags -print`") 4573 let &tags = substitute(tagfiles, "\n", ",", "g") 4574 < The result of the program inside the backticks should be one 4575 item per line. Spaces inside an item are allowed. 4576 4577 See |expand()| for expanding special Vim variables. See 4578 |system()| for getting the raw output of an external command. 4579 4580 Parameters: ~ 4581 • {expr} (`string`) 4582 • {nosuf} (`boolean?`) 4583 • {list} (`boolean?`) 4584 • {alllinks} (`boolean?`) 4585 4586 Return: ~ 4587 (`any`) 4588 4589 glob2regpat({string}) *glob2regpat()* 4590 Convert a file pattern, as used by |glob()|, into a search 4591 pattern. The result can be used to match with a string that 4592 is a file name. E.g. >vim 4593 if filename =~ glob2regpat('Make*.mak') 4594 " ... 4595 endif 4596 < This is equivalent to: >vim 4597 if filename =~ '^Make.*\.mak$' 4598 " ... 4599 endif 4600 < When {string} is an empty string the result is "^$", match an 4601 empty string. 4602 Note that the result depends on the system. On MS-Windows 4603 a backslash usually means a path separator. 4604 4605 Parameters: ~ 4606 • {string} (`string`) 4607 4608 Return: ~ 4609 (`string`) 4610 4611 globpath({path}, {expr} [, {nosuf} [, {list} [, {allinks}]]]) *globpath()* 4612 Perform |glob()| for String {expr} on all directories in {path} 4613 and concatenate the results. Example: >vim 4614 echo globpath(&rtp, "syntax/c.vim") 4615 < 4616 {path} is a comma-separated list of directory names. Each 4617 directory name is prepended to {expr} and expanded like with 4618 |glob()|. A path separator is inserted when needed. 4619 To add a comma inside a directory name escape it with a 4620 backslash. Note that on MS-Windows a directory may have a 4621 trailing backslash, remove it if you put a comma after it. 4622 If the expansion fails for one of the directories, there is no 4623 error message. 4624 4625 Unless the optional {nosuf} argument is given and is |TRUE|, 4626 the 'suffixes' and 'wildignore' options apply: Names matching 4627 one of the patterns in 'wildignore' will be skipped and 4628 'suffixes' affect the ordering of matches. 4629 4630 When {list} is present and it is |TRUE| the result is a |List| 4631 with all matching files. The advantage of using a List is, 4632 you also get filenames containing newlines correctly. 4633 Otherwise the result is a String and when there are several 4634 matches, they are separated by <NL> characters. Example: >vim 4635 echo globpath(&rtp, "syntax/c.vim", 0, 1) 4636 < 4637 {allinks} is used as with |glob()|. 4638 4639 The "**" item can be used to search in a directory tree. 4640 For example, to find all "README.txt" files in the directories 4641 in 'runtimepath' and below: >vim 4642 echo globpath(&rtp, "**/README.txt") 4643 < Upwards search and limiting the depth of "**" is not 4644 supported, thus using 'path' will not always work properly. 4645 4646 Parameters: ~ 4647 • {path} (`string`) 4648 • {expr} (`string`) 4649 • {nosuf} (`boolean?`) 4650 • {list} (`boolean?`) 4651 • {allinks} (`boolean?`) 4652 4653 Return: ~ 4654 (`any`) 4655 4656 has({feature}) *has()* 4657 Returns 1 if {feature} is supported, 0 otherwise. The 4658 {feature} argument is a feature name like "nvim-0.2.1" or 4659 "win32", see below. See also |exists()|. 4660 4661 To get the system name use |vim.uv|.os_uname() in Lua: >lua 4662 print(vim.uv.os_uname().sysname) 4663 4664 < If the code has a syntax error then Vimscript may skip the 4665 rest of the line. Put |:if| and |:endif| on separate lines to 4666 avoid the syntax error: >vim 4667 if has('feature') 4668 let x = this_breaks_without_the_feature() 4669 endif 4670 < 4671 Vim's compile-time feature-names (prefixed with "+") are not 4672 recognized because Nvim is always compiled with all possible 4673 features. |feature-compile| 4674 4675 Feature names can be: 4676 1. Nvim version. For example the "nvim-0.2.1" feature means 4677 that Nvim is version 0.2.1 or later: >vim 4678 if has("nvim-0.2.1") 4679 " ... 4680 endif 4681 4682 < 2. Runtime condition or other pseudo-feature. For example the 4683 "win32" feature checks if the current system is Windows: >vim 4684 if has("win32") 4685 " ... 4686 endif 4687 < *feature-list* 4688 List of supported pseudo-feature names: 4689 acl |ACL| support. 4690 bsd BSD system (not macOS, use "mac" for that). 4691 clipboard |clipboard| provider is available. 4692 fname_case Case in file names matters (for Darwin and MS-Windows 4693 this is not present). 4694 gui_running Nvim has a GUI. 4695 hurd GNU/Hurd system. 4696 iconv Can use |iconv()| for conversion. 4697 linux Linux system. 4698 mac MacOS system. 4699 nvim This is Nvim. 4700 python3 Legacy Vim |python3| interface. |has-python| 4701 pythonx Legacy Vim |python_x| interface. |has-pythonx| 4702 sun SunOS system. 4703 ttyin input is a terminal (tty). 4704 ttyout output is a terminal (tty). 4705 unix Unix system. 4706 *vim_starting* True during |startup|. 4707 win32 Windows system (32 or 64 bit). 4708 win64 Windows system (64 bit). 4709 wsl WSL (Windows Subsystem for Linux) system. 4710 4711 *has-patch* 4712 3. Vim patch. For example the "patch123" feature means that 4713 Vim patch 123 at the current |v:version| was included: >vim 4714 if v:version > 602 || v:version == 602 && has("patch148") 4715 " ... 4716 endif 4717 4718 < 4. Vim version. For example the "patch-7.4.237" feature means 4719 that Nvim is Vim-compatible to version 7.4.237 or later. >vim 4720 if has("patch-7.4.237") 4721 " ... 4722 endif 4723 < 4724 4725 Parameters: ~ 4726 • {feature} (`string`) 4727 4728 Return: ~ 4729 (`0|1`) 4730 4731 has_key({dict}, {key}) *has_key()* 4732 The result is a Number, which is TRUE if |Dictionary| {dict} 4733 has an entry with key {key}. FALSE otherwise. The {key} 4734 argument is a string. 4735 4736 Parameters: ~ 4737 • {dict} (`table`) 4738 • {key} (`string`) 4739 4740 Return: ~ 4741 (`0|1`) 4742 4743 haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()* 4744 The result is a Number, which is 1 when the window has set a 4745 local path via |:lcd| or when {winnr} is -1 and the tabpage 4746 has set a local path via |:tcd|, otherwise 0. 4747 4748 Tabs and windows are identified by their respective numbers, 4749 0 means current tab or window. Missing argument implies 0. 4750 Thus the following are equivalent: >vim 4751 echo haslocaldir() 4752 echo haslocaldir(0) 4753 echo haslocaldir(0, 0) 4754 < With {winnr} use that window in the current tabpage. 4755 With {winnr} and {tabnr} use the window in that tabpage. 4756 {winnr} can be the window number or the |window-ID|. 4757 If {winnr} is -1 it is ignored, only the tab is resolved. 4758 Throw error if the arguments are invalid. |E5000| |E5001| |E5002| 4759 4760 Parameters: ~ 4761 • {winnr} (`integer?`) 4762 • {tabnr} (`integer?`) 4763 4764 Return: ~ 4765 (`0|1`) 4766 4767 hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* 4768 The result is a Number, which is TRUE if there is a mapping 4769 that contains {what} in somewhere in the rhs (what it is 4770 mapped to) and this mapping exists in one of the modes 4771 indicated by {mode}. 4772 The arguments {what} and {mode} are strings. 4773 When {abbr} is there and it is |TRUE| use abbreviations 4774 instead of mappings. Don't forget to specify Insert and/or 4775 Command-line mode. 4776 Both the global mappings and the mappings local to the current 4777 buffer are checked for a match. 4778 If no matching mapping is found FALSE is returned. 4779 The following characters are recognized in {mode}: 4780 n Normal mode 4781 v Visual and Select mode 4782 x Visual mode 4783 s Select mode 4784 o Operator-pending mode 4785 i Insert mode 4786 l Language-Argument ("r", "f", "t", etc.) 4787 c Command-line mode 4788 When {mode} is omitted, "nvo" is used. 4789 4790 This function is useful to check if a mapping already exists 4791 to a function in a Vim script. Example: >vim 4792 if !hasmapto('\ABCdoit') 4793 map <Leader>d \ABCdoit 4794 endif 4795 < This installs the mapping to "\ABCdoit" only if there isn't 4796 already a mapping to "\ABCdoit". 4797 4798 Parameters: ~ 4799 • {what} (`any`) 4800 • {mode} (`string?`) 4801 • {abbr} (`boolean?`) 4802 4803 Return: ~ 4804 (`0|1`) 4805 4806 histadd({history}, {item}) *histadd()* 4807 Add the String {item} to the history {history} which can be 4808 one of: *hist-names* 4809 "cmd" or ":" command line history 4810 "search" or "/" search pattern history 4811 "expr" or "=" typed expression history 4812 "input" or "@" input line history 4813 "debug" or ">" debug command history 4814 empty the current or last used history 4815 The {history} string does not need to be the whole name, one 4816 character is sufficient. 4817 If {item} does already exist in the history, it will be 4818 shifted to become the newest entry. 4819 The result is a Number: TRUE if the operation was successful, 4820 otherwise FALSE is returned. 4821 4822 Example: >vim 4823 call histadd("input", strftime("%Y %b %d")) 4824 let date=input("Enter date: ") 4825 < This function is not available in the |sandbox|. 4826 4827 Parameters: ~ 4828 • {history} (`string`) 4829 • {item} (`any`) 4830 4831 Return: ~ 4832 (`0|1`) 4833 4834 histdel({history} [, {item}]) *histdel()* 4835 Clear {history}, i.e. delete all its entries. See |hist-names| 4836 for the possible values of {history}. 4837 4838 If the parameter {item} evaluates to a String, it is used as a 4839 regular expression. All entries matching that expression will 4840 be removed from the history (if there are any). 4841 Upper/lowercase must match, unless "\c" is used |/\c|. 4842 If {item} evaluates to a Number, it will be interpreted as 4843 an index, see |:history-indexing|. The respective entry will 4844 be removed if it exists. 4845 4846 The result is TRUE for a successful operation, otherwise FALSE 4847 is returned. 4848 4849 Examples: 4850 Clear expression register history: >vim 4851 call histdel("expr") 4852 < 4853 Remove all entries starting with "*" from the search history: >vim 4854 call histdel("/", '^\*') 4855 < 4856 The following three are equivalent: >vim 4857 call histdel("search", histnr("search")) 4858 call histdel("search", -1) 4859 call histdel("search", '^' .. histget("search", -1) .. '$') 4860 < 4861 To delete the last search pattern and use the last-but-one for 4862 the "n" command and 'hlsearch': >vim 4863 call histdel("search", -1) 4864 let @/ = histget("search", -1) 4865 < 4866 4867 Parameters: ~ 4868 • {history} (`string`) 4869 • {item} (`any?`) 4870 4871 Return: ~ 4872 (`0|1`) 4873 4874 histget({history} [, {index}]) *histget()* 4875 The result is a String, the entry with Number {index} from 4876 {history}. See |hist-names| for the possible values of 4877 {history}, and |:history-indexing| for {index}. If there is 4878 no such entry, an empty String is returned. When {index} is 4879 omitted, the most recent item from the history is used. 4880 4881 Examples: 4882 Redo the second last search from history. >vim 4883 execute '/' .. histget("search", -2) 4884 4885 < Define an Ex command ":H {num}" that supports re-execution of 4886 the {num}th entry from the output of |:history|. >vim 4887 command -nargs=1 H execute histget("cmd", 0+<args>) 4888 < 4889 4890 Parameters: ~ 4891 • {history} (`string`) 4892 • {index} (`integer|string?`) 4893 4894 Return: ~ 4895 (`string`) 4896 4897 histnr({history}) *histnr()* 4898 The result is the Number of the current entry in {history}. 4899 See |hist-names| for the possible values of {history}. 4900 If an error occurred, -1 is returned. 4901 4902 Example: >vim 4903 let inp_index = histnr("expr") 4904 < 4905 4906 Parameters: ~ 4907 • {history} (`string`) 4908 4909 Return: ~ 4910 (`integer`) 4911 4912 hlID({name}) *hlID()* 4913 The result is a Number, which is the ID of the highlight group 4914 with name {name}. When the highlight group doesn't exist, 4915 zero is returned. 4916 This can be used to retrieve information about the highlight 4917 group. For example, to get the background color of the 4918 "Comment" group: >vim 4919 echo synIDattr(synIDtrans(hlID("Comment")), "bg") 4920 < 4921 4922 Parameters: ~ 4923 • {name} (`string`) 4924 4925 Return: ~ 4926 (`integer`) 4927 4928 hlexists({name}) *hlexists()* 4929 The result is a Number, which is TRUE if a highlight group 4930 called {name} exists. This is when the group has been 4931 defined in some way. Not necessarily when highlighting has 4932 been defined for it, it may also have been used for a syntax 4933 item. 4934 4935 Parameters: ~ 4936 • {name} (`string`) 4937 4938 Return: ~ 4939 (`0|1`) 4940 4941 hostname() *hostname()* 4942 The result is a String, which is the name of the machine on 4943 which Vim is currently running. Machine names greater than 4944 256 characters long are truncated. 4945 4946 Return: ~ 4947 (`string`) 4948 4949 iconv({string}, {from}, {to}) *iconv()* 4950 The result is a String, which is the text {string} converted 4951 from encoding {from} to encoding {to}. 4952 When the conversion completely fails an empty string is 4953 returned. When some characters could not be converted they 4954 are replaced with "?". 4955 The encoding names are whatever the iconv() library function 4956 can accept, see ":!man 3 iconv". 4957 Note that Vim uses UTF-8 for all Unicode encodings, conversion 4958 from/to UCS-2 is automatically changed to use UTF-8. You 4959 cannot use UCS-2 in a string anyway, because of the NUL bytes. 4960 4961 Parameters: ~ 4962 • {string} (`string`) 4963 • {from} (`string`) 4964 • {to} (`string`) 4965 4966 Return: ~ 4967 (`string`) 4968 4969 id({expr}) *id()* 4970 Returns a |String| which is a unique identifier of the 4971 container type (|List|, |Dict|, |Blob| and |Partial|). It is 4972 guaranteed that for the mentioned types `id(v1) ==# id(v2)` 4973 returns true iff `type(v1) == type(v2) && v1 is v2`. 4974 Note that `v:_null_string`, `v:_null_list`, `v:_null_dict` and 4975 `v:_null_blob` have the same `id()` with different types 4976 because they are internally represented as NULL pointers. 4977 `id()` returns a hexadecimal representation of the pointers to 4978 the containers (i.e. like `0x994a40`), same as `printf("%p", 4979 {expr})`, but it is advised against counting on the exact 4980 format of the return value. 4981 4982 It is not guaranteed that `id(no_longer_existing_container)` 4983 will not be equal to some other `id()`: new containers may 4984 reuse identifiers of the garbage-collected ones. 4985 4986 Parameters: ~ 4987 • {expr} (`any`) 4988 4989 Return: ~ 4990 (`string`) 4991 4992 indent({lnum}) *indent()* 4993 The result is a Number, which is indent of line {lnum} in the 4994 current buffer. The indent is counted in spaces, the value 4995 of 'tabstop' is relevant. {lnum} is used just like in 4996 |getline()|. 4997 When {lnum} is invalid -1 is returned. 4998 4999 To get or set indent of lines in a string, see |vim.text.indent()|. 5000 5001 Parameters: ~ 5002 • {lnum} (`integer|string`) 5003 5004 Return: ~ 5005 (`integer`) 5006 5007 index({object}, {expr} [, {start} [, {ic}]]) *index()* 5008 Find {expr} in {object} and return its index. See 5009 |indexof()| for using a lambda to select the item. 5010 5011 If {object} is a |List| return the lowest index where the item 5012 has a value equal to {expr}. There is no automatic 5013 conversion, so the String "4" is different from the Number 4. 5014 And the Number 4 is different from the Float 4.0. The value 5015 of 'ignorecase' is not used here, case matters as indicated by 5016 the {ic} argument. 5017 5018 If {object} is a |Blob| return the lowest index where the byte 5019 value is equal to {expr}. 5020 5021 If {start} is given then start looking at the item with index 5022 {start} (may be negative for an item relative to the end). 5023 5024 When {ic} is given and it is |TRUE|, ignore case. Otherwise 5025 case must match. 5026 5027 -1 is returned when {expr} is not found in {object}. 5028 Example: >vim 5029 let idx = index(words, "the") 5030 if index(numbers, 123) >= 0 5031 " ... 5032 endif 5033 < 5034 5035 Parameters: ~ 5036 • {object} (`any`) 5037 • {expr} (`any`) 5038 • {start} (`integer?`) 5039 • {ic} (`boolean?`) 5040 5041 Return: ~ 5042 (`integer`) 5043 5044 indexof({object}, {expr} [, {opts}]) *indexof()* 5045 Returns the index of an item in {object} where {expr} is 5046 v:true. {object} must be a |List| or a |Blob|. 5047 5048 If {object} is a |List|, evaluate {expr} for each item in the 5049 List until the expression is v:true and return the index of 5050 this item. 5051 5052 If {object} is a |Blob| evaluate {expr} for each byte in the 5053 Blob until the expression is v:true and return the index of 5054 this byte. 5055 5056 {expr} must be a |string| or |Funcref|. 5057 5058 If {expr} is a |string|: If {object} is a |List|, inside 5059 {expr} |v:key| has the index of the current List item and 5060 |v:val| has the value of the item. If {object} is a |Blob|, 5061 inside {expr} |v:key| has the index of the current byte and 5062 |v:val| has the byte value. 5063 5064 If {expr} is a |Funcref| it must take two arguments: 5065 1. the key or the index of the current item. 5066 2. the value of the current item. 5067 The function must return |TRUE| if the item is found and the 5068 search should stop. 5069 5070 The optional argument {opts} is a Dict and supports the 5071 following items: 5072 startidx start evaluating {expr} at the item with this 5073 index; may be negative for an item relative to 5074 the end 5075 Returns -1 when {expr} evaluates to v:false for all the items. 5076 Example: >vim 5077 let l = [#{n: 10}, #{n: 20}, #{n: 30}] 5078 echo indexof(l, "v:val.n == 20") 5079 echo indexof(l, {i, v -> v.n == 30}) 5080 echo indexof(l, "v:val.n == 20", #{startidx: 1}) 5081 < 5082 5083 Parameters: ~ 5084 • {object} (`any`) 5085 • {expr} (`any`) 5086 • {opts} (`table?`) 5087 5088 Return: ~ 5089 (`integer`) 5090 5091 input({prompt} [, {text} [, {completion}]]) *input()* 5092 5093 Parameters: ~ 5094 • {prompt} (`string`) 5095 • {text} (`string?`) 5096 • {completion} (`string?`) 5097 5098 Return: ~ 5099 (`string`) 5100 5101 input({opts}) 5102 The result is a String, which is whatever the user typed on 5103 the command-line. The {prompt} argument is either a prompt 5104 string, or a blank string (for no prompt). A '\n' can be used 5105 in the prompt to start a new line. 5106 5107 In the second form it accepts a single dictionary with the 5108 following keys, any of which may be omitted: 5109 5110 Key Default Description ~ 5111 prompt "" Same as {prompt} in the first form. 5112 default "" Same as {text} in the first form. 5113 completion nothing Same as {completion} in the first form. 5114 cancelreturn "" The value returned when the dialog is 5115 cancelled. 5116 highlight nothing Highlight handler: |Funcref|. 5117 5118 The highlighting set with |:echohl| is used for the prompt. 5119 The input is entered just like a command-line, with the same 5120 editing commands and mappings. There is a separate history 5121 for lines typed for input(). 5122 Example: >vim 5123 if input("Coffee or beer? ") == "beer" 5124 echo "Cheers!" 5125 endif 5126 < 5127 If the optional {text} argument is present and not empty, this 5128 is used for the default reply, as if the user typed this. 5129 Example: >vim 5130 let color = input("Color? ", "white") 5131 5132 < The optional {completion} argument specifies the type of 5133 completion supported for the input. Without it completion is 5134 not performed. The supported completion types are the same as 5135 that can be supplied to a user-defined command using the 5136 "-complete=" argument. Refer to |:command-completion| for 5137 more information. Example: >vim 5138 let fname = input("File: ", "", "file") 5139 5140 < *input()-highlight* *E5400* *E5402* 5141 The optional `highlight` key allows specifying function which 5142 will be used for highlighting user input. This function 5143 receives user input as its only argument and must return 5144 a list of 3-tuples [hl_start_col, hl_end_col + 1, hl_group] 5145 where 5146 hl_start_col is the first highlighted column, 5147 hl_end_col is the last highlighted column (+ 1!), 5148 hl_group is |:hi| group used for highlighting. 5149 *E5403* *E5404* *E5405* *E5406* 5150 Both hl_start_col and hl_end_col + 1 must point to the start 5151 of the multibyte character (highlighting must not break 5152 multibyte characters), hl_end_col + 1 may be equal to the 5153 input length. Start column must be in range [0, len(input)), 5154 end column must be in range (hl_start_col, len(input)], 5155 sections must be ordered so that next hl_start_col is greater 5156 then or equal to previous hl_end_col. 5157 5158 Example (try some input with parentheses): >vim 5159 highlight RBP1 guibg=Red ctermbg=red 5160 highlight RBP2 guibg=Yellow ctermbg=yellow 5161 highlight RBP3 guibg=Green ctermbg=green 5162 highlight RBP4 guibg=Blue ctermbg=blue 5163 let g:rainbow_levels = 4 5164 function! RainbowParens(cmdline) 5165 let ret = [] 5166 let i = 0 5167 let lvl = 0 5168 while i < len(a:cmdline) 5169 if a:cmdline[i] is# '(' 5170 call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)]) 5171 let lvl += 1 5172 elseif a:cmdline[i] is# ')' 5173 let lvl -= 1 5174 call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)]) 5175 endif 5176 let i += 1 5177 endwhile 5178 return ret 5179 endfunction 5180 call input({'prompt':'>','highlight':'RainbowParens'}) 5181 < 5182 Highlight function is called at least once for each new 5183 displayed input string, before command-line is redrawn. It is 5184 expected that function is pure for the duration of one input() 5185 call, i.e. it produces the same output for the same input, so 5186 output may be memoized. Function is run like under |:silent| 5187 modifier. If the function causes any errors, it will be 5188 skipped for the duration of the current input() call. 5189 5190 Highlighting is disabled if command-line contains arabic 5191 characters. 5192 5193 NOTE: This function must not be used in a startup file, for 5194 the versions that only run in GUI mode (e.g., the Win32 GUI). 5195 Note: When input() is called from within a mapping it will 5196 consume remaining characters from that mapping, because a 5197 mapping is handled like the characters were typed. 5198 Use |inputsave()| before input() and |inputrestore()| 5199 after input() to avoid that. Another solution is to avoid 5200 that further characters follow in the mapping, e.g., by using 5201 |:execute| or |:normal|. 5202 5203 Example with a mapping: >vim 5204 nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR> 5205 function GetFoo() 5206 call inputsave() 5207 let g:Foo = input("enter search pattern: ") 5208 call inputrestore() 5209 endfunction 5210 < 5211 5212 Parameters: ~ 5213 • {opts} (`table`) 5214 5215 Return: ~ 5216 (`string`) 5217 5218 inputlist({textlist}) *inputlist()* 5219 {textlist} must be a |List| of strings. This |List| is 5220 displayed, one string per line. The user will be prompted to 5221 enter a number, which is returned. 5222 The user can also select an item by clicking on it with the 5223 mouse, if the mouse is enabled in the command line ('mouse' is 5224 "a" or includes "c"). For the first string 0 is returned. 5225 When clicking above the first item a negative number is 5226 returned. When clicking on the prompt one more than the 5227 length of {textlist} is returned. 5228 Make sure {textlist} has less than 'lines' entries, otherwise 5229 it won't work. It's a good idea to put the entry number at 5230 the start of the string. And put a prompt in the first item. 5231 Example: >vim 5232 let color = inputlist(['Select color:', '1. red', 5233 \ '2. green', '3. blue']) 5234 < 5235 5236 Parameters: ~ 5237 • {textlist} (`string[]`) 5238 5239 Return: ~ 5240 (`any`) 5241 5242 inputrestore() *inputrestore()* 5243 Restore typeahead that was saved with a previous |inputsave()|. 5244 Should be called the same number of times |inputsave()| is 5245 called. Calling it more often is harmless though. 5246 Returns TRUE when there is nothing to restore, FALSE 5247 otherwise. 5248 5249 Return: ~ 5250 (`integer`) 5251 5252 inputsave() *inputsave()* 5253 Preserve typeahead (also from mappings) and clear it, so that 5254 a following prompt gets input from the user. Should be 5255 followed by a matching |inputrestore()| after the prompt. Can 5256 be used several times, in which case there must be just as 5257 many |inputrestore()| calls. 5258 Returns TRUE when out of memory, FALSE otherwise. 5259 5260 Return: ~ 5261 (`integer`) 5262 5263 inputsecret({prompt} [, {text}]) *inputsecret()* 5264 This function acts much like the |input()| function with but 5265 two exceptions: 5266 a) the user's response will be displayed as a sequence of 5267 asterisks ("*") thereby keeping the entry secret, and 5268 b) the user's response will not be recorded on the input 5269 |history| stack. 5270 The result is a String, which is whatever the user actually 5271 typed on the command-line in response to the issued prompt. 5272 NOTE: Command-line completion is not supported. 5273 5274 Parameters: ~ 5275 • {prompt} (`string`) 5276 • {text} (`string?`) 5277 5278 Return: ~ 5279 (`string`) 5280 5281 insert({object}, {item} [, {idx}]) *insert()* 5282 When {object} is a |List| or a |Blob| insert {item} at the start 5283 of it. 5284 5285 If {idx} is specified insert {item} before the item with index 5286 {idx}. If {idx} is zero it goes before the first item, just 5287 like omitting {idx}. A negative {idx} is also possible, see 5288 |list-index|. -1 inserts just before the last item. 5289 5290 Returns the resulting |List| or |Blob|. Examples: >vim 5291 let mylist = insert([2, 3, 5], 1) 5292 call insert(mylist, 4, -1) 5293 call insert(mylist, 6, len(mylist)) 5294 < The last example can be done simpler with |add()|. 5295 Note that when {item} is a |List| it is inserted as a single 5296 item. Use |extend()| to concatenate |Lists|. 5297 5298 Parameters: ~ 5299 • {object} (`any`) 5300 • {item} (`any`) 5301 • {idx} (`integer?`) 5302 5303 Return: ~ 5304 (`any`) 5305 5306 interrupt() *interrupt()* 5307 Interrupt script execution. It works more or less like the 5308 user typing CTRL-C, most commands won't execute and control 5309 returns to the user. This is useful to abort execution 5310 from lower down, e.g. in an autocommand. Example: >vim 5311 function s:check_typoname(file) 5312 if fnamemodify(a:file, ':t') == '[' 5313 echomsg 'Maybe typo' 5314 call interrupt() 5315 endif 5316 endfunction 5317 au BufWritePre * call s:check_typoname(expand('<amatch>')) 5318 < 5319 5320 Return: ~ 5321 (`any`) 5322 5323 invert({expr}) *invert()* 5324 Bitwise invert. The argument is converted to a number. A 5325 List, Dict or Float argument causes an error. Example: >vim 5326 let bits = invert(bits) 5327 < 5328 5329 Parameters: ~ 5330 • {expr} (`integer`) 5331 5332 Return: ~ 5333 (`integer`) 5334 5335 isabsolutepath({path}) *isabsolutepath()* 5336 The result is a Number, which is |TRUE| when {path} is an 5337 absolute path. 5338 On Unix, a path is considered absolute when it starts with 5339 '/'. 5340 On MS-Windows, it is considered absolute when it starts with 5341 an optional drive prefix and is followed by a '\' or '/'. UNC 5342 paths are always absolute. 5343 Example: >vim 5344 echo isabsolutepath('/usr/share/') " 1 5345 echo isabsolutepath('./foobar') " 0 5346 echo isabsolutepath('C:\Windows') " 1 5347 echo isabsolutepath('foobar') " 0 5348 echo isabsolutepath('\\remote\file') " 1 5349 < 5350 5351 Parameters: ~ 5352 • {path} (`string`) 5353 5354 Return: ~ 5355 (`0|1`) 5356 5357 isdirectory({directory}) *isdirectory()* 5358 The result is a Number, which is |TRUE| when a directory 5359 with the name {directory} exists. If {directory} doesn't 5360 exist, or isn't a directory, the result is |FALSE|. {directory} 5361 is any expression, which is used as a String. 5362 5363 Parameters: ~ 5364 • {directory} (`string`) 5365 5366 Return: ~ 5367 (`0|1`) 5368 5369 isinf({expr}) *isinf()* 5370 Return 1 if {expr} is a positive infinity, or -1 a negative 5371 infinity, otherwise 0. >vim 5372 echo isinf(1.0 / 0.0) 5373 < 1 >vim 5374 echo isinf(-1.0 / 0.0) 5375 < -1 5376 5377 Parameters: ~ 5378 • {expr} (`number`) 5379 5380 Return: ~ 5381 (`1|0|-1`) 5382 5383 islocked({expr}) *islocked()* *E786* 5384 The result is a Number, which is |TRUE| when {expr} is the 5385 name of a locked variable. 5386 The string argument {expr} must be the name of a variable, 5387 |List| item or |Dictionary| entry, not the variable itself! 5388 Example: >vim 5389 let alist = [0, ['a', 'b'], 2, 3] 5390 lockvar 1 alist 5391 echo islocked('alist') " 1 5392 echo islocked('alist[1]') " 0 5393 5394 < When {expr} is a variable that does not exist you get an error 5395 message. Use |exists()| to check for existence. 5396 5397 Parameters: ~ 5398 • {expr} (`any`) 5399 5400 Return: ~ 5401 (`0|1`) 5402 5403 isnan({expr}) *isnan()* 5404 Return |TRUE| if {expr} is a float with value NaN. >vim 5405 echo isnan(0.0 / 0.0) 5406 < 1 5407 5408 Parameters: ~ 5409 • {expr} (`number`) 5410 5411 Return: ~ 5412 (`0|1`) 5413 5414 items({expr}) *items()* 5415 Return a |List| with all key/index and value pairs of {expr}. 5416 Each |List| item is a list with two items: 5417 - for a |Dict|: the key and the value 5418 - for a |List|, |Blob| or |String|: the index and the value 5419 The returned |List| is in arbitrary order for a |Dict|, 5420 otherwise it's in ascending order of the index. 5421 5422 Also see |keys()| and |values()|. 5423 5424 Example: >vim 5425 let mydict = #{a: 'red', b: 'blue'} 5426 for [key, value] in items(mydict) 5427 echo $"{key} = {value}" 5428 endfor 5429 echo items([1, 2, 3]) 5430 echo items("foobar") 5431 echo items(0z0102) 5432 < 5433 5434 Parameters: ~ 5435 • {expr} (`table|string`) 5436 5437 Return: ~ 5438 (`any`) 5439 5440 jobpid({job}) *jobpid()* 5441 Return the PID (process id) of |job-id| {job}. 5442 5443 Parameters: ~ 5444 • {job} (`integer`) 5445 5446 Return: ~ 5447 (`integer`) 5448 5449 jobresize({job}, {width}, {height}) *jobresize()* 5450 Resize the pseudo terminal window of |job-id| {job} to {width} 5451 columns and {height} rows. 5452 Fails if the job was not started with `"pty":v:true`. 5453 5454 Parameters: ~ 5455 • {job} (`integer`) 5456 • {width} (`integer`) 5457 • {height} (`integer`) 5458 5459 Return: ~ 5460 (`any`) 5461 5462 jobstart({cmd} [, {opts}]) *jobstart()* 5463 Note: Prefer |vim.system()| in Lua (unless using `rpc`, `pty`, or `term`). 5464 5465 Spawns {cmd} as a job. 5466 If {cmd} is a List it runs directly (no 'shell'). 5467 If {cmd} is a String it runs in the 'shell', like this: >vim 5468 call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}']) 5469 < (See |shell-unquoting| for details.) 5470 5471 Example: start a job and handle its output: >vim 5472 call jobstart(['nvim', '-h'], {'on_stdout':{j,d,e->append(line('.'),d)}}) 5473 < 5474 Example: start a job in a |terminal| connected to the current buffer: >vim 5475 call jobstart(['nvim', '-h'], {'term':v:true}) 5476 < 5477 Returns |job-id| on success, 0 on invalid arguments (or job 5478 table is full), -1 if {cmd}[0] or 'shell' is not executable. 5479 The returned job-id is a valid |channel-id| representing the 5480 job's stdio streams. Use |chansend()| (or |rpcnotify()| and 5481 |rpcrequest()| if "rpc" was enabled) to send data to stdin and 5482 |chanclose()| to close the streams without stopping the job. 5483 5484 See |job-control| and |RPC|. 5485 5486 NOTE: on Windows if {cmd} is a List: 5487 - cmd[0] must be an executable (not a "built-in"). If it is 5488 in $PATH it can be called by name, without an extension: >vim 5489 call jobstart(['ping', 'neovim.io']) 5490 < If it is a full or partial path, extension is required: >vim 5491 call jobstart(['System32\ping.exe', 'neovim.io']) 5492 < - {cmd} is collapsed to a string of quoted args as expected 5493 by CommandLineToArgvW https://msdn.microsoft.com/bb776391 5494 unless cmd[0] is some form of "cmd.exe". 5495 5496 *jobstart-env* 5497 The job environment is initialized as follows: 5498 $NVIM is set to |v:servername| of the parent Nvim 5499 $NVIM_LISTEN_ADDRESS is unset 5500 $NVIM_LOG_FILE is unset 5501 $VIM is unset 5502 $VIMRUNTIME is unset 5503 You can set these with the `env` option. 5504 5505 *jobstart-options* 5506 {opts} is a dictionary with these keys: 5507 clear_env: (boolean) `env` defines the job environment 5508 exactly, instead of merging current environment. 5509 cwd: (string, default=|current-directory|) Working 5510 directory of the job. 5511 detach: (boolean) Detach the job process: it will not be 5512 killed when Nvim exits. If the process exits 5513 before Nvim, `on_exit` will be invoked. 5514 env: (dict) Map of environment variable name:value 5515 pairs extending (or replace with "clear_env") 5516 the current environment. |jobstart-env| 5517 height: (number) Height of the `pty` terminal. 5518 |on_exit|: (function) Callback invoked when the job exits. 5519 |on_stdout|: (function) Callback invoked when the job emits 5520 stdout data. 5521 |on_stderr|: (function) Callback invoked when the job emits 5522 stderr data. 5523 overlapped: (boolean) Sets FILE_FLAG_OVERLAPPED for the 5524 stdio passed to the child process. Only on 5525 MS-Windows; ignored on other platforms. 5526 pty: (boolean) Connect the job to a new pseudo 5527 terminal, and its streams to the master file 5528 descriptor. `on_stdout` receives all output, 5529 `on_stderr` is ignored. |terminal-start| 5530 rpc: (boolean) Use |msgpack-rpc| to communicate with 5531 the job over stdio. Then `on_stdout` is ignored, 5532 but `on_stderr` can still be used. 5533 stderr_buffered: (boolean) Collect data until EOF (stream closed) 5534 before invoking `on_stderr`. |channel-buffered| 5535 stdout_buffered: (boolean) Collect data until EOF (stream 5536 closed) before invoking `on_stdout`. |channel-buffered| 5537 stdin: (string) Either "pipe" (default) to connect the 5538 job's stdin to a channel or "null" to disconnect 5539 stdin. 5540 term: (boolean) Spawns {cmd} in a new pseudo-terminal session 5541 connected to the current (unmodified) buffer. Implies "pty". 5542 Default "height" and "width" are set to the current window 5543 dimensions. |jobstart()|. Defaults $TERM to "xterm-256color". 5544 width: (number) Width of the `pty` terminal. 5545 5546 {opts} is passed as |self| dictionary to the callback; the 5547 caller may set other keys to pass application-specific data. 5548 5549 Returns: 5550 - |channel-id| on success 5551 - 0 on invalid arguments 5552 - -1 if {cmd}[0] is not executable. 5553 See also |job-control|, |channel|, |msgpack-rpc|. 5554 5555 Parameters: ~ 5556 • {cmd} (`string|string[]`) 5557 • {opts} (`table?`) 5558 5559 Return: ~ 5560 (`integer`) 5561 5562 jobstop({id}) *jobstop()* 5563 Stop |job-id| {id} by sending SIGTERM to the job process. If 5564 the process does not terminate after a timeout then SIGKILL 5565 will be sent. When the job terminates its |on_exit| handler 5566 (if any) will be invoked. 5567 See |job-control|. 5568 5569 Returns 1 for valid job id, 0 for invalid id, including jobs have 5570 exited or stopped. 5571 5572 Parameters: ~ 5573 • {id} (`integer`) 5574 5575 Return: ~ 5576 (`integer`) 5577 5578 jobwait({jobs} [, {timeout}]) *jobwait()* 5579 Waits for jobs and their |on_exit| handlers to complete. 5580 5581 {jobs} is a List of |job-id|s to wait for. 5582 {timeout} is the maximum waiting time in milliseconds. If 5583 omitted or -1, wait forever. 5584 5585 Timeout of 0 can be used to check the status of a job: >vim 5586 let running = jobwait([{job-id}], 0)[0] == -1 5587 < 5588 During jobwait() callbacks for jobs not in the {jobs} list may 5589 be invoked. The screen will not redraw unless |:redraw| is 5590 invoked by a callback. 5591 5592 Returns a list of len({jobs}) integers, where each integer is 5593 the status of the corresponding job: 5594 Exit-code, if the job exited 5595 -1 if the timeout was exceeded 5596 -2 if the job was interrupted (by |CTRL-C|) 5597 -3 if the job-id is invalid 5598 5599 Parameters: ~ 5600 • {jobs} (`integer[]`) 5601 • {timeout} (`integer?`) 5602 5603 Return: ~ 5604 (`integer[]`) 5605 5606 join({list} [, {sep}]) *join()* 5607 Join the items in {list} together into one String. 5608 When {sep} is specified it is put in between the items. If 5609 {sep} is omitted a single space is used. 5610 Note that {sep} is not added at the end. You might want to 5611 add it there too: >vim 5612 let lines = join(mylist, "\n") .. "\n" 5613 < String items are used as-is. |Lists| and |Dictionaries| are 5614 converted into a string like with |string()|. 5615 The opposite function is |split()|. 5616 5617 Parameters: ~ 5618 • {list} (`any[]`) 5619 • {sep} (`string?`) 5620 5621 Return: ~ 5622 (`string`) 5623 5624 json_decode({expr}) *json_decode()* 5625 Convert {expr} from JSON object. Accepts |readfile()|-style 5626 list as the input, as well as regular string. May output any 5627 Vim value. In the following cases it will output 5628 |msgpack-special-dict|: 5629 1. Dictionary contains duplicate key. 5630 2. String contains NUL byte. Two special dictionaries: for 5631 dictionary and for string will be emitted in case string 5632 with NUL byte was a dictionary key. 5633 5634 Note: function treats its input as UTF-8 always. The JSON 5635 standard allows only a few encodings, of which UTF-8 is 5636 recommended and the only one required to be supported. 5637 Non-UTF-8 characters are an error. 5638 5639 Parameters: ~ 5640 • {expr} (`any`) 5641 5642 Return: ~ 5643 (`any`) 5644 5645 json_encode({expr}) *json_encode()* 5646 Convert {expr} into a JSON string. Accepts 5647 |msgpack-special-dict| as the input. Will not convert 5648 |Funcref|s, mappings with non-string keys (can be created as 5649 |msgpack-special-dict|), values with self-referencing 5650 containers, strings which contain non-UTF-8 characters, 5651 pseudo-UTF-8 strings which contain codepoints reserved for 5652 surrogate pairs (such strings are not valid UTF-8 strings). 5653 Non-printable characters are converted into "\u1234" escapes 5654 or special escapes like "\t", other are dumped as-is. 5655 |Blob|s are converted to arrays of the individual bytes. 5656 5657 Parameters: ~ 5658 • {expr} (`any`) 5659 5660 Return: ~ 5661 (`string`) 5662 5663 keys({dict}) *keys()* 5664 Return a |List| with all the keys of {dict}. The |List| is in 5665 arbitrary order. Also see |items()| and |values()|. 5666 5667 Parameters: ~ 5668 • {dict} (`table`) 5669 5670 Return: ~ 5671 (`string[]`) 5672 5673 keytrans({string}) *keytrans()* 5674 Turn the internal byte representation of keys into a form that 5675 can be used for |:map|. E.g. >vim 5676 let xx = "\<C-Home>" 5677 echo keytrans(xx) 5678 < <C-Home> 5679 5680 Parameters: ~ 5681 • {string} (`string`) 5682 5683 Return: ~ 5684 (`string`) 5685 5686 len({expr}) *len()* *E701* 5687 The result is a Number, which is the length of the argument. 5688 When {expr} is a String or a Number the length in bytes is 5689 used, as with |strlen()|. 5690 When {expr} is a |List| the number of items in the |List| is 5691 returned. 5692 When {expr} is a |Blob| the number of bytes is returned. 5693 When {expr} is a |Dictionary| the number of entries in the 5694 |Dictionary| is returned. 5695 Otherwise an error is given and returns zero. 5696 5697 Parameters: ~ 5698 • {expr} (`any[]`) 5699 5700 Return: ~ 5701 (`integer`) 5702 5703 libcall({libname}, {funcname}, {argument}) *libcall()* *E364* *E368* 5704 Call function {funcname} in the run-time library {libname} 5705 with single argument {argument}. 5706 This is useful to call functions in a library that you 5707 especially made to be used with Vim. Since only one argument 5708 is possible, calling standard library functions is rather 5709 limited. 5710 The result is the String returned by the function. If the 5711 function returns NULL, this will appear as an empty string "" 5712 to Vim. 5713 If the function returns a number, use |libcallnr()|! 5714 If {argument} is a number, it is passed to the function as an 5715 int; if {argument} is a string, it is passed as a 5716 null-terminated string. 5717 5718 libcall() allows you to write your own 'plug-in' extensions to 5719 Vim without having to recompile the program. It is NOT a 5720 means to call system functions! If you try to do so Vim will 5721 very probably crash. 5722 5723 For Win32, the functions you write must be placed in a DLL 5724 and use the normal C calling convention (NOT Pascal which is 5725 used in Windows System DLLs). The function must take exactly 5726 one parameter, either a character pointer or a long integer, 5727 and must return a character pointer or NULL. The character 5728 pointer returned must point to memory that will remain valid 5729 after the function has returned (e.g. in static data in the 5730 DLL). If it points to allocated memory, that memory will 5731 leak away. Using a static buffer in the function should work, 5732 it's then freed when the DLL is unloaded. 5733 5734 WARNING: If the function returns a non-valid pointer, Vim may 5735 crash! This also happens if the function returns a number, 5736 because Vim thinks it's a pointer. 5737 For Win32 systems, {libname} should be the filename of the DLL 5738 without the ".DLL" suffix. A full path is only required if 5739 the DLL is not in the usual places. 5740 For Unix: When compiling your own plugins, remember that the 5741 object code must be compiled as position-independent ('PIC'). 5742 Examples: >vim 5743 echo libcall("libc.so", "getenv", "HOME") 5744 < 5745 5746 Parameters: ~ 5747 • {libname} (`string`) 5748 • {funcname} (`string`) 5749 • {argument} (`any`) 5750 5751 Return: ~ 5752 (`any`) 5753 5754 libcallnr({libname}, {funcname}, {argument}) *libcallnr()* 5755 Just like |libcall()|, but used for a function that returns an 5756 int instead of a string. 5757 Examples: >vim 5758 echo libcallnr("/usr/lib/libc.so", "getpid", "") 5759 call libcallnr("libc.so", "printf", "Hello World!\n") 5760 call libcallnr("libc.so", "sleep", 10) 5761 < 5762 5763 Parameters: ~ 5764 • {libname} (`string`) 5765 • {funcname} (`string`) 5766 • {argument} (`any`) 5767 5768 Return: ~ 5769 (`any`) 5770 5771 line({expr} [, {winid}]) *line()* 5772 See |getpos()| for accepted positions. 5773 5774 To get the column number use |col()|. To get both use 5775 |getpos()|. 5776 5777 With the optional {winid} argument the values are obtained for 5778 that window instead of the current window. 5779 5780 Returns 0 for invalid values of {expr} and {winid}. 5781 5782 Examples: >vim 5783 echo line(".") " line number of the cursor 5784 echo line(".", winid) " idem, in window "winid" 5785 echo line("'t") " line number of mark t 5786 echo line("'" .. marker) " line number of mark marker 5787 < 5788 To jump to the last known position when opening a file see 5789 |last-position-jump|. 5790 5791 Parameters: ~ 5792 • {expr} (`string|integer[]`) 5793 • {winid} (`integer?`) 5794 5795 Return: ~ 5796 (`integer`) 5797 5798 line2byte({lnum}) *line2byte()* 5799 Return the byte count from the start of the buffer for line 5800 {lnum}. This includes the end-of-line character, depending on 5801 the 'fileformat' option for the current buffer. The first 5802 line returns 1. UTF-8 encoding is used, 'fileencoding' is 5803 ignored. This can also be used to get the byte count for the 5804 line just below the last line: >vim 5805 echo line2byte(line("$") + 1) 5806 < This is the buffer size plus one. If 'fileencoding' is empty 5807 it is the file size plus one. {lnum} is used like with 5808 |getline()|. When {lnum} is invalid -1 is returned. 5809 Also see |byte2line()|, |go| and |:goto|. 5810 5811 Parameters: ~ 5812 • {lnum} (`integer|string`) 5813 5814 Return: ~ 5815 (`integer`) 5816 5817 lispindent({lnum}) *lispindent()* 5818 Get the amount of indent for line {lnum} according the lisp 5819 indenting rules, as with 'lisp'. 5820 The indent is counted in spaces, the value of 'tabstop' is 5821 relevant. {lnum} is used just like in |getline()|. 5822 When {lnum} is invalid, -1 is returned. 5823 5824 Parameters: ~ 5825 • {lnum} (`integer|string`) 5826 5827 Return: ~ 5828 (`integer`) 5829 5830 list2blob({list}) *list2blob()* 5831 Return a Blob concatenating all the number values in {list}. 5832 Examples: >vim 5833 echo list2blob([1, 2, 3, 4]) " returns 0z01020304 5834 echo list2blob([]) " returns 0z 5835 < Returns an empty Blob on error. If one of the numbers is 5836 negative or more than 255 error *E1239* is given. 5837 5838 |blob2list()| does the opposite. 5839 5840 Parameters: ~ 5841 • {list} (`any[]`) 5842 5843 Return: ~ 5844 (`string`) 5845 5846 list2str({list} [, {utf8}]) *list2str()* 5847 Convert each number in {list} to a character string can 5848 concatenate them all. Examples: >vim 5849 echo list2str([32]) " returns " " 5850 echo list2str([65, 66, 67]) " returns "ABC" 5851 < The same can be done (slowly) with: >vim 5852 echo join(map(list, {nr, val -> nr2char(val)}), '') 5853 < |str2list()| does the opposite. 5854 5855 UTF-8 encoding is always used, {utf8} option has no effect, 5856 and exists only for backwards-compatibility. 5857 With UTF-8 composing characters work as expected: >vim 5858 echo list2str([97, 769]) " returns "á" 5859 < 5860 Returns an empty string on error. 5861 5862 Parameters: ~ 5863 • {list} (`any[]`) 5864 • {utf8} (`boolean?`) 5865 5866 Return: ~ 5867 (`string`) 5868 5869 localtime() *localtime()* 5870 Return the current time, measured as seconds since 1st Jan 5871 1970. See also |strftime()|, |strptime()| and |getftime()|. 5872 5873 Return: ~ 5874 (`integer`) 5875 5876 log({expr}) *log()* 5877 Return the natural logarithm (base e) of {expr} as a |Float|. 5878 {expr} must evaluate to a |Float| or a |Number| in the range 5879 (0, inf]. 5880 Returns 0.0 if {expr} is not a |Float| or a |Number|. 5881 Examples: >vim 5882 echo log(10) 5883 < 2.302585 >vim 5884 echo log(exp(5)) 5885 < 5.0 5886 5887 Parameters: ~ 5888 • {expr} (`number`) 5889 5890 Return: ~ 5891 (`number`) 5892 5893 log10({expr}) *log10()* 5894 Return the logarithm of Float {expr} to base 10 as a |Float|. 5895 {expr} must evaluate to a |Float| or a |Number|. 5896 Returns 0.0 if {expr} is not a |Float| or a |Number|. 5897 Examples: >vim 5898 echo log10(1000) 5899 < 3.0 >vim 5900 echo log10(0.01) 5901 < -2.0 5902 5903 Parameters: ~ 5904 • {expr} (`number`) 5905 5906 Return: ~ 5907 (`number`) 5908 5909 luaeval({expr} [, {expr}]) *luaeval()* 5910 Evaluate Lua expression {expr} and return its result converted 5911 to Vim data structures. See |lua-eval| for details. 5912 5913 See also |v:lua-call|. 5914 5915 Parameters: ~ 5916 • {expr} (`string`) 5917 • {expr1} (`any[]?`) 5918 5919 Return: ~ 5920 (`any`) 5921 5922 map({expr1}, {expr2}) *map()* 5923 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 5924 When {expr1} is a |List| or |Dictionary|, replace each 5925 item in {expr1} with the result of evaluating {expr2}. 5926 For a |Blob| each byte is replaced. 5927 For a |String|, each character, including composing 5928 characters, is replaced. 5929 If the item type changes you may want to use |mapnew()| to 5930 create a new List or Dictionary. 5931 5932 {expr2} must be a |String| or |Funcref|. 5933 5934 If {expr2} is a |String|, inside {expr2} |v:val| has the value 5935 of the current item. For a |Dictionary| |v:key| has the key 5936 of the current item and for a |List| |v:key| has the index of 5937 the current item. For a |Blob| |v:key| has the index of the 5938 current byte. For a |String| |v:key| has the index of the 5939 current character. 5940 Example: >vim 5941 call map(mylist, '"> " .. v:val .. " <"') 5942 < This puts "> " before and " <" after each item in "mylist". 5943 5944 Note that {expr2} is the result of an expression and is then 5945 used as an expression again. Often it is good to use a 5946 |literal-string| to avoid having to double backslashes. You 5947 still have to double ' quotes 5948 5949 If {expr2} is a |Funcref| it is called with two arguments: 5950 1. The key or the index of the current item. 5951 2. the value of the current item. 5952 The function must return the new value of the item. Example 5953 that changes each value by "key-value": >vim 5954 func KeyValue(key, val) 5955 return a:key .. '-' .. a:val 5956 endfunc 5957 call map(myDict, function('KeyValue')) 5958 < It is shorter when using a |lambda|: >vim 5959 call map(myDict, {key, val -> key .. '-' .. val}) 5960 < If you do not use "val" you can leave it out: >vim 5961 call map(myDict, {key -> 'item: ' .. key}) 5962 < If you do not use "key" you can use a short name: >vim 5963 call map(myDict, {_, val -> 'item: ' .. val}) 5964 < 5965 The operation is done in-place for a |List| and |Dictionary|. 5966 If you want it to remain unmodified make a copy first: >vim 5967 let tlist = map(copy(mylist), ' v:val .. "\t"') 5968 5969 < Returns {expr1}, the |List| or |Dictionary| that was filtered, 5970 or a new |Blob| or |String|. 5971 When an error is encountered while evaluating {expr2} no 5972 further items in {expr1} are processed. 5973 When {expr2} is a Funcref errors inside a function are 5974 ignored, unless it was defined with the "abort" flag. 5975 5976 Parameters: ~ 5977 • {expr1} (`string|table|any[]`) 5978 • {expr2} (`string|function`) 5979 5980 Return: ~ 5981 (`any`) 5982 5983 maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* 5984 When {dict} is omitted or zero: Return the rhs of mapping 5985 {name} in mode {mode}. The returned String has special 5986 characters translated like in the output of the ":map" command 5987 listing. When {dict} is TRUE a dictionary is returned, see 5988 below. To get a list of all mappings see |maplist()|. 5989 5990 When there is no mapping for {name}, an empty String is 5991 returned if {dict} is FALSE, otherwise returns an empty Dict. 5992 When the mapping for {name} is empty, then "<Nop>" is 5993 returned. 5994 5995 The {name} can have special key names, like in the ":map" 5996 command. 5997 5998 {mode} can be one of these strings: 5999 "n" Normal 6000 "v" Visual (including Select) 6001 "o" Operator-pending 6002 "i" Insert 6003 "c" Cmd-line 6004 "s" Select 6005 "x" Visual 6006 "l" langmap |language-mapping| 6007 "t" Terminal 6008 "" Normal, Visual and Operator-pending 6009 When {mode} is omitted, the modes for "" are used. 6010 6011 When {abbr} is there and it is |TRUE| use abbreviations 6012 instead of mappings. 6013 6014 When {dict} is |TRUE|, return a dictionary describing the 6015 mapping, with these items: *mapping-dict* 6016 "lhs" The {lhs} of the mapping as it would be typed 6017 "lhsraw" The {lhs} of the mapping as raw bytes 6018 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate 6019 form, only present when it differs from "lhsraw" 6020 "rhs" The {rhs} of the mapping as typed. 6021 "callback" Lua function, if RHS was defined as such. 6022 "silent" 1 for a |:map-silent| mapping, else 0. 6023 "noremap" 1 if the {rhs} of the mapping is not remappable. 6024 "script" 1 if mapping was defined with <script>. 6025 "expr" 1 for an expression mapping (|:map-<expr>|). 6026 "buffer" 1 for a buffer local mapping (|:map-local|). 6027 "mode" Modes for which the mapping is defined. In 6028 addition to the modes mentioned above, these 6029 characters will be used: 6030 " " Normal, Visual and Operator-pending 6031 "!" Insert and Commandline mode 6032 (|mapmode-ic|) 6033 "sid" The script local ID, used for <sid> mappings 6034 (|<SID>|). Negative for special contexts. 6035 "scriptversion" The version of the script, always 1. 6036 "lnum" The line number in "sid", zero if unknown. 6037 "nowait" Do not wait for other, longer mappings. 6038 (|:map-<nowait>|). 6039 "abbr" True if this is an |abbreviation|. 6040 "mode_bits" Nvim's internal binary representation of "mode". 6041 |mapset()| ignores this; only "mode" is used. 6042 See |maplist()| for usage examples. The values 6043 are from src/nvim/state_defs.h and may change in 6044 the future. 6045 6046 The dictionary can be used to restore a mapping with 6047 |mapset()|. 6048 6049 The mappings local to the current buffer are checked first, 6050 then the global mappings. 6051 This function can be used to map a key even when it's already 6052 mapped, and have it do the original mapping too. Sketch: >vim 6053 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n') 6054 < 6055 6056 Parameters: ~ 6057 • {name} (`string`) 6058 • {mode} (`string?`) 6059 • {abbr} (`boolean?`) 6060 • {dict} (`false?`) 6061 6062 Return: ~ 6063 (`string`) 6064 6065 mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()* 6066 Check if there is a mapping that matches with {name} in mode 6067 {mode}. See |maparg()| for {mode} and special names in 6068 {name}. 6069 When {abbr} is there and it is non-zero use abbreviations 6070 instead of mappings. 6071 A match happens with a mapping that starts with {name} and 6072 with a mapping which is equal to the start of {name}. 6073 6074 matches mapping "a" "ab" "abc" ~ 6075 mapcheck("a") yes yes yes 6076 mapcheck("abc") yes yes yes 6077 mapcheck("ax") yes no no 6078 mapcheck("b") no no no 6079 6080 The difference with |maparg()| is that mapcheck() finds a 6081 mapping that matches with {name}, while |maparg()| only finds a 6082 mapping for {name} exactly. 6083 When there is no mapping that starts with {name}, an empty 6084 String is returned. If there is one, the RHS of that mapping 6085 is returned. If there are several mappings that start with 6086 {name}, the RHS of one of them is returned. This will be 6087 "<Nop>" if the RHS is empty. 6088 The mappings local to the current buffer are checked first, 6089 then the global mappings. 6090 This function can be used to check if a mapping can be added 6091 without being ambiguous. Example: >vim 6092 if mapcheck("_vv") == "" 6093 map _vv :set guifont=7x13<CR> 6094 endif 6095 < This avoids adding the "_vv" mapping when there already is a 6096 mapping for "_v" or for "_vvv". 6097 6098 Parameters: ~ 6099 • {name} (`string`) 6100 • {mode} (`string?`) 6101 • {abbr} (`boolean?`) 6102 6103 Return: ~ 6104 (`any`) 6105 6106 maplist([{abbr}]) *maplist()* 6107 Returns a |List| of all mappings. Each List item is a |Dict|, 6108 the same as what is returned by |maparg()|, see 6109 |mapping-dict|. When {abbr} is there and it is |TRUE| use 6110 abbreviations instead of mappings. 6111 6112 Example to show all mappings with "MultiMatch" in rhs: >vim 6113 echo maplist()->filter({_, m -> 6114 \ match(get(m, 'rhs', ''), 'MultiMatch') >= 0 6115 \ }) 6116 < It can be tricky to find mappings for particular |:map-modes|. 6117 |mapping-dict|'s "mode_bits" can simplify this. For example, 6118 the mode_bits for Normal, Insert or Command-line modes are 6119 0x19. To find all the mappings available in those modes you 6120 can do: >vim 6121 let saved_maps = [] 6122 for m in maplist() 6123 if and(m.mode_bits, 0x19) != 0 6124 eval saved_maps->add(m) 6125 endif 6126 endfor 6127 echo saved_maps->mapnew({_, m -> m.lhs}) 6128 < The values of the mode_bits are defined in Nvim's 6129 src/nvim/state_defs.h file and they can be discovered at 6130 runtime using |:map-commands| and "maplist()". Example: >vim 6131 omap xyzzy <Nop> 6132 let op_bit = maplist()->filter( 6133 \ {_, m -> m.lhs == 'xyzzy'})[0].mode_bits 6134 ounmap xyzzy 6135 echo printf("Operator-pending mode bit: 0x%x", op_bit) 6136 < 6137 6138 Parameters: ~ 6139 • {abbr} (`0|1?`) 6140 6141 Return: ~ 6142 (`table[]`) 6143 6144 mapnew({expr1}, {expr2}) *mapnew()* 6145 Like |map()| but instead of replacing items in {expr1} a new 6146 List or Dictionary is created and returned. {expr1} remains 6147 unchanged. Items can still be changed by {expr2}, if you 6148 don't want that use |deepcopy()| first. 6149 6150 Parameters: ~ 6151 • {expr1} (`any`) 6152 • {expr2} (`any`) 6153 6154 Return: ~ 6155 (`any`) 6156 6157 mapset({mode}, {abbr}, {dict}) *mapset()* 6158 mapset({dict}) 6159 Restore a mapping from a dictionary, possibly returned by 6160 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer 6161 is true, is set on the current buffer; it is up to the caller 6162 to ensure that the intended buffer is the current buffer. 6163 This feature allows copying mappings from one buffer to 6164 another. 6165 The dict.mode value may restore a single mapping that covers 6166 more than one mode, like with mode values of '!', ' ', "nox", 6167 or 'v'. *E1276* 6168 6169 In the first form, {mode} and {abbr} should be the same as 6170 for the call to |maparg()|. *E460* 6171 {mode} is used to define the mode in which the mapping is set, 6172 not the "mode" entry in {dict}. 6173 Example for saving and restoring a mapping: >vim 6174 let save_map = maparg('K', 'n', 0, 1) 6175 nnoremap K somethingelse 6176 " ... 6177 call mapset('n', 0, save_map) 6178 < Note that if you are going to replace a map in several modes, 6179 e.g. with `:map!`, you need to save/restore the mapping for 6180 all of them, when they might differ. 6181 6182 In the second form, with {dict} as the only argument, mode 6183 and abbr are taken from the dict. 6184 Example: >vim 6185 let save_maps = maplist()->filter( 6186 \ {_, m -> m.lhs == 'K'}) 6187 nnoremap K somethingelse 6188 cnoremap K somethingelse2 6189 " ... 6190 unmap K 6191 for d in save_maps 6192 call mapset(d) 6193 endfor 6194 < 6195 6196 Parameters: ~ 6197 • {dict} (`table<string,any>`) 6198 6199 Return: ~ 6200 (`any`) 6201 6202 match({expr}, {pat} [, {start} [, {count}]]) *match()* 6203 When {expr} is a |List| then this returns the index of the 6204 first item where {pat} matches. Each item is used as a 6205 String, |Lists| and |Dictionaries| are used as echoed. 6206 6207 Otherwise, {expr} is used as a String. The result is a 6208 Number, which gives the index (byte offset) in {expr} where 6209 {pat} matches. 6210 6211 A match at the first character or |List| item returns zero. 6212 If there is no match -1 is returned. 6213 6214 For getting submatches see |matchlist()|. 6215 Example: >vim 6216 echo match("testing", "ing") " results in 4 6217 echo match([1, 'x'], '\a') " results in 1 6218 < See |string-match| for how {pat} is used. 6219 *strpbrk()* 6220 Vim doesn't have a strpbrk() function. But you can do: >vim 6221 let sepidx = match(line, '[.,;: \t]') 6222 < *strcasestr()* 6223 Vim doesn't have a strcasestr() function. But you can add 6224 "\c" to the pattern to ignore case: >vim 6225 let idx = match(haystack, '\cneedle') 6226 < 6227 If {start} is given, the search starts from byte index 6228 {start} in a String or item {start} in a |List|. 6229 The result, however, is still the index counted from the 6230 first character/item. Example: >vim 6231 echo match("testing", "ing", 2) 6232 < result is again "4". >vim 6233 echo match("testing", "ing", 4) 6234 < result is again "4". >vim 6235 echo match("testing", "t", 2) 6236 < result is "3". 6237 For a String, if {start} > 0 then it is like the string starts 6238 {start} bytes later, thus "^" will match at {start}. Except 6239 when {count} is given, then it's like matches before the 6240 {start} byte are ignored (this is a bit complicated to keep it 6241 backwards compatible). 6242 For a String, if {start} < 0, it will be set to 0. For a list 6243 the index is counted from the end. 6244 If {start} is out of range ({start} > strlen({expr}) for a 6245 String or {start} > len({expr}) for a |List|) -1 is returned. 6246 6247 When {count} is given use the {count}th match. When a match 6248 is found in a String the search for the next one starts one 6249 character further. Thus this example results in 1: >vim 6250 echo match("testing", "..", 0, 2) 6251 < In a |List| the search continues in the next item. 6252 Note that when {count} is added the way {start} works changes, 6253 see above. 6254 6255 *match-pattern* 6256 See |pattern| for the patterns that are accepted. 6257 The 'ignorecase' option is used to set the ignore-caseness of 6258 the pattern. 'smartcase' is NOT used. The matching is always 6259 done like 'magic' is set and 'cpoptions' is empty. 6260 Note that a match at the start is preferred, thus when the 6261 pattern is using "*" (any number of matches) it tends to find 6262 zero matches at the start instead of a number of matches 6263 further down in the text. 6264 6265 Parameters: ~ 6266 • {expr} (`string|any[]`) 6267 • {pat} (`string`) 6268 • {start} (`integer?`) 6269 • {count} (`integer?`) 6270 6271 Return: ~ 6272 (`integer`) 6273 6274 *matchadd()* *E798* *E799* *E801* *E957* 6275 matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) 6276 Defines a pattern to be highlighted in the current window (a 6277 "match"). It will be highlighted with {group}. Returns an 6278 identification number (ID), which can be used to delete the 6279 match using |matchdelete()|. The ID is bound to the window. 6280 Matching is case sensitive and magic, unless case sensitivity 6281 or magicness are explicitly overridden in {pattern}. The 6282 'magic', 'smartcase' and 'ignorecase' options are not used. 6283 The "Conceal" value is special, it causes the match to be 6284 concealed. 6285 6286 The optional {priority} argument assigns a priority to the 6287 match. A match with a high priority will have its 6288 highlighting overrule that of a match with a lower priority. 6289 A priority is specified as an integer (negative numbers are no 6290 exception). If the {priority} argument is not specified, the 6291 default priority is 10. The priority of 'hlsearch' is zero, 6292 hence all matches with a priority greater than zero will 6293 overrule it. Syntax highlighting (see 'syntax') is a separate 6294 mechanism, and regardless of the chosen priority a match will 6295 always overrule syntax highlighting. 6296 6297 The optional {id} argument allows the request for a specific 6298 match ID. If a specified ID is already taken, an error 6299 message will appear and the match will not be added. An ID 6300 is specified as a positive integer (zero excluded). IDs 1, 2 6301 and 3 are reserved for |:match|, |:2match| and |:3match|, 6302 respectively. 3 is reserved for use by the |matchparen| 6303 plugin. 6304 If the {id} argument is not specified or -1, |matchadd()| 6305 automatically chooses a free ID, which is at least 1000. 6306 6307 The optional {dict} argument allows for further custom 6308 values. Currently this is used to specify a match specific 6309 conceal character that will be shown for |hl-Conceal| 6310 highlighted matches. The dict can have the following members: 6311 6312 conceal Special character to show instead of the 6313 match (only for |hl-Conceal| highlighted 6314 matches, see |:syn-cchar|) 6315 window Instead of the current window use the 6316 window with this number or window ID. 6317 6318 The number of matches is not limited, as it is the case with 6319 the |:match| commands. 6320 6321 Returns -1 on error. 6322 6323 Example: >vim 6324 highlight MyGroup ctermbg=green guibg=green 6325 let m = matchadd("MyGroup", "TODO") 6326 < Deletion of the pattern: >vim 6327 call matchdelete(m) 6328 6329 < A list of matches defined by |matchadd()| and |:match| are 6330 available from |getmatches()|. All matches can be deleted in 6331 one operation by |clearmatches()|. 6332 6333 Parameters: ~ 6334 • {group} (`integer|string`) 6335 • {pattern} (`string`) 6336 • {priority} (`integer?`) 6337 • {id} (`integer?`) 6338 • {dict} (`table?`) 6339 6340 Return: ~ 6341 (`integer`) 6342 6343 matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) *matchaddpos()* 6344 Same as |matchadd()|, but requires a list of positions {pos} 6345 instead of a pattern. This command is faster than |matchadd()| 6346 because it does not handle regular expressions and it sets 6347 buffer line boundaries to redraw screen. It is supposed to be 6348 used when fast match additions and deletions are required, for 6349 example to highlight matching parentheses. 6350 *E5030* *E5031* 6351 {pos} is a list of positions. Each position can be one of 6352 these: 6353 - A number. This whole line will be highlighted. The first 6354 line has number 1. 6355 - A list with one number, e.g., [23]. The whole line with 6356 this number will be highlighted. 6357 - A list with two numbers, e.g., [23, 11]. The first number 6358 is the line number, the second one is the column number 6359 (first column is 1, the value must correspond to the byte 6360 index as |col()| would return). The character at this 6361 position will be highlighted. 6362 - A list with three numbers, e.g., [23, 11, 3]. As above, but 6363 the third number gives the length of the highlight in bytes. 6364 6365 Entries with zero and negative line numbers are silently 6366 ignored, as well as entries with negative column numbers and 6367 lengths. 6368 6369 Returns -1 on error. 6370 6371 Example: >vim 6372 highlight MyGroup ctermbg=green guibg=green 6373 let m = matchaddpos("MyGroup", [[23, 24], 34]) 6374 < Deletion of the pattern: >vim 6375 call matchdelete(m) 6376 6377 < Matches added by |matchaddpos()| are returned by 6378 |getmatches()|. 6379 6380 Parameters: ~ 6381 • {group} (`integer|string`) 6382 • {pos} (`any[]`) 6383 • {priority} (`integer?`) 6384 • {id} (`integer?`) 6385 • {dict} (`table?`) 6386 6387 Return: ~ 6388 (`integer|table`) 6389 6390 matcharg({nr}) *matcharg()* 6391 Selects the {nr} match item, as set with a |:match|, 6392 |:2match| or |:3match| command. 6393 Return a |List| with two elements: 6394 The name of the highlight group used 6395 The pattern used. 6396 When {nr} is not 1, 2 or 3 returns an empty |List|. 6397 When there is no match item set returns ['', '']. 6398 This is useful to save and restore a |:match|. 6399 Highlighting matches using the |:match| commands are limited 6400 to three matches. |matchadd()| does not have this limitation. 6401 6402 Parameters: ~ 6403 • {nr} (`integer`) 6404 6405 Return: ~ 6406 (`string[]`) 6407 6408 matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}]) *matchbufline()* 6409 Returns the |List| of matches in lines from {lnum} to {end} in 6410 buffer {buf} where {pat} matches. 6411 6412 {lnum} and {end} can either be a line number or the string "$" 6413 to refer to the last line in {buf}. 6414 6415 The {dict} argument supports following items: 6416 submatches include submatch information (|/\(|) 6417 6418 For each match, a |Dict| with the following items is returned: 6419 byteidx starting byte index of the match 6420 lnum line number where there is a match 6421 text matched string 6422 Note that there can be multiple matches in a single line. 6423 6424 This function works only for loaded buffers. First call 6425 |bufload()| if needed. 6426 6427 See |match-pattern| for information about the effect of some 6428 option settings on the pattern. 6429 6430 When {buf} is not a valid buffer, the buffer is not loaded or 6431 {lnum} or {end} is not valid then an error is given and an 6432 empty |List| is returned. 6433 6434 Examples: >vim 6435 " Assuming line 3 in buffer 5 contains "a" 6436 echo matchbufline(5, '\<\k\+\>', 3, 3) 6437 < `[{'lnum': 3, 'byteidx': 0, 'text': 'a'}]` >vim 6438 " Assuming line 4 in buffer 10 contains "tik tok" 6439 echo matchbufline(10, '\<\k\+\>', 1, 4) 6440 < `[{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]` 6441 6442 If {submatch} is present and is v:true, then submatches like 6443 "\1", "\2", etc. are also returned. Example: >vim 6444 " Assuming line 2 in buffer 2 contains "acd" 6445 echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2 6446 \ {'submatches': v:true}) 6447 < `[{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]` 6448 The "submatches" List always contains 9 items. If a submatch 6449 is not found, then an empty string is returned for that 6450 submatch. 6451 6452 Parameters: ~ 6453 • {buf} (`string|integer`) 6454 • {pat} (`string`) 6455 • {lnum} (`string|integer`) 6456 • {end} (`string|integer`) 6457 • {dict} (`table?`) 6458 6459 Return: ~ 6460 (`string[]`) 6461 6462 matchdelete({id} [, {win}]) *matchdelete()* *E802* *E803* 6463 Deletes a match with ID {id} previously defined by |matchadd()| 6464 or one of the |:match| commands. Returns 0 if successful, 6465 otherwise -1. See example for |matchadd()|. All matches can 6466 be deleted in one operation by |clearmatches()|. 6467 If {win} is specified, use the window with this number or 6468 window ID instead of the current window. 6469 6470 Parameters: ~ 6471 • {id} (`integer`) 6472 • {win} (`integer?`) 6473 6474 Return: ~ 6475 (`any`) 6476 6477 matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()* 6478 Same as |match()|, but return the index of first character 6479 after the match. Example: >vim 6480 echo matchend("testing", "ing") 6481 < results in "7". 6482 *strspn()* *strcspn()* 6483 Vim doesn't have a strspn() or strcspn() function, but you can 6484 do it with matchend(): >vim 6485 let span = matchend(line, '[a-zA-Z]') 6486 let span = matchend(line, '[^a-zA-Z]') 6487 < Except that -1 is returned when there are no matches. 6488 6489 The {start}, if given, has the same meaning as for |match()|. >vim 6490 echo matchend("testing", "ing", 2) 6491 < results in "7". >vim 6492 echo matchend("testing", "ing", 5) 6493 < result is "-1". 6494 When {expr} is a |List| the result is equal to |match()|. 6495 6496 Parameters: ~ 6497 • {expr} (`any`) 6498 • {pat} (`string`) 6499 • {start} (`integer?`) 6500 • {count} (`integer?`) 6501 6502 Return: ~ 6503 (`integer`) 6504 6505 matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()* 6506 If {list} is a list of strings, then returns a |List| with all 6507 the strings in {list} that fuzzy match {str}. The strings in 6508 the returned list are sorted based on the matching score. 6509 6510 The optional {dict} argument always supports the following 6511 items: 6512 matchseq When this item is present return only matches 6513 that contain the characters in {str} in the 6514 given sequence. 6515 limit Maximum number of matches in {list} to be 6516 returned. Zero means no limit. 6517 6518 If {list} is a list of dictionaries, then the optional {dict} 6519 argument supports the following additional items: 6520 key Key of the item which is fuzzy matched against 6521 {str}. The value of this item should be a 6522 string. 6523 text_cb |Funcref| that will be called for every item 6524 in {list} to get the text for fuzzy matching. 6525 This should accept a dictionary item as the 6526 argument and return the text for that item to 6527 use for fuzzy matching. 6528 6529 {str} is treated as a literal string and regular expression 6530 matching is NOT supported. The maximum supported {str} length 6531 is 256. 6532 6533 When {str} has multiple words each separated by white space, 6534 then the list of strings that have all the words is returned. 6535 6536 If there are no matching strings or there is an error, then an 6537 empty list is returned. If length of {str} is greater than 6538 256, then returns an empty list. 6539 6540 When {limit} is given, matchfuzzy() will find up to this 6541 number of matches in {list} and return them in sorted order. 6542 6543 Refer to |fuzzy-matching| for more information about fuzzy 6544 matching strings. 6545 6546 Example: >vim 6547 echo matchfuzzy(["clay", "crow"], "cay") 6548 < results in ["clay"]. >vim 6549 echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") 6550 < results in a list of buffer names fuzzy matching "ndl". >vim 6551 echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'}) 6552 < results in a list of buffer information dicts with buffer 6553 names fuzzy matching "ndl". >vim 6554 echo getbufinfo()->matchfuzzy("spl", 6555 \ {'text_cb' : {v -> v.name}}) 6556 < results in a list of buffer information dicts with buffer 6557 names fuzzy matching "spl". >vim 6558 echo v:oldfiles->matchfuzzy("test") 6559 < results in a list of file names fuzzy matching "test". >vim 6560 let l = readfile("buffer.c")->matchfuzzy("str") 6561 < results in a list of lines in "buffer.c" fuzzy matching "str". >vim 6562 echo ['one two', 'two one']->matchfuzzy('two one') 6563 < results in `['two one', 'one two']` . >vim 6564 echo ['one two', 'two one']->matchfuzzy('two one', 6565 \ {'matchseq': 1}) 6566 < results in `['two one']`. 6567 6568 Parameters: ~ 6569 • {list} (`any[]`) 6570 • {str} (`string`) 6571 • {dict} (`table?`) 6572 6573 Return: ~ 6574 (`table`) 6575 6576 matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()* 6577 Same as |matchfuzzy()|, but returns the list of matched 6578 strings, the list of character positions where characters 6579 in {str} matches and a list of matching scores. You can 6580 use |byteidx()| to convert a character position to a byte 6581 position. 6582 6583 If {str} matches multiple times in a string, then only the 6584 positions for the best match is returned. 6585 6586 If there are no matching strings or there is an error, then a 6587 list with three empty list items is returned. 6588 6589 Example: >vim 6590 echo matchfuzzypos(['testing'], 'tsg') 6591 < results in [["testing"], [[0, 2, 6]], [99]] >vim 6592 echo matchfuzzypos(['clay', 'lacy'], 'la') 6593 < results in [["lacy", "clay"], [[0, 1], [1, 2]], [153, 133]] >vim 6594 echo [{'text': 'hello', 'id' : 10}] 6595 \ ->matchfuzzypos('ll', {'key' : 'text'}) 6596 < results in `[[{"id": 10, "text": "hello"}], [[2, 3]], [127]]` 6597 6598 Parameters: ~ 6599 • {list} (`any[]`) 6600 • {str} (`string`) 6601 • {dict} (`table?`) 6602 6603 Return: ~ 6604 (`table`) 6605 6606 matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()* 6607 Same as |match()|, but return a |List|. The first item in the 6608 list is the matched string, same as what |matchstr()| would 6609 return. Following items are submatches, like "\1", "\2", etc. 6610 in |:substitute|. When an optional submatch didn't match an 6611 empty string is used. Example: >vim 6612 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)') 6613 < Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] 6614 When there is no match an empty list is returned. 6615 6616 You can pass in a List, but that is not very useful. 6617 6618 Parameters: ~ 6619 • {expr} (`any`) 6620 • {pat} (`string`) 6621 • {start} (`integer?`) 6622 • {count} (`integer?`) 6623 6624 Return: ~ 6625 (`string[]`) 6626 6627 matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()* 6628 Same as |match()|, but return the matched string. Example: >vim 6629 echo matchstr("testing", "ing") 6630 < results in "ing". 6631 When there is no match "" is returned. 6632 The {start}, if given, has the same meaning as for |match()|. >vim 6633 echo matchstr("testing", "ing", 2) 6634 < results in "ing". >vim 6635 echo matchstr("testing", "ing", 5) 6636 < result is "". 6637 When {expr} is a |List| then the matching item is returned. 6638 The type isn't changed, it's not necessarily a String. 6639 6640 Parameters: ~ 6641 • {expr} (`any`) 6642 • {pat} (`string`) 6643 • {start} (`integer?`) 6644 • {count} (`integer?`) 6645 6646 Return: ~ 6647 (`string`) 6648 6649 matchstrlist({list}, {pat} [, {dict}]) *matchstrlist()* 6650 Returns the |List| of matches in {list} where {pat} matches. 6651 {list} is a |List| of strings. {pat} is matched against each 6652 string in {list}. 6653 6654 The {dict} argument supports following items: 6655 submatches include submatch information (|/\(|) 6656 6657 For each match, a |Dict| with the following items is returned: 6658 byteidx starting byte index of the match. 6659 idx index in {list} of the match. 6660 text matched string 6661 submatches a List of submatches. Present only if 6662 "submatches" is set to v:true in {dict}. 6663 6664 See |match-pattern| for information about the effect of some 6665 option settings on the pattern. 6666 6667 Example: >vim 6668 echo matchstrlist(['tik tok'], '\<\k\+\>') 6669 < `[{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]` >vim 6670 echo matchstrlist(['a', 'b'], '\<\k\+\>') 6671 < `[{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]` 6672 6673 If "submatches" is present and is v:true, then submatches like 6674 "\1", "\2", etc. are also returned. Example: >vim 6675 echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 6676 \ #{submatches: v:true}) 6677 < `[{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]` 6678 The "submatches" List always contains 9 items. If a submatch 6679 is not found, then an empty string is returned for that 6680 submatch. 6681 6682 Parameters: ~ 6683 • {list} (`string[]`) 6684 • {pat} (`string`) 6685 • {dict} (`table?`) 6686 6687 Return: ~ 6688 (`string[]`) 6689 6690 matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()* 6691 Same as |matchstr()|, but return the matched string, the start 6692 position and the end position of the match. Example: >vim 6693 echo matchstrpos("testing", "ing") 6694 < results in ["ing", 4, 7]. 6695 When there is no match ["", -1, -1] is returned. 6696 The {start}, if given, has the same meaning as for |match()|. >vim 6697 echo matchstrpos("testing", "ing", 2) 6698 < results in ["ing", 4, 7]. >vim 6699 echo matchstrpos("testing", "ing", 5) 6700 < result is ["", -1, -1]. 6701 When {expr} is a |List| then the matching item, the index 6702 of first item where {pat} matches, the start position and the 6703 end position of the match are returned. >vim 6704 echo matchstrpos([1, '__x'], '\a') 6705 < result is ["x", 1, 2, 3]. 6706 The type isn't changed, it's not necessarily a String. 6707 6708 Parameters: ~ 6709 • {expr} (`any`) 6710 • {pat} (`string`) 6711 • {start} (`integer?`) 6712 • {count} (`integer?`) 6713 6714 Return: ~ 6715 (`table`) 6716 6717 max({expr}) *max()* 6718 Return the maximum value of all items in {expr}. Example: >vim 6719 echo max([apples, pears, oranges]) 6720 6721 < {expr} can be a |List| or a |Dictionary|. For a Dictionary, 6722 it returns the maximum of all values in the Dictionary. 6723 If {expr} is neither a List nor a Dictionary, or one of the 6724 items in {expr} cannot be used as a Number this results in 6725 an error. An empty |List| or |Dictionary| results in zero. 6726 6727 Parameters: ~ 6728 • {expr} (`any`) 6729 6730 Return: ~ 6731 (`number`) 6732 6733 menu_get({path} [, {modes}]) *menu_get()* 6734 Returns a |List| of |Dictionaries| describing |menus| (defined 6735 by |:menu|, |:amenu|, …), including |hidden-menus|. 6736 6737 {path} matches a menu by name, or all menus if {path} is an 6738 empty string. Example: >vim 6739 echo menu_get('File','') 6740 echo menu_get('') 6741 < 6742 {modes} is a string of zero or more modes (see |maparg()| or 6743 |creating-menus| for the list of modes). "a" means "all". 6744 6745 Example: >vim 6746 nnoremenu &Test.Test inormal 6747 inoremenu Test.Test insert 6748 vnoremenu Test.Test x 6749 echo menu_get("") 6750 6751 < returns something like this: > 6752 6753 [ { 6754 "hidden": 0, 6755 "name": "Test", 6756 "priority": 500, 6757 "shortcut": 84, 6758 "submenus": [ { 6759 "hidden": 0, 6760 "mappings": { 6761 i": { 6762 "enabled": 1, 6763 "noremap": 1, 6764 "rhs": "insert", 6765 "sid": 1, 6766 "silent": 0 6767 }, 6768 n": { ... }, 6769 s": { ... }, 6770 v": { ... } 6771 }, 6772 "name": "Test", 6773 "priority": 500, 6774 "shortcut": 0 6775 } ] 6776 } ] 6777 < 6778 6779 Parameters: ~ 6780 • {path} (`string`) 6781 • {modes} (`string?`) 6782 6783 Return: ~ 6784 (`any`) 6785 6786 menu_info({name} [, {mode}]) *menu_info()* 6787 Return information about the specified menu {name} in 6788 mode {mode}. The menu name should be specified without the 6789 shortcut character ('&'). If {name} is "", then the top-level 6790 menu names are returned. 6791 6792 {mode} can be one of these strings: 6793 "n" Normal 6794 "v" Visual (including Select) 6795 "o" Operator-pending 6796 "i" Insert 6797 "c" Cmd-line 6798 "s" Select 6799 "x" Visual 6800 "t" Terminal-Job 6801 "" Normal, Visual and Operator-pending 6802 "!" Insert and Cmd-line 6803 When {mode} is omitted, the modes for "" are used. 6804 6805 Returns a |Dictionary| containing the following items: 6806 accel menu item accelerator text |menu-text| 6807 display display name (name without '&') 6808 enabled v:true if this menu item is enabled 6809 Refer to |:menu-enable| 6810 icon name of the icon file (for toolbar) 6811 |toolbar-icon| 6812 iconidx index of a built-in icon 6813 modes modes for which the menu is defined. In 6814 addition to the modes mentioned above, these 6815 characters will be used: 6816 " " Normal, Visual and Operator-pending 6817 name menu item name. 6818 noremenu v:true if the {rhs} of the menu item is not 6819 remappable else v:false. 6820 priority menu order priority |menu-priority| 6821 rhs right-hand-side of the menu item. The 6822 returned string has special characters 6823 translated like in the output of the ":menu" 6824 command listing. When the {rhs} of a menu 6825 item is empty, then "<Nop>" is returned. 6826 script v:true if script-local remapping of {rhs} is 6827 allowed else v:false. See |:menu-script|. 6828 shortcut shortcut key (character after '&' in 6829 the menu name) |menu-shortcut| 6830 silent v:true if the menu item is created 6831 with <silent> argument |:menu-silent| 6832 submenus |List| containing the names of 6833 all the submenus. Present only if the menu 6834 item has submenus. 6835 6836 Returns an empty dictionary if the menu item is not found. 6837 6838 Examples: >vim 6839 echo menu_info('Edit.Cut') 6840 echo menu_info('File.Save', 'n') 6841 6842 " Display the entire menu hierarchy in a buffer 6843 func ShowMenu(name, pfx) 6844 let m = menu_info(a:name) 6845 call append(line('$'), a:pfx .. m.display) 6846 for child in m->get('submenus', []) 6847 call ShowMenu(a:name .. '.' .. escape(child, '.'), 6848 \ a:pfx .. ' ') 6849 endfor 6850 endfunc 6851 new 6852 for topmenu in menu_info('').submenus 6853 call ShowMenu(topmenu, '') 6854 endfor 6855 < 6856 6857 Parameters: ~ 6858 • {name} (`string`) 6859 • {mode} (`string?`) 6860 6861 Return: ~ 6862 (`any`) 6863 6864 min({expr}) *min()* 6865 Return the minimum value of all items in {expr}. Example: >vim 6866 echo min([apples, pears, oranges]) 6867 6868 < {expr} can be a |List| or a |Dictionary|. For a Dictionary, 6869 it returns the minimum of all values in the Dictionary. 6870 If {expr} is neither a List nor a Dictionary, or one of the 6871 items in {expr} cannot be used as a Number this results in 6872 an error. An empty |List| or |Dictionary| results in zero. 6873 6874 Parameters: ~ 6875 • {expr} (`any`) 6876 6877 Return: ~ 6878 (`number`) 6879 6880 mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739* 6881 Create directory {name}. 6882 6883 When {flags} is present it must be a string. An empty string 6884 has no effect. 6885 6886 {flags} can contain these character flags: 6887 "p" intermediate directories will be created as necessary 6888 "D" {name} will be deleted at the end of the current 6889 function, but not recursively |:defer| 6890 "R" {name} will be deleted recursively at the end of the 6891 current function |:defer| 6892 6893 Note that when {name} has more than one part and "p" is used 6894 some directories may already exist. Only the first one that 6895 is created and what it contains is scheduled to be deleted. 6896 E.g. when using: >vim 6897 call mkdir('subdir/tmp/autoload', 'pR') 6898 < and "subdir" already exists then "subdir/tmp" will be 6899 scheduled for deletion, like with: >vim 6900 defer delete('subdir/tmp', 'rf') 6901 < 6902 If {prot} is given it is used to set the protection bits of 6903 the new directory. The default is 0o755 (rwxr-xr-x: r/w for 6904 the user, readable for others). Use 0o700 to make it 6905 unreadable for others. This is used for the newly created 6906 directories. Note: umask is applied to {prot} (on Unix). 6907 Example: >vim 6908 call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700) 6909 6910 < This function is not available in the |sandbox|. 6911 6912 If you try to create an existing directory with {flags} set to 6913 "p" mkdir() will silently exit. 6914 6915 The function result is a Number, which is TRUE if the call was 6916 successful or FALSE if the directory creation failed or partly 6917 failed. 6918 6919 Parameters: ~ 6920 • {name} (`string`) 6921 • {flags} (`string?`) 6922 • {prot} (`string?`) 6923 6924 Return: ~ 6925 (`integer`) 6926 6927 mode([{expr}]) *mode()* 6928 Return a string that indicates the current mode. 6929 If {expr} is supplied and it evaluates to a non-zero Number or 6930 a non-empty String (|non-zero-arg|), then the full mode is 6931 returned, otherwise only the first letter is returned. 6932 Also see |state()|. 6933 6934 n Normal 6935 no Operator-pending 6936 nov Operator-pending (forced charwise |o_v|) 6937 noV Operator-pending (forced linewise |o_V|) 6938 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|) 6939 CTRL-V is one character 6940 niI Normal using |i_CTRL-O| in |Insert-mode| 6941 niR Normal using |i_CTRL-O| in |Replace-mode| 6942 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode| 6943 nt Normal in |terminal-emulator| (insert goes to 6944 Terminal mode) 6945 ntT Normal using |t_CTRL-\_CTRL-O| in |Terminal-mode| 6946 v Visual by character 6947 vs Visual by character using |v_CTRL-O| in Select mode 6948 V Visual by line 6949 Vs Visual by line using |v_CTRL-O| in Select mode 6950 CTRL-V Visual blockwise 6951 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode 6952 s Select by character 6953 S Select by line 6954 CTRL-S Select blockwise 6955 i Insert 6956 ic Insert mode completion |compl-generic| 6957 ix Insert mode |i_CTRL-X| completion 6958 R Replace |R| 6959 Rc Replace mode completion |compl-generic| 6960 Rx Replace mode |i_CTRL-X| completion 6961 Rv Virtual Replace |gR| 6962 Rvc Virtual Replace mode completion |compl-generic| 6963 Rvx Virtual Replace mode |i_CTRL-X| completion 6964 c Command-line editing 6965 cr Command-line editing overstrike mode |c_<Insert>| 6966 cv Vim Ex mode |gQ| 6967 cvr Vim Ex mode while in overstrike mode |c_<Insert>| 6968 r Hit-enter prompt 6969 rm The -- more -- prompt 6970 r? A |:confirm| query of some sort 6971 ! Shell or external command is executing 6972 t Terminal mode: keys go to the job 6973 6974 This is useful in the 'statusline' option or RPC calls. In 6975 most other places it always returns "c" or "n". 6976 Note that in the future more modes and more specific modes may 6977 be added. It's better not to compare the whole string but 6978 only the leading character(s). 6979 Also see |visualmode()|. 6980 6981 Parameters: ~ 6982 • {expr} (`any?`) 6983 6984 Return: ~ 6985 (`any`) 6986 6987 msgpackdump({list} [, {type}]) *msgpackdump()* 6988 Convert a list of Vimscript objects to msgpack. Returned value is a 6989 |readfile()|-style list. When {type} contains "B", a |Blob| is 6990 returned instead. Example: >vim 6991 call writefile(msgpackdump([{}]), 'fname.mpack', 'b') 6992 < or, using a |Blob|: >vim 6993 call writefile(msgpackdump([{}], 'B'), 'fname.mpack') 6994 < 6995 This will write the single 0x80 byte to a `fname.mpack` file 6996 (dictionary with zero items is represented by 0x80 byte in 6997 messagepack). 6998 6999 Limitations: *E5004* *E5005* 7000 1. |Funcref|s cannot be dumped. 7001 2. Containers that reference themselves cannot be dumped. 7002 3. Dictionary keys are always dumped as STR strings. 7003 4. Other strings and |Blob|s are always dumped as BIN strings. 7004 5. Points 3. and 4. do not apply to |msgpack-special-dict|s. 7005 7006 Parameters: ~ 7007 • {list} (`any`) 7008 • {type} (`any?`) 7009 7010 Return: ~ 7011 (`any`) 7012 7013 msgpackparse({data}) *msgpackparse()* 7014 Convert a |readfile()|-style list or a |Blob| to a list of 7015 Vimscript objects. 7016 Example: >vim 7017 let fname = expand('~/.config/nvim/shada/main.shada') 7018 let mpack = readfile(fname, 'b') 7019 let shada_objects = msgpackparse(mpack) 7020 < This will read ~/.config/nvim/shada/main.shada file to 7021 `shada_objects` list. 7022 7023 Limitations: 7024 1. Mapping ordering is not preserved unless messagepack 7025 mapping is dumped using generic mapping 7026 (|msgpack-special-map|). 7027 2. Since the parser aims to preserve all data untouched 7028 (except for 1.) some strings are parsed to 7029 |msgpack-special-dict| format which is not convenient to 7030 use. 7031 *msgpack-special-dict* 7032 Some messagepack strings may be parsed to special 7033 dictionaries. Special dictionaries are dictionaries which 7034 7035 1. Contain exactly two keys: `_TYPE` and `_VAL`. 7036 2. `_TYPE` key is one of the types found in |v:msgpack_types| 7037 variable. 7038 3. Value for `_VAL` has the following format (Key column 7039 contains name of the key from |v:msgpack_types|): 7040 7041 Key Value ~ 7042 nil Zero, ignored when dumping. Not returned by 7043 |msgpackparse()| since |v:null| was introduced. 7044 boolean One or zero. When dumping it is only checked that 7045 value is a |Number|. Not returned by |msgpackparse()| 7046 since |v:true| and |v:false| were introduced. 7047 integer |List| with four numbers: sign (-1 or 1), highest two 7048 bits, number with bits from 62nd to 31st, lowest 31 7049 bits. I.e. to get actual number one will need to use 7050 code like > 7051 _VAL[0] * ((_VAL[1] << 62) 7052 & (_VAL[2] << 31) 7053 & _VAL[3]) 7054 < Special dictionary with this type will appear in 7055 |msgpackparse()| output under one of the following 7056 circumstances: 7057 1. |Number| is 32-bit and value is either above 7058 INT32_MAX or below INT32_MIN. 7059 2. |Number| is 64-bit and value is above INT64_MAX. It 7060 cannot possibly be below INT64_MIN because msgpack 7061 C parser does not support such values. 7062 float |Float|. This value cannot possibly appear in 7063 |msgpackparse()| output. 7064 string |String|, or |Blob| if binary string contains zero 7065 byte. This value cannot appear in |msgpackparse()| 7066 output since blobs were introduced. 7067 array |List|. This value cannot appear in |msgpackparse()| 7068 output. 7069 *msgpack-special-map* 7070 map |List| of |List|s with two items (key and value) each. 7071 This value will appear in |msgpackparse()| output if 7072 parsed mapping contains one of the following keys: 7073 1. Any key that is not a string (including keys which 7074 are binary strings). 7075 2. String with NUL byte inside. 7076 3. Duplicate key. 7077 ext |List| with two values: first is a signed integer 7078 representing extension type. Second is 7079 |readfile()|-style list of strings. 7080 7081 Parameters: ~ 7082 • {data} (`any`) 7083 7084 Return: ~ 7085 (`any`) 7086 7087 nextnonblank({lnum}) *nextnonblank()* 7088 Return the line number of the first line at or below {lnum} 7089 that is not blank. Example: >vim 7090 if getline(nextnonblank(1)) =~ "Java" | endif 7091 < When {lnum} is invalid or there is no non-blank line at or 7092 below it, zero is returned. 7093 {lnum} is used like with |getline()|. 7094 See also |prevnonblank()|. 7095 7096 Parameters: ~ 7097 • {lnum} (`integer|string`) 7098 7099 Return: ~ 7100 (`integer`) 7101 7102 nr2char({expr} [, {utf8}]) *nr2char()* 7103 Return a string with a single character, which has the number 7104 value {expr}. Examples: >vim 7105 echo nr2char(64) " returns '@' 7106 echo nr2char(32) " returns ' ' 7107 < Example for "utf-8": >vim 7108 echo nr2char(300) " returns I with bow character 7109 < 7110 UTF-8 encoding is always used, {utf8} option has no effect, 7111 and exists only for backwards-compatibility. 7112 Note that a NUL character in the file is specified with 7113 nr2char(10), because NULs are represented with newline 7114 characters. nr2char(0) is a real NUL and terminates the 7115 string, thus results in an empty string. 7116 7117 Parameters: ~ 7118 • {expr} (`integer`) 7119 • {utf8} (`boolean?`) 7120 7121 Return: ~ 7122 (`string`) 7123 7124 nvim_...({...}) *nvim_...()* *E5555* *eval-api* 7125 Call nvim |api| functions. The type checking of arguments will 7126 be stricter than for most other builtins. For instance, 7127 if Integer is expected, a |Number| must be passed in, a 7128 |String| will not be autoconverted. 7129 Buffer numbers, as returned by |bufnr()| could be used as 7130 first argument to nvim_buf_... functions. All functions 7131 expecting an object (buffer, window or tabpage) can 7132 also take the numerical value 0 to indicate the current 7133 (focused) object. 7134 7135 Parameters: ~ 7136 • {...} (`any`) 7137 7138 Return: ~ 7139 (`any`) 7140 7141 or({expr}, {expr}) *or()* 7142 Bitwise OR on the two arguments. The arguments are converted 7143 to a number. A List, Dict or Float argument causes an error. 7144 Also see `and()` and `xor()`. 7145 Example: >vim 7146 let bits = or(bits, 0x80) 7147 7148 < Rationale: The reason this is a function and not using the "|" 7149 character like many languages, is that Vi has always used "|" 7150 to separate commands. In many places it would not be clear if 7151 "|" is an operator or a command separator. 7152 7153 Parameters: ~ 7154 • {expr} (`number`) 7155 • {expr1} (`number`) 7156 7157 Return: ~ 7158 (`any`) 7159 7160 pathshorten({path} [, {len}]) *pathshorten()* 7161 Shorten directory names in the path {path} and return the 7162 result. The tail, the file name, is kept as-is. The other 7163 components in the path are reduced to {len} letters in length. 7164 If {len} is omitted or smaller than 1 then 1 is used (single 7165 letters). Leading '~' and '.' characters are kept. Examples: >vim 7166 echo pathshorten('~/.config/nvim/autoload/file1.vim') 7167 < ~/.c/n/a/file1.vim ~ 7168 >vim 7169 echo pathshorten('~/.config/nvim/autoload/file2.vim', 2) 7170 < ~/.co/nv/au/file2.vim ~ 7171 It doesn't matter if the path exists or not. 7172 Returns an empty string on error. 7173 7174 Parameters: ~ 7175 • {path} (`string`) 7176 • {len} (`integer?`) 7177 7178 Return: ~ 7179 (`string`) 7180 7181 perleval({expr}) *perleval()* 7182 Evaluate |perl| expression {expr} and return its result 7183 converted to Vim data structures. 7184 Numbers and strings are returned as they are (strings are 7185 copied though). 7186 Lists are represented as Vim |List| type. 7187 Dictionaries are represented as Vim |Dictionary| type, 7188 non-string keys result in error. 7189 7190 Note: If you want an array or hash, {expr} must return a 7191 reference to it. 7192 Example: >vim 7193 echo perleval('[1 .. 4]') 7194 < [1, 2, 3, 4] 7195 7196 Parameters: ~ 7197 • {expr} (`any`) 7198 7199 Return: ~ 7200 (`any`) 7201 7202 pow({x}, {y}) *pow()* 7203 Return the power of {x} to the exponent {y} as a |Float|. 7204 {x} and {y} must evaluate to a |Float| or a |Number|. 7205 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|. 7206 Examples: >vim 7207 echo pow(3, 3) 7208 < 27.0 >vim 7209 echo pow(2, 16) 7210 < 65536.0 >vim 7211 echo pow(32, 0.20) 7212 < 2.0 7213 7214 Parameters: ~ 7215 • {x} (`number`) 7216 • {y} (`number`) 7217 7218 Return: ~ 7219 (`number`) 7220 7221 preinserted() *preinserted()* 7222 Returns non-zero if text has been inserted after the cursor 7223 because "preinsert" is present in 'completeopt', or because 7224 "longest" is present in 'completeopt' while 'autocomplete' 7225 is active. Otherwise returns zero. 7226 7227 Return: ~ 7228 (`number`) 7229 7230 prevnonblank({lnum}) *prevnonblank()* 7231 Return the line number of the first line at or above {lnum} 7232 that is not blank. Example: >vim 7233 let ind = indent(prevnonblank(v:lnum - 1)) 7234 < When {lnum} is invalid or there is no non-blank line at or 7235 above it, zero is returned. 7236 {lnum} is used like with |getline()|. 7237 Also see |nextnonblank()|. 7238 7239 Parameters: ~ 7240 • {lnum} (`integer|string`) 7241 7242 Return: ~ 7243 (`integer`) 7244 7245 printf({fmt}, {expr1} ...) *printf()* 7246 Return a String with {fmt}, where "%" items are replaced by 7247 the formatted form of their respective arguments. Example: >vim 7248 echo printf("%4d: E%d %.30s", lnum, errno, msg) 7249 < May result in: 7250 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ 7251 7252 When used as a |method| the base is passed as the second 7253 argument: >vim 7254 Compute()->printf("result: %d") 7255 < 7256 You can use `call()` to pass the items as a list. 7257 7258 Often used items are: 7259 %s string 7260 %6S string right-aligned in 6 display cells 7261 %6s string right-aligned in 6 bytes 7262 %.9s string truncated to 9 bytes 7263 %c single byte 7264 %d decimal number 7265 %5d decimal number padded with spaces to 5 characters 7266 %b binary number 7267 %08b binary number padded with zeros to at least 8 characters 7268 %B binary number using upper case letters 7269 %x hex number 7270 %04x hex number padded with zeros to at least 4 characters 7271 %X hex number using upper case letters 7272 %o octal number 7273 %f floating point number as 12.23, inf, -inf or nan 7274 %F floating point number as 12.23, INF, -INF or NAN 7275 %e floating point number as 1.23e3, inf, -inf or nan 7276 %E floating point number as 1.23E3, INF, -INF or NAN 7277 %g floating point number, as %f or %e depending on value 7278 %G floating point number, as %F or %E depending on value 7279 %% the % character itself 7280 %p representation of the pointer to the container 7281 7282 Conversion specifications start with '%' and end with the 7283 conversion type. All other characters are copied unchanged to 7284 the result. 7285 7286 The "%" starts a conversion specification. The following 7287 arguments appear in sequence: 7288 7289 % [pos-argument] [flags] [field-width] [.precision] type 7290 7291 pos-argument 7292 At most one positional argument specifier. These take 7293 the form {n$}, where n is >= 1. 7294 7295 flags 7296 Zero or more of the following flags: 7297 7298 # The value should be converted to an "alternate 7299 form". For c, d, and s conversions, this option 7300 has no effect. For o conversions, the precision 7301 of the number is increased to force the first 7302 character of the output string to a zero (except 7303 if a zero value is printed with an explicit 7304 precision of zero). 7305 For x and X conversions, a non-zero result has 7306 the string "0x" (or "0X" for X conversions) 7307 prepended to it. 7308 7309 0 (zero) Zero padding. For all conversions the converted 7310 value is padded on the left with zeros rather 7311 than blanks. If a precision is given with a 7312 numeric conversion (d, o, x, and X), the 0 flag 7313 is ignored. 7314 7315 - A negative field width flag; the converted value 7316 is to be left adjusted on the field boundary. 7317 The converted value is padded on the right with 7318 blanks, rather than on the left with blanks or 7319 zeros. A - overrides a 0 if both are given. 7320 7321 ' ' (space) A blank should be left before a positive 7322 number produced by a signed conversion (d). 7323 7324 + A sign must always be placed before a number 7325 produced by a signed conversion. A + overrides 7326 a space if both are used. 7327 7328 field-width 7329 An optional decimal digit string specifying a minimum 7330 field width. If the converted value has fewer bytes 7331 than the field width, it will be padded with spaces on 7332 the left (or right, if the left-adjustment flag has 7333 been given) to fill out the field width. For the S 7334 conversion the count is in cells. 7335 7336 .precision 7337 An optional precision, in the form of a period '.' 7338 followed by an optional digit string. If the digit 7339 string is omitted, the precision is taken as zero. 7340 This gives the minimum number of digits to appear for 7341 d, o, x, and X conversions, the maximum number of 7342 bytes to be printed from a string for s conversions, 7343 or the maximum number of cells to be printed from a 7344 string for S conversions. 7345 For floating point it is the number of digits after 7346 the decimal point. 7347 7348 type 7349 A character that specifies the type of conversion to 7350 be applied, see below. 7351 7352 A field width or precision, or both, may be indicated by an 7353 asterisk "*" instead of a digit string. In this case, a 7354 Number argument supplies the field width or precision. A 7355 negative field width is treated as a left adjustment flag 7356 followed by a positive field width; a negative precision is 7357 treated as though it were missing. Example: >vim 7358 echo printf("%d: %.*s", nr, width, line) 7359 < This limits the length of the text used from "line" to 7360 "width" bytes. 7361 7362 If the argument to be formatted is specified using a 7363 positional argument specifier, and a '*' is used to indicate 7364 that a number argument is to be used to specify the width or 7365 precision, the argument(s) to be used must also be specified 7366 using a {n$} positional argument specifier. See |printf-$|. 7367 7368 The conversion specifiers and their meanings are: 7369 7370 *printf-d* *printf-b* *printf-B* *printf-o* *printf-x* *printf-X* 7371 dbBoxX The Number argument is converted to signed decimal (d), 7372 unsigned binary (b and B), unsigned octal (o), or 7373 unsigned hexadecimal (x and X) notation. The letters 7374 "abcdef" are used for x conversions; the letters 7375 "ABCDEF" are used for X conversions. The precision, if 7376 any, gives the minimum number of digits that must 7377 appear; if the converted value requires fewer digits, it 7378 is padded on the left with zeros. In no case does a 7379 non-existent or small field width cause truncation of a 7380 numeric field; if the result of a conversion is wider 7381 than the field width, the field is expanded to contain 7382 the conversion result. 7383 The 'h' modifier indicates the argument is 16 bits. 7384 The 'l' modifier indicates the argument is a long 7385 integer. The size will be 32 bits or 64 bits 7386 depending on your platform. 7387 The "ll" modifier indicates the argument is 64 bits. 7388 The b and B conversion specifiers never take a width 7389 modifier and always assume their argument is a 64 bit 7390 integer. 7391 Generally, these modifiers are not useful. They are 7392 ignored when type is known from the argument. 7393 7394 i alias for d 7395 D alias for ld 7396 U alias for lu 7397 O alias for lo 7398 7399 *printf-c* 7400 c The Number argument is converted to a byte, and the 7401 resulting character is written. 7402 7403 *printf-s* 7404 s The text of the String argument is used. If a 7405 precision is specified, no more bytes than the number 7406 specified are used. 7407 If the argument is not a String type, it is 7408 automatically converted to text with the same format 7409 as ":echo". 7410 *printf-S* 7411 S The text of the String argument is used. If a 7412 precision is specified, no more display cells than the 7413 number specified are used. 7414 7415 *printf-f* *E807* 7416 f F The Float argument is converted into a string of the 7417 form 123.456. The precision specifies the number of 7418 digits after the decimal point. When the precision is 7419 zero the decimal point is omitted. When the precision 7420 is not specified 6 is used. A really big number 7421 (out of range or dividing by zero) results in "inf" 7422 or "-inf" with %f (INF or -INF with %F). 7423 "0.0 / 0.0" results in "nan" with %f (NAN with %F). 7424 Example: >vim 7425 echo printf("%.2f", 12.115) 7426 < 12.12 7427 Note that roundoff depends on the system libraries. 7428 Use |round()| when in doubt. 7429 7430 *printf-e* *printf-E* 7431 e E The Float argument is converted into a string of the 7432 form 1.234e+03 or 1.234E+03 when using 'E'. The 7433 precision specifies the number of digits after the 7434 decimal point, like with 'f'. 7435 7436 *printf-g* *printf-G* 7437 g G The Float argument is converted like with 'f' if the 7438 value is between 0.001 (inclusive) and 10000000.0 7439 (exclusive). Otherwise 'e' is used for 'g' and 'E' 7440 for 'G'. When no precision is specified superfluous 7441 zeroes and '+' signs are removed, except for the zero 7442 immediately after the decimal point. Thus 10000000.0 7443 results in 1.0e7. 7444 7445 *printf-%* 7446 % A '%' is written. No argument is converted. The 7447 complete conversion specification is "%%". 7448 7449 When a Number argument is expected a String argument is also 7450 accepted and automatically converted. 7451 When a Float or String argument is expected a Number argument 7452 is also accepted and automatically converted. 7453 Any other argument type results in an error message. 7454 7455 *E766* *E767* 7456 The number of {exprN} arguments must exactly match the number 7457 of "%" items. If there are not sufficient or too many 7458 arguments an error is given. Up to 18 arguments can be used. 7459 7460 *printf-$* 7461 In certain languages, error and informative messages are 7462 more readable when the order of words is different from the 7463 corresponding message in English. To accommodate translations 7464 having a different word order, positional arguments may be 7465 used to indicate this. For instance: >vim 7466 7467 #, c-format 7468 msgid "%s returning %s" 7469 msgstr "waarde %2$s komt terug van %1$s" 7470 < 7471 In this example, the sentence has its 2 string arguments 7472 reversed in the output. >vim 7473 7474 echo printf( 7475 "In The Netherlands, vim's creator's name is: %1$s %2$s", 7476 "Bram", "Moolenaar") 7477 < In The Netherlands, vim's creator's name is: Bram Moolenaar >vim 7478 7479 echo printf( 7480 "In Belgium, vim's creator's name is: %2$s %1$s", 7481 "Bram", "Moolenaar") 7482 < In Belgium, vim's creator's name is: Moolenaar Bram 7483 7484 Width (and precision) can be specified using the '*' 7485 specifier. In this case, you must specify the field width 7486 position in the argument list. >vim 7487 7488 echo printf("%1$*2$.*3$d", 1, 2, 3) 7489 < 001 >vim 7490 echo printf("%2$*3$.*1$d", 1, 2, 3) 7491 < 2 >vim 7492 echo printf("%3$*1$.*2$d", 1, 2, 3) 7493 < 03 >vim 7494 echo printf("%1$*2$.*3$g", 1.4142, 2, 3) 7495 < 1.414 7496 7497 You can mix specifying the width and/or precision directly 7498 and via positional arguments: >vim 7499 7500 echo printf("%1$4.*2$f", 1.4142135, 6) 7501 < 1.414214 >vim 7502 echo printf("%1$*2$.4f", 1.4142135, 6) 7503 < 1.4142 >vim 7504 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2) 7505 < 1.41 7506 7507 You will get an overflow error |E1510|, when the field-width 7508 or precision will result in a string longer than 1 MB 7509 (1024*1024 = 1048576) chars. 7510 7511 *E1500* 7512 You cannot mix positional and non-positional arguments: >vim 7513 echo printf("%s%1$s", "One", "Two") 7514 " E1500: Cannot mix positional and non-positional arguments: 7515 " %s%1$s 7516 < 7517 *E1501* 7518 You cannot skip a positional argument in a format string: >vim 7519 echo printf("%3$s%1$s", "One", "Two", "Three") 7520 " E1501: format argument 2 unused in $-style format: 7521 " %3$s%1$s 7522 < 7523 *E1502* 7524 You can re-use a [field-width] (or [precision]) argument: >vim 7525 echo printf("%1$d at width %2$d is: %1$0*2$d", 1, 2) 7526 " 1 at width 2 is: 01 7527 < 7528 However, you can't use it as a different type: >vim 7529 echo printf("%1$d at width %2$ld is: %1$0*2$d", 1, 2) 7530 " E1502: Positional argument 2 used as field width reused as 7531 " different type: long int/int 7532 < 7533 *E1503* 7534 When a positional argument is used, but not the correct number 7535 or arguments is given, an error is raised: >vim 7536 echo printf("%1$d at width %2$d is: %1$0*2$.*3$d", 1, 2) 7537 " E1503: Positional argument 3 out of bounds: %1$d at width 7538 " %2$d is: %1$0*2$.*3$d 7539 < 7540 Only the first error is reported: >vim 7541 echo printf("%1$0*2$.*3$d %4$d", 1, 2) 7542 " E1503: Positional argument 3 out of bounds: %1$0*2$.*3$d 7543 " %4$d 7544 < 7545 *E1504* 7546 A positional argument can be used more than once: >vim 7547 echo printf("%1$s %2$s %1$s", "One", "Two") 7548 " One Two One 7549 < 7550 However, you can't use a different type the second time: >vim 7551 echo printf("%1$s %2$s %1$d", "One", "Two") 7552 " E1504: Positional argument 1 type used inconsistently: 7553 " int/string 7554 < 7555 *E1505* 7556 Various other errors that lead to a format string being 7557 wrongly formatted lead to: >vim 7558 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2) 7559 " E1505: Invalid format specifier: %1$d at width %2$d is: 7560 " %01$*2$.3$d 7561 < 7562 *E1507* 7563 This internal error indicates that the logic to parse a 7564 positional format argument ran into a problem that couldn't be 7565 otherwise reported. Please file a bug against Vim if you run 7566 into this, copying the exact format string and parameters that 7567 were used. 7568 7569 Parameters: ~ 7570 • {fmt} (`string`) 7571 • {expr1} (`any?`) 7572 7573 Return: ~ 7574 (`string`) 7575 7576 prompt_getinput({buf}) *prompt_getinput()* 7577 Gets the current user-input in |prompt-buffer| {buf} without invoking 7578 prompt_callback. {buf} can be a buffer name or number. 7579 7580 If the buffer doesn't exist or isn't a prompt buffer, an empty 7581 string is returned. 7582 7583 Parameters: ~ 7584 • {buf} (`integer|string`) 7585 7586 Return: ~ 7587 (`any`) 7588 7589 prompt_getprompt({buf}) *prompt_getprompt()* 7590 Returns the effective prompt text for buffer {buf}. {buf} can 7591 be a buffer name or number. See |prompt-buffer|. 7592 7593 If the buffer doesn't exist or isn't a prompt buffer, an empty 7594 string is returned. 7595 7596 Parameters: ~ 7597 • {buf} (`integer|string`) 7598 7599 Return: ~ 7600 (`any`) 7601 7602 prompt_setcallback({buf}, {expr}) *prompt_setcallback()* 7603 Set prompt callback for buffer {buf} to {expr}. When {expr} 7604 is an empty string the callback is removed. This has only 7605 effect if {buf} has 'buftype' set to "prompt". 7606 7607 The callback is invoked when pressing Enter. The current 7608 buffer will always be the prompt buffer. A new line for a 7609 prompt is added before invoking the callback, thus the prompt 7610 for which the callback was invoked will be in the last but one 7611 line. 7612 If the callback wants to add text to the buffer, it must 7613 insert it above the last line, since that is where the current 7614 prompt is. This can also be done asynchronously. 7615 The callback is invoked with one argument, which is the text 7616 that was entered at the prompt. This can be an empty string 7617 if the user only typed Enter. 7618 Example: >vim 7619 func s:TextEntered(text) 7620 if a:text == 'exit' || a:text == 'quit' 7621 stopinsert 7622 " Reset 'modified' to allow the buffer to be closed. 7623 " We assume there is nothing useful to be saved. 7624 set nomodified 7625 close 7626 else 7627 " Do something useful with "a:text". In this example 7628 " we just repeat it. 7629 call append(line('$') - 1, 'Entered: "' .. a:text .. '"') 7630 endif 7631 endfunc 7632 call prompt_setcallback(bufnr(), function('s:TextEntered')) 7633 < 7634 7635 Parameters: ~ 7636 • {buf} (`integer|string`) 7637 • {expr} (`string|function`) 7638 7639 Return: ~ 7640 (`any`) 7641 7642 prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()* 7643 Set a callback for buffer {buf} to {expr}. When {expr} is an 7644 empty string the callback is removed. This has only effect if 7645 {buf} has 'buftype' set to "prompt". 7646 7647 This callback will be invoked when pressing CTRL-C in Insert 7648 mode. Without setting a callback Vim will exit Insert mode, 7649 as in any buffer. 7650 7651 Parameters: ~ 7652 • {buf} (`integer|string`) 7653 • {expr} (`string|function`) 7654 7655 Return: ~ 7656 (`any`) 7657 7658 prompt_setprompt({buf}, {text}) *prompt_setprompt()* 7659 Set prompt for buffer {buf} to {text}. You most likely want 7660 {text} to end in a space. 7661 The result is only visible if {buf} has 'buftype' set to 7662 "prompt". Example: >vim 7663 call prompt_setprompt(bufnr(''), 'command: ') 7664 < 7665 7666 Parameters: ~ 7667 • {buf} (`integer|string`) 7668 • {text} (`string`) 7669 7670 Return: ~ 7671 (`any`) 7672 7673 pum_getpos() *pum_getpos()* 7674 If the popup menu (see |ins-completion-menu|) is not visible, 7675 returns an empty |Dictionary|, otherwise, returns a 7676 |Dictionary| with the following keys: 7677 height nr of items visible 7678 width screen cells 7679 row top screen row (0 first row) 7680 col leftmost screen column (0 first col) 7681 size total nr of items 7682 scrollbar |TRUE| if scrollbar is visible 7683 7684 The values are the same as in |v:event| during |CompleteChanged|. 7685 7686 Return: ~ 7687 (`any`) 7688 7689 pumvisible() *pumvisible()* 7690 Returns non-zero when the popup menu is visible, zero 7691 otherwise. See |ins-completion-menu|. 7692 This can be used to avoid some things that would remove the 7693 popup menu. 7694 7695 Return: ~ 7696 (`any`) 7697 7698 py3eval({expr}) *py3eval()* 7699 Evaluate Python expression {expr} and return its result 7700 converted to Vim data structures. 7701 Numbers and strings are returned as they are (strings are 7702 copied though, Unicode strings are additionally converted to 7703 UTF-8). 7704 Lists are represented as Vim |List| type. 7705 Dictionaries are represented as Vim |Dictionary| type with 7706 keys converted to strings. 7707 7708 Parameters: ~ 7709 • {expr} (`any`) 7710 7711 Return: ~ 7712 (`any`) 7713 7714 pyeval({expr}) *pyeval()* *E858* *E859* 7715 Evaluate Python expression {expr} and return its result 7716 converted to Vim data structures. 7717 Numbers and strings are returned as they are (strings are 7718 copied though). 7719 Lists are represented as Vim |List| type. 7720 Dictionaries are represented as Vim |Dictionary| type, 7721 non-string keys result in error. 7722 7723 Parameters: ~ 7724 • {expr} (`any`) 7725 7726 Return: ~ 7727 (`any`) 7728 7729 pyxeval({expr}) *pyxeval()* 7730 Evaluate Python expression {expr} and return its result 7731 converted to Vim data structures. 7732 Uses Python 2 or 3, see |python_x| and 'pyxversion'. 7733 See also: |pyeval()|, |py3eval()| 7734 7735 Parameters: ~ 7736 • {expr} (`any`) 7737 7738 Return: ~ 7739 (`any`) 7740 7741 rand([{expr}]) *rand()* 7742 Return a pseudo-random Number generated with an xoshiro128** 7743 algorithm using seed {expr}. The returned number is 32 bits, 7744 also on 64 bits systems, for consistency. 7745 {expr} can be initialized by |srand()| and will be updated by 7746 rand(). If {expr} is omitted, an internal seed value is used 7747 and updated. 7748 Returns -1 if {expr} is invalid. 7749 7750 Examples: >vim 7751 echo rand() 7752 let seed = srand() 7753 echo rand(seed) 7754 echo rand(seed) % 16 " random number 0 - 15 7755 < 7756 7757 Parameters: ~ 7758 • {expr} (`number?`) 7759 7760 Return: ~ 7761 (`any`) 7762 7763 range({expr} [, {max} [, {stride}]]) *range()* *E726* *E727* 7764 Returns a |List| with Numbers: 7765 - If only {expr} is specified: [0, 1, ..., {expr} - 1] 7766 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}] 7767 - If {stride} is specified: [{expr}, {expr} + {stride}, ..., 7768 {max}] (increasing {expr} with {stride} each time, not 7769 producing a value past {max}). 7770 When the maximum is one before the start the result is an 7771 empty list. When the maximum is more than one before the 7772 start this is an error. 7773 Examples: >vim 7774 echo range(4) " [0, 1, 2, 3] 7775 echo range(2, 4) " [2, 3, 4] 7776 echo range(2, 9, 3) " [2, 5, 8] 7777 echo range(2, -2, -1) " [2, 1, 0, -1, -2] 7778 echo range(0) " [] 7779 echo range(2, 0) " error! 7780 < 7781 7782 Parameters: ~ 7783 • {expr} (`any`) 7784 • {max} (`integer?`) 7785 • {stride} (`integer?`) 7786 7787 Return: ~ 7788 (`any`) 7789 7790 readblob({fname} [, {offset} [, {size}]]) *readblob()* 7791 Read file {fname} in binary mode and return a |Blob|. 7792 If {offset} is specified, read the file from the specified 7793 offset. If it is a negative value, it is used as an offset 7794 from the end of the file. E.g., to read the last 12 bytes: >vim 7795 echo readblob('file.bin', -12) 7796 < If {size} is specified, only the specified size will be read. 7797 E.g. to read the first 100 bytes of a file: >vim 7798 echo readblob('file.bin', 0, 100) 7799 < If {size} is -1 or omitted, the whole data starting from 7800 {offset} will be read. 7801 This can be also used to read the data from a character device 7802 on Unix when {size} is explicitly set. Only if the device 7803 supports seeking {offset} can be used. Otherwise it should be 7804 zero. E.g. to read 10 bytes from a serial console: >vim 7805 echo readblob('/dev/ttyS0', 0, 10) 7806 < When the file can't be opened an error message is given and 7807 the result is an empty |Blob|. 7808 When the offset is beyond the end of the file the result is an 7809 empty blob. 7810 When trying to read more bytes than are available the result 7811 is truncated. 7812 Also see |readfile()| and |writefile()|. 7813 7814 Parameters: ~ 7815 • {fname} (`string`) 7816 • {offset} (`integer?`) 7817 • {size} (`integer?`) 7818 7819 Return: ~ 7820 (`any`) 7821 7822 readdir({directory} [, {expr}]) *readdir()* 7823 Return a list with file and directory names in {directory}. 7824 You can also use |glob()| if you don't need to do complicated 7825 things, such as limiting the number of matches. 7826 7827 When {expr} is omitted all entries are included. 7828 When {expr} is given, it is evaluated to check what to do: 7829 If {expr} results in -1 then no further entries will 7830 be handled. 7831 If {expr} results in 0 then this entry will not be 7832 added to the list. 7833 If {expr} results in 1 then this entry will be added 7834 to the list. 7835 Each time {expr} is evaluated |v:val| is set to the entry name. 7836 When {expr} is a function the name is passed as the argument. 7837 For example, to get a list of files ending in ".txt": >vim 7838 echo readdir(dirname, {n -> n =~ '.txt$'}) 7839 < To skip hidden and backup files: >vim 7840 echo readdir(dirname, {n -> n !~ '^\.\|\~$'}) 7841 7842 < If you want to get a directory tree: >vim 7843 function! s:tree(dir) 7844 return {a:dir : map(readdir(a:dir), 7845 \ {_, x -> isdirectory(x) ? 7846 \ {x : s:tree(a:dir .. '/' .. x)} : x})} 7847 endfunction 7848 echo s:tree(".") 7849 < 7850 Returns an empty List on error. 7851 7852 Parameters: ~ 7853 • {directory} (`string`) 7854 • {expr} (`integer?`) 7855 7856 Return: ~ 7857 (`any`) 7858 7859 readfile({fname} [, {type} [, {max}]]) *readfile()* 7860 Read file {fname} and return a |List|, each line of the file 7861 as an item. Lines are broken at NL characters. Macintosh 7862 files separated with CR will result in a single long line 7863 (unless a NL appears somewhere). 7864 All NUL characters are replaced with a NL character. 7865 When {type} contains "b" binary mode is used: 7866 - When the last line ends in a NL an extra empty list item is 7867 added. 7868 - No CR characters are removed. 7869 Otherwise: 7870 - CR characters that appear before a NL are removed. 7871 - Whether the last line ends in a NL or not does not matter. 7872 - Any UTF-8 byte order mark is removed from the text. 7873 When {max} is given this specifies the maximum number of lines 7874 to be read. Useful if you only want to check the first ten 7875 lines of a file: >vim 7876 for line in readfile(fname, '', 10) 7877 if line =~ 'Date' | echo line | endif 7878 endfor 7879 < When {max} is negative -{max} lines from the end of the file 7880 are returned, or as many as there are. 7881 When {max} is zero the result is an empty list. 7882 Note that without {max} the whole file is read into memory. 7883 Also note that there is no recognition of encoding. Read a 7884 file into a buffer if you need to. 7885 Deprecated (use |readblob()| instead): When {type} contains 7886 "B" a |Blob| is returned with the binary data of the file 7887 unmodified. 7888 When the file can't be opened an error message is given and 7889 the result is an empty list. 7890 Also see |writefile()|. 7891 7892 Parameters: ~ 7893 • {fname} (`string`) 7894 • {type} (`string?`) 7895 • {max} (`integer?`) 7896 7897 Return: ~ 7898 (`string[]`) 7899 7900 reduce({object}, {func} [, {initial}]) *reduce()* *E998* 7901 {func} is called for every item in {object}, which can be a 7902 |String|, |List| or a |Blob|. {func} is called with two 7903 arguments: the result so far and current item. After 7904 processing all items the result is returned. 7905 7906 {initial} is the initial result. When omitted, the first item 7907 in {object} is used and {func} is first called for the second 7908 item. If {initial} is not given and {object} is empty no 7909 result can be computed, an E998 error is given. 7910 7911 Examples: >vim 7912 echo reduce([1, 3, 5], { acc, val -> acc + val }) 7913 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') 7914 echo reduce(0z1122, { acc, val -> 2 * acc + val }) 7915 echo reduce('xyz', { acc, val -> acc .. ',' .. val }) 7916 < 7917 7918 Parameters: ~ 7919 • {object} (`any`) 7920 • {func} (`fun(accumulator: T, current: any): any`) 7921 • {initial} (`any?`) 7922 7923 Return: ~ 7924 (`T`) 7925 7926 reg_executing() *reg_executing()* 7927 Returns the single letter name of the register being executed. 7928 Returns an empty string when no register is being executed. 7929 See |@|. 7930 7931 Return: ~ 7932 (`any`) 7933 7934 reg_recorded() *reg_recorded()* 7935 Returns the single letter name of the last recorded register. 7936 Returns an empty string when nothing was recorded yet. 7937 See |q| and |Q|. 7938 7939 Return: ~ 7940 (`any`) 7941 7942 reg_recording() *reg_recording()* 7943 Returns the single letter name of the register being recorded. 7944 Returns an empty string when not recording. See |q|. 7945 7946 Return: ~ 7947 (`any`) 7948 7949 reltime() *reltime()* 7950 reltime({start}) 7951 reltime({start}, {end}) 7952 Return an item that represents a time value. The item is a 7953 list with items that depend on the system. 7954 The item can be passed to |reltimestr()| to convert it to a 7955 string or |reltimefloat()| to convert to a Float. 7956 7957 Without an argument it returns the current "relative time", an 7958 implementation-defined value meaningful only when used as an 7959 argument to |reltime()|, |reltimestr()| and |reltimefloat()|. 7960 7961 With one argument it returns the time passed since the time 7962 specified in the argument. 7963 With two arguments it returns the time passed between {start} 7964 and {end}. 7965 7966 The {start} and {end} arguments must be values returned by 7967 reltime(). Returns zero on error. 7968 7969 Note: |localtime()| returns the current (non-relative) time. 7970 7971 Parameters: ~ 7972 • {start} (`any?`) 7973 • {end} (`any?`) 7974 7975 Return: ~ 7976 (`any`) 7977 7978 reltimefloat({time}) *reltimefloat()* 7979 Return a Float that represents the time value of {time}. 7980 Unit of time is seconds. 7981 Example: 7982 let start = reltime() 7983 call MyFunction() 7984 let seconds = reltimefloat(reltime(start)) 7985 See the note of |reltimestr()| about overhead. 7986 Also see |profiling|. 7987 If there is an error an empty string is returned 7988 7989 Parameters: ~ 7990 • {time} (`any`) 7991 7992 Return: ~ 7993 (`any`) 7994 7995 reltimestr({time}) *reltimestr()* 7996 Return a String that represents the time value of {time}. 7997 This is the number of seconds, a dot and the number of 7998 microseconds. Example: >vim 7999 let start = reltime() 8000 call MyFunction() 8001 echo reltimestr(reltime(start)) 8002 < Note that overhead for the commands will be added to the time. 8003 Leading spaces are used to make the string align nicely. You 8004 can use |split()| to remove it. >vim 8005 echo split(reltimestr(reltime(start)))[0] 8006 < Also see |profiling|. 8007 If there is an error an empty string is returned 8008 8009 Parameters: ~ 8010 • {time} (`any`) 8011 8012 Return: ~ 8013 (`any`) 8014 8015 remove({list}, {idx}) *remove()* 8016 remove({list}, {idx}, {end}) 8017 Without {end}: Remove the item at {idx} from |List| {list} and 8018 return the item. 8019 With {end}: Remove items from {idx} to {end} (inclusive) and 8020 return a |List| with these items. When {idx} points to the same 8021 item as {end} a list with one item is returned. When {end} 8022 points to an item before {idx} this is an error. 8023 See |list-index| for possible values of {idx} and {end}. 8024 Returns zero on error. 8025 Example: >vim 8026 echo "last item: " .. remove(mylist, -1) 8027 call remove(mylist, 0, 9) 8028 < 8029 Use |delete()| to remove a file. 8030 8031 Parameters: ~ 8032 • {list} (`any[]`) 8033 • {idx} (`integer`) 8034 • {end} (`integer?`) 8035 8036 Return: ~ 8037 (`any`) 8038 8039 remove({blob}, {idx}) 8040 remove({blob}, {idx}, {end}) 8041 Without {end}: Remove the byte at {idx} from |Blob| {blob} and 8042 return the byte. 8043 With {end}: Remove bytes from {idx} to {end} (inclusive) and 8044 return a |Blob| with these bytes. When {idx} points to the same 8045 byte as {end} a |Blob| with one byte is returned. When {end} 8046 points to a byte before {idx} this is an error. 8047 Returns zero on error. 8048 Example: >vim 8049 echo "last byte: " .. remove(myblob, -1) 8050 call remove(mylist, 0, 9) 8051 < 8052 8053 Parameters: ~ 8054 • {blob} (`any`) 8055 • {idx} (`integer`) 8056 • {end} (`integer?`) 8057 8058 Return: ~ 8059 (`any`) 8060 8061 remove({dict}, {key}) 8062 Remove the entry from {dict} with key {key} and return it. 8063 Example: >vim 8064 echo "removed " .. remove(dict, "one") 8065 < If there is no {key} in {dict} this is an error. 8066 Returns zero on error. 8067 8068 Parameters: ~ 8069 • {dict} (`any`) 8070 • {key} (`string`) 8071 8072 Return: ~ 8073 (`any`) 8074 8075 rename({from}, {to}) *rename()* 8076 Rename the file by the name {from} to the name {to}. This 8077 should also work to move files across file systems. The 8078 result is a Number, which is 0 if the file was renamed 8079 successfully, and non-zero when the renaming failed. 8080 NOTE: If {to} exists it is overwritten without warning. 8081 This function is not available in the |sandbox|. 8082 8083 Parameters: ~ 8084 • {from} (`string`) 8085 • {to} (`string`) 8086 8087 Return: ~ 8088 (`integer`) 8089 8090 repeat({expr}, {count}) *repeat()* 8091 Repeat {expr} {count} times and return the concatenated 8092 result. Example: >vim 8093 let separator = repeat('-', 80) 8094 < When {count} is zero or negative the result is empty. 8095 When {expr} is a |List| or a |Blob| the result is {expr} 8096 concatenated {count} times. Example: >vim 8097 let longlist = repeat(['a', 'b'], 3) 8098 < Results in ['a', 'b', 'a', 'b', 'a', 'b']. 8099 8100 Parameters: ~ 8101 • {expr} (`any`) 8102 • {count} (`integer`) 8103 8104 Return: ~ 8105 (`any`) 8106 8107 resolve({filename}) *resolve()* *E655* 8108 On MS-Windows, when {filename} is a shortcut (a .lnk file), 8109 returns the path the shortcut points to in a simplified form. 8110 On Unix, repeat resolving symbolic links in all path 8111 components of {filename} and return the simplified result. 8112 To cope with link cycles, resolving of symbolic links is 8113 stopped after 100 iterations. 8114 On other systems, return the simplified {filename}. 8115 The simplification step is done as by |simplify()|. 8116 resolve() keeps a leading path component specifying the 8117 current directory (provided the result is still a relative 8118 path name) and also keeps a trailing path separator. 8119 8120 Parameters: ~ 8121 • {filename} (`string`) 8122 8123 Return: ~ 8124 (`string`) 8125 8126 reverse({object}) *reverse()* 8127 Reverse the order of items in {object}. {object} can be a 8128 |List|, a |Blob| or a |String|. For a List and a Blob the 8129 items are reversed in-place and {object} is returned. 8130 For a String a new String is returned. 8131 Returns zero if {object} is not a List, Blob or a String. 8132 If you want a List or Blob to remain unmodified make a copy 8133 first: >vim 8134 let revlist = reverse(copy(mylist)) 8135 < 8136 8137 Parameters: ~ 8138 • {object} (`T[]`) 8139 8140 Return: ~ 8141 (`T[]`) 8142 8143 round({expr}) *round()* 8144 Round off {expr} to the nearest integral value and return it 8145 as a |Float|. If {expr} lies halfway between two integral 8146 values, then use the larger one (away from zero). 8147 {expr} must evaluate to a |Float| or a |Number|. 8148 Returns 0.0 if {expr} is not a |Float| or a |Number|. 8149 Examples: >vim 8150 echo round(0.456) 8151 < 0.0 >vim 8152 echo round(4.5) 8153 < 5.0 >vim 8154 echo round(-4.5) 8155 < -5.0 8156 8157 Parameters: ~ 8158 • {expr} (`number`) 8159 8160 Return: ~ 8161 (`number`) 8162 8163 rpcnotify({channel}, {event} [, {args}...]) *rpcnotify()* 8164 Sends {event} to {channel} via |RPC| and returns immediately. 8165 If {channel} is 0, the event is broadcast to all channels. 8166 Example: >vim 8167 au VimLeave call rpcnotify(0, "leaving") 8168 < 8169 8170 Parameters: ~ 8171 • {channel} (`integer`) 8172 • {event} (`string`) 8173 • {...} (`any`) 8174 8175 Return: ~ 8176 (`integer`) 8177 8178 rpcrequest({channel}, {method} [, {args}...]) *rpcrequest()* 8179 Sends a request to {channel} to invoke {method} via 8180 |RPC| and blocks until a response is received. 8181 Example: >vim 8182 let result = rpcrequest(rpc_chan, "func", 1, 2, 3) 8183 < 8184 8185 Parameters: ~ 8186 • {channel} (`integer`) 8187 • {method} (`string`) 8188 • {...} (`any`) 8189 8190 Return: ~ 8191 (`any`) 8192 8193 rubyeval({expr}) *rubyeval()* 8194 Evaluate Ruby expression {expr} and return its result 8195 converted to Vim data structures. 8196 Numbers, floats and strings are returned as they are (strings 8197 are copied though). 8198 Arrays are represented as Vim |List| type. 8199 Hashes are represented as Vim |Dictionary| type. 8200 Other objects are represented as strings resulted from their 8201 "Object#to_s" method. 8202 8203 Parameters: ~ 8204 • {expr} (`any`) 8205 8206 Return: ~ 8207 (`any`) 8208 8209 screenattr({row}, {col}) *screenattr()* 8210 Like |screenchar()|, but return the attribute. This is a rather 8211 arbitrary number that can only be used to compare to the 8212 attribute at other positions. 8213 Returns -1 when row or col is out of range. 8214 8215 Parameters: ~ 8216 • {row} (`integer`) 8217 • {col} (`integer`) 8218 8219 Return: ~ 8220 (`integer`) 8221 8222 screenchar({row}, {col}) *screenchar()* 8223 The result is a Number, which is the character at position 8224 [row, col] on the screen. This works for every possible 8225 screen position, also status lines, window separators and the 8226 command line. The top left position is row one, column one 8227 The character excludes composing characters. For double-byte 8228 encodings it may only be the first byte. 8229 This is mainly to be used for testing. 8230 Returns -1 when row or col is out of range. 8231 8232 Parameters: ~ 8233 • {row} (`integer`) 8234 • {col} (`integer`) 8235 8236 Return: ~ 8237 (`integer`) 8238 8239 screenchars({row}, {col}) *screenchars()* 8240 The result is a |List| of Numbers. The first number is the same 8241 as what |screenchar()| returns. Further numbers are 8242 composing characters on top of the base character. 8243 This is mainly to be used for testing. 8244 Returns an empty List when row or col is out of range. 8245 8246 Parameters: ~ 8247 • {row} (`integer`) 8248 • {col} (`integer`) 8249 8250 Return: ~ 8251 (`integer[]`) 8252 8253 screencol() *screencol()* 8254 The result is a Number, which is the current screen column of 8255 the cursor. The leftmost column has number 1. 8256 This function is mainly used for testing. 8257 8258 Note: Always returns the current screen column, thus if used 8259 in a command (e.g. ":echo screencol()") it will return the 8260 column inside the command line, which is 1 when the command is 8261 executed. To get the cursor position in the file use one of 8262 the following mappings: >vim 8263 nnoremap <expr> GG ":echom " .. screencol() .. "\n" 8264 nnoremap <silent> GG :echom screencol()<CR> 8265 noremap GG <Cmd>echom screencol()<CR> 8266 < 8267 8268 Return: ~ 8269 (`integer[]`) 8270 8271 screenpos({winid}, {lnum}, {col}) *screenpos()* 8272 The result is a Dict with the screen position of the text 8273 character in window {winid} at buffer line {lnum} and column 8274 {col}. {col} is a one-based byte index. 8275 The Dict has these members: 8276 row screen row 8277 col first screen column 8278 endcol last screen column 8279 curscol cursor screen column 8280 If the specified position is not visible, all values are zero. 8281 The "endcol" value differs from "col" when the character 8282 occupies more than one screen cell. E.g. for a Tab "col" can 8283 be 1 and "endcol" can be 8. 8284 The "curscol" value is where the cursor would be placed. For 8285 a Tab it would be the same as "endcol", while for a double 8286 width character it would be the same as "col". 8287 The |conceal| feature is ignored here, the column numbers are 8288 as if 'conceallevel' is zero. You can set the cursor to the 8289 right position and use |screencol()| to get the value with 8290 |conceal| taken into account. 8291 If the position is in a closed fold the screen position of the 8292 first character is returned, {col} is not used. 8293 Returns an empty Dict if {winid} is invalid. 8294 8295 Parameters: ~ 8296 • {winid} (`integer`) 8297 • {lnum} (`integer`) 8298 • {col} (`integer`) 8299 8300 Return: ~ 8301 (`any`) 8302 8303 screenrow() *screenrow()* 8304 The result is a Number, which is the current screen row of the 8305 cursor. The top line has number one. 8306 This function is mainly used for testing. 8307 Alternatively you can use |winline()|. 8308 8309 Note: Same restrictions as with |screencol()|. 8310 8311 Return: ~ 8312 (`integer`) 8313 8314 screenstring({row}, {col}) *screenstring()* 8315 The result is a String that contains the base character and 8316 any composing characters at position [row, col] on the screen. 8317 This is like |screenchars()| but returning a String with the 8318 characters. 8319 This is mainly to be used for testing. 8320 Returns an empty String when row or col is out of range. 8321 8322 Parameters: ~ 8323 • {row} (`integer`) 8324 • {col} (`integer`) 8325 8326 Return: ~ 8327 (`string`) 8328 8329 search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) *search()* 8330 Search for regexp pattern {pattern}. The search starts at the 8331 cursor position (you can use |cursor()| to set it). 8332 8333 When a match has been found its line number is returned. 8334 If there is no match a 0 is returned and the cursor doesn't 8335 move. No error message is given. 8336 To get the matched string, use |matchbufline()|. 8337 8338 {flags} is a String, which can contain these character flags: 8339 'b' search Backward instead of forward 8340 'c' accept a match at the Cursor position 8341 'e' move to the End of the match 8342 'n' do Not move the cursor 8343 'p' return number of matching sub-Pattern (see below) 8344 's' Set the ' mark at the previous location of the cursor 8345 'w' Wrap around the end of the file 8346 'W' don't Wrap around the end of the file 8347 'z' start searching at the cursor column instead of Zero 8348 If neither 'w' or 'W' is given, the 'wrapscan' option applies. 8349 8350 If the 's' flag is supplied, the ' mark is set, only if the 8351 cursor is moved. The 's' flag cannot be combined with the 'n' 8352 flag. 8353 8354 'ignorecase', 'smartcase' and 'magic' are used. 8355 8356 When the 'z' flag is not given, forward searching always 8357 starts in column zero and then matches before the cursor are 8358 skipped. When the 'c' flag is present in 'cpo' the next 8359 search starts after the match. Without the 'c' flag the next 8360 search starts one column after the start of the match. This 8361 matters for overlapping matches. See |cpo-c|. You can also 8362 insert "\ze" to change where the match ends, see |/\ze|. 8363 8364 When searching backwards and the 'z' flag is given then the 8365 search starts in column zero, thus no match in the current 8366 line will be found (unless wrapping around the end of the 8367 file). 8368 8369 When the {stopline} argument is given then the search stops 8370 after searching this line. This is useful to restrict the 8371 search to a range of lines. Examples: >vim 8372 let match = search('(', 'b', line("w0")) 8373 let end = search('END', '', line("w$")) 8374 < When {stopline} is used and it is not zero this also implies 8375 that the search does not wrap around the end of the file. 8376 A zero value is equal to not giving the argument. 8377 8378 When the {timeout} argument is given the search stops when 8379 more than this many milliseconds have passed. Thus when 8380 {timeout} is 500 the search stops after half a second. 8381 The value must not be negative. A zero value is like not 8382 giving the argument. 8383 8384 Note: the timeout is only considered when searching, not 8385 while evaluating the {skip} expression. 8386 8387 If the {skip} expression is given it is evaluated with the 8388 cursor positioned on the start of a match. If it evaluates to 8389 non-zero this match is skipped. This can be used, for 8390 example, to skip a match in a comment or a string. 8391 {skip} can be a string, which is evaluated as an expression, a 8392 function reference or a lambda. 8393 When {skip} is omitted or empty, every match is accepted. 8394 When evaluating {skip} causes an error the search is aborted 8395 and -1 returned. 8396 *search()-sub-match* 8397 With the 'p' flag the returned value is one more than the 8398 first sub-match in \(\). One if none of them matched but the 8399 whole pattern did match. 8400 To get the column number too use |searchpos()|. 8401 8402 The cursor will be positioned at the match, unless the 'n' 8403 flag is used. 8404 8405 Example (goes over all files in the argument list): >vim 8406 let n = 1 8407 while n <= argc() " loop over all files in arglist 8408 exe "argument " .. n 8409 " start at the last char in the file and wrap for the 8410 " first search to find match at start of file 8411 normal G$ 8412 let flags = "w" 8413 while search("foo", flags) > 0 8414 s/foo/bar/g 8415 let flags = "W" 8416 endwhile 8417 update " write the file if modified 8418 let n = n + 1 8419 endwhile 8420 < 8421 Example for using some flags: >vim 8422 echo search('\<if\|\(else\)\|\(endif\)', 'ncpe') 8423 < This will search for the keywords "if", "else", and "endif" 8424 under or after the cursor. Because of the 'p' flag, it 8425 returns 1, 2, or 3 depending on which keyword is found, or 0 8426 if the search fails. With the cursor on the first word of the 8427 line: 8428 if (foo == 0) | let foo = foo + 1 | endif ~ 8429 the function returns 1. Without the 'c' flag, the function 8430 finds the "endif" and returns 3. The same thing happens 8431 without the 'e' flag if the cursor is on the "f" of "if". 8432 The 'n' flag tells the function not to move the cursor. 8433 8434 Parameters: ~ 8435 • {pattern} (`string`) 8436 • {flags} (`string?`) 8437 • {stopline} (`integer?`) 8438 • {timeout} (`integer?`) 8439 • {skip} (`string|function?`) 8440 8441 Return: ~ 8442 (`integer`) 8443 8444 searchcount([{options}]) *searchcount()* 8445 Get or update the last search count, like what is displayed 8446 without the "S" flag in 'shortmess'. This works even if 8447 'shortmess' does contain the "S" flag. 8448 8449 This returns a |Dictionary|. The dictionary is empty if the 8450 previous pattern was not set and "pattern" was not specified. 8451 8452 key type meaning ~ 8453 current |Number| current position of match; 8454 0 if the cursor position is 8455 before the first match 8456 exact_match |Boolean| 1 if "current" is matched on 8457 "pos", otherwise 0 8458 total |Number| total count of matches found 8459 incomplete |Number| 0: search was fully completed 8460 1: recomputing was timed out 8461 2: max count exceeded 8462 8463 For {options} see further down. 8464 8465 To get the last search count when |n| or |N| was pressed, call 8466 this function with `recompute: 0` . This sometimes returns 8467 wrong information because of 'maxsearchcount'. 8468 If the count exceeded 'maxsearchcount', the result must be 8469 'maxsearchcount' + 1. If you want to get correct information, 8470 specify `recompute: 1`: >vim 8471 8472 " result == 'maxsearchcount' + 1 when many matches 8473 let result = searchcount(#{recompute: 0}) 8474 8475 " Below returns correct result (recompute defaults 8476 " to 1) 8477 let result = searchcount() 8478 < 8479 The function is useful to add the count to 'statusline': >vim 8480 function! LastSearchCount() abort 8481 let result = searchcount(#{recompute: 0}) 8482 if empty(result) 8483 return '' 8484 endif 8485 if result.incomplete ==# 1 " timed out 8486 return printf(' /%s [?/??]', @/) 8487 elseif result.incomplete ==# 2 " max count exceeded 8488 if result.total > result.maxcount && 8489 \ result.current > result.maxcount 8490 return printf(' /%s [>%d/>%d]', @/, 8491 \ result.current, result.total) 8492 elseif result.total > result.maxcount 8493 return printf(' /%s [%d/>%d]', @/, 8494 \ result.current, result.total) 8495 endif 8496 endif 8497 return printf(' /%s [%d/%d]', @/, 8498 \ result.current, result.total) 8499 endfunction 8500 let &statusline ..= '%{LastSearchCount()}' 8501 8502 " Or if you want to show the count only when 8503 " 'hlsearch' was on 8504 " let &statusline ..= 8505 " \ '%{v:hlsearch ? LastSearchCount() : ""}' 8506 < 8507 You can also update the search count, which can be useful in a 8508 |CursorMoved| or |CursorMovedI| autocommand: >vim 8509 8510 autocmd CursorMoved,CursorMovedI * 8511 \ let s:searchcount_timer = timer_start( 8512 \ 200, function('s:update_searchcount')) 8513 function! s:update_searchcount(timer) abort 8514 if a:timer ==# s:searchcount_timer 8515 call searchcount(#{ 8516 \ recompute: 1, maxcount: 0, timeout: 100}) 8517 redrawstatus 8518 endif 8519 endfunction 8520 < 8521 This can also be used to count matched texts with specified 8522 pattern in the current buffer using "pattern": >vim 8523 8524 " Count '\<foo\>' in this buffer 8525 " (Note that it also updates search count) 8526 let result = searchcount(#{pattern: '\<foo\>'}) 8527 8528 " To restore old search count by old pattern, 8529 " search again 8530 call searchcount() 8531 < 8532 {options} must be a |Dictionary|. It can contain: 8533 key type meaning ~ 8534 recompute |Boolean| if |TRUE|, recompute the count 8535 like |n| or |N| was executed. 8536 otherwise returns the last 8537 computed result (when |n| or 8538 |N| was used when "S" is not 8539 in 'shortmess', or this 8540 function was called). 8541 (default: |TRUE|) 8542 pattern |String| recompute if this was given 8543 and different with |@/|. 8544 this works as same as the 8545 below command is executed 8546 before calling this function >vim 8547 let @/ = pattern 8548 < (default: |@/|) 8549 timeout |Number| 0 or negative number is no 8550 timeout. timeout milliseconds 8551 for recomputing the result 8552 (default: 0) 8553 maxcount |Number| 0 or negative number is no 8554 limit. max count of matched 8555 text while recomputing the 8556 result. if search exceeded 8557 total count, "total" value 8558 becomes `maxcount + 1` 8559 (default: 'maxsearchcount') 8560 pos |List| `[lnum, col, off]` value 8561 when recomputing the result. 8562 this changes "current" result 8563 value. see |cursor()|, |getpos()| 8564 (default: cursor's position) 8565 8566 Parameters: ~ 8567 • {options} (`table?`) 8568 8569 Return: ~ 8570 (`any`) 8571 8572 searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()* 8573 Search for the declaration of {name}. 8574 8575 With a non-zero {global} argument it works like |gD|, find 8576 first match in the file. Otherwise it works like |gd|, find 8577 first match in the function. 8578 8579 With a non-zero {thisblock} argument matches in a {} block 8580 that ends before the cursor position are ignored. Avoids 8581 finding variable declarations only valid in another scope. 8582 8583 Moves the cursor to the found match. 8584 Returns zero for success, non-zero for failure. 8585 Example: >vim 8586 if searchdecl('myvar') == 0 8587 echo getline('.') 8588 endif 8589 < 8590 8591 Parameters: ~ 8592 • {name} (`string`) 8593 • {global} (`boolean?`) 8594 • {thisblock} (`boolean?`) 8595 8596 Return: ~ 8597 (`any`) 8598 8599 *searchpair()* 8600 searchpair({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline} [, {timeout}]]]]) 8601 Search for the match of a nested start-end pair. This can be 8602 used to find the "endif" that matches an "if", while other 8603 if/endif pairs in between are ignored. 8604 The search starts at the cursor. The default is to search 8605 forward, include 'b' in {flags} to search backward. 8606 If a match is found, the cursor is positioned at it and the 8607 line number is returned. If no match is found 0 or -1 is 8608 returned and the cursor doesn't move. No error message is 8609 given. 8610 8611 {start}, {middle} and {end} are patterns, see |pattern|. They 8612 must not contain \( \) pairs. Use of \%( \) is allowed. When 8613 {middle} is not empty, it is found when searching from either 8614 direction, but only when not in a nested start-end pair. A 8615 typical use is: >vim 8616 echo searchpair('\<if\>', '\<else\>', '\<endif\>') 8617 < By leaving {middle} empty the "else" is skipped. 8618 8619 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with 8620 |search()|. Additionally: 8621 'r' Repeat until no more matches found; will find the 8622 outer pair. Implies the 'W' flag. 8623 'm' Return number of matches instead of line number with 8624 the match; will be > 1 when 'r' is used. 8625 Note: it's nearly always a good idea to use the 'W' flag, to 8626 avoid wrapping around the end of the file. 8627 8628 When a match for {start}, {middle} or {end} is found, the 8629 {skip} expression is evaluated with the cursor positioned on 8630 the start of the match. It should return non-zero if this 8631 match is to be skipped. E.g., because it is inside a comment 8632 or a string. 8633 When {skip} is omitted or empty, every match is accepted. 8634 When evaluating {skip} causes an error the search is aborted 8635 and -1 returned. 8636 {skip} can be a string, a lambda, a funcref or a partial. 8637 Anything else makes the function fail. 8638 8639 For {stopline} and {timeout} see |search()|. 8640 8641 The value of 'ignorecase' is used. 'magic' is ignored, the 8642 patterns are used like it's on. 8643 8644 The search starts exactly at the cursor. A match with 8645 {start}, {middle} or {end} at the next character, in the 8646 direction of searching, is the first one found. Example: >vim 8647 if 1 8648 if 2 8649 endif 2 8650 endif 1 8651 < When starting at the "if 2", with the cursor on the "i", and 8652 searching forwards, the "endif 2" is found. When starting on 8653 the character just before the "if 2", the "endif 1" will be 8654 found. That's because the "if 2" will be found first, and 8655 then this is considered to be a nested if/endif from "if 2" to 8656 "endif 2". 8657 When searching backwards and {end} is more than one character, 8658 it may be useful to put "\zs" at the end of the pattern, so 8659 that when the cursor is inside a match with the end it finds 8660 the matching start. 8661 8662 Example, to find the "endif" command in a Vim script: >vim 8663 8664 echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W', 8665 \ 'getline(".") =~ "^\\s*\""') 8666 8667 < The cursor must be at or after the "if" for which a match is 8668 to be found. Note that single-quote strings are used to avoid 8669 having to double the backslashes. The skip expression only 8670 catches comments at the start of a line, not after a command. 8671 Also, a word "en" or "if" halfway through a line is considered 8672 a match. 8673 Another example, to search for the matching "{" of a "}": >vim 8674 8675 echo searchpair('{', '', '}', 'bW') 8676 8677 < This works when the cursor is at or before the "}" for which a 8678 match is to be found. To reject matches that syntax 8679 highlighting recognized as strings: >vim 8680 8681 echo searchpair('{', '', '}', 'bW', 8682 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"') 8683 < 8684 8685 Parameters: ~ 8686 • {start} (`string`) 8687 • {middle} (`string`) 8688 • {end} (`string`) 8689 • {flags} (`string?`) 8690 • {skip} (`string|function?`) 8691 • {stopline} (`integer?`) 8692 • {timeout} (`integer?`) 8693 8694 Return: ~ 8695 (`integer`) 8696 8697 *searchpairpos()* 8698 searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline} [, {timeout}]]]]) 8699 Same as |searchpair()|, but returns a |List| with the line and 8700 column position of the match. The first element of the |List| 8701 is the line number and the second element is the byte index of 8702 the column position of the match. If no match is found, 8703 returns [0, 0]. >vim 8704 8705 let [lnum,col] = searchpairpos('{', '', '}', 'n') 8706 < 8707 See |match-parens| for a bigger and more useful example. 8708 8709 Parameters: ~ 8710 • {start} (`string`) 8711 • {middle} (`string`) 8712 • {end} (`string`) 8713 • {flags} (`string?`) 8714 • {skip} (`string|function?`) 8715 • {stopline} (`integer?`) 8716 • {timeout} (`integer?`) 8717 8718 Return: ~ 8719 (`[integer, integer]`) 8720 8721 *searchpos()* 8722 searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) 8723 Same as |search()|, but returns a |List| with the line and 8724 column position of the match. The first element of the |List| 8725 is the line number and the second element is the byte index of 8726 the column position of the match. If no match is found, 8727 returns [0, 0]. 8728 Example: >vim 8729 let [lnum, col] = searchpos('mypattern', 'n') 8730 8731 < When the 'p' flag is given then there is an extra item with 8732 the sub-pattern match number |search()-sub-match|. Example: >vim 8733 let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np') 8734 < In this example "submatch" is 2 when a lowercase letter is 8735 found |/\l|, 3 when an uppercase letter is found |/\u|. 8736 8737 Parameters: ~ 8738 • {pattern} (`string`) 8739 • {flags} (`string?`) 8740 • {stopline} (`integer?`) 8741 • {timeout} (`integer?`) 8742 • {skip} (`string|function?`) 8743 8744 Return: ~ 8745 (`any`) 8746 8747 serverlist([{opts}]) *serverlist()* 8748 Returns a list of server addresses, or empty if all servers 8749 were stopped. |serverstart()| |serverstop()| 8750 8751 The optional argument {opts} is a Dict and supports the following items: 8752 8753 peer : If |TRUE|, servers not started by |serverstart()| 8754 will also be returned. (default: |FALSE|) 8755 Not supported on Windows yet. 8756 8757 Example: >vim 8758 echo serverlist() 8759 < 8760 8761 Parameters: ~ 8762 • {opts} (`table?`) 8763 8764 Return: ~ 8765 (`string[]`) 8766 8767 serverstart([{address}]) *serverstart()* 8768 Opens a socket or named pipe at {address} and listens for 8769 |RPC| messages. Clients can send |API| commands to the 8770 returned address to control Nvim. 8771 8772 Returns the address string (which may differ from the 8773 {address} argument, see below). 8774 8775 - If {address} has a colon (":") it is a TCP/IPv4/IPv6 address 8776 where the last ":" separates host and port (empty or zero 8777 assigns a random port). 8778 - Else {address} is the path to a named pipe (except on Windows). 8779 - If {address} has no slashes ("/") it is treated as the 8780 "name" part of a generated path in this format: >vim 8781 stdpath("run").."/{name}.{pid}.{counter}" 8782 < - If {address} is omitted the name is "nvim". >vim 8783 echo serverstart() 8784 < > 8785 => /tmp/nvim.bram/oknANW/nvim.15430.5 8786 < 8787 Example bash command to list all Nvim servers: >bash 8788 ls ${XDG_RUNTIME_DIR:-${TMPDIR}nvim.${USER}}/*/nvim.*.0 8789 8790 < Example named pipe: >vim 8791 if has('win32') 8792 echo serverstart('\\.\pipe\nvim-pipe-1234') 8793 else 8794 echo serverstart('nvim.sock') 8795 endif 8796 < 8797 Example TCP/IP address: >vim 8798 echo serverstart('::1:12345') 8799 < 8800 8801 Parameters: ~ 8802 • {address} (`string?`) 8803 8804 Return: ~ 8805 (`string`) 8806 8807 serverstop({address}) *serverstop()* 8808 Closes the pipe or socket at {address}. 8809 Returns TRUE if {address} is valid, else FALSE. 8810 If |v:servername| is stopped it is set to the next available 8811 address in |serverlist()|. 8812 8813 Parameters: ~ 8814 • {address} (`string`) 8815 8816 Return: ~ 8817 (`integer`) 8818 8819 setbufline({buf}, {lnum}, {text}) *setbufline()* 8820 Set line {lnum} to {text} in buffer {buf}. This works like 8821 |setline()| for the specified buffer. 8822 8823 This function works only for loaded buffers. First call 8824 |bufload()| if needed. 8825 8826 To insert lines use |appendbufline()|. 8827 8828 {text} can be a string to set one line, or a List of strings 8829 to set multiple lines. If the List extends below the last 8830 line then those lines are added. If the List is empty then 8831 nothing is changed and zero is returned. 8832 8833 For the use of {buf}, see |bufname()| above. 8834 8835 {lnum} is used like with |setline()|. 8836 Use "$" to refer to the last line in buffer {buf}. 8837 When {lnum} is just below the last line the {text} will be 8838 added below the last line. 8839 On success 0 is returned, on failure 1 is returned. 8840 8841 If {buf} is not a valid buffer or {lnum} is not valid, an 8842 error message is given. 8843 8844 Parameters: ~ 8845 • {buf} (`integer|string`) 8846 • {lnum} (`integer`) 8847 • {text} (`string|string[]`) 8848 8849 Return: ~ 8850 (`integer`) 8851 8852 setbufvar({buf}, {varname}, {val}) *setbufvar()* 8853 Set option or local variable {varname} in buffer {buf} to 8854 {val}. 8855 This also works for a global or local window option, but it 8856 doesn't work for a global or local window variable. 8857 For a local window option the global value is unchanged. 8858 For the use of {buf}, see |bufname()| above. 8859 The {varname} argument is a string. 8860 Note that the variable name without "b:" must be used. 8861 Examples: >vim 8862 call setbufvar(1, "&mod", 1) 8863 call setbufvar("todo", "myvar", "foobar") 8864 < This function is not available in the |sandbox|. 8865 8866 Parameters: ~ 8867 • {buf} (`integer|string`) 8868 • {varname} (`string`) 8869 • {val} (`any`) 8870 8871 Return: ~ 8872 (`any`) 8873 8874 setcellwidths({list}) *setcellwidths()* 8875 Specify overrides for cell widths of character ranges. This 8876 tells Vim how wide characters are when displayed in the 8877 terminal, counted in screen cells. The values override 8878 'ambiwidth'. Example: >vim 8879 call setcellwidths([ 8880 \ [0x111, 0x111, 1], 8881 \ [0x2194, 0x2199, 2], 8882 \ ]) 8883 8884 < The {list} argument is a List of Lists with each three 8885 numbers: [{low}, {high}, {width}]. *E1109* *E1110* 8886 {low} and {high} can be the same, in which case this refers to 8887 one character. Otherwise it is the range of characters from 8888 {low} to {high} (inclusive). *E1111* *E1114* 8889 Only characters with value 0x80 and higher can be used. 8890 8891 {width} must be either 1 or 2, indicating the character width 8892 in screen cells. *E1112* 8893 An error is given if the argument is invalid, also when a 8894 range overlaps with another. *E1113* 8895 8896 If the new value causes 'fillchars' or 'listchars' to become 8897 invalid it is rejected and an error is given. 8898 8899 To clear the overrides pass an empty {list}: >vim 8900 call setcellwidths([]) 8901 8902 < You can use the script $VIMRUNTIME/scripts/emoji_list.lua to see 8903 the effect for known emoji characters. Move the cursor 8904 through the text to check if the cell widths of your terminal 8905 match with what Vim knows about each emoji. If it doesn't 8906 look right you need to adjust the {list} argument. 8907 8908 Parameters: ~ 8909 • {list} (`any[]`) 8910 8911 Return: ~ 8912 (`any`) 8913 8914 setcharpos({expr}, {list}) *setcharpos()* 8915 Same as |setpos()| but uses the specified column number as the 8916 character index instead of the byte index in the line. 8917 8918 Example: 8919 With the text "여보세요" in line 8: >vim 8920 call setcharpos('.', [0, 8, 4, 0]) 8921 < positions the cursor on the fourth character '요'. >vim 8922 call setpos('.', [0, 8, 4, 0]) 8923 < positions the cursor on the second character '보'. 8924 8925 Parameters: ~ 8926 • {expr} (`string`) 8927 • {list} (`integer[]`) 8928 8929 Return: ~ 8930 (`any`) 8931 8932 setcharsearch({dict}) *setcharsearch()* 8933 Set the current character search information to {dict}, 8934 which contains one or more of the following entries: 8935 8936 char character which will be used for a subsequent 8937 |,| or |;| command; an empty string clears the 8938 character search 8939 forward direction of character search; 1 for forward, 8940 0 for backward 8941 until type of character search; 1 for a |t| or |T| 8942 character search, 0 for an |f| or |F| 8943 character search 8944 8945 This can be useful to save/restore a user's character search 8946 from a script: >vim 8947 let prevsearch = getcharsearch() 8948 " Perform a command which clobbers user's search 8949 call setcharsearch(prevsearch) 8950 < Also see |getcharsearch()|. 8951 8952 Parameters: ~ 8953 • {dict} (`{ char?: string, forward?: 1|0, until?: 1|0 }`) 8954 8955 Return: ~ 8956 (`any`) 8957 8958 setcmdline({str} [, {pos}]) *setcmdline()* 8959 Set the command line to {str} and set the cursor position to 8960 {pos}. 8961 If {pos} is omitted, the cursor is positioned after the text. 8962 Returns 0 when successful, 1 when not editing the command 8963 line. 8964 8965 Parameters: ~ 8966 • {str} (`string`) 8967 • {pos} (`integer?`) 8968 8969 Return: ~ 8970 (`integer`) 8971 8972 setcmdpos({pos}) *setcmdpos()* 8973 Set the cursor position in the command line to byte position 8974 {pos}. The first position is 1. 8975 Use |getcmdpos()| to obtain the current position. 8976 Only works while editing the command line, thus you must use 8977 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For 8978 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is 8979 set after the command line is set to the expression. For 8980 |c_CTRL-R_=| it is set after evaluating the expression but 8981 before inserting the resulting text. 8982 When the number is too big the cursor is put at the end of the 8983 line. A number smaller than one has undefined results. 8984 Returns 0 when successful, 1 when not editing the command 8985 line. 8986 8987 Parameters: ~ 8988 • {pos} (`integer`) 8989 8990 Return: ~ 8991 (`any`) 8992 8993 setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()* 8994 setcursorcharpos({list}) 8995 Same as |cursor()| but uses the specified column number as the 8996 character index instead of the byte index in the line. 8997 8998 Example: 8999 With the text "여보세요" in line 4: >vim 9000 call setcursorcharpos(4, 3) 9001 < positions the cursor on the third character '세'. >vim 9002 call cursor(4, 3) 9003 < positions the cursor on the first character '여'. 9004 9005 Returns 0 when the position could be set, -1 otherwise. 9006 9007 Parameters: ~ 9008 • {list} (`integer[]`) 9009 9010 Return: ~ 9011 (`any`) 9012 9013 setenv({name}, {val}) *setenv()* 9014 Set environment variable {name} to {val}. Example: >vim 9015 call setenv('HOME', '/home/myhome') 9016 9017 < When {val} is |v:null| the environment variable is deleted. 9018 See also |expr-env|. 9019 9020 Parameters: ~ 9021 • {name} (`string`) 9022 • {val} (`string`) 9023 9024 Return: ~ 9025 (`any`) 9026 9027 setfperm({fname}, {mode}) *setfperm()* *chmod* 9028 Set the file permissions for {fname} to {mode}. 9029 {mode} must be a string with 9 characters. It is of the form 9030 "rwxrwxrwx", where each group of "rwx" flags represent, in 9031 turn, the permissions of the owner of the file, the group the 9032 file belongs to, and other users. A '-' character means the 9033 permission is off, any other character means on. Multi-byte 9034 characters are not supported. 9035 9036 For example "rw-r-----" means read-write for the user, 9037 readable by the group, not accessible by others. "xx-x-----" 9038 would do the same thing. 9039 9040 Returns non-zero for success, zero for failure. 9041 9042 To read permissions see |getfperm()|. 9043 9044 Parameters: ~ 9045 • {fname} (`string`) 9046 • {mode} (`string`) 9047 9048 Return: ~ 9049 (`any`) 9050 9051 setline({lnum}, {text}) *setline()* 9052 Set line {lnum} of the current buffer to {text}. To insert 9053 lines use |append()|. To set lines in another buffer use 9054 |setbufline()|. 9055 9056 {lnum} is used like with |getline()|. 9057 When {lnum} is just below the last line the {text} will be 9058 added below the last line. 9059 {text} can be any type or a List of any type, each item is 9060 converted to a String. When {text} is an empty List then 9061 nothing is changed and FALSE is returned. 9062 9063 If this succeeds, FALSE is returned. If this fails (most 9064 likely because {lnum} is invalid) TRUE is returned. 9065 9066 Example: >vim 9067 call setline(5, strftime("%c")) 9068 9069 < When {text} is a |List| then line {lnum} and following lines 9070 will be set to the items in the list. Example: >vim 9071 call setline(5, ['aaa', 'bbb', 'ccc']) 9072 < This is equivalent to: >vim 9073 for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']] 9074 call setline(n, l) 9075 endfor 9076 9077 < Note: The '[ and '] marks are not set. 9078 9079 Parameters: ~ 9080 • {lnum} (`integer|string`) 9081 • {text} (`any`) 9082 9083 Return: ~ 9084 (`any`) 9085 9086 setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()* 9087 Create or replace or add to the location list for window {nr}. 9088 {nr} can be the window number or the |window-ID|. 9089 When {nr} is zero the current window is used. 9090 9091 For a location list window, the displayed location list is 9092 modified. For an invalid window number {nr}, -1 is returned. 9093 Otherwise, same as |setqflist()|. 9094 Also see |location-list|. 9095 9096 For {action} see |setqflist-action|. 9097 9098 If the optional {what} dictionary argument is supplied, then 9099 only the items listed in {what} are set. Refer to |setqflist()| 9100 for the list of supported keys in {what}. 9101 9102 Parameters: ~ 9103 • {nr} (`integer`) 9104 • {list} (`vim.quickfix.entry[]`) 9105 • {action} (`string?`) 9106 • {what} (`vim.fn.setqflist.what?`) 9107 9108 Return: ~ 9109 (`any`) 9110 9111 setmatches({list} [, {win}]) *setmatches()* 9112 Restores a list of matches saved by |getmatches()| for the 9113 current window. Returns 0 if successful, otherwise -1. All 9114 current matches are cleared before the list is restored. See 9115 example for |getmatches()|. 9116 If {win} is specified, use the window with this number or 9117 window ID instead of the current window. 9118 9119 Parameters: ~ 9120 • {list} (`vim.fn.getmatches.ret.item[]`) 9121 • {win} (`integer?`) 9122 9123 Return: ~ 9124 (`any`) 9125 9126 setpos({expr}, {list}) *setpos()* 9127 Set the position for String {expr}. Possible values: 9128 . the cursor 9129 'x mark x 9130 9131 {list} must be a |List| with four or five numbers: 9132 [bufnum, lnum, col, off] 9133 [bufnum, lnum, col, off, curswant] 9134 9135 "bufnum" is the buffer number. Zero can be used for the 9136 current buffer. When setting an uppercase mark "bufnum" is 9137 used for the mark position. For other marks it specifies the 9138 buffer to set the mark in. You can use the |bufnr()| function 9139 to turn a file name into a buffer number. 9140 For setting the cursor and the ' mark "bufnum" is ignored, 9141 since these are associated with a window, not a buffer. 9142 Does not change the jumplist. 9143 9144 "lnum" and "col" are the position in the buffer. The first 9145 column is 1. Use a zero "lnum" to delete a mark. If "col" is 9146 smaller than 1 then 1 is used. To use the character count 9147 instead of the byte count, use |setcharpos()|. 9148 9149 The "off" number is only used when 'virtualedit' is set. Then 9150 it is the offset in screen columns from the start of the 9151 character. E.g., a position within a <Tab> or after the last 9152 character. 9153 9154 The "curswant" number is only used when setting the cursor 9155 position. It sets the preferred column for when moving the 9156 cursor vertically. When the "curswant" number is missing the 9157 preferred column is not set. When it is present and setting a 9158 mark position it is not used. 9159 9160 Note that for |'<| and |'>| changing the line number may 9161 result in the marks to be effectively swapped, so that |'<| is 9162 always before |'>|. 9163 9164 The visual marks |'<| and |'>| refer to the beginning and end 9165 of the visual selection relative to the cursor position. 9166 Note that this differs from |getpos()|, where they are 9167 relative to the buffer. 9168 9169 Returns 0 when the position could be set, -1 otherwise. 9170 An error message is given if {expr} is invalid. 9171 9172 Also see |setcharpos()|, |getpos()| and |getcurpos()|. 9173 9174 This does not restore the preferred column for moving 9175 vertically; if you set the cursor position with this, |j| and 9176 |k| motions will jump to previous columns! Use |cursor()| to 9177 also set the preferred column. Also see the "curswant" key in 9178 |winrestview()|. 9179 9180 Parameters: ~ 9181 • {expr} (`string`) 9182 • {list} (`integer[]`) 9183 9184 Return: ~ 9185 (`any`) 9186 9187 setqflist({list} [, {action} [, {what}]]) *setqflist()* 9188 Create or replace or add to the quickfix list. 9189 9190 If the optional {what} dictionary argument is supplied, then 9191 only the items listed in {what} are set. The first {list} 9192 argument is ignored. See below for the supported items in 9193 {what}. 9194 *setqflist-what* 9195 When {what} is not present, the items in {list} are used. 9196 Each item must be a dictionary. Non-dictionary items in 9197 {list} are ignored. Each dictionary item can contain the 9198 following entries: 9199 9200 bufnr buffer number; must be the number of a valid 9201 buffer 9202 filename name of a file; only used when "bufnr" is not 9203 present or it is invalid. 9204 module name of a module; if given it will be used in 9205 quickfix error window instead of the filename. 9206 lnum line number in the file 9207 end_lnum end of lines, if the item spans multiple lines 9208 pattern search pattern used to locate the error 9209 col column number 9210 vcol when non-zero: "col" is visual column 9211 when zero: "col" is byte index 9212 end_col end column, if the item spans multiple columns 9213 nr error number 9214 text description of the error 9215 type single-character error type, 'E', 'W', etc. 9216 valid recognized error message 9217 user_data 9218 custom data associated with the item, can be 9219 any type. 9220 9221 The "col", "vcol", "nr", "type" and "text" entries are 9222 optional. Either "lnum" or "pattern" entry can be used to 9223 locate a matching error line. 9224 If the "filename" and "bufnr" entries are not present or 9225 neither the "lnum" or "pattern" entries are present, then the 9226 item will not be handled as an error line. 9227 If both "pattern" and "lnum" are present then "pattern" will 9228 be used. 9229 If the "valid" entry is not supplied, then the valid flag is 9230 set when "bufnr" is a valid buffer or "filename" exists. 9231 If you supply an empty {list}, the quickfix list will be 9232 cleared. 9233 Note that the list is not exactly the same as what 9234 |getqflist()| returns. 9235 9236 {action} values: *setqflist-action* *E927* 9237 'a' The items from {list} are added to the existing 9238 quickfix list. If there is no existing list, then a 9239 new list is created. 9240 9241 'r' The items from the current quickfix list are replaced 9242 with the items from {list}. This can also be used to 9243 clear the list: >vim 9244 call setqflist([], 'r') 9245 < 9246 'u' Like 'r', but tries to preserve the current selection 9247 in the quickfix list. 9248 'f' All the quickfix lists in the quickfix stack are 9249 freed. 9250 9251 If {action} is not present or is set to ' ', then a new list 9252 is created. The new quickfix list is added after the current 9253 quickfix list in the stack and all the following lists are 9254 freed. To add a new quickfix list at the end of the stack, 9255 set "nr" in {what} to "$". 9256 9257 The following items can be specified in dictionary {what}: 9258 context quickfix list context. See |quickfix-context| 9259 efm errorformat to use when parsing text from 9260 "lines". If this is not present, then the 9261 'errorformat' option value is used. 9262 See |quickfix-parse| 9263 id quickfix list identifier |quickfix-ID| 9264 idx index of the current entry in the quickfix 9265 list specified by "id" or "nr". If set to 9266 '$', then the last entry in the list is set as 9267 the current entry. See |quickfix-index| 9268 items list of quickfix entries. Same as the {list} 9269 argument. 9270 lines use 'errorformat' to parse a list of lines and 9271 add the resulting entries to the quickfix list 9272 {nr} or {id}. Only a |List| value is supported. 9273 See |quickfix-parse| 9274 nr list number in the quickfix stack; zero 9275 means the current quickfix list and "$" means 9276 the last quickfix list. 9277 quickfixtextfunc 9278 function to get the text to display in the 9279 quickfix window. The value can be the name of 9280 a function or a funcref or a lambda. Refer to 9281 |quickfix-window-function| for an explanation 9282 of how to write the function and an example. 9283 title quickfix list title text. See |quickfix-title| 9284 Unsupported keys in {what} are ignored. 9285 If the "nr" item is not present, then the current quickfix 9286 list is modified. When creating a new quickfix list, "nr" can 9287 be set to a value one greater than the quickfix stack size. 9288 When modifying a quickfix list, to guarantee that the correct 9289 list is modified, "id" should be used instead of "nr" to 9290 specify the list. 9291 9292 Examples (See also |setqflist-examples|): >vim 9293 call setqflist([], 'r', {'title': 'My search'}) 9294 call setqflist([], 'r', {'nr': 2, 'title': 'Errors'}) 9295 call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]}) 9296 < 9297 Returns zero for success, -1 for failure. 9298 9299 This function can be used to create a quickfix list 9300 independent of the 'errorformat' setting. Use a command like 9301 `:cc 1` to jump to the first position. 9302 9303 Parameters: ~ 9304 • {list} (`vim.quickfix.entry[]`) 9305 • {action} (`string?`) 9306 • {what} (`vim.fn.setqflist.what?`) 9307 9308 Return: ~ 9309 (`integer`) 9310 9311 setreg({regname}, {value} [, {options}]) *setreg()* 9312 Set the register {regname} to {value}. 9313 If {regname} is "" or "@", the unnamed register '"' is used. 9314 The {regname} argument is a string. 9315 9316 {value} may be any value returned by |getreg()| or 9317 |getreginfo()|, including a |List| or |Dict|. 9318 If {options} contains "a" or {regname} is upper case, 9319 then the value is appended. 9320 9321 {options} can also contain a register type specification: 9322 "c" or "v" |charwise| mode 9323 "l" or "V" |linewise| mode 9324 "b" or "<CTRL-V>" |blockwise-visual| mode 9325 If a number immediately follows "b" or "<CTRL-V>" then this is 9326 used as the width of the selection - if it is not specified 9327 then the width of the block is set to the number of characters 9328 in the longest line (counting a <Tab> as 1 character). 9329 If {options} contains "u" or '"', then the unnamed register is 9330 set to point to register {regname}. 9331 9332 If {options} contains no register settings, then the default 9333 is to use character mode unless {value} ends in a <NL> for 9334 string {value} and linewise mode for list {value}. Blockwise 9335 mode is never selected automatically. 9336 Returns zero for success, non-zero for failure. 9337 9338 *E883* 9339 Note: you may not use |List| containing more than one item to 9340 set search and expression registers. Lists containing 9341 no items act like empty strings. 9342 9343 Examples: >vim 9344 call setreg(v:register, @*) 9345 call setreg('*', @%, 'ac') 9346 call setreg('a', "1\n2\n3", 'b5') 9347 call setreg('"', { 'points_to': 'a'}) 9348 9349 < This example shows using the functions to save and restore a 9350 register: >vim 9351 let var_a = getreginfo() 9352 call setreg('a', var_a) 9353 < or: >vim 9354 let var_a = getreg('a', 1, 1) 9355 let var_amode = getregtype('a') 9356 " .... 9357 call setreg('a', var_a, var_amode) 9358 < Note: you may not reliably restore register value 9359 without using the third argument to |getreg()| as without it 9360 newlines are represented as newlines AND Nul bytes are 9361 represented as newlines as well, see |NL-used-for-Nul|. 9362 9363 You can also change the type of a register by appending 9364 nothing: >vim 9365 call setreg('a', '', 'al') 9366 < 9367 9368 Parameters: ~ 9369 • {regname} (`string`) 9370 • {value} (`any`) 9371 • {options} (`string?`) 9372 9373 Return: ~ 9374 (`any`) 9375 9376 settabvar({tabnr}, {varname}, {val}) *settabvar()* 9377 Set tab-local variable {varname} to {val} in tab page {tabnr}. 9378 |t:var| 9379 The {varname} argument is a string. 9380 Note that the variable name without "t:" must be used. 9381 Tabs are numbered starting with one. 9382 This function is not available in the |sandbox|. 9383 9384 Parameters: ~ 9385 • {tabnr} (`integer`) 9386 • {varname} (`string`) 9387 • {val} (`any`) 9388 9389 Return: ~ 9390 (`any`) 9391 9392 settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* 9393 Set option or local variable {varname} in window {winnr} to 9394 {val}. 9395 Tabs are numbered starting with one. For the current tabpage 9396 use |setwinvar()|. 9397 {winnr} can be the window number or the |window-ID|. 9398 When {winnr} is zero the current window is used. 9399 This also works for a global or local buffer option, but it 9400 doesn't work for a global or local buffer variable. 9401 For a local buffer option the global value is unchanged. 9402 Note that the variable name without "w:" must be used. 9403 Examples: >vim 9404 call settabwinvar(1, 1, "&list", 0) 9405 call settabwinvar(3, 2, "myvar", "foobar") 9406 < This function is not available in the |sandbox|. 9407 9408 Parameters: ~ 9409 • {tabnr} (`integer`) 9410 • {winnr} (`integer`) 9411 • {varname} (`string`) 9412 • {val} (`any`) 9413 9414 Return: ~ 9415 (`any`) 9416 9417 settagstack({nr}, {dict} [, {action}]) *settagstack()* 9418 Modify the tag stack of the window {nr} using {dict}. 9419 {nr} can be the window number or the |window-ID|. 9420 9421 For a list of supported items in {dict}, refer to 9422 |gettagstack()|. "curidx" takes effect before changing the tag 9423 stack. 9424 *E962* 9425 How the tag stack is modified depends on the {action} 9426 argument: 9427 - If {action} is not present or is set to 'r', then the tag 9428 stack is replaced. 9429 - If {action} is set to 'a', then new entries from {dict} are 9430 pushed (added) onto the tag stack. 9431 - If {action} is set to 't', then all the entries from the 9432 current entry in the tag stack or "curidx" in {dict} are 9433 removed and then new entries are pushed to the stack. 9434 9435 The current index is set to one after the length of the tag 9436 stack after the modification. 9437 9438 Returns zero for success, -1 for failure. 9439 9440 Examples (for more examples see |tagstack-examples|): 9441 Empty the tag stack of window 3: >vim 9442 call settagstack(3, {'items' : []}) 9443 9444 < Save and restore the tag stack: >vim 9445 let stack = gettagstack(1003) 9446 " do something else 9447 call settagstack(1003, stack) 9448 unlet stack 9449 < 9450 9451 Parameters: ~ 9452 • {nr} (`integer`) 9453 • {dict} (`any`) 9454 • {action} (`string?`) 9455 9456 Return: ~ 9457 (`any`) 9458 9459 setwinvar({nr}, {varname}, {val}) *setwinvar()* 9460 Like |settabwinvar()| for the current tab page. 9461 Examples: >vim 9462 call setwinvar(1, "&list", 0) 9463 call setwinvar(2, "myvar", "foobar") 9464 < 9465 9466 Parameters: ~ 9467 • {nr} (`integer`) 9468 • {varname} (`string`) 9469 • {val} (`any`) 9470 9471 Return: ~ 9472 (`any`) 9473 9474 sha256({expr}) *sha256()* 9475 Returns a String with 64 hex characters, which is the SHA256 9476 checksum of {expr}. 9477 {expr} is a String or a Blob. 9478 9479 Parameters: ~ 9480 • {expr} (`string`) 9481 9482 Return: ~ 9483 (`string`) 9484 9485 shellescape({string} [, {special}]) *shellescape()* 9486 Escape {string} for use as a shell command argument. 9487 9488 On Windows when 'shellslash' is not set, encloses {string} in 9489 double-quotes and doubles all double-quotes within {string}. 9490 Otherwise encloses {string} in single-quotes and replaces all 9491 "'" with "'\''". 9492 9493 The {special} argument adds additional escaping of keywords 9494 used in Vim commands. If it is a |non-zero-arg|: 9495 - Special items such as "!", "%", "#" and "<cword>" (as listed 9496 in |expand()|) will be preceded by a backslash. 9497 The backslash will be removed again by the |:!| command. 9498 - The <NL> character is escaped. 9499 9500 If 'shell' contains "csh" in the tail: 9501 - The "!" character will be escaped. This is because csh and 9502 tcsh use "!" for history replacement even in single-quotes. 9503 - The <NL> character is escaped (twice if {special} is 9504 a |non-zero-arg|). 9505 9506 If 'shell' contains "fish" in the tail, the "\" character will 9507 be escaped because in fish it is used as an escape character 9508 inside single quotes. 9509 9510 Example of use with a |:!| command: >vim 9511 exe '!dir ' .. shellescape(expand('<cfile>'), 1) 9512 < This results in a directory listing for the file under the 9513 cursor. Example of use with |system()|: >vim 9514 call system("chmod +w -- " .. shellescape(expand("%"))) 9515 < See also |::S|. 9516 9517 Parameters: ~ 9518 • {string} (`string`) 9519 • {special} (`boolean?`) 9520 9521 Return: ~ 9522 (`string`) 9523 9524 shiftwidth([{col}]) *shiftwidth()* 9525 Returns the effective value of 'shiftwidth'. This is the 9526 'shiftwidth' value unless it is zero, in which case it is the 9527 'tabstop' value. To be backwards compatible in indent 9528 plugins, use this: >vim 9529 if exists('*shiftwidth') 9530 func s:sw() 9531 return shiftwidth() 9532 endfunc 9533 else 9534 func s:sw() 9535 return &sw 9536 endfunc 9537 endif 9538 < And then use s:sw() instead of &sw. 9539 9540 for which to return the 'shiftwidth' value. This matters for 9541 the 'vartabstop' feature. If the 'vartabstop' setting is 9542 enabled and no {col} argument is given, column 1 will be 9543 assumed. 9544 9545 Parameters: ~ 9546 • {col} (`integer?`) 9547 9548 Return: ~ 9549 (`integer`) 9550 9551 sign_define({name} [, {dict}]) *sign_define()* 9552 sign_define({list}) 9553 Define a new sign named {name} or modify the attributes of an 9554 existing sign. This is similar to the |:sign-define| command. 9555 9556 Prefix {name} with a unique text to avoid name collisions. 9557 There is no {group} like with placing signs. 9558 9559 The {name} can be a String or a Number. The optional {dict} 9560 argument specifies the sign attributes. The following values 9561 are supported: 9562 icon full path to the bitmap file for the sign. 9563 linehl highlight group used for the whole line the 9564 sign is placed in. 9565 priority default priority value of the sign 9566 numhl highlight group used for the line number where 9567 the sign is placed. 9568 text text that is displayed when there is no icon 9569 or the GUI is not being used. 9570 texthl highlight group used for the text item 9571 culhl highlight group used for the text item when 9572 the cursor is on the same line as the sign and 9573 'cursorline' is enabled. 9574 9575 If the sign named {name} already exists, then the attributes 9576 of the sign are updated. 9577 9578 The one argument {list} can be used to define a list of signs. 9579 Each list item is a dictionary with the above items in {dict} 9580 and a "name" item for the sign name. 9581 9582 Returns 0 on success and -1 on failure. When the one argument 9583 {list} is used, then returns a List of values one for each 9584 defined sign. 9585 9586 Examples: >vim 9587 call sign_define("mySign", { 9588 \ "text" : "=>", 9589 \ "texthl" : "Error", 9590 \ "linehl" : "Search"}) 9591 call sign_define([ 9592 \ {'name' : 'sign1', 9593 \ 'text' : '=>'}, 9594 \ {'name' : 'sign2', 9595 \ 'text' : '!!'} 9596 \ ]) 9597 < 9598 9599 Parameters: ~ 9600 • {list} (`vim.fn.sign_define.dict[]`) 9601 9602 Return: ~ 9603 (`(0|-1)[]`) 9604 9605 sign_getdefined([{name}]) *sign_getdefined()* 9606 Get a list of defined signs and their attributes. 9607 This is similar to the |:sign-list| command. 9608 9609 If the {name} is not supplied, then a list of all the defined 9610 signs is returned. Otherwise the attribute of the specified 9611 sign is returned. 9612 9613 Each list item in the returned value is a dictionary with the 9614 following entries: 9615 icon full path to the bitmap file of the sign 9616 linehl highlight group used for the whole line the 9617 sign is placed in; not present if not set. 9618 name name of the sign 9619 priority default priority value of the sign 9620 numhl highlight group used for the line number where 9621 the sign is placed; not present if not set. 9622 text text that is displayed when there is no icon 9623 or the GUI is not being used. 9624 texthl highlight group used for the text item; not 9625 present if not set. 9626 culhl highlight group used for the text item when 9627 the cursor is on the same line as the sign and 9628 'cursorline' is enabled; not present if not 9629 set. 9630 9631 Returns an empty List if there are no signs and when {name} is 9632 not found. 9633 9634 Examples: >vim 9635 " Get a list of all the defined signs 9636 echo sign_getdefined() 9637 9638 " Get the attribute of the sign named mySign 9639 echo sign_getdefined("mySign") 9640 < 9641 9642 Parameters: ~ 9643 • {name} (`string?`) 9644 9645 Return: ~ 9646 (`vim.fn.sign_getdefined.ret.item[]`) 9647 9648 sign_getplaced([{buf} [, {dict}]]) *sign_getplaced()* 9649 Return a list of signs placed in a buffer or all the buffers. 9650 This is similar to the |:sign-place-list| command. 9651 9652 If the optional buffer name {buf} is specified, then only the 9653 list of signs placed in that buffer is returned. For the use 9654 of {buf}, see |bufname()|. The optional {dict} can contain 9655 the following entries: 9656 group select only signs in this group 9657 id select sign with this identifier 9658 lnum select signs placed in this line. For the use 9659 of {lnum}, see |line()|. 9660 If {group} is "*", then signs in all the groups including the 9661 global group are returned. If {group} is not supplied or is 9662 an empty string, then only signs in the global group are 9663 returned. If no arguments are supplied, then signs in the 9664 global group placed in all the buffers are returned. 9665 See |sign-group|. 9666 9667 Each list item in the returned value is a dictionary with the 9668 following entries: 9669 bufnr number of the buffer with the sign 9670 signs list of signs placed in {bufnr}. Each list 9671 item is a dictionary with the below listed 9672 entries 9673 9674 The dictionary for each sign contains the following entries: 9675 group sign group. Set to '' for the global group. 9676 id identifier of the sign 9677 lnum line number where the sign is placed 9678 name name of the defined sign 9679 priority sign priority 9680 9681 The returned signs in a buffer are ordered by their line 9682 number and priority. 9683 9684 Returns an empty list on failure or if there are no placed 9685 signs. 9686 9687 Examples: >vim 9688 " Get a List of signs placed in eval.c in the 9689 " global group 9690 echo sign_getplaced("eval.c") 9691 9692 " Get a List of signs in group 'g1' placed in eval.c 9693 echo sign_getplaced("eval.c", {'group' : 'g1'}) 9694 9695 " Get a List of signs placed at line 10 in eval.c 9696 echo sign_getplaced("eval.c", {'lnum' : 10}) 9697 9698 " Get sign with identifier 10 placed in a.py 9699 echo sign_getplaced("a.py", {'id' : 10}) 9700 9701 " Get sign with id 20 in group 'g1' placed in a.py 9702 echo sign_getplaced("a.py", {'group' : 'g1', 9703 \ 'id' : 20}) 9704 9705 " Get a List of all the placed signs 9706 echo sign_getplaced() 9707 < 9708 9709 Parameters: ~ 9710 • {buf} (`integer|string?`) 9711 • {dict} (`vim.fn.sign_getplaced.dict?`) 9712 9713 Return: ~ 9714 (`vim.fn.sign_getplaced.ret.item[]`) 9715 9716 sign_jump({id}, {group}, {buf}) *sign_jump()* 9717 Open the buffer {buf} or jump to the window that contains 9718 {buf} and position the cursor at sign {id} in group {group}. 9719 This is similar to the |:sign-jump| command. 9720 9721 If {group} is an empty string, then the global group is used. 9722 For the use of {buf}, see |bufname()|. 9723 9724 Returns the line number of the sign. Returns -1 if the 9725 arguments are invalid. 9726 9727 Example: >vim 9728 " Jump to sign 10 in the current buffer 9729 call sign_jump(10, '', '') 9730 < 9731 9732 Parameters: ~ 9733 • {id} (`integer`) 9734 • {group} (`string`) 9735 • {buf} (`integer|string`) 9736 9737 Return: ~ 9738 (`integer`) 9739 9740 sign_place({id}, {group}, {name}, {buf} [, {dict}]) *sign_place()* 9741 Place the sign defined as {name} at line {lnum} in file or 9742 buffer {buf} and assign {id} and {group} to sign. This is 9743 similar to the |:sign-place| command. 9744 9745 If the sign identifier {id} is zero, then a new identifier is 9746 allocated. Otherwise the specified number is used. {group} 9747 is the sign group name. To use the global sign group, use an 9748 empty string. {group} functions as a namespace for {id}, thus 9749 two groups can use the same IDs. Refer to |sign-identifier| 9750 and |sign-group| for more information. 9751 9752 {name} refers to a defined sign. 9753 {buf} refers to a buffer name or number. For the accepted 9754 values, see |bufname()|. 9755 9756 The optional {dict} argument supports the following entries: 9757 lnum line number in the file or buffer 9758 {buf} where the sign is to be placed. 9759 For the accepted values, see |line()|. 9760 priority priority of the sign. See 9761 |sign-priority| for more information. 9762 9763 If the optional {dict} is not specified, then it modifies the 9764 placed sign {id} in group {group} to use the defined sign 9765 {name}. 9766 9767 Returns the sign identifier on success and -1 on failure. 9768 9769 Examples: >vim 9770 " Place a sign named sign1 with id 5 at line 20 in 9771 " buffer json.c 9772 call sign_place(5, '', 'sign1', 'json.c', 9773 \ {'lnum' : 20}) 9774 9775 " Updates sign 5 in buffer json.c to use sign2 9776 call sign_place(5, '', 'sign2', 'json.c') 9777 9778 " Place a sign named sign3 at line 30 in 9779 " buffer json.c with a new identifier 9780 let id = sign_place(0, '', 'sign3', 'json.c', 9781 \ {'lnum' : 30}) 9782 9783 " Place a sign named sign4 with id 10 in group 'g3' 9784 " at line 40 in buffer json.c with priority 90 9785 call sign_place(10, 'g3', 'sign4', 'json.c', 9786 \ {'lnum' : 40, 'priority' : 90}) 9787 < 9788 9789 Parameters: ~ 9790 • {id} (`integer`) 9791 • {group} (`string`) 9792 • {name} (`string`) 9793 • {buf} (`integer|string`) 9794 • {dict} (`vim.fn.sign_place.dict?`) 9795 9796 Return: ~ 9797 (`integer`) 9798 9799 sign_placelist({list}) *sign_placelist()* 9800 Place one or more signs. This is similar to the 9801 |sign_place()| function. The {list} argument specifies the 9802 List of signs to place. Each list item is a dict with the 9803 following sign attributes: 9804 buffer Buffer name or number. For the accepted 9805 values, see |bufname()|. 9806 group Sign group. {group} functions as a namespace 9807 for {id}, thus two groups can use the same 9808 IDs. If not specified or set to an empty 9809 string, then the global group is used. See 9810 |sign-group| for more information. 9811 id Sign identifier. If not specified or zero, 9812 then a new unique identifier is allocated. 9813 Otherwise the specified number is used. See 9814 |sign-identifier| for more information. 9815 lnum Line number in the buffer where the sign is to 9816 be placed. For the accepted values, see 9817 |line()|. 9818 name Name of the sign to place. See |sign_define()| 9819 for more information. 9820 priority Priority of the sign. When multiple signs are 9821 placed on a line, the sign with the highest 9822 priority is used. If not specified, the 9823 default value of 10 is used, unless specified 9824 otherwise by the sign definition. See 9825 |sign-priority| for more information. 9826 9827 If {id} refers to an existing sign, then the existing sign is 9828 modified to use the specified {name} and/or {priority}. 9829 9830 Returns a List of sign identifiers. If failed to place a 9831 sign, the corresponding list item is set to -1. 9832 9833 Examples: >vim 9834 " Place sign s1 with id 5 at line 20 and id 10 at line 9835 " 30 in buffer a.c 9836 let [n1, n2] = sign_placelist([ 9837 \ {'id' : 5, 9838 \ 'name' : 's1', 9839 \ 'buffer' : 'a.c', 9840 \ 'lnum' : 20}, 9841 \ {'id' : 10, 9842 \ 'name' : 's1', 9843 \ 'buffer' : 'a.c', 9844 \ 'lnum' : 30} 9845 \ ]) 9846 9847 " Place sign s1 in buffer a.c at line 40 and 50 9848 " with auto-generated identifiers 9849 let [n1, n2] = sign_placelist([ 9850 \ {'name' : 's1', 9851 \ 'buffer' : 'a.c', 9852 \ 'lnum' : 40}, 9853 \ {'name' : 's1', 9854 \ 'buffer' : 'a.c', 9855 \ 'lnum' : 50} 9856 \ ]) 9857 < 9858 9859 Parameters: ~ 9860 • {list} (`vim.fn.sign_placelist.list.item[]`) 9861 9862 Return: ~ 9863 (`integer[]`) 9864 9865 sign_undefine([{name}]) *sign_undefine()* 9866 sign_undefine({list}) 9867 Deletes a previously defined sign {name}. This is similar to 9868 the |:sign-undefine| command. If {name} is not supplied, then 9869 deletes all the defined signs. 9870 9871 The one argument {list} can be used to undefine a list of 9872 signs. Each list item is the name of a sign. 9873 9874 Returns 0 on success and -1 on failure. For the one argument 9875 {list} call, returns a list of values one for each undefined 9876 sign. 9877 9878 Examples: >vim 9879 " Delete a sign named mySign 9880 call sign_undefine("mySign") 9881 9882 " Delete signs 'sign1' and 'sign2' 9883 call sign_undefine(["sign1", "sign2"]) 9884 9885 " Delete all the signs 9886 call sign_undefine() 9887 < 9888 9889 Parameters: ~ 9890 • {list} (`string[]?`) 9891 9892 Return: ~ 9893 (`integer[]`) 9894 9895 sign_unplace({group} [, {dict}]) *sign_unplace()* 9896 Remove a previously placed sign in one or more buffers. This 9897 is similar to the |:sign-unplace| command. 9898 9899 {group} is the sign group name. To use the global sign group, 9900 use an empty string. If {group} is set to "*", then all the 9901 groups including the global group are used. 9902 The signs in {group} are selected based on the entries in 9903 {dict}. The following optional entries in {dict} are 9904 supported: 9905 buffer buffer name or number. See |bufname()|. 9906 id sign identifier 9907 If {dict} is not supplied, then all the signs in {group} are 9908 removed. 9909 9910 Returns 0 on success and -1 on failure. 9911 9912 Examples: >vim 9913 " Remove sign 10 from buffer a.vim 9914 call sign_unplace('', {'buffer' : "a.vim", 'id' : 10}) 9915 9916 " Remove sign 20 in group 'g1' from buffer 3 9917 call sign_unplace('g1', {'buffer' : 3, 'id' : 20}) 9918 9919 " Remove all the signs in group 'g2' from buffer 10 9920 call sign_unplace('g2', {'buffer' : 10}) 9921 9922 " Remove sign 30 in group 'g3' from all the buffers 9923 call sign_unplace('g3', {'id' : 30}) 9924 9925 " Remove all the signs placed in buffer 5 9926 call sign_unplace('*', {'buffer' : 5}) 9927 9928 " Remove the signs in group 'g4' from all the buffers 9929 call sign_unplace('g4') 9930 9931 " Remove sign 40 from all the buffers 9932 call sign_unplace('*', {'id' : 40}) 9933 9934 " Remove all the placed signs from all the buffers 9935 call sign_unplace('*') 9936 < 9937 9938 Parameters: ~ 9939 • {group} (`string`) 9940 • {dict} (`vim.fn.sign_unplace.dict?`) 9941 9942 Return: ~ 9943 (`0|-1`) 9944 9945 sign_unplacelist({list}) *sign_unplacelist()* 9946 Remove previously placed signs from one or more buffers. This 9947 is similar to the |sign_unplace()| function. 9948 9949 The {list} argument specifies the List of signs to remove. 9950 Each list item is a dict with the following sign attributes: 9951 buffer buffer name or number. For the accepted 9952 values, see |bufname()|. If not specified, 9953 then the specified sign is removed from all 9954 the buffers. 9955 group sign group name. If not specified or set to an 9956 empty string, then the global sign group is 9957 used. If set to "*", then all the groups 9958 including the global group are used. 9959 id sign identifier. If not specified, then all 9960 the signs in the specified group are removed. 9961 9962 Returns a List where an entry is set to 0 if the corresponding 9963 sign was successfully removed or -1 on failure. 9964 9965 Example: >vim 9966 " Remove sign with id 10 from buffer a.vim and sign 9967 " with id 20 from buffer b.vim 9968 call sign_unplacelist([ 9969 \ {'id' : 10, 'buffer' : "a.vim"}, 9970 \ {'id' : 20, 'buffer' : 'b.vim'}, 9971 \ ]) 9972 < 9973 9974 Parameters: ~ 9975 • {list} (`vim.fn.sign_unplacelist.list.item`) 9976 9977 Return: ~ 9978 (`(0|-1)[]`) 9979 9980 simplify({filename}) *simplify()* 9981 Simplify the file name as much as possible without changing 9982 the meaning. Shortcuts (on MS-Windows) or symbolic links (on 9983 Unix) are not resolved. If the first path component in 9984 {filename} designates the current directory, this will be 9985 valid for the result as well. A trailing path separator is 9986 not removed either. On Unix "//path" is unchanged, but 9987 "///path" is simplified to "/path" (this follows the Posix 9988 standard). 9989 Example: >vim 9990 simplify("./dir/.././/file/") == "./file/" 9991 < Note: The combination "dir/.." is only removed if "dir" is 9992 a searchable directory or does not exist. On Unix, it is also 9993 removed when "dir" is a symbolic link within the same 9994 directory. In order to resolve all the involved symbolic 9995 links before simplifying the path name, use |resolve()|. 9996 9997 Parameters: ~ 9998 • {filename} (`string`) 9999 10000 Return: ~ 10001 (`string`) 10002 10003 sin({expr}) *sin()* 10004 Return the sine of {expr}, measured in radians, as a |Float|. 10005 {expr} must evaluate to a |Float| or a |Number|. 10006 Returns 0.0 if {expr} is not a |Float| or a |Number|. 10007 Examples: >vim 10008 echo sin(100) 10009 < -0.506366 >vim 10010 echo sin(-4.01) 10011 < 0.763301 10012 10013 Parameters: ~ 10014 • {expr} (`number`) 10015 10016 Return: ~ 10017 (`number`) 10018 10019 sinh({expr}) *sinh()* 10020 Return the hyperbolic sine of {expr} as a |Float| in the range 10021 [-inf, inf]. 10022 {expr} must evaluate to a |Float| or a |Number|. 10023 Returns 0.0 if {expr} is not a |Float| or a |Number|. 10024 Examples: >vim 10025 echo sinh(0.5) 10026 < 0.521095 >vim 10027 echo sinh(-0.9) 10028 < -1.026517 10029 10030 Parameters: ~ 10031 • {expr} (`number`) 10032 10033 Return: ~ 10034 (`any`) 10035 10036 slice({expr}, {start} [, {end}]) *slice()* 10037 Similar to using a |slice| "expr[start : end]", but "end" is 10038 used exclusive. And for a string the indexes are used as 10039 character indexes instead of byte indexes. 10040 Also, composing characters are treated as a part of the 10041 preceding base character. 10042 When {end} is omitted the slice continues to the last item. 10043 When {end} is -1 the last item is omitted. 10044 Returns an empty value if {start} or {end} are invalid. 10045 10046 Parameters: ~ 10047 • {expr} (`any`) 10048 • {start} (`integer`) 10049 • {end} (`integer?`) 10050 10051 Return: ~ 10052 (`any`) 10053 10054 sockconnect({mode}, {address} [, {opts}]) *sockconnect()* 10055 Connect a socket to an address. If {mode} is "pipe" then 10056 {address} should be the path of a local domain socket (on 10057 unix) or named pipe (on Windows). If {mode} is "tcp" then 10058 {address} should be of the form "host:port" where the host 10059 should be an ip address or host name, and port the port 10060 number. 10061 10062 For "pipe" mode, see |luv-pipe-handle|. For "tcp" mode, see 10063 |luv-tcp-handle|. 10064 10065 Returns a |channel| ID. Close the socket with |chanclose()|. 10066 Use |chansend()| to send data over a bytes socket, and 10067 |rpcrequest()| and |rpcnotify()| to communicate with a RPC 10068 socket. 10069 10070 {opts} is an optional dictionary with these keys: 10071 |on_data| : callback invoked when data was read from socket 10072 data_buffered : read socket data in |channel-buffered| mode. 10073 rpc : If set, |msgpack-rpc| will be used to communicate 10074 over the socket. 10075 Returns: 10076 - The channel ID on success (greater than zero) 10077 - 0 on invalid arguments or connection failure. 10078 10079 Parameters: ~ 10080 • {mode} (`string`) 10081 • {address} (`string`) 10082 • {opts} (`table?`) 10083 10084 Return: ~ 10085 (`any`) 10086 10087 sort({list} [, {how} [, {dict}]]) *sort()* *E702* 10088 Sort the items in {list} in-place. Returns {list}. 10089 10090 If you want a list to remain unmodified make a copy first: >vim 10091 let sortedlist = sort(copy(mylist)) 10092 10093 < When {how} is omitted or is a string, then sort() uses the 10094 string representation of each item to sort on. Numbers sort 10095 after Strings, |Lists| after Numbers. For sorting text in the 10096 current buffer use |:sort|. 10097 10098 When {how} is given and it is 'i' then case is ignored. 10099 For backwards compatibility, the value one can be used to 10100 ignore case. Zero means to not ignore case. 10101 10102 When {how} is given and it is 'l' then the current collation 10103 locale is used for ordering. Implementation details: 10104 strcoll() is used to compare strings. See |:language| to check 10105 or set the collation locale. |v:collate| can also be used to 10106 check the current locale. Sorting using the locale typically 10107 ignores case. Example: >vim 10108 " ö is sorted similarly to o with English locale. 10109 language collate en_US.UTF8 10110 echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 10111 < ['n', 'o', 'O', 'ö', 'p', 'z'] ~ 10112 >vim 10113 " ö is sorted after z with Swedish locale. 10114 language collate sv_SE.UTF8 10115 echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 10116 < ['n', 'o', 'O', 'p', 'z', 'ö'] ~ 10117 This does not work properly on Mac. 10118 10119 When {how} is given and it is 'n' then all items will be 10120 sorted numerical (Implementation detail: this uses the 10121 strtod() function to parse numbers, Strings, Lists, Dicts and 10122 Funcrefs will be considered as being 0). 10123 10124 When {how} is given and it is 'N' then all items will be 10125 sorted numerical. This is like 'n' but a string containing 10126 digits will be used as the number they represent. 10127 10128 When {how} is given and it is 'f' then all items will be 10129 sorted numerical. All values must be a Number or a Float. 10130 10131 When {how} is a |Funcref| or a function name, this function 10132 is called to compare items. The function is invoked with two 10133 items as argument and must return zero if they are equal, 1 or 10134 bigger if the first one sorts after the second one, -1 or 10135 smaller if the first one sorts before the second one. 10136 10137 {dict} is for functions with the "dict" attribute. It will be 10138 used to set the local variable "self". |Dictionary-function| 10139 10140 The sort is stable, items which compare equal (as number or as 10141 string) will keep their relative position. E.g., when sorting 10142 on numbers, text strings will sort next to each other, in the 10143 same order as they were originally. 10144 10145 10146 Example: >vim 10147 func MyCompare(i1, i2) 10148 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 10149 endfunc 10150 eval mylist->sort("MyCompare") 10151 < A shorter compare version for this specific simple case, which 10152 ignores overflow: >vim 10153 func MyCompare(i1, i2) 10154 return a:i1 - a:i2 10155 endfunc 10156 < For a simple expression you can use a lambda: >vim 10157 eval mylist->sort({i1, i2 -> i1 - i2}) 10158 < 10159 10160 Parameters: ~ 10161 • {list} (`T[]`) 10162 • {how} (`string|function?`) 10163 • {dict} (`any?`) 10164 10165 Return: ~ 10166 (`T[]`) 10167 10168 soundfold({word}) *soundfold()* 10169 Return the sound-folded equivalent of {word}. Uses the first 10170 language in 'spelllang' for the current window that supports 10171 soundfolding. 'spell' must be set. When no sound folding is 10172 possible the {word} is returned unmodified. 10173 This can be used for making spelling suggestions. Note that 10174 the method can be quite slow. 10175 10176 Parameters: ~ 10177 • {word} (`string`) 10178 10179 Return: ~ 10180 (`string`) 10181 10182 spellbadword([{sentence}]) *spellbadword()* 10183 Without argument: The result is the badly spelled word under 10184 or after the cursor. The cursor is moved to the start of the 10185 bad word. When no bad word is found in the cursor line the 10186 result is an empty string and the cursor doesn't move. 10187 10188 With argument: The result is the first word in {sentence} that 10189 is badly spelled. If there are no spelling mistakes the 10190 result is an empty string. 10191 10192 The return value is a list with two items: 10193 - The badly spelled word or an empty string. 10194 - The type of the spelling error: 10195 "bad" spelling mistake 10196 "rare" rare word 10197 "local" word only valid in another region 10198 "caps" word should start with Capital 10199 Example: >vim 10200 echo spellbadword("the quik brown fox") 10201 < ['quik', 'bad'] ~ 10202 10203 The spelling information for the current window and the value 10204 of 'spelllang' are used. 10205 10206 Parameters: ~ 10207 • {sentence} (`string?`) 10208 10209 Return: ~ 10210 (`any`) 10211 10212 spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()* 10213 Return a |List| with spelling suggestions to replace {word}. 10214 When {max} is given up to this number of suggestions are 10215 returned. Otherwise up to 25 suggestions are returned. 10216 10217 When the {capital} argument is given and it's non-zero only 10218 suggestions with a leading capital will be given. Use this 10219 after a match with 'spellcapcheck'. 10220 10221 {word} can be a badly spelled word followed by other text. 10222 This allows for joining two words that were split. The 10223 suggestions also include the following text, thus you can 10224 replace a line. 10225 10226 {word} may also be a good word. Similar words will then be 10227 returned. {word} itself is not included in the suggestions, 10228 although it may appear capitalized. 10229 10230 The spelling information for the current window is used. The 10231 values of 'spelllang' and 'spellsuggest' are used. 10232 10233 Parameters: ~ 10234 • {word} (`string`) 10235 • {max} (`integer?`) 10236 • {capital} (`boolean?`) 10237 10238 Return: ~ 10239 (`string[]`) 10240 10241 split({string} [, {pattern} [, {keepempty}]]) *split()* 10242 Make a |List| out of {string}. When {pattern} is omitted or 10243 empty each white space separated sequence of characters 10244 becomes an item. 10245 Otherwise the string is split where {pattern} matches, 10246 removing the matched characters. 'ignorecase' is not used 10247 here, add \c to ignore case. |/\c| 10248 When the first or last item is empty it is omitted, unless the 10249 {keepempty} argument is given and it's non-zero. 10250 Other empty items are kept when {pattern} matches at least one 10251 character or when {keepempty} is non-zero. 10252 Example: >vim 10253 let words = split(getline('.'), '\W\+') 10254 < To split a string in individual characters: >vim 10255 for c in split(mystring, '\zs') | endfor 10256 < If you want to keep the separator you can also use '\zs' at 10257 the end of the pattern: >vim 10258 echo split('abc:def:ghi', ':\zs') 10259 < > 10260 ['abc:', 'def:', 'ghi'] 10261 < 10262 Splitting a table where the first element can be empty: >vim 10263 let items = split(line, ':', 1) 10264 < The opposite function is |join()|. 10265 10266 Parameters: ~ 10267 • {string} (`string`) 10268 • {pattern} (`string?`) 10269 • {keepempty} (`boolean?`) 10270 10271 Return: ~ 10272 (`string[]`) 10273 10274 sqrt({expr}) *sqrt()* 10275 Return the non-negative square root of Float {expr} as a 10276 |Float|. 10277 {expr} must evaluate to a |Float| or a |Number|. When {expr} 10278 is negative the result is NaN (Not a Number). Returns 0.0 if 10279 {expr} is not a |Float| or a |Number|. 10280 Examples: >vim 10281 echo sqrt(100) 10282 < 10.0 >vim 10283 echo sqrt(-4.01) 10284 < str2float("nan") 10285 NaN may be different, it depends on system libraries. 10286 10287 Parameters: ~ 10288 • {expr} (`number`) 10289 10290 Return: ~ 10291 (`any`) 10292 10293 srand([{expr}]) *srand()* 10294 Initialize seed used by |rand()|: 10295 - If {expr} is not given, seed values are initialized by 10296 reading from /dev/urandom, if possible, or using time(NULL) 10297 a.k.a. epoch time otherwise; this only has second accuracy. 10298 - If {expr} is given it must be a Number. It is used to 10299 initialize the seed values. This is useful for testing or 10300 when a predictable sequence is intended. 10301 10302 Examples: >vim 10303 let seed = srand() 10304 let seed = srand(userinput) 10305 echo rand(seed) 10306 < 10307 10308 Parameters: ~ 10309 • {expr} (`number?`) 10310 10311 Return: ~ 10312 (`any`) 10313 10314 state([{what}]) *state()* 10315 Return a string which contains characters indicating the 10316 current state. Mostly useful in callbacks that want to do 10317 work that may not always be safe. Roughly this works like: 10318 - callback uses state() to check if work is safe to do. 10319 Yes: then do it right away. 10320 No: add to work queue and add a |SafeState| autocommand. 10321 - When SafeState is triggered and executes your autocommand, 10322 check with `state()` if the work can be done now, and if yes 10323 remove it from the queue and execute. 10324 Remove the autocommand if the queue is now empty. 10325 Also see |mode()|. 10326 10327 When {what} is given only characters in this string will be 10328 added. E.g, this checks if the screen has scrolled: >vim 10329 if state('s') == '' 10330 " screen has not scrolled 10331 < 10332 These characters indicate the state, generally indicating that 10333 something is busy: 10334 m halfway a mapping, :normal command, |feedkeys()| or 10335 stuffed command 10336 o operator pending, e.g. after |d| 10337 a Insert mode autocomplete active 10338 x executing an autocommand 10339 S not triggering SafeState, e.g. after |f| or a count 10340 c callback invoked, including timer (repeats for 10341 recursiveness up to "ccc") 10342 s screen has scrolled for messages 10343 10344 Parameters: ~ 10345 • {what} (`string?`) 10346 10347 Return: ~ 10348 (`any`) 10349 10350 stdioopen({opts}) *stdioopen()* 10351 With |--headless| this opens stdin and stdout as a |channel|. 10352 May be called only once. See |channel-stdio|. stderr is not 10353 handled by this function, see |v:stderr|. 10354 10355 Close the stdio handles with |chanclose()|. Use |chansend()| 10356 to send data to stdout, and |rpcrequest()| and |rpcnotify()| 10357 to communicate over RPC. 10358 10359 {opts} is a dictionary with these keys: 10360 |on_stdin| : callback invoked when stdin is written to. 10361 on_print : callback invoked when Nvim needs to print a 10362 message, with the message (whose type is string) 10363 as sole argument. 10364 stdin_buffered : read stdin in |channel-buffered| mode. 10365 rpc : If set, |msgpack-rpc| will be used to communicate 10366 over stdio 10367 Returns: 10368 - |channel-id| on success (value is always 1) 10369 - 0 on invalid arguments 10370 10371 Parameters: ~ 10372 • {opts} (`table`) 10373 10374 Return: ~ 10375 (`any`) 10376 10377 stdpath({what}) *stdpath()* *E6100* 10378 Returns |standard-path| locations of various default files and 10379 directories. The locations are driven by |base-directories| 10380 which you can configure via |$NVIM_APPNAME| or the `$XDG_…` 10381 environment variables. 10382 10383 {what} Type Description ~ 10384 cache String Cache directory: arbitrary temporary 10385 storage for plugins, etc. 10386 config String User configuration directory. |init.vim| 10387 is stored here. 10388 config_dirs List Other configuration directories. 10389 data String User data directory. 10390 data_dirs List Other data directories. 10391 log String Logs directory (for use by plugins too). 10392 run String Run directory: temporary, local storage 10393 for sockets, named pipes, etc. 10394 state String Session state: storage for backupdir, 10395 file drafts, |shada|, swap, undo, 'viewdir'. 10396 10397 Example: >vim 10398 echo stdpath("config") 10399 < 10400 10401 Parameters: ~ 10402 • {what} 10403 (`'cache'|'config'|'config_dirs'|'data'|'data_dirs'|'log'|'run'|'state'`) 10404 10405 Return: ~ 10406 (`string|string[]`) 10407 10408 str2float({string} [, {quoted}]) *str2float()* 10409 Convert String {string} to a Float. This mostly works the 10410 same as when using a floating point number in an expression, 10411 see |floating-point-format|. But it's a bit more permissive. 10412 E.g., "1e40" is accepted, while in an expression you need to 10413 write "1.0e40". The hexadecimal form "0x123" is also 10414 accepted, but not others, like binary or octal. 10415 When {quoted} is present and non-zero then embedded single 10416 quotes before the dot are ignored, thus "1'000.0" is a 10417 thousand. 10418 Text after the number is silently ignored. 10419 The decimal point is always '.', no matter what the locale is 10420 set to. A comma ends the number: "12,345.67" is converted to 10421 12.0. You can strip out thousands separators with 10422 |substitute()|: >vim 10423 let f = str2float(substitute(text, ',', '', 'g')) 10424 < 10425 Returns 0.0 if the conversion fails. 10426 10427 Parameters: ~ 10428 • {string} (`string`) 10429 • {quoted} (`boolean?`) 10430 10431 Return: ~ 10432 (`any`) 10433 10434 str2list({string} [, {utf8}]) *str2list()* 10435 Return a list containing the number values which represent 10436 each character in String {string}. Examples: >vim 10437 echo str2list(" ") " returns [32] 10438 echo str2list("ABC") " returns [65, 66, 67] 10439 < |list2str()| does the opposite. 10440 10441 UTF-8 encoding is always used, {utf8} option has no effect, 10442 and exists only for backwards-compatibility. 10443 With UTF-8 composing characters are handled properly: >vim 10444 echo str2list("á") " returns [97, 769] 10445 < 10446 10447 Parameters: ~ 10448 • {string} (`string`) 10449 • {utf8} (`boolean?`) 10450 10451 Return: ~ 10452 (`any`) 10453 10454 str2nr({string} [, {base}]) *str2nr()* 10455 Convert string {string} to a number. 10456 {base} is the conversion base, it can be 2, 8, 10 or 16. 10457 When {quoted} is present and non-zero then embedded single 10458 quotes are ignored, thus "1'000'000" is a million. 10459 10460 When {base} is omitted base 10 is used. This also means that 10461 a leading zero doesn't cause octal conversion to be used, as 10462 with the default String to Number conversion. Example: >vim 10463 let nr = str2nr('0123') 10464 < 10465 When {base} is 16 a leading "0x" or "0X" is ignored. With a 10466 different base the result will be zero. Similarly, when 10467 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when 10468 {base} is 2 a leading "0b" or "0B" is ignored. 10469 Text after the number is silently ignored. 10470 10471 Returns 0 if {string} is empty or on error. 10472 10473 Parameters: ~ 10474 • {string} (`string`) 10475 • {base} (`integer?`) 10476 10477 Return: ~ 10478 (`any`) 10479 10480 strcharlen({string}) *strcharlen()* 10481 The result is a Number, which is the number of characters 10482 in String {string}. Composing characters are ignored. 10483 |strchars()| can count the number of characters, counting 10484 composing characters separately. 10485 10486 Returns 0 if {string} is empty or on error. 10487 10488 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 10489 10490 Parameters: ~ 10491 • {string} (`string`) 10492 10493 Return: ~ 10494 (`integer`) 10495 10496 strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()* 10497 Like |strpart()| but using character index and length instead 10498 of byte index and length. 10499 When {skipcc} is omitted or zero, composing characters are 10500 counted separately. 10501 When {skipcc} set to 1, composing characters are treated as a 10502 part of the preceding base character, similar to |slice()|. 10503 When a character index is used where a character does not 10504 exist it is omitted and counted as one character. For 10505 example: >vim 10506 echo strcharpart('abc', -1, 2) 10507 < results in 'a'. 10508 10509 Returns an empty string on error. 10510 10511 Parameters: ~ 10512 • {src} (`string`) 10513 • {start} (`integer`) 10514 • {len} (`integer?`) 10515 • {skipcc} (`0|1|boolean?`) 10516 10517 Return: ~ 10518 (`string`) 10519 10520 strchars({string} [, {skipcc}]) *strchars()* 10521 The result is a Number, which is the number of characters 10522 in String {string}. 10523 When {skipcc} is omitted or zero, composing characters are 10524 counted separately. 10525 When {skipcc} set to 1, composing characters are ignored. 10526 |strcharlen()| always does this. 10527 10528 Returns zero on error. 10529 10530 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 10531 10532 {skipcc} is only available after 7.4.755. For backward 10533 compatibility, you can define a wrapper function: >vim 10534 if has("patch-7.4.755") 10535 function s:strchars(str, skipcc) 10536 return strchars(a:str, a:skipcc) 10537 endfunction 10538 else 10539 function s:strchars(str, skipcc) 10540 if a:skipcc 10541 return strlen(substitute(a:str, ".", "x", "g")) 10542 else 10543 return strchars(a:str) 10544 endif 10545 endfunction 10546 endif 10547 < 10548 10549 Parameters: ~ 10550 • {string} (`string`) 10551 • {skipcc} (`0|1|boolean?`) 10552 10553 Return: ~ 10554 (`integer`) 10555 10556 strdisplaywidth({string} [, {col}]) *strdisplaywidth()* 10557 The result is a Number, which is the number of display cells 10558 String {string} occupies on the screen when it starts at {col} 10559 (first column is zero). When {col} is omitted zero is used. 10560 Otherwise it is the screen column where to start. This 10561 matters for Tab characters. 10562 The option settings of the current window are used. This 10563 matters for anything that's displayed differently, such as 10564 'tabstop' and 'display'. 10565 When {string} contains characters with East Asian Width Class 10566 Ambiguous, this function's return value depends on 10567 'ambiwidth'. 10568 Returns zero on error. 10569 Also see |strlen()|, |strwidth()| and |strchars()|. 10570 10571 Parameters: ~ 10572 • {string} (`string`) 10573 • {col} (`integer?`) 10574 10575 Return: ~ 10576 (`integer`) 10577 10578 strftime({format} [, {time}]) *strftime()* 10579 The result is a String, which is a formatted date and time, as 10580 specified by the {format} string. The given {time} is used, 10581 or the current time if no time is given. The accepted 10582 {format} depends on your system, thus this is not portable! 10583 See the manual page of the C function strftime() for the 10584 format. The maximum length of the result is 80 characters. 10585 See also |localtime()|, |getftime()| and |strptime()|. 10586 The language can be changed with the |:language| command. 10587 Examples: >vim 10588 echo strftime("%c") " Sun Apr 27 11:49:23 1997 10589 echo strftime("%Y %b %d %X") " 1997 Apr 27 11:53:25 10590 echo strftime("%y%m%d %T") " 970427 11:53:55 10591 echo strftime("%H:%M") " 11:55 10592 echo strftime("%c", getftime("file.c")) 10593 " Show mod time of file.c. 10594 < 10595 10596 Parameters: ~ 10597 • {format} (`string`) 10598 • {time} (`number?`) 10599 10600 Return: ~ 10601 (`string`) 10602 10603 strgetchar({str}, {index}) *strgetchar()* 10604 Get a Number corresponding to the character at {index} in 10605 {str}. This uses a zero-based character index, not a byte 10606 index. Composing characters are considered separate 10607 characters here. Use |nr2char()| to convert the Number to a 10608 String. 10609 Returns -1 if {index} is invalid. 10610 Also see |strcharpart()| and |strchars()|. 10611 10612 Parameters: ~ 10613 • {str} (`string`) 10614 • {index} (`integer`) 10615 10616 Return: ~ 10617 (`integer`) 10618 10619 stridx({haystack}, {needle} [, {start}]) *stridx()* 10620 The result is a Number, which gives the byte index in 10621 {haystack} of the first occurrence of the String {needle}. 10622 If {start} is specified, the search starts at index {start}. 10623 This can be used to find a second match: >vim 10624 let colon1 = stridx(line, ":") 10625 let colon2 = stridx(line, ":", colon1 + 1) 10626 < The search is done case-sensitive. 10627 For pattern searches use |match()|. 10628 -1 is returned if the {needle} does not occur in {haystack}. 10629 See also |strridx()|. 10630 Examples: >vim 10631 echo stridx("An Example", "Example") " 3 10632 echo stridx("Starting point", "Start") " 0 10633 echo stridx("Starting point", "start") " -1 10634 < *strstr()* *strchr()* 10635 stridx() works similar to the C function strstr(). When used 10636 with a single character it works similar to strchr(). 10637 10638 Parameters: ~ 10639 • {haystack} (`string`) 10640 • {needle} (`string`) 10641 • {start} (`integer?`) 10642 10643 Return: ~ 10644 (`integer`) 10645 10646 string({expr}) *string()* 10647 Return {expr} converted to a String. If {expr} is a Number, 10648 Float, String, Blob or a composition of them, then the result 10649 can be parsed back with |eval()|. 10650 {expr} type result ~ 10651 String 'string' 10652 Number 123 10653 Float 123.123456 or 1.123456e8 or 10654 `str2float('inf')` 10655 Funcref `function('name')` 10656 Blob 0z00112233.44556677.8899 10657 List [item, item] 10658 Dictionary `{key: value, key: value}` 10659 Note that in String values the ' character is doubled. 10660 Also see |strtrans()|. 10661 Note 2: Output format is mostly compatible with YAML, except 10662 for infinite and NaN floating-point values representations 10663 which use |str2float()|. Strings are also dumped literally, 10664 only single quote is escaped, which does not allow using YAML 10665 for parsing back binary strings. |eval()| should always work 10666 for strings and floats though, and this is the only official 10667 method. Use |msgpackdump()| or |json_encode()| if you need to 10668 share data with other applications. 10669 10670 Parameters: ~ 10671 • {expr} (`any`) 10672 10673 Return: ~ 10674 (`string`) 10675 10676 strlen({string}) *strlen()* 10677 The result is a Number, which is the length of the String 10678 {string} in bytes. 10679 If the argument is a Number it is first converted to a String. 10680 For other types an error is given and zero is returned. 10681 If you want to count the number of multibyte characters use 10682 |strchars()|. 10683 Also see |len()|, |strdisplaywidth()| and |strwidth()|. 10684 10685 Parameters: ~ 10686 • {string} (`string`) 10687 10688 Return: ~ 10689 (`integer`) 10690 10691 strpart({src}, {start} [, {len} [, {chars}]]) *strpart()* 10692 The result is a String, which is part of {src}, starting from 10693 byte {start}, with the byte length {len}. 10694 When {chars} is present and TRUE then {len} is the number of 10695 characters positions (composing characters are not counted 10696 separately, thus "1" means one base character and any 10697 following composing characters). 10698 To count {start} as characters instead of bytes use 10699 |strcharpart()|. 10700 10701 When bytes are selected which do not exist, this doesn't 10702 result in an error, the bytes are simply omitted. 10703 If {len} is missing, the copy continues from {start} till the 10704 end of the {src}. >vim 10705 echo strpart("abcdefg", 3, 2) " returns 'de' 10706 echo strpart("abcdefg", -2, 4) " returns 'ab' 10707 echo strpart("abcdefg", 5, 4) " returns 'fg' 10708 echo strpart("abcdefg", 3) " returns 'defg' 10709 10710 < Note: To get the first character, {start} must be 0. For 10711 example, to get the character under the cursor: >vim 10712 strpart(getline("."), col(".") - 1, 1, v:true) 10713 < 10714 Returns an empty string on error. 10715 10716 Parameters: ~ 10717 • {src} (`string`) 10718 • {start} (`integer`) 10719 • {len} (`integer?`) 10720 • {chars} (`0|1?`) 10721 10722 Return: ~ 10723 (`string`) 10724 10725 strptime({format}, {timestring}) *strptime()* 10726 The result is a Number, which is a unix timestamp representing 10727 the date and time in {timestring}, which is expected to match 10728 the format specified in {format}. 10729 10730 The accepted {format} depends on your system, thus this is not 10731 portable! See the manual page of the C function strptime() 10732 for the format. Especially avoid "%c". The value of $TZ also 10733 matters. 10734 10735 If the {timestring} cannot be parsed with {format} zero is 10736 returned. If you do not know the format of {timestring} you 10737 can try different {format} values until you get a non-zero 10738 result. 10739 10740 See also |strftime()|. 10741 Examples: >vim 10742 echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23") 10743 < 862156163 >vim 10744 echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55")) 10745 < Sun Apr 27 11:53:55 1997 >vim 10746 echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600) 10747 < Sun Apr 27 12:53:55 1997 10748 10749 Parameters: ~ 10750 • {format} (`string`) 10751 • {timestring} (`string`) 10752 10753 Return: ~ 10754 (`integer`) 10755 10756 strridx({haystack}, {needle} [, {start}]) *strridx()* 10757 The result is a Number, which gives the byte index in 10758 {haystack} of the last occurrence of the String {needle}. 10759 When {start} is specified, matches beyond this index are 10760 ignored. This can be used to find a match before a previous 10761 match: >vim 10762 let lastcomma = strridx(line, ",") 10763 let comma2 = strridx(line, ",", lastcomma - 1) 10764 < The search is done case-sensitive. 10765 For pattern searches use |match()|. 10766 -1 is returned if the {needle} does not occur in {haystack}. 10767 If the {needle} is empty the length of {haystack} is returned. 10768 See also |stridx()|. Examples: >vim 10769 echo strridx("an angry armadillo", "an") 3 10770 < *strrchr()* 10771 When used with a single character it works similar to the C 10772 function strrchr(). 10773 10774 Parameters: ~ 10775 • {haystack} (`string`) 10776 • {needle} (`string`) 10777 • {start} (`integer?`) 10778 10779 Return: ~ 10780 (`integer`) 10781 10782 strtrans({string}) *strtrans()* 10783 The result is a String, which is {string} with all unprintable 10784 characters translated into printable characters 'isprint'. 10785 Like they are shown in a window. Example: >vim 10786 echo strtrans(@a) 10787 < This displays a newline in register a as "^@" instead of 10788 starting a new line. 10789 10790 Returns an empty string on error. 10791 10792 Parameters: ~ 10793 • {string} (`string`) 10794 10795 Return: ~ 10796 (`string`) 10797 10798 strutf16len({string} [, {countcc}]) *strutf16len()* 10799 The result is a Number, which is the number of UTF-16 code 10800 units in String {string} (after converting it to UTF-16). 10801 10802 When {countcc} is TRUE, composing characters are counted 10803 separately. 10804 When {countcc} is omitted or FALSE, composing characters are 10805 ignored. 10806 10807 Returns zero on error. 10808 10809 Also see |strlen()| and |strcharlen()|. 10810 Examples: >vim 10811 echo strutf16len('a') " returns 1 10812 echo strutf16len('©') " returns 1 10813 echo strutf16len('😊') " returns 2 10814 echo strutf16len('ą́') " returns 1 10815 echo strutf16len('ą́', v:true) " returns 3 10816 < 10817 10818 Parameters: ~ 10819 • {string} (`string`) 10820 • {countcc} (`0|1?`) 10821 10822 Return: ~ 10823 (`integer`) 10824 10825 strwidth({string}) *strwidth()* 10826 The result is a Number, which is the number of display cells 10827 String {string} occupies. A Tab character is counted as one 10828 cell, alternatively use |strdisplaywidth()|. 10829 When {string} contains characters with East Asian Width Class 10830 Ambiguous, this function's return value depends on 10831 'ambiwidth'. 10832 Returns zero on error. 10833 Also see |strlen()|, |strdisplaywidth()| and |strchars()|. 10834 10835 Parameters: ~ 10836 • {string} (`string`) 10837 10838 Return: ~ 10839 (`integer`) 10840 10841 submatch({nr} [, {list}]) *submatch()* *E935* 10842 Only for an expression in a |:substitute| command or 10843 |substitute()| function. 10844 Returns the {nr}th submatch of the matched text. When {nr} 10845 is 0 the whole matched text is returned. 10846 Note that a NL in the string can stand for a line break of a 10847 multi-line match or a NUL character in the text. 10848 Also see |sub-replace-expression|. 10849 10850 If {list} is present and non-zero then submatch() returns 10851 a list of strings, similar to |getline()| with two arguments. 10852 NL characters in the text represent NUL characters in the 10853 text. 10854 Only returns more than one item for |:substitute|, inside 10855 |substitute()| this list will always contain one or zero 10856 items, since there are no real line breaks. 10857 10858 When |substitute()| is used recursively only the submatches in 10859 the current (deepest) call can be obtained. 10860 10861 Returns an empty string or list on error. 10862 10863 Examples: >vim 10864 s/\d\+/\=submatch(0) + 1/ 10865 echo substitute(text, '\d\+', '\=submatch(0) + 1', '') 10866 < This finds the first number in the line and adds one to it. 10867 A line break is included as a newline character. 10868 10869 Parameters: ~ 10870 • {nr} (`integer`) 10871 • {list} (`nil?`) 10872 10873 Return: ~ 10874 (`string`) 10875 10876 substitute({string}, {pat}, {sub}, {flags}) *substitute()* 10877 The result is a String, which is a copy of {string}, in which 10878 the first match of {pat} is replaced with {sub}. 10879 When {flags} is "g", all matches of {pat} in {string} are 10880 replaced. Otherwise {flags} should be "". 10881 10882 This works like the ":substitute" command (without any flags). 10883 But the matching with {pat} is always done like the 'magic' 10884 option is set and 'cpoptions' is empty (to make scripts 10885 portable). 'ignorecase' is still relevant, use |/\c| or |/\C| 10886 if you want to ignore or match case and ignore 'ignorecase'. 10887 'smartcase' is not used. See |string-match| for how {pat} is 10888 used. 10889 10890 A "~" in {sub} is not replaced with the previous {sub}. 10891 Note that some codes in {sub} have a special meaning 10892 |sub-replace-special|. For example, to replace something with 10893 "\n" (two characters), use "\\\\n" or '\\n'. 10894 10895 When {pat} does not match in {string}, {string} is returned 10896 unmodified. 10897 10898 Example: >vim 10899 let &path = substitute(&path, ",\\=[^,]*$", "", "") 10900 < This removes the last component of the 'path' option. >vim 10901 echo substitute("testing", ".*", "\\U\\0", "") 10902 < results in "TESTING". 10903 10904 When {sub} starts with "\=", the remainder is interpreted as 10905 an expression. See |sub-replace-expression|. Example: >vim 10906 echo substitute(s, '%\(\x\x\)', 10907 \ '\=nr2char("0x" .. submatch(1))', 'g') 10908 10909 < When {sub} is a Funcref that function is called, with one 10910 optional argument. Example: >vim 10911 echo substitute(s, '%\(\x\x\)', SubNr, 'g') 10912 < The optional argument is a list which contains the whole 10913 matched string and up to nine submatches, like what 10914 |submatch()| returns. Example: >vim 10915 echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g') 10916 10917 < Returns an empty string on error. 10918 10919 Parameters: ~ 10920 • {string} (`string`) 10921 • {pat} (`string`) 10922 • {sub} (`string`) 10923 • {flags} (`string`) 10924 10925 Return: ~ 10926 (`string`) 10927 10928 swapfilelist() *swapfilelist()* 10929 Returns a list of swap file names, like what "vim -r" shows. 10930 See the |-r| command argument. The 'directory' option is used 10931 for the directories to inspect. If you only want to get a 10932 list of swap files in the current directory then temporarily 10933 set 'directory' to a dot: >vim 10934 let save_dir = &directory 10935 let &directory = '.' 10936 let swapfiles = swapfilelist() 10937 let &directory = save_dir 10938 < 10939 10940 Return: ~ 10941 (`string[]`) 10942 10943 swapinfo({fname}) *swapinfo()* 10944 The result is a dictionary, which holds information about the 10945 swapfile {fname}. The available fields are: 10946 version Vim version 10947 user user name 10948 host host name 10949 fname original file name 10950 pid PID of the Nvim process that created the swap 10951 file, or zero if not running. 10952 mtime last modification time in seconds 10953 inode Optional: INODE number of the file 10954 dirty 1 if file was modified, 0 if not 10955 In case of failure an "error" item is added with the reason: 10956 Cannot open file: file not found or in accessible 10957 Cannot read file: cannot read first block 10958 Not a swap file: does not contain correct block ID 10959 Magic number mismatch: Info in first block is invalid 10960 10961 Parameters: ~ 10962 • {fname} (`string`) 10963 10964 Return: ~ 10965 (`any`) 10966 10967 swapname({buf}) *swapname()* 10968 The result is the swap file path of the buffer {buf}. 10969 For the use of {buf}, see |bufname()| above. 10970 If buffer {buf} is the current buffer, the result is equal to 10971 |:swapname| (unless there is no swap file). 10972 If buffer {buf} has no swap file, returns an empty string. 10973 10974 Parameters: ~ 10975 • {buf} (`integer|string`) 10976 10977 Return: ~ 10978 (`string`) 10979 10980 synID({lnum}, {col}, {trans}) *synID()* 10981 The result is a Number, which is the syntax ID at the position 10982 {lnum} and {col} in the current window. 10983 The syntax ID can be used with |synIDattr()| and 10984 |synIDtrans()| to obtain syntax information about text. 10985 10986 {col} is 1 for the leftmost column, {lnum} is 1 for the first 10987 line. 'synmaxcol' applies, in a longer line zero is returned. 10988 Note that when the position is after the last character, 10989 that's where the cursor can be in Insert mode, synID() returns 10990 zero. {lnum} is used like with |getline()|. 10991 10992 When {trans} is |TRUE|, transparent items are reduced to the 10993 item that they reveal. This is useful when wanting to know 10994 the effective color. When {trans} is |FALSE|, the transparent 10995 item is returned. This is useful when wanting to know which 10996 syntax item is effective (e.g. inside parens). 10997 Warning: This function can be very slow. Best speed is 10998 obtained by going through the file in forward direction. 10999 11000 Returns zero on error. 11001 11002 Example (echoes the name of the syntax item under the cursor): >vim 11003 echo synIDattr(synID(line("."), col("."), 1), "name") 11004 < 11005 11006 Parameters: ~ 11007 • {lnum} (`integer|string`) 11008 • {col} (`integer`) 11009 • {trans} (`0|1`) 11010 11011 Return: ~ 11012 (`integer`) 11013 11014 synIDattr({synID}, {what} [, {mode}]) *synIDattr()* 11015 The result is a String, which is the {what} attribute of 11016 syntax ID {synID}. This can be used to obtain information 11017 about a syntax item. 11018 {mode} can be "gui" or "cterm", to get the attributes 11019 for that mode. When {mode} is omitted, or an invalid value is 11020 used, the attributes for the currently active highlighting are 11021 used (GUI or cterm). 11022 Use |synIDtrans()| to follow linked highlight groups. 11023 {what} result 11024 "name" the name of the syntax item 11025 "fg" foreground color (GUI: color name used to set 11026 the color, cterm: color number as a string, 11027 term: empty string) 11028 "bg" background color (as with "fg") 11029 "font" font name (only available in the GUI) 11030 |highlight-font| 11031 "sp" special color (as with "fg") |guisp| 11032 "fg#" like "fg", but for the GUI and the GUI is 11033 running the name in "#RRGGBB" form 11034 "bg#" like "fg#" for "bg" 11035 "sp#" like "fg#" for "sp" 11036 "bold" "1" if bold 11037 "italic" "1" if italic 11038 "reverse" "1" if reverse 11039 "inverse" "1" if inverse (= reverse) 11040 "standout" "1" if standout 11041 "underline" "1" if underlined 11042 "undercurl" "1" if undercurled 11043 "underdouble" "1" if double underlined 11044 "underdotted" "1" if dotted underlined 11045 "underdashed" "1" if dashed underlined 11046 "strikethrough" "1" if struckthrough 11047 "altfont" "1" if alternative font 11048 "nocombine" "1" if nocombine 11049 "dim" "1" if half-bright/dimmed 11050 "blink" "1" if blinking 11051 "conceal" "1" if concealed 11052 "overline" "1" if overlined 11053 11054 Returns an empty string on error. 11055 11056 Example (echoes the color of the syntax item under the 11057 cursor): >vim 11058 echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") 11059 < 11060 Can also be used as a |method|: >vim 11061 echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") 11062 < 11063 11064 Parameters: ~ 11065 • {synID} (`integer`) 11066 • {what} (`string`) 11067 • {mode} (`string?`) 11068 11069 Return: ~ 11070 (`string`) 11071 11072 synIDtrans({synID}) *synIDtrans()* 11073 The result is a Number, which is the translated syntax ID of 11074 {synID}. This is the syntax group ID of what is being used to 11075 highlight the character. Highlight links given with 11076 ":highlight link" are followed. 11077 11078 Returns zero on error. 11079 11080 Parameters: ~ 11081 • {synID} (`integer`) 11082 11083 Return: ~ 11084 (`integer`) 11085 11086 synconcealed({lnum}, {col}) *synconcealed()* 11087 The result is a |List| with three items: 11088 1. The first item in the list is 0 if the character at the 11089 position {lnum} and {col} is not part of a concealable 11090 region, 1 if it is. {lnum} is used like with |getline()|. 11091 2. The second item in the list is a string. If the first item 11092 is 1, the second item contains the text which will be 11093 displayed in place of the concealed text, depending on the 11094 current setting of 'conceallevel' and 'listchars'. 11095 3. The third and final item in the list is a number 11096 representing the specific syntax region matched in the 11097 line. When the character is not concealed the value is 11098 zero. This allows detection of the beginning of a new 11099 concealable region if there are two consecutive regions 11100 with the same replacement character. For an example, if 11101 the text is "123456" and both "23" and "45" are concealed 11102 and replaced by the character "X", then: 11103 call returns ~ 11104 synconcealed(lnum, 1) [0, '', 0] 11105 synconcealed(lnum, 2) [1, 'X', 1] 11106 synconcealed(lnum, 3) [1, 'X', 1] 11107 synconcealed(lnum, 4) [1, 'X', 2] 11108 synconcealed(lnum, 5) [1, 'X', 2] 11109 synconcealed(lnum, 6) [0, '', 0] 11110 11111 Note: Doesn't consider |matchadd()| highlighting items, 11112 since syntax and matching highlighting are two different 11113 mechanisms |syntax-vs-match|. 11114 11115 Parameters: ~ 11116 • {lnum} (`integer|string`) 11117 • {col} (`integer`) 11118 11119 Return: ~ 11120 (`[integer, string, integer]`) 11121 11122 synstack({lnum}, {col}) *synstack()* 11123 Return a |List|, which is the stack of syntax items at the 11124 position {lnum} and {col} in the current window. {lnum} is 11125 used like with |getline()|. Each item in the List is an ID 11126 like what |synID()| returns. 11127 The first item in the List is the outer region, following are 11128 items contained in that one. The last one is what |synID()| 11129 returns, unless not the whole item is highlighted or it is a 11130 transparent item. 11131 This function is useful for debugging a syntax file. 11132 Example that shows the syntax stack under the cursor: >vim 11133 for id in synstack(line("."), col(".")) 11134 echo synIDattr(id, "name") 11135 endfor 11136 < When the position specified with {lnum} and {col} is invalid 11137 an empty list is returned. The position just after the last 11138 character in a line and the first column in an empty line are 11139 valid positions. 11140 11141 Parameters: ~ 11142 • {lnum} (`integer|string`) 11143 • {col} (`integer`) 11144 11145 Return: ~ 11146 (`integer[]`) 11147 11148 system({cmd} [, {input}]) *system()* *E677* 11149 Note: Prefer |vim.system()| in Lua. 11150 11151 Gets the output of {cmd} as a |string| (|systemlist()| returns 11152 a |List|) and sets |v:shell_error| to the error code. 11153 {cmd} is treated as in |jobstart()|: 11154 If {cmd} is a List it runs directly (no 'shell'). 11155 If {cmd} is a String it runs in the 'shell', like this: >vim 11156 call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}']) 11157 11158 < Not to be used for interactive commands. 11159 11160 Result is a String, filtered to avoid platform-specific quirks: 11161 - <CR><NL> is replaced with <NL> 11162 - NUL characters are replaced with SOH (0x01) 11163 11164 Example: >vim 11165 echo system(['ls', expand('%:h')]) 11166 11167 < If {input} is a string it is written to a pipe and passed as 11168 stdin to the command. The string is written as-is, line 11169 separators are not changed. 11170 If {input} is a |List| it is written to the pipe as 11171 |writefile()| does with {binary} set to "b" (i.e. with 11172 a newline between each list item, and newlines inside list 11173 items converted to NULs). 11174 When {input} is given and is a valid buffer id, the content of 11175 the buffer is written to the file line by line, each line 11176 terminated by NL (and NUL where the text has NL). 11177 *E5677* 11178 Note: system() cannot write to or read from backgrounded ("&") 11179 shell commands, e.g.: >vim 11180 echo system("cat - &", "foo") 11181 < which is equivalent to: > 11182 $ echo foo | bash -c 'cat - &' 11183 < The pipes are disconnected (unless overridden by shell 11184 redirection syntax) before input can reach it. Use 11185 |jobstart()| instead. 11186 11187 Note: Use |shellescape()| or |::S| with |expand()| or 11188 |fnamemodify()| to escape special characters in a command 11189 argument. 'shellquote' and 'shellxquote' must be properly 11190 configured. Example: >vim 11191 echo system('ls '..shellescape(expand('%:h'))) 11192 echo system('ls '..expand('%:h:S')) 11193 11194 < Unlike ":!cmd" there is no automatic check for changed files. 11195 Use |:checktime| to force a check. 11196 11197 Parameters: ~ 11198 • {cmd} (`string|string[]`) 11199 • {input} (`string|string[]|integer?`) 11200 11201 Return: ~ 11202 (`string`) 11203 11204 systemlist({cmd} [, {input} [, {keepempty}]]) *systemlist()* 11205 Same as |system()|, but returns a |List| with lines (parts of 11206 output separated by NL) with NULs transformed into NLs. 11207 Output is the same as |readfile()| will output with {binary} 11208 argument set to "b", except that a final newline is not 11209 preserved, unless {keepempty} is non-zero. 11210 Note that on MS-Windows you may get trailing CR characters. 11211 11212 To see the difference between "echo hello" and "echo -n hello" 11213 use |system()| and |split()|: >vim 11214 echo split(system('echo hello'), '\n', 1) 11215 < 11216 Returns an empty string on error. 11217 11218 Parameters: ~ 11219 • {cmd} (`string|string[]`) 11220 • {input} (`string|string[]|integer?`) 11221 • {keepempty} (`integer?`) 11222 11223 Return: ~ 11224 (`string[]`) 11225 11226 tabpagebuflist([{arg}]) *tabpagebuflist()* 11227 The result is a |List|, where each item is the number of the 11228 buffer associated with each window in the current tab page. 11229 {arg} specifies the number of the tab page to be used. When 11230 omitted the current tab page is used. 11231 When {arg} is invalid the number zero is returned. 11232 To get a list of all buffers in all tabs use this: >vim 11233 let buflist = [] 11234 for i in range(tabpagenr('$')) 11235 call extend(buflist, tabpagebuflist(i + 1)) 11236 endfor 11237 < Note that a buffer may appear in more than one window. 11238 11239 Parameters: ~ 11240 • {arg} (`integer?`) 11241 11242 Return: ~ 11243 (`any`) 11244 11245 tabpagenr([{arg}]) *tabpagenr()* 11246 The result is a Number, which is the number of the current 11247 tab page. The first tab page has number 1. 11248 11249 The optional argument {arg} supports the following values: 11250 $ the number of the last tab page (the tab page 11251 count). 11252 # the number of the last accessed tab page 11253 (where |g<Tab>| goes to). If there is no 11254 previous tab page, 0 is returned. 11255 The number can be used with the |:tab| command. 11256 11257 Returns zero on error. 11258 11259 Parameters: ~ 11260 • {arg} (`'$'|'#'?`) 11261 11262 Return: ~ 11263 (`integer`) 11264 11265 tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()* 11266 Like |winnr()| but for tab page {tabarg}. 11267 {tabarg} specifies the number of tab page to be used. 11268 {arg} is used like with |winnr()|: 11269 - When omitted the current window number is returned. This is 11270 the window which will be used when going to this tab page. 11271 - When "$" the number of windows is returned. 11272 - When "#" the previous window nr is returned. 11273 Useful examples: >vim 11274 tabpagewinnr(1) " current window of tab page 1 11275 tabpagewinnr(4, '$') " number of windows in tab page 4 11276 < When {tabarg} is invalid zero is returned. 11277 11278 Parameters: ~ 11279 • {tabarg} (`integer`) 11280 • {arg} (`'$'|'#'?`) 11281 11282 Return: ~ 11283 (`integer`) 11284 11285 tagfiles() *tagfiles()* 11286 Returns a |List| with the file names used to search for tags 11287 for the current buffer. This is the 'tags' option expanded. 11288 11289 Return: ~ 11290 (`string[]`) 11291 11292 taglist({expr} [, {filename}]) *taglist()* 11293 Returns a |List| of tags matching the regular expression {expr}. 11294 11295 If {filename} is passed it is used to prioritize the results 11296 in the same way that |:tselect| does. See |tag-priority|. 11297 {filename} should be the full path of the file. 11298 11299 Each list item is a dictionary with at least the following 11300 entries: 11301 name Name of the tag. 11302 filename Name of the file where the tag is 11303 defined. It is either relative to the 11304 current directory or a full path. 11305 cmd Ex command used to locate the tag in 11306 the file. 11307 kind Type of the tag. The value for this 11308 entry depends on the language specific 11309 kind values. Only available when 11310 using a tags file generated by 11311 Universal/Exuberant ctags or hdrtag. 11312 static A file specific tag. Refer to 11313 |static-tag| for more information. 11314 More entries may be present, depending on the content of the 11315 tags file: access, implementation, inherits and signature. 11316 Refer to the ctags documentation for information about these 11317 fields. For C code the fields "struct", "class" and "enum" 11318 may appear, they give the name of the entity the tag is 11319 contained in. 11320 11321 The ex-command "cmd" can be either an ex search pattern, a 11322 line number or a line number followed by a byte number. 11323 11324 If there are no matching tags, then an empty list is returned. 11325 11326 To get an exact tag match, the anchors '^' and '$' should be 11327 used in {expr}. This also make the function work faster. 11328 Refer to |tag-regexp| for more information about the tag 11329 search regular expression pattern. 11330 11331 Refer to 'tags' for information about how the tags file is 11332 located by Vim. Refer to |tags-file-format| for the format of 11333 the tags file generated by the different ctags tools. 11334 11335 Parameters: ~ 11336 • {expr} (`any`) 11337 • {filename} (`string?`) 11338 11339 Return: ~ 11340 (`any`) 11341 11342 tan({expr}) *tan()* 11343 Return the tangent of {expr}, measured in radians, as a |Float| 11344 in the range [-inf, inf]. 11345 {expr} must evaluate to a |Float| or a |Number|. 11346 Returns 0.0 if {expr} is not a |Float| or a |Number|. 11347 Examples: >vim 11348 echo tan(10) 11349 < 0.648361 >vim 11350 echo tan(-4.01) 11351 < -1.181502 11352 11353 Parameters: ~ 11354 • {expr} (`number`) 11355 11356 Return: ~ 11357 (`number`) 11358 11359 tanh({expr}) *tanh()* 11360 Return the hyperbolic tangent of {expr} as a |Float| in the 11361 range [-1, 1]. 11362 {expr} must evaluate to a |Float| or a |Number|. 11363 Returns 0.0 if {expr} is not a |Float| or a |Number|. 11364 Examples: >vim 11365 echo tanh(0.5) 11366 < 0.462117 >vim 11367 echo tanh(-1) 11368 < -0.761594 11369 11370 Parameters: ~ 11371 • {expr} (`number`) 11372 11373 Return: ~ 11374 (`number`) 11375 11376 tempname() *tempname()* 11377 Generates a (non-existent) filename located in the Nvim root 11378 |tempdir|. Scripts can use the filename as a temporary file. 11379 Example: >vim 11380 let tmpfile = tempname() 11381 exe "redir > " .. tmpfile 11382 < 11383 11384 Return: ~ 11385 (`string`) 11386 11387 test_garbagecollect_now() *test_garbagecollect_now()* 11388 Like |garbagecollect()|, but executed right away. This must 11389 only be called directly to avoid any structure to exist 11390 internally, and |v:testing| must have been set before calling 11391 any function. *E1142* 11392 11393 Return: ~ 11394 (`any`) 11395 11396 timer_info([{id}]) *timer_info()* 11397 Return a list with information about timers. 11398 When {id} is given only information about this timer is 11399 returned. When timer {id} does not exist an empty list is 11400 returned. 11401 When {id} is omitted information about all timers is returned. 11402 11403 For each timer the information is stored in a |Dictionary| with 11404 these items: 11405 "id" the timer ID 11406 "time" time the timer was started with 11407 "repeat" number of times the timer will still fire; 11408 -1 means forever 11409 "callback" the callback 11410 11411 Parameters: ~ 11412 • {id} (`integer?`) 11413 11414 Return: ~ 11415 (`any`) 11416 11417 timer_pause({timer}, {paused}) *timer_pause()* 11418 Pause or unpause a timer. A paused timer does not invoke its 11419 callback when its time expires. Unpausing a timer may cause 11420 the callback to be invoked almost immediately if enough time 11421 has passed. 11422 11423 Pausing a timer is useful to avoid the callback to be called 11424 for a short time. 11425 11426 If {paused} evaluates to a non-zero Number or a non-empty 11427 String, then the timer is paused, otherwise it is unpaused. 11428 See |non-zero-arg|. 11429 11430 Parameters: ~ 11431 • {timer} (`integer`) 11432 • {paused} (`boolean`) 11433 11434 Return: ~ 11435 (`any`) 11436 11437 timer_start({time}, {callback} [, {options}]) *timer_start()* *timer* 11438 Create a timer and return the timer ID. 11439 11440 {time} is the waiting time in milliseconds. This is the 11441 minimum time before invoking the callback. When the system is 11442 busy or Vim is not waiting for input the time will be longer. 11443 Zero can be used to execute the callback when Vim is back in 11444 the main loop. 11445 11446 {callback} is the function to call. It can be the name of a 11447 function or a |Funcref|. It is called with one argument, which 11448 is the timer ID. The callback is only invoked when Vim is 11449 waiting for input. 11450 11451 {options} is a dictionary. Supported entries: 11452 "repeat" Number of times to repeat the callback. 11453 -1 means forever. Default is 1. 11454 If the timer causes an error three times in a 11455 row the repeat is cancelled. 11456 11457 Returns -1 on error. 11458 11459 Example: >vim 11460 func MyHandler(timer) 11461 echo 'Handler called' 11462 endfunc 11463 let timer = timer_start(500, 'MyHandler', 11464 \ {'repeat': 3}) 11465 < This invokes MyHandler() three times at 500 msec intervals. 11466 11467 Parameters: ~ 11468 • {time} (`number`) 11469 • {callback} (`string|function`) 11470 • {options} (`table?`) 11471 11472 Return: ~ 11473 (`any`) 11474 11475 timer_stop({timer}) *timer_stop()* 11476 Stop a timer. The timer callback will no longer be invoked. 11477 {timer} is an ID returned by |timer_start()|, thus it must be a 11478 Number. If {timer} does not exist there is no error. 11479 11480 Parameters: ~ 11481 • {timer} (`integer`) 11482 11483 Return: ~ 11484 (`any`) 11485 11486 timer_stopall() *timer_stopall()* 11487 Stop all timers. The timer callbacks will no longer be 11488 invoked. Useful if some timers is misbehaving. If there are 11489 no timers there is no error. 11490 11491 Return: ~ 11492 (`any`) 11493 11494 tolower({expr}) *tolower()* 11495 The result is a copy of the String given, with all uppercase 11496 characters turned into lowercase (just like applying |gu| to 11497 the string). Returns an empty string on error. 11498 11499 Parameters: ~ 11500 • {expr} (`string`) 11501 11502 Return: ~ 11503 (`string`) 11504 11505 toupper({expr}) *toupper()* 11506 The result is a copy of the String given, with all lowercase 11507 characters turned into uppercase (just like applying |gU| to 11508 the string). Returns an empty string on error. 11509 11510 Parameters: ~ 11511 • {expr} (`string`) 11512 11513 Return: ~ 11514 (`string`) 11515 11516 tr({src}, {fromstr}, {tostr}) *tr()* 11517 The result is a copy of the {src} string with all characters 11518 which appear in {fromstr} replaced by the character in that 11519 position in the {tostr} string. Thus the first character in 11520 {fromstr} is translated into the first character in {tostr} 11521 and so on. Exactly like the unix "tr" command. 11522 This code also deals with multibyte characters properly. 11523 11524 Returns an empty string on error. 11525 11526 Examples: >vim 11527 echo tr("hello there", "ht", "HT") 11528 < returns "Hello THere" >vim 11529 echo tr("<blob>", "<>", "{}") 11530 < returns "{blob}" 11531 11532 Parameters: ~ 11533 • {src} (`string`) 11534 • {fromstr} (`string`) 11535 • {tostr} (`string`) 11536 11537 Return: ~ 11538 (`string`) 11539 11540 trim({text} [, {mask} [, {dir}]]) *trim()* 11541 Return {text} as a String where any character in {mask} is 11542 removed from the beginning and/or end of {text}. 11543 11544 If {mask} is not given, or is an empty string, {mask} is all 11545 characters up to 0x20, which includes Tab, space, NL and CR, 11546 plus the non-breaking space character 0xa0. 11547 11548 The optional {dir} argument specifies where to remove the 11549 characters: 11550 0 remove from the beginning and end of {text} 11551 1 remove only at the beginning of {text} 11552 2 remove only at the end of {text} 11553 When omitted both ends are trimmed. 11554 11555 This function deals with multibyte characters properly. 11556 Returns an empty string on error. 11557 11558 Examples: >vim 11559 echo trim(" some text ") 11560 < returns "some text" >vim 11561 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL" 11562 < returns "RESERVE_TAIL" >vim 11563 echo trim("rm<Xrm<>X>rrm", "rm<>") 11564 < returns "Xrm<>X" (characters in the middle are not removed) >vim 11565 echo trim(" vim ", " ", 2) 11566 < returns " vim" 11567 11568 Parameters: ~ 11569 • {text} (`string`) 11570 • {mask} (`string?`) 11571 • {dir} (`0|1|2?`) 11572 11573 Return: ~ 11574 (`string`) 11575 11576 trunc({expr}) *trunc()* 11577 Return the largest integral value with magnitude less than or 11578 equal to {expr} as a |Float| (truncate towards zero). 11579 {expr} must evaluate to a |Float| or a |Number|. 11580 Returns 0.0 if {expr} is not a |Float| or a |Number|. 11581 Examples: >vim 11582 echo trunc(1.456) 11583 < 1.0 >vim 11584 echo trunc(-5.456) 11585 < -5.0 >vim 11586 echo trunc(4.0) 11587 < 4.0 11588 11589 Parameters: ~ 11590 • {expr} (`number`) 11591 11592 Return: ~ 11593 (`integer`) 11594 11595 type({expr}) *type()* 11596 The result is a Number representing the type of {expr}. 11597 Instead of using the number directly, it is better to use the 11598 v:t_ variable that has the value: 11599 Number: 0 |v:t_number| 11600 String: 1 |v:t_string| 11601 Funcref: 2 |v:t_func| 11602 List: 3 |v:t_list| 11603 Dictionary: 4 |v:t_dict| 11604 Float: 5 |v:t_float| 11605 Boolean: 6 |v:t_bool| (|v:false| and |v:true|) 11606 Null: 7 (|v:null|) 11607 Blob: 10 |v:t_blob| 11608 For backward compatibility, this method can be used: >vim 11609 if type(myvar) == type(0) | endif 11610 if type(myvar) == type("") | endif 11611 if type(myvar) == type(function("tr")) | endif 11612 if type(myvar) == type([]) | endif 11613 if type(myvar) == type({}) | endif 11614 if type(myvar) == type(0.0) | endif 11615 if type(myvar) == type(v:true) | endif 11616 < In place of checking for |v:null| type it is better to check 11617 for |v:null| directly as it is the only value of this type: >vim 11618 if myvar is v:null | endif 11619 < To check if the v:t_ variables exist use this: >vim 11620 if exists('v:t_number') | endif 11621 < 11622 11623 Parameters: ~ 11624 • {expr} (`any`) 11625 11626 Return: ~ 11627 (`integer`) 11628 11629 undofile({name}) *undofile()* 11630 Return the name of the undo file that would be used for a file 11631 with name {name} when writing. This uses the 'undodir' 11632 option, finding directories that exist. It does not check if 11633 the undo file exists. 11634 {name} is always expanded to the full path, since that is what 11635 is used internally. 11636 If {name} is empty undofile() returns an empty string, since a 11637 buffer without a file name will not write an undo file. 11638 Useful in combination with |:wundo| and |:rundo|. 11639 11640 Parameters: ~ 11641 • {name} (`string`) 11642 11643 Return: ~ 11644 (`string`) 11645 11646 undotree([{buf}]) *undotree()* 11647 Return the current state of the undo tree for the current 11648 buffer, or for a specific buffer if {buf} is given. The 11649 result is a dictionary with the following items: 11650 "seq_last" The highest undo sequence number used. 11651 "seq_cur" The sequence number of the current position in 11652 the undo tree. This differs from "seq_last" 11653 when some changes were undone. 11654 "time_cur" Time last used for |:earlier| and related 11655 commands. Use |strftime()| to convert to 11656 something readable. 11657 "save_last" Number of the last file write. Zero when no 11658 write yet. 11659 "save_cur" Number of the current position in the undo 11660 tree. 11661 "synced" Non-zero when the last undo block was synced. 11662 This happens when waiting from input from the 11663 user. See |undo-blocks|. 11664 "entries" A list of dictionaries with information about 11665 undo blocks. 11666 11667 The first item in the "entries" list is the oldest undo item. 11668 Each List item is a |Dictionary| with these items: 11669 "seq" Undo sequence number. Same as what appears in 11670 |:undolist|. 11671 "time" Timestamp when the change happened. Use 11672 |strftime()| to convert to something readable. 11673 "newhead" Only appears in the item that is the last one 11674 that was added. This marks the last change 11675 and where further changes will be added. 11676 "curhead" Only appears in the item that is the last one 11677 that was undone. This marks the current 11678 position in the undo tree, the block that will 11679 be used by a redo command. When nothing was 11680 undone after the last change this item will 11681 not appear anywhere. 11682 "save" Only appears on the last block before a file 11683 write. The number is the write count. The 11684 first write has number 1, the last one the 11685 "save_last" mentioned above. 11686 "alt" Alternate entry. This is again a List of undo 11687 blocks. Each item may again have an "alt" 11688 item. 11689 11690 Parameters: ~ 11691 • {buf} (`integer|string?`) 11692 11693 Return: ~ 11694 (`vim.fn.undotree.ret`) 11695 11696 uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* 11697 Note: Prefer |vim.list.unique()| in Lua. 11698 11699 Remove second and succeeding copies of repeated adjacent 11700 {list} items in-place. Returns {list}. If you want a list 11701 to remain unmodified make a copy first: >vim 11702 let newlist = uniq(copy(mylist)) 11703 < The default compare function uses the string representation of 11704 each item. For the use of {func} and {dict} see |sort()|. 11705 For deduplicating text in the current buffer see |:uniq|. 11706 11707 Returns zero if {list} is not a |List|. 11708 11709 Parameters: ~ 11710 • {list} (`any`) 11711 • {func} (`any?`) 11712 • {dict} (`any?`) 11713 11714 Return: ~ 11715 (`any[]|0`) 11716 11717 utf16idx({string}, {idx} [, {countcc} [, {charidx}]]) *utf16idx()* 11718 Same as |charidx()| but returns the UTF-16 code unit index of 11719 the byte at {idx} in {string} (after converting it to UTF-16). 11720 11721 When {charidx} is present and TRUE, {idx} is used as the 11722 character index in the String {string} instead of as the byte 11723 index. 11724 An {idx} in the middle of a UTF-8 sequence is rounded 11725 downwards to the beginning of that sequence. 11726 11727 Returns -1 if the arguments are invalid or if there are less 11728 than {idx} bytes in {string}. If there are exactly {idx} 11729 bytes, the length of the string in UTF-16 code units is 11730 returned. 11731 11732 See |byteidx()| and |byteidxcomp()| for getting the byte index 11733 from the UTF-16 index and |charidx()| for getting the 11734 character index from the UTF-16 index. 11735 Refer to |string-offset-encoding| for more information. 11736 Examples: >vim 11737 echo utf16idx('a😊😊', 3) " returns 2 11738 echo utf16idx('a😊😊', 7) " returns 4 11739 echo utf16idx('a😊😊', 1, 0, 1) " returns 2 11740 echo utf16idx('a😊😊', 2, 0, 1) " returns 4 11741 echo utf16idx('aą́c', 6) " returns 2 11742 echo utf16idx('aą́c', 6, 1) " returns 4 11743 echo utf16idx('a😊😊', 9) " returns -1 11744 < 11745 11746 Parameters: ~ 11747 • {string} (`string`) 11748 • {idx} (`integer`) 11749 • {countcc} (`boolean?`) 11750 • {charidx} (`boolean?`) 11751 11752 Return: ~ 11753 (`integer`) 11754 11755 values({dict}) *values()* 11756 Return a |List| with all the values of {dict}. The |List| is 11757 in arbitrary order. Also see |items()| and |keys()|. 11758 Returns zero if {dict} is not a |Dict|. 11759 11760 Parameters: ~ 11761 • {dict} (`any`) 11762 11763 Return: ~ 11764 (`any`) 11765 11766 virtcol({expr} [, {list} [, {winid}]]) *virtcol()* 11767 The result is a Number, which is the screen column of the file 11768 position given with {expr}. That is, the total number of 11769 screen cells occupied by the part of the line until the end of 11770 the character at that position. When there is a <Tab> at the 11771 position, the returned Number will be the column at the end of 11772 the <Tab>. For example, for a <Tab> in column 1, with 'ts' 11773 set to 8, it returns 8. |conceal| is ignored. 11774 For the byte position use |col()|. 11775 11776 For the use of {expr} see |getpos()| and |col()|. 11777 When {expr} is "$", it means the end of the cursor line, so 11778 the result is the number of cells in the cursor line plus one. 11779 11780 When 'virtualedit' is used {expr} can be [lnum, col, off], 11781 where "off" is the offset in screen columns from the start of 11782 the character. E.g., a position within a <Tab> or after the 11783 last character. When "off" is omitted zero is used. When 11784 Virtual editing is active in the current mode, a position 11785 beyond the end of the line can be returned. Also see 11786 'virtualedit' 11787 11788 If {list} is present and non-zero then virtcol() returns a 11789 List with the first and last screen position occupied by the 11790 character. 11791 11792 With the optional {winid} argument the values are obtained for 11793 that window instead of the current window. 11794 11795 Note that only marks in the current file can be used. 11796 Examples: >vim 11797 " With text "foo^Lbar" and cursor on the "^L": 11798 11799 echo virtcol(".") " returns 5 11800 echo virtcol(".", 1) " returns [4, 5] 11801 echo virtcol("$") " returns 9 11802 11803 " With text " there", with 't at 'h': 11804 11805 echo virtcol("'t") " returns 6 11806 < 11807 The first column is 1. 0 or [0, 0] is returned for an error. 11808 11809 A more advanced example that echoes the maximum length of 11810 all lines: >vim 11811 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) 11812 < 11813 11814 Parameters: ~ 11815 • {expr} (`string|any[]`) 11816 • {list} (`boolean?`) 11817 • {winid} (`integer?`) 11818 11819 Return: ~ 11820 (`integer|[integer, integer]`) 11821 11822 virtcol2col({winid}, {lnum}, {col}) *virtcol2col()* 11823 The result is a Number, which is the byte index of the 11824 character in window {winid} at buffer line {lnum} and virtual 11825 column {col}. 11826 11827 If buffer line {lnum} is an empty line, 0 is returned. 11828 11829 If {col} is greater than the last virtual column in line 11830 {lnum}, then the byte index of the character at the last 11831 virtual column is returned. 11832 11833 For a multi-byte character, the column number of the first 11834 byte in the character is returned. 11835 11836 The {winid} argument can be the window number or the 11837 |window-ID|. If this is zero, then the current window is used. 11838 11839 Returns -1 if the window {winid} doesn't exist or the buffer 11840 line {lnum} or virtual column {col} is invalid. 11841 11842 See also |screenpos()|, |virtcol()| and |col()|. 11843 11844 Parameters: ~ 11845 • {winid} (`integer`) 11846 • {lnum} (`integer`) 11847 • {col} (`integer`) 11848 11849 Return: ~ 11850 (`integer`) 11851 11852 visualmode([{expr}]) *visualmode()* 11853 The result is a String, which describes the last Visual mode 11854 used in the current buffer. Initially it returns an empty 11855 string, but once Visual mode has been used, it returns "v", 11856 "V", or "<CTRL-V>" (a single CTRL-V character) for 11857 character-wise, line-wise, or block-wise Visual mode 11858 respectively. 11859 Example: >vim 11860 exe "normal " .. visualmode() 11861 < This enters the same Visual mode as before. It is also useful 11862 in scripts if you wish to act differently depending on the 11863 Visual mode that was used. 11864 If Visual mode is active, use |mode()| to get the Visual mode 11865 (e.g., in a |:vmap|). 11866 If {expr} is supplied and it evaluates to a non-zero Number or 11867 a non-empty String, then the Visual mode will be cleared and 11868 the old value is returned. See |non-zero-arg|. 11869 11870 Parameters: ~ 11871 • {expr} (`boolean?`) 11872 11873 Return: ~ 11874 (`string`) 11875 11876 wait({timeout}, {condition} [, {interval}]) *wait()* 11877 Waits until {condition} evaluates to |TRUE|, where {condition} 11878 is a |Funcref| or |string| containing an expression. 11879 11880 {timeout} is the maximum waiting time in milliseconds, -1 11881 means forever. 11882 11883 Condition is evaluated on user events, internal events, and 11884 every {interval} milliseconds (default: 200). 11885 11886 Returns a status integer: 11887 0 if the condition was satisfied before timeout 11888 -1 if the timeout was exceeded 11889 -2 if the function was interrupted (by |CTRL-C|) 11890 -3 if an error occurred 11891 11892 Parameters: ~ 11893 • {timeout} (`integer`) 11894 • {condition} (`any`) 11895 • {interval} (`number?`) 11896 11897 Return: ~ 11898 (`any`) 11899 11900 wildmenumode() *wildmenumode()* 11901 Returns |TRUE| when the wildmenu is active and |FALSE| 11902 otherwise. See 'wildmenu' and 'wildmode'. 11903 This can be used in mappings to handle the 'wildcharm' option 11904 gracefully. (Makes only sense with |mapmode-c| mappings). 11905 11906 For example to make <c-j> work like <down> in wildmode, use: >vim 11907 cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>" 11908 < 11909 (Note: this needs the 'wildcharm' option set appropriately). 11910 11911 Return: ~ 11912 (`any`) 11913 11914 wildtrigger() *wildtrigger()* 11915 Start wildcard expansion in the command-line, using the 11916 behavior defined by the 'wildmode' and 'wildoptions' settings. 11917 11918 This function also enables completion in search patterns such 11919 as |/|, |?|, |:s|, |:g|, |:v| and |:vimgrep|. 11920 11921 Unlike pressing 'wildchar' manually, this function does not 11922 produce a beep when no matches are found and generally 11923 operates more quietly. This makes it suitable for triggering 11924 completion automatically. 11925 11926 Note: After navigating command-line history, the first call to 11927 wildtrigger() is a no-op; a second call is needed to start 11928 expansion. This is to support history navigation in 11929 command-line autocompletion. 11930 11931 See |cmdline-autocompletion|. 11932 11933 Return value is always 0. 11934 11935 Return: ~ 11936 (`number`) 11937 11938 win_execute({id}, {command} [, {silent}]) *win_execute()* 11939 Like `execute()` but in the context of window {id}. 11940 The window will temporarily be made the current window, 11941 without triggering autocommands or changing directory. When 11942 executing {command} autocommands will be triggered, this may 11943 have unexpected side effects. Use `:noautocmd` if needed. 11944 Example: >vim 11945 call win_execute(winid, 'syntax enable') 11946 < Doing the same with `setwinvar()` would not trigger 11947 autocommands and not actually show syntax highlighting. 11948 11949 When window {id} does not exist then no error is given and 11950 an empty string is returned. 11951 11952 Parameters: ~ 11953 • {id} (`integer`) 11954 • {command} (`string`) 11955 • {silent} (`boolean?`) 11956 11957 Return: ~ 11958 (`any`) 11959 11960 win_findbuf({bufnr}) *win_findbuf()* 11961 Returns a |List| with |window-ID|s for windows that contain 11962 buffer {bufnr}. When there is none the list is empty. 11963 11964 Parameters: ~ 11965 • {bufnr} (`integer`) 11966 11967 Return: ~ 11968 (`integer[]`) 11969 11970 win_getid([{win} [, {tab}]]) *win_getid()* 11971 Get the |window-ID| for the specified window. 11972 When {win} is missing use the current window. 11973 With {win} this is the window number. The top window has 11974 number 1. 11975 Without {tab} use the current tab, otherwise the tab with 11976 number {tab}. The first tab has number one. 11977 Return zero if the window cannot be found. 11978 11979 Parameters: ~ 11980 • {win} (`integer?`) 11981 • {tab} (`integer?`) 11982 11983 Return: ~ 11984 (`integer`) 11985 11986 win_gettype([{nr}]) *win_gettype()* 11987 Return the type of the window: 11988 "autocmd" autocommand window. Temporary window 11989 used to execute autocommands. 11990 "command" command-line window |cmdwin| 11991 (empty) normal window 11992 "loclist" |location-list-window| 11993 "popup" floating window |api-floatwin| 11994 "preview" preview window |preview-window| 11995 "quickfix" |quickfix-window| 11996 "unknown" window {nr} not found 11997 11998 When {nr} is omitted return the type of the current window. 11999 When {nr} is given return the type of this window by number or 12000 |window-ID|. 12001 12002 Also see the 'buftype' option. 12003 12004 Parameters: ~ 12005 • {nr} (`integer?`) 12006 12007 Return: ~ 12008 (`'autocmd'|'command'|''|'loclist'|'popup'|'preview'|'quickfix'|'unknown'`) 12009 12010 win_gotoid({expr}) *win_gotoid()* 12011 Go to window with ID {expr}. This may also change the current 12012 tabpage. 12013 Return TRUE if successful, FALSE if the window cannot be 12014 found. 12015 12016 Parameters: ~ 12017 • {expr} (`integer`) 12018 12019 Return: ~ 12020 (`0|1`) 12021 12022 win_id2tabwin({expr}) *win_id2tabwin()* 12023 Return a list with the tab number and window number of window 12024 with ID {expr}: [tabnr, winnr]. 12025 Return [0, 0] if the window cannot be found. 12026 12027 Parameters: ~ 12028 • {expr} (`integer`) 12029 12030 Return: ~ 12031 (`any`) 12032 12033 win_id2win({expr}) *win_id2win()* 12034 Return the window number of window with ID {expr}. 12035 Return 0 if the window cannot be found in the current tabpage. 12036 12037 Parameters: ~ 12038 • {expr} (`integer`) 12039 12040 Return: ~ 12041 (`integer`) 12042 12043 win_move_separator({nr}, {offset}) *win_move_separator()* 12044 Move window {nr}'s vertical separator (i.e., the right border) 12045 by {offset} columns, as if being dragged by the mouse. {nr} 12046 can be a window number or |window-ID|. A positive {offset} 12047 moves right and a negative {offset} moves left. Moving a 12048 window's vertical separator will change the width of the 12049 window and the width of other windows adjacent to the vertical 12050 separator. The magnitude of movement may be smaller than 12051 specified (e.g., as a consequence of maintaining 12052 'winminwidth'). Returns TRUE if the window can be found and 12053 FALSE otherwise. 12054 This will fail for the rightmost window and a full-width 12055 window, since it has no separator on the right. 12056 Only works for the current tab page. *E1308* 12057 12058 Parameters: ~ 12059 • {nr} (`integer`) 12060 • {offset} (`integer`) 12061 12062 Return: ~ 12063 (`any`) 12064 12065 win_move_statusline({nr}, {offset}) *win_move_statusline()* 12066 Move window {nr}'s status line (i.e., the bottom border) by 12067 {offset} rows, as if being dragged by the mouse. {nr} can be 12068 a window number or |window-ID|. A positive {offset} moves 12069 down and a negative {offset} moves up. Moving a window's 12070 status line will change the height of the window and the 12071 height of other windows adjacent to the status line. The 12072 magnitude of movement may be smaller than specified (e.g., as 12073 a consequence of maintaining 'winminheight'). Returns TRUE if 12074 the window can be found and FALSE otherwise. 12075 Only works for the current tab page. 12076 12077 Parameters: ~ 12078 • {nr} (`integer`) 12079 • {offset} (`integer`) 12080 12081 Return: ~ 12082 (`any`) 12083 12084 win_screenpos({nr}) *win_screenpos()* 12085 Return the screen position of window {nr} as a list with two 12086 numbers: [row, col]. The first window always has position 12087 [1, 1], unless there is a tabline, then it is [2, 1]. 12088 {nr} can be the window number or the |window-ID|. Use zero 12089 for the current window. 12090 Returns [0, 0] if the window cannot be found. 12091 12092 Parameters: ~ 12093 • {nr} (`integer`) 12094 12095 Return: ~ 12096 (`any`) 12097 12098 win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* 12099 Temporarily switch to window {target}, then move window {nr} 12100 to a new split adjacent to {target}. 12101 Unlike commands such as |:split|, no new windows are created 12102 (the |window-ID| of window {nr} is unchanged after the move). 12103 12104 Both {nr} and {target} can be window numbers or |window-ID|s. 12105 Both must be in the current tab page. 12106 12107 Returns zero for success, non-zero for failure. 12108 12109 {options} is a |Dictionary| with the following optional entries: 12110 "vertical" When TRUE, the split is created vertically, 12111 like with |:vsplit|. 12112 "rightbelow" When TRUE, the split is made below or to the 12113 right (if vertical). When FALSE, it is done 12114 above or to the left (if vertical). When not 12115 present, the values of 'splitbelow' and 12116 'splitright' are used. 12117 12118 Parameters: ~ 12119 • {nr} (`integer`) 12120 • {target} (`integer`) 12121 • {options} (`table?`) 12122 12123 Return: ~ 12124 (`any`) 12125 12126 winbufnr({nr}) *winbufnr()* 12127 The result is a Number, which is the number of the buffer 12128 associated with window {nr}. {nr} can be the window number or 12129 the |window-ID|. 12130 When {nr} is zero, the number of the buffer in the current 12131 window is returned. 12132 When window {nr} doesn't exist, -1 is returned. 12133 Example: >vim 12134 echo "The file in the current window is " .. bufname(winbufnr(0)) 12135 < 12136 12137 Parameters: ~ 12138 • {nr} (`integer`) 12139 12140 Return: ~ 12141 (`integer`) 12142 12143 wincol() *wincol()* 12144 The result is a Number, which is the virtual column of the 12145 cursor in the window. This is counting screen cells from the 12146 left side of the window. The leftmost column is one. 12147 12148 Return: ~ 12149 (`integer`) 12150 12151 windowsversion() *windowsversion()* 12152 The result is a String. For MS-Windows it indicates the OS 12153 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2", 12154 Windows XP is "5.1". For non-MS-Windows systems the result is 12155 an empty string. 12156 12157 Return: ~ 12158 (`string`) 12159 12160 winheight({nr}) *winheight()* 12161 Gets the height of |window-ID| {nr} (zero for "current 12162 window"), excluding any 'winbar' and 'statusline'. Returns -1 12163 if window {nr} doesn't exist. An existing window always has 12164 a height of zero or more. 12165 12166 Examples: >vim 12167 echo "Current window has " .. winheight(0) .. " lines." 12168 < 12169 12170 Parameters: ~ 12171 • {nr} (`integer`) 12172 12173 Return: ~ 12174 (`integer`) 12175 12176 winlayout([{tabnr}]) *winlayout()* 12177 The result is a nested List containing the layout of windows 12178 in a tabpage. 12179 12180 Without {tabnr} use the current tabpage, otherwise the tabpage 12181 with number {tabnr}. If the tabpage {tabnr} is not found, 12182 returns an empty list. 12183 12184 For a leaf window, it returns: > 12185 ["leaf", {winid}] 12186 < 12187 For horizontally split windows, which form a column, it 12188 returns: > 12189 ["col", [{nested list of windows}]] 12190 < For vertically split windows, which form a row, it returns: > 12191 ["row", [{nested list of windows}]] 12192 < 12193 Example: >vim 12194 " Only one window in the tab page 12195 echo winlayout() 12196 < > 12197 ['leaf', 1000] 12198 < >vim 12199 " Two horizontally split windows 12200 echo winlayout() 12201 < > 12202 ['col', [['leaf', 1000], ['leaf', 1001]]] 12203 < >vim 12204 " The second tab page, with three horizontally split 12205 " windows, with two vertically split windows in the 12206 " middle window 12207 echo winlayout(2) 12208 < > 12209 ['col', [['leaf', 1002], ['row', [['leaf', 1003], 12210 ['leaf', 1001]]], ['leaf', 1000]]] 12211 < 12212 12213 Parameters: ~ 12214 • {tabnr} (`integer?`) 12215 12216 Return: ~ 12217 (`vim.fn.winlayout.ret`) 12218 12219 winline() *winline()* 12220 The result is a Number, which is the screen line of the cursor 12221 in the window. This is counting screen lines from the top of 12222 the window. The first line is one. 12223 If the cursor was moved the view on the file will be updated 12224 first, this may cause a scroll. 12225 12226 Return: ~ 12227 (`integer`) 12228 12229 winnr([{arg}]) *winnr()* 12230 The result is a Number, which is the number of the current 12231 window. The top window has number 1. 12232 Returns zero for a hidden or non |focusable| window, unless 12233 it is the current window. 12234 12235 The optional argument {arg} supports the following values: 12236 $ the number of the last window (the window 12237 count). 12238 # the number of the last accessed window (where 12239 |CTRL-W_p| goes to). If there is no previous 12240 window or it is in another tab page 0 is 12241 returned. May refer to the current window in 12242 some cases (e.g. when evaluating 'statusline' 12243 expressions). 12244 {N}j the number of the Nth window below the 12245 current window (where |CTRL-W_j| goes to). 12246 {N}k the number of the Nth window above the current 12247 window (where |CTRL-W_k| goes to). 12248 {N}h the number of the Nth window left of the 12249 current window (where |CTRL-W_h| goes to). 12250 {N}l the number of the Nth window right of the 12251 current window (where |CTRL-W_l| goes to). 12252 The number can be used with |CTRL-W_w| and ":wincmd w" 12253 |:wincmd|. 12254 When {arg} is invalid an error is given and zero is returned. 12255 Also see |tabpagewinnr()| and |win_getid()|. 12256 Examples: >vim 12257 let window_count = winnr('$') 12258 let prev_window = winnr('#') 12259 let wnum = winnr('3k') 12260 < 12261 12262 Parameters: ~ 12263 • {arg} (`string|integer?`) 12264 12265 Return: ~ 12266 (`integer`) 12267 12268 winrestcmd() *winrestcmd()* 12269 Returns a sequence of |:resize| commands that should restore 12270 the current window sizes. Only works properly when no windows 12271 are opened or closed and the current window and tab page is 12272 unchanged. 12273 Example: >vim 12274 let cmd = winrestcmd() 12275 call MessWithWindowSizes() 12276 exe cmd 12277 < 12278 12279 Return: ~ 12280 (`string`) 12281 12282 winrestview({dict}) *winrestview()* 12283 Uses the |Dictionary| returned by |winsaveview()| to restore 12284 the view of the current window. 12285 Note: The {dict} does not have to contain all values, that are 12286 returned by |winsaveview()|. If values are missing, those 12287 settings won't be restored. So you can use: >vim 12288 call winrestview({'curswant': 4}) 12289 < 12290 This will only set the curswant value (the column the cursor 12291 wants to move on vertical movements) of the cursor to column 5 12292 (yes, that is 5), while all other settings will remain the 12293 same. This is useful, if you set the cursor position 12294 manually. 12295 12296 If you have changed the values the result is unpredictable. 12297 If the window size changed the result won't be the same. 12298 12299 Parameters: ~ 12300 • {dict} (`vim.fn.winrestview.dict`) 12301 12302 Return: ~ 12303 (`any`) 12304 12305 winsaveview() *winsaveview()* 12306 Returns a |Dictionary| that contains information to restore 12307 the view of the current window. Use |winrestview()| to 12308 restore the view. 12309 This is useful if you have a mapping that jumps around in the 12310 buffer and you want to go back to the original view. 12311 This does not save fold information. Use the 'foldenable' 12312 option to temporarily switch off folding, so that folds are 12313 not opened when moving around. This may have side effects. 12314 The return value includes: 12315 lnum cursor line number 12316 col cursor column (Note: the first column 12317 zero, as opposed to what |getcurpos()| 12318 returns) 12319 coladd cursor column offset for 'virtualedit' 12320 curswant column for vertical movement (Note: 12321 the first column is zero, as opposed 12322 to what |getcurpos()| returns). After 12323 |$| command it will be a very large 12324 number equal to |v:maxcol|. 12325 topline first line in the window 12326 topfill filler lines, only in diff mode 12327 leftcol first column displayed; only used when 12328 'wrap' is off 12329 skipcol columns skipped 12330 Note that no option values are saved. 12331 12332 Return: ~ 12333 (`vim.fn.winsaveview.ret`) 12334 12335 winwidth({nr}) *winwidth()* 12336 Gets the width of |window-ID| {nr} (zero for "current 12337 window"), including columns (|sign-column|, 'statuscolumn', 12338 etc.). Returns -1 if window {nr} doesn't exist. An existing 12339 window always has a width of zero or more. 12340 12341 Example: >vim 12342 echo "Current window has " .. winwidth(0) .. " columns." 12343 if winwidth(0) <= 50 12344 50 wincmd | 12345 endif 12346 < 12347 To get the buffer "viewport", use |getwininfo()|: >vim 12348 :echo getwininfo(win_getid())[0].width - getwininfo(win_getid())[0].textoff 12349 < 12350 To get the Nvim screen size, see the 'columns' option. 12351 12352 Parameters: ~ 12353 • {nr} (`integer`) 12354 12355 Return: ~ 12356 (`integer`) 12357 12358 wordcount() *wordcount()* 12359 The result is a dictionary of byte/chars/word statistics for 12360 the current buffer. This is the same info as provided by 12361 |g_CTRL-G| 12362 The return value includes: 12363 bytes Number of bytes in the buffer 12364 chars Number of chars in the buffer 12365 words Number of words in the buffer 12366 cursor_bytes Number of bytes before cursor position 12367 (not in Visual mode) 12368 cursor_chars Number of chars before cursor position 12369 (not in Visual mode) 12370 cursor_words Number of words before cursor position 12371 (not in Visual mode) 12372 visual_bytes Number of bytes visually selected 12373 (only in Visual mode) 12374 visual_chars Number of chars visually selected 12375 (only in Visual mode) 12376 visual_words Number of words visually selected 12377 (only in Visual mode) 12378 12379 Return: ~ 12380 (`any`) 12381 12382 writefile({object}, {fname} [, {flags}]) *writefile()* 12383 When {object} is a |List| write it to file {fname}. Each list 12384 item is separated with a NL. Each list item must be a String 12385 or Number. 12386 All NL characters are replaced with a NUL character. 12387 Inserting CR characters needs to be done before passing {list} 12388 to writefile(). 12389 12390 When {object} is a |Blob| write the bytes to file {fname} 12391 unmodified, also when binary mode is not specified. 12392 12393 {flags} must be a String. These characters are recognized: 12394 12395 'b' Binary mode is used: There will not be a NL after the 12396 last list item. An empty item at the end does cause the 12397 last line in the file to end in a NL. 12398 12399 'a' Append mode is used, lines are appended to the file: >vim 12400 call writefile(["foo"], "event.log", "a") 12401 call writefile(["bar"], "event.log", "a") 12402 < 12403 'D' Delete the file when the current function ends. This 12404 works like: >vim 12405 defer delete({fname}) 12406 < Fails when not in a function. Also see |:defer|. 12407 12408 's' fsync() is called after writing the file. This flushes 12409 the file to disk, if possible. This takes more time but 12410 avoids losing the file if the system crashes. 12411 12412 'S' fsync() is not called, even when 'fsync' is set. 12413 12414 When {flags} does not contain "S" or "s" then fsync() is 12415 called if the 'fsync' option is set. 12416 12417 An existing file is overwritten, if possible. 12418 12419 When the write fails -1 is returned, otherwise 0. There is an 12420 error message if the file can't be created or when writing 12421 fails. 12422 12423 Also see |readfile()|. 12424 To copy a file byte for byte: >vim 12425 let fl = readfile("foo", "b") 12426 call writefile(fl, "foocopy", "b") 12427 < 12428 12429 Parameters: ~ 12430 • {object} (`any`) 12431 • {fname} (`string`) 12432 • {flags} (`string?`) 12433 12434 Return: ~ 12435 (`any`) 12436 12437 xor({expr}, {expr}) *xor()* 12438 Bitwise XOR on the two arguments. The arguments are converted 12439 to a number. A List, Dict or Float argument causes an error. 12440 Also see `and()` and `or()`. 12441 Example: >vim 12442 let bits = xor(bits, 0x80) 12443 < 12444 12445 Parameters: ~ 12446 • {expr} (`integer`) 12447 • {expr1} (`integer`) 12448 12449 Return: ~ 12450 (`integer`) 12451 12452 ============================================================================== 12453 2. Matching a pattern in a String *string-match* 12454 12455 This is common between several functions. A regexp pattern as explained at 12456 |pattern| is normally used to find a match in the buffer lines. When a 12457 pattern is used to find a match in a String, almost everything works in the 12458 same way. The difference is that a String is handled like it is one line. 12459 When it contains a "\n" character, this is not seen as a line break for the 12460 pattern. It can be matched with a "\n" in the pattern, or with ".". Example: 12461 >vim 12462 let a = "aaaa\nxxxx" 12463 echo matchstr(a, "..\n..") 12464 " aa 12465 " xx 12466 echo matchstr(a, "a.x") 12467 " a 12468 " x 12469 12470 Don't forget that "^" will only match at the first character of the String and 12471 "$" at the last character of the string. They don't match after or before a 12472 "\n". 12473 12474 vim:tw=78:ts=8:noet:ft=help:norl: