robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1*vimfn.txt* Nvim 2 3 4 NVIM REFERENCE MANUAL 5 6 7Vimscript functions *vimscript-functions* *builtin.txt* 8 9For functions grouped by what they are used for see |function-list|. 10 11 Type |gO| to see the table of contents. 12============================================================================== 131. Details *vimscript-functions-details* 14 15abs({expr}) *abs()* 16 Lua: Prefer |math.abs()|. 17 18 Return the absolute value of {expr}. When {expr} evaluates to 19 a |Float| abs() returns a |Float|. When {expr} can be 20 converted to a |Number| abs() returns a |Number|. Otherwise 21 abs() gives an error message and returns -1. 22 Examples: >vim 23 echo abs(1.456) 24< 1.456 >vim 25 echo abs(-5.456) 26< 5.456 >vim 27 echo abs(-4) 28< 4 29 30 Parameters: ~ 31 • {expr} (`number`) 32 33 Return: ~ 34 (`number`) 35 36acos({expr}) *acos()* 37 Lua: Prefer |math.acos()|. 38 39 Return the arc cosine of {expr} measured in radians, as a 40 |Float| in the range of [0, pi]. 41 {expr} must evaluate to a |Float| or a |Number| in the range 42 [-1, 1]. 43 Returns NaN if {expr} is outside the range [-1, 1]. Returns 44 0.0 if {expr} is not a |Float| or a |Number|. 45 Examples: >vim 46 echo acos(0) 47< 1.570796 >vim 48 echo acos(-0.5) 49< 2.094395 50 51 Parameters: ~ 52 • {expr} (`number`) 53 54 Return: ~ 55 (`number`) 56 57add({object}, {expr}) *add()* 58 Lua: Prefer |table.insert()| for lists and `..` for blobs. 59 60 Append the item {expr} to |List| or |Blob| {object}. Returns 61 the resulting |List| or |Blob|. Examples: >vim 62 let alist = add([1, 2, 3], item) 63 call add(mylist, "woodstock") 64< Note that when {expr} is a |List| it is appended as a single 65 item. Use |extend()| to concatenate |Lists|. 66 When {object} is a |Blob| then {expr} must be a number. 67 Use |insert()| to add an item at another position. 68 Returns 1 if {object} is not a |List| or a |Blob|. 69 70 Parameters: ~ 71 • {object} (`any`) 72 • {expr} (`any`) 73 74 Return: ~ 75 (`any`) Resulting |List| or |Blob|, or 1 if {object} is not 76 a |List| or a |Blob|. 77 78and({expr}, {expr}) *and()* 79 Lua: Prefer |bit.band()|. 80 81 Bitwise AND on the two arguments. The arguments are converted 82 to a number. A List, Dict or Float argument causes an error. 83 Also see |or()| and |xor()|. 84 Example: >vim 85 let flag = and(bits, 0x80) 86< 87 88 Parameters: ~ 89 • {expr} (`number`) 90 • {expr1} (`number`) 91 92 Return: ~ 93 (`integer`) 94 95api_info() *api_info()* 96 Returns Dictionary of |api-metadata|. 97 98 View it in a nice human-readable format: >vim 99 lua vim.print(vim.fn.api_info()) 100< 101 102 Attributes: ~ 103 |api-fast| 104 105 Return: ~ 106 (`table`) 107 108append({lnum}, {text}) *append()* 109 Lua: Prefer |nvim_buf_set_lines()|. 110 111 When {text} is a |List|: Append each item of the |List| as a 112 text line below line {lnum} in the current buffer. 113 Otherwise append {text} as one text line below line {lnum} in 114 the current buffer. 115 Any type of item is accepted and converted to a String. 116 {lnum} can be zero to insert a line before the first one. 117 {lnum} is used like with |getline()|. 118 Returns 1 for failure ({lnum} out of range or out of memory), 119 0 for success. When {text} is an empty list zero is returned, 120 no matter the value of {lnum}. Example: >vim 121 let failed = append(line('$'), "# THE END") 122 let failed = append(0, ["Chapter 1", "the beginning"]) 123< 124 125 Parameters: ~ 126 • {lnum} (`integer|string`) 127 • {text} (`string|string[]`) 128 129 Return: ~ 130 (`0|1`) 131 132appendbufline({buf}, {lnum}, {text}) *appendbufline()* 133 Lua: Prefer |nvim_buf_set_lines()|. 134 135 Like |append()| but append the text in buffer {buf}. 136 137 This function works only for loaded buffers. First call 138 |bufload()| if needed. 139 140 For the use of {buf}, see |bufname()|. 141 142 {lnum} is the line number to append below. Note that using 143 |line()| would use the current buffer, not the one appending 144 to. Use "$" to append at the end of the buffer. Other string 145 values are not supported. 146 147 On success 0 is returned, on failure 1 is returned. 148 149 If {buf} is not a valid buffer or {lnum} is not valid, an 150 error message is given. Example: >vim 151 let failed = appendbufline(13, 0, "# THE START") 152< However, when {text} is an empty list then no error is given 153 for an invalid {lnum}, since {lnum} isn't actually used. 154 155 Parameters: ~ 156 • {buf} (`integer|string`) 157 • {lnum} (`integer`) 158 • {text} (`string`) 159 160 Return: ~ 161 (`0|1`) 162 163argc([{winid}]) *argc()* 164 The result is the number of files in the argument list. See 165 |arglist|. 166 If {winid} is not supplied, the argument list of the current 167 window is used. 168 If {winid} is -1, the global argument list is used. 169 Otherwise {winid} (a |window-number| or |window-ID|) specifies 170 the window of which the argument list is used. 171 Returns -1 if the {winid} argument is invalid. 172 173 Parameters: ~ 174 • {winid} (`integer?`) 175 176 Return: ~ 177 (`integer`) 178 179argidx() *argidx()* 180 The result is the current index in the argument list. 0 is 181 the first file. |argc()| - 1 is the last one. See |arglist|. 182 183 Return: ~ 184 (`integer`) 185 186arglistid([{winnr} [, {tabnr}]]) *arglistid()* 187 Return the argument list ID. This is a number which 188 identifies the argument list being used. Zero is used for the 189 global argument list. See |arglist|. 190 Returns -1 if the arguments are invalid. 191 192 Without arguments use the current window. 193 With {winnr} only use this window in the current tabpage. 194 With {winnr} and {tabnr} use the window in the specified tab 195 page. 196 {winnr} is a |window-number| or |window-ID|. 197 198 Parameters: ~ 199 • {winnr} (`integer?`) 200 • {tabnr} (`integer?`) 201 202 Return: ~ 203 (`integer`) 204 205argv([{nr} [, {winid}]]) *argv()* 206 The result is the {nr}th file in the argument list. See 207 |arglist|. "argv(0)" is the first one. Example: >vim 208 let i = 0 209 while i < argc() 210 let f = escape(fnameescape(argv(i)), '.') 211 exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>' 212 let i = i + 1 213 endwhile 214< Without the {nr} argument, or when {nr} is -1, a |List| with 215 the whole |arglist| is returned. 216 217 The {winid} argument is a |window-ID|, see |argc()|. 218 For the Vim command line arguments see |v:argv|. 219 220 Returns an empty string if {nr}th argument is not present in 221 the argument list. Returns an empty List if the {winid} 222 argument is invalid. 223 224 Parameters: ~ 225 • {nr} (`integer?`) 226 • {winid} (`integer?`) 227 228 Return: ~ 229 (`string|string[]`) 230 231asin({expr}) *asin()* 232 Lua: Prefer |math.asin()|. 233 234 Return the arc sine of {expr} measured in radians, as a |Float| 235 in the range of [-pi/2, pi/2]. 236 {expr} must evaluate to a |Float| or a |Number| in the range 237 [-1, 1]. 238 Returns NaN if {expr} is outside the range [-1, 1]. Returns 239 0.0 if {expr} is not a |Float| or a |Number|. 240 Examples: >vim 241 echo asin(0.8) 242< 0.927295 >vim 243 echo asin(-0.5) 244< -0.523599 245 246 Parameters: ~ 247 • {expr} (`any`) 248 249 Return: ~ 250 (`number`) 251 252assert_beeps({cmd}) *assert_beeps()* 253 Run {cmd} and add an error message to |v:errors| if it does 254 NOT produce a beep or visual bell. 255 Also see |assert_fails()|, |assert_nobeep()| and 256 |assert-return|. 257 258 Parameters: ~ 259 • {cmd} (`string`) 260 261 Return: ~ 262 (`0|1`) 263 264assert_equal({expected}, {actual} [, {msg}]) *assert_equal()* 265 Lua: Prefer |assert()| with |vim.deep_equal()|. 266 267 When {expected} and {actual} are not equal an error message is 268 added to |v:errors| and 1 is returned. Otherwise zero is 269 returned. |assert-return| 270 The error is in the form "Expected {expected} but got 271 {actual}". When {msg} is present it is prefixed to that, 272 along with the location of the assert when run from a script. 273 274 There is no automatic conversion, the String "4" is different 275 from the Number 4. And the number 4 is different from the 276 Float 4.0. The value of 'ignorecase' is not used here, case 277 always matters. 278 Example: >vim 279 call assert_equal('foo', 'bar', 'baz') 280< Will add the following to |v:errors|: > 281 test.vim line 12: baz: Expected 'foo' but got 'bar' 282< 283 284 Parameters: ~ 285 • {expected} (`any`) 286 • {actual} (`any`) 287 • {msg} (`any?`) 288 289 Return: ~ 290 (`0|1`) 291 292assert_equalfile({fname_one}, {fname_two}) *assert_equalfile()* 293 When the files {fname_one} and {fname_two} do not contain 294 exactly the same text an error message is added to |v:errors|. 295 Also see |assert-return|. 296 When {fname_one} or {fname_two} does not exist the error will 297 mention that. 298 299 Parameters: ~ 300 • {fname_one} (`string`) 301 • {fname_two} (`string`) 302 303 Return: ~ 304 (`0|1`) 305 306assert_exception({error} [, {msg}]) *assert_exception()* 307 When v:exception does not contain the string {error} an error 308 message is added to |v:errors|. Also see |assert-return|. 309 This can be used to assert that a command throws an exception. 310 Using the error number, followed by a colon, avoids problems 311 with translations: >vim 312 try 313 commandthatfails 314 call assert_false(1, 'command should have failed') 315 catch 316 call assert_exception('E492:') 317 endtry 318< 319 320 Parameters: ~ 321 • {error} (`any`) 322 • {msg} (`any?`) 323 324 Return: ~ 325 (`0|1`) 326 327 *assert_fails()* 328assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]]) 329 Run {cmd} and add an error message to |v:errors| if it does 330 NOT produce an error or when {error} is not found in the 331 error message. Also see |assert-return|. 332 333 When {error} is a string it must be found literally in the 334 first reported error. Most often this will be the error code, 335 including the colon, e.g. "E123:". >vim 336 call assert_fails('bad cmd', 'E987:') 337< 338 When {error} is a |List| with one or two strings, these are 339 used as patterns. The first pattern is matched against the 340 first reported error: >vim 341 call assert_fails('cmd', ['E987:.*expected bool']) 342< The second pattern, if present, is matched against the last 343 reported error. To only match the last error use an empty 344 string for the first error: >vim 345 call assert_fails('cmd', ['', 'E987:']) 346< 347 If {msg} is empty then it is not used. Do this to get the 348 default message when passing the {lnum} argument. 349 *E1115* 350 When {lnum} is present and not negative, and the {error} 351 argument is present and matches, then this is compared with 352 the line number at which the error was reported. That can be 353 the line number in a function or in a script. 354 *E1116* 355 When {context} is present it is used as a pattern and matched 356 against the context (script name or function name) where 357 {lnum} is located in. 358 359 Note that beeping is not considered an error, and some failing 360 commands only beep. Use |assert_beeps()| for those. 361 362 Parameters: ~ 363 • {cmd} (`string`) 364 • {error} (`any?`) 365 • {msg} (`any?`) 366 • {lnum} (`integer?`) 367 • {context} (`any?`) 368 369 Return: ~ 370 (`0|1`) 371 372assert_false({actual} [, {msg}]) *assert_false()* 373 Lua: Prefer |assert()|. 374 375 When {actual} is not false an error message is added to 376 |v:errors|, like with |assert_equal()|. 377 The error is in the form "Expected False but got {actual}". 378 When {msg} is present it is prefixed to that, along with the 379 location of the assert when run from a script. 380 Also see |assert-return|. 381 382 A value is false when it is zero. When {actual} is not a 383 number the assert fails. 384 385 Parameters: ~ 386 • {actual} (`any`) 387 • {msg} (`any?`) 388 389 Return: ~ 390 (`0|1`) 391 392assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* 393 Lua: Prefer |assert()|. 394 395 This asserts number and |Float| values. When {actual} is lower 396 than {lower} or higher than {upper} an error message is added 397 to |v:errors|. Also see |assert-return|. 398 The error is in the form "Expected range {lower} - {upper}, 399 but got {actual}". When {msg} is present it is prefixed to 400 that. 401 402 Parameters: ~ 403 • {lower} (`number`) 404 • {upper} (`number`) 405 • {actual} (`number`) 406 • {msg} (`string?`) 407 408 Return: ~ 409 (`0|1`) 410 411assert_match({pattern}, {actual} [, {msg}]) *assert_match()* 412 When {pattern} does not match {actual} an error message is 413 added to |v:errors|. Also see |assert-return|. 414 The error is in the form "Pattern {pattern} does not match 415 {actual}". When {msg} is present it is prefixed to that, 416 along with the location of the assert when run from a script. 417 418 {pattern} is used as with |expr-=~|: The matching is always done 419 like 'magic' was set and 'cpoptions' is empty, no matter what 420 the actual value of 'magic' or 'cpoptions' is. 421 422 {actual} is used as a string, automatic conversion applies. 423 Use "^" and "$" to match with the start and end of the text. 424 Use both to match the whole text. 425 426 Example: >vim 427 call assert_match('^f.*o$', 'foobar') 428< Will result in a string to be added to |v:errors|: > 429 test.vim line 12: Pattern '^f.*o$' does not match 'foobar' 430< 431 432 Parameters: ~ 433 • {pattern} (`string`) 434 • {actual} (`string`) 435 • {msg} (`string?`) 436 437 Return: ~ 438 (`0|1`) 439 440assert_nobeep({cmd}) *assert_nobeep()* 441 Run {cmd} and add an error message to |v:errors| if it 442 produces a beep or visual bell. 443 Also see |assert_beeps()|. 444 445 Parameters: ~ 446 • {cmd} (`string`) 447 448 Return: ~ 449 (`0|1`) 450 451assert_notequal({expected}, {actual} [, {msg}]) *assert_notequal()* 452 The opposite of `assert_equal()`: add an error message to 453 |v:errors| when {expected} and {actual} are equal. 454 Also see |assert-return|. 455 456 Parameters: ~ 457 • {expected} (`any`) 458 • {actual} (`any`) 459 • {msg} (`any?`) 460 461 Return: ~ 462 (`0|1`) 463 464assert_notmatch({pattern}, {actual} [, {msg}]) *assert_notmatch()* 465 The opposite of `assert_match()`: add an error message to 466 |v:errors| when {pattern} matches {actual}. 467 Also see |assert-return|. 468 469 Parameters: ~ 470 • {pattern} (`string`) 471 • {actual} (`string`) 472 • {msg} (`string?`) 473 474 Return: ~ 475 (`0|1`) 476 477assert_report({msg}) *assert_report()* 478 Report a test failure directly, using String {msg}. 479 Always returns one. 480 481 Parameters: ~ 482 • {msg} (`string`) 483 484 Return: ~ 485 (`0|1`) 486 487assert_true({actual} [, {msg}]) *assert_true()* 488 Lua: Prefer |assert()|. 489 490 When {actual} is not true an error message is added to 491 |v:errors|, like with |assert_equal()|. 492 Also see |assert-return|. 493 A value is |TRUE| when it is a non-zero number or |v:true|. 494 When {actual} is not a number or |v:true| the assert fails. 495 When {msg} is given it is prefixed to the default message, 496 along with the location of the assert when run from a script. 497 498 Parameters: ~ 499 • {actual} (`any`) 500 • {msg} (`string?`) 501 502 Return: ~ 503 (`0|1`) 504 505atan({expr}) *atan()* 506 Lua: Prefer |math.atan()|. 507 508 Return the principal value of the arc tangent of {expr}, in 509 the range [-pi/2, +pi/2] radians, as a |Float|. 510 {expr} must evaluate to a |Float| or a |Number|. 511 Returns 0.0 if {expr} is not a |Float| or a |Number|. 512 Examples: >vim 513 echo atan(100) 514< 1.560797 >vim 515 echo atan(-4.01) 516< -1.326405 517 518 Parameters: ~ 519 • {expr} (`number`) 520 521 Return: ~ 522 (`number`) 523 524atan2({expr1}, {expr2}) *atan2()* 525 Lua: Prefer |math.atan2()|. 526 527 Return the arc tangent of {expr1} / {expr2}, measured in 528 radians, as a |Float| in the range [-pi, pi]. 529 {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 530 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a 531 |Number|. 532 Examples: >vim 533 echo atan2(-1, 1) 534< -0.785398 >vim 535 echo atan2(1, -1) 536< 2.356194 537 538 Parameters: ~ 539 • {expr1} (`number`) 540 • {expr2} (`number`) 541 542 Return: ~ 543 (`number`) 544 545blob2list({blob}) *blob2list()* 546 Return a List containing the number value of each byte in Blob 547 {blob}. Examples: >vim 548 blob2list(0z0102.0304) " returns [1, 2, 3, 4] 549 blob2list(0z) " returns [] 550< Returns an empty List on error. |list2blob()| does the 551 opposite. 552 553 Parameters: ~ 554 • {blob} (`any`) 555 556 Return: ~ 557 (`any[]`) 558 559browse({save}, {title}, {initdir}, {default}) *browse()* 560 Put up a file requester. This only works when "has("browse")" 561 returns |TRUE| (only in some GUI versions). 562 The input fields are: 563 {save} when |TRUE|, select file to write 564 {title} title for the requester 565 {initdir} directory to start browsing in 566 {default} default file name 567 An empty string is returned when the "Cancel" button is hit, 568 something went wrong, or browsing is not possible. 569 570 Parameters: ~ 571 • {save} (`any`) 572 • {title} (`string`) 573 • {initdir} (`string`) 574 • {default} (`string`) 575 576 Return: ~ 577 (`0|1`) 578 579browsedir({title}, {initdir}) *browsedir()* 580 Put up a directory requester. This only works when 581 "has("browse")" returns |TRUE| (only in some GUI versions). 582 On systems where a directory browser is not supported a file 583 browser is used. In that case: select a file in the directory 584 to be used. 585 The input fields are: 586 {title} title for the requester 587 {initdir} directory to start browsing in 588 When the "Cancel" button is hit, something went wrong, or 589 browsing is not possible, an empty string is returned. 590 591 Parameters: ~ 592 • {title} (`string`) 593 • {initdir} (`string`) 594 595 Return: ~ 596 (`0|1`) 597 598bufadd({name}) *bufadd()* 599 Adds buffer {name} to the |buffer-list| literally: no special 600 chars or expansion are applied (including "~"). Returns the 601 new (or existing matching) buffer number, or 0 on error. 602 603 The buffer is not loaded and 'buflisted' is not set. When 604 {name} is an empty string, a new buffer is always created. 605 606 Example (Lua): >lua 607 local buf = vim.fn.bufadd(vim.fs.normalize('someName')) 608 -- Set 'buflisted'; trigger BufReadPre/BufReadPost/FileType. 609 vim.api.nvim_buf_call(buf, vim.cmd.edit) 610< 611 612 Parameters: ~ 613 • {name} (`string`) 614 615 Return: ~ 616 (`integer`) 617 618bufexists({buf}) *bufexists()* 619 Lua: Prefer |nvim_buf_is_valid()| after resolving {buf} to a 620 bufnr. 621 622 Checks whether a buffer with the name or number {buf} exists. 623 Returns |TRUE| if the buffer exists, |FALSE| otherwise. 624 If the {buf} argument is a number, buffer numbers are used. 625 Number zero is the alternate buffer for the current window. 626 627 If the {buf} argument is a string it must match a buffer name 628 exactly. The name can be: 629 - Relative to the current directory. 630 - A full path. 631 - The name of a buffer with 'buftype' set to "nofile". 632 - A URL name. 633 Unlisted buffers will be found. 634 Note that help files are listed by their short name in the 635 output of |:buffers|, but bufexists() requires using their 636 long name to be able to find them. 637 bufexists() may report a buffer exists, but to use the name 638 with a |:buffer| command you may need to use |expand()|. Esp 639 for MS-Windows 8.3 names in the form "c:\DOCUME~1" 640 Use "bufexists(0)" to test for the existence of an alternate 641 file name. 642 643 Parameters: ~ 644 • {buf} (`any`) 645 646 Return: ~ 647 (`0|1`) 648 649buflisted({buf}) *buflisted()* 650 Lua: Prefer |vim.bo| or |nvim_get_option_value()| after 651 resolving {buf} to a bufnr. 652 653 Checks whether a buffer called {buf} exists and is listed 654 (has the 'buflisted' option set). Returns |TRUE| if so, 655 |FALSE| otherwise. 656 The {buf} argument is used like with |bufexists()|. 657 658 Parameters: ~ 659 • {buf} (`any`) 660 661 Return: ~ 662 (`0|1`) 663 664bufload({buf}) *bufload()* 665 Ensure the buffer {buf} is loaded. When the buffer name 666 refers to an existing file then the file is read. Otherwise 667 the buffer will be empty. If the buffer was already loaded 668 then there is no change. If the buffer is not related to a 669 file then no file is read (e.g., when 'buftype' is "nofile"). 670 If there is an existing swap file for the file of the buffer, 671 there will be no dialog, the buffer will be loaded anyway. 672 The {buf} argument is used like with |bufexists()|. 673 674 Parameters: ~ 675 • {buf} (`any`) 676 677bufloaded({buf}) *bufloaded()* 678 Lua: Prefer |nvim_buf_is_loaded()| after resolving {buf} to a 679 bufnr. 680 681 Checks whether a buffer called {buf} exists and is loaded 682 (shown in a window or hidden). Returns |TRUE| if so, 683 |FALSE| otherwise. 684 The {buf} argument is used like with |bufexists()|. 685 686 Parameters: ~ 687 • {buf} (`any`) 688 689 Return: ~ 690 (`0|1`) 691 692bufname([{buf}]) *bufname()* 693 Lua: Prefer |nvim_buf_get_name()| after resolving {buf} to a 694 bufnr. 695 696 The result is the name of a buffer. Mostly as it is displayed 697 by the `:ls` command, but not using special names such as 698 "[No Name]". If the buffer represents a directory, the name 699 ends with a path separator, unless it was changed by |:file| or 700 |nvim_buf_set_name()|. 701 If {buf} is omitted the current buffer is used. 702 If {buf} is a Number, that buffer number's name is given. 703 Number zero is the alternate buffer for the current window. 704 If {buf} is a String, it is used as a |file-pattern| to match 705 with the buffer names. This is always done like 'magic' is 706 set and 'cpoptions' is empty. When there is more than one 707 match an empty string is returned. 708 "" or "%" can be used for the current buffer, "#" for the 709 alternate buffer. 710 A full match is preferred, otherwise a match at the start, end 711 or middle of the buffer name is accepted. If you only want a 712 full match then put "^" at the start and "$" at the end of the 713 pattern. 714 Listed buffers are found first. If there is a single match 715 with a listed buffer, that one is returned. Next unlisted 716 buffers are searched for. 717 If the {buf} is a String, but you want to use it as a buffer 718 number, force it to be a Number by adding zero to it: >vim 719 echo bufname("3" + 0) 720< If the buffer doesn't exist, or doesn't have a name, an empty 721 string is returned. >vim 722 echo bufname("#") " alternate buffer name 723 echo bufname(3) " name of buffer 3 724 echo bufname("%") " name of current buffer 725 echo bufname("file2") " name of buffer where "file2" matches. 726< 727 728 Parameters: ~ 729 • {buf} (`integer|string?`) 730 731 Return: ~ 732 (`string`) 733 734bufnr([{buf} [, {create}]]) *bufnr()* 735 Lua: Prefer |nvim_get_current_buf()| when omitted, or 736 |nvim_create_buf()| with |nvim_buf_set_name()| for creating; 737 name lookup, "$", "%", "#", and {create} semantics differ. 738 739 The result is the number of a buffer, as it is displayed by 740 the `:ls` command. For the use of {buf}, see |bufname()| 741 above. 742 If the buffer doesn't exist, -1 is returned. Or, if the 743 {create} argument is present and TRUE, a new, unlisted, 744 buffer is created and its number is returned. Example: >vim 745 let newbuf = bufnr('Scratch001', 1) 746< Using an empty name uses the current buffer. To create a new 747 buffer with an empty name use |bufadd()|. 748 749 bufnr("$") is the last buffer: >vim 750 let last_buffer = bufnr("$") 751< The result is a Number, which is the highest buffer number 752 of existing buffers. Note that not all buffers with a smaller 753 number necessarily exist, because ":bwipeout" may have removed 754 them. Use |bufexists()| to test for the existence of a buffer. 755 756 Parameters: ~ 757 • {buf} (`integer|string?`) 758 • {create} (`any?`) 759 760 Return: ~ 761 (`integer`) 762 763bufwinid({buf}) *bufwinid()* 764 Lua: Prefer |nvim_tabpage_list_wins()| with 765 |nvim_win_get_buf()| after resolving {buf}; only the current 766 tabpage is checked and no-match semantics differ. 767 768 Returns the |window-ID| of the first window associated with 769 buffer {buf}. For the use of {buf}, see |bufname()| above. 770 If buffer {buf} doesn't exist or there is no such window, -1 771 is returned. Example: >vim 772 773 echo "A window containing buffer 1 is " .. (bufwinid(1)) 774< 775 Only deals with the current tabpage. See |win_findbuf()| for 776 finding more. 777 778 Parameters: ~ 779 • {buf} (`any`) 780 781 Return: ~ 782 (`integer`) 783 784bufwinnr({buf}) *bufwinnr()* 785 Lua: Prefer |nvim_tabpage_list_wins()| with 786 |nvim_win_get_buf()| and |nvim_win_get_number()| after 787 resolving {buf}; only the current tabpage is checked and 788 no-match semantics differ. 789 790 Like |bufwinid()| but returns a |window-number| instead of a 791 |window-ID|. 792 If buffer {buf} doesn't exist or there is no such window, -1 793 is returned. Example: >vim 794 795 echo "A window containing buffer 1 is " .. (bufwinnr(1)) 796 797< The number can be used with |CTRL-W_w| and ":wincmd w" 798 |:wincmd|. 799 800 Parameters: ~ 801 • {buf} (`any`) 802 803 Return: ~ 804 (`integer`) 805 806byte2line({byte}) *byte2line()* 807 Return the line number that contains the character at byte 808 count {byte} in the current buffer. This includes the 809 end-of-line character, depending on the 'fileformat' option 810 for the current buffer. The first character has byte count 811 one. 812 Also see |line2byte()|, |go| and |:goto|. 813 814 Returns -1 if the {byte} value is invalid. 815 816 Parameters: ~ 817 • {byte} (`any`) 818 819 Return: ~ 820 (`integer`) 821 822byteidx({expr}, {nr} [, {utf16}]) *byteidx()* 823 Lua: Prefer |vim.str_byteindex()| for string input with 824 `"utf-32"` or `"utf-16"` and `strict_indexing = false`; 825 composing characters and out-of-range semantics differ. 826 827 Return byte index of the {nr}th character in the String 828 {expr}. Use zero for the first character, it then returns 829 zero. 830 If there are no multibyte characters the returned value is 831 equal to {nr}. 832 Composing characters are not counted separately, their byte 833 length is added to the preceding base character. See 834 |byteidxcomp()| below for counting composing characters 835 separately. 836 When {utf16} is present and TRUE, {nr} is used as the UTF-16 837 index in the String {expr} instead of as the character index. 838 The UTF-16 index is the index in the string when it is encoded 839 with 16-bit words. If the specified UTF-16 index is in the 840 middle of a character (e.g. in a 4-byte character), then the 841 byte index of the first byte in the character is returned. 842 Refer to |string-offset-encoding| for more information. 843 Example : >vim 844 echo matchstr(str, ".", byteidx(str, 3)) 845< will display the fourth character. Another way to do the 846 same: >vim 847 let s = strpart(str, byteidx(str, 3)) 848 echo strpart(s, 0, byteidx(s, 1)) 849< Also see |strgetchar()| and |strcharpart()|. 850 851 If there are less than {nr} characters -1 is returned. 852 If there are exactly {nr} characters the length of the string 853 in bytes is returned. 854 See |charidx()| and |utf16idx()| for getting the character and 855 UTF-16 index respectively from the byte index. 856 Examples: >vim 857 echo byteidx('a😊😊', 2) " returns 5 858 echo byteidx('a😊😊', 2, 1) " returns 1 859 echo byteidx('a😊😊', 3, 1) " returns 5 860< 861 862 Attributes: ~ 863 |api-fast| 864 865 Parameters: ~ 866 • {expr} (`any`) 867 • {nr} (`integer`) 868 • {utf16} (`any?`) 869 870 Return: ~ 871 (`integer`) 872 873byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()* 874 Lua: Prefer |vim.str_byteindex()| with `"utf-32"` or 875 `"utf-16"` and `strict_indexing = false`. 876 877 Like |byteidx()|, except that a composing character is counted 878 as a separate character. Example: >vim 879 let s = 'e' .. nr2char(0x301) 880 echo byteidx(s, 1) 881 echo byteidxcomp(s, 1) 882 echo byteidxcomp(s, 2) 883< The first and third echo result in 3 ('e' plus composing 884 character is 3 bytes), the second echo results in 1 ('e' is 885 one byte). 886 887 Attributes: ~ 888 |api-fast| 889 890 Parameters: ~ 891 • {expr} (`any`) 892 • {nr} (`integer`) 893 • {utf16} (`any?`) 894 895 Return: ~ 896 (`integer`) 897 898call({func}, {arglist} [, {dict}]) *call()* *E699* 899 Call function {func} with the items in |List| {arglist} as 900 arguments. 901 {func} can either be a |Funcref| or the name of a function. 902 a:firstline and a:lastline are set to the cursor line. 903 Returns the return value of the called function. 904 {dict} is for functions with the "dict" attribute. It will be 905 used to set the local variable "self". |Dictionary-function| 906 907 Parameters: ~ 908 • {func} (`any`) 909 • {arglist} (`any`) 910 • {dict} (`any?`) 911 912 Return: ~ 913 (`any`) 914 915ceil({expr}) *ceil()* 916 Lua: Prefer |math.ceil()|. 917 918 Return the smallest integral value greater than or equal to 919 {expr} as a |Float| (round up). 920 {expr} must evaluate to a |Float| or a |Number|. 921 Examples: >vim 922 echo ceil(1.456) 923< 2.0 >vim 924 echo ceil(-5.456) 925< -5.0 >vim 926 echo ceil(4.0) 927< 4.0 928 929 Returns 0.0 if {expr} is not a |Float| or a |Number|. 930 931 Parameters: ~ 932 • {expr} (`number`) 933 934 Return: ~ 935 (`number`) 936 937chanclose({id} [, {stream}]) *chanclose()* 938 Close a channel or a specific stream associated with it. 939 For a job, {stream} can be one of "stdin", "stdout", 940 "stderr" or "rpc" (closes stdin/stdout for a job started 941 with `"rpc":v:true`) If {stream} is omitted, all streams 942 are closed. If the channel is a pty, this will then close the 943 pty master, sending SIGHUP to the job process. 944 For a socket, there is only one stream, and {stream} should be 945 omitted. 946 947 Parameters: ~ 948 • {id} (`integer`) 949 • {stream} (`string?`) 950 951 Return: ~ 952 (`0|1`) 953 954changenr() *changenr()* 955 Return the number of the most recent change. This is the same 956 number as what is displayed with |:undolist| and can be used 957 with the |:undo| command. 958 When a change was made it is the number of that change. After 959 redo it is the number of the redone change. After undo it is 960 one less than the number of the undone change. 961 Returns 0 if the undo list is empty. 962 963 Return: ~ 964 (`integer`) 965 966chansend({id}, {data}) *chansend()* 967 Lua: Prefer |nvim_chan_send()| for string (binary) data. 968 969 Send data to channel {id}. For a job, it writes it to the 970 stdin of the process. For the stdio channel |channel-stdio|, 971 it writes to Nvim's stdout. Returns the number of bytes 972 written if the write succeeded, 0 otherwise. 973 See |channel-bytes| for more information. 974 975 {data} may be a string, string convertible, |Blob|, or a list. 976 977 If {data} is a list, the items will be joined by newlines; any 978 newlines in an item will be sent as NUL; to send a final 979 newline, include a final empty string. |NL-used-for-Nul| 980 981 Example: >vim 982 call chansend(id, ["abc", "123\n456", ""]) 983< will send "abc<NL>123<NUL>456<NL>". 984 985 chansend() writes raw data, not RPC messages. If the channel 986 was created with `"rpc":v:true` then the channel expects RPC 987 messages, use |rpcnotify()| and |rpcrequest()| instead. 988 989 Parameters: ~ 990 • {id} (`number`) 991 • {data} (`string|string[]`) 992 993 Return: ~ 994 (`integer`) 995 996char2nr({string} [, {utf8}]) *char2nr()* 997 Lua: Prefer |string.byte()|: only works with ASCII. 998 999 Return Number value of the first char in {string}. 1000 Examples: >vim 1001 echo char2nr(" ") " returns 32 1002 echo char2nr("ABC") " returns 65 1003 echo char2nr("á") " returns 225 1004 echo char2nr("á"[0]) " returns 195 1005 echo char2nr("\<M-x>") " returns 128 1006< Non-ASCII characters are always treated as UTF-8 characters. 1007 {utf8} is ignored, it exists only for backwards-compatibility. 1008 A combining character is a separate character. 1009 |nr2char()| does the opposite. 1010 1011 Returns 0 if {string} is not a |String|. 1012 1013 Attributes: ~ 1014 |api-fast| 1015 1016 Parameters: ~ 1017 • {string} (`string`) 1018 • {utf8} (`any?`) 1019 1020 Return: ~ 1021 (`0|1`) 1022 1023charclass({string}) *charclass()* 1024 Return the character class of the first character in {string}. 1025 The character class is one of: 1026 0 blank 1027 1 punctuation 1028 2 word character (depends on 'iskeyword') 1029 3 emoji 1030 other specific Unicode class 1031 The class is used in patterns and word motions. 1032 Returns 0 if {string} is not a |String|. 1033 1034 Parameters: ~ 1035 • {string} (`string`) 1036 1037 Return: ~ 1038 (`0|1|2|3|'other'`) 1039 1040charcol({expr} [, {winid}]) *charcol()* 1041 Lua: Prefer |nvim_win_get_cursor()| with |vim.str_utfindex()| 1042 for ".", or |nvim_get_current_line()| with 1043 |vim.str_utfindex()| for "$"; marks, list input, and window 1044 semantics differ. 1045 1046 Same as |col()| but returns the character index of the column 1047 position given with {expr} instead of the byte position. 1048 1049 Example: 1050 With the cursor on '세' in line 5 with text "여보세요": >vim 1051 echo charcol('.') " returns 3 1052 echo col('.') " returns 7 1053< 1054 1055 Parameters: ~ 1056 • {expr} (`string|any[]`) 1057 • {winid} (`integer?`) 1058 1059 Return: ~ 1060 (`integer`) 1061 1062charidx({string}, {idx} [, {countcc} [, {utf16}]]) *charidx()* 1063 Lua: Prefer |vim.str_utfindex()| for string input with 1064 `"utf-32"` or `"utf-16"` and `strict_indexing = false`; 1065 `countcc = false` and out-of-range semantics differ. 1066 1067 Return the character index of the byte at {idx} in {string}. 1068 The index of the first character is zero. 1069 If there are no multibyte characters the returned value is 1070 equal to {idx}. 1071 1072 When {countcc} is omitted or |FALSE|, then composing characters 1073 are not counted separately, their byte length is added to the 1074 preceding base character. 1075 When {countcc} is |TRUE|, then composing characters are 1076 counted as separate characters. 1077 1078 When {utf16} is present and TRUE, {idx} is used as the UTF-16 1079 index in the String {expr} instead of as the byte index. 1080 1081 Returns -1 if the arguments are invalid or if there are less 1082 than {idx} bytes. If there are exactly {idx} bytes the length 1083 of the string in characters is returned. 1084 1085 An error is given and -1 is returned if the first argument is 1086 not a string, the second argument is not a number or when the 1087 third argument is present and is not zero or one. 1088 1089 See |byteidx()| and |byteidxcomp()| for getting the byte index 1090 from the character index and |utf16idx()| for getting the 1091 UTF-16 index from the character index. 1092 Refer to |string-offset-encoding| for more information. 1093 Examples: >vim 1094 echo charidx('áb́ć', 3) " returns 1 1095 echo charidx('áb́ć', 6, 1) " returns 4 1096 echo charidx('áb́ć', 16) " returns -1 1097 echo charidx('a😊😊', 4, 0, 1) " returns 2 1098< 1099 1100 Attributes: ~ 1101 |api-fast| 1102 1103 Parameters: ~ 1104 • {string} (`string`) 1105 • {idx} (`integer`) 1106 • {countcc} (`boolean?`) 1107 • {utf16} (`boolean?`) 1108 1109 Return: ~ 1110 (`integer`) 1111 1112chdir({dir} [, {scope}]) *chdir()* 1113 Sets the |current-directory| of the given {scope}: 1114 - "buffer" Changes the buffer-local directory. |:bcd| 1115 - "window" Changes the window-local directory. |:lcd| 1116 - "tabpage" Changes the tabpage-local directory. |:tcd| 1117 - "global" Changes the global directory. |:cd| 1118 1119 If {scope} is not given it is decided as follows: 1120 - If buffer-local directory (|:bcd|) is set, scope is 1121 "buffer". 1122 - If the window-local directory (|:lcd|) is set, scope is 1123 "window". 1124 - If the tabpage-local directory (|:tcd|) is set, scope is 1125 "tabpage". 1126 - Otherwise, scope is "global". 1127 1128 If successful, returns the previous working directory. 1129 On failure, returns an empty string. 1130 1131 Example: >vim 1132 let save_dir = chdir(newdir) 1133 if save_dir != "" 1134 " ... do some work 1135 call chdir(save_dir) 1136 endif 1137< 1138 1139 Parameters: ~ 1140 • {dir} (`string`) 1141 • {scope} (`string?`) 1142 1143 Return: ~ 1144 (`string`) 1145 1146cindent({lnum}) *cindent()* 1147 Get the amount of indent for line {lnum} according the 1148 |C-indenting| rules, as with 'cindent'. 1149 The indent is counted in spaces, the value of 'tabstop' is 1150 relevant. {lnum} is used just like in |getline()|. 1151 When {lnum} is invalid -1 is returned. 1152 1153 To get or set indent of lines in a string, see |vim.text.indent()|. 1154 1155 Parameters: ~ 1156 • {lnum} (`integer|string`) 1157 1158 Return: ~ 1159 (`integer`) 1160 1161clearmatches([{win}]) *clearmatches()* 1162 Clears all matches previously defined for the current window 1163 by |matchadd()| and the |:match| commands. 1164 If {win} is specified, use this |window-number| or |window-ID| 1165 instead of the current window. 1166 1167 Parameters: ~ 1168 • {win} (`integer?`) 1169 1170cmdcomplete_info() *cmdcomplete_info()* 1171 Returns a |Dictionary| with information about cmdline 1172 completion. See |cmdline-completion|. 1173 The items are: 1174 cmdline_orig The original command-line string before 1175 completion began. 1176 pum_visible |TRUE| if popup menu is visible. 1177 See |pumvisible()|. 1178 matches List of all completion candidates. Each item 1179 is a string. 1180 selected Selected item index. First index is zero. 1181 Index is -1 if no item is selected (showing 1182 typed text only, or the last completion after 1183 no item is selected when using the <Up> or 1184 <Down> keys) 1185 1186 Returns an empty |Dictionary| if no completion was attempted, 1187 if there was only one candidate and it was fully completed, or 1188 if an error occurred. 1189 1190 Return: ~ 1191 (`table<string,any>`) 1192 1193col({expr} [, {winid}]) *col()* 1194 Lua: Prefer |nvim_win_get_cursor()| for "." (add 1), or Lua 1195 `#` on |nvim_get_current_line()| for "$"; marks, list input, 1196 and `virtualedit` differ. 1197 1198 Returns the byte index of the column position given with 1199 {expr}. 1200 For accepted positions see |getpos()|. 1201 When {expr} is "$", it means the end of the cursor line, so 1202 the result is the number of bytes in the cursor line plus one. 1203 Additionally {expr} can be [lnum, col]: a |List| with the line 1204 and column number. Most useful when the column is "$", to get 1205 the last column of a specific line. When "lnum" or "col" is 1206 out of range then col() returns zero. 1207 1208 With the optional {winid} argument the values are obtained for 1209 that window instead of the current window. 1210 1211 To get the line number use |line()|. To get both use 1212 |getpos()|. 1213 1214 For the screen column position use |virtcol()|. For the 1215 character position use |charcol()|. 1216 1217 Note that only marks in the current file can be used. 1218 1219 Examples: >vim 1220 echo col(".") " column of cursor 1221 echo col("$") " length of cursor line plus one 1222 echo col("'t") " column of mark t 1223 echo col("'" .. markname) " column of mark markname 1224< 1225 The first column is 1. Returns 0 if {expr} is invalid or when 1226 the window with ID {winid} is not found. 1227 For an uppercase mark the column may actually be in another 1228 buffer. 1229 For the cursor position, when 'virtualedit' is active, the 1230 column is one higher if the cursor is after the end of the 1231 line. Also, when using a <Cmd> mapping the cursor isn't 1232 moved, this can be used to obtain the column in Insert mode: >vim 1233 imap <F2> <Cmd>echo col(".").."\n"<CR> 1234< 1235 1236 Parameters: ~ 1237 • {expr} (`string|any[]`) 1238 • {winid} (`integer?`) 1239 1240 Return: ~ 1241 (`integer`) 1242 1243complete({startcol}, {matches}) *complete()* *E785* 1244 Set the matches for Insert mode completion. Can only be used 1245 in Insert mode. Typically invoked from a mapping with 1246 CTRL-R = (see |i_CTRL-R|), but may also be called from a 1247 |<Cmd>| mapping. It does not work after CTRL-O or with an 1248 expression mapping. 1249 {startcol} is the byte offset in the line where the completed 1250 text start. The text up to the cursor is the original text 1251 that will be replaced by the matches. Use col('.') for an 1252 empty string. "col('.') - 1" will replace one character by a 1253 match. 1254 {matches} must be a |List|. Each |List| item is one match. 1255 See |complete-items| for the kind of items that are possible. 1256 "longest" in 'completeopt' is ignored. 1257 Note that the after calling this function you need to avoid 1258 inserting anything that would cause completion to stop. 1259 The match can be selected with CTRL-N and CTRL-P as usual with 1260 Insert mode completion. The popup menu will appear if 1261 specified, see |ins-completion-menu|. 1262 Unlike with other |ins-completion| modes, the CTRL-N and 1263 CTRL-P keys can be mapped while this completion is active. 1264 For example, to make CTRL-N move the selection without 1265 inserting the match: >vim 1266 1267 inoremap <expr> <C-N> complete_info().mode ==# 'eval' 1268 \ ? '<Down>' : '<C-N>' 1269< 1270 1271 Example: >vim 1272 1273 inoremap <F5> <C-R>=ListMonths()<CR> 1274 1275 func ListMonths() 1276 call complete(col('.'), ['January', 'February', 'March', 1277 \ 'April', 'May', 'June', 'July', 'August', 1278 \ 'September', 'October', 'November', 'December']) 1279 return '' 1280 endfunc 1281 1282< This isn't very useful, but it shows how it works. Note that 1283 an empty string is returned to avoid a zero being inserted. 1284 1285 Parameters: ~ 1286 • {startcol} (`integer`) 1287 • {matches} (`any[]`) 1288 1289complete_add({expr}) *complete_add()* 1290 Add {expr} to the list of matches. Only to be used by the 1291 function specified with the 'completefunc' option. 1292 Returns 0 for failure (empty string or out of memory), 1293 1 when the match was added, 2 when the match was already in 1294 the list. 1295 See |complete-functions| for an explanation of {expr}. It is 1296 the same as one item in the list that 'omnifunc' would return. 1297 1298 Parameters: ~ 1299 • {expr} (`any`) 1300 1301 Return: ~ 1302 (`0|1|2`) 1303 1304complete_check() *complete_check()* 1305 Check for a key typed while looking for completion matches. 1306 This is to be used when looking for matches takes some time. 1307 Returns |TRUE| when searching for matches is to be aborted, 1308 zero otherwise. 1309 Only to be used by the function specified with the 1310 'completefunc' option. 1311 1312 Return: ~ 1313 (`0|1`) 1314 1315complete_info([{what}]) *complete_info()* 1316 Returns a |Dictionary| with information about Insert mode 1317 completion. See |ins-completion|. 1318 The items are: 1319 auto |TRUE| when Vim started this completion by 1320 itself, which is what 'autocomplete' does, 1321 and |FALSE| when a key asked for it, such as 1322 |i_CTRL-X_CTRL-O|. A |complete-functions| 1323 function can read this to tell the two apart. 1324 Returned only when asked for in {what}. 1325 completed Return a dictionary containing the entries of 1326 the currently selected index item. 1327 items List of all completion candidates. Each item 1328 is a dictionary containing the entries "word", 1329 "abbr", "menu", "kind", "info", 1330 "abbr_hlgroup", "kind_hlgroup" and 1331 "user_data". The highlight group entries hold 1332 the name that the item was added with, 1333 or an empty string. 1334 "equal", "preselect" and "commit_chars" are 1335 included only for items that set them. 1336 See |complete-items|. 1337 matches Same as "items", but only returns items that 1338 are matching current query. If both "matches" 1339 and "items" are in "what", the returned list 1340 will still be named "items", but each item 1341 will have an additional "match" field. 1342 mode Current completion mode name string. 1343 See |complete_info_mode| for the values. 1344 preinserted_text 1345 The actual text that is pre-inserted, see 1346 |preinserted()|. 1347 pum_visible |TRUE| if popup menu is visible. 1348 See |pumvisible()|. 1349 selected Selected item index. First index is zero. 1350 Index is -1 if no item is selected (showing 1351 typed text only, or the last completion after 1352 no item is selected when using the <Up> or 1353 <Down> keys) 1354 preview_winid Info floating preview window id. 1355 preview_bufnr Info floating preview buffer id. 1356 1357 *complete_info_mode* 1358 mode values are: 1359 "" Not in completion mode 1360 "keyword" Keyword completion |i_CTRL-X_CTRL-N| 1361 "ctrl_x" Just pressed CTRL-X |i_CTRL-X| 1362 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or 1363 |i_CTRL-X_CTRL-Y| 1364 "whole_line" Whole lines |i_CTRL-X_CTRL-L| 1365 "files" File names |i_CTRL-X_CTRL-F| 1366 "tags" Tags |i_CTRL-X_CTRL-]| 1367 "path_defines" Definition completion |i_CTRL-X_CTRL-D| 1368 "path_patterns" Include completion |i_CTRL-X_CTRL-I| 1369 "dictionary" Dictionary |i_CTRL-X_CTRL-K| 1370 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T| 1371 "cmdline" Vim Command line |i_CTRL-X_CTRL-V| 1372 "function" User defined completion |i_CTRL-X_CTRL-U| 1373 "omni" Omni completion |i_CTRL-X_CTRL-O| 1374 "spell" Spelling suggestions |i_CTRL-X_s| 1375 "eval" |complete()| completion 1376 "register" Words from registers |i_CTRL-X_CTRL-R| 1377 "unknown" Other internal modes 1378 1379 If the optional {what} list argument is supplied, then only 1380 the items listed in {what} are returned. Unsupported items in 1381 {what} are silently ignored. 1382 1383 To get the position and size of the popup menu, see 1384 |pum_getpos()|. It's also available in |v:event| during the 1385 |CompleteChanged| event. 1386 1387 Returns an empty |Dictionary| on error. 1388 1389 Examples: >vim 1390 " Get all items 1391 call complete_info() 1392 " Get only 'mode' 1393 call complete_info(['mode']) 1394 " Get only 'mode' and 'pum_visible' 1395 call complete_info(['mode', 'pum_visible']) 1396< 1397 1398 Parameters: ~ 1399 • {what} (`any[]?`) 1400 1401 Return: ~ 1402 (`table`) 1403 1404confirm({msg} [, {choices} [, {default} [, {type}]]]) *confirm()* 1405 confirm() offers the user a dialog, from which a choice can be 1406 made. It returns the number of the choice. For the first 1407 choice this is 1. 1408 1409 {msg} is displayed in a dialog with {choices} as the 1410 alternatives. When {choices} is missing or empty, "&OK" is 1411 used (and translated). 1412 {msg} is a String, use '\n' to include a newline. Only on 1413 some systems the string is wrapped when it doesn't fit. 1414 1415 {choices} is a String, with the individual choices separated 1416 by '\n', e.g. >vim 1417 confirm("Save changes?", "&Yes\n&No\n&Cancel") 1418< The letter after the '&' is the shortcut key for that choice. 1419 Thus you can type 'c' to select "Cancel". The shortcut does 1420 not need to be the first letter: >vim 1421 confirm("file has been modified", "&Save\nSave &All") 1422< For the console, the first letter of each choice is used as 1423 the default shortcut key. Case is ignored. 1424 1425 The optional {type} String argument gives the type of dialog. 1426 It can be one of these values: "Error", "Question", "Info", 1427 "Warning" or "Generic". Only the first character is relevant. 1428 When {type} is omitted, "Generic" is used. 1429 1430 The optional {type} argument gives the type of dialog. This 1431 is only used for the icon of the Win32 GUI. It can be one of 1432 these values: "Error", "Question", "Info", "Warning" or 1433 "Generic". Only the first character is relevant. 1434 When {type} is omitted, "Generic" is used. 1435 1436 If the user aborts the dialog by pressing <Esc>, CTRL-C, 1437 or another valid interrupt key, confirm() returns 0. 1438 1439 An example: >vim 1440 let choice = confirm("What do you want?", 1441 \ "&Apples\n&Oranges\n&Bananas", 2) 1442 if choice == 0 1443 echo "make up your mind!" 1444 elseif choice == 3 1445 echo "tasteful" 1446 else 1447 echo "I prefer bananas myself." 1448 endif 1449< In a GUI dialog, buttons are used. The layout of the buttons 1450 depends on the 'v' flag in 'guioptions'. If it is included, 1451 the buttons are always put vertically. Otherwise, confirm() 1452 tries to put the buttons in one horizontal line. If they 1453 don't fit, a vertical layout is used anyway. For some systems 1454 the horizontal layout is always used. 1455 1456 Parameters: ~ 1457 • {msg} (`string`) 1458 • {choices} (`string?`) 1459 • {default} (`integer?`) 1460 • {type} (`string?`) 1461 1462 Return: ~ 1463 (`integer`) 1464 1465copy({expr}) *copy()* 1466 Lua: Prefer |vim.deepcopy()|; deeper than Vimscript |copy()|. 1467 1468 Make a copy of {expr}. For Numbers and Strings this isn't 1469 different from using {expr} directly. 1470 When {expr} is a |List| a shallow copy is created. This means 1471 that the original |List| can be changed without changing the 1472 copy, and vice versa. But the items are identical, thus 1473 changing an item changes the contents of both |Lists|. 1474 A |Dictionary| is copied in a similar way as a |List|. 1475 Also see |deepcopy()|. 1476 1477 Parameters: ~ 1478 • {expr} (`T`) 1479 1480 Return: ~ 1481 (`T`) 1482 1483cos({expr}) *cos()* 1484 Lua: Prefer |math.cos()|. 1485 1486 Return the cosine of {expr}, measured in radians, as a |Float|. 1487 {expr} must evaluate to a |Float| or a |Number|. 1488 Returns 0.0 if {expr} is not a |Float| or a |Number|. 1489 Examples: >vim 1490 echo cos(100) 1491< 0.862319 >vim 1492 echo cos(-4.01) 1493< -0.646043 1494 1495 Parameters: ~ 1496 • {expr} (`number`) 1497 1498 Return: ~ 1499 (`number`) 1500 1501cosh({expr}) *cosh()* 1502 Lua: Prefer |math.cosh()|. 1503 1504 Return the hyperbolic cosine of {expr} as a |Float| in the range 1505 [1, inf]. 1506 {expr} must evaluate to a |Float| or a |Number|. 1507 Returns 0.0 if {expr} is not a |Float| or a |Number|. 1508 Examples: >vim 1509 echo cosh(0.5) 1510< 1.127626 >vim 1511 echo cosh(-0.5) 1512< 1.127626 1513 1514 Parameters: ~ 1515 • {expr} (`number`) 1516 1517 Return: ~ 1518 (`number`) 1519 1520count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706* 1521 Return the number of times an item with value {expr} appears 1522 in |String|, |List| or |Dictionary| {comp}. 1523 1524 If {start} is given then start with the item with this index. 1525 {start} can only be used with a |List|. 1526 1527 When {ic} is given and it's |TRUE| then case is ignored. 1528 1529 When {comp} is a string then the number of not overlapping 1530 occurrences of {expr} is returned. Zero is returned when 1531 {expr} is an empty string. 1532 1533 Parameters: ~ 1534 • {comp} (`string|table|any[]`) 1535 • {expr} (`any`) 1536 • {ic} (`boolean?`) 1537 • {start} (`integer?`) 1538 1539 Return: ~ 1540 (`integer`) 1541 1542cursor({lnum}, {col} [, {off}]) *cursor()* 1543cursor({list}) 1544 Lua: Prefer |nvim_win_set_cursor()| with `{lnum, col - 1}`; 1545 `off`, `curswant`, and failure semantics differ. 1546 1547 Positions the cursor at the column (byte count) {col} in the 1548 line {lnum}. The first column is one. 1549 1550 When there is one argument {list} this is used as a |List| 1551 with two, three or four item: 1552 [{lnum}, {col}] 1553 [{lnum}, {col}, {off}] 1554 [{lnum}, {col}, {off}, {curswant}] 1555 This is like the return value of |getpos()| or |getcurpos()|, 1556 but without the first item. 1557 1558 To position the cursor using {col} as the character count, use 1559 |setcursorcharpos()|. 1560 1561 Does not change the jumplist. 1562 {lnum} is used like with |getline()|, except that if {lnum} is 1563 zero, the cursor will stay in the current line. 1564 If {lnum} is greater than the number of lines in the buffer, 1565 the cursor will be positioned at the last line in the buffer. 1566 If {col} is greater than the number of bytes in the line, 1567 the cursor will be positioned at the last character in the 1568 line. 1569 If {col} is zero, the cursor will stay in the current column. 1570 If {curswant} is given it is used to set the preferred column 1571 for vertical movement. Otherwise {col} is used. 1572 1573 When 'virtualedit' is used {off} specifies the offset in 1574 screen columns from the start of the character. E.g., a 1575 position within a <Tab> or after the last character. 1576 Returns 0 when the position could be set, -1 otherwise. 1577 1578 Parameters: ~ 1579 • {list} (`integer[]`) 1580 1581 Return: ~ 1582 (`any`) 1583 1584debugbreak({pid}) *debugbreak()* 1585 Lua: Prefer |uv.kill()| with `"sigtrap"` (or `"sigint"` 1586 outside MS-Windows); exact semantics differ. 1587 1588 Specifically used to interrupt a program being debugged. It 1589 will cause process {pid} to get a SIGTRAP. Behavior for other 1590 processes is undefined. See |terminal-debug|. 1591 (Sends a SIGINT to a process {pid} other than MS-Windows) 1592 1593 Returns |TRUE| if successfully interrupted the program. 1594 Otherwise returns |FALSE|. 1595 1596 Parameters: ~ 1597 • {pid} (`integer`) 1598 1599 Return: ~ 1600 (`any`) 1601 1602deepcopy({expr} [, {noref}]) *deepcopy()* *E698* 1603 Lua: Prefer |vim.deepcopy()|. 1604 1605 Make a copy of {expr}. For Numbers and Strings this isn't 1606 different from using {expr} directly. 1607 When {expr} is a |List| a full copy is created. This means 1608 that the original |List| can be changed without changing the 1609 copy, and vice versa. When an item is a |List|, a copy for it 1610 is made, recursively. Thus changing an item in the copy does 1611 not change the contents of the original |List|. 1612 1613 When {noref} is omitted or zero a contained |List| or 1614 |Dictionary| is only copied once. All references point to 1615 this single copy. With {noref} set to 1 every occurrence of a 1616 |List| or |Dictionary| results in a new copy. This also means 1617 that a cyclic reference causes deepcopy() to fail. 1618 *E724* 1619 Nesting is possible up to 100 levels. When there is an item 1620 that refers back to a higher level making a deep copy with 1621 {noref} set to 1 will fail. 1622 Also see |copy()|. 1623 1624 Parameters: ~ 1625 • {expr} (`T`) 1626 • {noref} (`boolean?`) 1627 1628 Return: ~ 1629 (`T`) 1630 1631delete({fname} [, {flags}]) *delete()* 1632 Lua: Prefer |vim.fs.rm()|. 1633 1634 Without {flags} or with {flags} empty: Deletes the file by the 1635 name {fname}. 1636 1637 This also works when {fname} is a symbolic link. The symbolic 1638 link itself is deleted, not what it points to. 1639 1640 When {flags} is "d": Deletes the directory by the name 1641 {fname}. This fails when directory {fname} is not empty. 1642 1643 When {flags} is "rf": Deletes the directory by the name 1644 {fname} and everything in it, recursively. BE CAREFUL! 1645 Note: on MS-Windows it is not possible to delete a directory 1646 that is being used. 1647 1648 The result is a Number, which is 0/false if the delete 1649 operation was successful and -1/true when the deletion failed 1650 or partly failed. 1651 1652 Parameters: ~ 1653 • {fname} (`string`) 1654 • {flags} (`string?`) 1655 1656 Return: ~ 1657 (`integer`) 1658 1659deletebufline({buf}, {first} [, {last}]) *deletebufline()* 1660 Lua: Prefer |nvim_buf_set_lines()|. 1661 1662 Delete lines {first} to {last} (inclusive) from buffer {buf}. 1663 If {last} is omitted then delete line {first} only. 1664 On success 0 is returned, on failure 1 is returned. 1665 1666 This function works only for loaded buffers. First call 1667 |bufload()| if needed. 1668 1669 For the use of {buf}, see |bufname()| above. 1670 1671 {first} and {last} are used like with |getline()|. Note that 1672 when using |line()| this refers to the current buffer. Use "$" 1673 to refer to the last line in buffer {buf}. 1674 1675 Parameters: ~ 1676 • {buf} (`integer|string`) 1677 • {first} (`integer|string`) 1678 • {last} (`integer|string?`) 1679 1680 Return: ~ 1681 (`any`) 1682 1683dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()* 1684 Adds a watcher to a dictionary. A dictionary watcher is 1685 identified by three components: 1686 1687 - A dictionary({dict}); 1688 - A key pattern({pattern}). 1689 - A function({callback}). 1690 1691 After this is called, every change on {dict} and on keys 1692 matching {pattern} will result in {callback} being invoked. 1693 1694 For example, to watch all global variables: >vim 1695 silent! call dictwatcherdel(g:, '*', 'OnDictChanged') 1696 function! OnDictChanged(d,k,z) 1697 echomsg string(a:k) string(a:z) 1698 endfunction 1699 call dictwatcheradd(g:, '*', 'OnDictChanged') 1700< 1701 For now {pattern} only accepts very simple patterns that can 1702 contain a "*" at the end of the string, in which case it will 1703 match every key that begins with the substring before the "*". 1704 That means if "*" is not the last character of {pattern}, only 1705 keys that are exactly equal as {pattern} will be matched. 1706 1707 The {callback} receives three arguments: 1708 1709 - The dictionary being watched. 1710 - The key which changed. 1711 - A dictionary containing the new and old values for the key. 1712 1713 The type of change can be determined by examining the keys 1714 present on the third argument: 1715 1716 - If contains both `old` and `new`, the key was updated. 1717 - If it contains only `new`, the key was added. 1718 - If it contains only `old`, the key was deleted. 1719 1720 This function can be used by plugins to implement options with 1721 validation and parsing logic. 1722 1723 Parameters: ~ 1724 • {dict} (`table`) 1725 • {pattern} (`string`) 1726 • {callback} (`function`) 1727 1728 Return: ~ 1729 (`any`) 1730 1731dictwatcherdel({dict}, {pattern}, {callback}) *dictwatcherdel()* 1732 Removes a watcher added with |dictwatcheradd()|. All three 1733 arguments must match the ones passed to |dictwatcheradd()| in 1734 order for the watcher to be successfully deleted. 1735 1736 Parameters: ~ 1737 • {dict} (`any`) 1738 • {pattern} (`string`) 1739 • {callback} (`function`) 1740 1741 Return: ~ 1742 (`any`) 1743 1744did_filetype() *did_filetype()* 1745 Returns |TRUE| when autocommands are being executed and the 1746 FileType event triggered at least once for a buffer with 1747 a non-empty 'filetype'. Can be used to avoid triggering 1748 the FileType event again in the |ftdetect| scripts. |FileType| 1749 Returns |FALSE| when `:setf FALLBACK` was used. 1750 1751 When editing another file, the counter is reset, thus this 1752 really checks if the FileType event has been triggered for the 1753 current buffer. This allows an autocommand that starts 1754 editing another buffer to set 'filetype' and load a syntax 1755 file. 1756 1757 Attributes: ~ 1758 |api-fast| 1759 1760 Return: ~ 1761 (`integer`) 1762 1763diff_filler({lnum}) *diff_filler()* 1764 Returns the number of filler lines above line {lnum}. 1765 These are the lines that were inserted at this point in 1766 another diff'ed window. These filler lines are shown in the 1767 display but don't exist in the buffer. 1768 {lnum} is used like with |getline()|. Thus "." is the current 1769 line, "'m" mark m, etc. 1770 1771 To get the filler lines after the last buffer line, use: >vim 1772 echo diff_filler(line('$')+1) 1773< 1774 Returns 0 if the current window is not in diff mode or filler 1775 lines have been disabled using 'diffopt'. 1776 1777 Parameters: ~ 1778 • {lnum} (`integer|string`) 1779 1780 Return: ~ 1781 (`integer`) 1782 1783diff_hlID({lnum}, {col}) *diff_hlID()* 1784 Returns the highlight ID for diff mode at line {lnum} column 1785 {col} (byte index). When the current line does not have a 1786 diff change zero is returned. 1787 {lnum} is used like with |getline()|. Thus "." is the current 1788 line, "'m" mark m, etc. 1789 {col} is 1 for the leftmost column, {lnum} is 1 for the first 1790 line. 1791 The highlight ID can be used with |synIDattr()| to obtain 1792 syntax information about the highlighting. 1793 1794 Parameters: ~ 1795 • {lnum} (`integer|string`) 1796 • {col} (`integer`) 1797 1798 Return: ~ 1799 (`any`) 1800 1801digraph_get({chars}) *digraph_get()* *E1214* 1802 Return the digraph of {chars}. This should be a string with 1803 exactly two characters. If {chars} are not just two 1804 characters, or the digraph of {chars} does not exist, an error 1805 is given and an empty string is returned. 1806 1807 Also see |digraph_getlist()|. 1808 1809 Examples: >vim 1810 " Get a built-in digraph 1811 echo digraph_get('00') " Returns '∞' 1812 1813 " Get a user-defined digraph 1814 call digraph_set('aa', 'あ') 1815 echo digraph_get('aa') " Returns 'あ' 1816< 1817 1818 Parameters: ~ 1819 • {chars} (`string`) 1820 1821 Return: ~ 1822 (`string`) 1823 1824digraph_getlist([{listall}]) *digraph_getlist()* 1825 Return a list of digraphs. If the {listall} argument is given 1826 and it is TRUE, return all digraphs, including the default 1827 digraphs. Otherwise, return only user-defined digraphs. 1828 1829 Also see |digraph_get()|. 1830 1831 Examples: >vim 1832 " Get user-defined digraphs 1833 echo digraph_getlist() 1834 1835 " Get all the digraphs, including default digraphs 1836 echo digraph_getlist(1) 1837< 1838 1839 Parameters: ~ 1840 • {listall} (`boolean?`) 1841 1842 Return: ~ 1843 (`string[][]`) 1844 1845digraph_set({chars}, {digraph}) *digraph_set()* 1846 Add digraph {chars} to the list. {chars} must be a string 1847 with two characters. {digraph} is a string with one UTF-8 1848 encoded character. *E1215* 1849 Be careful, composing characters are NOT ignored. This 1850 function is similar to |:digraphs| command, but useful to add 1851 digraphs start with a white space. 1852 1853 The function result is v:true if |digraph| is registered. If 1854 this fails an error message is given and v:false is returned. 1855 1856 If you want to define multiple digraphs at once, you can use 1857 |digraph_setlist()|. 1858 1859 Example: >vim 1860 call digraph_set(' ', 'あ') 1861< 1862 1863 Parameters: ~ 1864 • {chars} (`string`) 1865 • {digraph} (`string`) 1866 1867 Return: ~ 1868 (`any`) 1869 1870digraph_setlist({digraphlist}) *digraph_setlist()* 1871 Similar to |digraph_set()| but this function can add multiple 1872 digraphs at once. {digraphlist} is a list composed of lists, 1873 where each list contains two strings with {chars} and 1874 {digraph} as in |digraph_set()|. *E1216* 1875 Example: >vim 1876 call digraph_setlist([['aa', 'あ'], ['ii', 'い']]) 1877< 1878 It is similar to the following: >vim 1879 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']] 1880 call digraph_set(chars, digraph) 1881 endfor 1882< Except that the function returns after the first error, 1883 following digraphs will not be added. 1884 1885 Parameters: ~ 1886 • {digraphlist} (`table<integer,string[]>`) 1887 1888 Return: ~ 1889 (`any`) 1890 1891empty({expr}) *empty()* 1892 Lua: Prefer plain Lua emptiness checks, or |vim.tbl_isempty()| 1893 for tables. 1894 1895 Return the Number 1 if {expr} is empty, zero otherwise. 1896 - A |List| or |Dictionary| is empty when it does not have any 1897 items. 1898 - A |String| is empty when its length is zero. 1899 - A |Number| and |Float| are empty when their value is zero. 1900 - |v:false| and |v:null| are empty, |v:true| is not. 1901 - A |Blob| is empty when its length is zero. 1902 1903 Parameters: ~ 1904 • {expr} (`any`) 1905 1906 Return: ~ 1907 (`integer`) 1908 1909environ() *environ()* 1910 Lua: Prefer |uv.os_environ()| for the full environment table; 1911 |vim.env| for keyed access. 1912 1913 Return all of environment variables as dictionary. You can 1914 check if an environment variable exists like this: >vim 1915 echo has_key(environ(), 'HOME') 1916< Note that the variable name may be CamelCase; to ignore case 1917 use this: >vim 1918 echo index(keys(environ()), 'HOME', 0, 1) != -1 1919< 1920 1921 Attributes: ~ 1922 |api-fast| 1923 1924 Return: ~ 1925 (`any`) 1926 1927escape({string}, {chars}) *escape()* 1928 Escape the characters in {chars} that occur in {string} with a 1929 backslash. Example: >vim 1930 echo escape('c:\program files\vim', ' \') 1931< results in: > 1932 c:\\program\ files\\vim 1933< Also see |shellescape()| and |fnameescape()|. 1934 1935 Attributes: ~ 1936 |api-fast| 1937 1938 Parameters: ~ 1939 • {string} (`string`) 1940 • {chars} (`string`) 1941 1942 Return: ~ 1943 (`string`) 1944 1945eval({string}) *eval()* 1946 Evaluate {string} and return the result. Especially useful to 1947 turn the result of |string()| back into the original value. 1948 This works for Numbers, Floats, Strings, Blobs and composites 1949 of them. Also works for |Funcref|s that refer to existing 1950 functions. 1951 1952 Parameters: ~ 1953 • {string} (`string`) 1954 1955 Return: ~ 1956 (`any`) 1957 1958eventhandler() *eventhandler()* 1959 Returns 1 when inside an event handler. That is that Vim got 1960 interrupted while waiting for the user to type a character, 1961 e.g., when dropping a file on Vim. This means interactive 1962 commands cannot be used. Otherwise zero is returned. 1963 1964 Return: ~ 1965 (`any`) 1966 1967executable({expr}) *executable()* 1968 This function checks if an executable with the name {expr} 1969 exists. {expr} must be the name of the program without any 1970 arguments. 1971 1972 executable() uses the value of $PATH and/or the normal 1973 searchpath for programs. 1974 *PATHEXT* 1975 On MS-Windows the ".exe", ".bat", etc. can optionally be 1976 included. Then the extensions in $PATHEXT are tried. Thus if 1977 "foo.exe" does not exist, "foo.exe.bat" can be found. If 1978 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot 1979 by itself can be used in $PATHEXT to try using the name 1980 without an extension. When 'shell' looks like a Unix shell, 1981 then the name is also tried without adding an extension. 1982 On MS-Windows it only checks if the file exists and is not a 1983 directory, not if it's really executable. 1984 1985 On MS-Windows an executable in the same directory as the Vim 1986 executable is always found (it's added to $PATH at |startup|). 1987 *$NoDefaultCurrentDirectoryInExePath* 1988 On MS-Windows when using cmd.exe as 'shell' an executable in 1989 Vim's current working directory is also normally found, which 1990 can be disabled by setting the 1991 `$NoDefaultCurrentDirectoryInExePath` environment variable. 1992 This variable is always set by Vim when executing external 1993 commands (e.g., via |:!|, |:make|, or |system()|) for security 1994 reasons. 1995 1996 The result is a Number: 1997 1 exists 1998 0 does not exist 1999 |exepath()| can be used to get the full path of an executable. 2000 2001 Attributes: ~ 2002 |api-fast| 2003 2004 Parameters: ~ 2005 • {expr} (`string`) 2006 2007 Return: ~ 2008 (`0|1`) 2009 2010execute({command} [, {silent}]) *execute()* 2011 Lua: Prefer |nvim_exec()| or |vim.cmd()|. 2012 2013 Execute {command} and capture its output. 2014 If {command} is a |String|, returns {command} output. 2015 If {command} is a |List|, returns concatenated outputs. 2016 Line continuations in {command} are not recognized. 2017 Examples: >vim 2018 echo execute('echon "foo"') 2019< foo >vim 2020 echo execute(['echon "foo"', 'echon "bar"']) 2021< foobar 2022 2023 The optional {silent} argument can have these values: 2024 "" no `:silent` used 2025 "silent" `:silent` used 2026 "silent!" `:silent!` used 2027 The default is "silent". Note that with "silent!", unlike 2028 `:redir`, error messages are dropped. 2029 2030 To get a list of lines use `split()` on the result: >vim 2031 execute('args')->split("\n") 2032 2033< This function is not available in the |sandbox|. 2034 Note: If nested, an outer execute() will not observe output of 2035 the inner calls. 2036 Note: Text attributes (highlights) are not captured. 2037 To execute a command in another window than the current one 2038 use `win_execute()`. 2039 2040 Parameters: ~ 2041 • {command} (`string|string[]`) 2042 • {silent} (`''|'silent'|'silent!'?`) 2043 2044 Return: ~ 2045 (`string`) 2046 2047exepath({expr}) *exepath()* 2048 Returns the full path of {expr} if it is an executable and 2049 given as a (partial or full) path or is found in $PATH. 2050 Returns empty string otherwise. 2051 If {expr} starts with "./" the |current-directory| is used. 2052 2053 Attributes: ~ 2054 |api-fast| 2055 2056 Parameters: ~ 2057 • {expr} (`string`) 2058 2059 Return: ~ 2060 (`string`) 2061 2062exists({expr}) *exists()* 2063 Checks whether the expression {expr} is defined. 2064 Returns |TRUE| if {expr} is defined, zero otherwise. 2065 2066 For checking for a supported feature use |has()|. 2067 For checking if a file exists use |filereadable()|. 2068 2069 The {expr} argument is a string, which contains one of these: 2070 varname internal variable (see 2071 dict.key |internal-variables|). Also works 2072 list[i] for |curly-braces-names|, |Dictionary| 2073 entries, |List| items, etc. 2074 Beware that evaluating an index may 2075 cause an error message for an invalid 2076 expression. E.g.: >vim 2077 let l = [1, 2, 3] 2078 echo exists("l[5]") 2079< 0 >vim 2080 echo exists("l[xx]") 2081< E121: Undefined variable: xx 2082 0 2083 &option-name Vim option (only checks if it exists, 2084 not if it really works) 2085 +option-name Vim option that works. 2086 $ENVNAME environment variable (could also be 2087 done by comparing with an empty 2088 string) 2089 `*funcname` built-in function (see |functions|) 2090 or user defined function (see 2091 |user-function|). Also works for a 2092 variable that is a Funcref. 2093 :cmdname Ex command: built-in command, user 2094 command or command modifier |:command|. 2095 Returns: 2096 1 for match with start of a command 2097 2 full match with a command 2098 3 matches several user commands 2099 To check for a supported command 2100 always check the return value to be 2. 2101 :2match The |:2match| command. 2102 :3match The |:3match| command (but you 2103 probably should not use it, it is 2104 reserved for internal usage) 2105 #event autocommand defined for this event 2106 #event#pattern autocommand defined for this event and 2107 pattern (the pattern is taken 2108 literally and compared to the 2109 autocommand patterns character by 2110 character) 2111 #group autocommand group exists 2112 #group#event autocommand defined for this group and 2113 event. 2114 #group#event#pattern 2115 autocommand defined for this group, 2116 event and pattern. 2117 ##event autocommand for this event is 2118 supported. 2119 2120 Examples: >vim 2121 echo exists("&mouse") 2122 echo exists("$HOSTNAME") 2123 echo exists("*strftime") 2124 echo exists("*s:MyFunc") 2125 echo exists("*MyFunc") 2126 echo exists("*v:lua.Func") 2127 echo exists("bufcount") 2128 echo exists(":Make") 2129 echo exists("#CursorHold") 2130 echo exists("#BufReadPre#*.gz") 2131 echo exists("#filetypeindent") 2132 echo exists("#filetypeindent#FileType") 2133 echo exists("#filetypeindent#FileType#*") 2134 echo exists("##ColorScheme") 2135< There must be no space between the symbol (&/$/*/#) and the 2136 name. 2137 There must be no extra characters after the name, although in 2138 a few cases this is ignored. That may become stricter in the 2139 future, thus don't count on it! 2140 Working example: >vim 2141 echo exists(":make") 2142< NOT working example: >vim 2143 echo exists(":make install") 2144 2145< Note that the argument must be a string, not the name of the 2146 variable itself. For example: >vim 2147 echo exists(bufcount) 2148< This doesn't check for existence of the "bufcount" variable, 2149 but gets the value of "bufcount", and checks if that exists. 2150 2151 Parameters: ~ 2152 • {expr} (`string`) 2153 2154 Return: ~ 2155 (`0|1`) 2156 2157exp({expr}) *exp()* 2158 Lua: Prefer |math.exp()|. 2159 2160 Return the exponential of {expr} as a |Float| in the range 2161 [0, inf]. 2162 {expr} must evaluate to a |Float| or a |Number|. 2163 Returns 0.0 if {expr} is not a |Float| or a |Number|. 2164 Examples: >vim 2165 echo exp(2) 2166< 7.389056 >vim 2167 echo exp(-1) 2168< 0.367879 2169 2170 Parameters: ~ 2171 • {expr} (`number`) 2172 2173 Return: ~ 2174 (`any`) 2175 2176expand({string} [, {nosuf} [, {list}]]) *expand()* 2177 Expand wildcards and the following special keywords in 2178 {string}. 'wildignorecase' applies. 2179 2180 If {list} is given and it is |TRUE|, a List will be returned. 2181 Otherwise the result is a String and when there are several 2182 matches, they are separated by <NL> characters. 2183 2184 If the expansion fails, the result is an empty string. A name 2185 for a non-existing file is not included, unless {string} does 2186 not start with '%', '#' or '<', see below. 2187 2188 When {string} starts with '%', '#' or '<', the expansion is 2189 done like for the |cmdline-special| variables with their 2190 associated modifiers. Here is a short overview: 2191 2192 % Current file name 2193 # Alternate file name 2194 #n Alternate file name n 2195 <cfile> File name under the cursor 2196 <afile> Autocmd file name 2197 <abuf> Autocmd buffer number (as a String!) 2198 <amatch> Autocmd matched name 2199 <cexpr> C expression under the cursor 2200 <sfile> Deprecated, use <script> or <stack> 2201 <slnum> Sourced script line number or function 2202 line number 2203 <sflnum> Script file line number, also when in 2204 a function 2205 <SID> "<SNR>123_" where "123" is the 2206 current script ID |<SID>| 2207 <script> Sourced script file, or script file 2208 where the current function was defined. 2209 Lua: see |lua-script-location|. 2210 <stack> Call stack 2211 <cword> Word under the cursor 2212 <cWORD> WORD under the cursor 2213 <client> The {clientid} of the last received 2214 message 2215 Modifiers: 2216 :p Expand to full path 2217 :h Head (last path component removed) 2218 :t Tail (last path component only) 2219 :r Root (one extension removed) 2220 :e Extension only 2221 2222 More modifiers are supported, for the full list see 2223 |filename-modifiers|. 2224 2225 Example: >vim 2226 let &tags = expand("%:p:h") .. "/tags" 2227< Note that when expanding a string that starts with '%', '#' or 2228 '<', any following text is ignored. This does NOT work: >vim 2229 let doesntwork = expand("%:h.bak") 2230< Use this: >vim 2231 let doeswork = expand("%:h") .. ".bak" 2232< Also note that expanding "<cfile>" and others only returns the 2233 referenced file name without further expansion. If "<cfile>" 2234 is "~/.cshrc", you need to do another expand() to have the 2235 "~/" expanded into the path of the home directory: >vim 2236 echo expand(expand("<cfile>")) 2237< 2238 There cannot be white space between the variables and the 2239 following modifier. The |fnamemodify()| function can be used 2240 to modify normal file names. 2241 2242 When using '%' or '#', and the current or alternate file name 2243 is not defined, an empty string is used. Using "%:p" in a 2244 buffer with no name, results in the current directory, with a 2245 '/' added. 2246 When 'verbose' is set then expanding '%', '#' and <> items 2247 will result in an error message if the argument cannot be 2248 expanded. 2249 2250 When {string} does not start with '%', '#' or '<', it is 2251 expanded like a file name is expanded on the command line. 2252 'suffixes' and 'wildignore' are used, unless the optional 2253 {nosuf} argument is given and it is |TRUE|. 2254 Names for non-existing files are included. The "**" item can 2255 be used to search in a directory tree. For example, to find 2256 all "README" files in the current directory and below: >vim 2257 echo expand("**/README") 2258< 2259 expand() can also be used to expand variables and environment 2260 variables that are only known in a shell. But this can be 2261 slow, because a shell may be used to do the expansion. See 2262 |expr-env-expand|. 2263 The expanded variable is still handled like a list of file 2264 names. When an environment variable cannot be expanded, it is 2265 left unchanged. Thus ":echo expand('$FOOBAR')" results in 2266 "$FOOBAR". 2267 2268 See |glob()| for finding existing files. See |system()| for 2269 getting the raw output of an external command. 2270 2271 Parameters: ~ 2272 • {string} (`string`) 2273 • {nosuf} (`boolean?`) 2274 • {list} (`nil|false?`) 2275 2276 Return: ~ 2277 (`string`) 2278 2279expandcmd({string} [, {options}]) *expandcmd()* 2280 Expand special items in String {string} like what is done for 2281 an Ex command such as `:edit`. This expands special keywords, 2282 like with |expand()|, and environment variables, anywhere in 2283 {string}. "~user" and "~/path" are only expanded at the 2284 start. 2285 The expansion is done in two steps: the special keywords are 2286 evaluated first, then "~" and environment variables are 2287 expanded in the result. Thus `expand('%:~')` keeps the "~", 2288 while `expandcmd('%:~')` returns the full path. 2289 2290 The following items are supported in the {options} Dict 2291 argument: 2292 errmsg If set to TRUE, error messages are displayed 2293 if an error is encountered during expansion. 2294 By default, error messages are not displayed. 2295 2296 Returns the expanded string. If an error is encountered 2297 during expansion, the unmodified {string} is returned. 2298 2299 Example: >vim 2300 echo expandcmd('make %<.o') 2301< > 2302 make /path/runtime/doc/builtin.o 2303< >vim 2304 echo expandcmd('make %<.o', {'errmsg': v:true}) 2305< 2306 2307 Parameters: ~ 2308 • {string} (`string`) 2309 • {options} (`table?`) 2310 2311 Return: ~ 2312 (`any`) 2313 2314extend({expr1}, {expr2} [, {expr3}]) *extend()* 2315 Lua: Prefer |vim.list_extend()| for lists, or 2316 |vim.tbl_extend()| and |vim.tbl_deep_extend()| for dicts; 2317 insertion and keep/force/error behavior differ. 2318 2319 {expr1} and {expr2} must be both |Lists| or both 2320 |Dictionaries|. 2321 2322 If they are |Lists|: Append {expr2} to {expr1}. 2323 If {expr3} is given insert the items of {expr2} before the 2324 item with index {expr3} in {expr1}. When {expr3} is zero 2325 insert before the first item. When {expr3} is equal to 2326 len({expr1}) then {expr2} is appended. 2327 Examples: >vim 2328 echo sort(extend(mylist, [7, 5])) 2329 call extend(mylist, [2, 3], 1) 2330< When {expr1} is the same List as {expr2} then the number of 2331 items copied is equal to the original length of the List. 2332 E.g., when {expr3} is 1 you get N new copies of the first item 2333 (where N is the original length of the List). 2334 Use |add()| to concatenate one item to a list. To concatenate 2335 two lists into a new list use the + operator: >vim 2336 let newlist = [1, 2, 3] + [4, 5] 2337< 2338 If they are |Dictionaries|: 2339 Add all entries from {expr2} to {expr1}. 2340 If a key exists in both {expr1} and {expr2} then {expr3} is 2341 used to decide what to do: 2342 {expr3} = "keep": keep the value of {expr1} 2343 {expr3} = "force": use the value of {expr2} 2344 {expr3} = "error": give an error message *E737* 2345 When {expr3} is omitted then "force" is assumed. 2346 2347 {expr1} is changed when {expr2} is not empty. If necessary 2348 make a copy of {expr1} first or use |extendnew()| to return a 2349 new List/Dictionary. 2350 {expr2} remains unchanged. 2351 When {expr1} is locked and {expr2} is not empty the operation 2352 fails. 2353 Returns {expr1}. Returns 0 on error. 2354 2355 Parameters: ~ 2356 • {expr1} (`table`) 2357 • {expr2} (`table`) 2358 • {expr3} (`table?`) 2359 2360 Return: ~ 2361 (`any`) 2362 2363extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()* 2364 Lua: Prefer |vim.list_extend()| on a copy for lists, or 2365 |vim.tbl_extend()| and |vim.tbl_deep_extend()| for dicts; 2366 insertion and keep/force/error behavior differ. 2367 2368 Like |extend()| but instead of adding items to {expr1} a new 2369 List or Dictionary is created and returned. {expr1} remains 2370 unchanged. 2371 2372 Parameters: ~ 2373 • {expr1} (`table`) 2374 • {expr2} (`table`) 2375 • {expr3} (`table?`) 2376 2377 Return: ~ 2378 (`any`) 2379 2380feedkeys({string} [, {mode}]) *feedkeys()* 2381 Lua: Prefer |nvim_feedkeys()|. 2382 2383 Characters in {string} are queued for processing as if they 2384 come from a mapping or were typed by the user. 2385 2386 By default the string is added to the end of the typeahead 2387 buffer, thus if a mapping is still being executed the 2388 characters come after them. Use the 'i' flag to insert before 2389 other characters, they will be executed next, before any 2390 characters from a mapping. 2391 2392 The function does not wait for processing of keys contained in 2393 {string}. 2394 2395 To include special keys into {string}, use double-quotes 2396 and "\..." notation |expr-quote|. For example, 2397 feedkeys("\<CR>") simulates pressing of the <Enter> key. But 2398 feedkeys('\<CR>') pushes 5 characters. 2399 The |<Ignore>| keycode may be used to exit the 2400 wait-for-character without doing anything. 2401 2402 {mode} is a String, which can contain these character flags: 2403 'm' Remap keys. This is default. If {mode} is absent, 2404 keys are remapped. 2405 'n' Do not remap keys. 2406 't' Handle keys as if typed; otherwise they are handled as 2407 if coming from a mapping. This matters for undo, 2408 opening folds, etc. 2409 'L' Lowlevel input. Other flags are not used. 2410 'i' Insert the string instead of appending (see above). 2411 'x' Execute commands until typeahead is empty. This is 2412 similar to using ":normal!". You can call feedkeys() 2413 several times without 'x' and then one time with 'x' 2414 (possibly with an empty {string}) to execute all the 2415 typeahead. Note that when Vim ends in Insert mode it 2416 will behave as if <Esc> is typed, to avoid getting 2417 stuck, waiting for a character to be typed before the 2418 script continues. 2419 Note that if you manage to call feedkeys() while 2420 executing commands, thus calling it recursively, then 2421 all typeahead will be consumed by the last call. 2422 '!' When used with 'x' will not end Insert mode. Can be 2423 used in a test when a timer is set to exit Insert mode 2424 a little later. Useful for testing CursorHoldI. 2425 2426 Return value is always 0. 2427 2428 Parameters: ~ 2429 • {string} (`string`) 2430 • {mode} (`string?`) 2431 2432 Return: ~ 2433 (`any`) 2434 2435filecopy({from}, {to}) *filecopy()* 2436 Lua: Prefer |uv.fs_copyfile()| with `{ excl = true }`; return 2437 semantics differ. 2438 2439 Copy the file pointed to by the name {from} to {to}. The 2440 result is a Number, which is |TRUE| if the file was copied 2441 successfully, and |FALSE| when it failed. 2442 If a file with name {to} already exists, it will fail. 2443 Note that it does not handle directories (yet). 2444 2445 This function is not available in the |sandbox|. 2446 2447 Parameters: ~ 2448 • {from} (`string`) 2449 • {to} (`string`) 2450 2451 Return: ~ 2452 (`0|1`) 2453 2454filereadable({file}) *filereadable()* 2455 Lua: Prefer |uv.fs_access()| with `"R"` and |uv.fs_stat()| to 2456 exclude directories. 2457 2458 Returns |TRUE| if {file} exists, can be read, and is not 2459 a directory, else |FALSE|. 2460 2461 {file} is any expression, which is used as a String. If you 2462 don't care about the file being readable you can use |glob()|. 2463 2464 {file} is used as-is, you may want to expand wildcards first: >vim 2465 echo filereadable('~/.vimrc') 2466< > 2467 0 2468< >vim 2469 echo filereadable(expand('~/.vimrc')) 2470< > 2471 1 2472< 2473 2474 Attributes: ~ 2475 |api-fast| 2476 2477 Parameters: ~ 2478 • {file} (`string`) 2479 2480 Return: ~ 2481 (`0|1`) 2482 2483filewritable({file}) *filewritable()* 2484 Lua: Prefer |uv.fs_access()| with `"W"` and |uv.fs_stat()| if 2485 you need Vim's `2` return for directories. 2486 2487 Checks whether a file with the name {file} exists and can 2488 be written. Returns 1 if so. If {file} doesn't exist, or 2489 is not writable, the result is 0. If {file} is a 2490 directory, and we can write to it, the result is 2. 2491 2492 Attributes: ~ 2493 |api-fast| 2494 2495 Parameters: ~ 2496 • {file} (`string`) 2497 2498 Return: ~ 2499 (`0|1`) 2500 2501filter({expr1}, {expr2}) *filter()* 2502 Lua: Prefer |vim.tbl_filter()| for lists; dicts, strings, and 2503 blobs differ. 2504 2505 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 2506 For each item in {expr1} evaluate {expr2} and when the result 2507 is zero or false remove the item from the |List| or 2508 |Dictionary|. Similarly for each byte in a |Blob| and each 2509 character in a |String|. 2510 2511 {expr2} must be a |string| or |Funcref|. 2512 2513 If {expr2} is a |string|, inside {expr2} |v:val| has the value 2514 of the current item. For a |Dictionary| |v:key| has the key 2515 of the current item and for a |List| |v:key| has the index of 2516 the current item. For a |Blob| |v:key| has the index of the 2517 current byte. For a |String| |v:key| has the index of the 2518 current character. 2519 Examples: >vim 2520 call filter(mylist, 'v:val !~ "OLD"') 2521< Removes the items where "OLD" appears. >vim 2522 call filter(mydict, 'v:key >= 8') 2523< Removes the items with a key below 8. >vim 2524 call filter(var, 0) 2525< Removes all the items, thus clears the |List| or |Dictionary|. 2526 2527 Note that {expr2} is the result of expression and is then 2528 used as an expression again. Often it is good to use a 2529 |literal-string| to avoid having to double backslashes. 2530 2531 If {expr2} is a |Funcref| it must take two arguments: 2532 1. the key or the index of the current item. 2533 2. the value of the current item. 2534 The function must return |TRUE| if the item should be kept. 2535 Example that keeps the odd items of a list: >vim 2536 func Odd(idx, val) 2537 return a:idx % 2 == 1 2538 endfunc 2539 call filter(mylist, function('Odd')) 2540< It is shorter when using a |lambda|: >vim 2541 call filter(myList, {idx, val -> idx * val <= 42}) 2542< If you do not use "val" you can leave it out: >vim 2543 call filter(myList, {idx -> idx % 2 == 1}) 2544< 2545 For a |List| and a |Dictionary| the operation is done 2546 in-place. If you want it to remain unmodified make a copy 2547 first: >vim 2548 let l = filter(copy(mylist), 'v:val =~ "KEEP"') 2549 2550< Returns {expr1}, the |List| or |Dictionary| that was filtered, 2551 or a new |Blob| or |String|. 2552 When an error is encountered while evaluating {expr2} no 2553 further items in {expr1} are processed. 2554 When {expr2} is a Funcref errors inside a function are 2555 ignored, unless it was defined with the "abort" flag. 2556 2557 Parameters: ~ 2558 • {expr1} (`string|table`) 2559 • {expr2} (`string|function`) 2560 2561 Return: ~ 2562 (`any`) 2563 2564finddir({name} [, {path} [, {count}]]) *finddir()* 2565 Lua: Prefer |vim.fs.find()| with `type = 'directory'`; `path`, 2566 `count`, and return semantics differ. 2567 2568 Find directory {name} in {path}. Supports both downwards and 2569 upwards recursive directory searches. See |file-searching| 2570 for the syntax of {path}. 2571 2572 Returns the path of the first found match. When the found 2573 directory is below the current directory a relative path is 2574 returned. Otherwise a full path is returned. 2575 If {path} is omitted or empty then 'path' is used. 2576 2577 If the optional {count} is given, find {count}'s occurrence of 2578 {name} in {path} instead of the first one. 2579 When {count} is negative return all the matches in a |List|. 2580 2581 Returns an empty string if the directory is not found. 2582 2583 This is quite similar to the ex-command `:find`. 2584 2585 Parameters: ~ 2586 • {name} (`string`) 2587 • {path} (`string?`) 2588 • {count} (`integer?`) 2589 2590 Return: ~ 2591 (`string|string[]`) 2592 2593findfile({name} [, {path} [, {count}]]) *findfile()* 2594 Lua: Prefer |vim.fs.find()|; `path`, `count`, return 2595 semantics, and |'suffixesadd'| handling differ. 2596 2597 Just like |finddir()|, but find a file instead of a directory. 2598 Uses 'suffixesadd'. 2599 Example: >vim 2600 echo findfile("tags.vim", ".;") 2601< Searches from the directory of the current file upwards until 2602 it finds the file "tags.vim". 2603 2604 Parameters: ~ 2605 • {name} (`string`) 2606 • {path} (`string?`) 2607 • {count} (`integer?`) 2608 2609 Return: ~ 2610 (`string|string[]`) 2611 2612flatten({list} [, {maxdepth}]) *flatten()* 2613 Lua: Prefer `vim.iter(list):flatten():totable()` for a new 2614 flattened list; in-place updates and `maxdepth` differ. 2615 2616 Flatten {list} up to {maxdepth} levels. Without {maxdepth} 2617 the result is a |List| without nesting, as if {maxdepth} is 2618 a very large number. 2619 The {list} is changed in place, use |flattennew()| if you do 2620 not want that. 2621 *E900* 2622 {maxdepth} means how deep in nested lists changes are made. 2623 {list} is not modified when {maxdepth} is 0. 2624 {maxdepth} must be positive number. 2625 2626 If there is an error the number zero is returned. 2627 2628 Example: >vim 2629 echo flatten([1, [2, [3, 4]], 5]) 2630< [1, 2, 3, 4, 5] >vim 2631 echo flatten([1, [2, [3, 4]], 5], 1) 2632< [1, 2, [3, 4], 5] 2633 2634 Parameters: ~ 2635 • {list} (`any[]`) 2636 • {maxdepth} (`integer?`) 2637 2638 Return: ~ 2639 (`any[]|0`) 2640 2641flattennew({list} [, {maxdepth}]) *flattennew()* 2642 Lua: Prefer `vim.iter(list):flatten():totable()` for a new 2643 flattened list; `maxdepth` differs. 2644 2645 Like |flatten()| but first make a copy of {list}. 2646 2647 Parameters: ~ 2648 • {list} (`any[]`) 2649 • {maxdepth} (`integer?`) 2650 2651 Return: ~ 2652 (`any[]|0`) 2653 2654float2nr({expr}) *float2nr()* 2655 Lua: Prefer |math.modf()| (first return value). 2656 2657 Convert {expr} to a Number by omitting the part after the 2658 decimal point. 2659 {expr} must evaluate to a |Float| or a |Number|. 2660 Returns 0 if {expr} is not a |Float| or a |Number|. 2661 When the value of {expr} is out of range for a |Number| the 2662 result is truncated to 0x7fffffff or -0x7fffffff (or when 2663 64-bit Number support is enabled, 0x7fffffffffffffff or 2664 -0x7fffffffffffffff). NaN results in -0x80000000 (or when 2665 64-bit Number support is enabled, -0x8000000000000000). 2666 Examples: >vim 2667 echo float2nr(3.95) 2668< 3 >vim 2669 echo float2nr(-23.45) 2670< -23 >vim 2671 echo float2nr(1.0e100) 2672< 2147483647 (or 9223372036854775807) >vim 2673 echo float2nr(-1.0e150) 2674< -2147483647 (or -9223372036854775807) >vim 2675 echo float2nr(1.0e-100) 2676< 0 2677 2678 Parameters: ~ 2679 • {expr} (`number`) 2680 2681 Return: ~ 2682 (`any`) 2683 2684floor({expr}) *floor()* 2685 Lua: Prefer |math.floor()|. 2686 2687 Return the largest integral value less than or equal to 2688 {expr} as a |Float| (round down). 2689 {expr} must evaluate to a |Float| or a |Number|. 2690 Returns 0.0 if {expr} is not a |Float| or a |Number|. 2691 Examples: >vim 2692 echo floor(1.856) 2693< 1.0 >vim 2694 echo floor(-5.456) 2695< -6.0 >vim 2696 echo floor(4.0) 2697< 4.0 2698 2699 Parameters: ~ 2700 • {expr} (`number`) 2701 2702 Return: ~ 2703 (`any`) 2704 2705fmod({expr1}, {expr2}) *fmod()* 2706 Lua: Prefer |math.fmod()|. 2707 2708 Return the remainder of {expr1} / {expr2}, even if the 2709 division is not representable. Returns {expr1} - i * {expr2} 2710 for some integer i such that if {expr2} is non-zero, the 2711 result has the same sign as {expr1} and magnitude less than 2712 the magnitude of {expr2}. If {expr2} is zero, the value 2713 returned is zero. The value returned is a |Float|. 2714 {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 2715 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a 2716 |Number|. 2717 Examples: >vim 2718 echo fmod(12.33, 1.22) 2719< 0.13 >vim 2720 echo fmod(-12.33, 1.22) 2721< -0.13 2722 2723 Parameters: ~ 2724 • {expr1} (`number`) 2725 • {expr2} (`number`) 2726 2727 Return: ~ 2728 (`any`) 2729 2730fnameescape({filepath}) *fnameescape()* 2731 Escapes {filepath} for use as a command argument. 2732 2733 (Note: To open a literal filepath programmatically use 2734 `bufadd(vim.fs.normalize(…))`, see |open-file|.) 2735 2736 All characters that have a special meaning, such as `'%'` and 2737 `'|'` are escaped with a backslash. For most systems the 2738 characters escaped are: > 2739 \t\n *?[{`$\\%#'\"|!< 2740< For systems where a backslash appears in a filename, it 2741 depends on the value of 'isfname'. A leading '+' and '>' is 2742 also escaped (special after |:edit| and |:write|). And a "-" 2743 by itself (special after |:cd|). 2744 Returns an empty string on error. 2745 Example: >vim 2746 let fname = '+some str%nge|name' 2747 exe "edit " .. fnameescape(fname) 2748< results in executing: >vim 2749 edit \+some\ str\%nge\|name 2750< 2751 2752 Attributes: ~ 2753 |api-fast| 2754 2755 Parameters: ~ 2756 • {filepath} (`string`) 2757 2758 Return: ~ 2759 (`string`) 2760 2761fnamemodify({fname}, {mods}) *fnamemodify()* 2762 Lua: Prefer |vim.fs.dirname()|, |vim.fs.basename()|, 2763 |vim.fs.abspath()|, and |vim.fs.normalize()| for common path 2764 modifiers; modifier coverage differs. 2765 2766 Modify file name {fname} according to {mods}. {mods} is a 2767 string of characters like it is used for file names on the 2768 command line. See |filename-modifiers|. 2769 Example: >vim 2770 echo fnamemodify("main.c", ":p:h") 2771< results in: > 2772 /home/user/vim/vim/src 2773< If {mods} is empty or an unsupported modifier is used then 2774 {fname} is returned. 2775 When {fname} is empty then with {mods} ":h" returns ".", so 2776 that `:cd` can be used with it. This is different from 2777 expand('%:h') without a buffer name, which returns an empty 2778 string. 2779 Note: Environment variables don't work in {fname}, use 2780 |expand()| first then. 2781 2782 Attributes: ~ 2783 |api-fast| 2784 2785 Parameters: ~ 2786 • {fname} (`string`) 2787 • {mods} (`string`) 2788 2789 Return: ~ 2790 (`string`) 2791 2792foldclosed({lnum}) *foldclosed()* 2793 Returns the first line number of the closed fold containing 2794 line {lnum}. If the line {lnum} is not in a closed fold, 2795 -1 is returned. 2796 {lnum} is used like with |getline()|. Thus "." is the current 2797 line, "'m" mark m, etc. 2798 2799 Parameters: ~ 2800 • {lnum} (`integer|string`) 2801 2802 Return: ~ 2803 (`integer`) 2804 2805foldclosedend({lnum}) *foldclosedend()* 2806 Returns the last line number of the closed fold containing 2807 line {lnum}. If the line {lnum} is not in a closed fold, 2808 -1 is returned. 2809 {lnum} is used like with |getline()|. Thus "." is the current 2810 line, "'m" mark m, etc. 2811 2812 Parameters: ~ 2813 • {lnum} (`integer|string`) 2814 2815 Return: ~ 2816 (`integer`) 2817 2818foldlevel({lnum}) *foldlevel()* 2819 Returns the fold nesting level of line {lnum} in the current 2820 buffer. {lnum} is used like with |getline()| ("." is the 2821 current line, "'m" mark m, etc). 2822 2823 For nested folds the deepest level is returned. If there is 2824 no fold at line {lnum}, zero is returned. It doesn't matter 2825 if the folds are open or closed. When used while updating 2826 folds (from 'foldexpr') -1 is returned for lines where folds 2827 are still to be updated and the foldlevel is unknown. As 2828 a special case the level of the previous line is usually 2829 available. 2830 2831 Parameters: ~ 2832 • {lnum} (`integer|string`) 2833 2834 Return: ~ 2835 (`integer`) 2836 2837foldtext() *foldtext()* 2838 Returns a String, to be displayed for a closed fold. This is 2839 the default function used for the 'foldtext' option and should 2840 only be called from evaluating 'foldtext'. It uses the 2841 |v:foldstart|, |v:foldend| and |v:folddashes| variables. 2842 The returned string looks like this: > 2843 +-- 45 lines: abcdef 2844< The number of leading dashes depends on the foldlevel. The 2845 "45" is the number of lines in the fold. "abcdef" is the text 2846 in the first non-blank line of the fold. Leading white space, 2847 "//" or "/*" and the text from the 'foldmarker' and 2848 'commentstring' options is removed. 2849 When used to draw the actual foldtext, the rest of the line 2850 will be filled with the fold char from the 'fillchars' 2851 setting. 2852 Returns an empty string when there is no fold. 2853 2854 Return: ~ 2855 (`string`) 2856 2857foldtextresult({lnum}) *foldtextresult()* 2858 Returns the text that is displayed for the closed fold at line 2859 {lnum}. Evaluates 'foldtext' in the appropriate context. 2860 When there is no closed fold at {lnum} an empty string is 2861 returned. 2862 {lnum} is used like with |getline()|. Thus "." is the current 2863 line, "'m" mark m, etc. 2864 Useful when exporting folded text, e.g., to HTML. 2865 2866 Parameters: ~ 2867 • {lnum} (`integer|string`) 2868 2869 Return: ~ 2870 (`string`) 2871 2872foreach({expr1}, {expr2}) *foreach()* 2873 Lua: Prefer |pairs()| or |ipairs()|. 2874 2875 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 2876 For each item in {expr1} execute {expr2}. {expr1} is not 2877 modified; its values may be, as with |:lockvar| 1. |E741| 2878 See |map()| and |filter()| to modify {expr1}. 2879 2880 {expr2} must be a |string| or |Funcref|. 2881 2882 If {expr2} is a |string|, inside {expr2} |v:val| has the value 2883 of the current item. For a |Dictionary| |v:key| has the key 2884 of the current item and for a |List| |v:key| has the index of 2885 the current item. For a |Blob| |v:key| has the index of the 2886 current byte. For a |String| |v:key| has the index of the 2887 current character. 2888 Examples: >vim 2889 call foreach(mylist, 'let used[v:val] = v:true') 2890< This records the items that are in the {expr1} list. 2891 2892 Note that {expr2} is the result of expression and is then used 2893 as a command. Often it is good to use a |literal-string| to 2894 avoid having to double backslashes. 2895 2896 If {expr2} is a |Funcref| it must take two arguments: 2897 1. the key or the index of the current item. 2898 2. the value of the current item. 2899 With a lambda you don't get an error if it only accepts one 2900 argument. 2901 If the function returns a value, it is ignored. 2902 2903 Returns {expr1} in all cases. 2904 When an error is encountered while executing {expr2} no 2905 further items in {expr1} are processed. 2906 When {expr2} is a Funcref errors inside a function are 2907 ignored, unless it was defined with the "abort" flag. 2908 2909 Parameters: ~ 2910 • {expr1} (`string|table`) 2911 • {expr2} (`string|function`) 2912 2913 Return: ~ 2914 (`string|table`) 2915 2916fullcommand({name}) *fullcommand()* 2917 Get the full command name from a short abbreviated command 2918 name; see |20.2| for details on command abbreviations. 2919 2920 The string argument {name} may start with a `:` and can 2921 include a [range], these are skipped and not returned. 2922 Returns an empty string if a command doesn't exist or if it's 2923 ambiguous (for user-defined commands). 2924 2925 Note: Command validation is not performed. Results depend on 2926 Vim's internal command-specific identification rules. 2927 Examples: 2928>vim 2929 echo [fullcommand('s')] |" ['substitute'] 2930 echo [fullcommand('sub')] |" ['substitute'] 2931 echo [fullcommand(': mark word')] |" ['mark'] 2932 echo [fullcommand(': markword')] |" [''] 2933 echo [fullcommand('en')] |" ['endif'] 2934< 2935 2936 Parameters: ~ 2937 • {name} (`string`) 2938 2939 Return: ~ 2940 (`string`) 2941 2942funcref({name} [, {arglist}] [, {dict}]) *funcref()* 2943 Just like |function()|, but the returned Funcref will lookup 2944 the function by reference, not by name. This matters when the 2945 function {name} is redefined later. 2946 2947 Unlike |function()|, {name} must be an existing user function. 2948 It only works for an autoloaded function if it has already 2949 been loaded (to avoid mistakenly loading the autoload script 2950 when only intending to use the function name, use |function()| 2951 instead). {name} cannot be a builtin function. 2952 Returns 0 on error. 2953 2954 Parameters: ~ 2955 • {name} (`string`) 2956 • {arglist} (`any?`) 2957 • {dict} (`any?`) 2958 2959 Return: ~ 2960 (`any`) 2961 2962function({name} [, {arglist}] [, {dict}]) *function()* *partial* *E700* *E923* 2963 Return a |Funcref| variable that refers to function {name}. 2964 {name} can be the name of a user defined function or an 2965 internal function. 2966 2967 {name} can also be a Funcref or a partial. When it is a 2968 partial the dict stored in it will be used and the {dict} 2969 argument is not allowed. E.g.: >vim 2970 let FuncWithArg = function(dict.Func, [arg]) 2971 let Broken = function(dict.Func, [arg], dict) 2972< 2973 When using the Funcref the function will be found by {name}, 2974 also when it was redefined later. Use |funcref()| to keep the 2975 same function. 2976 2977 When {arglist} or {dict} is present this creates a partial. 2978 That means the argument list and/or the dictionary is stored 2979 in the Funcref and will be used when the Funcref is called. 2980 2981 The arguments are passed to the function in front of other 2982 arguments, but after any argument from |method|. Example: >vim 2983 func Callback(arg1, arg2, name) 2984 "... 2985 endfunc 2986 let Partial = function('Callback', ['one', 'two']) 2987 "... 2988 call Partial('name') 2989< Invokes the function as with: >vim 2990 call Callback('one', 'two', 'name') 2991 2992< With a |method|: >vim 2993 func Callback(one, two, three) 2994 "... 2995 endfunc 2996 let Partial = function('Callback', ['two']) 2997 "... 2998 eval 'one'->Partial('three') 2999< Invokes the function as with: >vim 3000 call Callback('one', 'two', 'three') 3001 3002< The function() call can be nested to add more arguments to the 3003 Funcref. The extra arguments are appended to the list of 3004 arguments. Example: >vim 3005 func Callback(arg1, arg2, name) 3006 "... 3007 endfunc 3008 let Func = function('Callback', ['one']) 3009 let Func2 = function(Func, ['two']) 3010 "... 3011 call Func2('name') 3012< Invokes the function as with: >vim 3013 call Callback('one', 'two', 'name') 3014 3015< The Dictionary is only useful when calling a "dict" function. 3016 In that case the {dict} is passed in as "self". Example: >vim 3017 function Callback() dict 3018 echo "called for " .. self.name 3019 endfunction 3020 "... 3021 let context = {"name": "example"} 3022 let Func = function('Callback', context) 3023 "... 3024 call Func() " will echo: called for example 3025< The use of function() is not needed when there are no extra 3026 arguments, these two are equivalent, if Callback() is defined 3027 as context.Callback(): >vim 3028 let Func = function('Callback', context) 3029 let Func = context.Callback 3030 3031< The argument list and the Dictionary can be combined: >vim 3032 function Callback(arg1, count) dict 3033 "... 3034 endfunction 3035 let context = {"name": "example"} 3036 let Func = function('Callback', ['one'], context) 3037 "... 3038 call Func(500) 3039< Invokes the function as with: >vim 3040 call context.Callback('one', 500) 3041< 3042 Returns 0 on error. 3043 3044 Parameters: ~ 3045 • {name} (`string`) 3046 • {arglist} (`any?`) 3047 • {dict} (`any?`) 3048 3049 Return: ~ 3050 (`any`) 3051 3052garbagecollect([{atexit}]) *garbagecollect()* 3053 Cleanup unused |Lists| and |Dictionaries| that have circular 3054 references. 3055 3056 There is hardly ever a need to invoke this function, as it is 3057 automatically done when Vim runs out of memory or is waiting 3058 for the user to press a key after 'updatetime'. Items without 3059 circular references are always freed when they become unused. 3060 This is useful if you have deleted a very big |List| and/or 3061 |Dictionary| with circular references in a script that runs 3062 for a long time. 3063 3064 When the optional {atexit} argument is one, garbage 3065 collection will also be done when exiting Vim, if it wasn't 3066 done before. This is useful when checking for memory leaks. 3067 3068 The garbage collection is not done immediately but only when 3069 it's safe to perform. This is when waiting for the user to 3070 type a character. 3071 3072 Parameters: ~ 3073 • {atexit} (`boolean?`) 3074 3075 Return: ~ 3076 (`any`) 3077 3078get({list}, {idx} [, {default}]) *get()* *get()-list* 3079 Get item {idx} from |List| {list}. When this item is not 3080 available return {default}. Return zero when {default} is 3081 omitted. 3082 3083 Parameters: ~ 3084 • {list} (`any[]`) 3085 • {idx} (`integer`) 3086 • {default} (`any?`) 3087 3088 Return: ~ 3089 (`any`) 3090 3091get({blob}, {idx} [, {default}]) *get()-blob* 3092 Get byte {idx} from |Blob| {blob}. When this byte is not 3093 available return {default}. Return -1 when {default} is 3094 omitted. 3095 3096 Parameters: ~ 3097 • {blob} (`string`) 3098 • {idx} (`integer`) 3099 • {default} (`any?`) 3100 3101 Return: ~ 3102 (`any`) 3103 3104get({dict}, {key} [, {default}]) *get()-dict* 3105 Get item with key {key} from |Dictionary| {dict}. When this 3106 item is not available return {default}. Return zero when 3107 {default} is omitted. Useful example: >vim 3108 let val = get(g:, 'var_name', 'default') 3109< This gets the value of g:var_name if it exists, and uses 3110 "default" when it does not exist. 3111 3112 Parameters: ~ 3113 • {dict} (`table<string,any>`) 3114 • {key} (`string`) 3115 • {default} (`any?`) 3116 3117 Return: ~ 3118 (`any`) 3119 3120get({func}, {what}) *get()-func* 3121 Get item {what} from |Funcref| {func}. Possible values for 3122 {what} are: 3123 "name" The function name 3124 "func" The function 3125 "dict" The dictionary 3126 "args" The list with arguments 3127 "arity" A dictionary with information about the number of 3128 arguments accepted by the function (minus the 3129 {arglist}) with the following fields: 3130 required the number of positional arguments 3131 optional the number of optional arguments, 3132 in addition to the required ones 3133 varargs |TRUE| if the function accepts a 3134 variable number of arguments |...| 3135 3136 Note: There is no error, if the {arglist} of 3137 the Funcref contains more arguments than the 3138 Funcref expects, it's not validated. 3139 3140 Returns zero on error. 3141 3142 Parameters: ~ 3143 • {func} (`function`) 3144 • {what} (`string`) 3145 3146 Return: ~ 3147 (`any`) 3148 3149getbufinfo([{buf}]) *getbufinfo()* 3150getbufinfo([{dict}]) 3151 Get information about buffers as a List of Dictionaries. 3152 3153 Without an argument information about all the buffers is 3154 returned. 3155 3156 When the argument is a |Dictionary| only the buffers matching 3157 the specified criteria are returned. The following keys can 3158 be specified in {dict}: 3159 buflisted include only listed buffers. 3160 bufloaded include only loaded buffers. 3161 bufmodified include only modified buffers. 3162 3163 Otherwise, {buf} specifies a particular buffer to return 3164 information for. For the use of {buf}, see |bufname()| 3165 above. If the buffer is found the returned List has one item. 3166 Otherwise the result is an empty list. 3167 3168 Each returned List item is a dictionary with the following 3169 entries: 3170 bufnr Buffer number. 3171 changed TRUE if the buffer is modified. 3172 changedtick Number of changes made to the buffer. 3173 command TRUE if the buffer belongs to the 3174 command-line window |cmdwin|. 3175 hidden TRUE if the buffer is hidden. 3176 lastused Timestamp in seconds, like 3177 |localtime()|, when the buffer was 3178 last used. 3179 listed TRUE if the buffer is listed. 3180 lnum Line number used for the buffer when 3181 opened in the current window. 3182 Only valid if the buffer has been 3183 displayed in the window in the past. 3184 If you want the line number of the 3185 last known cursor position in a given 3186 window, use |line()|: >vim 3187 echo line('.', {winid}) 3188< 3189 linecount Number of lines in the buffer (only 3190 valid when loaded) 3191 loaded TRUE if the buffer is loaded. 3192 name Full path to the file in the buffer. 3193 signs List of signs placed in the buffer. 3194 Each list item is a dictionary with 3195 the following fields: 3196 id sign identifier 3197 lnum line number 3198 name sign name 3199 variables A reference to the dictionary with 3200 buffer-local variables. 3201 windows List of |window-ID|s that display this 3202 buffer 3203 3204 Examples: >vim 3205 for buf in getbufinfo() 3206 echo buf.name 3207 endfor 3208 for buf in getbufinfo({'buflisted':1}) 3209 if buf.changed 3210 " .... 3211 endif 3212 endfor 3213< 3214 To get buffer-local options use: >vim 3215 getbufvar({bufnr}, '&option_name') 3216< 3217 3218 Parameters: ~ 3219 • {dict} (`vim.fn.getbufinfo.dict?`) 3220 3221 Return: ~ 3222 (`vim.fn.getbufinfo.ret.item[]`) 3223 3224getbufline({buf}, {lnum} [, {end}]) *getbufline()* 3225 Lua: Prefer |nvim_buf_get_lines()|. 3226 3227 Return a |List| with the lines starting from {lnum} to {end} 3228 (inclusive) in the buffer {buf}. If {end} is omitted, a 3229 |List| with only the line {lnum} is returned. See 3230 `getbufoneline()` for only getting the line. 3231 3232 For the use of {buf}, see |bufname()| above. 3233 3234 For {lnum} and {end} "$" can be used for the last line of the 3235 buffer. Otherwise a number must be used. 3236 3237 When {lnum} is smaller than 1 or bigger than the number of 3238 lines in the buffer, an empty |List| is returned. 3239 3240 When {end} is greater than the number of lines in the buffer, 3241 it is treated as {end} is set to the number of lines in the 3242 buffer. When {end} is before {lnum} an empty |List| is 3243 returned. 3244 3245 This function works only for loaded buffers. For unloaded and 3246 non-existing buffers, an empty |List| is returned. 3247 3248 Example: >vim 3249 let lines = getbufline(bufnr("myfile"), 1, "$") 3250< 3251 3252 Parameters: ~ 3253 • {buf} (`integer|string`) 3254 • {lnum} (`integer`) 3255 • {end} (`integer?`) 3256 3257 Return: ~ 3258 (`string[]`) 3259 3260getbufoneline({buf}, {lnum}) *getbufoneline()* 3261 Lua: Prefer |nvim_buf_get_lines()|. 3262 3263 Just like `getbufline()` but only get one line and return it 3264 as a string. 3265 3266 Parameters: ~ 3267 • {buf} (`integer|string`) 3268 • {lnum} (`integer`) 3269 3270 Return: ~ 3271 (`string`) 3272 3273getbufvar({buf}, {varname} [, {def}]) *getbufvar()* 3274 Lua: Prefer |nvim_buf_get_var()| or |vim.b| after resolving 3275 {buf} to a bufnr; option names use |nvim_get_option_value()| 3276 or |vim.bo|. 3277 3278 Gets the value of a buffer-local variable or option {varname} 3279 in buffer {buf}. 3280 3281 {varname} is a string: 3282 - Name of the variable (without "b:"). 3283 - If empty, gets a |Dictionary| of all buffer-local variables. 3284 - If "&", gets a |Dictionary| of all buffer-local options. 3285 - If it starts with "&", gets the value of a buffer-local 3286 option. 3287 3288 {buf} has the same form as in |bufname()|. 3289 3290 Also works for a global or buffer-local option. But not for 3291 a global variable, window-local variable or window-local 3292 option. 3293 3294 When the buffer or variable doesn't exist, {def} or an empty 3295 string is returned; there is no error. 3296 3297 Examples: >vim 3298 let bufmodified = getbufvar(1, "&mod") 3299 echo "todo myvar = " .. getbufvar("todo", "myvar") 3300< 3301 3302 Parameters: ~ 3303 • {buf} (`integer|string`) 3304 • {varname} (`string`) 3305 • {def} (`any?`) 3306 3307 Return: ~ 3308 (`any`) 3309 3310getcellwidths() *getcellwidths()* 3311 Returns a |List| of cell widths of character ranges overridden 3312 by |setcellwidths()|. The format is equal to the argument of 3313 |setcellwidths()|. If no character ranges have their cell 3314 widths overridden, an empty List is returned. 3315 3316 Return: ~ 3317 (`any`) 3318 3319getchangelist([{buf}]) *getchangelist()* 3320 Returns the |changelist| for the buffer {buf}. For the use 3321 of {buf}, see |bufname()| above. If buffer {buf} doesn't 3322 exist, an empty list is returned. 3323 3324 The returned list contains two entries: a list with the change 3325 locations and the current position in the list. Each 3326 entry in the change list is a dictionary with the following 3327 entries: 3328 col column number 3329 coladd column offset for 'virtualedit' 3330 lnum line number 3331 If buffer {buf} is the current buffer, then the current 3332 position refers to the position in the list. For other 3333 buffers, it is set to the length of the list. 3334 3335 Parameters: ~ 3336 • {buf} (`integer|string?`) 3337 3338 Return: ~ 3339 (`table[]`) 3340 3341getchar([{expr} [, {opts}]]) *getchar()* 3342 Get a single character from the user or input stream. 3343 If {expr} is omitted or is -1, wait until a character is 3344 available. 3345 If {expr} is 0, only get a character when one is available. 3346 Return zero otherwise. 3347 If {expr} is 1, only check if a character is available, it is 3348 not consumed. Return zero if no character available. 3349 To always get a string, specify "number" as |FALSE| in {opts}. 3350 3351 Without {expr} and when {expr} is 0 a whole character or 3352 special key is returned. If it is a single character, the 3353 result is a Number. Use |nr2char()| to convert it to a String. 3354 Otherwise a String is returned with the encoded character. 3355 For a special key it's a String with a sequence of bytes 3356 starting with 0x80 (decimal: 128). This is the same value as 3357 the String "\<Key>", e.g., "\<Left>". The returned value is 3358 also a String when a modifier (shift, control, alt) was used 3359 that is not included in the character. |keytrans()| can also 3360 be used to convert a returned String into a readable form. 3361 3362 When {expr} is 0 and Esc is typed, there will be a short delay 3363 while Vim waits to see if this is the start of an escape 3364 sequence. 3365 3366 When {expr} is 1 only the first byte is returned. For a 3367 one-byte character it is the character itself as a number. 3368 Use |nr2char()| to convert it to a String. 3369 3370 Use |getcharmod()| to obtain any additional modifiers. 3371 3372 The optional argument {opts} is a Dict and supports the 3373 following items: 3374 3375 cursor A String specifying cursor behavior 3376 when waiting for a character. 3377 "hide": hide the cursor. 3378 "keep": keep current cursor unchanged. 3379 "msg": move cursor to message area. 3380 (default: automagically decide 3381 between "keep" and "msg") 3382 3383 number If |TRUE|, return a Number when getting 3384 a single character. 3385 If |FALSE|, the return value is always 3386 converted to a String, and an empty 3387 String (instead of 0) is returned when 3388 no character is available. 3389 (default: |TRUE|) 3390 3391 simplify If |TRUE|, include modifiers in the 3392 character if possible. E.g., return 3393 the same value for CTRL-I and <Tab>. 3394 If |FALSE|, don't include modifiers in 3395 the character. 3396 (default: |TRUE|) 3397 3398 When the user clicks a mouse button, the mouse event will be 3399 returned. The position can then be found in |v:mouse_col|, 3400 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. 3401 |getmousepos()| can also be used. Mouse move events will be 3402 ignored. 3403 This example positions the mouse as it would normally happen: >vim 3404 let c = getchar() 3405 if c == "\<LeftMouse>" && v:mouse_win > 0 3406 exe v:mouse_win .. "wincmd w" 3407 exe v:mouse_lnum 3408 exe "normal " .. v:mouse_col .. "|" 3409 endif 3410< 3411 There is no prompt, you will somehow have to make clear to the 3412 user that a character has to be typed. The screen is not 3413 redrawn, e.g. when resizing the window. 3414 3415 There is no mapping for the character. 3416 Key codes are replaced, thus when the user presses the <Del> 3417 key you get the code for the <Del> key, not the raw character 3418 sequence. Examples: >vim 3419 getchar() == "\<Del>" 3420 getchar() == "\<S-Left>" 3421< This example redefines "f" to ignore case: >vim 3422 nmap f :call FindChar()<CR> 3423 function FindChar() 3424 let c = nr2char(getchar()) 3425 while col('.') < col('$') - 1 3426 normal l 3427 if getline('.')[col('.') - 1] ==? c 3428 break 3429 endif 3430 endwhile 3431 endfunction 3432< 3433 3434 Parameters: ~ 3435 • {expr} (`-1|0|1?`) 3436 • {opts} (`table?`) 3437 3438 Return: ~ 3439 (`integer|string`) 3440 3441getcharmod() *getcharmod()* 3442 Returns the state of the keyboard modifiers for the last 3443 character obtained with |getchar()| or in another way. 3444 These values are added together: 3445 2 shift 3446 4 control 3447 8 alt (meta) 3448 16 meta (when it's different from ALT) 3449 32 mouse double click 3450 64 mouse triple click 3451 96 mouse quadruple click (== 32 + 64) 3452 128 command (Mac) or super 3453 Only the modifiers that have not been included in the 3454 character itself are obtained. Thus Shift-a results in "A" 3455 without a modifier. Returns 0 if no modifiers are used. 3456 3457 Return: ~ 3458 (`integer`) 3459 3460getcharpos({expr}) *getcharpos()* 3461 Same as |getpos()|, except the column-number is 3462 character-indexed (UTF-8) instead of byte-indexed. 3463 3464 If |getpos()| returns |v:maxcol|, then getcharpos() returns 3465 the index of the last character. 3466 3467 Example: 3468 With the cursor on '세' in line 5 with text "여보세요": >vim 3469 getcharpos('.') returns [0, 5, 3, 0] 3470 getpos('.') returns [0, 5, 7, 0] 3471< 3472 3473 Parameters: ~ 3474 • {expr} (`string`) 3475 3476 Return: ~ 3477 (`integer[]`) 3478 3479getcharsearch() *getcharsearch()* 3480 Return the current character search information as a {dict} 3481 with the following entries: 3482 3483 char character previously used for a character 3484 search (|t|, |f|, |T|, or |F|); empty string 3485 if no character search has been performed 3486 forward direction of character search; 1 for forward, 3487 0 for backward 3488 until type of character search; 1 for a |t| or |T| 3489 character search, 0 for an |f| or |F| 3490 character search 3491 3492 This can be useful to always have |;| and |,| search 3493 forward/backward regardless of the direction of the previous 3494 character search: >vim 3495 nnoremap <expr> ; getcharsearch().forward ? ';' : ',' 3496 nnoremap <expr> , getcharsearch().forward ? ',' : ';' 3497< Also see |setcharsearch()|. 3498 3499 Return: ~ 3500 (`{ char: string, forward: 1|0, until: 1|0 }`) 3501 3502getcharstr([{expr} [, {opts}]]) *getcharstr()* 3503 The same as |getchar()|, except that this always returns a 3504 String, and "number" isn't allowed in {opts}. 3505 3506 Parameters: ~ 3507 • {expr} (`-1|0|1?`) 3508 • {opts} (`table?`) 3509 3510 Return: ~ 3511 (`string`) 3512 3513getcmdcomplpat() *getcmdcomplpat()* 3514 Return completion pattern of the current command-line. 3515 Only works when the command line is being edited, thus 3516 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3517 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3518 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|. 3519 Returns an empty string when completion is not defined. 3520 3521 Return: ~ 3522 (`string`) 3523 3524getcmdcompltype() *getcmdcompltype()* 3525 Return the type of the current command-line completion. 3526 Only works when the command line is being edited, thus 3527 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3528 See |:command-completion| for the return string. 3529 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3530 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|. 3531 Returns an empty string when completion is not defined. 3532 3533 To get the type of the command-line completion for a specified 3534 string, use |getcompletiontype()|. 3535 3536 Return: ~ 3537 (`string`) 3538 3539getcmdline() *getcmdline()* 3540 Return the current command-line input. Only works when the 3541 command line is being edited, thus requires use of 3542 |c_CTRL-\_e| or |c_CTRL-R_=|. 3543 Example: >vim 3544 cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> 3545< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|, 3546 |getcmdprompt()| and |setcmdline()|. 3547 Returns an empty string when entering a password or using 3548 |inputsecret()|. 3549 3550 Return: ~ 3551 (`string`) 3552 3553getcmdpos() *getcmdpos()* 3554 Return the position of the cursor in the command line as a 3555 byte count. The first column is 1. 3556 Only works when editing the command line, thus requires use of 3557 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3558 Returns 0 otherwise. 3559 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3560 |getcmdprompt()| and |setcmdline()|. 3561 3562 Return: ~ 3563 (`integer`) 3564 3565getcmdprompt() *getcmdprompt()* 3566 Return the current command-line prompt when using functions 3567 like |input()| or |confirm()|. 3568 Only works when the command line is being edited, thus 3569 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3570 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|, 3571 |setcmdpos()| and |setcmdline()|. 3572 3573 Return: ~ 3574 (`string`) 3575 3576getcmdscreenpos() *getcmdscreenpos()* 3577 Return the screen position of the cursor in the command line 3578 as a byte count. The first column is 1. 3579 Instead of |getcmdpos()|, it adds the prompt position. 3580 Only works when editing the command line, thus requires use of 3581 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3582 Returns 0 otherwise. 3583 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and 3584 |setcmdline()|. 3585 3586 Return: ~ 3587 (`integer`) 3588 3589getcmdtype() *getcmdtype()* 3590 Return the current command-line type. Possible return values 3591 are: 3592 : normal Ex command 3593 > debug mode command |debug-mode| 3594 / forward search command 3595 ? backward search command 3596 @ |input()| command 3597 `-` |:insert| or |:append| command 3598 = |i_CTRL-R_=| 3599 Only works when editing the command line, thus requires use of 3600 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3601 Returns an empty string otherwise. 3602 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|. 3603 3604 Return: ~ 3605 (`':'|'>'|'/'|'?'|'@'|'-'|'='|''`) 3606 3607getcmdwintype() *getcmdwintype()* 3608 Return the current |command-line-window| type. Possible return 3609 values are the same as |getcmdtype()|. Returns an empty string 3610 when not in the command-line window. 3611 3612 Return: ~ 3613 (`':'|'>'|'/'|'?'|'@'|'-'|'='|''`) 3614 3615getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* 3616 Return a list of command-line completion matches. The String 3617 {type} argument specifies what for. The following completion 3618 types are supported: 3619 3620 arglist file names in argument list 3621 augroup autocmd groups 3622 buffer buffer names 3623 breakpoint |:breakadd| and |:breakdel| suboptions 3624 cmdline |cmdline-completion| result 3625 color color schemes 3626 command Ex command 3627 compiler compilers 3628 custom,{func} custom completion, defined via {func} 3629 customlist,{func} custom completion, defined via {func} 3630 diff_buffer |:diffget| and |:diffput| completion 3631 dir directory names 3632 dir_in_path directory names in 'cdpath' 3633 environment environment variable names 3634 event autocommand events 3635 expression Vim expression 3636 file file and directory names 3637 file_in_path file and directory names in 'path' 3638 filetype filetype names 'filetype' 3639 filetypecmd |:filetype| suboptions 3640 function function name 3641 help help subjects 3642 highlight highlight groups 3643 history |:history| suboptions 3644 keymap keyboard mappings 3645 locale locale names (as output of locale -a) 3646 mapclear buffer argument 3647 mapping mapping name 3648 menu menus 3649 messages |:messages| suboptions 3650 option options 3651 packadd optional package |pack-add| names 3652 retab |:retab| suboptions 3653 runtime |:runtime| completion 3654 scriptnames sourced script names |:scriptnames| 3655 shellcmd Shell command 3656 shellcmdline Shell command line with filename arguments 3657 sign |:sign| suboptions 3658 syntax syntax file names 'syntax' 3659 syntime |:syntime| suboptions 3660 tag tags 3661 tag_listfiles tags, file names 3662 user user names 3663 var user variables 3664 3665 If {pat} is an empty string, then all the matches are 3666 returned. Otherwise only items matching {pat} are returned. 3667 See |wildcards| for the use of special characters in {pat}. 3668 3669 If the optional {filtered} flag is set to 1, then 'wildignore' 3670 is applied to filter the results. Otherwise all the matches 3671 are returned. The 'wildignorecase' option always applies. 3672 3673 If the 'wildoptions' option contains "fuzzy", then fuzzy 3674 matching is used to get the completion matches. Otherwise 3675 regular expression matching is used. Thus this function 3676 follows the user preference, what happens on the command line. 3677 If you do not want this you can make 'wildoptions' empty 3678 before calling getcompletion() and restore it afterwards. 3679 3680 If {type} is "cmdline", then the |cmdline-completion| result is 3681 returned. For example, to complete the possible values after 3682 a ":call" command: >vim 3683 echo getcompletion('call ', 'cmdline') 3684< 3685 If there are no matches, an empty list is returned. An 3686 invalid value for {type} produces an error. 3687 3688 Parameters: ~ 3689 • {pat} (`string`) 3690 • {type} (`string`) 3691 • {filtered} (`boolean?`) 3692 3693 Return: ~ 3694 (`string[]`) 3695 3696getcompletiontype({pat}) *getcompletiontype()* 3697 Return the type of the command-line completion using {pat}. 3698 When no corresponding completion type is found, an empty 3699 string is returned. 3700 To get the current command-line completion type, use 3701 |getcmdcompltype()|. 3702 3703 Parameters: ~ 3704 • {pat} (`string`) 3705 3706 Return: ~ 3707 (`string`) 3708 3709getcurpos([{winid}]) *getcurpos()* 3710 Lua: Prefer |nvim_win_get_cursor()|; return shape, 0-based 3711 column, and `curswant`/invalid-window semantics differ. 3712 3713 Get the position of the cursor. This is like getpos('.'), but 3714 includes an extra "curswant" item in the list: 3715 [0, lnum, col, off, curswant] ~ 3716 The "curswant" number is the preferred column when moving the 3717 cursor vertically. After |$| command it will be a very large 3718 number equal to |v:maxcol|. Also see |getcursorcharpos()| and 3719 |getpos()|. 3720 The first "bufnum" item is always zero. The byte position of 3721 the cursor is returned in "col". To get the character 3722 position, use |getcursorcharpos()|. 3723 3724 The optional {winid} (|window-number| or |window-ID|) specifies 3725 the window. The last known cursor position is returned, this 3726 may be invalid for the current value of the buffer if it is not 3727 the current window. 3728 If {winid} is invalid a list with zeroes is returned. 3729 3730 This can be used to save and restore the cursor position: >vim 3731 let save_cursor = getcurpos() 3732 MoveTheCursorAround 3733 call setpos('.', save_cursor) 3734< Note that this only works within the window. See 3735 |winrestview()| for restoring more state. 3736 3737 Parameters: ~ 3738 • {winid} (`integer?`) 3739 3740 Return: ~ 3741 (`[integer, integer, integer, integer, integer]`) 3742 3743getcursorcharpos([{winid}]) *getcursorcharpos()* 3744 Same as |getcurpos()| but the column number in the returned 3745 List is a character index instead of a byte index. 3746 3747 Example: 3748 With the cursor on '보' in line 3 with text "여보세요": >vim 3749 getcursorcharpos() " returns [0, 3, 2, 0, 3] 3750 getcurpos() " returns [0, 3, 4, 0, 3] 3751< 3752 3753 Parameters: ~ 3754 • {winid} (`integer?`) 3755 3756 Return: ~ 3757 (`any`) 3758 3759 *getcwd()* *E5000* *E5002* *E5006* *E5007* 3760getcwd([{winnr} [, {tabnr} [, {bufnr}]]]) 3761 Without arguments, returns the effective |current-directory|. 3762 With {winnr} (|window-number| or |window-ID|), {tabnr} or 3763 {bufnr} the working directory of that scope is returned, 3764 ignoring 'autochdir'. 3765 3766 - If {winnr} is -1: gets the tabpage directory. 3767 - If {winnr} and {tabnr} are both -1: gets the global 3768 directory. 3769 - Note: Vim returns an empty string when {tabnr} is -1. 3770 - If {bufnr} is given: gets the buffer-local directory. 3771 ({winnr} and {tabnr} must be -1.) 3772 - An argument may be -1 only if preceding args are -1. *E5001* 3773 3774 Tabs, windows and buffers are identified by their respective 3775 numbers, 0 means current tab/window/buffer. Missing {tabnr} 3776 implies 0 (missing {bufnr} does not; see below). Thus the 3777 following are equivalent: >vim 3778 getcwd(0) 3779 getcwd(0, 0) 3780< 3781 Each form reports its own scope or "wider", so e.g. {winnr} 3782 never reports a buffer-local directory. The {bufnr} form 3783 falls back to the global directory, because a buffer belongs 3784 to no particular window or tabpage. 3785 3786 Examples: >vim 3787 getcwd(-1, -1, 0) " Get current buffer's directory 3788 getcwd(-1, -1, 3) " Get directory of buffer 3 3789 getcwd(-1, -1, -1) " Get global directory 3790 getcwd(-1, -1) " Get global directory 3791< 3792 3793 Parameters: ~ 3794 • {winnr} (`integer?`) 3795 • {tabnr} (`integer?`) 3796 • {bufnr} (`integer?`) 3797 3798 Return: ~ 3799 (`string`) 3800 3801getenv({name}) *getenv()* 3802 Lua: Prefer |vim.env|. 3803 3804 Return the value of environment variable {name}. The {name} 3805 argument is a string, without a leading '$'. Example: >vim 3806 myHome = getenv('HOME') 3807 3808< When the variable does not exist |v:null| is returned. That 3809 is different from a variable set to an empty string. 3810 See also |expr-env|. 3811 3812 Parameters: ~ 3813 • {name} (`string`) 3814 3815 Return: ~ 3816 (`string`) 3817 3818getfontname([{name}]) *getfontname()* 3819 Without an argument returns the name of the normal font being 3820 used. Like what is used for the Normal highlight group 3821 |hl-Normal|. 3822 With an argument a check is done whether String {name} is a 3823 valid font name. If not then an empty string is returned. 3824 Otherwise the actual font name is returned, or {name} if the 3825 GUI does not support obtaining the real name. 3826 Only works when the GUI is running, thus not in your vimrc or 3827 gvimrc file. Use the |GUIEnter| autocommand to use this 3828 function just after the GUI has started. 3829 3830 Parameters: ~ 3831 • {name} (`string?`) 3832 3833 Return: ~ 3834 (`string`) 3835 3836getfperm({fname}) *getfperm()* 3837 Lua: Prefer |uv.fs_stat()|. 3838 3839 Returns the file permissions of the given file {fname} as a 3840 String. If {fname} does not exist or its directory cannot be 3841 read, an empty string is returned. 3842 The result is of the form "rwxrwxrwx", where each group of 3843 "rwx" flags represent, in turn, the permissions of the owner 3844 of the file, the group the file belongs to, and other users. 3845 If a user does not have a given permission the flag for this 3846 is replaced with the string "-". Examples: >vim 3847 echo getfperm("/etc/passwd") 3848 echo getfperm(expand("~/.config/nvim/init.vim")) 3849< This will hopefully (from a security point of view) display 3850 the string "rw-r--r--" or even "rw-------". 3851 3852 For setting permissions use |setfperm()|. 3853 3854 Attributes: ~ 3855 |api-fast| 3856 3857 Parameters: ~ 3858 • {fname} (`string`) 3859 3860 Return: ~ 3861 (`string`) 3862 3863getfsize({fname}) *getfsize()* 3864 Lua: Prefer |uv.fs_stat()|. 3865 3866 Returns the size in bytes of the given file {fname}. 3867 If {fname} is a directory, 0 is returned. 3868 If the file {fname} can't be found, -1 is returned. 3869 If the size of {fname} is too big to fit in a Number then -2 3870 is returned. 3871 3872 Attributes: ~ 3873 |api-fast| 3874 3875 Parameters: ~ 3876 • {fname} (`string`) 3877 3878 Return: ~ 3879 (`integer`) 3880 3881getftime({fname}) *getftime()* 3882 Lua: Prefer |uv.fs_stat()|. 3883 3884 Returns the last modification time ("mtime") of file {fname}. 3885 The value is measured as seconds since 1st Jan 1970, and may 3886 be passed to |strftime()|. See also 3887 |localtime()| and |strftime()|. 3888 If the file {fname} can't be found -1 is returned. 3889 3890 Attributes: ~ 3891 |api-fast| 3892 3893 Parameters: ~ 3894 • {fname} (`string`) 3895 3896 Return: ~ 3897 (`integer`) 3898 3899getftype({fname}) *getftype()* 3900 Lua: Prefer |uv.fs_stat()|. 3901 3902 Returns a description of the type of file {fname} as a 3903 String. If {fname} does not exist an empty string is 3904 returned. 3905 Here is a table over different kinds of files and their 3906 results: 3907 Normal file "file" 3908 Directory "dir" 3909 Symbolic link "link" 3910 Block device "bdev" 3911 Character device "cdev" 3912 Socket "socket" 3913 FIFO "fifo" 3914 All other "other" 3915 Example: >vim 3916 getftype("/home") 3917< Note that a type such as "link" will only be returned on 3918 systems that support it. On some systems only "dir" and 3919 "file" are returned. 3920 3921 Attributes: ~ 3922 |api-fast| 3923 3924 Parameters: ~ 3925 • {fname} (`string`) 3926 3927 Return: ~ 3928 (`'file'|'dir'|'link'|'bdev'|'cdev'|'socket'|'fifo'|'other'`) 3929 3930getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* 3931 Lua: Prefer |nvim_get_context()| for current jump history; 3932 window/tab arguments and return shape differ. 3933 3934 Returns the |jumplist| for the specified window. 3935 3936 Without arguments use the current window. 3937 With {winnr} (|window-number| or |window-ID|) only use this 3938 window in the current tabpage. 3939 With {winnr} and {tabnr} use the window in the specified tab 3940 page. If {winnr} or {tabnr} is invalid, an empty list is 3941 returned. 3942 3943 The returned list contains two entries: a list with the jump 3944 locations and the last used jump position number in the list. 3945 Each entry in the jump location list is a dictionary with 3946 the following entries: 3947 bufnr buffer number 3948 col column number 3949 coladd column offset for 'virtualedit' 3950 filename filename if available 3951 lnum line number 3952 3953 Parameters: ~ 3954 • {winnr} (`integer?`) 3955 • {tabnr} (`integer?`) 3956 3957 Return: ~ 3958 (`vim.fn.getjumplist.ret`) 3959 3960getline({lnum}) *getline()* 3961 Lua: Prefer |nvim_get_current_line()| or 3962 |nvim_buf_get_lines()|. 3963 3964 Without {end} the result is a String, which is line {lnum} 3965 from the current buffer. Example: >vim 3966 getline(1) 3967< When {lnum} is a String that doesn't start with a 3968 digit, |line()| is called to translate the String into a Number. 3969 To get the line under the cursor: >vim 3970 getline(".") 3971< When {lnum} is a number smaller than 1 or bigger than the 3972 number of lines in the buffer, an empty string is returned. 3973 3974 Parameters: ~ 3975 • {lnum} (`integer|string`) 3976 3977 Return: ~ 3978 (`string`) 3979 3980getline({lnum}, {end}) 3981 Lua: Prefer |nvim_buf_get_lines()|. 3982 3983 When {end} is given the result is a |List| where each item is 3984 a line from the current buffer in the range {lnum} to {end}, 3985 including line {end}. 3986 {end} is used in the same way as {lnum}. 3987 Non-existing lines are silently omitted. 3988 When {end} is before {lnum} an empty |List| is returned. 3989 Example: >vim 3990 let start = line('.') 3991 let end = search("^$") - 1 3992 let lines = getline(start, end) 3993 3994< To get lines from another buffer see |getbufline()| and 3995 |getbufoneline()| 3996 3997 Parameters: ~ 3998 • {lnum} (`integer|string`) 3999 • {end} (`integer|string`) 4000 4001 Return: ~ 4002 (`string[]`) 4003 4004getloclist({nr}) *getloclist()* 4005 Returns a |List| with all the entries in the location list for 4006 window {nr} (|window-number| or |window-ID|). 4007 When {nr} is zero the current window is used. 4008 4009 For a location list window, the displayed location list is 4010 returned. For an invalid {nr}, an empty list is returned. 4011 Otherwise, same as |getqflist()|. 4012 4013 Parameters: ~ 4014 • {nr} (`integer`) 4015 4016 Return: ~ 4017 (`vim.fn.getqflist.ret.item[]`) 4018 4019getloclist({nr}, {what}) 4020 If the optional {what} dictionary argument is supplied, then 4021 returns the items listed in {what} as a dictionary. Refer to 4022 |getqflist()| for the supported items in {what}. 4023 4024 In addition to the items supported by |getqflist()| in {what}, 4025 the following item is supported by |getloclist()|: 4026 4027 filewinid id of the window used to display files 4028 from the location list. This field is 4029 applicable only when called from a 4030 location list window. See 4031 |location-list-file-window| for more 4032 details. 4033 4034 Returns a |Dictionary| with default values if there is no 4035 location list for the window {nr}. 4036 Returns an empty Dictionary if window {nr} does not exist. 4037 4038 Examples (See also |getqflist-examples|): >vim 4039 echo getloclist(3, {'all': 0}) 4040 echo getloclist(5, {'filewinid': 0}) 4041< 4042 4043 Parameters: ~ 4044 • {nr} (`integer`) 4045 • {what} (`vim.fn.getloclist.what`) 4046 4047 Return: ~ 4048 (`vim.fn.getloclist.ret`) 4049 4050getmarklist([{buf}]) *getmarklist()* 4051 Without the {buf} argument returns a |List| with information 4052 about all the global marks. |mark| 4053 4054 If the optional {buf} argument is specified, returns the 4055 local marks defined in buffer {buf}. For the use of {buf}, 4056 see |bufname()|. If {buf} is invalid, an empty list is 4057 returned. For a |prompt-buffer| the result includes the 4058 |':| mark. 4059 4060 Each item in the returned List is a |Dict| with the following: 4061 mark name of the mark prefixed by "'" 4062 pos a |List| with the position of the mark: 4063 [bufnum, lnum, col, off] 4064 Refer to |getpos()| for more information. 4065 file file name 4066 4067 Refer to |getpos()| for getting information about a specific 4068 mark. 4069 4070 Parameters: ~ 4071 • {buf} (`integer??`) 4072 4073 Return: ~ 4074 (`vim.fn.getmarklist.ret.item[]`) 4075 4076getmatches([{win}]) *getmatches()* 4077 Returns a |List| with all matches previously defined for the 4078 current window by |matchadd()| and the |:match| commands. 4079 |getmatches()| is useful in combination with |setmatches()|, 4080 as |setmatches()| can restore a list of matches saved by 4081 |getmatches()|. 4082 If {win} is specified, use this |window-number| or |window-ID| 4083 instead of the current window. If {win} is invalid, an empty 4084 list is returned. 4085 Example: >vim 4086 echo getmatches() 4087< > 4088 [{"group": "MyGroup1", "pattern": "TODO", 4089 "priority": 10, "id": 1}, {"group": "MyGroup2", 4090 "pattern": "FIXME", "priority": 10, "id": 2}] 4091< >vim 4092 let m = getmatches() 4093 call clearmatches() 4094 echo getmatches() 4095< > 4096 [] 4097< >vim 4098 call setmatches(m) 4099 echo getmatches() 4100< > 4101 [{"group": "MyGroup1", "pattern": "TODO", 4102 "priority": 10, "id": 1}, {"group": "MyGroup2", 4103 "pattern": "FIXME", "priority": 10, "id": 2}] 4104< >vim 4105 unlet m 4106< 4107 4108 Parameters: ~ 4109 • {win} (`integer?`) 4110 4111 Return: ~ 4112 (`vim.fn.getmatches.ret.item[]`) 4113 4114getmousepos() *getmousepos()* 4115 Returns a |Dictionary| with the last known position of the 4116 mouse. This can be used in a mapping for a mouse click. The 4117 items are: 4118 screenrow screen row 4119 screencol screen column 4120 winid Window ID of the click 4121 winrow row inside "winid" 4122 wincol column inside "winid" 4123 line text line inside "winid" 4124 column text column inside "winid" 4125 coladd offset (in screen columns) from the 4126 start of the clicked char 4127 All numbers are 1-based. 4128 4129 If not over a window, e.g. when in the command line, then only 4130 "screenrow" and "screencol" are valid, the others are zero. 4131 4132 When on the status line below a window or the vertical 4133 separator right of a window, the "line" and "column" values 4134 are zero. 4135 4136 When the position is after the text then "column" is the 4137 length of the text in bytes plus one. 4138 4139 If the mouse is over a focusable floating window then that 4140 window is used. 4141 4142 When using |getchar()| the Vim variables |v:mouse_lnum|, 4143 |v:mouse_col| and |v:mouse_winid| also provide these values. 4144 4145 Return: ~ 4146 (`vim.fn.getmousepos.ret`) 4147 4148getpid() *getpid()* 4149 Lua: Prefer |uv.os_getpid()|. 4150 4151 Return a Number which is the process ID of the Vim process. 4152 This is a unique number, until Vim exits. 4153 4154 Attributes: ~ 4155 |api-fast| 4156 4157 Return: ~ 4158 (`integer`) 4159 4160getpos({expr}) *getpos()* 4161 Lua: Prefer |nvim_win_get_cursor()| for "." or 4162 |nvim_buf_get_mark()| for marks; return shape, `off`, and 4163 special-position semantics differ. 4164 4165 Gets a position, where {expr} is one of: 4166 . Cursor position. 4167 $ Last line in the current buffer. 4168 'x Position of mark x (if the mark is not set, 0 is 4169 returned for all values). 4170 w0 First line visible in current window (one if the 4171 display isn't updated, e.g. in |silent-mode|). 4172 w$ Last line visible in current window (this is one 4173 less than "w0" if no lines are visible). 4174 v End of the current Visual selection (unlike |'<| 4175 |'>| which give the previous, not current, Visual 4176 selection), or the cursor position if not in Visual 4177 mode. 4178 4179 To get the current selected region: >vim 4180 let region = getregionpos(getpos('v'), getpos('.')) 4181< 4182 Explanation: in Visual mode "v" and "." complement each 4183 other. While "." refers to the cursor position, "v" 4184 refers to where |v_o| would move the cursor. So you can 4185 use "v" and "." together to get the selected region. 4186 4187 Note that if a mark in another file is used, the line number 4188 applies to that buffer. 4189 4190 The result is a |List| with four numbers: 4191 [bufnum, lnum, col, off] 4192 "bufnum" is zero, unless a mark like '0 or 'A is used, then it 4193 is the buffer number of the mark. 4194 "lnum" and "col" are the position in the buffer. The first 4195 column is 1. 4196 The "off" number is zero, unless 'virtualedit' is used. Then 4197 it is the offset in screen columns from the start of the 4198 character. E.g., a position within a <Tab> or after the last 4199 character. 4200 4201 For getting the cursor position see |getcurpos()|. 4202 The column number in the returned List is the byte position 4203 within the line. To get the character position in the line, 4204 use |getcharpos()|. 4205 4206 The visual marks |'<| and |'>| refer to the beginning and end 4207 of the visual selection relative to the buffer. Note that 4208 this differs from |setpos()|, where they are relative to the 4209 cursor position. 4210 4211 Note that for '< and '> Visual mode matters: when it is "V" 4212 (visual line mode) the column of '< is zero and the column of 4213 '> is a large number equal to |v:maxcol|. 4214 A very large column number equal to |v:maxcol| can be returned, 4215 in which case it means "after the end of the line". 4216 If {expr} is invalid, returns a list with all zeros. 4217 4218 This can be used to save and restore the position of a mark: >vim 4219 let save_a_mark = getpos("'a") 4220 " ... 4221 call setpos("'a", save_a_mark) 4222< 4223 Also see |getcharpos()|, |getcurpos()| and |setpos()|. 4224 4225 Parameters: ~ 4226 • {expr} (`string`) 4227 4228 Return: ~ 4229 (`[integer, integer, integer, integer]`) 4230 4231getqflist() *getqflist()* 4232 Returns a |List| with all the current quickfix errors. Each 4233 list item is a dictionary with these entries: 4234 bufnr number of buffer that has the file name, use 4235 |bufname()| to get the name 4236 module module name 4237 lnum line number in the buffer (first line is 1) 4238 end_lnum 4239 end of line number if the item is multiline 4240 col column number (first column is 1) 4241 end_col end of column number if the item has range 4242 vcol |TRUE|: "col" is visual column 4243 |FALSE|: "col" is byte index 4244 nr error number 4245 pattern search pattern used to locate the error 4246 text description of the error 4247 type type of the error, 'E', '1', etc. 4248 valid |TRUE|: recognized error message 4249 user_data 4250 any type. This entry is present only when 4251 user data was set for this item. 4252 4253 When there is no error list or it's empty, an empty list is 4254 returned. Quickfix list entries with a non-existing buffer 4255 number are returned with "bufnr" set to zero (Note: some 4256 functions accept buffer number zero for the alternate buffer, 4257 you may need to explicitly check for zero). 4258 4259 Useful application: Find pattern matches in multiple files and 4260 do something with them: >vim 4261 vimgrep /theword/jg *.c 4262 for d in getqflist() 4263 echo bufname(d.bufnr) ':' d.lnum '=' d.text 4264 endfor 4265< 4266 4267 Return: ~ 4268 (`vim.fn.getqflist.ret.item[]`) 4269 4270getqflist({what}) 4271 If the optional {what} dictionary argument is supplied, then 4272 returns only the items listed in {what} as a dictionary. The 4273 following string items are supported in {what}: 4274 changedtick get the total number of changes made 4275 to the list |quickfix-changedtick| 4276 context get the |quickfix-context| 4277 efm errorformat to use when parsing "lines". If 4278 not present, then the 'errorformat' option 4279 value is used. 4280 id get information for the quickfix list with 4281 |quickfix-ID|; zero means the id for the 4282 current list or the list specified by "nr" 4283 idx get information for the quickfix entry at this 4284 index in the list specified by "id" or "nr". 4285 If set to zero, then uses the current entry. 4286 See |quickfix-index| 4287 items quickfix list entries 4288 lines parse a list of lines using 'efm' and return 4289 the resulting entries. Only a |List| type is 4290 accepted. The current quickfix list is not 4291 modified. See |quickfix-parse|. 4292 nr get information for this quickfix list; zero 4293 means the current quickfix list and "$" means 4294 the last quickfix list 4295 qfbufnr number of the buffer displayed in the quickfix 4296 window. Returns 0 if the quickfix buffer is 4297 not present. See |quickfix-buffer|. 4298 quickfixtextfunc 4299 function to get the text to display in the 4300 quickfix window. Returns an empty string if 4301 this function is not set for the list. See 4302 |quickfix-window-function|. 4303 size number of entries in the quickfix list 4304 title get the list title |quickfix-title| 4305 winid get the quickfix |window-ID| 4306 all all of the above quickfix properties 4307 Non-string items in {what} are ignored. To get the value of a 4308 particular item, set it to zero. 4309 If "nr" is not present then the current quickfix list is used. 4310 If both "nr" and a non-zero "id" are specified, then the list 4311 specified by "id" is used. 4312 To get the number of lists in the quickfix stack, set "nr" to 4313 "$" in {what}. The "nr" value in the returned dictionary 4314 contains the quickfix stack size. 4315 When "lines" is specified, all the other items except "efm" 4316 are ignored. The returned dictionary contains the entry 4317 "items" with the list of entries. 4318 4319 The returned dictionary contains the following entries: 4320 changedtick total number of changes made to the 4321 list |quickfix-changedtick| 4322 context quickfix list context. See |quickfix-context| 4323 If not present, set to "". 4324 id quickfix list ID |quickfix-ID|. If not 4325 present, set to 0. 4326 idx index of the quickfix entry in the list. If 4327 not present, set to 0. 4328 items quickfix list entries. If not present, set to 4329 an empty list. 4330 nr quickfix list number. If not present, set to 4331 0 4332 qfbufnr number of the buffer displayed in the quickfix 4333 window. If not present, set to 0. 4334 quickfixtextfunc 4335 'quickfixtextfunc' setting of the list. If 4336 not present, set to "". 4337 size number of entries in the quickfix list. If 4338 not present, set to 0. 4339 title quickfix list title text. If not present, set 4340 to "". 4341 winid quickfix |window-ID|. If not present, set to 0 4342 4343 Examples (See also |getqflist-examples|): >vim 4344 echo getqflist({'all': 1}) 4345 echo getqflist({'nr': 2, 'title': 1}) 4346 echo getqflist({'lines' : ["F1:10:L10"]}) 4347< 4348 4349 Parameters: ~ 4350 • {what} (`vim.fn.getqflist.what`) 4351 4352 Return: ~ 4353 (`vim.fn.getqflist.ret`) 4354 4355getreg([{regname} [, 1 [, {list}]]]) *getreg()* 4356 Returns the contents of register {regname} as a String. 4357 Example: >vim 4358 let cliptext = getreg('*') 4359< When register {regname} was not set the result is an empty 4360 string. 4361 The {regname} argument must be a string. 4362 4363 getreg('=') returns the last evaluated value of the expression 4364 register. (For use in maps.) 4365 getreg('=', 1) returns the expression itself, so that it can 4366 be restored with |setreg()|. For other registers the extra 4367 argument is ignored, thus you can always give it. 4368 4369 If {list} is present and |TRUE|, the result type is changed 4370 to |List|. Each list item is one text line. Use it if you care 4371 about zero bytes possibly present inside register: without 4372 third argument both NLs and zero bytes are represented as NLs 4373 (see |NL-used-for-Nul|). 4374 When the register was not set an empty list is returned. 4375 4376 If {regname} is not specified, |v:register| is used. 4377 4378 Parameters: ~ 4379 • {regname} (`string?`) 4380 • {expr} (`any?`) 4381 • {list} (`nil|false?`) 4382 4383 Return: ~ 4384 (`string`) 4385 4386getreginfo([{regname}]) *getreginfo()* 4387 Returns detailed information about register {regname} as a 4388 Dictionary with the following entries: 4389 regcontents List of lines contained in register 4390 {regname}, like 4391 getreg({regname}, 1, 1). 4392 regtype the type of register {regname}, as in 4393 |getregtype()|. 4394 isunnamed Boolean flag, v:true if this register 4395 is currently pointed to by the unnamed 4396 register. 4397 points_to for the unnamed register, gives the 4398 single letter name of the register 4399 currently pointed to (see |quotequote|). 4400 For example, after deleting a line 4401 with `dd`, this field will be "1", 4402 which is the register that got the 4403 deleted text. 4404 4405 The {regname} argument is a string. If {regname} is invalid 4406 or not set, an empty Dictionary will be returned. 4407 If {regname} is not specified, |v:register| is used. 4408 The returned Dictionary can be passed to |setreg()|. 4409 4410 Parameters: ~ 4411 • {regname} (`string?`) 4412 4413 Return: ~ 4414 (`table`) 4415 4416getregion({pos1}, {pos2} [, {opts}]) *getregion()* 4417 Returns the list of strings from {pos1} to {pos2} from a 4418 buffer. 4419 4420 {pos1} and {pos2} must both be |List|s with four numbers. 4421 See |getpos()| for the format of the list. It's possible 4422 to specify positions from a different buffer, but please 4423 note the limitations at |getregion-notes|. 4424 4425 The optional argument {opts} is a Dict and supports the 4426 following items: 4427 4428 type Specify the region's selection type. 4429 See |getregtype()| for possible values, 4430 except that the width can be omitted 4431 and an empty string cannot be used. 4432 (default: "v") 4433 4434 exclusive If |TRUE|, use exclusive selection 4435 for the end position. 4436 (default: follow 'selection') 4437 4438 You can get the last selection type by |visualmode()|. 4439 If Visual mode is active, use |mode()| to get the Visual mode 4440 (e.g., in a |:vmap|). 4441 This function is useful to get text starting and ending in 4442 different columns, such as a |charwise-visual| selection. 4443 4444 *getregion-notes* 4445 Note that: 4446 - Order of {pos1} and {pos2} doesn't matter, it will always 4447 return content from the upper left position to the lower 4448 right position. 4449 - If 'virtualedit' is enabled and the region is past the end 4450 of the lines, resulting lines are padded with spaces. 4451 - If the region is blockwise and it starts or ends in the 4452 middle of a multi-cell character, it is not included but 4453 its selected part is substituted with spaces. 4454 - If {pos1} and {pos2} are not in the same buffer, an empty 4455 list is returned. 4456 - {pos1} and {pos2} must belong to a |bufloaded()| buffer. 4457 - It is evaluated in current window context, which makes a 4458 difference if the buffer is displayed in a window with 4459 different 'virtualedit' or 'list' values. 4460 - When specifying an exclusive selection and {pos1} and {pos2} 4461 are equal, the returned list contains a single character as 4462 if selection is inclusive, to match the behavior of an empty 4463 exclusive selection in Visual mode. 4464 4465 Examples: >vim 4466 xnoremap <CR> 4467 \ <Cmd>echom getregion( 4468 \ getpos('v'), getpos('.'), #{ type: mode() })<CR> 4469< 4470 4471 Parameters: ~ 4472 • {pos1} (`[integer, integer, integer, integer]`) 4473 • {pos2} (`[integer, integer, integer, integer]`) 4474 • {opts} (`{type?:string, exclusive?:boolean}?`) 4475 4476 Return: ~ 4477 (`string[]`) 4478 4479getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()* 4480 Same as |getregion()|, but returns a list of positions 4481 describing the buffer text segments bound by {pos1} and 4482 {pos2}. 4483 The segments are a pair of positions for every line: > 4484 [[{startpos}, {endpos}], ...] 4485< 4486 The position is a |List| with four numbers: 4487 [bufnum, lnum, col, off] 4488 "bufnum" is the buffer number. 4489 "lnum" and "col" are the position in the buffer. The first 4490 column is 1. 4491 If the "off" number of a starting position is non-zero, it is 4492 the offset in screen columns from the start of the character. 4493 E.g., a position within a <Tab> or after the last character. 4494 If the "off" number of an ending position is non-zero, it is 4495 the offset of the character's first cell not included in the 4496 selection, otherwise all its cells are included. 4497 4498 To get the current visual selection: >vim 4499 let region = getregionpos(getpos('v'), getpos('.')) 4500< 4501 The {opts} Dict supports the following items: 4502 4503 type See |getregion()|. 4504 4505 exclusive See |getregion()|. 4506 4507 eol If |TRUE|, indicate positions beyond 4508 the end of a line with "col" values 4509 one more than the length of the line. 4510 If |FALSE|, positions are limited 4511 within their lines, and if a line is 4512 empty or the selection is entirely 4513 beyond the end of a line, a "col" 4514 value of 0 is used for both positions. 4515 (default: |FALSE|) 4516 4517 bounds If |TRUE|, return only the outer 4518 bounds of the region as a single 4519 pair: > 4520 [[{startpos}, {endpos}]] 4521< {startpos} is the start position on 4522 the first line of the region and 4523 {endpos} the end position on its last 4524 line. The lines in between are not 4525 visited, which is much faster for a 4526 large region. 4527 (default: |FALSE|) 4528 4529 Using "bounds" with the same {opts} is equivalent to taking 4530 the outer positions of the full result: >vim 4531 let full = getregionpos(pos1, pos2, opts) 4532 let bounds = [[full[0][0], full[-1][1]]] 4533< When the full result is empty, e.g. because {pos1} and {pos2} 4534 are in different buffers, the result is empty as well. 4535 Note that the two positions then come from different lines, so 4536 they describe a diagonal of the region and not its shape. For 4537 a blockwise region they are the start of the first line and 4538 the end of the last line, not the corners of the block. 4539 Likewise, when the first line is empty and "eol" is |FALSE|, 4540 {startpos} has a "col" of 0 while {endpos} may not. 4541 4542 Parameters: ~ 4543 • {pos1} (`[integer, integer, integer, integer]`) 4544 • {pos2} (`[integer, integer, integer, integer]`) 4545 • {opts} 4546 (`{type?:string, exclusive?:boolean, eol?:boolean, bounds?:boolean}?`) 4547 4548 Return: ~ 4549 (`[ [integer, integer, integer, integer], [integer, integer, integer, integer] ][]`) 4550 4551getregtype([{regname}]) *getregtype()* 4552 Returns the type of register {regname} as a String. 4553 The value will be one of: 4554 "v" for |charwise| text 4555 "V" for |linewise| text 4556 "<CTRL-V>{width}" for |blockwise-visual| text 4557 "" for an empty or unknown register 4558 <CTRL-V> is one character with value 0x16. 4559 The {regname} argument is a string. If {regname} is not 4560 specified, |v:register| is used. 4561 4562 Parameters: ~ 4563 • {regname} (`string?`) 4564 4565 Return: ~ 4566 (`string`) 4567 4568getscriptinfo([{opts}]) *getscriptinfo()* 4569 Returns a |List| with information about all the sourced Vim 4570 scripts in the order they were sourced, like what 4571 `:scriptnames` shows. 4572 4573 The optional Dict argument {opts} supports the following 4574 optional items: 4575 name Script name match pattern. If specified, 4576 and "sid" is not specified, information about 4577 scripts with a name that match the pattern 4578 "name" are returned. 4579 sid Script ID |<SID>|. If specified, only 4580 information about the script with ID "sid" is 4581 returned and "name" is ignored. 4582 4583 Each item in the returned List is a |Dict| with the following 4584 items: 4585 autoload Always set to FALSE. 4586 functions List of script-local function names defined in 4587 the script. Present only when a particular 4588 script is specified using the "sid" item in 4589 {opts}. 4590 name Vim script file name. 4591 sid Script ID |<SID>|. 4592 variables A dictionary with the script-local variables. 4593 Present only when a particular script is 4594 specified using the "sid" item in {opts}. 4595 Note that this is a copy, the value of 4596 script-local variables cannot be changed using 4597 this dictionary. 4598 version Vim script version, always 1 4599 4600 Examples: >vim 4601 echo getscriptinfo({'name': 'myscript'}) 4602 echo getscriptinfo({'sid': 15})[0].variables 4603< 4604 4605 Parameters: ~ 4606 • {opts} (`table?`) 4607 4608 Return: ~ 4609 (`vim.fn.getscriptinfo.ret[]`) 4610 4611getstacktrace() *getstacktrace()* 4612 Lua: Prefer |debug.traceback()|. 4613 4614 Returns the current stack trace of Vim scripts. 4615 Stack trace is a |List|, of which each item is a |Dictionary| 4616 with the following items: 4617 funcref The funcref if the stack is at a function, 4618 otherwise this item is omitted. 4619 event The string of the event description if the 4620 stack is at an autocmd event, otherwise this 4621 item is omitted. 4622 lnum The line number in the script on the stack. 4623 filepath The file path of the script on the stack. 4624 4625 Return: ~ 4626 (`table[]`) 4627 4628gettabinfo([{tabnr}]) *gettabinfo()* 4629 If {tabnr} is not specified, then information about all the 4630 tabpages is returned as a |List|. Each List item is a 4631 |Dictionary|. Otherwise, {tabnr} specifies the tabpage 4632 number and information about that one is returned. If the tab 4633 page does not exist an empty List is returned. 4634 4635 Each List item is a |Dictionary| with the following entries: 4636 tabnr |tabpage-number| 4637 variables a reference to the dictionary with 4638 tabpage-local variables 4639 windows List of |window-ID|s in the tabpage. 4640 4641 Parameters: ~ 4642 • {tabnr} (`integer?`) 4643 4644 Return: ~ 4645 (`any`) 4646 4647gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()* 4648 Lua: Prefer |nvim_tabpage_get_var()| or |vim.t|. 4649 4650 Get the value of a tab-local variable {varname} in tabpage 4651 {tabnr}. |t:var| 4652 Tabs are numbered starting with one. 4653 The {varname} argument is a string. When {varname} is empty a 4654 dictionary with all tab-local variables is returned. 4655 Note that the name without "t:" must be used. 4656 When the tab or variable doesn't exist {def} or an empty 4657 string is returned, there is no error message. 4658 4659 Parameters: ~ 4660 • {tabnr} (`integer`) 4661 • {varname} (`string`) 4662 • {def} (`any?`) 4663 4664 Return: ~ 4665 (`any`) 4666 4667gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()* 4668 Lua: Prefer |nvim_win_get_var()| or |vim.w| after resolving 4669 {tabnr} and {winnr} to a winid; option names use 4670 |nvim_get_option_value()| or |vim.wo|. 4671 4672 Gets the value of window-local variable {varname} in {winnr} 4673 (|window-number| or |window-ID|) in |tabpage-number| {tabnr}. 4674 4675 {varname} is a string: 4676 - Name of the variable (without "w:"). 4677 - If empty, gets a dictionary with all window-local variables. 4678 - If "&", gets the values of all window-local options in 4679 a |Dictionary|. 4680 - If it starts with "&", gets the value of a window-local 4681 option. 4682 4683 To get window-local variables in the current tabpage use 4684 |getwinvar()|. 4685 4686 When {winnr} is zero the current window is used. 4687 4688 Also works for a global option, buffer-local option, 4689 window-local option, and tab-local option ('cmdheight'). 4690 But not for a global variable or buffer-local variable. 4691 4692 When the tab, window or variable doesn't exist, {def} or an 4693 empty string is returned; there is no error. 4694 4695 Examples: >vim 4696 let list_is_on = gettabwinvar(1, 2, '&list') 4697 echo "myvar = " .. gettabwinvar(3, 1, 'myvar') 4698< 4699 To get all window-local variables: >vim 4700 gettabwinvar({tabnr}, {winnr}, '&') 4701< 4702 4703 Parameters: ~ 4704 • {tabnr} (`integer`) 4705 • {winnr} (`integer`) 4706 • {varname} (`string`) 4707 • {def} (`any?`) 4708 4709 Return: ~ 4710 (`any`) 4711 4712gettagstack([{winnr}]) *gettagstack()* 4713 Returns the tag stack of window {winnr} (|window-number| or 4714 |window-ID|) as a Dict. 4715 When {winnr} is not specified, the current window is used. 4716 When window {winnr} doesn't exist, an empty Dict is returned. 4717 4718 The returned dictionary contains the following entries: 4719 curidx Current index in the stack. When at 4720 top of the stack, set to (length + 1). 4721 Index of bottom of the stack is 1. 4722 items List of items in the stack. Each item 4723 is a dictionary containing the 4724 entries described below. 4725 length Number of entries in the stack. 4726 4727 Each item in the stack is a dictionary with the following 4728 entries: 4729 bufnr buffer number of the current jump 4730 from cursor position before the tag jump. 4731 See |getpos()| for the format of the 4732 returned list. 4733 matchnr current matching tag number. Used 4734 when multiple matching tags are found 4735 for a name. 4736 tagname name of the tag 4737 4738 See |tagstack| for more information about the tag stack. 4739 4740 Parameters: ~ 4741 • {winnr} (`integer?`) 4742 4743 Return: ~ 4744 (`any`) 4745 4746gettext({text}) *gettext()* 4747 Translate String {text} if possible. 4748 This is mainly for use in the distributed Vim scripts. When 4749 generating message translations the {text} is extracted by 4750 xgettext, the translator can add the translated message in the 4751 .po file and Vim will lookup the translation when gettext() is 4752 called. 4753 For {text} double quoted strings are preferred, because 4754 xgettext does not understand escaping in single quoted 4755 strings. 4756 4757 Parameters: ~ 4758 • {text} (`string`) 4759 4760 Return: ~ 4761 (`string`) 4762 4763getwininfo([{winid}]) *getwininfo()* 4764 Returns information about windows as a |List| with Dictionaries. 4765 4766 If {winid} is given Information about the window with that ID 4767 is returned, as a |List| with one item. If the window does not 4768 exist the result is an empty list. 4769 4770 Without {winid} information about all the windows in all the 4771 tabpages is returned. 4772 4773 Each List item is a |Dictionary| with the following entries: 4774 botline last complete displayed buffer line 4775 bufnr number of buffer in the window 4776 height window height (excluding winbar) 4777 leftcol first column displayed; only used when 4778 'wrap' is off 4779 loclist 1 if showing a location list 4780 quickfix 1 if quickfix or location list window 4781 status_height status lines height (0 or 1) 4782 tabnr |tabpage-number| 4783 terminal 1 if a terminal window 4784 textoff number of columns occupied by any 4785 'foldcolumn', 'signcolumn' and line 4786 number in front of the text 4787 topline first displayed buffer line 4788 variables a reference to the dictionary with 4789 window-local variables 4790 width window width 4791 winbar 1 if the window has a toolbar, 0 4792 otherwise 4793 wincol leftmost screen column of the window; 4794 "col" from |win_screenpos()| 4795 winid |window-ID| 4796 winnr |window-number| 4797 winrow topmost screen line of the window; 4798 "row" from |win_screenpos()| 4799 4800 Parameters: ~ 4801 • {winid} (`integer?`) 4802 4803 Return: ~ 4804 (`vim.fn.getwininfo.ret.item[]`) 4805 4806getwinpos([{timeout}]) *getwinpos()* 4807 Returns the [x, y] screen position of the Nvim GUI window as 4808 a |List| with two numbers (result of |getwinposx()| and 4809 |getwinposy()| combined). 4810 4811 {timeout} can be used to specify how long to wait in msec for 4812 a response. When omitted 100 msec is used. 4813 4814 Use a longer time for a remote terminal. 4815 When using a value less than 10 and no response is received 4816 within that time, a previously reported position is returned, 4817 if available. This can be used to poll for the position and 4818 do some work in the meantime: >vim 4819 while 1 4820 let res = getwinpos(1) 4821 if res[0] >= 0 4822 break 4823 endif 4824 " Do some work here 4825 endwhile 4826< 4827 4828 Parameters: ~ 4829 • {timeout} (`integer?`) 4830 4831 Return: ~ 4832 (`any`) 4833 4834getwinposx() *getwinposx()* 4835 Returns the X coordinate in pixels of the left hand side of 4836 the Nvim GUI window, or -1 if not available. The value can be 4837 used with `:winpos`. 4838 4839 Return: ~ 4840 (`integer`) 4841 4842getwinposy() *getwinposy()* 4843 Returns the Y coordinate in pixels of the top of the Nvim GUI 4844 window, or -1 if not available. The value can be used with 4845 `:winpos`. 4846 4847 Return: ~ 4848 (`integer`) 4849 4850getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* 4851 Lua: Prefer |nvim_win_get_var()| or |vim.w| after resolving 4852 {winnr}; option names use |nvim_get_option_value()| or 4853 |vim.wo|. 4854 4855 Like |gettabwinvar()| for the current tabpage. 4856 Examples: >vim 4857 let list_is_on = getwinvar(2, '&list') 4858 echo "myvar = " .. getwinvar(1, 'myvar') 4859< 4860 4861 Parameters: ~ 4862 • {winnr} (`integer`) 4863 • {varname} (`string`) 4864 • {def} (`any?`) 4865 4866 Return: ~ 4867 (`any`) 4868 4869glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* 4870 Expand the file wildcards in {expr}. See |wildcards| for the 4871 use of special characters. 4872 4873 Unless the optional {nosuf} argument is given and is |TRUE|, 4874 the 'suffixes' and 'wildignore' options apply: Names matching 4875 one of the patterns in 'wildignore' will be skipped and 4876 'suffixes' affect the ordering of matches. 4877 'wildignorecase' always applies. 4878 4879 When {list} is present and it is |TRUE| the result is a |List| 4880 with all matching files. The advantage of using a List is, 4881 you also get filenames containing newlines correctly. 4882 Otherwise the result is a String and when there are several 4883 matches, they are separated by <NL> characters. 4884 4885 If the expansion fails, the result is an empty String or List. 4886 4887 You can also use |readdir()| if you need to do complicated 4888 things, such as limiting the number of matches. 4889 4890 A name for a non-existing file is not included. A symbolic 4891 link is only included if it points to an existing file. 4892 However, when the {alllinks} argument is present and it is 4893 |TRUE| then all symbolic links are included. 4894 4895 For most systems backticks can be used to get files names from 4896 any external command. Example: >vim 4897 let tagfiles = glob("`find . -name tags -print`") 4898 let &tags = substitute(tagfiles, "\n", ",", "g") 4899< The result of the program inside the backticks should be one 4900 item per line. Spaces inside an item are allowed. 4901 4902 See |expand()| for expanding special Vim variables. See 4903 |system()| for getting the raw output of an external command. 4904 4905 Parameters: ~ 4906 • {expr} (`string`) 4907 • {nosuf} (`boolean?`) 4908 • {list} (`boolean?`) 4909 • {alllinks} (`boolean?`) 4910 4911 Return: ~ 4912 (`any`) 4913 4914glob2regpat({string}) *glob2regpat()* 4915 Convert a file pattern, as used by |glob()|, into a search 4916 pattern. The result can be used to match with a string that 4917 is a file name. E.g. >vim 4918 if filename =~ glob2regpat('Make*.mak') 4919 " ... 4920 endif 4921< This is equivalent to: >vim 4922 if filename =~ '^Make.*\.mak$' 4923 " ... 4924 endif 4925< When {string} is an empty string the result is "^$", match an 4926 empty string. 4927 Note that the result depends on the system. On MS-Windows 4928 a backslash usually means a path separator. 4929 4930 Parameters: ~ 4931 • {string} (`string`) 4932 4933 Return: ~ 4934 (`string`) 4935 4936globpath({path}, {expr} [, {nosuf} [, {list} [, {allinks}]]]) *globpath()* 4937 Perform |glob()| for String {expr} on all directories in {path} 4938 and concatenate the results. Example: >vim 4939 echo globpath(&rtp, "syntax/c.vim") 4940< 4941 {path} is a comma-separated list of directory names. Each 4942 directory name is prepended to {expr} and expanded like with 4943 |glob()|. A path separator is inserted when needed. 4944 To add a comma inside a directory name escape it with a 4945 backslash. Note that on MS-Windows a directory may have a 4946 trailing backslash, remove it if you put a comma after it. 4947 If the expansion fails for one of the directories, there is no 4948 error message. 4949 4950 Unless the optional {nosuf} argument is given and is |TRUE|, 4951 the 'suffixes' and 'wildignore' options apply: Names matching 4952 one of the patterns in 'wildignore' will be skipped and 4953 'suffixes' affect the ordering of matches. 4954 4955 When {list} is present and it is |TRUE| the result is a |List| 4956 with all matching files. The advantage of using a List is, 4957 you also get filenames containing newlines correctly. 4958 Otherwise the result is a String and when there are several 4959 matches, they are separated by <NL> characters. Example: >vim 4960 echo globpath(&rtp, "syntax/c.vim", 0, 1) 4961< 4962 {allinks} is used as with |glob()|. 4963 4964 The "**" item can be used to search in a directory tree. 4965 For example, to find all "README.txt" files in the directories 4966 in 'runtimepath' and below: >vim 4967 echo globpath(&rtp, "**/README.txt") 4968< Upwards search and limiting the depth of "**" is not 4969 supported, thus using 'path' will not always work properly. 4970 4971 Parameters: ~ 4972 • {path} (`string`) 4973 • {expr} (`string`) 4974 • {nosuf} (`boolean?`) 4975 • {list} (`boolean?`) 4976 • {allinks} (`boolean?`) 4977 4978 Return: ~ 4979 (`any`) 4980 4981has({feature}) *has()* 4982 Returns 1 if {feature} is supported, 0 otherwise. The 4983 {feature} argument is a feature name like "nvim-0.2.1" or 4984 "win32", see below. See also |exists()|. 4985 4986 To get the system name use |vim.uv|.os_uname() in Lua: >lua 4987 print(vim.uv.os_uname().sysname) 4988 4989< If the code has a syntax error then Vimscript may skip the 4990 rest of the line. Put |:if| and |:endif| on separate lines to 4991 avoid the syntax error: >vim 4992 if has('feature') 4993 let x = this_breaks_without_the_feature() 4994 endif 4995< 4996 Vim's compile-time feature-names (prefixed with "+") are not 4997 recognized because Nvim is always compiled with all possible 4998 features. |feature-compile| 4999 5000 Feature names can be: 5001 1. Nvim version. For example the "nvim-0.2.1" feature means 5002 that Nvim is version 0.2.1 or later: >vim 5003 if has("nvim-0.2.1") 5004 " ... 5005 endif 5006 5007< 2. Runtime condition or other pseudo-feature. For example the 5008 "win32" feature checks if the current system is Windows: >vim 5009 if has("win32") 5010 " ... 5011 endif 5012< *feature-list* 5013 List of supported pseudo-feature names: 5014 acl |ACL| support. 5015 *android* Android system (not necessarily |termux|). 5016 bsd BSD system (not macOS, use "mac" for that). 5017 clipboard |clipboard| provider is available. 5018 fname_case Case in file names matters (for Darwin and MS-Windows 5019 this is not present). 5020 gui_running Nvim has a GUI. 5021 hurd GNU/Hurd system. 5022 iconv Can use |iconv()| for conversion. 5023 linux Linux system. 5024 mac MacOS system. 5025 nvim This is Nvim. 5026 python3 Legacy Vim |python3| interface. |has-python| 5027 pythonx Legacy Vim |python_x| interface. |has-pythonx| 5028 sun SunOS system. 5029 *termux* Termux, an |android| terminal app and packaging environment. 5030 ttyin input is a terminal (tty). 5031 ttyout output is a terminal (tty). 5032 unix Unix system. 5033 *vim_starting* True during |startup|. 5034 win32 Windows system (32 or 64 bit). 5035 win64 Windows system (64 bit). 5036 wsl WSL (Windows Subsystem for Linux) system. 5037 5038 *has-patch* 5039 3. Vim patch. For example the "patch123" feature means that 5040 Vim patch 123 at the current |v:version| was included: >vim 5041 if v:version > 602 || v:version == 602 && has("patch148") 5042 " ... 5043 endif 5044 5045< 4. Vim version. For example the "patch-7.4.237" feature means 5046 that Nvim is Vim-compatible to version 7.4.237 or later. >vim 5047 if has("patch-7.4.237") 5048 " ... 5049 endif 5050< 5051 5052 Attributes: ~ 5053 |api-fast| 5054 5055 Parameters: ~ 5056 • {feature} (`string`) 5057 5058 Return: ~ 5059 (`0|1`) 5060 5061has_key({dict}, {key}) *has_key()* 5062 Lua: Prefer `dict[key] ~= nil`. 5063 5064 Checks whether |Dictionary| {dict} has an entry with key 5065 {key}. Returns TRUE if so, FALSE otherwise. The {key} 5066 argument is a string. 5067 5068 Parameters: ~ 5069 • {dict} (`table`) 5070 • {key} (`string`) 5071 5072 Return: ~ 5073 (`0|1`) 5074 5075haslocaldir([{winnr} [, {tabnr} [, {bufnr} ]]]) *haslocaldir()* 5076 Checks whether the tabpage, window or buffer has set a local 5077 working directory. Returns 1 when the window has set a local 5078 path via |:lcd|, or when {winnr} is -1 and the tabpage has set 5079 a local path via |:tcd|, or when {winnr} and {tabnr} are -1 5080 and {bufnr} has set a local path via |:bcd|, otherwise 0. 5081 5082 Tabs, windows and buffers are identified by their respective 5083 numbers, 0 means current tab/window/buffer. Missing {winnr} 5084 or {tabnr} implies 0 (missing {bufnr} does not; see below). 5085 Thus the following are equivalent: >vim 5086 echo haslocaldir() 5087 echo haslocaldir(0) 5088 echo haslocaldir(0, 0) 5089< With {winnr} use that window in the current tabpage. 5090 With {winnr} and {tabnr} use the window in that tabpage. 5091 {winnr} is a |window-number| or |window-ID|. 5092 If {winnr} is -1 it is ignored, only the tab is resolved. 5093 If {bufnr} is provided, {winnr} and {tabnr} must be -1 and 5094 only the buffer is resolved. An argument may be -1 only if 5095 all preceding arguments are -1. 5096 Examples of buffer usage: >vim 5097 haslocaldir(-1, -1, 0) " Current buf has a local directory? 5098 haslocaldir(-1, -1, 3) " Buf #3 has a local directory? 5099< Throw error if the arguments are invalid. 5100 |E5000| |E5001| |E5002| |E5006| |E5007| 5101 5102 Parameters: ~ 5103 • {winnr} (`integer?`) 5104 • {tabnr} (`integer?`) 5105 • {bufnr} (`integer?`) 5106 5107 Return: ~ 5108 (`0|1`) 5109 5110hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* 5111 Checks whether a mapping exists whose rhs contains {what}. 5112 Returns TRUE if there is such a mapping in one of the modes 5113 indicated by {mode}. 5114 The arguments {what} and {mode} are strings. 5115 When {abbr} is there and it is |TRUE| use abbreviations 5116 instead of mappings. Don't forget to specify Insert and/or 5117 Command-line mode. 5118 Both the global mappings and the mappings local to the current 5119 buffer are checked for a match. 5120 If no matching mapping is found FALSE is returned. 5121 The following characters are recognized in {mode}: 5122 n Normal mode 5123 v Visual and Select mode 5124 x Visual mode 5125 s Select mode 5126 o Operator-pending mode 5127 i Insert mode 5128 l Language-Argument ("r", "f", "t", etc.) 5129 c Command-line mode 5130 When {mode} is omitted, "nvo" is used. 5131 5132 This function is useful to check if a mapping already exists 5133 to a function in a Vim script. Example: >vim 5134 if !hasmapto('\ABCdoit') 5135 map <Leader>d \ABCdoit 5136 endif 5137< This installs the mapping to "\ABCdoit" only if there isn't 5138 already a mapping to "\ABCdoit". 5139 5140 Parameters: ~ 5141 • {what} (`any`) 5142 • {mode} (`string?`) 5143 • {abbr} (`boolean?`) 5144 5145 Return: ~ 5146 (`0|1`) 5147 5148histadd({history}, {item}) *histadd()* 5149 Add the String {item} to the history {history} which can be 5150 one of: *hist-names* 5151 "cmd" or ":" command line history 5152 "search" or "/" search pattern history 5153 "expr" or "=" typed expression history 5154 "input" or "@" input line history 5155 "debug" or ">" debug command history 5156 empty the current or last used history 5157 The {history} string does not need to be the whole name, one 5158 character is sufficient. 5159 If {item} does already exist in the history, it will be 5160 shifted to become the newest entry. 5161 The result is a Number: TRUE if the operation was successful, 5162 otherwise FALSE is returned. 5163 5164 Example: >vim 5165 call histadd("input", strftime("%Y %b %d")) 5166 let date=input("Enter date: ") 5167< This function is not available in the |sandbox|. 5168 5169 Parameters: ~ 5170 • {history} (`string`) 5171 • {item} (`any`) 5172 5173 Return: ~ 5174 (`0|1`) 5175 5176histdel({history} [, {item}]) *histdel()* 5177 Clear {history}, i.e. delete all its entries. See |hist-names| 5178 for the possible values of {history}. 5179 5180 If the parameter {item} evaluates to a String, it is used as a 5181 regular expression. All entries matching that expression will 5182 be removed from the history (if there are any). 5183 Upper/lowercase must match, unless "\c" is used |/\c|. 5184 If {item} evaluates to a Number, it will be interpreted as 5185 an index, see |:history-indexing|. The respective entry will 5186 be removed if it exists. 5187 5188 The result is TRUE for a successful operation, otherwise FALSE 5189 is returned. 5190 5191 Examples: 5192 Clear expression register history: >vim 5193 call histdel("expr") 5194< 5195 Remove all entries starting with "*" from the search history: >vim 5196 call histdel("/", '^\*') 5197< 5198 The following three are equivalent: >vim 5199 call histdel("search", histnr("search")) 5200 call histdel("search", -1) 5201 call histdel("search", '^' .. histget("search", -1) .. '$') 5202< 5203 To delete the last search pattern and use the last-but-one for 5204 the "n" command and 'hlsearch': >vim 5205 call histdel("search", -1) 5206 let @/ = histget("search", -1) 5207< 5208 5209 Parameters: ~ 5210 • {history} (`string`) 5211 • {item} (`any?`) 5212 5213 Return: ~ 5214 (`0|1`) 5215 5216histget({history} [, {index}]) *histget()* 5217 Returns an entry from the specified command-line {history}. 5218 See |hist-names| for the possible values of {history}, and 5219 |:history-indexing| for {index}. If there is 5220 no such entry, an empty String is returned. When {index} is 5221 omitted, the most recent item from the history is used. 5222 5223 Examples: 5224 Redo the second last search from history. >vim 5225 execute '/' .. histget("search", -2) 5226 5227< Define an Ex command ":H {num}" that supports re-execution of 5228 the {num}th entry from the output of |:history|. >vim 5229 command -nargs=1 H execute histget("cmd", 0+<args>) 5230< 5231 5232 Parameters: ~ 5233 • {history} (`string`) 5234 • {index} (`integer|string?`) 5235 5236 Return: ~ 5237 (`string`) 5238 5239histnr({history}) *histnr()* 5240 The result is the Number of the current entry in {history}. 5241 See |hist-names| for the possible values of {history}. 5242 If an error occurred, -1 is returned. 5243 5244 Example: >vim 5245 let inp_index = histnr("expr") 5246< 5247 5248 Parameters: ~ 5249 • {history} (`string`) 5250 5251 Return: ~ 5252 (`integer`) 5253 5254hlID({name}) *hlID()* 5255 Lua: Prefer |nvim_get_hl()|. 5256 5257 Returns the numeric ID of the highlight group with name 5258 {name}. When the highlight group doesn't exist, zero is 5259 returned. 5260 This can be used to retrieve information about the highlight 5261 group. For example, to get the background color of the 5262 "Comment" group: >vim 5263 echo synIDattr(synIDtrans(hlID("Comment")), "bg") 5264< 5265 5266 Parameters: ~ 5267 • {name} (`string`) 5268 5269 Return: ~ 5270 (`integer`) 5271 5272hlexists({name}) *hlexists()* 5273 Lua: Prefer |nvim_get_hl()|. 5274 5275 Checks whether a highlight group called {name} exists. 5276 Returns TRUE if the group has been defined in some way. Not 5277 necessarily when highlighting has been defined for it, it may 5278 also have been used for a syntax item. 5279 5280 Parameters: ~ 5281 • {name} (`string|number|boolean|nil`) 5282 5283 Return: ~ 5284 (`0|1`) 5285 5286hostname() *hostname()* 5287 Lua: Prefer |uv.os_gethostname()|. 5288 5289 Returns the hostname of the machine on which the Nvim server 5290 (not the UI client) is currently running. 5291 5292 Attributes: ~ 5293 |api-fast| 5294 5295 Return: ~ 5296 (`string`) 5297 5298iconv({string}, {from}, {to}) *iconv()* 5299 Lua: Prefer |vim.iconv()|. 5300 5301 Converts the encoding of {string} from {from} to {to}. 5302 Returns the converted String. 5303 When the conversion completely fails an empty string is 5304 returned. When some characters could not be converted they 5305 are replaced with "?". 5306 The encoding names are whatever the iconv() library function 5307 can accept, see ":!man 3 iconv". 5308 Note that Vim uses UTF-8 for all Unicode encodings, conversion 5309 from/to UCS-2 is automatically changed to use UTF-8. You 5310 cannot use UCS-2 in a string anyway, because of the NUL bytes. 5311 5312 Attributes: ~ 5313 |api-fast| 5314 5315 Parameters: ~ 5316 • {string} (`string`) 5317 • {from} (`string`) 5318 • {to} (`string`) 5319 5320 Return: ~ 5321 (`string`) 5322 5323id({expr}) *id()* 5324 Returns a |String| which is a unique identifier of the 5325 container type (|List|, |Dict|, |Blob| and |Partial|). It is 5326 guaranteed that for the mentioned types `id(v1) ==# id(v2)` 5327 returns true iff `type(v1) == type(v2) && v1 is v2`. 5328 Note that `v:_null_string`, `v:_null_list`, `v:_null_dict` and 5329 `v:_null_blob` have the same `id()` with different types 5330 because they are internally represented as NULL pointers. 5331 `id()` returns a hexadecimal representation of the pointers to 5332 the containers (i.e. like `0x994a40`), same as `printf("%p", 5333 {expr})`, but it is advised against counting on the exact 5334 format of the return value. 5335 5336 It is not guaranteed that `id(no_longer_existing_container)` 5337 will not be equal to some other `id()`: new containers may 5338 reuse identifiers of the garbage-collected ones. 5339 5340 Parameters: ~ 5341 • {expr} (`any`) 5342 5343 Return: ~ 5344 (`string`) 5345 5346indent({lnum}) *indent()* 5347 Returns the indent of line {lnum} in the current buffer. 5348 The indent is counted in spaces, the value of 'tabstop' is 5349 relevant. {lnum} is used just like in 5350 |getline()|. 5351 When {lnum} is invalid -1 is returned. 5352 5353 To get or set indent of lines in a string, see |vim.text.indent()|. 5354 5355 Parameters: ~ 5356 • {lnum} (`integer|string`) 5357 5358 Return: ~ 5359 (`integer`) 5360 5361index({object}, {expr} [, {start} [, {ic}]]) *index()* 5362 Lua: Prefer |vim.iter()| with |Iter:enumerate()| and 5363 |Iter:find()| for lists; result is 1-based, and `start`, `ic`, 5364 and Blob semantics differ. 5365 5366 Find {expr} in {object} and return its index. See 5367 |indexof()| for using a lambda to select the item. 5368 5369 If {object} is a |List| return the lowest index where the item 5370 has a value equal to {expr}. There is no automatic 5371 conversion, so the String "4" is different from the Number 4. 5372 And the Number 4 is different from the Float 4.0. The value 5373 of 'ignorecase' is not used here, case matters as indicated by 5374 the {ic} argument. 5375 5376 If {object} is a |Blob| return the lowest index where the byte 5377 value is equal to {expr}. 5378 5379 If {start} is given then start looking at the item with index 5380 {start} (may be negative for an item relative to the end). 5381 5382 When {ic} is given and it is |TRUE|, ignore case. Otherwise 5383 case must match. 5384 5385 -1 is returned when {expr} is not found in {object}. 5386 Example: >vim 5387 let idx = index(words, "the") 5388 if index(numbers, 123) >= 0 5389 " ... 5390 endif 5391< 5392 5393 Parameters: ~ 5394 • {object} (`any`) 5395 • {expr} (`any`) 5396 • {start} (`integer?`) 5397 • {ic} (`boolean?`) 5398 5399 Return: ~ 5400 (`integer`) 5401 5402indexof({object}, {expr} [, {opts}]) *indexof()* 5403 Lua: Prefer |vim.iter()| with |Iter:enumerate()| and 5404 |Iter:find()| for list predicates; result is 1-based, and 5405 `startidx` and Blob semantics differ. 5406 5407 Returns the index of an item in {object} where {expr} is 5408 v:true. {object} must be a |List| or a |Blob|. 5409 5410 If {object} is a |List|, evaluate {expr} for each item in the 5411 List until the expression is v:true and return the index of 5412 this item. 5413 5414 If {object} is a |Blob| evaluate {expr} for each byte in the 5415 Blob until the expression is v:true and return the index of 5416 this byte. 5417 5418 {expr} must be a |string| or |Funcref|. 5419 5420 If {expr} is a |string|: If {object} is a |List|, inside 5421 {expr} |v:key| has the index of the current List item and 5422 |v:val| has the value of the item. If {object} is a |Blob|, 5423 inside {expr} |v:key| has the index of the current byte and 5424 |v:val| has the byte value. 5425 5426 If {expr} is a |Funcref| it must take two arguments: 5427 1. the key or the index of the current item. 5428 2. the value of the current item. 5429 The function must return |TRUE| if the item is found and the 5430 search should stop. 5431 5432 The optional argument {opts} is a Dict and supports the 5433 following items: 5434 startidx start evaluating {expr} at the item with this 5435 index; may be negative for an item relative to 5436 the end 5437 Returns -1 when {expr} evaluates to v:false for all the items. 5438 Example: >vim 5439 let l = [#{n: 10}, #{n: 20}, #{n: 30}] 5440 echo indexof(l, "v:val.n == 20") 5441 echo indexof(l, {i, v -> v.n == 30}) 5442 echo indexof(l, "v:val.n == 20", #{startidx: 1}) 5443< 5444 5445 Parameters: ~ 5446 • {object} (`any`) 5447 • {expr} (`any`) 5448 • {opts} (`table?`) 5449 5450 Return: ~ 5451 (`integer`) 5452 5453input({prompt} [, {text} [, {completion}]]) *input()* 5454 Lua: Prefer |vim.ui.input()| for callback-based input. 5455 5456 5457 Parameters: ~ 5458 • {prompt} (`string`) 5459 • {text} (`string?`) 5460 • {completion} (`string?`) 5461 5462 Return: ~ 5463 (`string`) 5464 5465input({opts}) 5466 Lua: Prefer |vim.ui.input()| for callback-based input. 5467 5468 Prompts the user to enter text on the command-line, and 5469 returns the text as a String. The {prompt} argument is either 5470 a prompt string, or a blank string (for no prompt). A '\n' 5471 can be used in the prompt to start a new line. 5472 5473 In the second form it accepts a single dictionary with the 5474 following keys, any of which may be omitted: 5475 5476 Key Default Description ~ 5477 prompt "" Same as {prompt} in the first form. 5478 default "" Same as {text} in the first form. 5479 completion nothing Same as {completion} in the first form. 5480 cancelreturn "" The value returned when the dialog is 5481 cancelled. 5482 highlight nothing Highlight handler: |Funcref|. 5483 5484 The highlighting set with |:echohl| is used for the prompt. 5485 The input is entered just like a command-line, with the same 5486 editing commands and mappings. There is a separate history 5487 for lines typed for input(). 5488 Example: >vim 5489 if input("Coffee or beer? ") == "beer" 5490 echo "Cheers!" 5491 endif 5492< 5493 If the optional {text} argument is present and not empty, this 5494 is used for the default reply, as if the user typed this. 5495 Example: >vim 5496 let color = input("Color? ", "white") 5497 5498< The optional {completion} argument specifies the type of 5499 completion supported for the input. Without it completion is 5500 not performed. The supported completion types are the same as 5501 that can be supplied to a user-defined command using the 5502 "-complete=" argument. Refer to |:command-completion| for 5503 more information. Example: >vim 5504 let fname = input("File: ", "", "file") 5505 5506< *input()-highlight* *E5400* *E5402* 5507 The optional `highlight` key allows specifying function which 5508 will be used for highlighting user input. This function 5509 receives user input as its only argument and must return 5510 a list of 3-tuples [hl_start_col, hl_end_col + 1, hl_group] 5511 where 5512 hl_start_col is the first highlighted column, 5513 hl_end_col is the last highlighted column (+ 1!), 5514 hl_group is |:hi| group used for highlighting. 5515 *E5403* *E5404* *E5405* *E5406* 5516 Both hl_start_col and hl_end_col + 1 must point to the start 5517 of the multibyte character (highlighting must not break 5518 multibyte characters), hl_end_col + 1 may be equal to the 5519 input length. Start column must be in range [0, len(input)), 5520 end column must be in range (hl_start_col, len(input)], 5521 sections must be ordered so that next hl_start_col is greater 5522 then or equal to previous hl_end_col. 5523 5524 Example (try some input with parentheses): >vim 5525 highlight RBP1 guibg=Red ctermbg=red 5526 highlight RBP2 guibg=Yellow ctermbg=yellow 5527 highlight RBP3 guibg=Green ctermbg=green 5528 highlight RBP4 guibg=Blue ctermbg=blue 5529 let g:rainbow_levels = 4 5530 function! RainbowParens(cmdline) 5531 let ret = [] 5532 let i = 0 5533 let lvl = 0 5534 while i < len(a:cmdline) 5535 if a:cmdline[i] is# '(' 5536 call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)]) 5537 let lvl += 1 5538 elseif a:cmdline[i] is# ')' 5539 let lvl -= 1 5540 call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)]) 5541 endif 5542 let i += 1 5543 endwhile 5544 return ret 5545 endfunction 5546 call input({'prompt':'>','highlight':'RainbowParens'}) 5547< 5548 Highlight function is called at least once for each new 5549 displayed input string, before command-line is redrawn. It is 5550 expected that function is pure for the duration of one input() 5551 call, i.e. it produces the same output for the same input, so 5552 output may be memoized. Function is run like under |:silent| 5553 modifier. If the function causes any errors, it will be 5554 skipped for the duration of the current input() call. 5555 5556 Highlighting is disabled if command-line contains arabic 5557 characters. 5558 5559 NOTE: This function must not be used in a startup file, for 5560 the versions that only run in GUI mode (e.g., the Win32 GUI). 5561 Note: When input() is called from within a mapping it will 5562 consume remaining characters from that mapping, because a 5563 mapping is handled like the characters were typed. 5564 Use |inputsave()| before input() and |inputrestore()| 5565 after input() to avoid that. Another solution is to avoid 5566 that further characters follow in the mapping, e.g., by using 5567 |:execute| or |:normal|. 5568 5569 Example with a mapping: >vim 5570 nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR> 5571 function GetFoo() 5572 call inputsave() 5573 let g:Foo = input("enter search pattern: ") 5574 call inputrestore() 5575 endfunction 5576< 5577 5578 Parameters: ~ 5579 • {opts} (`table`) 5580 5581 Return: ~ 5582 (`string`) 5583 5584inputlist({textlist}) *inputlist()* 5585 Lua: Prefer |vim.ui.select()| for simple selection menus; 5586 callback, returned item, and out-of-range semantics differ. 5587 5588 Displays a list of strings and prompts the user to select 5589 one by entering a number. {textlist} must be a |List| of 5590 strings. Returns the number the user entered. 5591 The user can also select an item by clicking on it with the 5592 mouse, if the mouse is enabled in the command line ('mouse' is 5593 "a" or includes "c"). For the first string 0 is returned. 5594 When clicking above the first item a negative number is 5595 returned. When clicking on the prompt one more than the 5596 length of {textlist} is returned. 5597 Make sure {textlist} has less than 'lines' entries, otherwise 5598 it won't work. It's a good idea to put the entry number at 5599 the start of the string. And put a prompt in the first item. 5600 Example: >vim 5601 let color = inputlist(['Select color:', '1. red', 5602 \ '2. green', '3. blue']) 5603< 5604 5605 Parameters: ~ 5606 • {textlist} (`string[]`) 5607 5608 Return: ~ 5609 (`any`) 5610 5611inputrestore() *inputrestore()* 5612 Restore typeahead that was saved with a previous |inputsave()|. 5613 Should be called the same number of times |inputsave()| is 5614 called. Calling it more often is harmless though. 5615 Returns TRUE when there is nothing to restore, FALSE 5616 otherwise. 5617 5618 Return: ~ 5619 (`integer`) 5620 5621inputsave() *inputsave()* 5622 Preserve typeahead (also from mappings) and clear it, so that 5623 a following prompt gets input from the user. Should be 5624 followed by a matching |inputrestore()| after the prompt. Can 5625 be used several times, in which case there must be just as 5626 many |inputrestore()| calls. 5627 Returns TRUE when out of memory, FALSE otherwise. 5628 5629 Return: ~ 5630 (`integer`) 5631 5632inputsecret({prompt} [, {text}]) *inputsecret()* 5633 This function acts much like the |input()| function with but 5634 two exceptions: 5635 a) the user's response will be displayed as a sequence of 5636 asterisks ("*") thereby keeping the entry secret, and 5637 b) the user's response will not be recorded on the input 5638 |history| stack. 5639 The result is a String, which is whatever the user actually 5640 typed on the command-line in response to the issued prompt. 5641 NOTE: Command-line completion is not supported. 5642 5643 Parameters: ~ 5644 • {prompt} (`string`) 5645 • {text} (`string?`) 5646 5647 Return: ~ 5648 (`string`) 5649 5650insert({object}, {item} [, {idx}]) *insert()* 5651 Lua: Prefer |table.insert()| for lists; blob insertion and 5652 negative indexes differ. 5653 5654 When {object} is a |List| or a |Blob| insert {item} at the start 5655 of it. 5656 5657 If {idx} is specified insert {item} before the item with index 5658 {idx}. If {idx} is zero it goes before the first item, just 5659 like omitting {idx}. A negative {idx} is also possible, see 5660 |list-index|. -1 inserts just before the last item. 5661 5662 Returns the resulting |List| or |Blob|. Examples: >vim 5663 let mylist = insert([2, 3, 5], 1) 5664 call insert(mylist, 4, -1) 5665 call insert(mylist, 6, len(mylist)) 5666< The last example can be done simpler with |add()|. 5667 Note that when {item} is a |List| it is inserted as a single 5668 item. Use |extend()| to concatenate |Lists|. 5669 5670 Parameters: ~ 5671 • {object} (`any`) 5672 • {item} (`any`) 5673 • {idx} (`integer?`) 5674 5675 Return: ~ 5676 (`any`) 5677 5678interrupt() *interrupt()* 5679 Interrupt script execution. It works more or less like the 5680 user typing CTRL-C, most commands won't execute and control 5681 returns to the user. This is useful to abort execution 5682 from lower down, e.g. in an autocommand. Example: >vim 5683 function s:check_typoname(file) 5684 if fnamemodify(a:file, ':t') == '[' 5685 echomsg 'Maybe typo' 5686 call interrupt() 5687 endif 5688 endfunction 5689 au BufWritePre * call s:check_typoname(expand('<amatch>')) 5690< 5691 5692 Return: ~ 5693 (`any`) 5694 5695invert({expr}) *invert()* 5696 Lua: Prefer |bit.bnot()|. 5697 5698 Bitwise invert. The argument is converted to a number. A 5699 List, Dict or Float argument causes an error. Example: >vim 5700 let bits = invert(bits) 5701< 5702 5703 Parameters: ~ 5704 • {expr} (`integer`) 5705 5706 Return: ~ 5707 (`integer`) 5708 5709isabsolutepath({path}) *isabsolutepath()* 5710 Checks whether {path} is an absolute path. Returns |TRUE| 5711 if so, |FALSE| otherwise. 5712 On Unix, a path is considered absolute when it starts with 5713 '/'. 5714 On MS-Windows, it is considered absolute when it starts with 5715 an optional drive prefix and is followed by a '\' or '/'. UNC 5716 paths are always absolute. 5717 Example: >vim 5718 echo isabsolutepath('/usr/share/') " 1 5719 echo isabsolutepath('./foobar') " 0 5720 echo isabsolutepath('C:\Windows') " 1 5721 echo isabsolutepath('foobar') " 0 5722 echo isabsolutepath('\\remote\file') " 1 5723< 5724 5725 Attributes: ~ 5726 |api-fast| 5727 5728 Parameters: ~ 5729 • {path} (`string`) 5730 5731 Return: ~ 5732 (`0|1`) 5733 5734isdirectory({directory}) *isdirectory()* 5735 Lua: Prefer |uv.fs_stat()| and check `type == "directory"`. 5736 5737 Returns |TRUE| if {directory} exists, or |FALSE| if it doesn't 5738 exist or isn't a directory. {directory} is any expression, 5739 which is used as a String. 5740 5741 Attributes: ~ 5742 |api-fast| 5743 5744 Parameters: ~ 5745 • {directory} (`string`) 5746 5747 Return: ~ 5748 (`0|1`) 5749 5750isinf({expr}) *isinf()* 5751 Lua: Prefer 5752 `expr == math.huge and 1 or expr == -math.huge and -1 or 0`. 5753 5754 Return 1 if {expr} is a positive infinity, or -1 a negative 5755 infinity, otherwise 0. >vim 5756 echo isinf(1.0 / 0.0) 5757< 1 >vim 5758 echo isinf(-1.0 / 0.0) 5759< -1 5760 5761 Parameters: ~ 5762 • {expr} (`number`) 5763 5764 Return: ~ 5765 (`1|0|-1`) 5766 5767islocked({expr}) *islocked()* *E786* 5768 Returns |TRUE| if {expr} is the name of a locked variable, 5769 else |FALSE|. 5770 The string argument {expr} must be the name of a variable, 5771 |List| item or |Dictionary| entry, not the variable itself! 5772 Example: >vim 5773 let alist = [0, ['a', 'b'], 2, 3] 5774 lockvar 1 alist 5775 echo islocked('alist') " 1 5776 echo islocked('alist[1]') " 0 5777 5778< When {expr} is a variable that does not exist you get an error 5779 message. Use |exists()| to check for existence. 5780 5781 Parameters: ~ 5782 • {expr} (`any`) 5783 5784 Return: ~ 5785 (`0|1`) 5786 5787isnan({expr}) *isnan()* 5788 Lua: Prefer `expr ~= expr`. 5789 5790 Return |TRUE| if {expr} is a float with value NaN. >vim 5791 echo isnan(0.0 / 0.0) 5792< 1 5793 5794 Parameters: ~ 5795 • {expr} (`number`) 5796 5797 Return: ~ 5798 (`0|1`) 5799 5800items({expr}) *items()* 5801 Lua: Prefer |pairs()| or |ipairs()|. 5802 5803 Return a |List| with all key/index and value pairs of {expr}. 5804 Each |List| item is a list with two items: 5805 - for a |Dict|: the key and the value 5806 - for a |List|, |Blob| or |String|: the index and the value 5807 The returned |List| is in arbitrary order for a |Dict|, 5808 otherwise it's in ascending order of the index. 5809 5810 Also see |keys()| and |values()|. 5811 5812 Example: >vim 5813 let mydict = #{a: 'red', b: 'blue'} 5814 for [key, value] in items(mydict) 5815 echo $"{key} = {value}" 5816 endfor 5817 echo items([1, 2, 3]) 5818 echo items("foobar") 5819 echo items(0z0102) 5820< 5821 5822 Parameters: ~ 5823 • {expr} (`table|string`) 5824 5825 Return: ~ 5826 (`any`) 5827 5828jobpid({job}) *jobpid()* 5829 Lua: Prefer |vim.system()| object `.pid`; |job-id| and channel 5830 semantics differ. 5831 5832 Return the PID (process id) of |job-id| {job}. 5833 5834 Parameters: ~ 5835 • {job} (`integer`) 5836 5837 Return: ~ 5838 (`integer`) 5839 5840jobresize({job}, {width}, {height}) *jobresize()* 5841 Resize the pseudo terminal window of |job-id| {job} to {width} 5842 columns and {height} rows. 5843 Fails if the job was not started with `"pty":v:true`. 5844 5845 Parameters: ~ 5846 • {job} (`integer`) 5847 • {width} (`integer`) 5848 • {height} (`integer`) 5849 5850 Return: ~ 5851 (`any`) 5852 5853jobstart({cmd} [, {opts}]) *jobstart()* 5854 Lua: Prefer |vim.system()| for simple processes; |RPC|, 5855 PTY/term, streaming callbacks, and shell-string behavior 5856 differ. 5857 5858 Spawns {cmd} as a job. 5859 If {cmd} is a List it runs directly (no 'shell'). 5860 If {cmd} is a String it runs in the 'shell', like this: >vim 5861 call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}']) 5862< (See |shell-unquoting| for details.) 5863 5864 Example: start a job and handle its output: >vim 5865 call jobstart(['nvim', '-h'], {'on_stdout':{j,d,e->append(line('.'),d)}}) 5866< 5867 Example: start a job in a |terminal| connected to the current buffer: >vim 5868 call jobstart(['nvim', '-h'], {'term':v:true}) 5869< 5870 Returns |job-id| on success, 0 on invalid arguments (or job 5871 table is full), -1 if {cmd}[0] or 'shell' is not executable. 5872 The returned job-id is a valid |channel-id| representing the 5873 job's stdio streams. Use |chansend()| (or |rpcnotify()| and 5874 |rpcrequest()| if "rpc" was enabled) to send data to stdin and 5875 |chanclose()| to close the streams without stopping the job. 5876 5877 See |job-control| and |RPC|. 5878 5879 NOTE: on Windows if {cmd} is a List: 5880 - cmd[0] must be an executable (not a "built-in"). If it is 5881 in $PATH it can be called by name, without an extension: >vim 5882 call jobstart(['ping', 'neovim.io']) 5883< If it is a full or partial path, extension is required: >vim 5884 call jobstart(['System32\ping.exe', 'neovim.io']) 5885< - {cmd} is collapsed to a string of quoted args as expected 5886 by CommandLineToArgvW https://msdn.microsoft.com/bb776391 5887 unless cmd[0] is some form of "cmd.exe". 5888 5889 *jobstart-env* 5890 The job environment is initialized as follows: 5891 $NVIM is set to |v:servername| of the parent Nvim 5892 $NVIM_LISTEN_ADDRESS is unset 5893 $NVIM_LOG_FILE is unset 5894 $VIM is unset 5895 $VIMRUNTIME is unset 5896 You can set these with the `env` option. 5897 5898 *jobstart-options* 5899 {opts} is a dictionary with these keys: 5900 clear_env: (boolean) `env` defines the job environment 5901 exactly, instead of merging current environment. 5902 cwd: (string, default=|current-directory|) Working 5903 directory of the job. 5904 detach: (boolean) Detach the job process: it will not be 5905 killed when Nvim exits. If the process exits 5906 before Nvim, `on_exit` will be invoked. 5907 env: (dict) Map of environment variable name:value 5908 pairs extending (or replace with "clear_env") 5909 the current environment. |jobstart-env| 5910 height: (number) Height of the `pty` terminal. 5911 |on_exit|: (function) Callback invoked when the job exits. 5912 |on_stdout|: (function) Callback invoked when the job emits 5913 stdout data. 5914 |on_stderr|: (function) Callback invoked when the job emits 5915 stderr data. 5916 overlapped: (boolean) Sets FILE_FLAG_OVERLAPPED for the 5917 stdio passed to the child process. Only on 5918 MS-Windows; ignored on other platforms. 5919 pty: (boolean) Connect the job to a new pseudo 5920 terminal, and its streams to the master file 5921 descriptor. `on_stdout` receives all output, 5922 `on_stderr` is ignored. Note: if the child writes 5923 a query (DA1, OSC, …), it may hang or timeout waiting 5924 for a response! To avoid that, `on_stdout` should 5925 reply via |nvim_chan_send()| on the child's stdin. 5926 See |terminal-start| |terminal-concepts| 5927 rpc: (boolean) Use |msgpack-rpc| to communicate with 5928 the job over stdio. Then `on_stdout` is ignored, 5929 but `on_stderr` can still be used. 5930 stderr_buffered: (boolean) Collect data until EOF (stream closed) 5931 before invoking `on_stderr`. |channel-buffered| 5932 stdout_buffered: (boolean) Collect data until EOF (stream 5933 closed) before invoking `on_stdout`. |channel-buffered| 5934 stdin: (string) Either "pipe" (default) to connect the 5935 job's stdin to a channel or "null" to disconnect 5936 stdin. 5937 term: (boolean) Spawns {cmd} in a new pseudo-terminal 5938 session connected to the current (unmodified) buffer. 5939 Implies "pty". Defaults "height" and "width" to the 5940 current window dimensions. Defaults $TERM to 5941 "xterm-256color". 5942 width: (number) Width of the `pty` pseudo-terminal. 5943 5944 {opts} is passed as |self| dictionary to the callback; the 5945 caller may set other keys to pass application-specific data. 5946 5947 Returns: 5948 - |channel-id| on success 5949 - 0 on invalid arguments 5950 - -1 if {cmd}[0] is not executable. 5951 See also |job-control|, |channel|, |msgpack-rpc|. 5952 5953 Parameters: ~ 5954 • {cmd} (`string|string[]`) 5955 • {opts} (`table?`) 5956 5957 Return: ~ 5958 (`integer`) 5959 5960jobstop({id}) *jobstop()* 5961 Lua: Prefer |SystemObj:kill()| on a |vim.system()| object; 5962 |job-id| semantics differ. 5963 5964 Stop |job-id| {id} by sending SIGTERM to the job process. If 5965 the process does not terminate after a timeout then SIGKILL 5966 will be sent. When the job terminates its |on_exit| handler 5967 (if any) will be invoked. 5968 See |job-control|. 5969 5970 Returns 1 for valid job id, 0 for invalid id, including jobs have 5971 exited or stopped. 5972 5973 Parameters: ~ 5974 • {id} (`integer`) 5975 5976 Return: ~ 5977 (`integer`) 5978 5979jobwait({jobs} [, {timeout}]) *jobwait()* 5980 Lua: Prefer |SystemObj:wait()| on a |vim.system()| object; 5981 list input and status values differ. 5982 5983 Waits for jobs and their |on_exit| handlers to complete. 5984 5985 {jobs} is a List of |job-id|s to wait for. 5986 {timeout} is the maximum waiting time in milliseconds. If 5987 omitted or -1, wait forever. 5988 5989 Timeout of 0 can be used to check the status of a job: >vim 5990 let running = jobwait([{job-id}], 0)[0] == -1 5991< 5992 During jobwait() callbacks for jobs not in the {jobs} list may 5993 be invoked. The screen will not redraw unless |:redraw| is 5994 invoked by a callback. 5995 5996 Returns a list of len({jobs}) integers, where each integer is 5997 the status of the corresponding job: 5998 Exit-code, if the job exited 5999 -1 if the timeout was exceeded 6000 -2 if the job was interrupted (by |CTRL-C|) 6001 -3 if the job-id is invalid 6002 6003 Parameters: ~ 6004 • {jobs} (`integer[]`) 6005 • {timeout} (`integer?`) 6006 6007 Return: ~ 6008 (`integer[]`) 6009 6010join({list} [, {sep}]) *join()* 6011 Lua: Prefer |table.concat()| for string lists; non-string 6012 values stringify differently. 6013 6014 Join the items in {list} together into one String. 6015 When {sep} is specified it is put in between the items. If 6016 {sep} is omitted a single space is used. 6017 Note that {sep} is not added at the end. You might want to 6018 add it there too: >vim 6019 let lines = join(mylist, "\n") .. "\n" 6020< String items are used as-is. |Lists| and |Dictionaries| are 6021 converted into a string like with |string()|. 6022 The opposite function is |split()|. 6023 6024 Parameters: ~ 6025 • {list} (`any[]`) 6026 • {sep} (`string?`) 6027 6028 Return: ~ 6029 (`string`) 6030 6031json_decode({expr}) *json_decode()* 6032 Lua: Prefer |vim.json.decode()|. 6033 6034 Convert {expr} from JSON object. Accepts |readfile()|-style 6035 list as the input, as well as regular string. May output any 6036 Vim value. In the following cases it will output 6037 |msgpack-special-dict|: 6038 1. Dictionary contains duplicate key. 6039 2. String contains NUL byte. Two special dictionaries: for 6040 dictionary and for string will be emitted in case string 6041 with NUL byte was a dictionary key. 6042 6043 Note: function treats its input as UTF-8 always. The JSON 6044 standard allows only a few encodings, of which UTF-8 is 6045 recommended and the only one required to be supported. 6046 Non-UTF-8 characters are an error. 6047 6048 Parameters: ~ 6049 • {expr} (`any`) 6050 6051 Return: ~ 6052 (`any`) 6053 6054json_encode({expr}) *json_encode()* 6055 Lua: Prefer |vim.json.encode()|. 6056 6057 Convert {expr} into a JSON string. Accepts 6058 |msgpack-special-dict| as the input. Will not convert 6059 |Funcref|s, mappings with non-string keys (can be created as 6060 |msgpack-special-dict|), values with self-referencing 6061 containers, strings which contain non-UTF-8 characters, 6062 pseudo-UTF-8 strings which contain codepoints reserved for 6063 surrogate pairs (such strings are not valid UTF-8 strings). 6064 Non-printable characters are converted into "\u1234" escapes 6065 or special escapes like "\t", other are dumped as-is. 6066 |Blob|s are converted to arrays of the individual bytes. 6067 6068 Parameters: ~ 6069 • {expr} (`any`) 6070 6071 Return: ~ 6072 (`string`) 6073 6074keys({dict}) *keys()* 6075 Lua: Prefer |vim.tbl_keys()|. 6076 6077 Return a |List| with all the keys of {dict}. The |List| is in 6078 arbitrary order. Also see |items()| and |values()|. 6079 6080 Parameters: ~ 6081 • {dict} (`table`) 6082 6083 Return: ~ 6084 (`string[]`) 6085 6086keytrans({string}) *keytrans()* 6087 Turn the internal byte representation of keys into a form that 6088 can be used for |:map|. E.g. >vim 6089 let xx = "\<C-Home>" 6090 echo keytrans(xx) 6091< <C-Home> 6092 6093 Attributes: ~ 6094 |api-fast| 6095 6096 Parameters: ~ 6097 • {string} (`string`) 6098 6099 Return: ~ 6100 (`string`) 6101 6102len({expr}) *len()* *E701* 6103 Lua: Prefer Lua `#` operator for strings and lists or 6104 `#vim.tbl_keys(expr)` for dicts. 6105 6106 Returns the length of the argument. 6107 When {expr} is a String or a Number the length in bytes is 6108 used, as with |strlen()|. 6109 When {expr} is a |List| the number of items in the |List| is 6110 returned. 6111 When {expr} is a |Blob| the number of bytes is returned. 6112 When {expr} is a |Dictionary| the number of entries in the 6113 |Dictionary| is returned. 6114 Otherwise an error is given and returns zero. 6115 6116 Parameters: ~ 6117 • {expr} (`any[]`) 6118 6119 Return: ~ 6120 (`integer`) 6121 6122libcall({libname}, {funcname}, {argument}) *libcall()* *E364* *E368* 6123 Lua: Prefer |package.loadlib()| or `ffi.load()`. 6124 6125 Call function {funcname} in the run-time library {libname} 6126 with single argument {argument}. 6127 This is useful to call functions in a library that you 6128 especially made to be used with Vim. Since only one argument 6129 is possible, calling standard library functions is rather 6130 limited. 6131 The result is the String returned by the function. If the 6132 function returns NULL, this will appear as an empty string "" 6133 to Vim. 6134 If the function returns a number, use |libcallnr()|! 6135 If {argument} is a number, it is passed to the function as an 6136 int; if {argument} is a string, it is passed as a 6137 null-terminated string. 6138 6139 libcall() allows you to write your own 'plug-in' extensions to 6140 Vim without having to recompile the program. It is NOT a 6141 means to call system functions! If you try to do so Vim will 6142 very probably crash. 6143 6144 For Win32, the functions you write must be placed in a DLL 6145 and use the normal C calling convention (NOT Pascal which is 6146 used in Windows System DLLs). The function must take exactly 6147 one parameter, either a character pointer or a long integer, 6148 and must return a character pointer or NULL. The character 6149 pointer returned must point to memory that will remain valid 6150 after the function has returned (e.g. in static data in the 6151 DLL). If it points to allocated memory, that memory will 6152 leak away. Using a static buffer in the function should work, 6153 it's then freed when the DLL is unloaded. 6154 6155 WARNING: If the function returns a non-valid pointer, Vim may 6156 crash! This also happens if the function returns a number, 6157 because Vim thinks it's a pointer. 6158 For Win32 systems, {libname} should be the filename of the DLL 6159 without the ".DLL" suffix. A full path is only required if 6160 the DLL is not in the usual places. 6161 For Unix: When compiling your own plugins, remember that the 6162 object code must be compiled as position-independent ('PIC'). 6163 Examples: >vim 6164 echo libcall("libc.so", "getenv", "HOME") 6165< 6166 6167 Parameters: ~ 6168 • {libname} (`string`) 6169 • {funcname} (`string`) 6170 • {argument} (`any`) 6171 6172 Return: ~ 6173 (`any`) 6174 6175libcallnr({libname}, {funcname}, {argument}) *libcallnr()* 6176 Lua: Prefer |package.loadlib()| or `ffi.load()`. 6177 6178 Just like |libcall()|, but used for a function that returns an 6179 int instead of a string. 6180 Examples: >vim 6181 echo libcallnr("/usr/lib/libc.so", "getpid", "") 6182 call libcallnr("libc.so", "printf", "Hello World!\n") 6183 call libcallnr("libc.so", "sleep", 10) 6184< 6185 6186 Parameters: ~ 6187 • {libname} (`string`) 6188 • {funcname} (`string`) 6189 • {argument} (`any`) 6190 6191 Return: ~ 6192 (`any`) 6193 6194line({expr} [, {winid}]) *line()* 6195 Lua: Prefer |nvim_win_get_cursor()| for "." or 6196 |nvim_buf_line_count()| for "$"; marks, lists, and other 6197 position expressions differ. 6198 6199 See |getpos()| for accepted positions. 6200 6201 To get the column number use |col()|. To get both use 6202 |getpos()|. 6203 6204 With the optional {winid} argument the values are obtained for 6205 that window instead of the current window. 6206 6207 Returns 0 for invalid values of {expr} and {winid}. 6208 6209 Examples: >vim 6210 echo line(".") " line number of the cursor 6211 echo line(".", winid) " idem, in window "winid" 6212 echo line("'t") " line number of mark t 6213 echo line("'" .. marker) " line number of mark marker 6214< 6215 To jump to the last known position when opening a file see 6216 |last-position-jump|. 6217 6218 Parameters: ~ 6219 • {expr} (`string|integer[]`) 6220 • {winid} (`integer?`) 6221 6222 Return: ~ 6223 (`integer`) 6224 6225line2byte({lnum}) *line2byte()* 6226 Lua: Prefer |nvim_buf_get_offset()| with `lnum - 1`; 6227 'fileformat' and invalid-line semantics differ. 6228 6229 Return the byte count from the start of the buffer for line 6230 {lnum}. This includes the end-of-line character, depending on 6231 the 'fileformat' option for the current buffer. The first 6232 line returns 1. UTF-8 encoding is used, 'fileencoding' is 6233 ignored. This can also be used to get the byte count for the 6234 line just below the last line: >vim 6235 echo line2byte(line("$") + 1) 6236< This is the buffer size plus one. If 'fileencoding' is empty 6237 it is the file size plus one. {lnum} is used like with 6238 |getline()|. When {lnum} is invalid -1 is returned. 6239 Also see |byte2line()|, |go| and |:goto|. 6240 6241 Parameters: ~ 6242 • {lnum} (`integer|string`) 6243 6244 Return: ~ 6245 (`integer`) 6246 6247lispindent({lnum}) *lispindent()* 6248 Get the amount of indent for line {lnum} according the lisp 6249 indenting rules, as with 'lisp'. 6250 The indent is counted in spaces, the value of 'tabstop' is 6251 relevant. {lnum} is used just like in |getline()|. 6252 When {lnum} is invalid, -1 is returned. 6253 6254 Parameters: ~ 6255 • {lnum} (`integer|string`) 6256 6257 Return: ~ 6258 (`integer`) 6259 6260list2blob({list}) *list2blob()* 6261 Return a Blob concatenating all the number values in {list}. 6262 Examples: >vim 6263 echo list2blob([1, 2, 3, 4]) " returns 0z01020304 6264 echo list2blob([]) " returns 0z 6265< Returns an empty Blob on error. If one of the numbers is 6266 negative or more than 255 error *E1239* is given. 6267 6268 |blob2list()| does the opposite. 6269 6270 Parameters: ~ 6271 • {list} (`any[]`) 6272 6273 Return: ~ 6274 (`string`) 6275 6276list2str({list} [, {utf8}]) *list2str()* 6277 Converts each codepoint in {list} to a UTF-8 character and 6278 returns the concatenated string. Examples: >vim 6279 echo list2str([32]) " returns " " 6280 echo list2str([65, 66, 67]) " returns "ABC" 6281< The same can be done (slowly) with: >vim 6282 echo join(map(list, {nr, val -> nr2char(val)}), '') 6283< |str2list()| does the opposite. 6284 6285 UTF-8 encoding is always used, {utf8} option has no effect, 6286 and exists only for backwards-compatibility. 6287 With UTF-8 composing characters work as expected: >vim 6288 echo list2str([97, 769]) " returns "á" 6289< 6290 Returns an empty string on error. 6291 6292 Parameters: ~ 6293 • {list} (`any[]`) 6294 • {utf8} (`boolean?`) 6295 6296 Return: ~ 6297 (`string`) 6298 6299localtime() *localtime()* 6300 Lua: Prefer |os.time()|. 6301 6302 Return the current time, measured as seconds since 1st Jan 6303 1970. See also |strftime()|, |strptime()| and |getftime()|. 6304 6305 Return: ~ 6306 (`integer`) 6307 6308log({expr}) *log()* 6309 Lua: Prefer |math.log()|. 6310 6311 Return the natural logarithm (base e) of {expr} as a |Float|. 6312 {expr} must evaluate to a |Float| or a |Number| in the range 6313 (0, inf]. 6314 Returns 0.0 if {expr} is not a |Float| or a |Number|. 6315 Examples: >vim 6316 echo log(10) 6317< 2.302585 >vim 6318 echo log(exp(5)) 6319< 5.0 6320 6321 Parameters: ~ 6322 • {expr} (`number`) 6323 6324 Return: ~ 6325 (`number`) 6326 6327log10({expr}) *log10()* 6328 Lua: Prefer |math.log10()|. 6329 6330 Return the logarithm of Float {expr} to base 10 as a |Float|. 6331 {expr} must evaluate to a |Float| or a |Number|. 6332 Returns 0.0 if {expr} is not a |Float| or a |Number|. 6333 Examples: >vim 6334 echo log10(1000) 6335< 3.0 >vim 6336 echo log10(0.01) 6337< -2.0 6338 6339 Parameters: ~ 6340 • {expr} (`number`) 6341 6342 Return: ~ 6343 (`number`) 6344 6345luaeval({expr} [, {expr}]) *luaeval()* 6346 Lua: Prefer plain Lua expressions and values directly. 6347 6348 Evaluate Lua expression {expr} and return its result converted 6349 to Vim data structures. See |lua-eval| for details. 6350 6351 See also |v:lua-call|. 6352 6353 Parameters: ~ 6354 • {expr} (`string`) 6355 • {expr1} (`any[]?`) 6356 6357 Return: ~ 6358 (`any`) 6359 6360map({expr1}, {expr2}) *map()* 6361 Lua: Prefer |vim.tbl_map()| for array-like tables; dict, 6362 string, blob, and in-place behavior differ. 6363 6364 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 6365 When {expr1} is a |List| or |Dictionary|, replace each 6366 item in {expr1} with the result of evaluating {expr2}. 6367 For a |Blob| each byte is replaced. 6368 For a |String|, each character, including composing 6369 characters, is replaced. 6370 If the item type changes you may want to use |mapnew()| to 6371 create a new List or Dictionary. 6372 6373 {expr2} must be a |String| or |Funcref|. 6374 6375 If {expr2} is a |String|, inside {expr2} |v:val| has the value 6376 of the current item. For a |Dictionary| |v:key| has the key 6377 of the current item and for a |List| |v:key| has the index of 6378 the current item. For a |Blob| |v:key| has the index of the 6379 current byte. For a |String| |v:key| has the index of the 6380 current character. 6381 Example: >vim 6382 call map(mylist, '"> " .. v:val .. " <"') 6383< This puts "> " before and " <" after each item in "mylist". 6384 6385 Note that {expr2} is the result of an expression and is then 6386 used as an expression again. Often it is good to use a 6387 |literal-string| to avoid having to double backslashes. You 6388 still have to double single (') quotes, though. 6389 6390 If {expr2} is a |Funcref| it is called with two arguments: 6391 1. The key or the index of the current item. 6392 2. the value of the current item. 6393 The function must return the new value of the item. Example 6394 that changes each value by "key-value": >vim 6395 func KeyValue(key, val) 6396 return a:key .. '-' .. a:val 6397 endfunc 6398 call map(myDict, function('KeyValue')) 6399< It is shorter when using a |lambda|: >vim 6400 call map(myDict, {key, val -> key .. '-' .. val}) 6401< If you do not use "val" you can leave it out: >vim 6402 call map(myDict, {key -> 'item: ' .. key}) 6403< If you do not use "key" you can use a short name: >vim 6404 call map(myDict, {_, val -> 'item: ' .. val}) 6405< 6406 The operation is done in-place for a |List| and |Dictionary|. 6407 If you want it to remain unmodified make a copy first: >vim 6408 let tlist = map(copy(mylist), ' v:val .. "\t"') 6409 6410< Returns {expr1}, the |List| or |Dictionary| that was filtered, 6411 or a new |Blob| or |String|. 6412 When an error is encountered while evaluating {expr2} no 6413 further items in {expr1} are processed. 6414 When {expr2} is a Funcref errors inside a function are 6415 ignored, unless it was defined with the "abort" flag. 6416 6417 Parameters: ~ 6418 • {expr1} (`string|table|any[]`) 6419 • {expr2} (`string|function`) 6420 6421 Return: ~ 6422 (`any`) 6423 6424maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* 6425 When {dict} is omitted or zero: Return the rhs of mapping 6426 {name} in mode {mode}. The returned String has special 6427 characters translated like in the output of the ":map" command 6428 listing. When {dict} is TRUE a dictionary is returned, see 6429 below. To get a list of all mappings see |maplist()|. 6430 6431 When there is no mapping for {name}, an empty String is 6432 returned if {dict} is FALSE, otherwise returns an empty Dict. 6433 When the mapping for {name} is empty, then "<Nop>" is 6434 returned. 6435 6436 The {name} can have special key names, like in the ":map" 6437 command. 6438 6439 {mode} can be one of these strings: 6440 "n" Normal 6441 "v" Visual (including Select) 6442 "o" Operator-pending 6443 "i" Insert 6444 "c" Cmd-line 6445 "s" Select 6446 "x" Visual 6447 "l" langmap |language-mapping| 6448 "t" Terminal 6449 "" Normal, Visual and Operator-pending 6450 When {mode} is omitted, the modes for "" are used. 6451 6452 When {abbr} is there and it is |TRUE| use abbreviations 6453 instead of mappings. 6454 6455 When {dict} is |TRUE|, return a dictionary describing the 6456 mapping, with these items: *mapping-dict* 6457 "lhs" The {lhs} of the mapping as it would be typed 6458 "lhsraw" The {lhs} of the mapping as raw bytes 6459 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate 6460 form, only present when it differs from "lhsraw" 6461 "rhs" The {rhs} of the mapping as typed. 6462 "callback" Lua function, if RHS was defined as such. 6463 "silent" 1 for a |:map-silent| mapping, else 0. 6464 "noremap" 1 if the {rhs} of the mapping is not remappable. 6465 "script" 1 if mapping was defined with <script>. 6466 "expr" 1 for an expression mapping (|:map-<expr>|). 6467 "buffer" 1 for a buffer local mapping (|:map-local|). 6468 "mode" Modes for which the mapping is defined. In 6469 addition to the modes mentioned above, these 6470 characters will be used: 6471 " " Normal, Visual and Operator-pending 6472 "!" Insert and Commandline mode 6473 (|mapmode-ic|) 6474 "sid" The script local ID, used for <sid> mappings 6475 (|<SID>|). Negative for special contexts. 6476 "scriptversion" The version of the script, always 1. 6477 "lnum" The line number in "sid", zero if unknown. 6478 "nowait" Do not wait for other, longer mappings. 6479 (|:map-<nowait>|). 6480 "abbr" True if this is an |abbreviation|. 6481 "mode_bits" Nvim's internal binary representation of "mode". 6482 |mapset()| ignores this; only "mode" is used. 6483 See |maplist()| for usage examples. The values 6484 are from src/nvim/state_defs.h and may change in 6485 the future. 6486 6487 The dictionary can be used to restore a mapping with 6488 |mapset()|. 6489 6490 The mappings local to the current buffer are checked first, 6491 then the global mappings. 6492 This function can be used to map a key even when it's already 6493 mapped, and have it do the original mapping too. Sketch: >vim 6494 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n') 6495< 6496 6497 Parameters: ~ 6498 • {name} (`string`) 6499 • {mode} (`string?`) 6500 • {abbr} (`boolean?`) 6501 • {dict} (`false?`) 6502 6503 Return: ~ 6504 (`string`) 6505 6506mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()* 6507 Check if there is a mapping that matches with {name} in mode 6508 {mode}. See |maparg()| for {mode} and special names in 6509 {name}. 6510 When {abbr} is there and it is non-zero use abbreviations 6511 instead of mappings. 6512 A match happens with a mapping that starts with {name} and 6513 with a mapping which is equal to the start of {name}. 6514 6515 matches mapping "a" "ab" "abc" ~ 6516 mapcheck("a") yes yes yes 6517 mapcheck("abc") yes yes yes 6518 mapcheck("ax") yes no no 6519 mapcheck("b") no no no 6520 6521 The difference with |maparg()| is that mapcheck() finds a 6522 mapping that matches with {name}, while |maparg()| only finds a 6523 mapping for {name} exactly. 6524 When there is no mapping that starts with {name}, an empty 6525 String is returned. If there is one, the RHS of that mapping 6526 is returned. If there are several mappings that start with 6527 {name}, the RHS of one of them is returned. This will be 6528 "<Nop>" if the RHS is empty. 6529 The mappings local to the current buffer are checked first, 6530 then the global mappings. 6531 This function can be used to check if a mapping can be added 6532 without being ambiguous. Example: >vim 6533 if mapcheck("_vv") == "" 6534 map _vv :set guifont=7x13<CR> 6535 endif 6536< This avoids adding the "_vv" mapping when there already is a 6537 mapping for "_v" or for "_vvv". 6538 6539 Parameters: ~ 6540 • {name} (`string`) 6541 • {mode} (`string?`) 6542 • {abbr} (`boolean?`) 6543 6544 Return: ~ 6545 (`any`) 6546 6547maplist([{abbr}]) *maplist()* 6548 Returns a |List| of all mappings. Each List item is a |Dict|, 6549 the same as what is returned by |maparg()|, see 6550 |mapping-dict|. When {abbr} is there and it is |TRUE| use 6551 abbreviations instead of mappings. 6552 6553 Example to show all mappings with "MultiMatch" in rhs: >vim 6554 echo maplist()->filter({_, m -> 6555 \ match(get(m, 'rhs', ''), 'MultiMatch') >= 0 6556 \ }) 6557< It can be tricky to find mappings for particular |:map-modes|. 6558 |mapping-dict|'s "mode_bits" can simplify this. For example, 6559 the mode_bits for Normal, Insert or Command-line modes are 6560 0x19. To find all the mappings available in those modes you 6561 can do: >vim 6562 let saved_maps = [] 6563 for m in maplist() 6564 if and(m.mode_bits, 0x19) != 0 6565 eval saved_maps->add(m) 6566 endif 6567 endfor 6568 echo saved_maps->mapnew({_, m -> m.lhs}) 6569< The values of the mode_bits are defined in Nvim's 6570 src/nvim/state_defs.h file and they can be discovered at 6571 runtime using |:map-commands| and "maplist()". Example: >vim 6572 omap xyzzy <Nop> 6573 let op_bit = maplist()->filter( 6574 \ {_, m -> m.lhs == 'xyzzy'})[0].mode_bits 6575 ounmap xyzzy 6576 echo printf("Operator-pending mode bit: 0x%x", op_bit) 6577< 6578 6579 Parameters: ~ 6580 • {abbr} (`0|1?`) 6581 6582 Return: ~ 6583 (`table[]`) 6584 6585mapnew({expr1}, {expr2}) *mapnew()* 6586 Lua: Prefer |vim.tbl_map()| for tables; string, blob, and 6587 `v:key` callback behavior differ. 6588 6589 Like |map()| but instead of replacing items in {expr1} a new 6590 List or Dictionary is created and returned. {expr1} remains 6591 unchanged. Items can still be changed by {expr2}, if you 6592 don't want that use |deepcopy()| first. 6593 6594 Parameters: ~ 6595 • {expr1} (`any`) 6596 • {expr2} (`any`) 6597 6598 Return: ~ 6599 (`any`) 6600 6601mapset({mode}, {abbr}, {dict}) *mapset()* 6602mapset({dict}) 6603 Restore a mapping from a dictionary, possibly returned by 6604 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer 6605 is true, is set on the current buffer; it is up to the caller 6606 to ensure that the intended buffer is the current buffer. 6607 This feature allows copying mappings from one buffer to 6608 another. 6609 The dict.mode value may restore a single mapping that covers 6610 more than one mode, like with mode values of '!', ' ', "nox", 6611 or 'v'. *E1276* 6612 6613 In the first form, {mode} and {abbr} should be the same as 6614 for the call to |maparg()|. *E460* 6615 {mode} is used to define the mode in which the mapping is set, 6616 not the "mode" entry in {dict}. 6617 Example for saving and restoring a mapping: >vim 6618 let save_map = maparg('K', 'n', 0, 1) 6619 nnoremap K somethingelse 6620 " ... 6621 call mapset('n', 0, save_map) 6622< Note that if you are going to replace a map in several modes, 6623 e.g. with `:map!`, you need to save/restore the mapping for 6624 all of them, when they might differ. 6625 6626 In the second form, with {dict} as the only argument, mode 6627 and abbr are taken from the dict. 6628 Example: >vim 6629 let save_maps = maplist()->filter( 6630 \ {_, m -> m.lhs == 'K'}) 6631 nnoremap K somethingelse 6632 cnoremap K somethingelse2 6633 " ... 6634 unmap K 6635 for d in save_maps 6636 call mapset(d) 6637 endfor 6638< 6639 6640 Parameters: ~ 6641 • {dict} (`table<string,any>`) 6642 6643 Return: ~ 6644 (`any`) 6645 6646match({expr}, {pat} [, {start} [, {count}]]) *match()* 6647 When {expr} is a |List| then this returns the index of the 6648 first item where {pat} matches. Each item is used as a 6649 String, |Lists| and |Dictionaries| are used as echoed. 6650 6651 Otherwise, {expr} is used as a String. The result is a 6652 Number, which gives the index (byte offset) in {expr} where 6653 {pat} matches. 6654 6655 A match at the first character or |List| item returns zero. 6656 If there is no match -1 is returned. 6657 6658 For getting submatches see |matchlist()|. 6659 Example: >vim 6660 echo match("testing", "ing") " results in 4 6661 echo match([1, 'x'], '\a') " results in 1 6662< See |string-match| for how {pat} is used. 6663 *strpbrk()* 6664 Vim doesn't have a strpbrk() function. But you can do: >vim 6665 let sepidx = match(line, '[.,;: \t]') 6666< *strcasestr()* 6667 Vim doesn't have a strcasestr() function. But you can add 6668 "\c" to the pattern to ignore case: >vim 6669 let idx = match(haystack, '\cneedle') 6670< 6671 If {start} is given, the search starts from byte index 6672 {start} in a String or item {start} in a |List|. 6673 The result, however, is still the index counted from the 6674 first character/item. Example: >vim 6675 echo match("testing", "ing", 2) 6676< result is again "4". >vim 6677 echo match("testing", "ing", 4) 6678< result is again "4". >vim 6679 echo match("testing", "t", 2) 6680< result is "3". 6681 For a String, if {start} > 0 then it is like the string starts 6682 {start} bytes later, thus "^" will match at {start}. Except 6683 when {count} is given, then it's like matches before the 6684 {start} byte are ignored (this is a bit complicated to keep it 6685 backwards compatible). 6686 For a String, if {start} < 0, it will be set to 0. For a list 6687 the index is counted from the end. 6688 If {start} is out of range ({start} > strlen({expr}) for a 6689 String or {start} > len({expr}) for a |List|) -1 is returned. 6690 6691 When {count} is given use the {count}th match. When a match 6692 is found in a String the search for the next one starts one 6693 character further. Thus this example results in 1: >vim 6694 echo match("testing", "..", 0, 2) 6695< In a |List| the search continues in the next item. 6696 Note that when {count} is added the way {start} works changes, 6697 see above. 6698 6699 *match-pattern* 6700 See |pattern| for the patterns that are accepted. 6701 The 'ignorecase' option is used to set the ignore-caseness of 6702 the pattern. 'smartcase' is NOT used. The matching is always 6703 done like 'magic' is set and 'cpoptions' is empty. 6704 Note that a match at the start is preferred, thus when the 6705 pattern is using "*" (any number of matches) it tends to find 6706 zero matches at the start instead of a number of matches 6707 further down in the text. 6708 6709 Parameters: ~ 6710 • {expr} (`string|any[]`) 6711 • {pat} (`string`) 6712 • {start} (`integer?`) 6713 • {count} (`integer?`) 6714 6715 Return: ~ 6716 (`integer`) 6717 6718 *matchadd()* *E798* *E799* *E801* *E957* 6719matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) 6720 Defines a pattern to be highlighted in the current window (a 6721 "match"). It will be highlighted with {group}. Returns an 6722 identification number (ID), which can be used to delete the 6723 match using |matchdelete()|. The ID is bound to the window. 6724 Matching is case sensitive and magic, unless case sensitivity 6725 or magicness are explicitly overridden in {pattern}. The 6726 'magic', 'smartcase' and 'ignorecase' options are not used. 6727 The "Conceal" value is special, it causes the match to be 6728 concealed. 6729 6730 The optional {priority} argument assigns a priority to the 6731 match. A match with a high priority will have its 6732 highlighting overrule that of a match with a lower priority. 6733 A priority is specified as an integer (negative numbers are no 6734 exception). If the {priority} argument is not specified, the 6735 default priority is 10. The priority of 'hlsearch' is zero, 6736 hence all matches with a priority greater than zero will 6737 overrule it. Syntax highlighting (see 'syntax') is a separate 6738 mechanism, and regardless of the chosen priority a match will 6739 always overrule syntax highlighting. 6740 6741 The optional {id} argument allows the request for a specific 6742 match ID. If a specified ID is already taken, an error 6743 message will appear and the match will not be added. An ID 6744 is specified as a positive integer (zero excluded). IDs 1, 2 6745 and 3 are reserved for |:match|, |:2match| and |:3match|, 6746 respectively. 3 is reserved for use by the |matchparen| 6747 plugin. 6748 If the {id} argument is not specified or -1, |matchadd()| 6749 automatically chooses a free ID, which is at least 1000. 6750 6751 The optional {dict} argument allows for further custom 6752 values. Currently this is used to specify a match specific 6753 conceal character that will be shown for |hl-Conceal| 6754 highlighted matches. The dict can have the following members: 6755 6756 conceal Special character to show instead of the 6757 match (only for |hl-Conceal| highlighted 6758 matches, see |:syn-cchar|) 6759 window Use this |window-number| or |window-ID| instead 6760 of the current window. 6761 6762 The number of matches is not limited, as it is the case with 6763 the |:match| commands. 6764 6765 Returns -1 on error. 6766 6767 Example: >vim 6768 highlight MyGroup ctermbg=green guibg=green 6769 let m = matchadd("MyGroup", "TODO") 6770< Deletion of the pattern: >vim 6771 call matchdelete(m) 6772 6773< A list of matches defined by |matchadd()| and |:match| are 6774 available from |getmatches()|. All matches can be deleted in 6775 one operation by |clearmatches()|. 6776 6777 Parameters: ~ 6778 • {group} (`integer|string`) 6779 • {pattern} (`string`) 6780 • {priority} (`integer?`) 6781 • {id} (`integer?`) 6782 • {dict} (`table?`) 6783 6784 Return: ~ 6785 (`integer`) 6786 6787matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) *matchaddpos()* 6788 Same as |matchadd()|, but requires a list of positions {pos} 6789 instead of a pattern. This command is faster than |matchadd()| 6790 because it does not handle regular expressions and it sets 6791 buffer line boundaries to redraw screen. It is supposed to be 6792 used when fast match additions and deletions are required, for 6793 example to highlight matching parentheses. 6794 *E5030* *E5031* 6795 {pos} is a list of positions. Each position can be one of 6796 these: 6797 - A number. This whole line will be highlighted. The first 6798 line has number 1. 6799 - A list with one number, e.g., [23]. The whole line with 6800 this number will be highlighted. 6801 - A list with two numbers, e.g., [23, 11]. The first number 6802 is the line number, the second one is the column number 6803 (first column is 1, the value must correspond to the byte 6804 index as |col()| would return). The character at this 6805 position will be highlighted. 6806 - A list with three numbers, e.g., [23, 11, 3]. As above, but 6807 the third number gives the length of the highlight in bytes. 6808 6809 Entries with zero and negative line numbers are silently 6810 ignored, as well as entries with negative column numbers and 6811 lengths. 6812 6813 Returns -1 on error. 6814 6815 Example: >vim 6816 highlight MyGroup ctermbg=green guibg=green 6817 let m = matchaddpos("MyGroup", [[23, 24], 34]) 6818< Deletion of the pattern: >vim 6819 call matchdelete(m) 6820 6821< Matches added by |matchaddpos()| are returned by 6822 |getmatches()|. 6823 6824 Parameters: ~ 6825 • {group} (`integer|string`) 6826 • {pos} (`any[]`) 6827 • {priority} (`integer?`) 6828 • {id} (`integer?`) 6829 • {dict} (`table?`) 6830 6831 Return: ~ 6832 (`integer|table`) 6833 6834matcharg({nr}) *matcharg()* 6835 Selects the {nr} match item, as set with a |:match|, 6836 |:2match| or |:3match| command. 6837 Return a |List| with two elements: 6838 The name of the highlight group used 6839 The pattern used. 6840 When {nr} is not 1, 2 or 3 returns an empty |List|. 6841 When there is no match item set returns ['', '']. 6842 This is useful to save and restore a |:match|. 6843 Highlighting matches using the |:match| commands are limited 6844 to three matches. |matchadd()| does not have this limitation. 6845 6846 Parameters: ~ 6847 • {nr} (`integer`) 6848 6849 Return: ~ 6850 (`string[]`) 6851 6852matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}]) *matchbufline()* 6853 Returns the |List| of matches in lines from {lnum} to {end} in 6854 buffer {buf} where {pat} matches. 6855 6856 {lnum} and {end} can either be a line number or the string "$" 6857 to refer to the last line in {buf}. 6858 6859 The {dict} argument supports following items: 6860 submatches include submatch information (|/\(|) 6861 6862 For each match, a |Dict| with the following items is returned: 6863 byteidx starting byte index of the match 6864 lnum line number where there is a match 6865 text matched string 6866 Note that there can be multiple matches in a single line. 6867 6868 This function works only for loaded buffers. First call 6869 |bufload()| if needed. 6870 6871 See |match-pattern| for information about the effect of some 6872 option settings on the pattern. 6873 6874 When {buf} is not a valid buffer, the buffer is not loaded or 6875 {lnum} or {end} is not valid then an error is given and an 6876 empty |List| is returned. 6877 6878 Examples: >vim 6879 " Assuming line 3 in buffer 5 contains "a" 6880 echo matchbufline(5, '\<\k\+\>', 3, 3) 6881< `[{'lnum': 3, 'byteidx': 0, 'text': 'a'}]` >vim 6882 " Assuming line 4 in buffer 10 contains "tik tok" 6883 echo matchbufline(10, '\<\k\+\>', 1, 4) 6884< `[{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]` 6885 6886 If {submatch} is present and is v:true, then submatches like 6887 "\1", "\2", etc. are also returned. Example: >vim 6888 " Assuming line 2 in buffer 2 contains "acd" 6889 echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2 6890 \ {'submatches': v:true}) 6891< `[{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]` 6892 The "submatches" List always contains 9 items. If a submatch 6893 is not found, then an empty string is returned for that 6894 submatch. 6895 6896 Parameters: ~ 6897 • {buf} (`string|integer`) 6898 • {pat} (`string`) 6899 • {lnum} (`string|integer`) 6900 • {end} (`string|integer`) 6901 • {dict} (`table?`) 6902 6903 Return: ~ 6904 (`string[]`) 6905 6906matchdelete({id} [, {win}]) *matchdelete()* *E802* *E803* 6907 Deletes a match with ID {id} previously defined by |matchadd()| 6908 or one of the |:match| commands. Returns 0 if successful, 6909 otherwise -1. See example for |matchadd()|. All matches can 6910 be deleted in one operation by |clearmatches()|. 6911 {win} (if given) is a |window-number| or |window-ID|. 6912 6913 Parameters: ~ 6914 • {id} (`integer`) 6915 • {win} (`integer?`) 6916 6917 Return: ~ 6918 (`any`) 6919 6920matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()* 6921 Same as |match()|, but return the index of first character 6922 after the match. Example: >vim 6923 echo matchend("testing", "ing") 6924< results in "7". 6925 *strspn()* *strcspn()* 6926 Vim doesn't have a strspn() or strcspn() function, but you can 6927 do it with matchend(): >vim 6928 let span = matchend(line, '[a-zA-Z]') 6929 let span = matchend(line, '[^a-zA-Z]') 6930< Except that -1 is returned when there are no matches. 6931 6932 The {start}, if given, has the same meaning as for |match()|. >vim 6933 echo matchend("testing", "ing", 2) 6934< results in "7". >vim 6935 echo matchend("testing", "ing", 5) 6936< result is "-1". 6937 When {expr} is a |List| the result is equal to |match()|. 6938 6939 Parameters: ~ 6940 • {expr} (`any`) 6941 • {pat} (`string`) 6942 • {start} (`integer?`) 6943 • {count} (`integer?`) 6944 6945 Return: ~ 6946 (`integer`) 6947 6948matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()* 6949 If {list} is a list of strings, then returns a |List| with all 6950 the strings in {list} that fuzzy match {str}. The strings in 6951 the returned list are sorted based on the matching score. 6952 6953 The optional {dict} argument always supports the following 6954 items: 6955 matchseq When this item is present return only matches 6956 that contain the characters in {str} in the 6957 given sequence. 6958 limit Maximum number of matches in {list} to be 6959 returned. Zero means no limit. 6960 6961 If {list} is a list of dictionaries, then the optional {dict} 6962 argument supports the following additional items: 6963 key Key of the item which is fuzzy matched against 6964 {str}. The value of this item should be a 6965 string. 6966 text_cb |Funcref| that will be called for every item 6967 in {list} to get the text for fuzzy matching. 6968 This should accept a dictionary item as the 6969 argument and return the text for that item to 6970 use for fuzzy matching. 6971 6972 {str} is treated as a literal string and regular expression 6973 matching is NOT supported. Only the first 1024 characters of 6974 {str} and of each item in {list} are used for matching; 6975 characters beyond that are ignored. 6976 6977 When {str} has multiple words each separated by white space, 6978 then the list of strings that have all the words is returned. 6979 6980 If there are no matching strings or there is an error, then an 6981 empty list is returned. 6982 6983 When {limit} is given, matchfuzzy() will find up to this 6984 number of matches in {list} and return them in sorted order. 6985 6986 Refer to |fuzzy-matching| for more information about fuzzy 6987 matching strings. 6988 6989 Example: >vim 6990 echo matchfuzzy(["clay", "crow"], "cay") 6991< results in ["clay"]. >vim 6992 echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") 6993< results in a list of buffer names fuzzy matching "ndl". >vim 6994 echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'}) 6995< results in a list of buffer information dicts with buffer 6996 names fuzzy matching "ndl". >vim 6997 echo getbufinfo()->matchfuzzy("spl", 6998 \ {'text_cb' : {v -> v.name}}) 6999< results in a list of buffer information dicts with buffer 7000 names fuzzy matching "spl". >vim 7001 echo v:oldfiles->matchfuzzy("test") 7002< results in a list of file names fuzzy matching "test". >vim 7003 let l = readfile("buffer.c")->matchfuzzy("str") 7004< results in a list of lines in "buffer.c" fuzzy matching "str". >vim 7005 echo ['one two', 'two one']->matchfuzzy('two one') 7006< results in `['two one', 'one two']` . >vim 7007 echo ['one two', 'two one']->matchfuzzy('two one', 7008 \ {'matchseq': 1}) 7009< results in `['two one']`. 7010 7011 Parameters: ~ 7012 • {list} (`any[]`) 7013 • {str} (`string`) 7014 • {dict} (`table?`) 7015 7016 Return: ~ 7017 (`table`) 7018 7019matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()* 7020 Same as |matchfuzzy()|, but returns the list of matched 7021 strings, the list of character positions where characters 7022 in {str} matches and a list of matching scores. You can 7023 use |byteidx()| to convert a character position to a byte 7024 position. 7025 7026 If {str} matches multiple times in a string, then only the 7027 positions for the best match is returned. 7028 7029 If there are no matching strings or there is an error, then a 7030 list with three empty list items is returned. 7031 7032 Example: >vim 7033 echo matchfuzzypos(['testing'], 'tsg') 7034< results in [["testing"], [[0, 2, 6]], [99]] >vim 7035 echo matchfuzzypos(['clay', 'lacy'], 'la') 7036< results in [["lacy", "clay"], [[0, 1], [1, 2]], [153, 133]] >vim 7037 echo [{'text': 'hello', 'id' : 10}] 7038 \ ->matchfuzzypos('ll', {'key' : 'text'}) 7039< results in `[[{"id": 10, "text": "hello"}], [[2, 3]], [127]]` 7040 7041 Parameters: ~ 7042 • {list} (`any[]`) 7043 • {str} (`string`) 7044 • {dict} (`table?`) 7045 7046 Return: ~ 7047 (`table`) 7048 7049matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()* 7050 Same as |match()|, but return a |List|. The first item in the 7051 list is the matched string, same as what |matchstr()| would 7052 return. Following items are submatches, like "\1", "\2", etc. 7053 in |:substitute|. When an optional submatch didn't match an 7054 empty string is used. Example: >vim 7055 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)') 7056< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] 7057 When there is no match an empty list is returned. 7058 7059 You can pass in a List, but that is not very useful. 7060 7061 Parameters: ~ 7062 • {expr} (`any`) 7063 • {pat} (`string`) 7064 • {start} (`integer?`) 7065 • {count} (`integer?`) 7066 7067 Return: ~ 7068 (`string[]`) 7069 7070matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()* 7071 Same as |match()|, but return the matched string. Example: >vim 7072 echo matchstr("testing", "ing") 7073< results in "ing". 7074 When there is no match "" is returned. 7075 The {start}, if given, has the same meaning as for |match()|. >vim 7076 echo matchstr("testing", "ing", 2) 7077< results in "ing". >vim 7078 echo matchstr("testing", "ing", 5) 7079< result is "". 7080 When {expr} is a |List| then the matching item is returned. 7081 The type isn't changed, it's not necessarily a String. 7082 7083 Parameters: ~ 7084 • {expr} (`any`) 7085 • {pat} (`string`) 7086 • {start} (`integer?`) 7087 • {count} (`integer?`) 7088 7089 Return: ~ 7090 (`string`) 7091 7092matchstrlist({list}, {pat} [, {dict}]) *matchstrlist()* 7093 Returns the |List| of matches in {list} where {pat} matches. 7094 {list} is a |List| of strings. {pat} is matched against each 7095 string in {list}. 7096 7097 The {dict} argument supports following items: 7098 submatches include submatch information (|/\(|) 7099 7100 For each match, a |Dict| with the following items is returned: 7101 byteidx starting byte index of the match. 7102 idx index in {list} of the match. 7103 text matched string 7104 submatches a List of submatches. Present only if 7105 "submatches" is set to v:true in {dict}. 7106 7107 See |match-pattern| for information about the effect of some 7108 option settings on the pattern. 7109 7110 Example: >vim 7111 echo matchstrlist(['tik tok'], '\<\k\+\>') 7112< `[{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]` >vim 7113 echo matchstrlist(['a', 'b'], '\<\k\+\>') 7114< `[{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]` 7115 7116 If "submatches" is present and is v:true, then submatches like 7117 "\1", "\2", etc. are also returned. Example: >vim 7118 echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 7119 \ #{submatches: v:true}) 7120< `[{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]` 7121 The "submatches" List always contains 9 items. If a submatch 7122 is not found, then an empty string is returned for that 7123 submatch. 7124 7125 Parameters: ~ 7126 • {list} (`string[]`) 7127 • {pat} (`string`) 7128 • {dict} (`table?`) 7129 7130 Return: ~ 7131 (`string[]`) 7132 7133matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()* 7134 Same as |matchstr()|, but return the matched string, the start 7135 position and the end position of the match. Example: >vim 7136 echo matchstrpos("testing", "ing") 7137< results in ["ing", 4, 7]. 7138 When there is no match ["", -1, -1] is returned. 7139 The {start}, if given, has the same meaning as for |match()|. >vim 7140 echo matchstrpos("testing", "ing", 2) 7141< results in ["ing", 4, 7]. >vim 7142 echo matchstrpos("testing", "ing", 5) 7143< result is ["", -1, -1]. 7144 When {expr} is a |List| then the matching item, the index 7145 of first item where {pat} matches, the start position and the 7146 end position of the match are returned. >vim 7147 echo matchstrpos([1, '__x'], '\a') 7148< result is ["x", 1, 2, 3]. 7149 The type isn't changed, it's not necessarily a String. 7150 7151 Parameters: ~ 7152 • {expr} (`any`) 7153 • {pat} (`string`) 7154 • {start} (`integer?`) 7155 • {count} (`integer?`) 7156 7157 Return: ~ 7158 (`table`) 7159 7160max({expr}) *max()* 7161 Lua: Prefer |math.max()| with `unpack(expr)` for lists; dict 7162 values and empty inputs need custom handling. 7163 7164 Return the maximum value of all items in {expr}. Example: >vim 7165 echo max([apples, pears, oranges]) 7166 7167< {expr} can be a |List| or a |Dictionary|. For a Dictionary, 7168 it returns the maximum of all values in the Dictionary. 7169 If {expr} is neither a List nor a Dictionary, or one of the 7170 items in {expr} cannot be used as a Number this results in 7171 an error. An empty |List| or |Dictionary| results in zero. 7172 7173 Parameters: ~ 7174 • {expr} (`any`) 7175 7176 Return: ~ 7177 (`number`) 7178 7179menu_get({path} [, {modes}]) *menu_get()* 7180 Returns a |List| of |Dictionaries| describing |menus| (defined 7181 by |:menu|, |:amenu|, …), including |hidden-menus|. 7182 7183 {path} matches a menu by name, or all menus if {path} is an 7184 empty string. Example: >vim 7185 echo menu_get('File','') 7186 echo menu_get('') 7187< 7188 {modes} is a string of zero or more modes (see |maparg()| or 7189 |creating-menus| for the list of modes). "a" means "all". 7190 7191 Example: >vim 7192 nnoremenu &Test.Test inormal 7193 inoremenu Test.Test insert 7194 vnoremenu Test.Test x 7195 echo menu_get("") 7196 7197< returns something like this: > 7198 7199 [ { 7200 "hidden": 0, 7201 "name": "Test", 7202 "priority": 500, 7203 "shortcut": 84, 7204 "submenus": [ { 7205 "hidden": 0, 7206 "mappings": { 7207 i": { 7208 "enabled": 1, 7209 "noremap": 1, 7210 "rhs": "insert", 7211 "sid": 1, 7212 "silent": 0 7213 }, 7214 n": { ... }, 7215 s": { ... }, 7216 v": { ... } 7217 }, 7218 "name": "Test", 7219 "priority": 500, 7220 "shortcut": 0 7221 } ] 7222 } ] 7223< 7224 7225 Parameters: ~ 7226 • {path} (`string`) 7227 • {modes} (`string?`) 7228 7229 Return: ~ 7230 (`any`) 7231 7232menu_info({name} [, {mode}]) *menu_info()* 7233 Return information about the specified menu {name} in 7234 mode {mode}. The menu name should be specified without the 7235 shortcut character ('&'). If {name} is "", then the top-level 7236 menu names are returned. 7237 7238 {mode} can be one of these strings: 7239 "n" Normal 7240 "v" Visual (including Select) 7241 "o" Operator-pending 7242 "i" Insert 7243 "c" Cmd-line 7244 "s" Select 7245 "x" Visual 7246 "t" Terminal-Job 7247 "" Normal, Visual and Operator-pending 7248 "!" Insert and Cmd-line 7249 When {mode} is omitted, the modes for "" are used. 7250 7251 Returns a |Dictionary| containing the following items: 7252 accel menu item accelerator text |menu-text| 7253 display display name (name without '&') 7254 enabled v:true if this menu item is enabled 7255 Refer to |:menu-enable| 7256 icon name of the icon file (for toolbar) 7257 |toolbar-icon| 7258 iconidx index of a built-in icon 7259 modes modes for which the menu is defined. In 7260 addition to the modes mentioned above, these 7261 characters will be used: 7262 " " Normal, Visual and Operator-pending 7263 name menu item name. 7264 noremenu v:true if the {rhs} of the menu item is not 7265 remappable else v:false. 7266 priority menu order priority |menu-priority| 7267 rhs right-hand-side of the menu item. The 7268 returned string has special characters 7269 translated like in the output of the ":menu" 7270 command listing. When the {rhs} of a menu 7271 item is empty, then "<Nop>" is returned. 7272 script v:true if script-local remapping of {rhs} is 7273 allowed else v:false. See |:menu-script|. 7274 shortcut shortcut key (character after '&' in 7275 the menu name) |menu-shortcut| 7276 silent v:true if the menu item is created 7277 with <silent> argument |:menu-silent| 7278 submenus |List| containing the names of 7279 all the submenus. Present only if the menu 7280 item has submenus. 7281 7282 Returns an empty dictionary if the menu item is not found. 7283 7284 Examples: >vim 7285 echo menu_info('Edit.Cut') 7286 echo menu_info('File.Save', 'n') 7287 7288 " Display the entire menu hierarchy in a buffer 7289 func ShowMenu(name, pfx) 7290 let m = menu_info(a:name) 7291 call append(line('$'), a:pfx .. m.display) 7292 for child in m->get('submenus', []) 7293 call ShowMenu(a:name .. '.' .. escape(child, '.'), 7294 \ a:pfx .. ' ') 7295 endfor 7296 endfunc 7297 new 7298 for topmenu in menu_info('').submenus 7299 call ShowMenu(topmenu, '') 7300 endfor 7301< 7302 7303 Parameters: ~ 7304 • {name} (`string`) 7305 • {mode} (`string?`) 7306 7307 Return: ~ 7308 (`any`) 7309 7310min({expr}) *min()* 7311 Lua: Prefer |math.min()| with `unpack(expr)` for lists; dict 7312 values and empty inputs need custom handling. 7313 7314 Return the minimum value of all items in {expr}. Example: >vim 7315 echo min([apples, pears, oranges]) 7316 7317< {expr} can be a |List| or a |Dictionary|. For a Dictionary, 7318 it returns the minimum of all values in the Dictionary. 7319 If {expr} is neither a List nor a Dictionary, or one of the 7320 items in {expr} cannot be used as a Number this results in 7321 an error. An empty |List| or |Dictionary| results in zero. 7322 7323 Parameters: ~ 7324 • {expr} (`any`) 7325 7326 Return: ~ 7327 (`number`) 7328 7329mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739* 7330 Lua: Prefer |vim.fs.mkdir()|; `"D"`, `"R"`, and return 7331 semantics differ. 7332 7333 Create directory {name}. 7334 7335 When {flags} is present it must be a string. An empty string 7336 has no effect. 7337 7338 {flags} can contain these character flags: 7339 "p" intermediate directories will be created as necessary 7340 "D" {name} will be deleted at the end of the current 7341 function, but not recursively |:defer| 7342 "R" {name} will be deleted recursively at the end of the 7343 current function |:defer| 7344 7345 Note that when {name} has more than one part and "p" is used 7346 some directories may already exist. Only the first one that 7347 is created and what it contains is scheduled to be deleted. 7348 E.g. when using: >vim 7349 call mkdir('subdir/tmp/autoload', 'pR') 7350< and "subdir" already exists then "subdir/tmp" will be 7351 scheduled for deletion, like with: >vim 7352 defer delete('subdir/tmp', 'rf') 7353< 7354 If {prot} is given it is used to set the protection bits of 7355 the new directory. The default is 0o755 (rwxr-xr-x: r/w for 7356 the user, readable for others). Use 0o700 to make it 7357 unreadable for others. This is used for the newly created 7358 directories. Note: umask is applied to {prot} (on Unix). 7359 Example: >vim 7360 call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700) 7361 7362< This function is not available in the |sandbox|. 7363 7364 If you try to create an existing directory with {flags} set to 7365 "p" mkdir() will silently exit. 7366 7367 The function result is a Number, which is TRUE if the call was 7368 successful or FALSE if the directory creation failed or partly 7369 failed. 7370 7371 Parameters: ~ 7372 • {name} (`string`) 7373 • {flags} (`string?`) 7374 • {prot} (`string?`) 7375 7376 Return: ~ 7377 (`integer`) 7378 7379mode([{expr}]) *mode()* 7380 Lua: Prefer |nvim_get_mode()|; use the `.mode` field. It 7381 always returns the full mode string, unlike |mode()| without a 7382 non-zero {expr}. 7383 7384 Return a string that indicates the current mode. 7385 If {expr} is supplied and it evaluates to a non-zero Number or 7386 a non-empty String (|non-zero-arg|), then the full mode is 7387 returned, otherwise only the first letter is returned. 7388 Also see |state()|. 7389 7390 n Normal 7391 no Operator-pending 7392 nov Operator-pending (forced charwise |o_v|) 7393 noV Operator-pending (forced linewise |o_V|) 7394 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|) 7395 CTRL-V is one character 7396 niI Normal using |i_CTRL-O| in |Insert-mode| 7397 niR Normal using |i_CTRL-O| in |Replace-mode| 7398 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode| 7399 nt Normal in |terminal-emulator| (insert goes to 7400 Terminal mode) 7401 ntT Normal using |t_CTRL-\_CTRL-O| in |Terminal-mode| 7402 v Visual by character 7403 vs Visual by character using |v_CTRL-O| in Select mode 7404 V Visual by line 7405 Vs Visual by line using |v_CTRL-O| in Select mode 7406 CTRL-V Visual blockwise 7407 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode 7408 s Select by character 7409 S Select by line 7410 CTRL-S Select blockwise 7411 i Insert 7412 ic Insert mode completion |compl-generic| 7413 ix Insert mode |i_CTRL-X| completion 7414 R Replace |R| 7415 Rc Replace mode completion |compl-generic| 7416 Rx Replace mode |i_CTRL-X| completion 7417 Rv Virtual Replace |gR| 7418 Rvc Virtual Replace mode completion |compl-generic| 7419 Rvx Virtual Replace mode |i_CTRL-X| completion 7420 c Command-line editing 7421 cr Command-line editing overstrike mode |c_<Insert>| 7422 cv Non-interactive Ex mode |-es| 7423 r Hit-enter prompt 7424 rm The -- more -- prompt 7425 r? A |:confirm| query of some sort 7426 ! Shell or external command is executing 7427 t Terminal mode: keys go to the job 7428 7429 This is useful in the 'statusline' option or RPC calls. In 7430 most other places it always returns "c" or "n". 7431 Note that in the future more modes and more specific modes may 7432 be added. It's better not to compare the whole string but 7433 only the leading character(s). 7434 Also see |visualmode()|. 7435 7436 Parameters: ~ 7437 • {expr} (`any?`) 7438 7439 Return: ~ 7440 (`any`) 7441 7442msgpackdump({list} [, {type}]) *msgpackdump()* 7443 Lua: Prefer |vim.mpack.encode()|; list wrapping, return shape, 7444 and special-dict semantics differ. 7445 7446 Convert a list of Vimscript objects to msgpack. Returned value is a 7447 |readfile()|-style list. When {type} contains "B", a |Blob| is 7448 returned instead. Example: >vim 7449 call writefile(msgpackdump([{}]), 'fname.mpack', 'b') 7450< or, using a |Blob|: >vim 7451 call writefile(msgpackdump([{}], 'B'), 'fname.mpack') 7452< 7453 This will write the single 0x80 byte to a `fname.mpack` file 7454 (dictionary with zero items is represented by 0x80 byte in 7455 messagepack). 7456 7457 Limitations: *E5004* *E5005* 7458 1. |Funcref|s cannot be dumped. 7459 2. Containers that reference themselves cannot be dumped. 7460 3. Dictionary keys are always dumped as STR strings. 7461 4. Other strings and |Blob|s are always dumped as BIN strings. 7462 5. Points 3. and 4. do not apply to |msgpack-special-dict|s. 7463 7464 Parameters: ~ 7465 • {list} (`any`) 7466 • {type} (`any?`) 7467 7468 Return: ~ 7469 (`any`) 7470 7471msgpackparse({data}) *msgpackparse()* 7472 Lua: Prefer |vim.mpack.decode()|; input and special-dict 7473 semantics differ. 7474 7475 Convert a |readfile()|-style list or a |Blob| to a list of 7476 Vimscript objects. 7477 Example: >vim 7478 let fname = expand('~/.config/nvim/shada/main.shada') 7479 let mpack = readfile(fname, 'b') 7480 let shada_objects = msgpackparse(mpack) 7481< This will read ~/.config/nvim/shada/main.shada file to 7482 `shada_objects` list. 7483 7484 Limitations: 7485 1. Mapping ordering is not preserved unless messagepack 7486 mapping is dumped using generic mapping 7487 (|msgpack-special-map|). 7488 2. Since the parser aims to preserve all data untouched 7489 (except for 1.) some strings are parsed to 7490 |msgpack-special-dict| format which is not convenient to 7491 use. 7492 *msgpack-special-dict* 7493 Some messagepack strings may be parsed to special 7494 dictionaries. Special dictionaries are dictionaries which 7495 7496 1. Contain exactly two keys: `_TYPE` and `_VAL`. 7497 2. `_TYPE` key is one of the types found in |v:msgpack_types| 7498 variable. 7499 3. Value for `_VAL` has the following format (Key column 7500 contains name of the key from |v:msgpack_types|): 7501 7502 Key Value ~ 7503 nil Zero, ignored when dumping. Not returned by 7504 |msgpackparse()| since |v:null| was introduced. 7505 boolean One or zero. When dumping it is only checked that 7506 value is a |Number|. Not returned by |msgpackparse()| 7507 since |v:true| and |v:false| were introduced. 7508 integer |List| with four numbers: sign (-1 or 1), highest two 7509 bits, number with bits from 62nd to 31st, lowest 31 7510 bits. I.e. to get actual number one will need to use 7511 code like > 7512 _VAL[0] * ((_VAL[1] << 62) 7513 & (_VAL[2] << 31) 7514 & _VAL[3]) 7515< Special dictionary with this type will appear in 7516 |msgpackparse()| output under one of the following 7517 circumstances: 7518 1. |Number| is 32-bit and value is either above 7519 INT32_MAX or below INT32_MIN. 7520 2. |Number| is 64-bit and value is above INT64_MAX. It 7521 cannot possibly be below INT64_MIN because msgpack 7522 C parser does not support such values. 7523 float |Float|. This value cannot possibly appear in 7524 |msgpackparse()| output. 7525 string |String|, or |Blob| if binary string contains zero 7526 byte. This value cannot appear in |msgpackparse()| 7527 output since blobs were introduced. 7528 array |List|. This value cannot appear in |msgpackparse()| 7529 output. 7530 *msgpack-special-map* 7531 map |List| of |List|s with two items (key and value) each. 7532 This value will appear in |msgpackparse()| output if 7533 parsed mapping contains one of the following keys: 7534 1. Any key that is not a string (including keys which 7535 are binary strings). 7536 2. String with NUL byte inside. 7537 3. Duplicate key. 7538 ext |List| with two values: first is a signed integer 7539 representing extension type. Second is 7540 |readfile()|-style list of strings. 7541 7542 Parameters: ~ 7543 • {data} (`any`) 7544 7545 Return: ~ 7546 (`any`) 7547 7548nextnonblank({lnum}) *nextnonblank()* 7549 Return the line number of the first line at or below {lnum} 7550 that is not blank. Example: >vim 7551 if getline(nextnonblank(1)) =~ "Java" | endif 7552< When {lnum} is invalid or there is no non-blank line at or 7553 below it, zero is returned. 7554 {lnum} is used like with |getline()|. 7555 See also |prevnonblank()|. 7556 7557 Parameters: ~ 7558 • {lnum} (`integer|string`) 7559 7560 Return: ~ 7561 (`integer`) 7562 7563nr2char({expr} [, {utf8}]) *nr2char()* 7564 Lua: Prefer |string.char()|: only works with ASCII. 7565 7566 Gets a UTF-8 string for a single codepoint {expr}. 7567 Examples: >vim 7568 echo nr2char(64) " returns '@' 7569 echo nr2char(32) " returns ' ' 7570 echo nr2char(300) " returns I with bow character 7571< 7572 UTF-8 encoding is always used, {utf8} option has no effect, 7573 and exists only for backwards-compatibility. 7574 Note that a NUL character in the file is specified with 7575 nr2char(10), because NULs are represented with newline 7576 characters. nr2char(0) is a real NUL and terminates the 7577 string, thus results in an empty string. 7578 7579 Attributes: ~ 7580 |api-fast| 7581 7582 Parameters: ~ 7583 • {expr} (`integer`) 7584 • {utf8} (`boolean?`) 7585 7586 Return: ~ 7587 (`string`) 7588 7589nvim_...({...}) *nvim_...()* *E5555* *eval-api* 7590 Lua: Prefer |vim.api|. 7591 7592 Call nvim |api| functions. The type checking of arguments will 7593 be stricter than for most other builtins. For instance, 7594 if Integer is expected, a |Number| must be passed in, a 7595 |String| will not be autoconverted. 7596 Buffer numbers, as returned by |bufnr()| could be used as 7597 first argument to nvim_buf_... functions. All functions 7598 expecting an object (buffer, window or tabpage) can 7599 also take the numerical value 0 to indicate the current 7600 (focused) object. 7601 7602 Parameters: ~ 7603 • {...} (`any`) 7604 7605 Return: ~ 7606 (`any`) 7607 7608or({expr}, {expr}) *or()* 7609 Lua: Prefer |bit.bor()|. 7610 7611 Bitwise OR on the two arguments. The arguments are converted 7612 to a number. A List, Dict or Float argument causes an error. 7613 Also see `and()` and `xor()`. 7614 Example: >vim 7615 let bits = or(bits, 0x80) 7616 7617< Rationale: The reason this is a function and not using the "|" 7618 character like many languages, is that Vi has always used "|" 7619 to separate commands. In many places it would not be clear if 7620 "|" is an operator or a command separator. 7621 7622 Parameters: ~ 7623 • {expr} (`number`) 7624 • {expr1} (`number`) 7625 7626 Return: ~ 7627 (`any`) 7628 7629pathshorten({path} [, {len}]) *pathshorten()* 7630 Shorten directory names in the path {path} and return the 7631 result. The tail, the file name, is kept as-is. The other 7632 components in the path are reduced to {len} letters in length. 7633 If {len} is omitted or smaller than 1 then 1 is used (single 7634 letters). Leading '~' and '.' characters are kept. Examples: >vim 7635 echo pathshorten('~/.config/nvim/autoload/file1.vim') 7636< ~/.c/n/a/file1.vim ~ 7637>vim 7638 echo pathshorten('~/.config/nvim/autoload/file2.vim', 2) 7639< ~/.co/nv/au/file2.vim ~ 7640 It doesn't matter if the path exists or not. 7641 Returns an empty string on error. 7642 7643 Parameters: ~ 7644 • {path} (`string`) 7645 • {len} (`integer?`) 7646 7647 Return: ~ 7648 (`string`) 7649 7650perleval({expr}) *perleval()* 7651 Evaluate |perl| expression {expr} and return its result 7652 converted to Vim data structures. 7653 Numbers and strings are returned as they are (strings are 7654 copied though). 7655 Lists are represented as Vim |List| type. 7656 Dictionaries are represented as Vim |Dictionary| type, 7657 non-string keys result in error. 7658 7659 Note: If you want an array or hash, {expr} must return a 7660 reference to it. 7661 Example: >vim 7662 echo perleval('[1 .. 4]') 7663< [1, 2, 3, 4] 7664 7665 Parameters: ~ 7666 • {expr} (`any`) 7667 7668 Return: ~ 7669 (`any`) 7670 7671pow({x}, {y}) *pow()* 7672 Lua: Prefer |math.pow()|. 7673 7674 Return the power of {x} to the exponent {y} as a |Float|. 7675 {x} and {y} must evaluate to a |Float| or a |Number|. 7676 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|. 7677 Examples: >vim 7678 echo pow(3, 3) 7679< 27.0 >vim 7680 echo pow(2, 16) 7681< 65536.0 >vim 7682 echo pow(32, 0.20) 7683< 2.0 7684 7685 Parameters: ~ 7686 • {x} (`number`) 7687 • {y} (`number`) 7688 7689 Return: ~ 7690 (`number`) 7691 7692preinserted() *preinserted()* 7693 Returns non-zero if text has been inserted after the cursor 7694 because "preinsert" is present in 'completeopt', or because 7695 "longest" is present in 'completeopt' while 'autocomplete' 7696 is active. Otherwise returns zero. 7697 7698 Return: ~ 7699 (`number`) 7700 7701prevnonblank({lnum}) *prevnonblank()* 7702 Return the line number of the first line at or above {lnum} 7703 that is not blank. Example: >vim 7704 let ind = indent(prevnonblank(v:lnum - 1)) 7705< When {lnum} is invalid or there is no non-blank line at or 7706 above it, zero is returned. 7707 {lnum} is used like with |getline()|. 7708 Also see |nextnonblank()|. 7709 7710 Parameters: ~ 7711 • {lnum} (`integer|string`) 7712 7713 Return: ~ 7714 (`integer`) 7715 7716printf({fmt}, {expr1} ...) *printf()* 7717 Lua: Prefer |string.format()|. 7718 7719 Return a String with {fmt}, where "%" items are replaced by 7720 the formatted form of their respective arguments. Example: >vim 7721 echo printf("%4d: E%d %.30s", lnum, errno, msg) 7722< May result in: 7723 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ 7724 7725 When used as a |method| the base is passed as the second 7726 argument: >vim 7727 Compute()->printf("result: %d") 7728< 7729 You can use `call()` to pass the items as a list. 7730 7731 Often used items are: 7732 %s string 7733 %6S string right-aligned in 6 display cells 7734 %6s string right-aligned in 6 bytes 7735 %.9s string truncated to 9 bytes 7736 %c single byte 7737 %d decimal number 7738 %5d decimal number padded with spaces to 5 characters 7739 %b binary number 7740 %08b binary number padded with zeros to at least 8 characters 7741 %B binary number using upper case letters 7742 %x hex number 7743 %04x hex number padded with zeros to at least 4 characters 7744 %X hex number using upper case letters 7745 %o octal number 7746 %f floating point number as 12.23, inf, -inf or nan 7747 %F floating point number as 12.23, INF, -INF or NAN 7748 %e floating point number as 1.23e3, inf, -inf or nan 7749 %E floating point number as 1.23E3, INF, -INF or NAN 7750 %g floating point number, as %f or %e depending on value 7751 %G floating point number, as %F or %E depending on value 7752 %% the % character itself 7753 %p representation of the pointer to the container 7754 7755 Conversion specifications start with '%' and end with the 7756 conversion type. All other characters are copied unchanged to 7757 the result. 7758 7759 The "%" starts a conversion specification. The following 7760 arguments appear in sequence: 7761 7762 % [pos-argument] [flags] [field-width] [.precision] type 7763 7764 pos-argument 7765 At most one positional argument specifier. These take 7766 the form {n$}, where n is >= 1. 7767 7768 flags 7769 Zero or more of the following flags: 7770 7771 # The value should be converted to an "alternate 7772 form". For c, d, and s conversions, this option 7773 has no effect. For o conversions, the precision 7774 of the number is increased to force the first 7775 character of the output string to a zero (except 7776 if a zero value is printed with an explicit 7777 precision of zero). 7778 For x and X conversions, a non-zero result has 7779 the string "0x" (or "0X" for X conversions) 7780 prepended to it. 7781 7782 0 (zero) Zero padding. For all conversions the converted 7783 value is padded on the left with zeros rather 7784 than blanks. If a precision is given with a 7785 numeric conversion (d, o, x, and X), the 0 flag 7786 is ignored. 7787 7788 - A negative field width flag; the converted value 7789 is to be left adjusted on the field boundary. 7790 The converted value is padded on the right with 7791 blanks, rather than on the left with blanks or 7792 zeros. A - overrides a 0 if both are given. 7793 7794 ' ' (space) A blank should be left before a positive 7795 number produced by a signed conversion (d). 7796 7797 + A sign must always be placed before a number 7798 produced by a signed conversion. A + overrides 7799 a space if both are used. 7800 7801 field-width 7802 An optional decimal digit string specifying a minimum 7803 field width. If the converted value has fewer bytes 7804 than the field width, it will be padded with spaces on 7805 the left (or right, if the left-adjustment flag has 7806 been given) to fill out the field width. For the S 7807 conversion the count is in cells. 7808 7809 .precision 7810 An optional precision, in the form of a period '.' 7811 followed by an optional digit string. If the digit 7812 string is omitted, the precision is taken as zero. 7813 This gives the minimum number of digits to appear for 7814 d, o, x, and X conversions, the maximum number of 7815 bytes to be printed from a string for s conversions, 7816 or the maximum number of cells to be printed from a 7817 string for S conversions. 7818 For floating point it is the number of digits after 7819 the decimal point. 7820 7821 type 7822 A character that specifies the type of conversion to 7823 be applied, see below. 7824 7825 A field width or precision, or both, may be indicated by an 7826 asterisk "*" instead of a digit string. In this case, a 7827 Number argument supplies the field width or precision. A 7828 negative field width is treated as a left adjustment flag 7829 followed by a positive field width; a negative precision is 7830 treated as though it were missing. Example: >vim 7831 echo printf("%d: %.*s", nr, width, line) 7832< This limits the length of the text used from "line" to 7833 "width" bytes. 7834 7835 If the argument to be formatted is specified using a 7836 positional argument specifier, and a '*' is used to indicate 7837 that a number argument is to be used to specify the width or 7838 precision, the argument(s) to be used must also be specified 7839 using a {n$} positional argument specifier. See |printf-$|. 7840 7841 The conversion specifiers and their meanings are: 7842 7843 *printf-d* *printf-b* *printf-B* *printf-o* *printf-x* *printf-X* 7844 dbBoxX The Number argument is converted to signed decimal (d), 7845 unsigned binary (b and B), unsigned octal (o), or 7846 unsigned hexadecimal (x and X) notation. The letters 7847 "abcdef" are used for x conversions; the letters 7848 "ABCDEF" are used for X conversions. The precision, if 7849 any, gives the minimum number of digits that must 7850 appear; if the converted value requires fewer digits, it 7851 is padded on the left with zeros. In no case does a 7852 non-existent or small field width cause truncation of a 7853 numeric field; if the result of a conversion is wider 7854 than the field width, the field is expanded to contain 7855 the conversion result. 7856 The 'h' modifier indicates the argument is 16 bits. 7857 The 'l' modifier indicates the argument is a long 7858 integer. The size will be 32 bits or 64 bits 7859 depending on your platform. 7860 The "ll" modifier indicates the argument is 64 bits. 7861 The b and B conversion specifiers never take a width 7862 modifier and always assume their argument is a 64 bit 7863 integer. 7864 Generally, these modifiers are not useful. They are 7865 ignored when type is known from the argument. 7866 7867 i alias for d 7868 D alias for ld 7869 U alias for lu 7870 O alias for lo 7871 7872 *printf-c* 7873 c The Number argument is converted to a byte, and the 7874 resulting character is written. 7875 7876 *printf-s* 7877 s The text of the String argument is used. If a 7878 precision is specified, no more bytes than the number 7879 specified are used. 7880 If the argument is not a String type, it is 7881 automatically converted to text with the same format 7882 as ":echo". 7883 *printf-S* 7884 S The text of the String argument is used. If a 7885 precision is specified, no more display cells than the 7886 number specified are used. 7887 7888 *printf-f* *E807* 7889 f F The Float argument is converted into a string of the 7890 form 123.456. The precision specifies the number of 7891 digits after the decimal point. When the precision is 7892 zero the decimal point is omitted. When the precision 7893 is not specified 6 is used. A really big number 7894 (out of range or dividing by zero) results in "inf" 7895 or "-inf" with %f (INF or -INF with %F). 7896 "0.0 / 0.0" results in "nan" with %f (NAN with %F). 7897 Example: >vim 7898 echo printf("%.2f", 12.115) 7899< 12.12 7900 Note that roundoff depends on the system libraries. 7901 Use |round()| when in doubt. 7902 7903 *printf-e* *printf-E* 7904 e E The Float argument is converted into a string of the 7905 form 1.234e+03 or 1.234E+03 when using 'E'. The 7906 precision specifies the number of digits after the 7907 decimal point, like with 'f'. 7908 7909 *printf-g* *printf-G* 7910 g G The Float argument is converted like with 'f' if the 7911 value is between 0.001 (inclusive) and 10000000.0 7912 (exclusive). Otherwise 'e' is used for 'g' and 'E' 7913 for 'G'. When no precision is specified superfluous 7914 zeroes and '+' signs are removed, except for the zero 7915 immediately after the decimal point. Thus 10000000.0 7916 results in 1.0e7. 7917 7918 *printf-%* 7919 % A '%' is written. No argument is converted. The 7920 complete conversion specification is "%%". 7921 7922 When a Number argument is expected a String argument is also 7923 accepted and automatically converted. 7924 When a Float or String argument is expected a Number argument 7925 is also accepted and automatically converted. 7926 Any other argument type results in an error message. 7927 7928 *E766* *E767* 7929 The number of {exprN} arguments must exactly match the number 7930 of "%" items. If there are not sufficient or too many 7931 arguments an error is given. Up to 18 arguments can be used. 7932 7933 *printf-$* 7934 In certain languages, error and informative messages are 7935 more readable when the order of words is different from the 7936 corresponding message in English. To accommodate translations 7937 having a different word order, positional arguments may be 7938 used to indicate this. For instance: >vim 7939 7940 #, c-format 7941 msgid "%s returning %s" 7942 msgstr "waarde %2$s komt terug van %1$s" 7943< 7944 In this example, the sentence has its 2 string arguments 7945 reversed in the output. >vim 7946 7947 echo printf( 7948 "In The Netherlands, vim's creator's name is: %1$s %2$s", 7949 "Bram", "Moolenaar") 7950< In The Netherlands, vim's creator's name is: Bram Moolenaar >vim 7951 7952 echo printf( 7953 "In Belgium, vim's creator's name is: %2$s %1$s", 7954 "Bram", "Moolenaar") 7955< In Belgium, vim's creator's name is: Moolenaar Bram 7956 7957 Width (and precision) can be specified using the '*' 7958 specifier. In this case, you must specify the field width 7959 position in the argument list. >vim 7960 7961 echo printf("%1$*2$.*3$d", 1, 2, 3) 7962< 001 >vim 7963 echo printf("%2$*3$.*1$d", 1, 2, 3) 7964< 2 >vim 7965 echo printf("%3$*1$.*2$d", 1, 2, 3) 7966< 03 >vim 7967 echo printf("%1$*2$.*3$g", 1.4142, 2, 3) 7968< 1.414 7969 7970 You can mix specifying the width and/or precision directly 7971 and via positional arguments: >vim 7972 7973 echo printf("%1$4.*2$f", 1.4142135, 6) 7974< 1.414214 >vim 7975 echo printf("%1$*2$.4f", 1.4142135, 6) 7976< 1.4142 >vim 7977 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2) 7978< 1.41 7979 7980 You will get an overflow error |E1510|, when the field-width 7981 or precision will result in a string longer than 1 MiB 7982 (1024*1024 = 1048576) chars. 7983 7984 *E1500* 7985 You cannot mix positional and non-positional arguments: >vim 7986 echo printf("%s%1$s", "One", "Two") 7987 " E1500: Cannot mix positional and non-positional arguments: 7988 " %s%1$s 7989< 7990 *E1501* 7991 You cannot skip a positional argument in a format string: >vim 7992 echo printf("%3$s%1$s", "One", "Two", "Three") 7993 " E1501: format argument 2 unused in $-style format: 7994 " %3$s%1$s 7995< 7996 *E1502* 7997 You can re-use a [field-width] (or [precision]) argument: >vim 7998 echo printf("%1$d at width %2$d is: %1$0*2$d", 1, 2) 7999 " 1 at width 2 is: 01 8000< 8001 However, you can't use it as a different type: >vim 8002 echo printf("%1$d at width %2$ld is: %1$0*2$d", 1, 2) 8003 " E1502: Positional argument 2 used as field width reused as 8004 " different type: long int/int 8005< 8006 *E1503* 8007 When a positional argument is used, but not the correct number 8008 or arguments is given, an error is raised: >vim 8009 echo printf("%1$d at width %2$d is: %1$0*2$.*3$d", 1, 2) 8010 " E1503: Positional argument 3 out of bounds: %1$d at width 8011 " %2$d is: %1$0*2$.*3$d 8012< 8013 Only the first error is reported: >vim 8014 echo printf("%1$0*2$.*3$d %4$d", 1, 2) 8015 " E1503: Positional argument 3 out of bounds: %1$0*2$.*3$d 8016 " %4$d 8017< 8018 *E1504* 8019 A positional argument can be used more than once: >vim 8020 echo printf("%1$s %2$s %1$s", "One", "Two") 8021 " One Two One 8022< 8023 However, you can't use a different type the second time: >vim 8024 echo printf("%1$s %2$s %1$d", "One", "Two") 8025 " E1504: Positional argument 1 type used inconsistently: 8026 " int/string 8027< 8028 *E1505* 8029 Various other errors that lead to a format string being 8030 wrongly formatted lead to: >vim 8031 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2) 8032 " E1505: Invalid format specifier: %1$d at width %2$d is: 8033 " %01$*2$.3$d 8034< 8035 *E1507* 8036 This internal error indicates that the logic to parse a 8037 positional format argument ran into a problem that couldn't be 8038 otherwise reported. Please file a bug against Vim if you run 8039 into this, copying the exact format string and parameters that 8040 were used. 8041 8042 Parameters: ~ 8043 • {fmt} (`string`) 8044 • {expr1} (`any?`) 8045 8046 Return: ~ 8047 (`string`) 8048 8049prompt_appendbuf({buf}, {text}) *prompt_appendbuf()* 8050 Appends text to prompt buffer before current prompt. When {text} is 8051 a |List|: Append each item of the |List| as a text line above 8052 prompt-line in the buffer. Any type of item is accepted and converted 8053 to a String. Returns 1 for failure ({buf} not a prmopt buffer), 8054 0 for success. When {text} is an empty list zero is returned. 8055 8056 Example: >vim 8057 func TextEntered(text) 8058 call prompt_appendbuf(bufnr(''), split('Entered: "' . a:text . '"', '\n')) 8059 endfunc 8060 8061 set buftype=prompt 8062 call prompt_setcallback(bufnr(''), function("TextEntered")) 8063 eval bufnr("")->prompt_setprompt("cmd: ") 8064 startinsert 8065< 8066 8067 Parameters: ~ 8068 • {buf} (`integer|string`) 8069 • {text} (`string|string[]`) 8070 8071 Return: ~ 8072 (`0|1`) 8073 8074prompt_getinput({buf}) *prompt_getinput()* 8075 Gets the current user-input in |prompt-buffer| {buf} without invoking 8076 prompt_callback. {buf} can be a buffer name or number. 8077 8078 If the buffer doesn't exist or isn't a prompt buffer, an empty 8079 string is returned. 8080 8081 Parameters: ~ 8082 • {buf} (`integer|string`) 8083 8084 Return: ~ 8085 (`any`) 8086 8087prompt_getprompt({buf}) *prompt_getprompt()* 8088 Returns the effective prompt text for buffer {buf}. {buf} can 8089 be a buffer name or number. See |prompt-buffer|. 8090 8091 If the buffer doesn't exist or isn't a prompt buffer, an empty 8092 string is returned. 8093 8094 Parameters: ~ 8095 • {buf} (`integer|string`) 8096 8097 Return: ~ 8098 (`any`) 8099 8100prompt_setcallback({buf}, {expr}) *prompt_setcallback()* 8101 Set prompt callback for buffer {buf} to {expr}. When {expr} 8102 is an empty string the callback is removed. This has only 8103 effect if {buf} has 'buftype' set to "prompt". 8104 8105 The callback is invoked when pressing Enter. The current 8106 buffer will always be the prompt buffer. A new line for a 8107 prompt is added before invoking the callback, thus the prompt 8108 for which the callback was invoked will be in the last but one 8109 line. 8110 If the callback wants to add text to the buffer, it must 8111 insert it above the last line, since that is where the current 8112 prompt is. This can also be done asynchronously. 8113 The callback is invoked with one argument, which is the text 8114 that was entered at the prompt. This can be an empty string 8115 if the user only typed Enter. 8116 Example: >vim 8117 func s:TextEntered(text) 8118 if a:text == 'exit' || a:text == 'quit' 8119 stopinsert 8120 " Reset 'modified' to allow the buffer to be closed. 8121 " We assume there is nothing useful to be saved. 8122 set nomodified 8123 close 8124 else 8125 " Do something useful with "a:text". In this example 8126 " we just repeat it. 8127 call append(line('$') - 1, 'Entered: "' .. a:text .. '"') 8128 endif 8129 endfunc 8130 call prompt_setcallback(bufnr(), function('s:TextEntered')) 8131< 8132 8133 Parameters: ~ 8134 • {buf} (`integer|string`) 8135 • {expr} (`string|function`) 8136 8137 Return: ~ 8138 (`any`) 8139 8140prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()* 8141 Set a callback for buffer {buf} to {expr}. When {expr} is an 8142 empty string the callback is removed. This has only effect if 8143 {buf} has 'buftype' set to "prompt". 8144 8145 This callback will be invoked when pressing CTRL-C in Insert 8146 mode. Without setting a callback Vim will exit Insert mode, 8147 as in any buffer. 8148 8149 Parameters: ~ 8150 • {buf} (`integer|string`) 8151 • {expr} (`string|function`) 8152 8153 Return: ~ 8154 (`any`) 8155 8156prompt_setprompt({buf}, {text}) *prompt_setprompt()* 8157 Set prompt for buffer {buf} to {text}. You most likely want 8158 {text} to end in a space. 8159 The result is only visible if {buf} has 'buftype' set to 8160 "prompt". Example: >vim 8161 call prompt_setprompt(bufnr(''), 'command: ') 8162< 8163 8164 Parameters: ~ 8165 • {buf} (`integer|string`) 8166 • {text} (`string`) 8167 8168 Return: ~ 8169 (`any`) 8170 8171pum_getpos() *pum_getpos()* 8172 If the popup menu (see |ins-completion-menu|) is not visible, 8173 returns an empty |Dictionary|, otherwise, returns a 8174 |Dictionary| with the following keys: 8175 height nr of items visible 8176 width screen cells 8177 row top screen row (0 first row) 8178 col leftmost screen column (0 first col) 8179 size total nr of items 8180 scrollbar |TRUE| if scrollbar is visible 8181 8182 The values are the same as in |v:event| during |CompleteChanged|. 8183 8184 Return: ~ 8185 (`any`) 8186 8187pumvisible() *pumvisible()* 8188 Returns non-zero when the popup menu is visible, zero 8189 otherwise. See |ins-completion-menu|. 8190 This can be used to avoid some things that would remove the 8191 popup menu. 8192 8193 Return: ~ 8194 (`any`) 8195 8196py3eval({expr}) *py3eval()* 8197 Evaluate Python expression {expr} and return its result 8198 converted to Vim data structures. 8199 Numbers and strings are returned as they are (strings are 8200 copied though, Unicode strings are additionally converted to 8201 UTF-8). 8202 Lists are represented as Vim |List| type. 8203 Dictionaries are represented as Vim |Dictionary| type with 8204 keys converted to strings. 8205 8206 Parameters: ~ 8207 • {expr} (`any`) 8208 8209 Return: ~ 8210 (`any`) 8211 8212pyeval({expr}) *pyeval()* *E858* *E859* 8213 Evaluate Python expression {expr} and return its result 8214 converted to Vim data structures. 8215 Numbers and strings are returned as they are (strings are 8216 copied though). 8217 Lists are represented as Vim |List| type. 8218 Dictionaries are represented as Vim |Dictionary| type, 8219 non-string keys result in error. 8220 8221 Parameters: ~ 8222 • {expr} (`any`) 8223 8224 Return: ~ 8225 (`any`) 8226 8227pyxeval({expr}) *pyxeval()* 8228 Evaluate Python expression {expr} and return its result 8229 converted to Vim data structures. 8230 Uses Python 2 or 3, see |python_x| and 'pyxversion'. 8231 See also: |pyeval()|, |py3eval()| 8232 8233 Parameters: ~ 8234 • {expr} (`any`) 8235 8236 Return: ~ 8237 (`any`) 8238 8239rand([{expr}]) *rand()* 8240 Lua: Prefer |math.random()|. 8241 8242 Return a pseudo-random Number generated with an xoshiro128** 8243 algorithm using seed {expr}. The returned number is 32 bits, 8244 also on 64 bits systems, for consistency. 8245 {expr} can be initialized by |srand()| and will be updated by 8246 rand(). If {expr} is omitted, an internal seed value is used 8247 and updated. 8248 Returns -1 if {expr} is invalid. 8249 8250 Examples: >vim 8251 echo rand() 8252 let seed = srand() 8253 echo rand(seed) 8254 echo rand(seed) % 16 " random number 0 - 15 8255< 8256 8257 Parameters: ~ 8258 • {expr} (`number?`) 8259 8260 Return: ~ 8261 (`any`) 8262 8263range({expr} [, {max} [, {stride}]]) *range()* *E726* *E727* 8264 Returns a |List| with Numbers: 8265 - If only {expr} is specified: [0, 1, ..., {expr} - 1] 8266 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}] 8267 - If {stride} is specified: [{expr}, {expr} + {stride}, ..., 8268 {max}] (increasing {expr} with {stride} each time, not 8269 producing a value past {max}). 8270 When the maximum is one before the start the result is an 8271 empty list. When the maximum is more than one before the 8272 start this is an error. 8273 Examples: >vim 8274 echo range(4) " [0, 1, 2, 3] 8275 echo range(2, 4) " [2, 3, 4] 8276 echo range(2, 9, 3) " [2, 5, 8] 8277 echo range(2, -2, -1) " [2, 1, 0, -1, -2] 8278 echo range(0) " [] 8279 echo range(2, 0) " error! 8280< 8281 8282 Parameters: ~ 8283 • {expr} (`any`) 8284 • {max} (`integer?`) 8285 • {stride} (`integer?`) 8286 8287 Return: ~ 8288 (`any`) 8289 8290readblob({fname} [, {offset} [, {size}]]) *readblob()* 8291 Lua: Prefer |io.open()| with `:read("*a")` in binary mode for 8292 whole-file reads; offset, size, and Blob return differ. 8293 8294 Read file {fname} in binary mode and return a |Blob|. 8295 If {offset} is specified, read the file from the specified 8296 offset. If it is a negative value, it is used as an offset 8297 from the end of the file. E.g., to read the last 12 bytes: >vim 8298 echo readblob('file.bin', -12) 8299< If {size} is specified, only the specified size will be read. 8300 E.g. to read the first 100 bytes of a file: >vim 8301 echo readblob('file.bin', 0, 100) 8302< If {size} is -1 or omitted, the whole data starting from 8303 {offset} will be read. 8304 This can be also used to read the data from a character device 8305 on Unix when {size} is explicitly set. Only if the device 8306 supports seeking {offset} can be used. Otherwise it should be 8307 zero. E.g. to read 10 bytes from a serial console: >vim 8308 echo readblob('/dev/ttyS0', 0, 10) 8309< When the file can't be opened an error message is given and 8310 the result is an empty |Blob|. 8311 When the offset is beyond the end of the file the result is an 8312 empty blob. 8313 When trying to read more bytes than are available the result 8314 is truncated. 8315 Also see |readfile()| and |writefile()|. 8316 8317 Parameters: ~ 8318 • {fname} (`string`) 8319 • {offset} (`integer?`) 8320 • {size} (`integer?`) 8321 8322 Return: ~ 8323 (`any`) 8324 8325readdir({directory} [, {expr}]) *readdir()* 8326 Lua: Prefer |vim.fs.dir()| as an iterator, then collect and 8327 filter results as needed. 8328 8329 Return a list with file and directory names in {directory}. 8330 You can also use |glob()| if you don't need to do complicated 8331 things, such as limiting the number of matches. 8332 8333 When {expr} is omitted all entries are included. 8334 When {expr} is given, it is evaluated to check what to do: 8335 If {expr} results in -1 then no further entries will 8336 be handled. 8337 If {expr} results in 0 then this entry will not be 8338 added to the list. 8339 If {expr} results in 1 then this entry will be added 8340 to the list. 8341 Each time {expr} is evaluated |v:val| is set to the entry name. 8342 When {expr} is a function the name is passed as the argument. 8343 For example, to get a list of files ending in ".txt": >vim 8344 echo readdir(dirname, {n -> n =~ '\.txt$'}) 8345< To skip hidden and backup files: >vim 8346 echo readdir(dirname, {n -> n !~ '^\.\|\~$'}) 8347 8348< If you want to get a directory tree: >vim 8349 function! s:tree(dir) 8350 return {a:dir : map(readdir(a:dir), 8351 \ {_, x -> isdirectory(x) ? 8352 \ {x : s:tree(a:dir .. '/' .. x)} : x})} 8353 endfunction 8354 echo s:tree(".") 8355< 8356 Returns an empty List on error. 8357 8358 Parameters: ~ 8359 • {directory} (`string`) 8360 • {expr} (`integer|string|fun(name: string): integer?`) 8361 8362 Return: ~ 8363 (`any`) 8364 8365readfile({fname} [, {type} [, {max}]]) *readfile()* 8366 Lua: Prefer |io.open()| with `:read("*a")`, then split lines 8367 as needed; `{type}`, `{max}`, and Blob return differ. 8368 8369 Read file {fname} and return a |List|, each line of the file 8370 as an item. Lines are broken at NL characters. Macintosh 8371 files separated with CR will result in a single long line 8372 (unless a NL appears somewhere). 8373 All NUL characters are replaced with a NL character. 8374 When {type} contains "b" binary mode is used: 8375 - When the last line ends in a NL an extra empty list item is 8376 added. 8377 - No CR characters are removed. 8378 Otherwise: 8379 - CR characters that appear before a NL are removed. 8380 - Whether the last line ends in a NL or not does not matter. 8381 - Any UTF-8 byte order mark is removed from the text. 8382 When {max} is given this specifies the maximum number of lines 8383 to be read. Useful if you only want to check the first ten 8384 lines of a file: >vim 8385 for line in readfile(fname, '', 10) 8386 if line =~ 'Date' | echo line | endif 8387 endfor 8388< When {max} is negative -{max} lines from the end of the file 8389 are returned, or as many as there are. 8390 When {max} is zero the result is an empty list. 8391 Note that without {max} the whole file is read into memory. 8392 Also note that there is no recognition of encoding. Read a 8393 file into a buffer if you need to. 8394 Deprecated (use |readblob()| instead): When {type} contains 8395 "B" a |Blob| is returned with the binary data of the file 8396 unmodified. 8397 When the file can't be opened an error message is given and 8398 the result is an empty list. 8399 Also see |writefile()|. 8400 8401 Parameters: ~ 8402 • {fname} (`string`) 8403 • {type} (`string?`) 8404 • {max} (`integer?`) 8405 8406 Return: ~ 8407 (`string[]`) 8408 8409reduce({object}, {func} [, {initial}]) *reduce()* *E998* 8410 Lua: Prefer |Iter:fold()|. 8411 8412 {func} is called for every item in {object}, which can be a 8413 |String|, |List| or a |Blob|. {func} is called with two 8414 arguments: the result so far and current item. After 8415 processing all items the result is returned. *E1132* 8416 8417 {initial} is the initial result. When omitted, the first item 8418 in {object} is used and {func} is first called for the second 8419 item. If {initial} is not given and {object} is empty no 8420 result can be computed, an E998 error is given. 8421 8422 Examples: >vim 8423 echo reduce([1, 3, 5], { acc, val -> acc + val }) 8424 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') 8425 echo reduce(0z1122, { acc, val -> 2 * acc + val }) 8426 echo reduce('xyz', { acc, val -> acc .. ',' .. val }) 8427< 8428 8429 Parameters: ~ 8430 • {object} (`any`) 8431 • {func} (`fun(accumulator: T, current: any): any`) 8432 • {initial} (`any?`) 8433 8434 Return: ~ 8435 (`T`) 8436 8437reg_executing() *reg_executing()* 8438 Returns the single letter name of the register being executed. 8439 Returns an empty string when no register is being executed. 8440 See |@|. 8441 8442 Return: ~ 8443 (`any`) 8444 8445reg_recorded() *reg_recorded()* 8446 Returns the single letter name of the last recorded register. 8447 Returns an empty string when nothing was recorded yet. 8448 See |q| and |Q|. 8449 8450 Return: ~ 8451 (`any`) 8452 8453reg_recording() *reg_recording()* 8454 Returns the single letter name of the register being recorded. 8455 Returns an empty string when not recording. See |q|. 8456 8457 Return: ~ 8458 (`any`) 8459 8460reltime() *reltime()* 8461reltime({start}) 8462reltime({start}, {end}) 8463 Lua: Prefer |uv.hrtime()|. 8464 8465 Return an item that represents a time value. The item is a 8466 list with items that depend on the system. 8467 The item can be passed to |reltimestr()| to convert it to a 8468 string or |reltimefloat()| to convert to a Float. 8469 8470 Without an argument it returns the current "relative time", an 8471 implementation-defined value meaningful only when used as an 8472 argument to |reltime()|, |reltimestr()| and |reltimefloat()|. 8473 8474 With one argument it returns the time passed since the time 8475 specified in the argument. 8476 With two arguments it returns the time passed between {start} 8477 and {end}. 8478 8479 The {start} and {end} arguments must be values returned by 8480 reltime(). Returns zero on error. 8481 8482 Note: |localtime()| returns the current (non-relative) time. 8483 8484 Attributes: ~ 8485 |api-fast| 8486 8487 Parameters: ~ 8488 • {start} (`any?`) 8489 • {end} (`any?`) 8490 8491 Return: ~ 8492 (`any`) 8493 8494reltimefloat({time}) *reltimefloat()* 8495 Lua: Prefer |uv.hrtime()| with `(finish - start) / 1e9` for 8496 elapsed seconds. 8497 8498 Return a Float that represents the time value of {time}. 8499 Unit of time is seconds. 8500 Example: 8501 let start = reltime() 8502 call MyFunction() 8503 let seconds = reltimefloat(reltime(start)) 8504 See the note of |reltimestr()| about overhead. 8505 Also see |profiling|. 8506 If there is an error an empty string is returned 8507 8508 Attributes: ~ 8509 |api-fast| 8510 8511 Parameters: ~ 8512 • {time} (`any`) 8513 8514 Return: ~ 8515 (`any`) 8516 8517reltimestr({time}) *reltimestr()* 8518 Return a String that represents the time value of {time}. 8519 This is the number of seconds, a dot and the number of 8520 microseconds. Example: >vim 8521 let start = reltime() 8522 call MyFunction() 8523 echo reltimestr(reltime(start)) 8524< Note that overhead for the commands will be added to the time. 8525 Leading spaces are used to make the string align nicely. You 8526 can use |split()| to remove it. >vim 8527 echo split(reltimestr(reltime(start)))[0] 8528< Also see |profiling|. 8529 If there is an error an empty string is returned 8530 8531 Attributes: ~ 8532 |api-fast| 8533 8534 Parameters: ~ 8535 • {time} (`any`) 8536 8537 Return: ~ 8538 (`any`) 8539 8540remove({list}, {idx}) *remove()* 8541 Lua: Prefer |table.remove()|. 8542 8543remove({list}, {idx}, {end}) 8544 Without {end}: Remove the item at {idx} from |List| {list} and 8545 return the item. 8546 With {end}: Remove items from {idx} to {end} (inclusive) and 8547 return a |List| with these items. When {idx} points to the same 8548 item as {end} a list with one item is returned. When {end} 8549 points to an item before {idx} this is an error. 8550 See |list-index| for possible values of {idx} and {end}. 8551 Returns zero on error. 8552 Example: >vim 8553 echo "last item: " .. remove(mylist, -1) 8554 call remove(mylist, 0, 9) 8555< 8556 Use |delete()| to remove a file. 8557 8558 Parameters: ~ 8559 • {list} (`any[]`) 8560 • {idx} (`integer`) 8561 • {end} (`integer?`) 8562 8563 Return: ~ 8564 (`any`) 8565 8566remove({blob}, {idx}) 8567remove({blob}, {idx}, {end}) 8568 Without {end}: Remove the byte at {idx} from |Blob| {blob} and 8569 return the byte. 8570 With {end}: Remove bytes from {idx} to {end} (inclusive) and 8571 return a |Blob| with these bytes. When {idx} points to the same 8572 byte as {end} a |Blob| with one byte is returned. When {end} 8573 points to a byte before {idx} this is an error. 8574 Returns zero on error. 8575 Example: >vim 8576 echo "last byte: " .. remove(myblob, -1) 8577 call remove(mylist, 0, 9) 8578< 8579 8580 Parameters: ~ 8581 • {blob} (`any`) 8582 • {idx} (`integer`) 8583 • {end} (`integer?`) 8584 8585 Return: ~ 8586 (`any`) 8587 8588remove({dict}, {key}) 8589 Lua: Prefer `local value = dict[key]; dict[key] = nil` for 8590 dicts; missing-key behavior differs. 8591 8592 Remove the entry from {dict} with key {key} and return it. 8593 Example: >vim 8594 echo "removed " .. remove(dict, "one") 8595< If there is no {key} in {dict} this is an error. 8596 Returns zero on error. 8597 8598 Parameters: ~ 8599 • {dict} (`any`) 8600 • {key} (`string`) 8601 8602 Return: ~ 8603 (`any`) 8604 8605rename({from}, {to}) *rename()* 8606 Lua: Prefer |uv.fs_rename()| or |os.rename()|. 8607 8608 Rename the file by the name {from} to the name {to}. This 8609 should also work to move files across file systems. The 8610 result is a Number, which is 0 if the file was renamed 8611 successfully, and non-zero when the renaming failed. 8612 NOTE: If {to} exists it is overwritten without warning. 8613 This function is not available in the |sandbox|. 8614 8615 Parameters: ~ 8616 • {from} (`string`) 8617 • {to} (`string`) 8618 8619 Return: ~ 8620 (`integer`) 8621 8622repeat({expr}, {count}) *repeat()* 8623 Lua: Prefer |string.rep()| for strings; lists need manual 8624 repetition. 8625 8626 Repeat {expr} {count} times and return the concatenated 8627 result. Example: >vim 8628 let separator = repeat('-', 80) 8629< When {count} is zero or negative the result is empty. 8630 When {expr} is a |List| or a |Blob| the result is {expr} 8631 concatenated {count} times. Example: >vim 8632 let longlist = repeat(['a', 'b'], 3) 8633< Results in ['a', 'b', 'a', 'b', 'a', 'b']. 8634 8635 Attributes: ~ 8636 |api-fast| 8637 8638 Parameters: ~ 8639 • {expr} (`any`) 8640 • {count} (`integer`) 8641 8642 Return: ~ 8643 (`any`) 8644 8645resolve({filename}) *resolve()* *E655* 8646 On MS-Windows, when {filename} is a shortcut (a .lnk file), 8647 returns the path the shortcut points to in a simplified form. 8648 On Unix, repeat resolving symbolic links in all path 8649 components of {filename} and return the simplified result. 8650 To cope with link cycles, resolving of symbolic links is 8651 stopped after 100 iterations. 8652 On other systems, return the simplified {filename}. 8653 The simplification step is done as by |simplify()|. 8654 resolve() keeps a leading path component specifying the 8655 current directory (provided the result is still a relative 8656 path name) and also keeps a trailing path separator. 8657 8658 Attributes: ~ 8659 |api-fast| 8660 8661 Parameters: ~ 8662 • {filename} (`string`) 8663 8664 Return: ~ 8665 (`string`) 8666 8667reverse({object}) *reverse()* 8668 Lua: Prefer `vim.iter(list):rev():totable()` for lists; 8669 strings, blobs, and in-place behavior differ. 8670 8671 Reverse the order of items in {object}. {object} can be a 8672 |List|, a |Blob| or a |String|. For a List and a Blob the 8673 items are reversed in-place and {object} is returned. 8674 For a String a new String is returned. 8675 Returns zero if {object} is not a List, Blob or a String. 8676 If you want a List or Blob to remain unmodified make a copy 8677 first: >vim 8678 let revlist = reverse(copy(mylist)) 8679< 8680 8681 Parameters: ~ 8682 • {object} (`T[]`) 8683 8684 Return: ~ 8685 (`T[]`) 8686 8687round({expr}) *round()* 8688 Lua: Prefer 8689 `expr >= 0 and math.floor(expr + 0.5) or math.ceil(expr - 0.5)` 8690 for half-away-from-zero rounding. 8691 8692 Round off {expr} to the nearest integral value and return it 8693 as a |Float|. If {expr} lies halfway between two integral 8694 values, then use the larger one (away from zero). 8695 {expr} must evaluate to a |Float| or a |Number|. 8696 Returns 0.0 if {expr} is not a |Float| or a |Number|. 8697 Examples: >vim 8698 echo round(0.456) 8699< 0.0 >vim 8700 echo round(4.5) 8701< 5.0 >vim 8702 echo round(-4.5) 8703< -5.0 8704 8705 Parameters: ~ 8706 • {expr} (`number`) 8707 8708 Return: ~ 8709 (`number`) 8710 8711rpcnotify({channel}, {event} [, {args}...]) *rpcnotify()* 8712 Lua: Prefer |vim.rpcnotify()|. 8713 8714 Sends {event} to {channel} via |RPC| and returns immediately. 8715 If {channel} is 0, the event is broadcast to all channels. 8716 Example: >vim 8717 au VimLeave call rpcnotify(0, "leaving") 8718< 8719 8720 Parameters: ~ 8721 • {channel} (`integer`) 8722 • {event} (`string`) 8723 • {...} (`any`) 8724 8725 Return: ~ 8726 (`integer`) 8727 8728rpcrequest({channel}, {method} [, {args}...]) *rpcrequest()* 8729 Lua: Prefer |vim.rpcrequest()|. 8730 8731 Sends a request to {channel} to invoke {method} via 8732 |RPC| and blocks until a response is received. 8733 Example: >vim 8734 let result = rpcrequest(rpc_chan, "func", 1, 2, 3) 8735< 8736 8737 Parameters: ~ 8738 • {channel} (`integer`) 8739 • {method} (`string`) 8740 • {...} (`any`) 8741 8742 Return: ~ 8743 (`any`) 8744 8745rubyeval({expr}) *rubyeval()* 8746 Evaluate Ruby expression {expr} and return its result 8747 converted to Vim data structures. 8748 Numbers, floats and strings are returned as they are (strings 8749 are copied though). 8750 Arrays are represented as Vim |List| type. 8751 Hashes are represented as Vim |Dictionary| type. 8752 Other objects are represented as strings resulted from their 8753 "Object#to_s" method. 8754 8755 Parameters: ~ 8756 • {expr} (`any`) 8757 8758 Return: ~ 8759 (`any`) 8760 8761screenattr({row}, {col}) *screenattr()* 8762 Like |screenchar()|, but return the attribute. This is a rather 8763 arbitrary number that can only be used to compare to the 8764 attribute at other positions. 8765 Returns -1 when row or col is out of range. 8766 8767 Parameters: ~ 8768 • {row} (`integer`) 8769 • {col} (`integer`) 8770 8771 Return: ~ 8772 (`integer`) 8773 8774screenchar({row}, {col}) *screenchar()* 8775 Returns the character at screen position [row, col] as a 8776 Number. This works for every possible screen position, also 8777 status lines, window separators and the command line. The 8778 top left position is row one, column one. The character 8779 excludes composing characters. For double-byte 8780 encodings it may only be the first byte. 8781 This is mainly to be used for testing. 8782 Returns -1 when row or col is out of range. 8783 8784 Parameters: ~ 8785 • {row} (`integer`) 8786 • {col} (`integer`) 8787 8788 Return: ~ 8789 (`integer`) 8790 8791screenchars({row}, {col}) *screenchars()* 8792 Returns the character and any composing characters at screen 8793 position [row, col] as a |List| of Numbers. The first number 8794 is the same as what |screenchar()| returns; further numbers 8795 are composing characters on top of the base character. 8796 This is mainly to be used for testing. 8797 Returns an empty List when row or col is out of range. 8798 8799 Parameters: ~ 8800 • {row} (`integer`) 8801 • {col} (`integer`) 8802 8803 Return: ~ 8804 (`integer[]`) 8805 8806screencol() *screencol()* 8807 Returns the current screen column of the cursor. The 8808 leftmost column has number 1. 8809 This function is mainly used for testing. 8810 8811 Note: Always returns the current screen column, thus if used 8812 in a command (e.g. ":echo screencol()") it will return the 8813 column inside the command line, which is 1 when the command is 8814 executed. To get the cursor position in the file use one of 8815 the following mappings: >vim 8816 nnoremap <expr> GG ":echom " .. screencol() .. "\n" 8817 nnoremap <silent> GG :echom screencol()<CR> 8818 noremap GG <Cmd>echom screencol()<CR> 8819< 8820 8821 Return: ~ 8822 (`integer`) 8823 8824screenpos({winid}, {lnum}, {col}) *screenpos()* 8825 Returns the screen position of the text character in window 8826 {winid} at buffer line {lnum} and column {col} as a Dict. 8827 {col} is a one-based byte index. 8828 The Dict has these members: 8829 row screen row 8830 col first screen column 8831 endcol last screen column 8832 curscol cursor screen column 8833 If the specified position is not visible, all values are zero. 8834 The "endcol" value differs from "col" when the character 8835 occupies more than one screen cell. E.g. for a Tab "col" can 8836 be 1 and "endcol" can be 8. 8837 The "curscol" value is where the cursor would be placed. For 8838 a Tab it would be the same as "endcol", while for a double 8839 width character it would be the same as "col". 8840 The |conceal| feature is ignored here, the column numbers are 8841 as if 'conceallevel' is zero. You can set the cursor to the 8842 right position and use |screencol()| to get the value with 8843 |conceal| taken into account. 8844 If the position is in a closed fold the screen position of the 8845 first character is returned, {col} is not used. 8846 Returns an empty Dict if {winid} is invalid. 8847 8848 Parameters: ~ 8849 • {winid} (`integer`) 8850 • {lnum} (`integer`) 8851 • {col} (`integer`) 8852 8853 Return: ~ 8854 (`{ col: integer, curscol: integer, endcol: integer, row: integer }`) 8855 8856screenrow() *screenrow()* 8857 Returns the current screen row of the cursor. The top line 8858 has number one. 8859 This function is mainly used for testing. 8860 Alternatively you can use |winline()|. 8861 8862 Note: Same restrictions as with |screencol()|. 8863 8864 Return: ~ 8865 (`integer`) 8866 8867screenstring({row}, {col}) *screenstring()* 8868 Returns the base character and any composing characters at 8869 screen position [row, col] as a String. This is like 8870 |screenchars()| but returning a String with the characters. 8871 This is mainly to be used for testing. 8872 Returns an empty String when row or col is out of range. 8873 8874 Parameters: ~ 8875 • {row} (`integer`) 8876 • {col} (`integer`) 8877 8878 Return: ~ 8879 (`string`) 8880 8881search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) *search()* 8882 Search for regexp pattern {pattern}. The search starts at the 8883 cursor position (you can use |cursor()| to set it). 8884 8885 When a match has been found its line number is returned. 8886 If there is no match a 0 is returned and the cursor doesn't 8887 move. No error message is given. 8888 To get the matched string, use |matchbufline()|. 8889 8890 {flags} is a String, which can contain these character flags: 8891 'b' search Backward instead of forward 8892 'c' accept a match at the Cursor position 8893 'e' move to the End of the match 8894 'n' do Not move the cursor 8895 'p' return number of matching sub-Pattern (see below) 8896 's' Set the ' mark at the previous location of the cursor 8897 'w' Wrap around the end of the file 8898 'W' don't Wrap around the end of the file 8899 'z' start searching at the cursor column instead of Zero 8900 If neither 'w' or 'W' is given, the 'wrapscan' option applies. 8901 8902 If the 's' flag is supplied, the ' mark is set, only if the 8903 cursor is moved. The 's' flag cannot be combined with the 'n' 8904 flag. 8905 8906 'ignorecase', 'smartcase' and 'magic' are used. 8907 8908 When the 'z' flag is not given, forward searching always 8909 starts in column zero and then matches before the cursor are 8910 skipped. When the 'c' flag is present in 'cpo' the next 8911 search starts after the match. Without the 'c' flag the next 8912 search starts one column after the start of the match. This 8913 matters for overlapping matches. See |cpo-c|. You can also 8914 insert "\ze" to change where the match ends, see |/\ze|. 8915 8916 When searching backwards and the 'z' flag is given then the 8917 search starts in column zero, thus no match in the current 8918 line will be found (unless wrapping around the end of the 8919 file). 8920 8921 When the {stopline} argument is given then the search stops 8922 after searching this line. This is useful to restrict the 8923 search to a range of lines. Examples: >vim 8924 let match = search('(', 'b', line("w0")) 8925 let end = search('END', '', line("w$")) 8926< When {stopline} is used and it is not zero this also implies 8927 that the search does not wrap around the end of the file. 8928 A zero value is equal to not giving the argument. 8929 8930 When the {timeout} argument is given the search stops when 8931 more than this many milliseconds have passed. Thus when 8932 {timeout} is 500 the search stops after half a second. 8933 The value must not be negative. A zero value is like not 8934 giving the argument. 8935 8936 Note: the timeout is only considered when searching, not 8937 while evaluating the {skip} expression. 8938 8939 If the {skip} expression is given it is evaluated with the 8940 cursor positioned on the start of a match. If it evaluates to 8941 non-zero this match is skipped. This can be used, for 8942 example, to skip a match in a comment or a string. 8943 {skip} can be a string, which is evaluated as an expression, a 8944 function reference or a lambda. 8945 When {skip} is omitted or empty, every match is accepted. 8946 When evaluating {skip} causes an error the search is aborted 8947 and -1 returned. 8948 *search()-sub-match* 8949 With the 'p' flag the returned value is one more than the 8950 first sub-match in \(\). One if none of them matched but the 8951 whole pattern did match. 8952 To get the column number too use |searchpos()|. 8953 8954 The cursor will be positioned at the match, unless the 'n' 8955 flag is used. 8956 8957 Example (goes over all files in the argument list): >vim 8958 let n = 1 8959 while n <= argc() " loop over all files in arglist 8960 exe "argument " .. n 8961 " start at the last char in the file and wrap for the 8962 " first search to find match at start of file 8963 normal G$ 8964 let flags = "w" 8965 while search("foo", flags) > 0 8966 s/foo/bar/g 8967 let flags = "W" 8968 endwhile 8969 update " write the file if modified 8970 let n = n + 1 8971 endwhile 8972< 8973 Example for using some flags: >vim 8974 echo search('\<if\|\(else\)\|\(endif\)', 'ncpe') 8975< This will search for the keywords "if", "else", and "endif" 8976 under or after the cursor. Because of the 'p' flag, it 8977 returns 1, 2, or 3 depending on which keyword is found, or 0 8978 if the search fails. With the cursor on the first word of the 8979 line: 8980 if (foo == 0) | let foo = foo + 1 | endif ~ 8981 the function returns 1. Without the 'c' flag, the function 8982 finds the "endif" and returns 3. The same thing happens 8983 without the 'e' flag if the cursor is on the "f" of "if". 8984 The 'n' flag tells the function not to move the cursor. 8985 8986 Parameters: ~ 8987 • {pattern} (`string`) 8988 • {flags} (`string?`) 8989 • {stopline} (`integer?`) 8990 • {timeout} (`integer?`) 8991 • {skip} (`string|function?`) 8992 8993 Return: ~ 8994 (`integer`) 8995 8996searchcount([{options}]) *searchcount()* 8997 Get or update the last search count, like what is displayed 8998 without the "S" flag in 'shortmess'. This works even if 8999 'shortmess' does contain the "S" flag. 9000 9001 This returns a |Dictionary|. The dictionary is empty if the 9002 previous pattern was not set and "pattern" was not specified. 9003 9004 key type meaning ~ 9005 current |Number| current position of match; 9006 0 if the cursor position is 9007 before the first match 9008 exact_match |Boolean| 1 if "current" is matched on 9009 "pos", otherwise 0 9010 total |Number| total count of matches found 9011 incomplete |Number| 0: search was fully completed 9012 1: recomputing was timed out 9013 2: max count exceeded 9014 9015 For {options} see further down. 9016 9017 To get the last search count when |n| or |N| was pressed, call 9018 this function with `recompute: 0` . This sometimes returns 9019 wrong information because of 'maxsearchcount'. 9020 If the count exceeded 'maxsearchcount', the result must be 9021 'maxsearchcount' + 1. If you want to get correct information, 9022 specify `recompute: 1`: >vim 9023 9024 " result == 'maxsearchcount' + 1 when many matches 9025 let result = searchcount(#{recompute: 0}) 9026 9027 " Below returns correct result (recompute defaults 9028 " to 1) 9029 let result = searchcount() 9030< 9031 The function is useful to add the count to 'statusline': >vim 9032 function! LastSearchCount() abort 9033 let result = searchcount(#{recompute: 0}) 9034 if empty(result) 9035 return '' 9036 endif 9037 if result.incomplete ==# 1 " timed out 9038 return printf(' /%s [?/??]', @/) 9039 elseif result.incomplete ==# 2 " max count exceeded 9040 if result.total > result.maxcount && 9041 \ result.current > result.maxcount 9042 return printf(' /%s [>%d/>%d]', @/, 9043 \ result.current, result.total) 9044 elseif result.total > result.maxcount 9045 return printf(' /%s [%d/>%d]', @/, 9046 \ result.current, result.total) 9047 endif 9048 endif 9049 return printf(' /%s [%d/%d]', @/, 9050 \ result.current, result.total) 9051 endfunction 9052 let &statusline ..= '%{LastSearchCount()}' 9053 9054 " Or if you want to show the count only when 9055 " 'hlsearch' was on 9056 " let &statusline ..= 9057 " \ '%{v:hlsearch ? LastSearchCount() : ""}' 9058< 9059 You can also update the search count, which can be useful in a 9060 |CursorMoved| or |CursorMovedI| autocommand: >vim 9061 9062 autocmd CursorMoved,CursorMovedI * 9063 \ let s:searchcount_timer = timer_start( 9064 \ 200, function('s:update_searchcount')) 9065 function! s:update_searchcount(timer) abort 9066 if a:timer ==# s:searchcount_timer 9067 call searchcount(#{ 9068 \ recompute: 1, maxcount: 0, timeout: 100}) 9069 redrawstatus 9070 endif 9071 endfunction 9072< 9073 This can also be used to count matched texts with specified 9074 pattern in the current buffer using "pattern": >vim 9075 9076 " Count '\<foo\>' in this buffer 9077 " (Note that it also updates search count) 9078 let result = searchcount(#{pattern: '\<foo\>'}) 9079 9080 " To restore old search count by old pattern, 9081 " search again 9082 call searchcount() 9083< 9084 {options} must be a |Dictionary|. It can contain: 9085 key type meaning ~ 9086 recompute |Boolean| if |TRUE|, recompute the count 9087 like |n| or |N| was executed. 9088 otherwise returns the last 9089 computed result (when |n| or 9090 |N| was used when "S" is not 9091 in 'shortmess', or this 9092 function was called). 9093 (default: |TRUE|) 9094 pattern |String| recompute if this was given 9095 and different with |@/|. 9096 this works as same as the 9097 below command is executed 9098 before calling this function >vim 9099 let @/ = pattern 9100< (default: |@/|) 9101 timeout |Number| 0 or negative number is no 9102 timeout. timeout milliseconds 9103 for recomputing the result 9104 (default: 0) 9105 maxcount |Number| 0 or negative number is no 9106 limit. max count of matched 9107 text while recomputing the 9108 result. if search exceeded 9109 total count, "total" value 9110 becomes `maxcount + 1` 9111 (default: 'maxsearchcount') 9112 pos |List| `[lnum, col, off]` value 9113 when recomputing the result. 9114 this changes "current" result 9115 value. see |cursor()|, |getpos()| 9116 (default: cursor's position) 9117 9118 Parameters: ~ 9119 • {options} (`table?`) 9120 9121 Return: ~ 9122 (`any`) 9123 9124searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()* 9125 Search for the declaration of {name}. 9126 9127 With a non-zero {global} argument it works like |gD|, find 9128 first match in the file. Otherwise it works like |gd|, find 9129 first match in the function. 9130 9131 With a non-zero {thisblock} argument matches in a {} block 9132 that ends before the cursor position are ignored. Avoids 9133 finding variable declarations only valid in another scope. 9134 9135 Moves the cursor to the found match. 9136 Returns zero for success, non-zero for failure. 9137 Example: >vim 9138 if searchdecl('myvar') == 0 9139 echo getline('.') 9140 endif 9141< 9142 9143 Parameters: ~ 9144 • {name} (`string`) 9145 • {global} (`boolean?`) 9146 • {thisblock} (`boolean?`) 9147 9148 Return: ~ 9149 (`any`) 9150 9151 *searchpair()* 9152searchpair({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline} [, {timeout}]]]]) 9153 Search for the match of a nested start-end pair. This can be 9154 used to find the "endif" that matches an "if", while other 9155 if/endif pairs in between are ignored. 9156 The search starts at the cursor. The default is to search 9157 forward, include 'b' in {flags} to search backward. 9158 If a match is found, the cursor is positioned at it and the 9159 line number is returned. If no match is found 0 or -1 is 9160 returned and the cursor doesn't move. No error message is 9161 given. 9162 9163 {start}, {middle} and {end} are patterns, see |pattern|. They 9164 must not contain \( \) pairs. Use of \%( \) is allowed. When 9165 {middle} is not empty, it is found when searching from either 9166 direction, but only when not in a nested start-end pair. A 9167 typical use is: >vim 9168 echo searchpair('\<if\>', '\<else\>', '\<endif\>') 9169< By leaving {middle} empty the "else" is skipped. 9170 9171 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with 9172 |search()|. Additionally: 9173 'r' Repeat until no more matches found; will find the 9174 outer pair. Implies the 'W' flag. 9175 'm' Return number of matches instead of line number with 9176 the match; will be > 1 when 'r' is used. 9177 Note: it's nearly always a good idea to use the 'W' flag, to 9178 avoid wrapping around the end of the file. 9179 9180 When a match for {start}, {middle} or {end} is found, the 9181 {skip} expression is evaluated with the cursor positioned on 9182 the start of the match. It should return non-zero if this 9183 match is to be skipped. E.g., because it is inside a comment 9184 or a string. 9185 When {skip} is omitted or empty, every match is accepted. 9186 When evaluating {skip} causes an error the search is aborted 9187 and -1 returned. 9188 {skip} can be a string, a lambda, a funcref or a partial. 9189 Anything else makes the function fail. 9190 9191 For {stopline} and {timeout} see |search()|. 9192 9193 The value of 'ignorecase' is used. 'magic' is ignored, the 9194 patterns are used like it's on. 9195 9196 The search starts exactly at the cursor. A match with 9197 {start}, {middle} or {end} at the next character, in the 9198 direction of searching, is the first one found. Example: >vim 9199 if 1 9200 if 2 9201 endif 2 9202 endif 1 9203< When starting at the "if 2", with the cursor on the "i", and 9204 searching forwards, the "endif 2" is found. When starting on 9205 the character just before the "if 2", the "endif 1" will be 9206 found. That's because the "if 2" will be found first, and 9207 then this is considered to be a nested if/endif from "if 2" to 9208 "endif 2". 9209 When searching backwards and {end} is more than one character, 9210 it may be useful to put "\zs" at the end of the pattern, so 9211 that when the cursor is inside a match with the end it finds 9212 the matching start. 9213 9214 Example, to find the "endif" command in a Vim script: >vim 9215 9216 echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W', 9217 \ 'getline(".") =~ "^\\s*\""') 9218 9219< The cursor must be at or after the "if" for which a match is 9220 to be found. Note that single-quote strings are used to avoid 9221 having to double the backslashes. The skip expression only 9222 catches comments at the start of a line, not after a command. 9223 Also, a word "en" or "if" halfway through a line is considered 9224 a match. 9225 Another example, to search for the matching "{" of a "}": >vim 9226 9227 echo searchpair('{', '', '}', 'bW') 9228 9229< This works when the cursor is at or before the "}" for which a 9230 match is to be found. To reject matches that syntax 9231 highlighting recognized as strings: >vim 9232 9233 echo searchpair('{', '', '}', 'bW', 9234 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"') 9235< 9236 9237 Parameters: ~ 9238 • {start} (`string`) 9239 • {middle} (`string`) 9240 • {end} (`string`) 9241 • {flags} (`string?`) 9242 • {skip} (`string|function?`) 9243 • {stopline} (`integer?`) 9244 • {timeout} (`integer?`) 9245 9246 Return: ~ 9247 (`integer`) 9248 9249 *searchpairpos()* 9250searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline} [, {timeout}]]]]) 9251 Same as |searchpair()|, but returns a |List| with the line and 9252 column position of the match. The first element of the |List| 9253 is the line number and the second element is the byte index of 9254 the column position of the match. If no match is found, 9255 returns [0, 0]. >vim 9256 9257 let [lnum,col] = searchpairpos('{', '', '}', 'n') 9258< 9259 See |match-parens| for a bigger and more useful example. 9260 9261 Parameters: ~ 9262 • {start} (`string`) 9263 • {middle} (`string`) 9264 • {end} (`string`) 9265 • {flags} (`string?`) 9266 • {skip} (`string|function?`) 9267 • {stopline} (`integer?`) 9268 • {timeout} (`integer?`) 9269 9270 Return: ~ 9271 (`[integer, integer]`) 9272 9273 *searchpos()* 9274searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) 9275 Same as |search()|, but returns a |List| with the line and 9276 column position of the match. The first element of the |List| 9277 is the line number and the second element is the byte index of 9278 the column position of the match. If no match is found, 9279 returns [0, 0]. 9280 Example: >vim 9281 let [lnum, col] = searchpos('mypattern', 'n') 9282 9283< When the 'p' flag is given then there is an extra item with 9284 the sub-pattern match number |search()-sub-match|. Example: >vim 9285 let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np') 9286< In this example "submatch" is 2 when a lowercase letter is 9287 found |/\l|, 3 when an uppercase letter is found |/\u|. 9288 9289 Parameters: ~ 9290 • {pattern} (`string`) 9291 • {flags} (`string?`) 9292 • {stopline} (`integer?`) 9293 • {timeout} (`integer?`) 9294 • {skip} (`string|function?`) 9295 9296 Return: ~ 9297 (`{ [1]: integer, [2]: integer, [3]: integer? }`) 9298 9299serverlist([{opts}]) *serverlist()* 9300 Returns a list of server addresses, or empty if all servers 9301 were stopped. |serverstart()| |serverstop()| 9302 9303 The optional argument {opts} is a Dict and supports the following items: 9304 9305 peer : If |TRUE|, servers not started by |serverstart()| 9306 will also be returned. (default: |FALSE|) 9307 Not supported on Windows yet. 9308 9309 info : If |TRUE|, return a list of Dicts with detailed info 9310 instead of addresses. Implies `peer=true`. Each Dict 9311 has the following items: 9312 addr (string) Server address. 9313 pid (number) PID of the Nvim process. 9314 own (bool) Whether this server belongs to 9315 the current Nvim instance. 9316 active (number) |v:useractive| of the server. 9317 (default: |FALSE|) 9318 9319 Example: >vim 9320 echo serverlist() 9321 echo serverlist(#{info: v:true}) 9322< 9323 9324 Parameters: ~ 9325 • {opts} (`table?`) 9326 9327 Return: ~ 9328 (`string[]|vim.ServerInfo[]`) 9329 9330serverstart([{address}]) *serverstart()* 9331 Opens a socket or named pipe at {address} and listens for 9332 |RPC| messages. Clients can send |API| commands to the 9333 returned address to control Nvim. 9334 9335 Returns the address string (which may differ from the 9336 {address} argument, see below). 9337 9338 - If {address} has a colon (":") it is a TCP/IPv4/IPv6 address 9339 where the last ":" separates host and port (empty or zero 9340 assigns a random port). 9341 - Else {address} is the path to a named pipe (except on Windows). 9342 - If {address} has no slashes ("/") it is treated as the 9343 "name" part of a generated path in this format: >vim 9344 stdpath("run").."/{name}.{pid}.{counter}" 9345< - If {address} is omitted the name is "nvim". >vim 9346 echo serverstart() 9347< > 9348 => /tmp/nvim.bram/oknANW/nvim.15430.5 9349< 9350 Example bash command to list all Nvim servers: >bash 9351 ls ${XDG_RUNTIME_DIR:-${TMPDIR}nvim.${USER}}/*/nvim.*.0 9352 9353< Example named pipe: >vim 9354 if has('win32') 9355 echo serverstart('//./pipe/nvim-pipe-1234') 9356 else 9357 echo serverstart('nvim.sock') 9358 endif 9359< 9360 Example TCP/IP address: >vim 9361 echo serverstart('::1:12345') 9362< 9363 9364 Parameters: ~ 9365 • {address} (`string?`) 9366 9367 Return: ~ 9368 (`string`) 9369 9370serverstop({address}) *serverstop()* 9371 Closes the pipe or socket at {address}. 9372 Returns TRUE if {address} is valid, else FALSE. 9373 If |v:servername| is stopped it is set to the next available 9374 address in |serverlist()|. 9375 9376 Parameters: ~ 9377 • {address} (`string`) 9378 9379 Return: ~ 9380 (`integer`) 9381 9382setbufline({buf}, {lnum}, {text}) *setbufline()* 9383 Lua: Prefer |nvim_buf_set_lines()|. 9384 9385 Set line {lnum} to {text} in buffer {buf}. This works like 9386 |setline()| for the specified buffer. 9387 9388 This function works only for loaded buffers. First call 9389 |bufload()| if needed. 9390 9391 To insert lines use |appendbufline()|. 9392 9393 {text} can be a string to set one line, or a List of strings 9394 to set multiple lines. If the List extends below the last 9395 line then those lines are added. If the List is empty then 9396 nothing is changed and zero is returned. 9397 9398 For the use of {buf}, see |bufname()| above. 9399 9400 {lnum} is used like with |setline()|. 9401 Use "$" to refer to the last line in buffer {buf}. 9402 When {lnum} is just below the last line the {text} will be 9403 added below the last line. 9404 On success 0 is returned, on failure 1 is returned. 9405 9406 If {buf} is not a valid buffer or {lnum} is not valid, an 9407 error message is given. 9408 9409 Parameters: ~ 9410 • {buf} (`integer|string`) 9411 • {lnum} (`integer`) 9412 • {text} (`string|string[]`) 9413 9414 Return: ~ 9415 (`integer`) 9416 9417setbufvar({buf}, {varname}, {val}) *setbufvar()* 9418 Lua: Prefer |nvim_buf_set_var()| or |vim.b| after resolving 9419 {buf} to a bufnr; option names use |nvim_set_option_value()|. 9420 9421 Set option or local variable {varname} (string, without "b:") 9422 in buffer {buf} to {val}. Also works for a global or 9423 window-local option (not variable). A window-local option is 9424 set in a window of the current tabpage that displays {buf}, 9425 and the global value is unchanged. When no window in the 9426 current tabpage displays {buf} the option is not set and no 9427 error is given; use |setwinvar()| or |win_execute()| for that. 9428 9429 For the use of {buf}, see |bufname()| above. 9430 9431 Examples: >vim 9432 call setbufvar(1, "&mod", 1) 9433 call setbufvar("todo", "myvar", "foobar") 9434< This function is not available in the |sandbox|. 9435 9436 Parameters: ~ 9437 • {buf} (`integer|string`) 9438 • {varname} (`string`) 9439 • {val} (`any`) 9440 9441 Return: ~ 9442 (`any`) 9443 9444setcellwidths({list}) *setcellwidths()* 9445 Specify overrides for cell widths of character ranges. This 9446 tells Vim how wide characters are when displayed in the 9447 terminal, counted in screen cells. The values override 9448 'ambiwidth'. Example: >vim 9449 call setcellwidths([ 9450 \ [0x111, 0x111, 1], 9451 \ [0x2194, 0x2199, 2], 9452 \ ]) 9453 9454< The {list} argument is a List of Lists with each three 9455 numbers: [{low}, {high}, {width}]. *E1109* *E1110* 9456 {low} and {high} can be the same, in which case this refers to 9457 one character. Otherwise it is the range of characters from 9458 {low} to {high} (inclusive). *E1111* *E1114* 9459 Only characters with value 0x80 and higher can be used. 9460 9461 {width} must be either 1 or 2, indicating the character width 9462 in screen cells. *E1112* 9463 An error is given if the argument is invalid, also when a 9464 range overlaps with another. *E1113* 9465 9466 If the new value causes 'fillchars' or 'listchars' to become 9467 invalid it is rejected and an error is given. 9468 9469 To clear the overrides pass an empty {list}: >vim 9470 call setcellwidths([]) 9471 9472< You can use the script $VIMRUNTIME/scripts/emoji_list.lua to see 9473 the effect for known emoji characters. Move the cursor 9474 through the text to check if the cell widths of your terminal 9475 match with what Vim knows about each emoji. If it doesn't 9476 look right you need to adjust the {list} argument. 9477 9478 |getcellwidths()| can be used to get the overrides later. 9479 9480 Parameters: ~ 9481 • {list} (`any[]`) 9482 9483 Return: ~ 9484 (`any`) 9485 9486setcharpos({expr}, {list}) *setcharpos()* 9487 Lua: Prefer |nvim_win_set_cursor()| or |nvim_buf_set_mark()| 9488 with |vim.str_byteindex()|; special positions, `off`, and 9489 `curswant` differ. 9490 9491 Same as |setpos()| but uses the specified column number as the 9492 character index instead of the byte index in the line. 9493 9494 Example: 9495 With the text "여보세요" in line 8: >vim 9496 call setcharpos('.', [0, 8, 4, 0]) 9497< positions the cursor on the fourth character '요'. >vim 9498 call setpos('.', [0, 8, 4, 0]) 9499< positions the cursor on the second character '보'. 9500 9501 Parameters: ~ 9502 • {expr} (`string`) 9503 • {list} (`integer[]`) 9504 9505 Return: ~ 9506 (`any`) 9507 9508setcharsearch({dict}) *setcharsearch()* 9509 Set the current character search information to {dict}, 9510 which contains one or more of the following entries: 9511 9512 char character which will be used for a subsequent 9513 |,| or |;| command; an empty string clears the 9514 character search 9515 forward direction of character search; 1 for forward, 9516 0 for backward 9517 until type of character search; 1 for a |t| or |T| 9518 character search, 0 for an |f| or |F| 9519 character search 9520 9521 This can be useful to save/restore a user's character search 9522 from a script: >vim 9523 let prevsearch = getcharsearch() 9524 " Perform a command which clobbers user's search 9525 call setcharsearch(prevsearch) 9526< Also see |getcharsearch()|. 9527 9528 Parameters: ~ 9529 • {dict} (`{ char?: string, forward?: 1|0, until?: 1|0 }`) 9530 9531 Return: ~ 9532 (`any`) 9533 9534setcmdline({str} [, {pos}]) *setcmdline()* 9535 Set the command line to {str} and set the cursor position to 9536 {pos}. 9537 If {pos} is omitted, the cursor is positioned after the text. 9538 Returns 0 when successful, 1 when not editing the command 9539 line. 9540 9541 Parameters: ~ 9542 • {str} (`string`) 9543 • {pos} (`integer?`) 9544 9545 Return: ~ 9546 (`integer`) 9547 9548setcmdpos({pos}) *setcmdpos()* 9549 Set the cursor position in the command line to byte position 9550 {pos}. The first position is 1. 9551 Use |getcmdpos()| to obtain the current position. 9552 Only works while editing the command line, thus you must use 9553 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For 9554 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is 9555 set after the command line is set to the expression. For 9556 |c_CTRL-R_=| it is set after evaluating the expression but 9557 before inserting the resulting text. 9558 When the number is too big the cursor is put at the end of the 9559 line. A number smaller than one has undefined results. 9560 Returns 0 when successful, 1 when not editing the command 9561 line. 9562 9563 Parameters: ~ 9564 • {pos} (`integer`) 9565 9566 Return: ~ 9567 (`any`) 9568 9569setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()* 9570 Lua: Prefer |nvim_win_set_cursor()| with 9571 |vim.str_byteindex()|; `off`, return values, and special line 9572 forms differ. 9573 9574setcursorcharpos({list}) 9575 Lua: Prefer |nvim_win_set_cursor()| with 9576 |vim.str_byteindex()|; list shape, `off`, and return values 9577 differ. 9578 9579 Same as |cursor()| but uses the specified column number as the 9580 character index instead of the byte index in the line. 9581 9582 Example: 9583 With the text "여보세요" in line 4: >vim 9584 call setcursorcharpos(4, 3) 9585< positions the cursor on the third character '세'. >vim 9586 call cursor(4, 3) 9587< positions the cursor on the first character '여'. 9588 9589 Returns 0 when the position could be set, -1 otherwise. 9590 9591 Parameters: ~ 9592 • {list} (`integer[]`) 9593 9594 Return: ~ 9595 (`any`) 9596 9597setenv({name}, {val}) *setenv()* 9598 Lua: Prefer |vim.env|. 9599 9600 Set environment variable {name} to {val}. Example: >vim 9601 call setenv('HOME', '/home/myhome') 9602 9603< When {val} is |v:null| the environment variable is deleted. 9604 See also |expr-env|. 9605 9606 Parameters: ~ 9607 • {name} (`string`) 9608 • {val} (`string`) 9609 9610 Return: ~ 9611 (`any`) 9612 9613setfperm({fname}, {mode}) *setfperm()* *chmod* 9614 Lua: Prefer |uv.fs_chmod()|. 9615 9616 Set the file permissions for {fname} to {mode}. 9617 {mode} must be a string with 9 characters. It is of the form 9618 "rwxrwxrwx", where each group of "rwx" flags represent, in 9619 turn, the permissions of the owner of the file, the group the 9620 file belongs to, and other users. A '-' character means the 9621 permission is off, any other character means on. Multi-byte 9622 characters are not supported. 9623 9624 For example "rw-r-----" means read-write for the user, 9625 readable by the group, not accessible by others. "xx-x-----" 9626 would do the same thing. 9627 9628 Returns non-zero for success, zero for failure. 9629 9630 To read permissions see |getfperm()|. 9631 9632 Parameters: ~ 9633 • {fname} (`string`) 9634 • {mode} (`string`) 9635 9636 Return: ~ 9637 (`any`) 9638 9639setline({lnum}, {text}) *setline()* 9640 Lua: Prefer |nvim_set_current_line()| or 9641 |nvim_buf_set_lines()|. 9642 9643 Set line {lnum} of the current buffer to {text}. To insert 9644 lines use |append()|. To set lines in another buffer use 9645 |setbufline()|. 9646 9647 {lnum} is used like with |getline()|. 9648 When {lnum} is just below the last line the {text} will be 9649 added below the last line. 9650 {text} can be any type or a List of any type, each item is 9651 converted to a String. When {text} is an empty List then 9652 nothing is changed and FALSE is returned. 9653 9654 If this succeeds, FALSE is returned. If this fails (most 9655 likely because {lnum} is invalid) TRUE is returned. 9656 9657 Example: >vim 9658 call setline(5, strftime("%c")) 9659 9660< When {text} is a |List| then line {lnum} and following lines 9661 will be set to the items in the list. Example: >vim 9662 call setline(5, ['aaa', 'bbb', 'ccc']) 9663< This is equivalent to: >vim 9664 for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']] 9665 call setline(n, l) 9666 endfor 9667 9668< Note: The '[ and '] marks are not set. 9669 9670 Parameters: ~ 9671 • {lnum} (`integer|string`) 9672 • {text} (`any`) 9673 9674 Return: ~ 9675 (`any`) 9676 9677setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()* 9678 Create or replace or add to the location list for window {nr} 9679 (|window-number| or |window-ID|). 9680 When {nr} is zero the current window is used. 9681 9682 For a location list window, the displayed location list is 9683 modified. For an invalid {nr}, -1 is returned. 9684 Otherwise, same as |setqflist()|. 9685 Also see |location-list|. 9686 9687 For {action} see |setqflist-action|. 9688 9689 If the optional {what} dictionary argument is supplied, then 9690 only the items listed in {what} are set. Refer to |setqflist()| 9691 for the list of supported keys in {what}. 9692 9693 Parameters: ~ 9694 • {nr} (`integer`) 9695 • {list} (`vim.quickfix.entry[]`) 9696 • {action} (`string?`) 9697 • {what} (`vim.fn.setqflist.what?`) 9698 9699 Return: ~ 9700 (`any`) 9701 9702setmatches({list} [, {win}]) *setmatches()* 9703 Restores a list of matches saved by |getmatches()| for the 9704 current window. Returns 0 if successful, otherwise -1. All 9705 current matches are cleared before the list is restored. See 9706 example for |getmatches()|. 9707 {win} (if given) is a |window-number| or |window-ID|. 9708 9709 Parameters: ~ 9710 • {list} (`vim.fn.getmatches.ret.item[]`) 9711 • {win} (`integer?`) 9712 9713 Return: ~ 9714 (`any`) 9715 9716setpos({expr}, {list}) *setpos()* 9717 Lua: Prefer |nvim_win_set_cursor()| for "." or 9718 |nvim_buf_set_mark()| for marks; special positions, `off`, and 9719 `curswant` differ. 9720 9721 Set the position for String {expr}. Possible values: 9722 . the cursor 9723 'x mark x 9724 9725 {list} must be a |List| with four or five numbers: 9726 [bufnum, lnum, col, off] 9727 [bufnum, lnum, col, off, curswant] 9728 9729 "bufnum" is the buffer number. Zero can be used for the 9730 current buffer. When setting an uppercase mark "bufnum" is 9731 used for the mark position. For other marks it specifies the 9732 buffer to set the mark in. You can use the |bufnr()| function 9733 to turn a file name into a buffer number. 9734 For setting the cursor and the ' mark "bufnum" is ignored, 9735 since these are associated with a window, not a buffer. 9736 Does not change the jumplist. 9737 9738 "lnum" and "col" are the position in the buffer. The first 9739 column is 1. Use a zero "lnum" to delete a mark. If "col" is 9740 smaller than 1 then 1 is used. To use the character count 9741 instead of the byte count, use |setcharpos()|. 9742 9743 The "off" number is only used when 'virtualedit' is set. Then 9744 it is the offset in screen columns from the start of the 9745 character. E.g., a position within a <Tab> or after the last 9746 character. 9747 9748 The "curswant" number is only used when setting the cursor 9749 position. It sets the preferred column for when moving the 9750 cursor vertically. When the "curswant" number is missing the 9751 preferred column is not set. When it is present and setting a 9752 mark position it is not used. 9753 9754 Note that for |'<| and |'>| changing the line number may 9755 result in the marks to be effectively swapped, so that |'<| is 9756 always before |'>|. 9757 9758 The visual marks |'<| and |'>| refer to the beginning and end 9759 of the visual selection relative to the cursor position. 9760 Note that this differs from |getpos()|, where they are 9761 relative to the buffer. 9762 9763 Returns 0 when the position could be set, -1 otherwise. 9764 An error message is given if {expr} is invalid. 9765 9766 Also see |setcharpos()|, |getpos()| and |getcurpos()|. 9767 9768 This does not restore the preferred column for moving 9769 vertically; if you set the cursor position with this, |j| and 9770 |k| motions will jump to previous columns! Use |cursor()| to 9771 also set the preferred column. Also see the "curswant" key in 9772 |winrestview()|. 9773 9774 Parameters: ~ 9775 • {expr} (`string`) 9776 • {list} (`integer[]`) 9777 9778 Return: ~ 9779 (`any`) 9780 9781setqflist({list} [, {action} [, {what}]]) *setqflist()* 9782 Create or replace or add to the quickfix list. 9783 9784 If the optional {what} dictionary argument is supplied, then 9785 only the items listed in {what} are set. The first {list} 9786 argument is ignored. See below for the supported items in 9787 {what}. 9788 *setqflist-what* 9789 When {what} is not present, the items in {list} are used. 9790 Each item must be a dictionary. Non-dictionary items in 9791 {list} are ignored. Each dictionary item can contain the 9792 following entries: 9793 9794 bufnr buffer number; must be the number of a valid 9795 buffer 9796 filename name of a file; only used when "bufnr" is not 9797 present or it is invalid. 9798 module name of a module; if given it will be used in 9799 quickfix error window instead of the filename. 9800 lnum line number in the file 9801 end_lnum end of lines, if the item spans multiple lines 9802 pattern search pattern used to locate the error 9803 col column number 9804 vcol when non-zero: "col" is visual column 9805 when zero: "col" is byte index 9806 end_col end column, if the item spans multiple columns 9807 nr error number 9808 text description of the error 9809 type single-character error type, 'E', 'W', etc. 9810 valid recognized error message 9811 user_data 9812 custom data associated with the item, can be 9813 any type. 9814 9815 The "col", "vcol", "nr", "type" and "text" entries are 9816 optional. Either "lnum" or "pattern" entry can be used to 9817 locate a matching error line. 9818 If the "filename" and "bufnr" entries are not present or 9819 neither the "lnum" or "pattern" entries are present, then the 9820 item will not be handled as an error line. 9821 If both "pattern" and "lnum" are present then "pattern" will 9822 be used. 9823 If the "valid" entry is not supplied, then the valid flag is 9824 set when "bufnr" is a valid buffer or "filename" exists. 9825 If you supply an empty {list}, the quickfix list will be 9826 cleared. 9827 Note that the list is not exactly the same as what 9828 |getqflist()| returns. 9829 9830 {action} values: *setqflist-action* *E927* 9831 'a' The items from {list} are added to the existing 9832 quickfix list. If there is no existing list, then a 9833 new list is created. 9834 9835 'r' The items from the current quickfix list are replaced 9836 with the items from {list}. This can also be used to 9837 clear the list: >vim 9838 call setqflist([], 'r') 9839< 9840 'u' Like 'r', but tries to preserve the current selection 9841 in the quickfix list. The entry nearest to the 9842 previously selected one becomes the current entry. 9843 Proximity is determined by comparing the file, then 9844 the line number and then the column number. 9845 'f' All the quickfix lists in the quickfix stack are 9846 freed. 9847 9848 If {action} is not present or is set to ' ', then a new list 9849 is created. The new quickfix list is added after the current 9850 quickfix list in the stack and all the following lists are 9851 freed. To add a new quickfix list at the end of the stack, 9852 set "nr" in {what} to "$". 9853 9854 The following items can be specified in dictionary {what}: 9855 context quickfix list context. See |quickfix-context| 9856 efm errorformat to use when parsing text from 9857 "lines". If this is not present, then the 9858 'errorformat' option value is used. 9859 See |quickfix-parse| 9860 id quickfix list identifier |quickfix-ID| 9861 idx index of the current entry in the quickfix 9862 list specified by "id" or "nr". If set to 9863 '$', then the last entry in the list is set as 9864 the current entry. See |quickfix-index| 9865 items list of quickfix entries. Same as the {list} 9866 argument. 9867 lines use 'errorformat' to parse a list of lines and 9868 add the resulting entries to the quickfix list 9869 {nr} or {id}. Only a |List| value is supported. 9870 See |quickfix-parse| 9871 nr list number in the quickfix stack; zero 9872 means the current quickfix list and "$" means 9873 the last quickfix list. 9874 quickfixtextfunc 9875 function to get the text to display in the 9876 quickfix window. The value can be the name of 9877 a function or a funcref or a lambda. Refer to 9878 |quickfix-window-function| for an explanation 9879 of how to write the function and an example. 9880 title quickfix list title text. See |quickfix-title| 9881 Unsupported keys in {what} are ignored. 9882 If the "nr" item is not present, then the current quickfix 9883 list is modified. When creating a new quickfix list, "nr" can 9884 be set to a value one greater than the quickfix stack size. 9885 When modifying a quickfix list, to guarantee that the correct 9886 list is modified, "id" should be used instead of "nr" to 9887 specify the list. 9888 9889 Examples (See also |setqflist-examples|): >vim 9890 call setqflist([], 'r', {'title': 'My search'}) 9891 call setqflist([], 'r', {'nr': 2, 'title': 'Errors'}) 9892 call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]}) 9893< 9894 Returns zero for success, -1 for failure. 9895 9896 This function can be used to create a quickfix list 9897 independent of the 'errorformat' setting. Use a command like 9898 `:cc 1` to jump to the first position. 9899 9900 Parameters: ~ 9901 • {list} (`vim.quickfix.entry[]`) 9902 • {action} (`string?`) 9903 • {what} (`vim.fn.setqflist.what?`) 9904 9905 Return: ~ 9906 (`integer`) 9907 9908setreg({regname}, {value} [, {options}]) *setreg()* 9909 Set the register {regname} to {value}. 9910 If {regname} is "" or "@", the unnamed register '"' is used. 9911 The {regname} argument is a string. 9912 9913 {value} may be any value returned by |getreg()| or 9914 |getreginfo()|, including a |List| or |Dict|. 9915 If {options} contains "a" or {regname} is upper case, 9916 then the value is appended. 9917 9918 {options} can also contain a register type specification: 9919 "c" or "v" |charwise| mode 9920 "l" or "V" |linewise| mode 9921 "b" or "<CTRL-V>" |blockwise-visual| mode 9922 If a number immediately follows "b" or "<CTRL-V>" then this is 9923 used as the width of the selection - if it is not specified 9924 then the width of the block is set to the number of characters 9925 in the longest line (counting a <Tab> as 1 character). 9926 If {options} contains "u" or '"', then the unnamed register is 9927 set to point to register {regname}. 9928 9929 If {options} contains no register settings, then the default 9930 is to use character mode unless {value} ends in a <NL> for 9931 string {value} and linewise mode for list {value}. Blockwise 9932 mode is never selected automatically. 9933 Returns zero for success, non-zero for failure. 9934 9935 *E883* 9936 Note: you may not use |List| containing more than one item to 9937 set search and expression registers. Lists containing 9938 no items act like empty strings. 9939 9940 Examples: >vim 9941 call setreg(v:register, @*) 9942 call setreg('*', @%, 'ac') 9943 call setreg('a', "1\n2\n3", 'b5') 9944 call setreg('"', { 'points_to': 'a'}) 9945 9946< This example shows using the functions to save and restore a 9947 register: >vim 9948 let var_a = getreginfo() 9949 call setreg('a', var_a) 9950< or: >vim 9951 let var_a = getreg('a', 1, 1) 9952 let var_amode = getregtype('a') 9953 " .... 9954 call setreg('a', var_a, var_amode) 9955< Note: you may not reliably restore register value 9956 without using the third argument to |getreg()| as without it 9957 newlines are represented as newlines AND Nul bytes are 9958 represented as newlines as well, see |NL-used-for-Nul|. 9959 9960 You can also change the type of a register by appending 9961 nothing: >vim 9962 call setreg('a', '', 'al') 9963< 9964 9965 Parameters: ~ 9966 • {regname} (`string`) 9967 • {value} (`any`) 9968 • {options} (`string?`) 9969 9970 Return: ~ 9971 (`any`) 9972 9973settabvar({tabnr}, {varname}, {val}) *settabvar()* 9974 Lua: Prefer |nvim_tabpage_set_var()| or |vim.t|. 9975 9976 Set tab-local variable {varname} to {val} in tabpage {tabnr}. 9977 |t:var| 9978 The {varname} argument is a string. 9979 Note that the variable name without "t:" must be used. 9980 Tabs are numbered starting with one. 9981 This function is not available in the |sandbox|. 9982 9983 Parameters: ~ 9984 • {tabnr} (`integer`) 9985 • {varname} (`string`) 9986 • {val} (`any`) 9987 9988 Return: ~ 9989 (`any`) 9990 9991settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* 9992 Lua: Prefer |nvim_win_set_var()| or |vim.w| after resolving 9993 {tabnr} and {winnr} to a winid; option names use 9994 |nvim_set_option_value()|. 9995 9996 Set option or local variable {varname} in window {winnr} to 9997 {val}. 9998 Tabs are numbered starting with one. For the current tabpage 9999 use |setwinvar()|. 10000 {winnr} is a |window-number| or |window-ID|. 10001 When {winnr} is zero the current window is used. 10002 This also works for a global or local buffer option, but it 10003 doesn't work for a global or local buffer variable. 10004 For a local buffer option the global value is unchanged. 10005 Note that the variable name without "w:" must be used. 10006 Examples: >vim 10007 call settabwinvar(1, 1, "&list", 0) 10008 call settabwinvar(3, 2, "myvar", "foobar") 10009< This function is not available in the |sandbox|. 10010 10011 Parameters: ~ 10012 • {tabnr} (`integer`) 10013 • {winnr} (`integer`) 10014 • {varname} (`string`) 10015 • {val} (`any`) 10016 10017 Return: ~ 10018 (`any`) 10019 10020settagstack({nr}, {dict} [, {action}]) *settagstack()* 10021 Modify the tag stack of the window {nr} (|window-number| or 10022 |window-ID|) using {dict}. 10023 10024 For a list of supported items in {dict}, refer to 10025 |gettagstack()|. "curidx" takes effect before changing the tag 10026 stack. 10027 *E962* 10028 How the tag stack is modified depends on the {action} 10029 argument: 10030 - If {action} is not present or is set to 'r', then the tag 10031 stack is replaced. 10032 - If {action} is set to 'a', then new entries from {dict} are 10033 pushed (added) onto the tag stack. 10034 - If {action} is set to 't', then all the entries from the 10035 current entry in the tag stack or "curidx" in {dict} are 10036 removed and then new entries are pushed to the stack. 10037 10038 The current index is set to one after the length of the tag 10039 stack after the modification. 10040 10041 Returns zero for success, -1 for failure. 10042 10043 Examples (for more examples see |tagstack-examples|): 10044 Empty the tag stack of window 3: >vim 10045 call settagstack(3, {'items' : []}) 10046 10047< Save and restore the tag stack: >vim 10048 let stack = gettagstack(1003) 10049 " do something else 10050 call settagstack(1003, stack) 10051 unlet stack 10052< 10053 10054 Parameters: ~ 10055 • {nr} (`integer`) 10056 • {dict} (`any`) 10057 • {action} (`string?`) 10058 10059 Return: ~ 10060 (`any`) 10061 10062setwinvar({nr}, {varname}, {val}) *setwinvar()* 10063 Lua: Prefer |nvim_win_set_var()| or |vim.w| after resolving 10064 {nr} to a winid; option names use |nvim_set_option_value()|. 10065 10066 Like |settabwinvar()| for the current tabpage. 10067 Examples: >vim 10068 call setwinvar(1, "&list", 0) 10069 call setwinvar(2, "myvar", "foobar") 10070< 10071 10072 Parameters: ~ 10073 • {nr} (`integer`) 10074 • {varname} (`string`) 10075 • {val} (`any`) 10076 10077 Return: ~ 10078 (`any`) 10079 10080sha256({expr}) *sha256()* 10081 Returns a String with 64 hex characters, which is the SHA256 10082 checksum of {expr}. 10083 {expr} is a String or a Blob. 10084 10085 Parameters: ~ 10086 • {expr} (`string`) 10087 10088 Return: ~ 10089 (`string`) 10090 10091shellescape({string} [, {special}]) *shellescape()* 10092 Lua: Prefer |vim.system()| with list args to avoid shell 10093 escaping; `:!` and {special} semantics differ. 10094 10095 Escape {string} for use as a shell command argument. 10096 10097 On Windows when 'shellslash' is not set, encloses {string} in 10098 double-quotes and doubles all double-quotes within {string}. 10099 Otherwise encloses {string} in single-quotes and replaces all 10100 "'" with "'\''". 10101 10102 The {special} argument adds additional escaping of keywords 10103 used in Vim commands. If it is a |non-zero-arg|: 10104 - Special items such as "!", "%", "#" and "<cword>" (as listed 10105 in |expand()|) will be preceded by a backslash. 10106 The backslash will be removed again by the |:!| command. 10107 - The <NL> character is escaped. 10108 10109 If 'shell' contains "csh" in the tail: 10110 - The "!" character will be escaped. This is because csh and 10111 tcsh use "!" for history replacement even in single-quotes. 10112 - The <NL> character is escaped (twice if {special} is 10113 a |non-zero-arg|). 10114 10115 If 'shell' contains "fish" in the tail, the "\" character will 10116 be escaped because in fish it is used as an escape character 10117 inside single quotes. 10118 10119 Example of use with a |:!| command: >vim 10120 exe '!dir ' .. shellescape(expand('<cfile>'), 1) 10121< This results in a directory listing for the file under the 10122 cursor. Example of use with |system()|: >vim 10123 call system("chmod +w -- " .. shellescape(expand("%"))) 10124< See also |::S|. 10125 10126 Parameters: ~ 10127 • {string} (`string`) 10128 • {special} (`boolean?`) 10129 10130 Return: ~ 10131 (`string`) 10132 10133shiftwidth([{col}]) *shiftwidth()* 10134 Lua: Prefer |vim.bo| for simple cases: 10135 `vim.bo.shiftwidth > 0 and vim.bo.shiftwidth or vim.bo.tabstop`; 10136 `{col}` and 'vartabstop' semantics differ. 10137 10138 Returns the effective value of 'shiftwidth'. This is the 10139 'shiftwidth' value unless it is zero, in which case it is the 10140 'tabstop' value. To be backwards compatible in indent 10141 plugins, use this: >vim 10142 if exists('*shiftwidth') 10143 func s:sw() 10144 return shiftwidth() 10145 endfunc 10146 else 10147 func s:sw() 10148 return &sw 10149 endfunc 10150 endif 10151< And then use s:sw() instead of &sw. 10152 10153 for which to return the 'shiftwidth' value. This matters for 10154 the 'vartabstop' feature. If the 'vartabstop' setting is 10155 enabled and no {col} argument is given, column 1 will be 10156 assumed. 10157 10158 Parameters: ~ 10159 • {col} (`integer?`) 10160 10161 Return: ~ 10162 (`integer`) 10163 10164sign_define({name} [, {dict}]) *sign_define()* 10165sign_define({list}) 10166 Define a new sign named {name} or modify the attributes of an 10167 existing sign. This is similar to the |:sign-define| command. 10168 10169 Prefix {name} with a unique text to avoid name collisions. 10170 There is no {group} like with placing signs. 10171 10172 The {name} can be a String or a Number. The optional {dict} 10173 argument specifies the sign attributes. The following values 10174 are supported: 10175 icon full path to the bitmap file for the sign. 10176 linehl highlight group used for the whole line the 10177 sign is placed in. 10178 priority default priority value of the sign 10179 numhl highlight group used for the line number where 10180 the sign is placed. 10181 text text that is displayed when there is no icon 10182 or the GUI is not being used. 10183 texthl highlight group used for the text item 10184 culhl highlight group used for the text item when 10185 the cursor is on the same line as the sign and 10186 'cursorline' is enabled. 10187 10188 If the sign named {name} already exists, then the attributes 10189 of the sign are updated. 10190 10191 The one argument {list} can be used to define a list of signs. 10192 Each list item is a dictionary with the above items in {dict} 10193 and a "name" item for the sign name. 10194 10195 Returns 0 on success and -1 on failure. When the one argument 10196 {list} is used, then returns a List of values one for each 10197 defined sign. 10198 10199 Examples: >vim 10200 call sign_define("mySign", { 10201 \ "text" : "=>", 10202 \ "texthl" : "Error", 10203 \ "linehl" : "Search"}) 10204 call sign_define([ 10205 \ {'name' : 'sign1', 10206 \ 'text' : '=>'}, 10207 \ {'name' : 'sign2', 10208 \ 'text' : '!!'} 10209 \ ]) 10210< 10211 10212 Parameters: ~ 10213 • {list} (`vim.fn.sign_define.dict[]`) 10214 10215 Return: ~ 10216 (`(0|-1)[]`) 10217 10218sign_getdefined([{name}]) *sign_getdefined()* 10219 Get a list of defined signs and their attributes. 10220 This is similar to the |:sign-list| command. 10221 10222 If the {name} is not supplied, then a list of all the defined 10223 signs is returned. Otherwise the attribute of the specified 10224 sign is returned. 10225 10226 Each list item in the returned value is a dictionary with the 10227 following entries: 10228 icon full path to the bitmap file of the sign 10229 linehl highlight group used for the whole line the 10230 sign is placed in; not present if not set. 10231 name name of the sign 10232 priority default priority value of the sign 10233 numhl highlight group used for the line number where 10234 the sign is placed; not present if not set. 10235 text text that is displayed when there is no icon 10236 or the GUI is not being used. 10237 texthl highlight group used for the text item; not 10238 present if not set. 10239 culhl highlight group used for the text item when 10240 the cursor is on the same line as the sign and 10241 'cursorline' is enabled; not present if not 10242 set. 10243 10244 Returns an empty List if there are no signs and when {name} is 10245 not found. 10246 10247 Examples: >vim 10248 " Get a list of all the defined signs 10249 echo sign_getdefined() 10250 10251 " Get the attribute of the sign named mySign 10252 echo sign_getdefined("mySign") 10253< 10254 10255 Parameters: ~ 10256 • {name} (`string?`) 10257 10258 Return: ~ 10259 (`vim.fn.sign_getdefined.ret.item[]`) 10260 10261sign_getplaced([{buf} [, {dict}]]) *sign_getplaced()* 10262 Return a list of signs placed in a buffer or all the buffers. 10263 This is similar to the |:sign-place-list| command. 10264 10265 If the optional buffer name {buf} is specified, then only the 10266 list of signs placed in that buffer is returned. For the use 10267 of {buf}, see |bufname()|. The optional {dict} can contain 10268 the following entries: 10269 group select only signs in this group 10270 id select sign with this identifier 10271 lnum select signs placed in this line. For the use 10272 of {lnum}, see |line()|. 10273 If {group} is "*", then signs in all the groups including the 10274 global group are returned. If {group} is not supplied or is 10275 an empty string, then only signs in the global group are 10276 returned. If no arguments are supplied, then signs in the 10277 global group placed in all the buffers are returned. 10278 See |sign-group|. 10279 10280 Each list item in the returned value is a dictionary with the 10281 following entries: 10282 bufnr number of the buffer with the sign 10283 signs list of signs placed in {bufnr}. Each list 10284 item is a dictionary with the below listed 10285 entries 10286 10287 The dictionary for each sign contains the following entries: 10288 group sign group. Set to '' for the global group. 10289 id identifier of the sign 10290 lnum line number where the sign is placed 10291 name name of the defined sign 10292 priority sign priority 10293 10294 The returned signs in a buffer are ordered by their line 10295 number and priority. 10296 10297 Returns an empty list on failure or if there are no placed 10298 signs. 10299 10300 Examples: >vim 10301 " Get a List of signs placed in eval.c in the 10302 " global group 10303 echo sign_getplaced("eval.c") 10304 10305 " Get a List of signs in group 'g1' placed in eval.c 10306 echo sign_getplaced("eval.c", {'group' : 'g1'}) 10307 10308 " Get a List of signs placed at line 10 in eval.c 10309 echo sign_getplaced("eval.c", {'lnum' : 10}) 10310 10311 " Get sign with identifier 10 placed in a.py 10312 echo sign_getplaced("a.py", {'id' : 10}) 10313 10314 " Get sign with id 20 in group 'g1' placed in a.py 10315 echo sign_getplaced("a.py", {'group' : 'g1', 10316 \ 'id' : 20}) 10317 10318 " Get a List of all the placed signs 10319 echo sign_getplaced() 10320< 10321 10322 Parameters: ~ 10323 • {buf} (`integer|string?`) 10324 • {dict} (`vim.fn.sign_getplaced.dict?`) 10325 10326 Return: ~ 10327 (`vim.fn.sign_getplaced.ret.item[]`) 10328 10329sign_jump({id}, {group}, {buf}) *sign_jump()* 10330 Open the buffer {buf} or jump to the window that contains 10331 {buf} and position the cursor at sign {id} in group {group}. 10332 This is similar to the |:sign-jump| command. 10333 10334 If {group} is an empty string, then the global group is used. 10335 For the use of {buf}, see |bufname()|. 10336 10337 Returns the line number of the sign. Returns -1 if the 10338 arguments are invalid. 10339 10340 Example: >vim 10341 " Jump to sign 10 in the current buffer 10342 call sign_jump(10, '', '') 10343< 10344 10345 Parameters: ~ 10346 • {id} (`integer`) 10347 • {group} (`string`) 10348 • {buf} (`integer|string`) 10349 10350 Return: ~ 10351 (`integer`) 10352 10353sign_place({id}, {group}, {name}, {buf} [, {dict}]) *sign_place()* 10354 Place the sign defined as {name} at line {lnum} in file or 10355 buffer {buf} and assign {id} and {group} to sign. This is 10356 similar to the |:sign-place| command. 10357 10358 If the sign identifier {id} is zero, then a new identifier is 10359 allocated. Otherwise the specified number is used. {group} 10360 is the sign group name. To use the global sign group, use an 10361 empty string. {group} functions as a namespace for {id}, thus 10362 two groups can use the same IDs. Refer to |sign-identifier| 10363 and |sign-group| for more information. 10364 10365 {name} refers to a defined sign. 10366 {buf} refers to a buffer name or number. For the accepted 10367 values, see |bufname()|. 10368 10369 The optional {dict} argument supports the following entries: 10370 lnum line number in the file or buffer 10371 {buf} where the sign is to be placed. 10372 For the accepted values, see |line()|. 10373 priority priority of the sign. See 10374 |sign-priority| for more information. 10375 10376 If the optional {dict} is not specified, then it modifies the 10377 placed sign {id} in group {group} to use the defined sign 10378 {name}. 10379 10380 Returns the sign identifier on success and -1 on failure. 10381 10382 Examples: >vim 10383 " Place a sign named sign1 with id 5 at line 20 in 10384 " buffer json.c 10385 call sign_place(5, '', 'sign1', 'json.c', 10386 \ {'lnum' : 20}) 10387 10388 " Updates sign 5 in buffer json.c to use sign2 10389 call sign_place(5, '', 'sign2', 'json.c') 10390 10391 " Place a sign named sign3 at line 30 in 10392 " buffer json.c with a new identifier 10393 let id = sign_place(0, '', 'sign3', 'json.c', 10394 \ {'lnum' : 30}) 10395 10396 " Place a sign named sign4 with id 10 in group 'g3' 10397 " at line 40 in buffer json.c with priority 90 10398 call sign_place(10, 'g3', 'sign4', 'json.c', 10399 \ {'lnum' : 40, 'priority' : 90}) 10400< 10401 10402 Parameters: ~ 10403 • {id} (`integer`) 10404 • {group} (`string`) 10405 • {name} (`string`) 10406 • {buf} (`integer|string`) 10407 • {dict} (`vim.fn.sign_place.dict?`) 10408 10409 Return: ~ 10410 (`integer`) 10411 10412sign_placelist({list}) *sign_placelist()* 10413 Place one or more signs. This is similar to the 10414 |sign_place()| function. The {list} argument specifies the 10415 List of signs to place. Each list item is a dict with the 10416 following sign attributes: 10417 buffer Buffer name or number. For the accepted 10418 values, see |bufname()|. 10419 group Sign group. {group} functions as a namespace 10420 for {id}, thus two groups can use the same 10421 IDs. If not specified or set to an empty 10422 string, then the global group is used. See 10423 |sign-group| for more information. 10424 id Sign identifier. If not specified or zero, 10425 then a new unique identifier is allocated. 10426 Otherwise the specified number is used. See 10427 |sign-identifier| for more information. 10428 lnum Line number in the buffer where the sign is to 10429 be placed. For the accepted values, see 10430 |line()|. 10431 name Name of the sign to place. See |sign_define()| 10432 for more information. 10433 priority Priority of the sign. When multiple signs are 10434 placed on a line, the sign with the highest 10435 priority is used. If not specified, the 10436 default value of 10 is used, unless specified 10437 otherwise by the sign definition. See 10438 |sign-priority| for more information. 10439 10440 If {id} refers to an existing sign, then the existing sign is 10441 modified to use the specified {name} and/or {priority}. 10442 10443 Returns a List of sign identifiers. If failed to place a 10444 sign, the corresponding list item is set to -1. 10445 10446 Examples: >vim 10447 " Place sign s1 with id 5 at line 20 and id 10 at line 10448 " 30 in buffer a.c 10449 let [n1, n2] = sign_placelist([ 10450 \ {'id' : 5, 10451 \ 'name' : 's1', 10452 \ 'buffer' : 'a.c', 10453 \ 'lnum' : 20}, 10454 \ {'id' : 10, 10455 \ 'name' : 's1', 10456 \ 'buffer' : 'a.c', 10457 \ 'lnum' : 30} 10458 \ ]) 10459 10460 " Place sign s1 in buffer a.c at line 40 and 50 10461 " with auto-generated identifiers 10462 let [n1, n2] = sign_placelist([ 10463 \ {'name' : 's1', 10464 \ 'buffer' : 'a.c', 10465 \ 'lnum' : 40}, 10466 \ {'name' : 's1', 10467 \ 'buffer' : 'a.c', 10468 \ 'lnum' : 50} 10469 \ ]) 10470< 10471 10472 Parameters: ~ 10473 • {list} (`vim.fn.sign_placelist.list.item[]`) 10474 10475 Return: ~ 10476 (`integer[]`) 10477 10478sign_undefine([{name}]) *sign_undefine()* 10479sign_undefine({list}) 10480 Deletes a previously defined sign {name}. This is similar to 10481 the |:sign-undefine| command. If {name} is not supplied, then 10482 deletes all the defined signs. 10483 10484 The one argument {list} can be used to undefine a list of 10485 signs. Each list item is the name of a sign. 10486 10487 Returns 0 on success and -1 on failure. For the one argument 10488 {list} call, returns a list of values one for each undefined 10489 sign. 10490 10491 Examples: >vim 10492 " Delete a sign named mySign 10493 call sign_undefine("mySign") 10494 10495 " Delete signs 'sign1' and 'sign2' 10496 call sign_undefine(["sign1", "sign2"]) 10497 10498 " Delete all the signs 10499 call sign_undefine() 10500< 10501 10502 Parameters: ~ 10503 • {list} (`string[]?`) 10504 10505 Return: ~ 10506 (`integer[]`) 10507 10508sign_unplace({group} [, {dict}]) *sign_unplace()* 10509 Remove a previously placed sign in one or more buffers. This 10510 is similar to the |:sign-unplace| command. 10511 10512 {group} is the sign group name. To use the global sign group, 10513 use an empty string. If {group} is set to "*", then all the 10514 groups including the global group are used. 10515 The signs in {group} are selected based on the entries in 10516 {dict}. The following optional entries in {dict} are 10517 supported: 10518 buffer buffer name or number. See |bufname()|. 10519 id sign identifier 10520 If {dict} is not supplied, then all the signs in {group} are 10521 removed. 10522 10523 Returns 0 on success and -1 on failure. 10524 10525 Examples: >vim 10526 " Remove sign 10 from buffer a.vim 10527 call sign_unplace('', {'buffer' : "a.vim", 'id' : 10}) 10528 10529 " Remove sign 20 in group 'g1' from buffer 3 10530 call sign_unplace('g1', {'buffer' : 3, 'id' : 20}) 10531 10532 " Remove all the signs in group 'g2' from buffer 10 10533 call sign_unplace('g2', {'buffer' : 10}) 10534 10535 " Remove sign 30 in group 'g3' from all the buffers 10536 call sign_unplace('g3', {'id' : 30}) 10537 10538 " Remove all the signs placed in buffer 5 10539 call sign_unplace('*', {'buffer' : 5}) 10540 10541 " Remove the signs in group 'g4' from all the buffers 10542 call sign_unplace('g4') 10543 10544 " Remove sign 40 from all the buffers 10545 call sign_unplace('*', {'id' : 40}) 10546 10547 " Remove all the placed signs from all the buffers 10548 call sign_unplace('*') 10549< 10550 10551 Parameters: ~ 10552 • {group} (`string`) 10553 • {dict} (`vim.fn.sign_unplace.dict?`) 10554 10555 Return: ~ 10556 (`0|-1`) 10557 10558sign_unplacelist({list}) *sign_unplacelist()* 10559 Remove previously placed signs from one or more buffers. This 10560 is similar to the |sign_unplace()| function. 10561 10562 The {list} argument specifies the List of signs to remove. 10563 Each list item is a dict with the following sign attributes: 10564 buffer buffer name or number. For the accepted 10565 values, see |bufname()|. If not specified, 10566 then the specified sign is removed from all 10567 the buffers. 10568 group sign group name. If not specified or set to an 10569 empty string, then the global sign group is 10570 used. If set to "*", then all the groups 10571 including the global group are used. 10572 id sign identifier. If not specified, then all 10573 the signs in the specified group are removed. 10574 10575 Returns a List where an entry is set to 0 if the corresponding 10576 sign was successfully removed or -1 on failure. 10577 10578 Example: >vim 10579 " Remove sign with id 10 from buffer a.vim and sign 10580 " with id 20 from buffer b.vim 10581 call sign_unplacelist([ 10582 \ {'id' : 10, 'buffer' : "a.vim"}, 10583 \ {'id' : 20, 'buffer' : 'b.vim'}, 10584 \ ]) 10585< 10586 10587 Parameters: ~ 10588 • {list} (`vim.fn.sign_unplacelist.list.item`) 10589 10590 Return: ~ 10591 (`(0|-1)[]`) 10592 10593simplify({filename}) *simplify()* 10594 Lua: Prefer |vim.fs.normalize()|; `~`/$VAR expansion and 10595 leading `./` or trailing `/` handling differ. 10596 10597 Simplify the file name as much as possible without changing 10598 the meaning. Shortcuts (on MS-Windows) or symbolic links (on 10599 Unix) are not resolved. If the first path component in 10600 {filename} designates the current directory, this will be 10601 valid for the result as well. A trailing path separator is 10602 not removed either. On Unix "//path" is unchanged, but 10603 "///path" is simplified to "/path" (this follows the Posix 10604 standard). 10605 Example: >vim 10606 simplify("./dir/.././/file/") == "./file/" 10607< Note: The combination "dir/.." is only removed if "dir" is 10608 a searchable directory or does not exist. On Unix, it is also 10609 removed when "dir" is a symbolic link within the same 10610 directory. In order to resolve all the involved symbolic 10611 links before simplifying the path name, use |resolve()|. 10612 10613 Parameters: ~ 10614 • {filename} (`string`) 10615 10616 Return: ~ 10617 (`string`) 10618 10619sin({expr}) *sin()* 10620 Lua: Prefer |math.sin()|. 10621 10622 Return the sine of {expr}, measured in radians, as a |Float|. 10623 {expr} must evaluate to a |Float| or a |Number|. 10624 Returns 0.0 if {expr} is not a |Float| or a |Number|. 10625 Examples: >vim 10626 echo sin(100) 10627< -0.506366 >vim 10628 echo sin(-4.01) 10629< 0.763301 10630 10631 Parameters: ~ 10632 • {expr} (`number`) 10633 10634 Return: ~ 10635 (`number`) 10636 10637sinh({expr}) *sinh()* 10638 Lua: Prefer |math.sinh()|. 10639 10640 Return the hyperbolic sine of {expr} as a |Float| in the range 10641 [-inf, inf]. 10642 {expr} must evaluate to a |Float| or a |Number|. 10643 Returns 0.0 if {expr} is not a |Float| or a |Number|. 10644 Examples: >vim 10645 echo sinh(0.5) 10646< 0.521095 >vim 10647 echo sinh(-0.9) 10648< -1.026517 10649 10650 Parameters: ~ 10651 • {expr} (`number`) 10652 10653 Return: ~ 10654 (`any`) 10655 10656slice({expr}, {start} [, {end}]) *slice()* 10657 Similar to using a |slice| "expr[start : end]", but "end" is 10658 used exclusive. And for a string the indexes are used as 10659 character indexes instead of byte indexes. 10660 Also, composing characters are treated as a part of the 10661 preceding base character. 10662 When {end} is omitted the slice continues to the last item. 10663 When {end} is -1 the last item is omitted. 10664 Returns an empty value if {start} or {end} are invalid. 10665 10666 Parameters: ~ 10667 • {expr} (`any`) 10668 • {start} (`integer`) 10669 • {end} (`integer?`) 10670 10671 Return: ~ 10672 (`any`) 10673 10674sockconnect({mode}, {address} [, {opts}]) *sockconnect()* 10675 Connect a socket to an address. If {mode} is "pipe" then 10676 {address} should be the path of a local domain socket (on 10677 unix) or named pipe (on Windows). If {mode} is "tcp" then 10678 {address} should be of the form "host:port" where the host 10679 should be an ip address or host name, and port the port 10680 number. 10681 10682 For "pipe" mode, see |luv-pipe-handle|. For "tcp" mode, see 10683 |luv-tcp-handle|. 10684 10685 Returns a |channel| ID. Close the socket with |chanclose()|. 10686 Use |chansend()| to send data over a bytes socket, and 10687 |rpcrequest()| and |rpcnotify()| to communicate with a RPC 10688 socket. 10689 10690 {opts} is an optional dictionary with these keys: 10691 |on_data| : callback invoked when data was read from socket 10692 data_buffered : read socket data in |channel-buffered| mode. 10693 rpc : If set, |msgpack-rpc| will be used to communicate 10694 over the socket. 10695 Returns: 10696 - The channel ID on success (greater than zero) 10697 - 0 on invalid arguments or connection failure. 10698 10699 Parameters: ~ 10700 • {mode} (`string`) 10701 • {address} (`string`) 10702 • {opts} (`table?`) 10703 10704 Return: ~ 10705 (`any`) 10706 10707sort({list} [, {how} [, {dict}]]) *sort()* *E702* 10708 Lua: Prefer |table.sort()| with a custom comparator; it is not 10709 stable and Vim's `i`/`l`/`n`/`N`/`f` modes differ. 10710 10711 Sort the items in {list} in-place. Returns {list}. 10712 10713 If you want a list to remain unmodified make a copy first: >vim 10714 let sortedlist = sort(copy(mylist)) 10715 10716< When {how} is omitted or is a string, then sort() uses the 10717 string representation of each item to sort on. Numbers sort 10718 after Strings, |Lists| after Numbers. For sorting text in the 10719 current buffer use |:sort|. 10720 10721 When {how} is given and it is 'i' then case is ignored. 10722 For backwards compatibility, the value one can be used to 10723 ignore case. Zero means to not ignore case. 10724 10725 When {how} is given and it is 'l' then the current collation 10726 locale is used for ordering. Implementation details: 10727 strcoll() is used to compare strings. See |:language| to check 10728 or set the collation locale. |v:collate| can also be used to 10729 check the current locale. Sorting using the locale typically 10730 ignores case. Example: >vim 10731 " ö is sorted similarly to o with English locale. 10732 language collate en_US.UTF8 10733 echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 10734< ['n', 'o', 'O', 'ö', 'p', 'z'] ~ 10735>vim 10736 " ö is sorted after z with Swedish locale. 10737 language collate sv_SE.UTF8 10738 echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 10739< ['n', 'o', 'O', 'p', 'z', 'ö'] ~ 10740 This does not work properly on Mac. 10741 10742 When {how} is given and it is 'n' then all items will be 10743 sorted numerical (Implementation detail: this uses the 10744 strtod() function to parse numbers, Strings, Lists, Dicts and 10745 Funcrefs will be considered as being 0). 10746 10747 When {how} is given and it is 'N' then all items will be 10748 sorted numerical. This is like 'n' but a string containing 10749 digits will be used as the number they represent. 10750 10751 When {how} is given and it is 'f' then all items will be 10752 sorted numerical. All values must be a Number or a Float. 10753 10754 When {how} is a |Funcref| or a function name, this function 10755 is called to compare items. The function is invoked with two 10756 items as argument and must return zero if they are equal, 1 or 10757 bigger if the first one sorts after the second one, -1 or 10758 smaller if the first one sorts before the second one. 10759 10760 {dict} is for functions with the "dict" attribute. It will be 10761 used to set the local variable "self". |Dictionary-function| 10762 10763 The sort is stable, items which compare equal (as number or as 10764 string) will keep their relative position. E.g., when sorting 10765 on numbers, text strings will sort next to each other, in the 10766 same order as they were originally. 10767 10768 10769 Example: >vim 10770 func MyCompare(i1, i2) 10771 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 10772 endfunc 10773 eval mylist->sort("MyCompare") 10774< A shorter compare version for this specific simple case, which 10775 ignores overflow: >vim 10776 func MyCompare(i1, i2) 10777 return a:i1 - a:i2 10778 endfunc 10779< For a simple expression you can use a lambda: >vim 10780 eval mylist->sort({i1, i2 -> i1 - i2}) 10781< 10782 10783 Parameters: ~ 10784 • {list} (`T[]`) 10785 • {how} (`string|function?`) 10786 • {dict} (`any?`) 10787 10788 Return: ~ 10789 (`T[]`) 10790 10791soundfold({word}) *soundfold()* 10792 Return the sound-folded equivalent of {word}. Uses the first 10793 language in 'spelllang' for the current window that supports 10794 soundfolding. 'spell' must be set. When no sound folding is 10795 possible the {word} is returned unmodified. 10796 This can be used for making spelling suggestions. Note that 10797 the method can be quite slow. 10798 10799 Parameters: ~ 10800 • {word} (`string`) 10801 10802 Return: ~ 10803 (`string`) 10804 10805spellbadword([{sentence}]) *spellbadword()* 10806 Lua: Prefer |vim.spell.check()| for string input; it returns 10807 all matches with positions, not just the first one or 10808 cursor-moving behavior. 10809 10810 Without argument: The result is the badly spelled word under 10811 or after the cursor. The cursor is moved to the start of the 10812 bad word. When no bad word is found in the cursor line the 10813 result is an empty string and the cursor doesn't move. 10814 10815 With argument: The result is the first word in {sentence} that 10816 is badly spelled. If there are no spelling mistakes the 10817 result is an empty string. 10818 10819 The return value is a list with two items: 10820 - The badly spelled word or an empty string. 10821 - The type of the spelling error: 10822 "bad" spelling mistake 10823 "rare" rare word 10824 "local" word only valid in another region 10825 "caps" word should start with Capital 10826 Example: >vim 10827 echo spellbadword("the quik brown fox") 10828< ['quik', 'bad'] ~ 10829 10830 The spelling information for the current window and the value 10831 of 'spelllang' are used. 10832 10833 Parameters: ~ 10834 • {sentence} (`string?`) 10835 10836 Return: ~ 10837 (`any`) 10838 10839spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()* 10840 Return a |List| with spelling suggestions to replace {word}. 10841 When {max} is given up to this number of suggestions are 10842 returned. Otherwise up to 25 suggestions are returned. 10843 10844 When the {capital} argument is given and it's non-zero only 10845 suggestions with a leading capital will be given. Use this 10846 after a match with 'spellcapcheck'. 10847 10848 {word} can be a badly spelled word followed by other text. 10849 This allows for joining two words that were split. The 10850 suggestions also include the following text, thus you can 10851 replace a line. 10852 10853 {word} may also be a good word. Similar words will then be 10854 returned. {word} itself is not included in the suggestions, 10855 although it may appear capitalized. 10856 10857 The spelling information for the current window is used. The 10858 values of 'spelllang' and 'spellsuggest' are used. 10859 10860 Parameters: ~ 10861 • {word} (`string`) 10862 • {max} (`integer?`) 10863 • {capital} (`boolean?`) 10864 10865 Return: ~ 10866 (`string[]`) 10867 10868split({string} [, {pattern} [, {keepempty}]]) *split()* 10869 Lua: Prefer |vim.split()|. 10870 10871 Make a |List| out of {string}. When {pattern} is omitted or 10872 empty each white space separated sequence of characters 10873 becomes an item. 10874 Otherwise the string is split where {pattern} matches, 10875 removing the matched characters. 'ignorecase' is not used 10876 here, add \c to ignore case. |/\c| 10877 When the first or last item is empty it is omitted, unless the 10878 {keepempty} argument is given and it's non-zero. 10879 Other empty items are kept when {pattern} matches at least one 10880 character or when {keepempty} is non-zero. 10881 Example: >vim 10882 let words = split(getline('.'), '\W\+') 10883< To split a string in individual characters: >vim 10884 for c in split(mystring, '\zs') | endfor 10885< If you want to keep the separator you can also use '\zs' at 10886 the end of the pattern: >vim 10887 echo split('abc:def:ghi', ':\zs') 10888< > 10889 ['abc:', 'def:', 'ghi'] 10890< 10891 Splitting a table where the first element can be empty: >vim 10892 let items = split(line, ':', 1) 10893< The opposite function is |join()|. 10894 10895 Parameters: ~ 10896 • {string} (`string`) 10897 • {pattern} (`string?`) 10898 • {keepempty} (`boolean?`) 10899 10900 Return: ~ 10901 (`string[]`) 10902 10903sqrt({expr}) *sqrt()* 10904 Lua: Prefer |math.sqrt()|. 10905 10906 Return the non-negative square root of Float {expr} as a 10907 |Float|. 10908 {expr} must evaluate to a |Float| or a |Number|. When {expr} 10909 is negative the result is NaN (Not a Number). Returns 0.0 if 10910 {expr} is not a |Float| or a |Number|. 10911 Examples: >vim 10912 echo sqrt(100) 10913< 10.0 >vim 10914 echo sqrt(-4.01) 10915< str2float("nan") 10916 NaN may be different, it depends on system libraries. 10917 10918 Parameters: ~ 10919 • {expr} (`number`) 10920 10921 Return: ~ 10922 (`any`) 10923 10924srand([{expr}]) *srand()* 10925 Lua: Prefer |math.randomseed()|. 10926 10927 Initialize seed used by |rand()|: 10928 - If {expr} is not given, seed values are initialized by 10929 reading from /dev/urandom, if possible, or using time(NULL) 10930 a.k.a. epoch time otherwise; this only has second accuracy. 10931 - If {expr} is given it must be a Number. It is used to 10932 initialize the seed values. This is useful for testing or 10933 when a predictable sequence is intended. 10934 10935 Examples: >vim 10936 let seed = srand() 10937 let seed = srand(userinput) 10938 echo rand(seed) 10939< 10940 10941 Parameters: ~ 10942 • {expr} (`number?`) 10943 10944 Return: ~ 10945 (`any`) 10946 10947state([{what}]) *state()* 10948 Return a string which contains characters indicating the 10949 current state. Mostly useful in callbacks that want to do 10950 work that may not always be safe. Roughly this works like: 10951 - callback uses state() to check if work is safe to do. 10952 Yes: then do it right away. 10953 No: add to work queue and add a |SafeState| autocommand. 10954 - When SafeState is triggered and executes your autocommand, 10955 check with `state()` if the work can be done now, and if yes 10956 remove it from the queue and execute. 10957 Remove the autocommand if the queue is now empty. 10958 Also see |mode()|. 10959 10960 When {what} is given only characters in this string will be 10961 added. E.g, this checks if the screen has scrolled: >vim 10962 if state('s') == '' 10963 " screen has not scrolled 10964< 10965 These characters indicate the state, generally indicating that 10966 something is busy: 10967 m halfway a mapping, :normal command, |feedkeys()| or 10968 stuffed command 10969 o operator pending, e.g. after |d| 10970 a Insert mode autocomplete active 10971 x executing an autocommand 10972 S not triggering SafeState, e.g. after |f| or a count 10973 c callback invoked, including timer (repeats for 10974 recursiveness up to "ccc") 10975 s screen has scrolled for messages 10976 10977 Attributes: ~ 10978 |api-fast| 10979 10980 Parameters: ~ 10981 • {what} (`string?`) 10982 10983 Return: ~ 10984 (`any`) 10985 10986stdioopen({opts}) *stdioopen()* 10987 With |--headless| this opens stdin and stdout as a |channel|. 10988 May be called only once. See |channel-stdio|. stderr is not 10989 handled by this function, see |v:stderr|. 10990 10991 Close the stdio handles with |chanclose()|. Use |chansend()| 10992 to send data to stdout, and |rpcrequest()| and |rpcnotify()| 10993 to communicate over RPC. 10994 10995 {opts} is a dictionary with these keys: 10996 |on_stdin| : callback invoked when stdin is written to. 10997 on_print : callback invoked when Nvim needs to print a 10998 message, with the message (whose type is string) 10999 as sole argument. 11000 stdin_buffered : read stdin in |channel-buffered| mode. 11001 rpc : If set, |msgpack-rpc| will be used to communicate 11002 over stdio 11003 Returns: 11004 - |channel-id| on success (value is always 1) 11005 - 0 on invalid arguments 11006 11007 Parameters: ~ 11008 • {opts} (`table`) 11009 11010 Return: ~ 11011 (`any`) 11012 11013stdpath({what}) *stdpath()* *E6100* 11014 Returns |standard-path| locations of various default files and 11015 directories. The locations are driven by |base-directories| 11016 which you can configure via |$NVIM_APPNAME| or the `$XDG_…` 11017 environment variables. 11018 11019 {what} Type Description ~ 11020 cache String Cache directory: arbitrary temporary 11021 storage for plugins, etc. 11022 config String User configuration directory. |init.vim| 11023 is stored here. 11024 config_dirs List Other configuration directories. 11025 data String User data directory. 11026 data_dirs List Other data directories. 11027 log String Logs directory (for use by plugins too). 11028 run String Run directory: temporary, local storage 11029 for sockets, named pipes, etc. 11030 state String Session state: storage for backupdir, 11031 file drafts, |shada|, swap, undo, 'viewdir'. 11032 11033 Example: >vim 11034 echo stdpath("config") 11035< 11036 11037 Attributes: ~ 11038 |api-fast| 11039 11040 Parameters: ~ 11041 • {what} 11042 (`'cache'|'config'|'config_dirs'|'data'|'data_dirs'|'log'|'run'|'state'`) 11043 11044 Return: ~ 11045 (`string|string[]`) 11046 11047str2float({string} [, {quoted}]) *str2float()* 11048 Lua: Prefer |tonumber()| for simple numbers; quoted digits, 11049 hex forms, and trailing text differ. 11050 11051 Convert String {string} to a Float. This mostly works the 11052 same as when using a floating point number in an expression, 11053 see |floating-point-format|. But it's a bit more permissive. 11054 E.g., "1e40" is accepted, while in an expression you need to 11055 write "1.0e40". The hexadecimal form "0x123" is also 11056 accepted, but not others, like binary or octal. 11057 When {quoted} is present and non-zero then embedded single 11058 quotes before the dot are ignored, thus "1'000.0" is a 11059 thousand. 11060 Text after the number is silently ignored. 11061 The decimal point is always '.', no matter what the locale is 11062 set to. A comma ends the number: "12,345.67" is converted to 11063 12.0. You can strip out thousands separators with 11064 |substitute()|: >vim 11065 let f = str2float(substitute(text, ',', '', 'g')) 11066< 11067 Returns 0.0 if the conversion fails. 11068 11069 Parameters: ~ 11070 • {string} (`string`) 11071 • {quoted} (`boolean?`) 11072 11073 Return: ~ 11074 (`any`) 11075 11076str2list({string} [, {utf8}]) *str2list()* 11077 Return a list containing the number values which represent 11078 each character in String {string}. Examples: >vim 11079 echo str2list(" ") " returns [32] 11080 echo str2list("ABC") " returns [65, 66, 67] 11081< |list2str()| does the opposite. 11082 11083 UTF-8 encoding is always used, {utf8} option has no effect, 11084 and exists only for backwards-compatibility. 11085 With UTF-8 composing characters are handled properly: >vim 11086 echo str2list("á") " returns [97, 769] 11087< 11088 11089 Attributes: ~ 11090 |api-fast| 11091 11092 Parameters: ~ 11093 • {string} (`string`) 11094 • {utf8} (`boolean?`) 11095 11096 Return: ~ 11097 (`any`) 11098 11099str2nr({string} [, {base}]) *str2nr()* 11100 Lua: Prefer |tonumber()| for simple numbers; quoted digits, 11101 base prefixes, and trailing text differ. 11102 11103 Convert string {string} to a number. 11104 {base} is the conversion base, it can be 2, 8, 10 or 16. 11105 When {quoted} is present and non-zero then embedded single 11106 quotes are ignored, thus "1'000'000" is a million. 11107 11108 When {base} is omitted base 10 is used. This also means that 11109 a leading zero doesn't cause octal conversion to be used, as 11110 with the default String to Number conversion. Example: >vim 11111 let nr = str2nr('0123') 11112< 11113 When {base} is 16 a leading "0x" or "0X" is ignored. With a 11114 different base the result will be zero. Similarly, when 11115 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when 11116 {base} is 2 a leading "0b" or "0B" is ignored. 11117 Text after the number is silently ignored. 11118 11119 Returns 0 if {string} is empty or on error. 11120 11121 Parameters: ~ 11122 • {string} (`string`) 11123 • {base} (`integer?`) 11124 11125 Return: ~ 11126 (`any`) 11127 11128strcharlen({string}) *strcharlen()* 11129 Returns the number of characters in String {string}, ignoring 11130 composing characters. Returns 0 on error or empty {string}. 11131 11132 |strchars()| can count the number of characters, counting 11133 composing characters separately. 11134 11135 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 11136 11137 Attributes: ~ 11138 |api-fast| 11139 11140 Parameters: ~ 11141 • {string} (`string`) 11142 11143 Return: ~ 11144 (`integer`) 11145 11146strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()* 11147 Like |strpart()| but using character index and length instead 11148 of byte index and length. 11149 When {skipcc} is omitted or zero, composing characters are 11150 counted separately. 11151 When {skipcc} set to 1, composing characters are treated as a 11152 part of the preceding base character, similar to |slice()|. 11153 When a character index is used where a character does not 11154 exist it is omitted and counted as one character. For 11155 example: >vim 11156 echo strcharpart('abc', -1, 2) 11157< results in 'a'. 11158 11159 Returns an empty string on error. 11160 11161 Attributes: ~ 11162 |api-fast| 11163 11164 Parameters: ~ 11165 • {src} (`string`) 11166 • {start} (`integer`) 11167 • {len} (`integer?`) 11168 • {skipcc} (`0|1|boolean?`) 11169 11170 Return: ~ 11171 (`string`) 11172 11173strchars({string} [, {skipcc}]) *strchars()* 11174 Lua: Prefer |vim.str_utfindex()| for codepoint counts; 11175 `skipcc` handling differs. 11176 11177 Returns the number of characters in String {string}. 11178 When {skipcc} is omitted or zero, composing characters are 11179 counted separately. 11180 When {skipcc} set to 1, composing characters are ignored. 11181 |strcharlen()| always does this. 11182 11183 Returns zero on error. 11184 11185 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 11186 11187 {skipcc} is only available after 7.4.755. For backward 11188 compatibility, you can define a wrapper function: >vim 11189 if has("patch-7.4.755") 11190 function s:strchars(str, skipcc) 11191 return strchars(a:str, a:skipcc) 11192 endfunction 11193 else 11194 function s:strchars(str, skipcc) 11195 if a:skipcc 11196 return strlen(substitute(a:str, ".", "x", "g")) 11197 else 11198 return strchars(a:str) 11199 endif 11200 endfunction 11201 endif 11202< 11203 11204 Attributes: ~ 11205 |api-fast| 11206 11207 Parameters: ~ 11208 • {string} (`string`) 11209 • {skipcc} (`0|1|boolean?`) 11210 11211 Return: ~ 11212 (`integer`) 11213 11214strdisplaywidth({string} [, {col}]) *strdisplaywidth()* 11215 Lua: Prefer |nvim_strwidth()| when `{col}` is 0; Tab expansion 11216 and window-option semantics differ. 11217 11218 Returns the number of display cells String {string} occupies 11219 on the screen when it starts at {col} (first column is zero). 11220 Returns zero on error. 11221 11222 When {col} is omitted zero is used. Otherwise it is the screen 11223 column where to start. This matters for Tab characters. 11224 The option settings of the current window are used. This 11225 matters for anything that's displayed differently, such as 11226 'tabstop' and 'display'. 11227 11228 When {string} contains characters with East Asian Width Class 11229 Ambiguous, this function's return value depends on 11230 'ambiwidth'. 11231 11232 Also see |strlen()|, |strwidth()| and |strchars()|. 11233 11234 Attributes: ~ 11235 |api-fast| 11236 11237 Parameters: ~ 11238 • {string} (`string`) 11239 • {col} (`integer?`) 11240 11241 Return: ~ 11242 (`integer`) 11243 11244strftime({format} [, {time}]) *strftime()* 11245 Lua: Prefer |os.date()|. 11246 11247 Formats a date and time String specified by {format}. The 11248 given {time} is used, or the current time if no time is given. 11249 The {format} depends on your system, this is not portable! 11250 See the manual page of the C function strftime() for the 11251 format. The maximum length of the result is 80 characters. 11252 See also |localtime()|, |getftime()| and |strptime()|. 11253 The language can be changed with the |:language| command. 11254 Examples: >vim 11255 echo strftime("%c") " Sun Apr 27 11:49:23 1997 11256 echo strftime("%Y %b %d %X") " 1997 Apr 27 11:53:25 11257 echo strftime("%y%m%d %T") " 970427 11:53:55 11258 echo strftime("%H:%M") " 11:55 11259 echo strftime("%c", getftime("file.c")) 11260 " Show mod time of file.c. 11261< 11262 11263 Parameters: ~ 11264 • {format} (`string`) 11265 • {time} (`number?`) 11266 11267 Return: ~ 11268 (`string`) 11269 11270strgetchar({str}, {index}) *strgetchar()* 11271 Get a Number corresponding to the character at {index} in 11272 {str}. This uses a zero-based character index, not a byte 11273 index. Composing characters are considered separate 11274 characters here. Use |nr2char()| to convert the Number to a 11275 String. 11276 Returns -1 if {index} is invalid. 11277 Also see |strcharpart()| and |strchars()|. 11278 11279 Attributes: ~ 11280 |api-fast| 11281 11282 Parameters: ~ 11283 • {str} (`string`) 11284 • {index} (`integer`) 11285 11286 Return: ~ 11287 (`integer`) 11288 11289stridx({haystack}, {needle} [, {start}]) *stridx()* 11290 Lua: Prefer |string.find()| with `plain = true` and 11291 `start + 1`, then subtract 1; missing matches return nil 11292 instead of -1. 11293 11294 Returns the byte index of the first occurrence of {needle} 11295 in {haystack}. 11296 If {start} is specified, the search starts at index {start}. 11297 This can be used to find a second match: >vim 11298 let colon1 = stridx(line, ":") 11299 let colon2 = stridx(line, ":", colon1 + 1) 11300< The search is done case-sensitive. 11301 For pattern searches use |match()|. 11302 -1 is returned if the {needle} does not occur in {haystack}. 11303 See also |strridx()|. 11304 Examples: >vim 11305 echo stridx("An Example", "Example") " 3 11306 echo stridx("Starting point", "Start") " 0 11307 echo stridx("Starting point", "start") " -1 11308< *strstr()* *strchr()* 11309 stridx() works similar to the C function strstr(). When used 11310 with a single character it works similar to strchr(). 11311 11312 Attributes: ~ 11313 |api-fast| 11314 11315 Parameters: ~ 11316 • {haystack} (`string`) 11317 • {needle} (`string`) 11318 • {start} (`integer?`) 11319 11320 Return: ~ 11321 (`integer`) 11322 11323string({expr}) *string()* 11324 Lua: Prefer |vim.inspect()| for tables, or |tostring()| for 11325 scalars. 11326 11327 Converts {expr} to a String. If {expr} is a Number, Float, 11328 String, Blob or a composition of them, the result can be 11329 parsed back with |eval()|. 11330 11331 {expr} type result ~ 11332 String `'string'` 11333 Number 123 11334 Float 123.123456 or 1.123456e8 or 11335 `str2float('inf')` 11336 Funcref `function('name')` 11337 Blob 0z00112233.44556677.8899 11338 List [item, item] 11339 Dictionary `{key: value, key: value}` 11340 11341 Note: in String values the ' character is doubled. 11342 Also see |strtrans()|. 11343 11344 Note: Output format is mostly compatible with YAML, except for 11345 infinite and NaN floating-point values representations which 11346 use |str2float()|. Strings are also dumped literally, only 11347 single quote is escaped, which does not allow using YAML for 11348 parsing back binary strings. |eval()| should always work for 11349 strings and floats though, and this is the only official 11350 method. Use |msgpackdump()| or |json_encode()| if you need to 11351 share data with other applications. 11352 11353 Parameters: ~ 11354 • {expr} (`any`) 11355 11356 Return: ~ 11357 (`string`) 11358 11359strlen({string}) *strlen()* 11360 Lua: Prefer |string.len()|. 11361 11362 Returns the length of String {string} in bytes. 11363 If the argument is a Number it is first converted to a String. 11364 For other types an error is given and zero is returned. 11365 If you want to count the number of multibyte characters use 11366 |strchars()|. 11367 Also see |len()|, |strdisplaywidth()| and |strwidth()|. 11368 11369 Attributes: ~ 11370 |api-fast| 11371 11372 Parameters: ~ 11373 • {string} (`string`) 11374 11375 Return: ~ 11376 (`integer`) 11377 11378strpart({src}, {start} [, {len} [, {chars}]]) *strpart()* 11379 Lua: Prefer |string.sub()| for byte slices; negative `start` 11380 and the `chars` flag differ. 11381 11382 Gets a substring from {src}, starting from byte {start}, with 11383 byte length {len}. Returns empty string on error. 11384 11385 When {chars} is present and TRUE then {len} is the number of 11386 characters positions (composing characters are not counted 11387 separately, thus "1" means one base character and any 11388 following composing characters). 11389 11390 To count {start} as characters instead of bytes use 11391 |strcharpart()|. 11392 11393 When bytes are selected which do not exist, this doesn't 11394 result in an error, the bytes are simply omitted. 11395 If {len} is missing, the copy continues from {start} till the 11396 end of the {src}. >vim 11397 echo strpart("abcdefg", 3, 2) " returns 'de' 11398 echo strpart("abcdefg", -2, 4) " returns 'ab' 11399 echo strpart("abcdefg", 5, 4) " returns 'fg' 11400 echo strpart("abcdefg", 3) " returns 'defg' 11401 11402< Note: To get the first character, {start} must be 0. For 11403 example, to get the character under the cursor: >vim 11404 strpart(getline("."), col(".") - 1, 1, v:true) 11405< 11406 11407 Attributes: ~ 11408 |api-fast| 11409 11410 Parameters: ~ 11411 • {src} (`string`) 11412 • {start} (`integer`) 11413 • {len} (`integer?`) 11414 • {chars} (`0|1?`) 11415 11416 Return: ~ 11417 (`string`) 11418 11419strptime({format}, {timestring}) *strptime()* 11420 Parses a date/time string and returns a unix timestamp. 11421 {timestring} must match the format specified in {format}. 11422 11423 The {format} depends on your system, this is not portable! 11424 See the strptime() manpage for the format. Especially avoid 11425 "%c". The value of $TZ also matters. 11426 11427 If the {timestring} cannot be parsed with {format} zero is 11428 returned. If you do not know the format of {timestring} you 11429 can try different {format} values until you get a non-zero 11430 result. 11431 11432 See also |strftime()|. 11433 Examples: >vim 11434 echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23") 11435< 862156163 >vim 11436 echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55")) 11437< Sun Apr 27 11:53:55 1997 >vim 11438 echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600) 11439< Sun Apr 27 12:53:55 1997 11440 11441 Parameters: ~ 11442 • {format} (`string`) 11443 • {timestring} (`string`) 11444 11445 Return: ~ 11446 (`integer`) 11447 11448strridx({haystack}, {needle} [, {start}]) *strridx()* 11449 Lua: Prefer |string.find()| in a loop with `plain = true`, 11450 then subtract 1; empty-needle and missing-match semantics 11451 differ. 11452 11453 Returns the byte index of the last occurrence of {needle} 11454 in {haystack}. 11455 When {start} is specified, matches beyond this index are 11456 ignored. This can be used to find a match before a previous 11457 match: >vim 11458 let lastcomma = strridx(line, ",") 11459 let comma2 = strridx(line, ",", lastcomma - 1) 11460< The search is done case-sensitive. 11461 For pattern searches use |match()|. 11462 -1 is returned if the {needle} does not occur in {haystack}. 11463 If the {needle} is empty the length of {haystack} is returned. 11464 See also |stridx()|. Examples: >vim 11465 echo strridx("an angry armadillo", "an") 3 11466< *strrchr()* 11467 When used with a single character it works similar to the C 11468 function strrchr(). 11469 11470 Parameters: ~ 11471 • {haystack} (`string`) 11472 • {needle} (`string`) 11473 • {start} (`integer?`) 11474 11475 Return: ~ 11476 (`integer`) 11477 11478strtrans({string}) *strtrans()* 11479 Translates all unprintable characters in {string} into 11480 printable characters, like they are shown in a 11481 window. Example: >vim 11482 echo strtrans(@a) 11483< This displays a newline in register a as "^@" instead of 11484 starting a new line. 11485 11486 Returns an empty string on error. 11487 11488 Attributes: ~ 11489 |api-fast| 11490 11491 Parameters: ~ 11492 • {string} (`string`) 11493 11494 Return: ~ 11495 (`string`) 11496 11497strutf16len({string} [, {countcc}]) *strutf16len()* 11498 Lua: Prefer |vim.str_utfindex()| with `"utf-16"`; 11499 `countcc = false` semantics differ. 11500 11501 Returns the number of UTF-16 code units in String {string} 11502 (after converting it to UTF-16). 11503 11504 When {countcc} is TRUE, composing characters are counted 11505 separately. 11506 When {countcc} is omitted or FALSE, composing characters are 11507 ignored. 11508 11509 Returns zero on error. 11510 11511 Also see |strlen()| and |strcharlen()|. 11512 Examples: >vim 11513 echo strutf16len('a') " returns 1 11514 echo strutf16len('©') " returns 1 11515 echo strutf16len('😊') " returns 2 11516 echo strutf16len('ą́') " returns 1 11517 echo strutf16len('ą́', v:true) " returns 3 11518< 11519 11520 Parameters: ~ 11521 • {string} (`string`) 11522 • {countcc} (`0|1?`) 11523 11524 Return: ~ 11525 (`integer`) 11526 11527strwidth({string}) *strwidth()* 11528 Lua: Prefer |nvim_strwidth()|. 11529 11530 Returns the number of display cells String {string} occupies. 11531 A Tab character is counted as one cell, alternatively use 11532 |strdisplaywidth()|. 11533 When {string} contains characters with East Asian Width Class 11534 Ambiguous, this function's return value depends on 11535 'ambiwidth'. 11536 Returns zero on error. 11537 Also see |strlen()|, |strdisplaywidth()| and |strchars()|. 11538 11539 Attributes: ~ 11540 |api-fast| 11541 11542 Parameters: ~ 11543 • {string} (`string`) 11544 11545 Return: ~ 11546 (`integer`) 11547 11548submatch({nr} [, {list}]) *submatch()* *E935* 11549 Only for an expression in a |:substitute| command or 11550 |substitute()| function. 11551 Returns the {nr}th submatch of the matched text. When {nr} 11552 is 0 the whole matched text is returned. 11553 Note that a NL in the string can stand for a line break of a 11554 multi-line match or a NUL character in the text. 11555 Also see |sub-replace-expression|. 11556 11557 If {list} is present and non-zero then submatch() returns 11558 a list of strings, similar to |getline()| with two arguments. 11559 NL characters in the text represent NUL characters in the 11560 text. 11561 Only returns more than one item for |:substitute|, inside 11562 |substitute()| this list will always contain one or zero 11563 items, since there are no real line breaks. 11564 11565 When |substitute()| is used recursively only the submatches in 11566 the current (deepest) call can be obtained. 11567 11568 Returns an empty string or list on error. 11569 11570 Examples: >vim 11571 s/\d\+/\=submatch(0) + 1/ 11572 echo substitute(text, '\d\+', '\=submatch(0) + 1', '') 11573< This finds the first number in the line and adds one to it. 11574 A line break is included as a newline character. 11575 11576 Parameters: ~ 11577 • {nr} (`integer`) 11578 • {list} (`nil?`) 11579 11580 Return: ~ 11581 (`string`) 11582 11583substitute({string}, {pat}, {sub}, {flags}) *substitute()* 11584 Lua: Prefer |string.gsub()| for common substitutions; Vim 11585 patterns, flags, and replacement semantics differ. 11586 11587 Performs string substitution. Returns a copy of {string} 11588 in which the first match of {pat} is replaced with {sub}. 11589 When {flags} is "g", all matches of {pat} in {string} are 11590 replaced. Otherwise {flags} should be "". 11591 11592 This works like the ":substitute" command (without any flags). 11593 But the matching with {pat} is always done like the 'magic' 11594 option is set and 'cpoptions' is empty (to make scripts 11595 portable). 'ignorecase' is still relevant, use |/\c| or |/\C| 11596 if you want to ignore or match case and ignore 'ignorecase'. 11597 'smartcase' is not used. See |string-match| for how {pat} is 11598 used. 11599 11600 A "~" in {sub} is not replaced with the previous {sub}. 11601 Note that some codes in {sub} have a special meaning 11602 |sub-replace-special|. For example, to replace something with 11603 "\n" (two characters), use "\\\\n" or '\\n'. 11604 11605 When {pat} does not match in {string}, {string} is returned 11606 unmodified. 11607 11608 Example: >vim 11609 let &path = substitute(&path, ",\\=[^,]*$", "", "") 11610< This removes the last component of the 'path' option. >vim 11611 echo substitute("testing", ".*", "\\U\\0", "") 11612< results in "TESTING". 11613 11614 When {sub} starts with "\=", the remainder is interpreted as 11615 an expression. See |sub-replace-expression|. Example: >vim 11616 echo substitute(s, '%\(\x\x\)', 11617 \ '\=nr2char("0x" .. submatch(1))', 'g') 11618 11619< When {sub} is a Funcref that function is called, with one 11620 optional argument. Example: >vim 11621 echo substitute(s, '%\(\x\x\)', SubNr, 'g') 11622< The optional argument is a list which contains the whole 11623 matched string and up to nine submatches, like what 11624 |submatch()| returns. Example: >vim 11625 echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g') 11626 11627< Returns an empty string on error. 11628 11629 Parameters: ~ 11630 • {string} (`string`) 11631 • {pat} (`string`) 11632 • {sub} (`string`) 11633 • {flags} (`string`) 11634 11635 Return: ~ 11636 (`string`) 11637 11638swapfilelist() *swapfilelist()* 11639 Returns a list of swap file names, like what "vim -r" shows. 11640 See the |-r| command argument. The 'directory' option is used 11641 for the directories to inspect. If you only want to get a 11642 list of swap files in the current directory then temporarily 11643 set 'directory' to a dot: >vim 11644 let save_dir = &directory 11645 let &directory = '.' 11646 let swapfiles = swapfilelist() 11647 let &directory = save_dir 11648< 11649 11650 Return: ~ 11651 (`string[]`) 11652 11653swapinfo({fname}) *swapinfo()* 11654 Returns information about the swapfile {fname} as a 11655 dictionary. The available fields are: 11656 version Vim version 11657 user user name 11658 host host name 11659 fname original file name 11660 pid PID of the Nvim process that created the swap 11661 file, or zero if not running. 11662 mtime last modification time in seconds 11663 inode Optional: INODE number of the file 11664 dirty 1 if file was modified, 0 if not 11665 In case of failure an "error" item is added with the reason: 11666 Cannot open file: file not found or in accessible 11667 Cannot read file: cannot read first block 11668 Not a swap file: does not contain correct block ID 11669 Magic number mismatch: Info in first block is invalid 11670 11671 Parameters: ~ 11672 • {fname} (`string`) 11673 11674 Return: ~ 11675 (`any`) 11676 11677swapname({buf}) *swapname()* 11678 The result is the swap file path of the buffer {buf}. 11679 For the use of {buf}, see |bufname()| above. 11680 If buffer {buf} is the current buffer, the result is equal to 11681 |:swapname| (unless there is no swap file). 11682 If buffer {buf} has no swap file, returns an empty string. 11683 11684 Parameters: ~ 11685 • {buf} (`integer|string`) 11686 11687 Return: ~ 11688 (`string`) 11689 11690synID({lnum}, {col}, {trans}) *synID()* 11691 Returns the syntax ID at position {lnum} and {col} in the 11692 current window. The syntax ID can be used with |synIDattr()| 11693 and |synIDtrans()| to obtain syntax information about text. 11694 11695 {col} is 1 for the leftmost column, {lnum} is 1 for the first 11696 line. 'synmaxcol' applies, in a longer line zero is returned. 11697 Note that when the position is after the last character, 11698 that's where the cursor can be in Insert mode, synID() returns 11699 zero. {lnum} is used like with |getline()|. 11700 11701 When {trans} is |TRUE|, transparent items are reduced to the 11702 item that they reveal. This is useful when wanting to know 11703 the effective color. When {trans} is |FALSE|, the transparent 11704 item is returned. This is useful when wanting to know which 11705 syntax item is effective (e.g. inside parens). 11706 Warning: This function can be very slow. Best speed is 11707 obtained by going through the file in forward direction. 11708 11709 Returns zero on error. 11710 11711 Example (echoes the name of the syntax item under the cursor): >vim 11712 echo synIDattr(synID(line("."), col("."), 1), "name") 11713< 11714 11715 Parameters: ~ 11716 • {lnum} (`integer|string`) 11717 • {col} (`integer`) 11718 • {trans} (`0|1`) 11719 11720 Return: ~ 11721 (`integer`) 11722 11723synIDattr({synID}, {what} [, {mode}]) *synIDattr()* 11724 Returns the {what} attribute of syntax ID {synID} as a 11725 String. This can be used to obtain information about a 11726 syntax item. 11727 {mode} can be "gui" or "cterm", to get the attributes 11728 for that mode. When {mode} is omitted, or an invalid value is 11729 used, the attributes for the currently active highlighting are 11730 used (GUI or cterm). 11731 Use |synIDtrans()| to follow linked highlight groups. 11732 {what} result 11733 "name" the name of the syntax item 11734 "fg" foreground color (GUI: color name used to set 11735 the color, cterm: color number as a string, 11736 term: empty string) 11737 "bg" background color (as with "fg") 11738 "font" font name (only available in the GUI) 11739 |highlight-font| 11740 "sp" special color (as with "fg") |guisp| 11741 "fg#" like "fg", but for the GUI and the GUI is 11742 running the name in "#RRGGBB" form 11743 "bg#" like "fg#" for "bg" 11744 "sp#" like "fg#" for "sp" 11745 "bold" "1" if bold 11746 "italic" "1" if italic 11747 "reverse" "1" if reverse 11748 "inverse" "1" if inverse (= reverse) 11749 "standout" "1" if standout 11750 "underline" "1" if underlined 11751 "undercurl" "1" if undercurled 11752 "underdouble" "1" if double underlined 11753 "underdotted" "1" if dotted underlined 11754 "underdashed" "1" if dashed underlined 11755 "strikethrough" "1" if struckthrough 11756 "altfont" "1" if alternative font 11757 "nocombine" "1" if nocombine 11758 "dim" "1" if half-bright/dimmed 11759 "blink" "1" if blinking 11760 "conceal" "1" if concealed 11761 "overline" "1" if overlined 11762 11763 Returns an empty string on error. 11764 11765 Example (echoes the color of the syntax item under the 11766 cursor): >vim 11767 echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") 11768< 11769 Can also be used as a |method|: >vim 11770 echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") 11771< 11772 11773 Parameters: ~ 11774 • {synID} (`integer`) 11775 • {what} (`string`) 11776 • {mode} (`string?`) 11777 11778 Return: ~ 11779 (`string`) 11780 11781synIDtrans({synID}) *synIDtrans()* 11782 Returns the translated syntax ID of {synID}, following 11783 highlight links. This is the syntax group ID of what is 11784 being used to highlight the character. Highlight links given with 11785 ":highlight link" are followed. 11786 11787 Returns zero on error. 11788 11789 Parameters: ~ 11790 • {synID} (`integer`) 11791 11792 Return: ~ 11793 (`integer`) 11794 11795synconcealed({lnum}, {col}) *synconcealed()* 11796 Returns conceal information for the character at position 11797 {lnum} and {col} as a |List| with three items: 11798 1. The first item in the list is 0 if the character is not 11799 part of a concealable region, 1 if it is. {lnum} is used 11800 like with |getline()|. 11801 2. The second item in the list is a string. If the first item 11802 is 1, the second item contains the text which will be 11803 displayed in place of the concealed text, depending on the 11804 current setting of 'conceallevel' and 'listchars'. 11805 3. The third and final item in the list is a number 11806 representing the specific syntax region matched in the 11807 line. When the character is not concealed the value is 11808 zero. This allows detection of the beginning of a new 11809 concealable region if there are two consecutive regions 11810 with the same replacement character. For an example, if 11811 the text is "123456" and both "23" and "45" are concealed 11812 and replaced by the character "X", then: 11813 call returns ~ 11814 synconcealed(lnum, 1) [0, '', 0] 11815 synconcealed(lnum, 2) [1, 'X', 1] 11816 synconcealed(lnum, 3) [1, 'X', 1] 11817 synconcealed(lnum, 4) [1, 'X', 2] 11818 synconcealed(lnum, 5) [1, 'X', 2] 11819 synconcealed(lnum, 6) [0, '', 0] 11820 11821 Note: Doesn't consider |matchadd()| highlighting items, 11822 since syntax and matching highlighting are two different 11823 mechanisms |syntax-vs-match|. 11824 11825 Parameters: ~ 11826 • {lnum} (`integer|string`) 11827 • {col} (`integer`) 11828 11829 Return: ~ 11830 (`[integer, string, integer]`) 11831 11832synstack({lnum}, {col}) *synstack()* 11833 Return a |List|, which is the stack of syntax items at the 11834 position {lnum} and {col} in the current window. {lnum} is 11835 used like with |getline()|. Each item in the List is an ID 11836 like what |synID()| returns. 11837 The first item in the List is the outer region, following are 11838 items contained in that one. The last one is what |synID()| 11839 returns, unless not the whole item is highlighted or it is a 11840 transparent item. 11841 This function is useful for debugging a syntax file. 11842 Example that shows the syntax stack under the cursor: >vim 11843 for id in synstack(line("."), col(".")) 11844 echo synIDattr(id, "name") 11845 endfor 11846< When the position specified with {lnum} and {col} is invalid 11847 an empty list is returned. The position just after the last 11848 character in a line and the first column in an empty line are 11849 valid positions. 11850 11851 Parameters: ~ 11852 • {lnum} (`integer|string`) 11853 • {col} (`integer`) 11854 11855 Return: ~ 11856 (`integer[]`) 11857 11858system({cmd} [, {input}]) *system()* *E677* 11859 Lua: Prefer `vim.system(...):wait().stdout` for string output; 11860 string commands use the shell in Vimscript, not by default in 11861 Lua. 11862 11863 Gets the output of {cmd} as a |string| (|systemlist()| returns 11864 a |List|) and sets |v:shell_error| to the error code. 11865 {cmd} is treated as in |jobstart()|: 11866 If {cmd} is a List it runs directly (no 'shell'). 11867 If {cmd} is a String it runs in the 'shell', like this: >vim 11868 call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}']) 11869 11870< Not to be used for interactive commands. 11871 11872 Result is a String, filtered to avoid platform-specific quirks: 11873 - <CR><NL> is replaced with <NL> 11874 - NUL characters are replaced with SOH (0x01) 11875 11876 Example: >vim 11877 echo system(['ls', expand('%:h')]) 11878 11879< If {input} is a string it is written to a pipe and passed as 11880 stdin to the command. The string is written as-is, line 11881 separators are not changed. 11882 If {input} is a |List| it is written to the pipe as 11883 |writefile()| does with {binary} set to "b" (i.e. with 11884 a newline between each list item, and newlines inside list 11885 items converted to NULs). 11886 When {input} is given and is a valid buffer id, the content of 11887 the buffer is written to the file line by line, each line 11888 terminated by NL (and NUL where the text has NL). 11889 *E5677* 11890 Note: system() cannot write to or read from backgrounded ("&") 11891 shell commands, e.g.: >vim 11892 echo system("cat - &", "foo") 11893< which is equivalent to: > 11894 $ echo foo | bash -c 'cat - &' 11895< The pipes are disconnected (unless overridden by shell 11896 redirection syntax) before input can reach it. Use 11897 |jobstart()| instead. 11898 11899 Note: Use |shellescape()| or |::S| with |expand()| or 11900 |fnamemodify()| to escape special characters in a command 11901 argument. 'shellquote' and 'shellxquote' must be properly 11902 configured. Example: >vim 11903 echo system('ls '..shellescape(expand('%:h'))) 11904 echo system('ls '..expand('%:h:S')) 11905 11906< Unlike ":!cmd" there is no automatic check for changed files. 11907 Use |:checktime| to force a check. 11908 11909 Parameters: ~ 11910 • {cmd} (`string|string[]`) 11911 • {input} (`string|string[]|integer?`) 11912 11913 Return: ~ 11914 (`string`) 11915 11916systemlist({cmd} [, {input} [, {keepempty}]]) *systemlist()* 11917 Lua: Prefer `vim.system(...):wait().stdout` split into lines; 11918 string commands use the shell in Vimscript, not by default in 11919 Lua. 11920 11921 Same as |system()|, but returns a |List| with lines (parts of 11922 output separated by NL) with NULs transformed into NLs. 11923 Output is the same as |readfile()| will output with {binary} 11924 argument set to "b", except that a final newline is not 11925 preserved, unless {keepempty} is non-zero. 11926 Note that on MS-Windows you may get trailing CR characters. 11927 11928 To see the difference between "echo hello" and "echo -n hello" 11929 use |system()| and |split()|: >vim 11930 echo split(system('echo hello'), '\n', 1) 11931< 11932 Returns an empty string on error. 11933 11934 Parameters: ~ 11935 • {cmd} (`string|string[]`) 11936 • {input} (`string|string[]|integer?`) 11937 • {keepempty} (`integer?`) 11938 11939 Return: ~ 11940 (`string[]`) 11941 11942tabpagebuflist([{arg}]) *tabpagebuflist()* 11943 Lua: Prefer |nvim_tabpage_list_wins()| with 11944 |nvim_win_get_buf()|; invalid tabpages error instead of 11945 returning 0. 11946 11947 Returns a |List| of buffer numbers, one for each window in 11948 the specified tabpage. 11949 {arg} specifies the number of the tabpage to be used. When 11950 omitted the current tabpage is used. 11951 When {arg} is invalid the number zero is returned. 11952 To get a list of all buffers in all tabs use this: >vim 11953 let buflist = [] 11954 for i in range(tabpagenr('$')) 11955 call extend(buflist, tabpagebuflist(i + 1)) 11956 endfor 11957< Note that a buffer may appear in more than one window. 11958 11959 Parameters: ~ 11960 • {arg} (`integer?`) 11961 11962 Return: ~ 11963 (`any`) 11964 11965tabpagenr([{arg}]) *tabpagenr()* 11966 Lua: Prefer |nvim_tabpage_get_number()| with 11967 |nvim_get_current_tabpage()| for the current tab, or 11968 `#vim.api.nvim_list_tabpages()` for "$"; "#" differs. 11969 11970 Returns the current |tabpage-number|. 11971 11972 The optional argument {arg} supports the following values: 11973 $ the last |tabpage-number| (the tabpage count). 11974 # the last-accessed |tabpage-number| (where |g<Tab>| 11975 goes to), or 0 if there is no previous tabpage. 11976 The number can be used with the |:tab| command. 11977 11978 Returns zero on error. 11979 11980 Parameters: ~ 11981 • {arg} (`'$'|'#'?`) 11982 11983 Return: ~ 11984 (`integer`) 11985 11986tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()* 11987 Lua: Prefer |nvim_win_get_number()| with 11988 |nvim_tabpage_get_win()| for the current window, or the length 11989 of |nvim_tabpage_list_wins()| for "$"; "#" and invalid-tab 11990 behavior differ. 11991 11992 Like |winnr()| but for tabpage {tabarg}. 11993 {tabarg} specifies the |tabpage-number| to be used. 11994 {arg} is used like with |winnr()|: 11995 - When omitted the current window number is returned. This is 11996 the window which will be used when going to this tabpage. 11997 - When "$" the number of windows is returned. 11998 - When "#" the previous window nr is returned. 11999 Useful examples: >vim 12000 tabpagewinnr(1) " current window of tabpage 1 12001 tabpagewinnr(4, '$') " number of windows in tabpage 4 12002< When {tabarg} is invalid zero is returned. 12003 12004 Parameters: ~ 12005 • {tabarg} (`integer`) 12006 • {arg} (`'$'|'#'?`) 12007 12008 Return: ~ 12009 (`integer`) 12010 12011tagfiles() *tagfiles()* 12012 Returns a |List| with the file names used to search for tags 12013 for the current buffer. This is the 'tags' option expanded. 12014 12015 Return: ~ 12016 (`string[]`) 12017 12018taglist({expr} [, {filename}]) *taglist()* 12019 Returns a |List| of tags matching the regular expression {expr}. 12020 12021 If {filename} is passed it is used to prioritize the results 12022 in the same way that |:tselect| does. See |tag-priority|. 12023 {filename} should be the full path of the file. 12024 12025 Each list item is a dictionary with at least the following 12026 entries: 12027 name Name of the tag. 12028 filename Name of the file where the tag is 12029 defined. It is either relative to the 12030 current directory or a full path. 12031 cmd Ex command used to locate the tag in 12032 the file. 12033 kind Type of the tag. The value for this 12034 entry depends on the language specific 12035 kind values. Only available when 12036 using a tags file generated by 12037 Universal/Exuberant ctags or hdrtag. 12038 static A file specific tag. Refer to 12039 |static-tag| for more information. 12040 More entries may be present, depending on the content of the 12041 tags file: access, implementation, inherits and signature. 12042 Refer to the ctags documentation for information about these 12043 fields. For C code the fields "struct", "class" and "enum" 12044 may appear, they give the name of the entity the tag is 12045 contained in. 12046 12047 The ex-command "cmd" can be either an ex search pattern, a 12048 line number or a line number followed by a byte number. 12049 12050 If there are no matching tags, then an empty list is returned. 12051 12052 To get an exact tag match, the anchors '^' and '$' should be 12053 used in {expr}. This also make the function work faster. 12054 Refer to |tag-regexp| for more information about the tag 12055 search regular expression pattern. 12056 12057 Refer to 'tags' for information about how the tags file is 12058 located by Vim. Refer to |tags-file-format| for the format of 12059 the tags file generated by the different ctags tools. 12060 12061 Parameters: ~ 12062 • {expr} (`any`) 12063 • {filename} (`string?`) 12064 12065 Return: ~ 12066 (`any`) 12067 12068tan({expr}) *tan()* 12069 Lua: Prefer |math.tan()|. 12070 12071 Return the tangent of {expr}, measured in radians, as a |Float| 12072 in the range [-inf, inf]. 12073 {expr} must evaluate to a |Float| or a |Number|. 12074 Returns 0.0 if {expr} is not a |Float| or a |Number|. 12075 Examples: >vim 12076 echo tan(10) 12077< 0.648361 >vim 12078 echo tan(-4.01) 12079< -1.181502 12080 12081 Parameters: ~ 12082 • {expr} (`number`) 12083 12084 Return: ~ 12085 (`number`) 12086 12087tanh({expr}) *tanh()* 12088 Lua: Prefer |math.tanh()|. 12089 12090 Return the hyperbolic tangent of {expr} as a |Float| in the 12091 range [-1, 1]. 12092 {expr} must evaluate to a |Float| or a |Number|. 12093 Returns 0.0 if {expr} is not a |Float| or a |Number|. 12094 Examples: >vim 12095 echo tanh(0.5) 12096< 0.462117 >vim 12097 echo tanh(-1) 12098< -0.761594 12099 12100 Parameters: ~ 12101 • {expr} (`number`) 12102 12103 Return: ~ 12104 (`number`) 12105 12106tempname() *tempname()* 12107 Lua: Prefer |os.tmpname()| for a temporary name; Nvim's 12108 |tempdir| and nonexistence are not guaranteed. 12109 12110 Generates a (non-existent) filename located in the Nvim root 12111 |tempdir|. Scripts can use the filename as a temporary file. 12112 Example: >vim 12113 let tmpfile = tempname() 12114 exe "redir > " .. tmpfile 12115< 12116 12117 Return: ~ 12118 (`string`) 12119 12120test_garbagecollect_now() *test_garbagecollect_now()* 12121 Like |garbagecollect()|, but executed right away. This must 12122 only be called directly to avoid any structure to exist 12123 internally, and |v:testing| must have been set before calling 12124 any function. *E1142* 12125 12126 Return: ~ 12127 (`any`) 12128 12129timer_info([{id}]) *timer_info()* 12130 Return a list with information about timers. 12131 When {id} is given only information about this timer is 12132 returned. When timer {id} does not exist an empty list is 12133 returned. 12134 When {id} is omitted information about all timers is returned. 12135 12136 For each timer the information is stored in a |Dictionary| with 12137 these items: 12138 "id" the timer ID 12139 "time" time the timer was started with 12140 "repeat" number of times the timer will still fire; 12141 -1 means forever 12142 "callback" the callback 12143 12144 Parameters: ~ 12145 • {id} (`integer?`) 12146 12147 Return: ~ 12148 (`any`) 12149 12150timer_pause({timer}, {paused}) *timer_pause()* 12151 Pause or unpause a timer. A paused timer does not invoke its 12152 callback when its time expires. Unpausing a timer may cause 12153 the callback to be invoked almost immediately if enough time 12154 has passed. 12155 12156 Pausing a timer is useful to avoid the callback to be called 12157 for a short time. 12158 12159 If {paused} evaluates to a non-zero Number or a non-empty 12160 String, then the timer is paused, otherwise it is unpaused. 12161 See |non-zero-arg|. 12162 12163 Parameters: ~ 12164 • {timer} (`integer`) 12165 • {paused} (`boolean`) 12166 12167 Return: ~ 12168 (`any`) 12169 12170timer_start({time}, {callback} [, {options}]) *timer_start()* *timer* 12171 Lua: Prefer |vim.defer_fn()| for one-shot timers, or 12172 |uv.new_timer()| for repeating timers; callback and handle 12173 semantics differ. 12174 12175 Create a timer and return the timer ID. 12176 12177 {time} is the waiting time in milliseconds. This is the 12178 minimum time before invoking the callback. When the system is 12179 busy or Vim is not waiting for input the time will be longer. 12180 Zero can be used to execute the callback when Vim is back in 12181 the main loop. 12182 12183 {callback} is the function to call. It can be the name of a 12184 function or a |Funcref|. It is called with one argument, which 12185 is the timer ID. The callback is only invoked when Vim is 12186 waiting for input. 12187 12188 {options} is a dictionary. Supported entries: 12189 "repeat" Number of times to repeat the callback. 12190 -1 means forever. Default is 1. 12191 If the timer causes an error three times in a 12192 row the repeat is cancelled. 12193 12194 Returns -1 on error. 12195 12196 Example: >vim 12197 func MyHandler(timer) 12198 echo 'Handler called' 12199 endfunc 12200 let timer = timer_start(500, 'MyHandler', 12201 \ {'repeat': 3}) 12202< This invokes MyHandler() three times at 500 msec intervals. 12203 12204 Parameters: ~ 12205 • {time} (`number`) 12206 • {callback} (`string|function`) 12207 • {options} (`table?`) 12208 12209 Return: ~ 12210 (`any`) 12211 12212timer_stop({timer}) *timer_stop()* 12213 Lua: Prefer |uv.timer_stop()| and |uv.close()| on a stored 12214 |uv.new_timer()| handle; timer IDs differ. 12215 12216 Stop a timer. The timer callback will no longer be invoked. 12217 {timer} is an ID returned by |timer_start()|, thus it must be a 12218 Number. If {timer} does not exist there is no error. 12219 12220 Parameters: ~ 12221 • {timer} (`integer`) 12222 12223 Return: ~ 12224 (`any`) 12225 12226timer_stopall() *timer_stopall()* 12227 Stop all timers. The timer callbacks will no longer be 12228 invoked. Useful if some timers is misbehaving. If there are 12229 no timers there is no error. 12230 12231 Return: ~ 12232 (`any`) 12233 12234tolower({expr}) *tolower()* 12235 Lua: Prefer |string.lower()|. 12236 12237 Converts a String to lowercase (like applying |gu|). 12238 Returns empty string on error. 12239 12240 Attributes: ~ 12241 |api-fast| 12242 12243 Parameters: ~ 12244 • {expr} (`string`) 12245 12246 Return: ~ 12247 (`string`) 12248 12249toupper({expr}) *toupper()* 12250 Lua: Prefer |string.upper()|. 12251 12252 Converts a String to uppercase (like applying |gU|). 12253 Returns empty string on error. 12254 12255 Attributes: ~ 12256 |api-fast| 12257 12258 Parameters: ~ 12259 • {expr} (`string`) 12260 12261 Return: ~ 12262 (`string`) 12263 12264tr({src}, {fromstr}, {tostr}) *tr()* 12265 Translates characters in {src}, replacing each character that 12266 appears in {fromstr} with the corresponding character in 12267 {tostr}. Exactly like the unix "tr" command. 12268 This code also deals with multibyte characters properly. 12269 12270 Returns an empty string on error. 12271 12272 Examples: >vim 12273 echo tr("hello there", "ht", "HT") 12274< returns "Hello THere" >vim 12275 echo tr("<blob>", "<>", "{}") 12276< returns "{blob}" 12277 12278 Attributes: ~ 12279 |api-fast| 12280 12281 Parameters: ~ 12282 • {src} (`string`) 12283 • {fromstr} (`string`) 12284 • {tostr} (`string`) 12285 12286 Return: ~ 12287 (`string`) 12288 12289trim({text} [, {mask} [, {dir}]]) *trim()* 12290 Lua: Prefer |vim.trim()|. 12291 12292 Return {text} as a String where any character in {mask} is 12293 removed from the beginning and/or end of {text}. 12294 12295 If {mask} is not given, or is an empty string, {mask} is all 12296 characters up to 0x20, which includes Tab, space, NL and CR, 12297 plus the non-breaking space character 0xa0. 12298 12299 The optional {dir} argument specifies where to remove the 12300 characters: 12301 0 remove from the beginning and end of {text} 12302 1 remove only at the beginning of {text} 12303 2 remove only at the end of {text} 12304 When omitted both ends are trimmed. 12305 12306 This function deals with multibyte characters properly. 12307 Returns an empty string on error. 12308 12309 Examples: >vim 12310 echo trim(" some text ") 12311< returns "some text" >vim 12312 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL" 12313< returns "RESERVE_TAIL" >vim 12314 echo trim("rm<Xrm<>X>rrm", "rm<>") 12315< returns "Xrm<>X" (characters in the middle are not removed) >vim 12316 echo trim(" vim ", " ", 2) 12317< returns " vim" 12318 12319 Attributes: ~ 12320 |api-fast| 12321 12322 Parameters: ~ 12323 • {text} (`string`) 12324 • {mask} (`string?`) 12325 • {dir} (`0|1|2?`) 12326 12327 Return: ~ 12328 (`string`) 12329 12330trunc({expr}) *trunc()* 12331 Lua: Prefer |math.modf()| (first return value). 12332 12333 Return the largest integral value with magnitude less than or 12334 equal to {expr} as a |Float| (truncate towards zero). 12335 {expr} must evaluate to a |Float| or a |Number|. 12336 Returns 0.0 if {expr} is not a |Float| or a |Number|. 12337 Examples: >vim 12338 echo trunc(1.456) 12339< 1.0 >vim 12340 echo trunc(-5.456) 12341< -5.0 >vim 12342 echo trunc(4.0) 12343< 4.0 12344 12345 Parameters: ~ 12346 • {expr} (`number`) 12347 12348 Return: ~ 12349 (`integer`) 12350 12351type({expr}) *type()* 12352 Lua: Prefer |lua-type()| for most Lua type checks; Vim type 12353 IDs differ. 12354 12355 Returns the type of {expr} as a Number. 12356 Instead of using the number directly, it is better to use the 12357 v:t_ variable that has the value: 12358 Number: 0 |v:t_number| 12359 String: 1 |v:t_string| 12360 Funcref: 2 |v:t_func| 12361 List: 3 |v:t_list| 12362 Dictionary: 4 |v:t_dict| 12363 Float: 5 |v:t_float| 12364 Boolean: 6 |v:t_bool| (|v:false| and |v:true|) 12365 Null: 7 (|v:null|) 12366 Blob: 10 |v:t_blob| 12367 For backward compatibility, this method can be used: >vim 12368 if type(myvar) == type(0) | endif 12369 if type(myvar) == type("") | endif 12370 if type(myvar) == type(function("tr")) | endif 12371 if type(myvar) == type([]) | endif 12372 if type(myvar) == type({}) | endif 12373 if type(myvar) == type(0.0) | endif 12374 if type(myvar) == type(v:true) | endif 12375< In place of checking for |v:null| type it is better to check 12376 for |v:null| directly as it is the only value of this type: >vim 12377 if myvar is v:null | endif 12378< To check if the v:t_ variables exist use this: >vim 12379 if exists('v:t_number') | endif 12380< 12381 12382 Attributes: ~ 12383 |api-fast| 12384 12385 Parameters: ~ 12386 • {expr} (`any`) 12387 12388 Return: ~ 12389 (`integer`) 12390 12391undofile({name}) *undofile()* 12392 Return the name of the undo file that would be used for a file 12393 with name {name} when writing. This uses the 'undodir' 12394 option, finding directories that exist. It does not check if 12395 the undo file exists. 12396 {name} is always expanded to the full path, since that is what 12397 is used internally. 12398 If {name} is empty undofile() returns an empty string, since a 12399 buffer without a file name will not write an undo file. 12400 Useful in combination with |:wundo| and |:rundo|. 12401 12402 Parameters: ~ 12403 • {name} (`string`) 12404 12405 Return: ~ 12406 (`string`) 12407 12408undotree([{buf}]) *undotree()* 12409 Return the current state of the undo tree for the current 12410 buffer, or for a specific buffer if {buf} is given. The 12411 result is a dictionary with the following items: 12412 "seq_last" The highest undo sequence number used. 12413 "seq_cur" The sequence number of the current position in 12414 the undo tree. This differs from "seq_last" 12415 when some changes were undone. 12416 "time_cur" Time last used for |:earlier| and related 12417 commands. Use |strftime()| to convert to 12418 something readable. 12419 "save_last" Number of the last file write. Zero when no 12420 write yet. 12421 "save_cur" Number of the current position in the undo 12422 tree. 12423 "synced" Non-zero when the last undo block was synced. 12424 This happens when waiting from input from the 12425 user. See |undo-blocks|. 12426 "entries" A list of dictionaries with information about 12427 undo blocks. 12428 12429 The first item in the "entries" list is the oldest undo item. 12430 Each List item is a |Dictionary| with these items: 12431 "seq" Undo sequence number. Same as what appears in 12432 |:undolist|. 12433 "time" Timestamp when the change happened. Use 12434 |strftime()| to convert to something readable. 12435 "newhead" Only appears in the item that is the last one 12436 that was added. This marks the last change 12437 and where further changes will be added. 12438 "curhead" Only appears in the item that is the last one 12439 that was undone. This marks the current 12440 position in the undo tree, the block that will 12441 be used by a redo command. When nothing was 12442 undone after the last change this item will 12443 not appear anywhere. 12444 "save" Only appears on the last block before a file 12445 write. The number is the write count. The 12446 first write has number 1, the last one the 12447 "save_last" mentioned above. 12448 "alt" Alternate entry. This is again a List of undo 12449 blocks. Each item may again have an "alt" 12450 item. 12451 12452 Parameters: ~ 12453 • {buf} (`integer|string?`) 12454 12455 Return: ~ 12456 (`vim.fn.undotree.ret`) 12457 12458uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* 12459 Lua: Prefer |vim.list.unique()|. 12460 12461 Remove second and succeeding copies of repeated adjacent 12462 {list} items in-place. Returns {list}. If you want a list 12463 to remain unmodified make a copy first: >vim 12464 let newlist = uniq(copy(mylist)) 12465< The default compare function uses the string representation of 12466 each item. For the use of {func} and {dict} see |sort()|. 12467 For deduplicating text in the current buffer see |:uniq|. 12468 12469 Returns zero if {list} is not a |List|. 12470 12471 Parameters: ~ 12472 • {list} (`any`) 12473 • {func} (`any?`) 12474 • {dict} (`any?`) 12475 12476 Return: ~ 12477 (`any[]|0`) 12478 12479utf16idx({string}, {idx} [, {countcc} [, {charidx}]]) *utf16idx()* 12480 Lua: Prefer |vim.str_utfindex()| with `"utf-16"` and 12481 `strict_indexing = false`; `countcc` and `charidx` semantics 12482 differ. 12483 12484 Same as |charidx()| but returns the UTF-16 code unit index of 12485 the byte at {idx} in {string} (after converting it to UTF-16). 12486 12487 When {charidx} is present and TRUE, {idx} is used as the 12488 character index in the String {string} instead of as the byte 12489 index. 12490 An {idx} in the middle of a UTF-8 sequence is rounded 12491 downwards to the beginning of that sequence. 12492 12493 Returns -1 if the arguments are invalid or if there are less 12494 than {idx} bytes in {string}. If there are exactly {idx} 12495 bytes, the length of the string in UTF-16 code units is 12496 returned. 12497 12498 See |byteidx()| and |byteidxcomp()| for getting the byte index 12499 from the UTF-16 index and |charidx()| for getting the 12500 character index from the UTF-16 index. 12501 Refer to |string-offset-encoding| for more information. 12502 Examples: >vim 12503 echo utf16idx('a😊😊', 3) " returns 2 12504 echo utf16idx('a😊😊', 7) " returns 4 12505 echo utf16idx('a😊😊', 1, 0, 1) " returns 2 12506 echo utf16idx('a😊😊', 2, 0, 1) " returns 4 12507 echo utf16idx('aą́c', 6) " returns 2 12508 echo utf16idx('aą́c', 6, 1) " returns 4 12509 echo utf16idx('a😊😊', 9) " returns -1 12510< 12511 12512 Attributes: ~ 12513 |api-fast| 12514 12515 Parameters: ~ 12516 • {string} (`string`) 12517 • {idx} (`integer`) 12518 • {countcc} (`boolean?`) 12519 • {charidx} (`boolean?`) 12520 12521 Return: ~ 12522 (`integer`) 12523 12524values({dict}) *values()* 12525 Lua: Prefer |vim.tbl_values()|. 12526 12527 Return a |List| with all the values of {dict}. The |List| is 12528 in arbitrary order. Also see |items()| and |keys()|. 12529 Returns zero if {dict} is not a |Dict|. 12530 12531 Parameters: ~ 12532 • {dict} (`any`) 12533 12534 Return: ~ 12535 (`any`) 12536 12537virtcol({expr} [, {list} [, {winid}]]) *virtcol()* 12538 Returns the virtual (screen) column of the file position 12539 given with {expr}. That is, the total number of screen cells 12540 occupied by the part of the line until the end of the 12541 character at that position. When there is a <Tab> at the 12542 position, the returned Number will be the column at the end of 12543 the <Tab>. For example, for a <Tab> in column 1, with 'ts' 12544 set to 8, it returns 8. |conceal| is ignored. 12545 For the byte position use |col()|. 12546 12547 For the use of {expr} see |getpos()| and |col()|. 12548 When {expr} is "$", it means the end of the cursor line, so 12549 the result is the number of cells in the cursor line plus one. 12550 12551 When 'virtualedit' is used {expr} can be [lnum, col, off], 12552 where "off" is the offset in screen columns from the start of 12553 the character. E.g., a position within a <Tab> or after the 12554 last character. When "off" is omitted zero is used. When 12555 Virtual editing is active in the current mode, a position 12556 beyond the end of the line can be returned. Also see 12557 'virtualedit' 12558 12559 If {list} is present and non-zero then virtcol() returns a 12560 List with the first and last screen position occupied by the 12561 character. 12562 12563 With the optional {winid} argument the values are obtained for 12564 that window instead of the current window. 12565 12566 Note that only marks in the current file can be used. 12567 Examples: >vim 12568 " With text "foo^Lbar" and cursor on the "^L": 12569 12570 echo virtcol(".") " returns 5 12571 echo virtcol(".", 1) " returns [4, 5] 12572 echo virtcol("$") " returns 9 12573 12574 " With text " there", with 't at 'h': 12575 12576 echo virtcol("'t") " returns 6 12577< 12578 The first column is 1. 0 or [0, 0] is returned for an error. 12579 12580 A more advanced example that echoes the maximum length of 12581 all lines: >vim 12582 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) 12583< 12584 12585 Parameters: ~ 12586 • {expr} (`string|any[]`) 12587 • {list} (`boolean?`) 12588 • {winid} (`integer?`) 12589 12590 Return: ~ 12591 (`integer|[integer, integer]`) 12592 12593virtcol2col({winid}, {lnum}, {col}) *virtcol2col()* 12594 Converts a virtual column to a byte index. Returns the byte 12595 index of the character in window {winid} at buffer line 12596 {lnum} and virtual column {col}. 12597 12598 If buffer line {lnum} is an empty line, 0 is returned. 12599 12600 If {col} is greater than the last virtual column in line 12601 {lnum}, then the byte index of the character at the last 12602 virtual column is returned. 12603 12604 For a multi-byte character, the column number of the first 12605 byte in the character is returned. 12606 12607 {winid} is a |window-number| or |window-ID|. If zero, the 12608 current window is used. 12609 12610 Returns -1 if the window {winid} doesn't exist or the buffer 12611 line {lnum} or virtual column {col} is invalid. 12612 12613 See also |screenpos()|, |virtcol()| and |col()|. 12614 12615 Parameters: ~ 12616 • {winid} (`integer`) 12617 • {lnum} (`integer`) 12618 • {col} (`integer`) 12619 12620 Return: ~ 12621 (`integer`) 12622 12623visualmode([{expr}]) *visualmode()* 12624 Returns a String describing the last Visual mode used in the 12625 current buffer. Initially it returns an empty string, but 12626 once Visual mode has been used, it returns "v", 12627 "V", or "<CTRL-V>" (a single CTRL-V character) for 12628 character-wise, line-wise, or block-wise Visual mode 12629 respectively. 12630 Example: >vim 12631 exe "normal " .. visualmode() 12632< This enters the same Visual mode as before. It is also useful 12633 in scripts if you wish to act differently depending on the 12634 Visual mode that was used. 12635 If Visual mode is active, use |mode()| to get the Visual mode 12636 (e.g., in a |:vmap|). 12637 If {expr} is supplied and it evaluates to a non-zero Number or 12638 a non-empty String, then the Visual mode will be cleared and 12639 the old value is returned. See |non-zero-arg|. 12640 12641 Parameters: ~ 12642 • {expr} (`boolean?`) 12643 12644 Return: ~ 12645 (`string`) 12646 12647wait({timeout}, {condition} [, {interval}]) *wait()* 12648 Lua: Prefer |vim.wait()|. 12649 12650 Waits until {condition} evaluates to |TRUE|, where {condition} 12651 is a |Funcref| or |string| containing an expression. 12652 12653 {timeout} is the maximum waiting time in milliseconds, -1 12654 means forever. 12655 12656 Condition is evaluated on user events, internal events, and 12657 every {interval} milliseconds (default: 200). 12658 12659 Returns a status integer: 12660 0 if the condition was satisfied before timeout 12661 -1 if the timeout was exceeded 12662 -2 if the function was interrupted (by |CTRL-C|) 12663 -3 if an error occurred 12664 12665 Parameters: ~ 12666 • {timeout} (`integer`) 12667 • {condition} (`any`) 12668 • {interval} (`number?`) 12669 12670 Return: ~ 12671 (`any`) 12672 12673wildmenumode() *wildmenumode()* 12674 Returns |TRUE| when the wildmenu is active and |FALSE| 12675 otherwise. See 'wildmenu' and 'wildmode'. 12676 This can be used in mappings to handle the 'wildcharm' option 12677 gracefully. (Makes only sense with |mapmode-c| mappings). 12678 12679 For example to make <c-j> work like <down> in wildmode, use: >vim 12680 cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>" 12681< 12682 (Note: this needs the 'wildcharm' option set appropriately). 12683 12684 Return: ~ 12685 (`any`) 12686 12687wildtrigger() *wildtrigger()* 12688 Start wildcard expansion in the command-line, using the 12689 behavior defined by the 'wildmode' and 'wildoptions' settings. 12690 12691 This function also enables completion in search patterns such 12692 as |/|, |?|, |:s|, |:g|, |:v| and |:vimgrep|. 12693 12694 Unlike pressing 'wildchar' manually, this function does not 12695 produce a beep when no matches are found and generally 12696 operates more quietly. This makes it suitable for triggering 12697 completion automatically. 12698 12699 Note: After navigating command-line history, the first call to 12700 wildtrigger() is a no-op; a second call is needed to start 12701 expansion. This is to support history navigation in 12702 command-line autocompletion. 12703 12704 See |cmdline-autocompletion|. 12705 12706 Return value is always 0. 12707 12708 Return: ~ 12709 (`number`) 12710 12711win_execute({id}, {command} [, {silent}]) *win_execute()* 12712 Lua: Prefer |nvim_win_call()|. 12713 12714 Like `execute()` but in the context of window {id}. 12715 The window will temporarily be made the current window, 12716 without triggering autocommands or changing directory. When 12717 executing {command} autocommands will be triggered, this may 12718 have unexpected side effects. Use `:noautocmd` if needed. 12719 Example: >vim 12720 call win_execute(winid, 'syntax enable') 12721< Doing the same with `setwinvar()` would not trigger 12722 autocommands and not actually show syntax highlighting. 12723 12724 When window {id} does not exist then no error is given and 12725 an empty string is returned. 12726 12727 Parameters: ~ 12728 • {id} (`integer`) 12729 • {command} (`string`) 12730 • {silent} (`boolean?`) 12731 12732 Return: ~ 12733 (`any`) 12734 12735win_findbuf({bufnr}) *win_findbuf()* 12736 Lua: Prefer |nvim_list_wins()| with |nvim_win_get_buf()|. 12737 12738 Returns a |List| with |window-ID|s for windows that contain 12739 buffer {bufnr}. When there is none the list is empty. 12740 12741 Parameters: ~ 12742 • {bufnr} (`integer`) 12743 12744 Return: ~ 12745 (`integer[]`) 12746 12747win_getid([{win} [, {tab}]]) *win_getid()* 12748 Lua: Prefer |nvim_get_current_win()| when omitted, or 12749 |nvim_tabpage_list_wins()| with |nvim_win_get_number()| after 12750 resolving {tab}; invalid windows return 0 in Vimscript. 12751 12752 Get the |window-ID| for the specified window. 12753 When {win} is missing use the current window. 12754 With {win} this is the |window-number|. 12755 Without {tab} use the current tab, otherwise the 12756 |tabpage-number| given by {tab}. 12757 Return zero if the window cannot be found. 12758 12759 Parameters: ~ 12760 • {win} (`integer?`) 12761 • {tab} (`integer?`) 12762 12763 Return: ~ 12764 (`integer`) 12765 12766win_gettype([{nr}]) *win_gettype()* 12767 Gets the type of the given window, or current window if {nr} 12768 is omitted: 12769 - (empty) Normal window 12770 - "autocmd" Internal "context-switch" window. 12771 - "command" Command-line window |cmdwin| 12772 - "loclist" |location-list-window| 12773 - "popup" Floating window |api-floatwin| 12774 - "preview" Preview window |preview-window| 12775 - "quickfix" |quickfix-window| 12776 - "unknown" Window {nr} not found 12777 12778 See also the 'buftype' option. 12779 12780 Parameters: ~ 12781 • {nr} (`integer?`) 12782 12783 Return: ~ 12784 (`'autocmd'|'command'|''|'loclist'|'popup'|'preview'|'quickfix'|'unknown'`) 12785 12786win_gotoid({expr}) *win_gotoid()* 12787 Lua: Prefer |nvim_set_current_win()|; invalid IDs error 12788 instead of returning FALSE. 12789 12790 Go to |window-ID| {expr}. May change the current tabpage. 12791 Return TRUE if successful, FALSE if the window cannot be 12792 found. 12793 12794 Parameters: ~ 12795 • {expr} (`integer`) 12796 12797 Return: ~ 12798 (`0|1`) 12799 12800win_id2tabwin({expr}) *win_id2tabwin()* 12801 Lua: Prefer |nvim_win_get_tabpage()| and 12802 |nvim_win_get_number()| for valid windows; invalid IDs error 12803 instead of returning `[0, 0]`. 12804 12805 Return [tabnr, winnr] for window with |window-ID| {expr}, where 12806 tabnr is the |tabpage-number| and winnr is the |window-number|. 12807 Return [0, 0] if the window cannot be found. 12808 12809 Parameters: ~ 12810 • {expr} (`integer`) 12811 12812 Return: ~ 12813 (`any`) 12814 12815win_id2win({expr}) *win_id2win()* 12816 Lua: Prefer |nvim_win_get_number()| for valid windows; windows 12817 outside the current tabpage and invalid IDs differ. 12818 12819 Return the |window-number| of for the given |window-ID| {expr}. 12820 Return 0 if the window cannot be found in the current tabpage. 12821 12822 Parameters: ~ 12823 • {expr} (`integer`) 12824 12825 Return: ~ 12826 (`integer`) 12827 12828win_move_separator({nr}, {offset}) *win_move_separator()* 12829 Move window {nr}'s vertical separator (i.e., the right border) 12830 by {offset} columns, as if being dragged by the mouse. {nr} 12831 is a |window-number| or |window-ID|. A positive {offset} 12832 moves right and a negative {offset} moves left. Moving a 12833 window's vertical separator will change the width of the 12834 window and the width of other windows adjacent to the vertical 12835 separator. The magnitude of movement may be smaller than 12836 specified (e.g., as a consequence of maintaining 12837 'winminwidth'). Returns TRUE if the window can be found and 12838 FALSE otherwise. 12839 This will fail for the rightmost window and a full-width 12840 window, since it has no separator on the right. 12841 Only works for the current tabpage. *E1308* 12842 12843 Parameters: ~ 12844 • {nr} (`integer`) 12845 • {offset} (`integer`) 12846 12847 Return: ~ 12848 (`any`) 12849 12850win_move_statusline({nr}, {offset}) *win_move_statusline()* 12851 Move window {nr}'s status line (i.e., the bottom border) by 12852 {offset} rows, as if being dragged by the mouse. {nr} is a 12853 |window-number| or |window-ID|. A positive {offset} moves 12854 down and a negative {offset} moves up. Moving a window's 12855 status line will change the height of the window and the 12856 height of other windows adjacent to the status line. The 12857 magnitude of movement may be smaller than specified (e.g., as 12858 a consequence of maintaining 'winminheight'). Returns TRUE if 12859 the window can be found and FALSE otherwise. 12860 Only works for the current tabpage. 12861 12862 Parameters: ~ 12863 • {nr} (`integer`) 12864 • {offset} (`integer`) 12865 12866 Return: ~ 12867 (`any`) 12868 12869win_screenpos({nr}) *win_screenpos()* 12870 Lua: Prefer |nvim_win_get_position()| and add 1 to row and 12871 col; invalid-window semantics differ. 12872 12873 Return the screen position of window {nr} as a list with two 12874 numbers: [row, col]. The first window always has position 12875 [1, 1], unless there is a tabline, then it is [2, 1]. 12876 {nr} is a |window-number| or |window-ID|. Use zero for the 12877 current window. 12878 Returns [0, 0] if the window cannot be found. 12879 12880 Parameters: ~ 12881 • {nr} (`integer`) 12882 12883 Return: ~ 12884 (`any`) 12885 12886win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* 12887 Temporarily switch to window {target}, then move window {nr} 12888 to a new split adjacent to {target}. 12889 Unlike commands such as |:split|, no new windows are created 12890 (the |window-ID| of window {nr} is unchanged after the move). 12891 12892 Both {nr} and {target} are a |window-number| or |window-ID|. 12893 Both must be in the current tabpage. 12894 12895 Returns zero for success, non-zero for failure. 12896 12897 {options} is a |Dictionary| with the following optional entries: 12898 "vertical" When TRUE, the split is created vertically, 12899 like with |:vsplit|. 12900 "rightbelow" When TRUE, the split is made below or to the 12901 right (if vertical). When FALSE, it is done 12902 above or to the left (if vertical). When not 12903 present, the values of 'splitbelow' and 12904 'splitright' are used. 12905 12906 Parameters: ~ 12907 • {nr} (`integer`) 12908 • {target} (`integer`) 12909 • {options} (`table?`) 12910 12911 Return: ~ 12912 (`any`) 12913 12914winbufnr({nr}) *winbufnr()* 12915 Lua: Prefer |nvim_win_get_buf()|. 12916 12917 Returns the buffer number associated with window {nr} 12918 (|window-number| or |window-ID|). 12919 When {nr} is zero, the number of the buffer in the current 12920 window is returned. 12921 When window {nr} doesn't exist, -1 is returned. 12922 Example: >vim 12923 echo "The file in the current window is " .. bufname(winbufnr(0)) 12924< 12925 12926 Parameters: ~ 12927 • {nr} (`integer`) 12928 12929 Return: ~ 12930 (`integer`) 12931 12932wincol() *wincol()* 12933 Returns the virtual column of the cursor in the window. 12934 This is counting screen cells from the left side of the 12935 window. The leftmost column is one. 12936 12937 Return: ~ 12938 (`integer`) 12939 12940windowsversion() *windowsversion()* 12941 Returns the Windows OS version as a String. E.g, Windows 10 12942 is "10.0", Windows 8 is "6.2", Windows XP is "5.1". For 12943 non-MS-Windows systems the result is an empty string. 12944 12945 Lua: see |uv.os_uname()|. 12946 12947 Attributes: ~ 12948 |api-fast| 12949 12950 Return: ~ 12951 (`string`) 12952 12953winheight({nr}) *winheight()* 12954 Gets the height of |window-ID| {nr} (zero for "current 12955 window"), excluding any 'winbar' and 'statusline'. Returns -1 12956 if window {nr} doesn't exist. An existing window always has 12957 a height of zero or more. 12958 12959 Examples: >vim 12960 echo "Current window has " .. winheight(0) .. " lines." 12961< 12962 12963 Parameters: ~ 12964 • {nr} (`integer`) 12965 12966 Return: ~ 12967 (`integer`) 12968 12969winlayout([{tabnr}]) *winlayout()* 12970 Returns the layout of windows in a tabpage as a nested List. 12971 12972 Without {tabnr} use the current tabpage, otherwise the tabpage 12973 with number {tabnr}. If the tabpage {tabnr} is not found, 12974 returns an empty list. 12975 12976 For a leaf window, it returns: > 12977 ["leaf", {winid}] 12978< 12979 For horizontally split windows, which form a column, it 12980 returns: > 12981 ["col", [{nested list of windows}]] 12982< For vertically split windows, which form a row, it returns: > 12983 ["row", [{nested list of windows}]] 12984< 12985 Example: >vim 12986 " Only one window in the tabpage 12987 echo winlayout() 12988< > 12989 ['leaf', 1000] 12990< >vim 12991 " Two horizontally split windows 12992 echo winlayout() 12993< > 12994 ['col', [['leaf', 1000], ['leaf', 1001]]] 12995< >vim 12996 " The second tabpage, with three horizontally split 12997 " windows, with two vertically split windows in the 12998 " middle window 12999 echo winlayout(2) 13000< > 13001 ['col', [['leaf', 1002], ['row', [['leaf', 1003], 13002 ['leaf', 1001]]], ['leaf', 1000]]] 13003< 13004 13005 Parameters: ~ 13006 • {tabnr} (`integer?`) 13007 13008 Return: ~ 13009 (`vim.fn.winlayout.ret`) 13010 13011winline() *winline()* 13012 Returns the screen line of the cursor in the window. This is 13013 counting screen lines from the top of the window. The first 13014 line is one. 13015 If the cursor was moved the view on the file will be updated 13016 first, this may cause a scroll. 13017 13018 Return: ~ 13019 (`integer`) 13020 13021winnr([{arg}]) *winnr()* 13022 Lua: Prefer |nvim_win_get_number()| with 13023 |nvim_get_current_win()| for the current window, or 13024 |nvim_tabpage_list_wins()| with |nvim_get_current_tabpage()| 13025 for "$"; "#", motion args, and hidden windows differ. 13026 13027 Returns the number of the current window. The top window has 13028 number 1. Returns zero for a hidden or non |focusable| 13029 window, unless it is the current window. 13030 13031 The optional argument {arg} supports the following values: 13032 $ the number of the last window (the window 13033 count). 13034 # the number of the last accessed window (where 13035 |CTRL-W_p| goes to). If there is no previous 13036 window or it is in another tabpage, 0 is 13037 returned. May refer to the current window in 13038 some cases (e.g. when evaluating 'statusline' 13039 expressions). 13040 {N}j the number of the Nth window below the 13041 current window (where |CTRL-W_j| goes to). 13042 {N}k the number of the Nth window above the current 13043 window (where |CTRL-W_k| goes to). 13044 {N}h the number of the Nth window left of the 13045 current window (where |CTRL-W_h| goes to). 13046 {N}l the number of the Nth window right of the 13047 current window (where |CTRL-W_l| goes to). 13048 The number can be used with |CTRL-W_w| and ":wincmd w" 13049 |:wincmd|. 13050 When {arg} is invalid an error is given and zero is returned. 13051 Also see |tabpagewinnr()| and |win_getid()|. 13052 Examples: >vim 13053 let window_count = winnr('$') 13054 let prev_window = winnr('#') 13055 let wnum = winnr('3k') 13056< 13057 13058 Parameters: ~ 13059 • {arg} (`string|integer?`) 13060 13061 Return: ~ 13062 (`integer`) 13063 13064winrestcmd() *winrestcmd()* 13065 Returns a sequence of |:resize| commands that should restore 13066 the current window sizes. Only works properly when no windows 13067 are opened or closed and the current window and tabpage is 13068 unchanged. 13069 Example: >vim 13070 let cmd = winrestcmd() 13071 call MessWithWindowSizes() 13072 exe cmd 13073< 13074 13075 Return: ~ 13076 (`string`) 13077 13078winrestview({dict}) *winrestview()* 13079 Uses the |Dictionary| returned by |winsaveview()| to restore 13080 the view of the current window. 13081 Note: The {dict} does not have to contain all values, that are 13082 returned by |winsaveview()|. If values are missing, those 13083 settings won't be restored. So you can use: >vim 13084 call winrestview({'curswant': 4}) 13085< 13086 This will only set the curswant value (the column the cursor 13087 wants to move on vertical movements) of the cursor to column 5 13088 (yes, that is 5), while all other settings will remain the 13089 same. This is useful, if you set the cursor position 13090 manually. 13091 13092 If you have changed the values the result is unpredictable. 13093 If the window size changed the result won't be the same. 13094 13095 Parameters: ~ 13096 • {dict} (`vim.fn.winrestview.dict`) 13097 13098 Return: ~ 13099 (`any`) 13100 13101winsaveview() *winsaveview()* 13102 Returns a |Dictionary| that contains information to restore 13103 the view of the current window. Use |winrestview()| to 13104 restore the view. 13105 This is useful if you have a mapping that jumps around in the 13106 buffer and you want to go back to the original view. 13107 This does not save fold information. Use the 'foldenable' 13108 option to temporarily switch off folding, so that folds are 13109 not opened when moving around. This may have side effects. 13110 The return value includes: 13111 lnum cursor line number 13112 col cursor column (Note: the first column 13113 zero, as opposed to what |getcurpos()| 13114 returns) 13115 coladd cursor column offset for 'virtualedit' 13116 curswant column for vertical movement (Note: 13117 the first column is zero, as opposed 13118 to what |getcurpos()| returns). After 13119 |$| command it will be a very large 13120 number equal to |v:maxcol|. 13121 topline first line in the window 13122 topfill filler lines, only in diff mode 13123 leftcol first column displayed; only used when 13124 'wrap' is off 13125 skipcol columns skipped 13126 Note that no option values are saved. 13127 13128 Return: ~ 13129 (`vim.fn.winsaveview.ret`) 13130 13131winwidth({nr}) *winwidth()* 13132 Gets the width of |window-ID| {nr} (zero for "current 13133 window"), including columns (|sign-column|, 'statuscolumn', 13134 etc.). Returns -1 if window {nr} doesn't exist. An existing 13135 window always has a width of zero or more. 13136 13137 Example: >vim 13138 echo "Current window has " .. winwidth(0) .. " columns." 13139 if winwidth(0) <= 50 13140 50 wincmd | 13141 endif 13142< 13143 To get the buffer "viewport", use |getwininfo()|: >vim 13144 :echo getwininfo(win_getid())[0].width - getwininfo(win_getid())[0].textoff 13145< 13146 To get the Nvim screen size, see the 'columns' option. 13147 13148 Parameters: ~ 13149 • {nr} (`integer`) 13150 13151 Return: ~ 13152 (`integer`) 13153 13154wordcount() *wordcount()* 13155 Returns a dictionary of byte/chars/word statistics for the 13156 current buffer. This is the same info provided by |g_CTRL-G|. 13157 The return value includes: 13158 bytes Number of bytes in the buffer 13159 chars Number of chars in the buffer 13160 words Number of words in the buffer 13161 cursor_bytes Number of bytes before cursor position 13162 (not in Visual mode) 13163 cursor_chars Number of chars before cursor position 13164 (not in Visual mode) 13165 cursor_words Number of words before cursor position 13166 (not in Visual mode) 13167 visual_bytes Number of bytes visually selected 13168 (only in Visual mode) 13169 visual_chars Number of chars visually selected 13170 (only in Visual mode) 13171 visual_words Number of words visually selected 13172 (only in Visual mode) 13173 13174 Return: ~ 13175 (`any`) 13176 13177writefile({data}, {fname} [, {flags}]) *writefile()* 13178 Writes {data} to file {fname}. 13179 13180 - When {data} is a |Blob| its bytes are written unmodified 13181 (even if binary mode "b" is not specified). 13182 - When {data} is a Lua string, it is treated as a blob. 13183 - When {data} is a |List|, each list item is treated as a text 13184 line (terminated with a newline). Each list item must be 13185 a String or Number. 13186 - Any NL (newline) chars in the line are treated as a NUL 13187 character. (This is a workaround to allow Vimscript to 13188 write binary data, and is irrelevant for Lua, which should 13189 just pass a string instead.) 13190 13191 {flags} must be a String. These characters are recognized: 13192 13193 'b' Binary mode is used: There will not be a NL after the 13194 last list item. An empty item at the end does cause the 13195 last line in the file to end in a NL. 13196 13197 'a' Append mode is used, lines are appended to the file: >vim 13198 call writefile(["foo"], "event.log", "a") 13199 call writefile(["bar"], "event.log", "a") 13200< 13201 'D' Delete the file when the current function ends. This 13202 works like: >vim 13203 defer delete({fname}) 13204< Fails when not in a function. Also see |:defer|. 13205 13206 's' fsync() is called after writing the file. This flushes 13207 the file to disk, if possible. This takes more time but 13208 avoids losing the file if the system crashes. 13209 13210 'S' fsync() is not called, even when 'fsync' is set. 13211 13212 When {flags} does not contain "S" or "s" then fsync() is 13213 called if the 'fsync' option is set. 13214 13215 An existing file is overwritten, if possible. 13216 13217 When the write fails -1 is returned, otherwise 0. There is an 13218 error message if the file can't be created or when writing 13219 fails. 13220 13221 Also see |readfile()|. 13222 To copy a file byte for byte: >vim 13223 let fl = readfile("foo", "b") 13224 call writefile(fl, "foocopy", "b") 13225< 13226 13227 Parameters: ~ 13228 • {data} (`any`) 13229 • {fname} (`string`) 13230 • {flags} (`string?`) 13231 13232 Return: ~ 13233 (`any`) 13234 13235xor({expr}, {expr}) *xor()* 13236 Lua: Prefer |bit.bxor()|. 13237 13238 Bitwise XOR on the two arguments. The arguments are converted 13239 to a number. A List, Dict or Float argument causes an error. 13240 Also see `and()` and `or()`. 13241 Example: >vim 13242 let bits = xor(bits, 0x80) 13243< 13244 13245 Parameters: ~ 13246 • {expr} (`integer`) 13247 • {expr1} (`integer`) 13248 13249 Return: ~ 13250 (`integer`) 13251 13252============================================================================== 132532. Matching a pattern in a String *string-match* 13254 13255This is common between several functions. A regexp pattern as explained at 13256|pattern| is normally used to find a match in the buffer lines. When a 13257pattern is used to find a match in a String, almost everything works in the 13258same way. The difference is that a String is handled like it is one line. 13259When it contains a "\n" character, this is not seen as a line break for the 13260pattern. It can be matched with a "\n" in the pattern, or with ".". Example: 13261>vim 13262 let a = "aaaa\nxxxx" 13263 echo matchstr(a, "..\n..") 13264 " aa 13265 " xx 13266 echo matchstr(a, "a.x") 13267 " a 13268 " x 13269 13270Don't forget that "^" will only match at the first character of the String and 13271"$" at the last character of the string. They don't match after or before a 13272"\n". 13273 13274 vim:tw=78:ts=8:noet:ft=help:norl: