robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1--- @meta _ 2-- 3-- DO NOT EDIT. GENERATED BY: src/gen/gen_eval_files.lua 4-- 5error ( 'Cannot require a meta file' ) 6 7--- Lua: Prefer |math.abs()|. 8--- 9--- Return the absolute value of {expr}. When {expr} evaluates to 10--- a |Float| abs() returns a |Float|. When {expr} can be 11--- converted to a |Number| abs() returns a |Number|. Otherwise 12--- abs() gives an error message and returns -1. 13--- Examples: >vim 14--- echo abs(1.456) 15--- < 1.456 >vim 16--- echo abs(-5.456) 17--- < 5.456 >vim 18--- echo abs(-4) 19--- < 4 20--- 21--- @param expr number 22--- @return number 23function vim . fn . abs ( expr ) end 24 25--- Lua: Prefer |math.acos()|. 26--- 27--- Return the arc cosine of {expr} measured in radians, as a 28--- |Float| in the range of [0, pi]. 29--- {expr} must evaluate to a |Float| or a |Number| in the range 30--- [-1, 1]. 31--- Returns NaN if {expr} is outside the range [-1, 1]. Returns 32--- 0.0 if {expr} is not a |Float| or a |Number|. 33--- Examples: >vim 34--- echo acos(0) 35--- < 1.570796 >vim 36--- echo acos(-0.5) 37--- < 2.094395 38--- 39--- @param expr number 40--- @return number 41function vim . fn . acos ( expr ) end 42 43--- Lua: Prefer |table.insert()| for lists and `..` for blobs. 44--- 45--- Append the item {expr} to |List| or |Blob| {object}. Returns 46--- the resulting |List| or |Blob|. Examples: >vim 47--- let alist = add([1, 2, 3], item) 48--- call add(mylist, "woodstock") 49--- <Note that when {expr} is a |List| it is appended as a single 50--- item. Use |extend()| to concatenate |Lists|. 51--- When {object} is a |Blob| then {expr} must be a number. 52--- Use |insert()| to add an item at another position. 53--- Returns 1 if {object} is not a |List| or a |Blob|. 54--- 55--- @param object any 56--- @param expr any 57--- @return any # Resulting |List| or |Blob|, or 1 if {object} is not a |List| or a |Blob|. 58function vim . fn . add ( object , expr ) end 59 60--- Lua: Prefer |bit.band()|. 61--- 62--- Bitwise AND on the two arguments. The arguments are converted 63--- to a number. A List, Dict or Float argument causes an error. 64--- Also see |or()| and |xor()|. 65--- Example: >vim 66--- let flag = and(bits, 0x80) 67--- < 68--- 69--- @param expr number 70--- @param expr1 number 71--- @return integer 72vim . fn [ 'and' ] =function ( expr , expr1 ) end 73 74--- Returns Dictionary of |api-metadata|. 75--- 76--- View it in a nice human-readable format: >vim 77--- lua vim.print(vim.fn.api_info()) 78--- < 79--- 80--- @return table 81function vim . fn . api_info () end 82 83--- Lua: Prefer |nvim_buf_set_lines()|. 84--- 85--- When {text} is a |List|: Append each item of the |List| as a 86--- text line below line {lnum} in the current buffer. 87--- Otherwise append {text} as one text line below line {lnum} in 88--- the current buffer. 89--- Any type of item is accepted and converted to a String. 90--- {lnum} can be zero to insert a line before the first one. 91--- {lnum} is used like with |getline()|. 92--- Returns 1 for failure ({lnum} out of range or out of memory), 93--- 0 for success. When {text} is an empty list zero is returned, 94--- no matter the value of {lnum}. Example: >vim 95--- let failed = append(line('$'), "# THE END") 96--- let failed = append(0, ["Chapter 1", "the beginning"]) 97--- < 98--- 99--- @param lnum integer|string 100--- @param text string|string[] 101--- @return 0|1 102function vim . fn . append ( lnum , text ) end 103 104--- Lua: Prefer |nvim_buf_set_lines()|. 105--- 106--- Like |append()| but append the text in buffer {buf}. 107--- 108--- This function works only for loaded buffers. First call 109--- |bufload()| if needed. 110--- 111--- For the use of {buf}, see |bufname()|. 112--- 113--- {lnum} is the line number to append below. Note that using 114--- |line()| would use the current buffer, not the one appending 115--- to. Use "$" to append at the end of the buffer. Other string 116--- values are not supported. 117--- 118--- On success 0 is returned, on failure 1 is returned. 119--- 120--- If {buf} is not a valid buffer or {lnum} is not valid, an 121--- error message is given. Example: >vim 122--- let failed = appendbufline(13, 0, "# THE START") 123--- <However, when {text} is an empty list then no error is given 124--- for an invalid {lnum}, since {lnum} isn't actually used. 125--- 126--- @param buf integer|string 127--- @param lnum integer 128--- @param text string 129--- @return 0|1 130function vim . fn . appendbufline ( buf , lnum , text ) end 131 132--- The result is the number of files in the argument list. See 133--- |arglist|. 134--- If {winid} is not supplied, the argument list of the current 135--- window is used. 136--- If {winid} is -1, the global argument list is used. 137--- Otherwise {winid} (a |window-number| or |window-ID|) specifies 138--- the window of which the argument list is used. 139--- Returns -1 if the {winid} argument is invalid. 140--- 141--- @param winid? integer 142--- @return integer 143function vim . fn . argc ( winid ) end 144 145--- The result is the current index in the argument list. 0 is 146--- the first file. |argc()| - 1 is the last one. See |arglist|. 147--- 148--- @return integer 149function vim . fn . argidx () end 150 151--- Return the argument list ID. This is a number which 152--- identifies the argument list being used. Zero is used for the 153--- global argument list. See |arglist|. 154--- Returns -1 if the arguments are invalid. 155--- 156--- Without arguments use the current window. 157--- With {winnr} only use this window in the current tabpage. 158--- With {winnr} and {tabnr} use the window in the specified tab 159--- page. 160--- {winnr} is a |window-number| or |window-ID|. 161--- 162--- @param winnr? integer 163--- @param tabnr? integer 164--- @return integer 165function vim . fn . arglistid ( winnr , tabnr ) end 166 167--- The result is the {nr}th file in the argument list. See 168--- |arglist|. "argv(0)" is the first one. Example: >vim 169--- let i = 0 170--- while i < argc() 171--- let f = escape(fnameescape(argv(i)), '.') 172--- exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>' 173--- let i = i + 1 174--- endwhile 175--- <Without the {nr} argument, or when {nr} is -1, a |List| with 176--- the whole |arglist| is returned. 177--- 178--- The {winid} argument is a |window-ID|, see |argc()|. 179--- For the Vim command line arguments see |v:argv|. 180--- 181--- Returns an empty string if {nr}th argument is not present in 182--- the argument list. Returns an empty List if the {winid} 183--- argument is invalid. 184--- 185--- @param nr? integer 186--- @param winid? integer 187--- @return string|string[] 188function vim . fn . argv ( nr , winid ) end 189 190--- Lua: Prefer |math.asin()|. 191--- 192--- Return the arc sine of {expr} measured in radians, as a |Float| 193--- in the range of [-pi/2, pi/2]. 194--- {expr} must evaluate to a |Float| or a |Number| in the range 195--- [-1, 1]. 196--- Returns NaN if {expr} is outside the range [-1, 1]. Returns 197--- 0.0 if {expr} is not a |Float| or a |Number|. 198--- Examples: >vim 199--- echo asin(0.8) 200--- < 0.927295 >vim 201--- echo asin(-0.5) 202--- < -0.523599 203--- 204--- @param expr any 205--- @return number 206function vim . fn . asin ( expr ) end 207 208--- Run {cmd} and add an error message to |v:errors| if it does 209--- NOT produce a beep or visual bell. 210--- Also see |assert_fails()|, |assert_nobeep()| and 211--- |assert-return|. 212--- 213--- @param cmd string 214--- @return 0|1 215function vim . fn . assert_beeps ( cmd ) end 216 217--- Lua: Prefer |assert()| with |vim.deep_equal()|. 218--- 219--- When {expected} and {actual} are not equal an error message is 220--- added to |v:errors| and 1 is returned. Otherwise zero is 221--- returned. |assert-return| 222--- The error is in the form "Expected {expected} but got 223--- {actual}". When {msg} is present it is prefixed to that, 224--- along with the location of the assert when run from a script. 225--- 226--- There is no automatic conversion, the String "4" is different 227--- from the Number 4. And the number 4 is different from the 228--- Float 4.0. The value of 'ignorecase' is not used here, case 229--- always matters. 230--- Example: >vim 231--- call assert_equal('foo', 'bar', 'baz') 232--- <Will add the following to |v:errors|: > 233--- test.vim line 12: baz: Expected 'foo' but got 'bar' 234--- < 235--- 236--- @param expected any 237--- @param actual any 238--- @param msg? any 239--- @return 0|1 240function vim . fn . assert_equal ( expected , actual , msg ) end 241 242--- When the files {fname_one} and {fname_two} do not contain 243--- exactly the same text an error message is added to |v:errors|. 244--- Also see |assert-return|. 245--- When {fname_one} or {fname_two} does not exist the error will 246--- mention that. 247--- 248--- @param fname_one string 249--- @param fname_two string 250--- @return 0|1 251function vim . fn . assert_equalfile ( fname_one , fname_two ) end 252 253--- When v:exception does not contain the string {error} an error 254--- message is added to |v:errors|. Also see |assert-return|. 255--- This can be used to assert that a command throws an exception. 256--- Using the error number, followed by a colon, avoids problems 257--- with translations: >vim 258--- try 259--- commandthatfails 260--- call assert_false(1, 'command should have failed') 261--- catch 262--- call assert_exception('E492:') 263--- endtry 264--- < 265--- 266--- @param error any 267--- @param msg? any 268--- @return 0|1 269function vim . fn . assert_exception ( error , msg ) end 270 271--- Run {cmd} and add an error message to |v:errors| if it does 272--- NOT produce an error or when {error} is not found in the 273--- error message. Also see |assert-return|. 274--- 275--- When {error} is a string it must be found literally in the 276--- first reported error. Most often this will be the error code, 277--- including the colon, e.g. "E123:". >vim 278--- call assert_fails('bad cmd', 'E987:') 279--- < 280--- When {error} is a |List| with one or two strings, these are 281--- used as patterns. The first pattern is matched against the 282--- first reported error: >vim 283--- call assert_fails('cmd', ['E987:.*expected bool']) 284--- <The second pattern, if present, is matched against the last 285--- reported error. To only match the last error use an empty 286--- string for the first error: >vim 287--- call assert_fails('cmd', ['', 'E987:']) 288--- < 289--- If {msg} is empty then it is not used. Do this to get the 290--- default message when passing the {lnum} argument. 291--- *E1115* 292--- When {lnum} is present and not negative, and the {error} 293--- argument is present and matches, then this is compared with 294--- the line number at which the error was reported. That can be 295--- the line number in a function or in a script. 296--- *E1116* 297--- When {context} is present it is used as a pattern and matched 298--- against the context (script name or function name) where 299--- {lnum} is located in. 300--- 301--- Note that beeping is not considered an error, and some failing 302--- commands only beep. Use |assert_beeps()| for those. 303--- 304--- @param cmd string 305--- @param error? any 306--- @param msg? any 307--- @param lnum? integer 308--- @param context? any 309--- @return 0|1 310function vim . fn . assert_fails ( cmd , error , msg , lnum , context ) end 311 312--- Lua: Prefer |assert()|. 313--- 314--- When {actual} is not false an error message is added to 315--- |v:errors|, like with |assert_equal()|. 316--- The error is in the form "Expected False but got {actual}". 317--- When {msg} is present it is prefixed to that, along with the 318--- location of the assert when run from a script. 319--- Also see |assert-return|. 320--- 321--- A value is false when it is zero. When {actual} is not a 322--- number the assert fails. 323--- 324--- @param actual any 325--- @param msg? any 326--- @return 0|1 327function vim . fn . assert_false ( actual , msg ) end 328 329--- Lua: Prefer |assert()|. 330--- 331--- This asserts number and |Float| values. When {actual} is lower 332--- than {lower} or higher than {upper} an error message is added 333--- to |v:errors|. Also see |assert-return|. 334--- The error is in the form "Expected range {lower} - {upper}, 335--- but got {actual}". When {msg} is present it is prefixed to 336--- that. 337--- 338--- @param lower number 339--- @param upper number 340--- @param actual number 341--- @param msg? string 342--- @return 0|1 343function vim . fn . assert_inrange ( lower , upper , actual , msg ) end 344 345--- When {pattern} does not match {actual} an error message is 346--- added to |v:errors|. Also see |assert-return|. 347--- The error is in the form "Pattern {pattern} does not match 348--- {actual}". When {msg} is present it is prefixed to that, 349--- along with the location of the assert when run from a script. 350--- 351--- {pattern} is used as with |expr-=~|: The matching is always done 352--- like 'magic' was set and 'cpoptions' is empty, no matter what 353--- the actual value of 'magic' or 'cpoptions' is. 354--- 355--- {actual} is used as a string, automatic conversion applies. 356--- Use "^" and "$" to match with the start and end of the text. 357--- Use both to match the whole text. 358--- 359--- Example: >vim 360--- call assert_match('^f.*o$', 'foobar') 361--- <Will result in a string to be added to |v:errors|: > 362--- test.vim line 12: Pattern '^f.*o$' does not match 'foobar' 363--- < 364--- 365--- @param pattern string 366--- @param actual string 367--- @param msg? string 368--- @return 0|1 369function vim . fn . assert_match ( pattern , actual , msg ) end 370 371--- Run {cmd} and add an error message to |v:errors| if it 372--- produces a beep or visual bell. 373--- Also see |assert_beeps()|. 374--- 375--- @param cmd string 376--- @return 0|1 377function vim . fn . assert_nobeep ( cmd ) end 378 379--- The opposite of `assert_equal()`: add an error message to 380--- |v:errors| when {expected} and {actual} are equal. 381--- Also see |assert-return|. 382--- 383--- @param expected any 384--- @param actual any 385--- @param msg? any 386--- @return 0|1 387function vim . fn . assert_notequal ( expected , actual , msg ) end 388 389--- The opposite of `assert_match()`: add an error message to 390--- |v:errors| when {pattern} matches {actual}. 391--- Also see |assert-return|. 392--- 393--- @param pattern string 394--- @param actual string 395--- @param msg? string 396--- @return 0|1 397function vim . fn . assert_notmatch ( pattern , actual , msg ) end 398 399--- Report a test failure directly, using String {msg}. 400--- Always returns one. 401--- 402--- @param msg string 403--- @return 0|1 404function vim . fn . assert_report ( msg ) end 405 406--- Lua: Prefer |assert()|. 407--- 408--- When {actual} is not true an error message is added to 409--- |v:errors|, like with |assert_equal()|. 410--- Also see |assert-return|. 411--- A value is |TRUE| when it is a non-zero number or |v:true|. 412--- When {actual} is not a number or |v:true| the assert fails. 413--- When {msg} is given it is prefixed to the default message, 414--- along with the location of the assert when run from a script. 415--- 416--- @param actual any 417--- @param msg? string 418--- @return 0|1 419function vim . fn . assert_true ( actual , msg ) end 420 421--- Lua: Prefer |math.atan()|. 422--- 423--- Return the principal value of the arc tangent of {expr}, in 424--- the range [-pi/2, +pi/2] radians, as a |Float|. 425--- {expr} must evaluate to a |Float| or a |Number|. 426--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 427--- Examples: >vim 428--- echo atan(100) 429--- < 1.560797 >vim 430--- echo atan(-4.01) 431--- < -1.326405 432--- 433--- @param expr number 434--- @return number 435function vim . fn . atan ( expr ) end 436 437--- Lua: Prefer |math.atan2()|. 438--- 439--- Return the arc tangent of {expr1} / {expr2}, measured in 440--- radians, as a |Float| in the range [-pi, pi]. 441--- {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 442--- Returns 0.0 if {expr1} or {expr2} is not a |Float| or a 443--- |Number|. 444--- Examples: >vim 445--- echo atan2(-1, 1) 446--- < -0.785398 >vim 447--- echo atan2(1, -1) 448--- < 2.356194 449--- 450--- @param expr1 number 451--- @param expr2 number 452--- @return number 453function vim . fn . atan2 ( expr1 , expr2 ) end 454 455--- Return a List containing the number value of each byte in Blob 456--- {blob}. Examples: >vim 457--- blob2list(0z0102.0304) " returns [1, 2, 3, 4] 458--- blob2list(0z) " returns [] 459--- <Returns an empty List on error. |list2blob()| does the 460--- opposite. 461--- 462--- @param blob any 463--- @return any[] 464function vim . fn . blob2list ( blob ) end 465 466--- Put up a file requester. This only works when "has("browse")" 467--- returns |TRUE| (only in some GUI versions). 468--- The input fields are: 469--- {save} when |TRUE|, select file to write 470--- {title} title for the requester 471--- {initdir} directory to start browsing in 472--- {default} default file name 473--- An empty string is returned when the "Cancel" button is hit, 474--- something went wrong, or browsing is not possible. 475--- 476--- @param save any 477--- @param title string 478--- @param initdir string 479--- @param default string 480--- @return 0|1 481function vim . fn . browse ( save , title , initdir , default ) end 482 483--- Put up a directory requester. This only works when 484--- "has("browse")" returns |TRUE| (only in some GUI versions). 485--- On systems where a directory browser is not supported a file 486--- browser is used. In that case: select a file in the directory 487--- to be used. 488--- The input fields are: 489--- {title} title for the requester 490--- {initdir} directory to start browsing in 491--- When the "Cancel" button is hit, something went wrong, or 492--- browsing is not possible, an empty string is returned. 493--- 494--- @param title string 495--- @param initdir string 496--- @return 0|1 497function vim . fn . browsedir ( title , initdir ) end 498 499--- Adds buffer {name} to the |buffer-list| literally: no special 500--- chars or expansion are applied (including "~"). Returns the 501--- new (or existing matching) buffer number, or 0 on error. 502--- 503--- The buffer is not loaded and 'buflisted' is not set. When 504--- {name} is an empty string, a new buffer is always created. 505--- 506--- Example (Lua): >lua 507--- local buf = vim.fn.bufadd(vim.fs.normalize('someName')) 508--- -- Set 'buflisted'; trigger BufReadPre/BufReadPost/FileType. 509--- vim.api.nvim_buf_call(buf, vim.cmd.edit) 510--- < 511--- 512--- @param name string 513--- @return integer 514function vim . fn . bufadd ( name ) end 515 516--- Lua: Prefer |nvim_buf_is_valid()| after resolving {buf} to a bufnr. 517--- 518--- Checks whether a buffer with the name or number {buf} exists. 519--- Returns |TRUE| if the buffer exists, |FALSE| otherwise. 520--- If the {buf} argument is a number, buffer numbers are used. 521--- Number zero is the alternate buffer for the current window. 522--- 523--- If the {buf} argument is a string it must match a buffer name 524--- exactly. The name can be: 525--- - Relative to the current directory. 526--- - A full path. 527--- - The name of a buffer with 'buftype' set to "nofile". 528--- - A URL name. 529--- Unlisted buffers will be found. 530--- Note that help files are listed by their short name in the 531--- output of |:buffers|, but bufexists() requires using their 532--- long name to be able to find them. 533--- bufexists() may report a buffer exists, but to use the name 534--- with a |:buffer| command you may need to use |expand()|. Esp 535--- for MS-Windows 8.3 names in the form "c:\DOCUME~1" 536--- Use "bufexists(0)" to test for the existence of an alternate 537--- file name. 538--- 539--- @param buf any 540--- @return 0|1 541function vim . fn . bufexists ( buf ) end 542 543--- @deprecated 544--- Lua: Prefer |nvim_buf_is_valid()| after resolving {buf} to a bufnr. 545--- 546--- Obsolete name for |bufexists()|. 547--- 548--- @param ... any 549--- @return 0|1 550function vim . fn . buffer_exists ( ... ) end 551 552--- @deprecated 553--- Lua: Prefer |nvim_buf_get_name()| after resolving {buf} to a bufnr. 554--- 555--- Obsolete name for |bufname()|. 556--- 557--- @param ... any 558--- @return string 559function vim . fn . buffer_name ( ... ) end 560 561--- @deprecated 562--- Lua: Prefer |nvim_get_current_buf()| when omitted, or |nvim_create_buf()| with |nvim_buf_set_name()| for creating; name lookup, "$", "%", "#", and {create} semantics differ. 563--- 564--- Obsolete name for |bufnr()|. 565--- 566--- @param ... any 567--- @return integer 568function vim . fn . buffer_number ( ... ) end 569 570--- Lua: Prefer |vim.bo| or |nvim_get_option_value()| after resolving {buf} to a bufnr. 571--- 572--- Checks whether a buffer called {buf} exists and is listed 573--- (has the 'buflisted' option set). Returns |TRUE| if so, 574--- |FALSE| otherwise. 575--- The {buf} argument is used like with |bufexists()|. 576--- 577--- @param buf any 578--- @return 0|1 579function vim . fn . buflisted ( buf ) end 580 581--- Ensure the buffer {buf} is loaded. When the buffer name 582--- refers to an existing file then the file is read. Otherwise 583--- the buffer will be empty. If the buffer was already loaded 584--- then there is no change. If the buffer is not related to a 585--- file then no file is read (e.g., when 'buftype' is "nofile"). 586--- If there is an existing swap file for the file of the buffer, 587--- there will be no dialog, the buffer will be loaded anyway. 588--- The {buf} argument is used like with |bufexists()|. 589--- 590--- @param buf any 591function vim . fn . bufload ( buf ) end 592 593--- Lua: Prefer |nvim_buf_is_loaded()| after resolving {buf} to a bufnr. 594--- 595--- Checks whether a buffer called {buf} exists and is loaded 596--- (shown in a window or hidden). Returns |TRUE| if so, 597--- |FALSE| otherwise. 598--- The {buf} argument is used like with |bufexists()|. 599--- 600--- @param buf any 601--- @return 0|1 602function vim . fn . bufloaded ( buf ) end 603 604--- Lua: Prefer |nvim_buf_get_name()| after resolving {buf} to a bufnr. 605--- 606--- The result is the name of a buffer. Mostly as it is displayed 607--- by the `:ls` command, but not using special names such as 608--- "[No Name]". If the buffer represents a directory, the name 609--- ends with a path separator, unless it was changed by |:file| or 610--- |nvim_buf_set_name()|. 611--- If {buf} is omitted the current buffer is used. 612--- If {buf} is a Number, that buffer number's name is given. 613--- Number zero is the alternate buffer for the current window. 614--- If {buf} is a String, it is used as a |file-pattern| to match 615--- with the buffer names. This is always done like 'magic' is 616--- set and 'cpoptions' is empty. When there is more than one 617--- match an empty string is returned. 618--- "" or "%" can be used for the current buffer, "#" for the 619--- alternate buffer. 620--- A full match is preferred, otherwise a match at the start, end 621--- or middle of the buffer name is accepted. If you only want a 622--- full match then put "^" at the start and "$" at the end of the 623--- pattern. 624--- Listed buffers are found first. If there is a single match 625--- with a listed buffer, that one is returned. Next unlisted 626--- buffers are searched for. 627--- If the {buf} is a String, but you want to use it as a buffer 628--- number, force it to be a Number by adding zero to it: >vim 629--- echo bufname("3" + 0) 630--- <If the buffer doesn't exist, or doesn't have a name, an empty 631--- string is returned. >vim 632--- echo bufname("#") " alternate buffer name 633--- echo bufname(3) " name of buffer 3 634--- echo bufname("%") " name of current buffer 635--- echo bufname("file2") " name of buffer where "file2" matches. 636--- < 637--- 638--- @param buf? integer|string 639--- @return string 640function vim . fn . bufname ( buf ) end 641 642--- Lua: Prefer |nvim_get_current_buf()| when omitted, or |nvim_create_buf()| with |nvim_buf_set_name()| for creating; name lookup, "$", "%", "#", and {create} semantics differ. 643--- 644--- The result is the number of a buffer, as it is displayed by 645--- the `:ls` command. For the use of {buf}, see |bufname()| 646--- above. 647--- If the buffer doesn't exist, -1 is returned. Or, if the 648--- {create} argument is present and TRUE, a new, unlisted, 649--- buffer is created and its number is returned. Example: >vim 650--- let newbuf = bufnr('Scratch001', 1) 651--- <Using an empty name uses the current buffer. To create a new 652--- buffer with an empty name use |bufadd()|. 653--- 654--- bufnr("$") is the last buffer: >vim 655--- let last_buffer = bufnr("$") 656--- <The result is a Number, which is the highest buffer number 657--- of existing buffers. Note that not all buffers with a smaller 658--- number necessarily exist, because ":bwipeout" may have removed 659--- them. Use |bufexists()| to test for the existence of a buffer. 660--- 661--- @param buf? integer|string 662--- @param create? any 663--- @return integer 664function vim . fn . bufnr ( buf , create ) end 665 666--- Lua: Prefer |nvim_tabpage_list_wins()| with |nvim_win_get_buf()| after resolving {buf}; only the current tabpage is checked and no-match semantics differ. 667--- 668--- Returns the |window-ID| of the first window associated with 669--- buffer {buf}. For the use of {buf}, see |bufname()| above. 670--- If buffer {buf} doesn't exist or there is no such window, -1 671--- is returned. Example: >vim 672--- 673--- echo "A window containing buffer 1 is " .. (bufwinid(1)) 674--- < 675--- Only deals with the current tabpage. See |win_findbuf()| for 676--- finding more. 677--- 678--- @param buf any 679--- @return integer 680function vim . fn . bufwinid ( buf ) end 681 682--- Lua: Prefer |nvim_tabpage_list_wins()| with |nvim_win_get_buf()| and |nvim_win_get_number()| after resolving {buf}; only the current tabpage is checked and no-match semantics differ. 683--- 684--- Like |bufwinid()| but returns a |window-number| instead of a 685--- |window-ID|. 686--- If buffer {buf} doesn't exist or there is no such window, -1 687--- is returned. Example: >vim 688--- 689--- echo "A window containing buffer 1 is " .. (bufwinnr(1)) 690--- 691--- <The number can be used with |CTRL-W_w| and ":wincmd w" 692--- |:wincmd|. 693--- 694--- @param buf any 695--- @return integer 696function vim . fn . bufwinnr ( buf ) end 697 698--- Return the line number that contains the character at byte 699--- count {byte} in the current buffer. This includes the 700--- end-of-line character, depending on the 'fileformat' option 701--- for the current buffer. The first character has byte count 702--- one. 703--- Also see |line2byte()|, |go| and |:goto|. 704--- 705--- Returns -1 if the {byte} value is invalid. 706--- 707--- @param byte any 708--- @return integer 709function vim . fn . byte2line ( byte ) end 710 711--- Lua: Prefer |vim.str_byteindex()| for string input with `"utf-32"` or `"utf-16"` and `strict_indexing = false`; composing characters and out-of-range semantics differ. 712--- 713--- Return byte index of the {nr}th character in the String 714--- {expr}. Use zero for the first character, it then returns 715--- zero. 716--- If there are no multibyte characters the returned value is 717--- equal to {nr}. 718--- Composing characters are not counted separately, their byte 719--- length is added to the preceding base character. See 720--- |byteidxcomp()| below for counting composing characters 721--- separately. 722--- When {utf16} is present and TRUE, {nr} is used as the UTF-16 723--- index in the String {expr} instead of as the character index. 724--- The UTF-16 index is the index in the string when it is encoded 725--- with 16-bit words. If the specified UTF-16 index is in the 726--- middle of a character (e.g. in a 4-byte character), then the 727--- byte index of the first byte in the character is returned. 728--- Refer to |string-offset-encoding| for more information. 729--- Example : >vim 730--- echo matchstr(str, ".", byteidx(str, 3)) 731--- <will display the fourth character. Another way to do the 732--- same: >vim 733--- let s = strpart(str, byteidx(str, 3)) 734--- echo strpart(s, 0, byteidx(s, 1)) 735--- <Also see |strgetchar()| and |strcharpart()|. 736--- 737--- If there are less than {nr} characters -1 is returned. 738--- If there are exactly {nr} characters the length of the string 739--- in bytes is returned. 740--- See |charidx()| and |utf16idx()| for getting the character and 741--- UTF-16 index respectively from the byte index. 742--- Examples: >vim 743--- echo byteidx('a😊😊', 2) " returns 5 744--- echo byteidx('a😊😊', 2, 1) " returns 1 745--- echo byteidx('a😊😊', 3, 1) " returns 5 746--- < 747--- 748--- @param expr any 749--- @param nr integer 750--- @param utf16? any 751--- @return integer 752function vim . fn . byteidx ( expr , nr , utf16 ) end 753 754--- Lua: Prefer |vim.str_byteindex()| with `"utf-32"` or `"utf-16"` and `strict_indexing = false`. 755--- 756--- Like |byteidx()|, except that a composing character is counted 757--- as a separate character. Example: >vim 758--- let s = 'e' .. nr2char(0x301) 759--- echo byteidx(s, 1) 760--- echo byteidxcomp(s, 1) 761--- echo byteidxcomp(s, 2) 762--- <The first and third echo result in 3 ('e' plus composing 763--- character is 3 bytes), the second echo results in 1 ('e' is 764--- one byte). 765--- 766--- @param expr any 767--- @param nr integer 768--- @param utf16? any 769--- @return integer 770function vim . fn . byteidxcomp ( expr , nr , utf16 ) end 771 772--- Call function {func} with the items in |List| {arglist} as 773--- arguments. 774--- {func} can either be a |Funcref| or the name of a function. 775--- a:firstline and a:lastline are set to the cursor line. 776--- Returns the return value of the called function. 777--- {dict} is for functions with the "dict" attribute. It will be 778--- used to set the local variable "self". |Dictionary-function| 779--- 780--- @param func any 781--- @param arglist any 782--- @param dict? any 783--- @return any 784function vim . fn . call ( func , arglist , dict ) end 785 786--- Lua: Prefer |math.ceil()|. 787--- 788--- Return the smallest integral value greater than or equal to 789--- {expr} as a |Float| (round up). 790--- {expr} must evaluate to a |Float| or a |Number|. 791--- Examples: >vim 792--- echo ceil(1.456) 793--- < 2.0 >vim 794--- echo ceil(-5.456) 795--- < -5.0 >vim 796--- echo ceil(4.0) 797--- < 4.0 798--- 799--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 800--- 801--- @param expr number 802--- @return number 803function vim . fn . ceil ( expr ) end 804 805--- Close a channel or a specific stream associated with it. 806--- For a job, {stream} can be one of "stdin", "stdout", 807--- "stderr" or "rpc" (closes stdin/stdout for a job started 808--- with `"rpc":v:true`) If {stream} is omitted, all streams 809--- are closed. If the channel is a pty, this will then close the 810--- pty master, sending SIGHUP to the job process. 811--- For a socket, there is only one stream, and {stream} should be 812--- omitted. 813--- 814--- @param id integer 815--- @param stream? string 816--- @return 0|1 817function vim . fn . chanclose ( id , stream ) end 818 819--- Return the number of the most recent change. This is the same 820--- number as what is displayed with |:undolist| and can be used 821--- with the |:undo| command. 822--- When a change was made it is the number of that change. After 823--- redo it is the number of the redone change. After undo it is 824--- one less than the number of the undone change. 825--- Returns 0 if the undo list is empty. 826--- 827--- @return integer 828function vim . fn . changenr () end 829 830--- Lua: Prefer |nvim_chan_send()| for string (binary) data. 831--- 832--- Send data to channel {id}. For a job, it writes it to the 833--- stdin of the process. For the stdio channel |channel-stdio|, 834--- it writes to Nvim's stdout. Returns the number of bytes 835--- written if the write succeeded, 0 otherwise. 836--- See |channel-bytes| for more information. 837--- 838--- {data} may be a string, string convertible, |Blob|, or a list. 839--- 840--- If {data} is a list, the items will be joined by newlines; any 841--- newlines in an item will be sent as NUL; to send a final 842--- newline, include a final empty string. |NL-used-for-Nul| 843--- 844--- Example: >vim 845--- call chansend(id, ["abc", "123\n456", ""]) 846--- <will send "abc<NL>123<NUL>456<NL>". 847--- 848--- chansend() writes raw data, not RPC messages. If the channel 849--- was created with `"rpc":v:true` then the channel expects RPC 850--- messages, use |rpcnotify()| and |rpcrequest()| instead. 851--- 852--- @param id number 853--- @param data string|string[] 854--- @return integer 855function vim . fn . chansend ( id , data ) end 856 857--- Lua: Prefer |string.byte()|: only works with ASCII. 858--- 859--- Return Number value of the first char in {string}. 860--- Examples: >vim 861--- echo char2nr(" ") " returns 32 862--- echo char2nr("ABC") " returns 65 863--- echo char2nr("á") " returns 225 864--- echo char2nr("á"[0]) " returns 195 865--- echo char2nr("\<M-x>") " returns 128 866--- <Non-ASCII characters are always treated as UTF-8 characters. 867--- {utf8} is ignored, it exists only for backwards-compatibility. 868--- A combining character is a separate character. 869--- |nr2char()| does the opposite. 870--- 871--- Returns 0 if {string} is not a |String|. 872--- 873--- @param string string 874--- @param utf8? any 875--- @return 0|1 876function vim . fn . char2nr ( string , utf8 ) end 877 878--- Return the character class of the first character in {string}. 879--- The character class is one of: 880--- 0 blank 881--- 1 punctuation 882--- 2 word character (depends on 'iskeyword') 883--- 3 emoji 884--- other specific Unicode class 885--- The class is used in patterns and word motions. 886--- Returns 0 if {string} is not a |String|. 887--- 888--- @param string string 889--- @return 0|1|2|3|'other' 890function vim . fn . charclass ( string ) end 891 892--- Lua: Prefer |nvim_win_get_cursor()| with |vim.str_utfindex()| for ".", or |nvim_get_current_line()| with |vim.str_utfindex()| for "$"; marks, list input, and window semantics differ. 893--- 894--- Same as |col()| but returns the character index of the column 895--- position given with {expr} instead of the byte position. 896--- 897--- Example: 898--- With the cursor on '세' in line 5 with text "여보세요": >vim 899--- echo charcol('.') " returns 3 900--- echo col('.') " returns 7 901--- < 902--- 903--- @param expr string|any[] 904--- @param winid? integer 905--- @return integer 906function vim . fn . charcol ( expr , winid ) end 907 908--- Lua: Prefer |vim.str_utfindex()| for string input with `"utf-32"` or `"utf-16"` and `strict_indexing = false`; `countcc = false` and out-of-range semantics differ. 909--- 910--- Return the character index of the byte at {idx} in {string}. 911--- The index of the first character is zero. 912--- If there are no multibyte characters the returned value is 913--- equal to {idx}. 914--- 915--- When {countcc} is omitted or |FALSE|, then composing characters 916--- are not counted separately, their byte length is added to the 917--- preceding base character. 918--- When {countcc} is |TRUE|, then composing characters are 919--- counted as separate characters. 920--- 921--- When {utf16} is present and TRUE, {idx} is used as the UTF-16 922--- index in the String {expr} instead of as the byte index. 923--- 924--- Returns -1 if the arguments are invalid or if there are less 925--- than {idx} bytes. If there are exactly {idx} bytes the length 926--- of the string in characters is returned. 927--- 928--- An error is given and -1 is returned if the first argument is 929--- not a string, the second argument is not a number or when the 930--- third argument is present and is not zero or one. 931--- 932--- See |byteidx()| and |byteidxcomp()| for getting the byte index 933--- from the character index and |utf16idx()| for getting the 934--- UTF-16 index from the character index. 935--- Refer to |string-offset-encoding| for more information. 936--- Examples: >vim 937--- echo charidx('áb́ć', 3) " returns 1 938--- echo charidx('áb́ć', 6, 1) " returns 4 939--- echo charidx('áb́ć', 16) " returns -1 940--- echo charidx('a😊😊', 4, 0, 1) " returns 2 941--- < 942--- 943--- @param string string 944--- @param idx integer 945--- @param countcc? boolean 946--- @param utf16? boolean 947--- @return integer 948function vim . fn . charidx ( string , idx , countcc , utf16 ) end 949 950--- Sets the |current-directory| of the given {scope}: 951--- - "buffer" Changes the buffer-local directory. |:bcd| 952--- - "window" Changes the window-local directory. |:lcd| 953--- - "tabpage" Changes the tabpage-local directory. |:tcd| 954--- - "global" Changes the global directory. |:cd| 955--- 956--- If {scope} is not given it is decided as follows: 957--- - If buffer-local directory (|:bcd|) is set, scope is 958--- "buffer". 959--- - If the window-local directory (|:lcd|) is set, scope is 960--- "window". 961--- - If the tabpage-local directory (|:tcd|) is set, scope is 962--- "tabpage". 963--- - Otherwise, scope is "global". 964--- 965--- If successful, returns the previous working directory. 966--- On failure, returns an empty string. 967--- 968--- Example: >vim 969--- let save_dir = chdir(newdir) 970--- if save_dir != "" 971--- " ... do some work 972--- call chdir(save_dir) 973--- endif 974--- < 975--- 976--- @param dir string 977--- @param scope? string 978--- @return string 979function vim . fn . chdir ( dir , scope ) end 980 981--- Get the amount of indent for line {lnum} according the 982--- |C-indenting| rules, as with 'cindent'. 983--- The indent is counted in spaces, the value of 'tabstop' is 984--- relevant. {lnum} is used just like in |getline()|. 985--- When {lnum} is invalid -1 is returned. 986--- 987--- To get or set indent of lines in a string, see |vim.text.indent()|. 988--- 989--- @param lnum integer|string 990--- @return integer 991function vim . fn . cindent ( lnum ) end 992 993--- Clears all matches previously defined for the current window 994--- by |matchadd()| and the |:match| commands. 995--- If {win} is specified, use this |window-number| or |window-ID| 996--- instead of the current window. 997--- 998--- @param win? integer 999function vim . fn . clearmatches ( win ) end 1000 1001--- Returns a |Dictionary| with information about cmdline 1002--- completion. See |cmdline-completion|. 1003--- The items are: 1004--- cmdline_orig The original command-line string before 1005--- completion began. 1006--- pum_visible |TRUE| if popup menu is visible. 1007--- See |pumvisible()|. 1008--- matches List of all completion candidates. Each item 1009--- is a string. 1010--- selected Selected item index. First index is zero. 1011--- Index is -1 if no item is selected (showing 1012--- typed text only, or the last completion after 1013--- no item is selected when using the <Up> or 1014--- <Down> keys) 1015--- 1016--- Returns an empty |Dictionary| if no completion was attempted, 1017--- if there was only one candidate and it was fully completed, or 1018--- if an error occurred. 1019--- 1020--- @return table<string,any> 1021function vim . fn . cmdcomplete_info () end 1022 1023--- Lua: Prefer |nvim_win_get_cursor()| for "." (add 1), or Lua `#` on |nvim_get_current_line()| for "$"; marks, list input, and `virtualedit` differ. 1024--- 1025--- Returns the byte index of the column position given with 1026--- {expr}. 1027--- For accepted positions see |getpos()|. 1028--- When {expr} is "$", it means the end of the cursor line, so 1029--- the result is the number of bytes in the cursor line plus one. 1030--- Additionally {expr} can be [lnum, col]: a |List| with the line 1031--- and column number. Most useful when the column is "$", to get 1032--- the last column of a specific line. When "lnum" or "col" is 1033--- out of range then col() returns zero. 1034--- 1035--- With the optional {winid} argument the values are obtained for 1036--- that window instead of the current window. 1037--- 1038--- To get the line number use |line()|. To get both use 1039--- |getpos()|. 1040--- 1041--- For the screen column position use |virtcol()|. For the 1042--- character position use |charcol()|. 1043--- 1044--- Note that only marks in the current file can be used. 1045--- 1046--- Examples: >vim 1047--- echo col(".") " column of cursor 1048--- echo col("$") " length of cursor line plus one 1049--- echo col("'t") " column of mark t 1050--- echo col("'" .. markname) " column of mark markname 1051--- < 1052--- The first column is 1. Returns 0 if {expr} is invalid or when 1053--- the window with ID {winid} is not found. 1054--- For an uppercase mark the column may actually be in another 1055--- buffer. 1056--- For the cursor position, when 'virtualedit' is active, the 1057--- column is one higher if the cursor is after the end of the 1058--- line. Also, when using a <Cmd> mapping the cursor isn't 1059--- moved, this can be used to obtain the column in Insert mode: >vim 1060--- imap <F2> <Cmd>echo col(".").."\n"<CR> 1061--- < 1062--- 1063--- @param expr string|any[] 1064--- @param winid? integer 1065--- @return integer 1066function vim . fn . col ( expr , winid ) end 1067 1068--- Set the matches for Insert mode completion. Can only be used 1069--- in Insert mode. Typically invoked from a mapping with 1070--- CTRL-R = (see |i_CTRL-R|), but may also be called from a 1071--- |<Cmd>| mapping. It does not work after CTRL-O or with an 1072--- expression mapping. 1073--- {startcol} is the byte offset in the line where the completed 1074--- text start. The text up to the cursor is the original text 1075--- that will be replaced by the matches. Use col('.') for an 1076--- empty string. "col('.') - 1" will replace one character by a 1077--- match. 1078--- {matches} must be a |List|. Each |List| item is one match. 1079--- See |complete-items| for the kind of items that are possible. 1080--- "longest" in 'completeopt' is ignored. 1081--- Note that the after calling this function you need to avoid 1082--- inserting anything that would cause completion to stop. 1083--- The match can be selected with CTRL-N and CTRL-P as usual with 1084--- Insert mode completion. The popup menu will appear if 1085--- specified, see |ins-completion-menu|. 1086--- Unlike with other |ins-completion| modes, the CTRL-N and 1087--- CTRL-P keys can be mapped while this completion is active. 1088--- For example, to make CTRL-N move the selection without 1089--- inserting the match: >vim 1090--- 1091--- inoremap <expr> <C-N> complete_info().mode ==# 'eval' 1092--- \ ? '<Down>' : '<C-N>' 1093--- < 1094--- 1095--- Example: >vim 1096--- 1097--- inoremap <F5> <C-R>=ListMonths()<CR> 1098--- 1099--- func ListMonths() 1100--- call complete(col('.'), ['January', 'February', 'March', 1101--- \ 'April', 'May', 'June', 'July', 'August', 1102--- \ 'September', 'October', 'November', 'December']) 1103--- return '' 1104--- endfunc 1105--- 1106--- <This isn't very useful, but it shows how it works. Note that 1107--- an empty string is returned to avoid a zero being inserted. 1108--- 1109--- @param startcol integer 1110--- @param matches any[] 1111function vim . fn . complete ( startcol , matches ) end 1112 1113--- Add {expr} to the list of matches. Only to be used by the 1114--- function specified with the 'completefunc' option. 1115--- Returns 0 for failure (empty string or out of memory), 1116--- 1 when the match was added, 2 when the match was already in 1117--- the list. 1118--- See |complete-functions| for an explanation of {expr}. It is 1119--- the same as one item in the list that 'omnifunc' would return. 1120--- 1121--- @param expr any 1122--- @return 0|1|2 1123function vim . fn . complete_add ( expr ) end 1124 1125--- Check for a key typed while looking for completion matches. 1126--- This is to be used when looking for matches takes some time. 1127--- Returns |TRUE| when searching for matches is to be aborted, 1128--- zero otherwise. 1129--- Only to be used by the function specified with the 1130--- 'completefunc' option. 1131--- 1132--- @return 0|1 1133function vim . fn . complete_check () end 1134 1135--- Returns a |Dictionary| with information about Insert mode 1136--- completion. See |ins-completion|. 1137--- The items are: 1138--- auto |TRUE| when Vim started this completion by 1139--- itself, which is what 'autocomplete' does, 1140--- and |FALSE| when a key asked for it, such as 1141--- |i_CTRL-X_CTRL-O|. A |complete-functions| 1142--- function can read this to tell the two apart. 1143--- Returned only when asked for in {what}. 1144--- completed Return a dictionary containing the entries of 1145--- the currently selected index item. 1146--- items List of all completion candidates. Each item 1147--- is a dictionary containing the entries "word", 1148--- "abbr", "menu", "kind", "info", 1149--- "abbr_hlgroup", "kind_hlgroup" and 1150--- "user_data". The highlight group entries hold 1151--- the name that the item was added with, 1152--- or an empty string. 1153--- "equal", "preselect" and "commit_chars" are 1154--- included only for items that set them. 1155--- See |complete-items|. 1156--- matches Same as "items", but only returns items that 1157--- are matching current query. If both "matches" 1158--- and "items" are in "what", the returned list 1159--- will still be named "items", but each item 1160--- will have an additional "match" field. 1161--- mode Current completion mode name string. 1162--- See |complete_info_mode| for the values. 1163--- preinserted_text 1164--- The actual text that is pre-inserted, see 1165--- |preinserted()|. 1166--- pum_visible |TRUE| if popup menu is visible. 1167--- See |pumvisible()|. 1168--- selected Selected item index. First index is zero. 1169--- Index is -1 if no item is selected (showing 1170--- typed text only, or the last completion after 1171--- no item is selected when using the <Up> or 1172--- <Down> keys) 1173--- preview_winid Info floating preview window id. 1174--- preview_bufnr Info floating preview buffer id. 1175--- 1176--- *complete_info_mode* 1177--- mode values are: 1178--- "" Not in completion mode 1179--- "keyword" Keyword completion |i_CTRL-X_CTRL-N| 1180--- "ctrl_x" Just pressed CTRL-X |i_CTRL-X| 1181--- "scroll" Scrolling with |i_CTRL-X_CTRL-E| or 1182--- |i_CTRL-X_CTRL-Y| 1183--- "whole_line" Whole lines |i_CTRL-X_CTRL-L| 1184--- "files" File names |i_CTRL-X_CTRL-F| 1185--- "tags" Tags |i_CTRL-X_CTRL-]| 1186--- "path_defines" Definition completion |i_CTRL-X_CTRL-D| 1187--- "path_patterns" Include completion |i_CTRL-X_CTRL-I| 1188--- "dictionary" Dictionary |i_CTRL-X_CTRL-K| 1189--- "thesaurus" Thesaurus |i_CTRL-X_CTRL-T| 1190--- "cmdline" Vim Command line |i_CTRL-X_CTRL-V| 1191--- "function" User defined completion |i_CTRL-X_CTRL-U| 1192--- "omni" Omni completion |i_CTRL-X_CTRL-O| 1193--- "spell" Spelling suggestions |i_CTRL-X_s| 1194--- "eval" |complete()| completion 1195--- "register" Words from registers |i_CTRL-X_CTRL-R| 1196--- "unknown" Other internal modes 1197--- 1198--- If the optional {what} list argument is supplied, then only 1199--- the items listed in {what} are returned. Unsupported items in 1200--- {what} are silently ignored. 1201--- 1202--- To get the position and size of the popup menu, see 1203--- |pum_getpos()|. It's also available in |v:event| during the 1204--- |CompleteChanged| event. 1205--- 1206--- Returns an empty |Dictionary| on error. 1207--- 1208--- Examples: >vim 1209--- " Get all items 1210--- call complete_info() 1211--- " Get only 'mode' 1212--- call complete_info(['mode']) 1213--- " Get only 'mode' and 'pum_visible' 1214--- call complete_info(['mode', 'pum_visible']) 1215--- < 1216--- 1217--- @param what? any[] 1218--- @return table 1219function vim . fn . complete_info ( what ) end 1220 1221--- confirm() offers the user a dialog, from which a choice can be 1222--- made. It returns the number of the choice. For the first 1223--- choice this is 1. 1224--- 1225--- {msg} is displayed in a dialog with {choices} as the 1226--- alternatives. When {choices} is missing or empty, "&OK" is 1227--- used (and translated). 1228--- {msg} is a String, use '\n' to include a newline. Only on 1229--- some systems the string is wrapped when it doesn't fit. 1230--- 1231--- {choices} is a String, with the individual choices separated 1232--- by '\n', e.g. >vim 1233--- confirm("Save changes?", "&Yes\n&No\n&Cancel") 1234--- <The letter after the '&' is the shortcut key for that choice. 1235--- Thus you can type 'c' to select "Cancel". The shortcut does 1236--- not need to be the first letter: >vim 1237--- confirm("file has been modified", "&Save\nSave &All") 1238--- <For the console, the first letter of each choice is used as 1239--- the default shortcut key. Case is ignored. 1240--- 1241--- The optional {type} String argument gives the type of dialog. 1242--- It can be one of these values: "Error", "Question", "Info", 1243--- "Warning" or "Generic". Only the first character is relevant. 1244--- When {type} is omitted, "Generic" is used. 1245--- 1246--- The optional {type} argument gives the type of dialog. This 1247--- is only used for the icon of the Win32 GUI. It can be one of 1248--- these values: "Error", "Question", "Info", "Warning" or 1249--- "Generic". Only the first character is relevant. 1250--- When {type} is omitted, "Generic" is used. 1251--- 1252--- If the user aborts the dialog by pressing <Esc>, CTRL-C, 1253--- or another valid interrupt key, confirm() returns 0. 1254--- 1255--- An example: >vim 1256--- let choice = confirm("What do you want?", 1257--- \ "&Apples\n&Oranges\n&Bananas", 2) 1258--- if choice == 0 1259--- echo "make up your mind!" 1260--- elseif choice == 3 1261--- echo "tasteful" 1262--- else 1263--- echo "I prefer bananas myself." 1264--- endif 1265--- <In a GUI dialog, buttons are used. The layout of the buttons 1266--- depends on the 'v' flag in 'guioptions'. If it is included, 1267--- the buttons are always put vertically. Otherwise, confirm() 1268--- tries to put the buttons in one horizontal line. If they 1269--- don't fit, a vertical layout is used anyway. For some systems 1270--- the horizontal layout is always used. 1271--- 1272--- @param msg string 1273--- @param choices? string 1274--- @param default? integer 1275--- @param type? string 1276--- @return integer 1277function vim . fn . confirm ( msg , choices , default , type ) end 1278 1279--- Lua: Prefer |vim.deepcopy()|; deeper than Vimscript |copy()|. 1280--- 1281--- Make a copy of {expr}. For Numbers and Strings this isn't 1282--- different from using {expr} directly. 1283--- When {expr} is a |List| a shallow copy is created. This means 1284--- that the original |List| can be changed without changing the 1285--- copy, and vice versa. But the items are identical, thus 1286--- changing an item changes the contents of both |Lists|. 1287--- A |Dictionary| is copied in a similar way as a |List|. 1288--- Also see |deepcopy()|. 1289--- 1290--- @generic T 1291--- @param expr T 1292--- @return T 1293function vim . fn . copy ( expr ) end 1294 1295--- Lua: Prefer |math.cos()|. 1296--- 1297--- Return the cosine of {expr}, measured in radians, as a |Float|. 1298--- {expr} must evaluate to a |Float| or a |Number|. 1299--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 1300--- Examples: >vim 1301--- echo cos(100) 1302--- < 0.862319 >vim 1303--- echo cos(-4.01) 1304--- < -0.646043 1305--- 1306--- @param expr number 1307--- @return number 1308function vim . fn . cos ( expr ) end 1309 1310--- Lua: Prefer |math.cosh()|. 1311--- 1312--- Return the hyperbolic cosine of {expr} as a |Float| in the range 1313--- [1, inf]. 1314--- {expr} must evaluate to a |Float| or a |Number|. 1315--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 1316--- Examples: >vim 1317--- echo cosh(0.5) 1318--- < 1.127626 >vim 1319--- echo cosh(-0.5) 1320--- < 1.127626 1321--- 1322--- @param expr number 1323--- @return number 1324function vim . fn . cosh ( expr ) end 1325 1326--- Return the number of times an item with value {expr} appears 1327--- in |String|, |List| or |Dictionary| {comp}. 1328--- 1329--- If {start} is given then start with the item with this index. 1330--- {start} can only be used with a |List|. 1331--- 1332--- When {ic} is given and it's |TRUE| then case is ignored. 1333--- 1334--- When {comp} is a string then the number of not overlapping 1335--- occurrences of {expr} is returned. Zero is returned when 1336--- {expr} is an empty string. 1337--- 1338--- @param comp string|table|any[] 1339--- @param expr any 1340--- @param ic? boolean 1341--- @param start? integer 1342--- @return integer 1343function vim . fn . count ( comp , expr , ic , start ) end 1344 1345--- Lua: Prefer |nvim_win_set_cursor()| with `{lnum, col - 1}`; `off`, `curswant`, and failure semantics differ. 1346--- 1347--- Positions the cursor at the column (byte count) {col} in the 1348--- line {lnum}. The first column is one. 1349--- 1350--- When there is one argument {list} this is used as a |List| 1351--- with two, three or four item: 1352--- [{lnum}, {col}] 1353--- [{lnum}, {col}, {off}] 1354--- [{lnum}, {col}, {off}, {curswant}] 1355--- This is like the return value of |getpos()| or |getcurpos()|, 1356--- but without the first item. 1357--- 1358--- To position the cursor using {col} as the character count, use 1359--- |setcursorcharpos()|. 1360--- 1361--- Does not change the jumplist. 1362--- {lnum} is used like with |getline()|, except that if {lnum} is 1363--- zero, the cursor will stay in the current line. 1364--- If {lnum} is greater than the number of lines in the buffer, 1365--- the cursor will be positioned at the last line in the buffer. 1366--- If {col} is greater than the number of bytes in the line, 1367--- the cursor will be positioned at the last character in the 1368--- line. 1369--- If {col} is zero, the cursor will stay in the current column. 1370--- If {curswant} is given it is used to set the preferred column 1371--- for vertical movement. Otherwise {col} is used. 1372--- 1373--- When 'virtualedit' is used {off} specifies the offset in 1374--- screen columns from the start of the character. E.g., a 1375--- position within a <Tab> or after the last character. 1376--- Returns 0 when the position could be set, -1 otherwise. 1377--- 1378--- @overload fun(list: integer[]): (any) 1379--- @param lnum integer|string 1380--- @param col? integer 1381--- @param off? integer 1382--- @return any 1383function vim . fn . cursor ( lnum , col , off ) end 1384 1385--- Lua: Prefer |uv.kill()| with `"sigtrap"` (or `"sigint"` outside MS-Windows); exact semantics differ. 1386--- 1387--- Specifically used to interrupt a program being debugged. It 1388--- will cause process {pid} to get a SIGTRAP. Behavior for other 1389--- processes is undefined. See |terminal-debug|. 1390--- (Sends a SIGINT to a process {pid} other than MS-Windows) 1391--- 1392--- Returns |TRUE| if successfully interrupted the program. 1393--- Otherwise returns |FALSE|. 1394--- 1395--- @param pid integer 1396--- @return any 1397function vim . fn . debugbreak ( pid ) end 1398 1399--- Lua: Prefer |vim.deepcopy()|. 1400--- 1401--- Make a copy of {expr}. For Numbers and Strings this isn't 1402--- different from using {expr} directly. 1403--- When {expr} is a |List| a full copy is created. This means 1404--- that the original |List| can be changed without changing the 1405--- copy, and vice versa. When an item is a |List|, a copy for it 1406--- is made, recursively. Thus changing an item in the copy does 1407--- not change the contents of the original |List|. 1408--- 1409--- When {noref} is omitted or zero a contained |List| or 1410--- |Dictionary| is only copied once. All references point to 1411--- this single copy. With {noref} set to 1 every occurrence of a 1412--- |List| or |Dictionary| results in a new copy. This also means 1413--- that a cyclic reference causes deepcopy() to fail. 1414--- *E724* 1415--- Nesting is possible up to 100 levels. When there is an item 1416--- that refers back to a higher level making a deep copy with 1417--- {noref} set to 1 will fail. 1418--- Also see |copy()|. 1419--- 1420--- @generic T 1421--- @param expr T 1422--- @param noref? boolean 1423--- @return T 1424function vim . fn . deepcopy ( expr , noref ) end 1425 1426--- Lua: Prefer |vim.fs.rm()|. 1427--- 1428--- Without {flags} or with {flags} empty: Deletes the file by the 1429--- name {fname}. 1430--- 1431--- This also works when {fname} is a symbolic link. The symbolic 1432--- link itself is deleted, not what it points to. 1433--- 1434--- When {flags} is "d": Deletes the directory by the name 1435--- {fname}. This fails when directory {fname} is not empty. 1436--- 1437--- When {flags} is "rf": Deletes the directory by the name 1438--- {fname} and everything in it, recursively. BE CAREFUL! 1439--- Note: on MS-Windows it is not possible to delete a directory 1440--- that is being used. 1441--- 1442--- The result is a Number, which is 0/false if the delete 1443--- operation was successful and -1/true when the deletion failed 1444--- or partly failed. 1445--- 1446--- @param fname string 1447--- @param flags? string 1448--- @return integer 1449function vim . fn . delete ( fname , flags ) end 1450 1451--- Lua: Prefer |nvim_buf_set_lines()|. 1452--- 1453--- Delete lines {first} to {last} (inclusive) from buffer {buf}. 1454--- If {last} is omitted then delete line {first} only. 1455--- On success 0 is returned, on failure 1 is returned. 1456--- 1457--- This function works only for loaded buffers. First call 1458--- |bufload()| if needed. 1459--- 1460--- For the use of {buf}, see |bufname()| above. 1461--- 1462--- {first} and {last} are used like with |getline()|. Note that 1463--- when using |line()| this refers to the current buffer. Use "$" 1464--- to refer to the last line in buffer {buf}. 1465--- 1466--- @param buf integer|string 1467--- @param first integer|string 1468--- @param last? integer|string 1469--- @return any 1470function vim . fn . deletebufline ( buf , first , last ) end 1471 1472--- Adds a watcher to a dictionary. A dictionary watcher is 1473--- identified by three components: 1474--- 1475--- - A dictionary({dict}); 1476--- - A key pattern({pattern}). 1477--- - A function({callback}). 1478--- 1479--- After this is called, every change on {dict} and on keys 1480--- matching {pattern} will result in {callback} being invoked. 1481--- 1482--- For example, to watch all global variables: >vim 1483--- silent! call dictwatcherdel(g:, '*', 'OnDictChanged') 1484--- function! OnDictChanged(d,k,z) 1485--- echomsg string(a:k) string(a:z) 1486--- endfunction 1487--- call dictwatcheradd(g:, '*', 'OnDictChanged') 1488--- < 1489--- For now {pattern} only accepts very simple patterns that can 1490--- contain a "*" at the end of the string, in which case it will 1491--- match every key that begins with the substring before the "*". 1492--- That means if "*" is not the last character of {pattern}, only 1493--- keys that are exactly equal as {pattern} will be matched. 1494--- 1495--- The {callback} receives three arguments: 1496--- 1497--- - The dictionary being watched. 1498--- - The key which changed. 1499--- - A dictionary containing the new and old values for the key. 1500--- 1501--- The type of change can be determined by examining the keys 1502--- present on the third argument: 1503--- 1504--- - If contains both `old` and `new`, the key was updated. 1505--- - If it contains only `new`, the key was added. 1506--- - If it contains only `old`, the key was deleted. 1507--- 1508--- This function can be used by plugins to implement options with 1509--- validation and parsing logic. 1510--- 1511--- @param dict table 1512--- @param pattern string 1513--- @param callback function 1514--- @return any 1515function vim . fn . dictwatcheradd ( dict , pattern , callback ) end 1516 1517--- Removes a watcher added with |dictwatcheradd()|. All three 1518--- arguments must match the ones passed to |dictwatcheradd()| in 1519--- order for the watcher to be successfully deleted. 1520--- 1521--- @param dict any 1522--- @param pattern string 1523--- @param callback function 1524--- @return any 1525function vim . fn . dictwatcherdel ( dict , pattern , callback ) end 1526 1527--- Returns |TRUE| when autocommands are being executed and the 1528--- FileType event triggered at least once for a buffer with 1529--- a non-empty 'filetype'. Can be used to avoid triggering 1530--- the FileType event again in the |ftdetect| scripts. |FileType| 1531--- Returns |FALSE| when `:setf FALLBACK` was used. 1532--- 1533--- When editing another file, the counter is reset, thus this 1534--- really checks if the FileType event has been triggered for the 1535--- current buffer. This allows an autocommand that starts 1536--- editing another buffer to set 'filetype' and load a syntax 1537--- file. 1538--- 1539--- @return integer 1540function vim . fn . did_filetype () end 1541 1542--- Returns the number of filler lines above line {lnum}. 1543--- These are the lines that were inserted at this point in 1544--- another diff'ed window. These filler lines are shown in the 1545--- display but don't exist in the buffer. 1546--- {lnum} is used like with |getline()|. Thus "." is the current 1547--- line, "'m" mark m, etc. 1548--- 1549--- To get the filler lines after the last buffer line, use: >vim 1550--- echo diff_filler(line('$')+1) 1551--- < 1552--- Returns 0 if the current window is not in diff mode or filler 1553--- lines have been disabled using 'diffopt'. 1554--- 1555--- @param lnum integer|string 1556--- @return integer 1557function vim . fn . diff_filler ( lnum ) end 1558 1559--- Returns the highlight ID for diff mode at line {lnum} column 1560--- {col} (byte index). When the current line does not have a 1561--- diff change zero is returned. 1562--- {lnum} is used like with |getline()|. Thus "." is the current 1563--- line, "'m" mark m, etc. 1564--- {col} is 1 for the leftmost column, {lnum} is 1 for the first 1565--- line. 1566--- The highlight ID can be used with |synIDattr()| to obtain 1567--- syntax information about the highlighting. 1568--- 1569--- @param lnum integer|string 1570--- @param col integer 1571--- @return any 1572function vim . fn . diff_hlID ( lnum , col ) end 1573 1574--- Return the digraph of {chars}. This should be a string with 1575--- exactly two characters. If {chars} are not just two 1576--- characters, or the digraph of {chars} does not exist, an error 1577--- is given and an empty string is returned. 1578--- 1579--- Also see |digraph_getlist()|. 1580--- 1581--- Examples: >vim 1582--- " Get a built-in digraph 1583--- echo digraph_get('00') " Returns '∞' 1584--- 1585--- " Get a user-defined digraph 1586--- call digraph_set('aa', 'あ') 1587--- echo digraph_get('aa') " Returns 'あ' 1588--- < 1589--- 1590--- @param chars string 1591--- @return string 1592function vim . fn . digraph_get ( chars ) end 1593 1594--- Return a list of digraphs. If the {listall} argument is given 1595--- and it is TRUE, return all digraphs, including the default 1596--- digraphs. Otherwise, return only user-defined digraphs. 1597--- 1598--- Also see |digraph_get()|. 1599--- 1600--- Examples: >vim 1601--- " Get user-defined digraphs 1602--- echo digraph_getlist() 1603--- 1604--- " Get all the digraphs, including default digraphs 1605--- echo digraph_getlist(1) 1606--- < 1607--- 1608--- @param listall? boolean 1609--- @return string[][] 1610function vim . fn . digraph_getlist ( listall ) end 1611 1612--- Add digraph {chars} to the list. {chars} must be a string 1613--- with two characters. {digraph} is a string with one UTF-8 1614--- encoded character. *E1215* 1615--- Be careful, composing characters are NOT ignored. This 1616--- function is similar to |:digraphs| command, but useful to add 1617--- digraphs start with a white space. 1618--- 1619--- The function result is v:true if |digraph| is registered. If 1620--- this fails an error message is given and v:false is returned. 1621--- 1622--- If you want to define multiple digraphs at once, you can use 1623--- |digraph_setlist()|. 1624--- 1625--- Example: >vim 1626--- call digraph_set(' ', 'あ') 1627--- < 1628--- 1629--- @param chars string 1630--- @param digraph string 1631--- @return any 1632function vim . fn . digraph_set ( chars , digraph ) end 1633 1634--- Similar to |digraph_set()| but this function can add multiple 1635--- digraphs at once. {digraphlist} is a list composed of lists, 1636--- where each list contains two strings with {chars} and 1637--- {digraph} as in |digraph_set()|. *E1216* 1638--- Example: >vim 1639--- call digraph_setlist([['aa', 'あ'], ['ii', 'い']]) 1640--- < 1641--- It is similar to the following: >vim 1642--- for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']] 1643--- call digraph_set(chars, digraph) 1644--- endfor 1645--- <Except that the function returns after the first error, 1646--- following digraphs will not be added. 1647--- 1648--- @param digraphlist table<integer,string[]> 1649--- @return any 1650function vim . fn . digraph_setlist ( digraphlist ) end 1651 1652--- Lua: Prefer plain Lua emptiness checks, or |vim.tbl_isempty()| for tables. 1653--- 1654--- Return the Number 1 if {expr} is empty, zero otherwise. 1655--- - A |List| or |Dictionary| is empty when it does not have any 1656--- items. 1657--- - A |String| is empty when its length is zero. 1658--- - A |Number| and |Float| are empty when their value is zero. 1659--- - |v:false| and |v:null| are empty, |v:true| is not. 1660--- - A |Blob| is empty when its length is zero. 1661--- 1662--- @param expr any 1663--- @return integer 1664function vim . fn . empty ( expr ) end 1665 1666--- Lua: Prefer |uv.os_environ()| for the full environment table; |vim.env| for keyed access. 1667--- 1668--- Return all of environment variables as dictionary. You can 1669--- check if an environment variable exists like this: >vim 1670--- echo has_key(environ(), 'HOME') 1671--- <Note that the variable name may be CamelCase; to ignore case 1672--- use this: >vim 1673--- echo index(keys(environ()), 'HOME', 0, 1) != -1 1674--- < 1675--- 1676--- @return any 1677function vim . fn . environ () end 1678 1679--- Escape the characters in {chars} that occur in {string} with a 1680--- backslash. Example: >vim 1681--- echo escape('c:\program files\vim', ' \') 1682--- <results in: > 1683--- c:\\program\ files\\vim 1684--- <Also see |shellescape()| and |fnameescape()|. 1685--- 1686--- @param string string 1687--- @param chars string 1688--- @return string 1689function vim . fn . escape ( string , chars ) end 1690 1691--- Evaluate {string} and return the result. Especially useful to 1692--- turn the result of |string()| back into the original value. 1693--- This works for Numbers, Floats, Strings, Blobs and composites 1694--- of them. Also works for |Funcref|s that refer to existing 1695--- functions. 1696--- 1697--- @param string string 1698--- @return any 1699function vim . fn . eval ( string ) end 1700 1701--- Returns 1 when inside an event handler. That is that Vim got 1702--- interrupted while waiting for the user to type a character, 1703--- e.g., when dropping a file on Vim. This means interactive 1704--- commands cannot be used. Otherwise zero is returned. 1705--- 1706--- @return any 1707function vim . fn . eventhandler () end 1708 1709--- This function checks if an executable with the name {expr} 1710--- exists. {expr} must be the name of the program without any 1711--- arguments. 1712--- 1713--- executable() uses the value of $PATH and/or the normal 1714--- searchpath for programs. 1715--- *PATHEXT* 1716--- On MS-Windows the ".exe", ".bat", etc. can optionally be 1717--- included. Then the extensions in $PATHEXT are tried. Thus if 1718--- "foo.exe" does not exist, "foo.exe.bat" can be found. If 1719--- $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot 1720--- by itself can be used in $PATHEXT to try using the name 1721--- without an extension. When 'shell' looks like a Unix shell, 1722--- then the name is also tried without adding an extension. 1723--- On MS-Windows it only checks if the file exists and is not a 1724--- directory, not if it's really executable. 1725--- 1726--- On MS-Windows an executable in the same directory as the Vim 1727--- executable is always found (it's added to $PATH at |startup|). 1728--- *$NoDefaultCurrentDirectoryInExePath* 1729--- On MS-Windows when using cmd.exe as 'shell' an executable in 1730--- Vim's current working directory is also normally found, which 1731--- can be disabled by setting the 1732--- `$NoDefaultCurrentDirectoryInExePath` environment variable. 1733--- This variable is always set by Vim when executing external 1734--- commands (e.g., via |:!|, |:make|, or |system()|) for security 1735--- reasons. 1736--- 1737--- The result is a Number: 1738--- 1 exists 1739--- 0 does not exist 1740--- |exepath()| can be used to get the full path of an executable. 1741--- 1742--- @param expr string 1743--- @return 0|1 1744function vim . fn . executable ( expr ) end 1745 1746--- Lua: Prefer |nvim_exec()| or |vim.cmd()|. 1747--- 1748--- Execute {command} and capture its output. 1749--- If {command} is a |String|, returns {command} output. 1750--- If {command} is a |List|, returns concatenated outputs. 1751--- Line continuations in {command} are not recognized. 1752--- Examples: >vim 1753--- echo execute('echon "foo"') 1754--- < foo >vim 1755--- echo execute(['echon "foo"', 'echon "bar"']) 1756--- < foobar 1757--- 1758--- The optional {silent} argument can have these values: 1759--- "" no `:silent` used 1760--- "silent" `:silent` used 1761--- "silent!" `:silent!` used 1762--- The default is "silent". Note that with "silent!", unlike 1763--- `:redir`, error messages are dropped. 1764--- 1765--- To get a list of lines use `split()` on the result: >vim 1766--- execute('args')->split("\n") 1767--- 1768--- <This function is not available in the |sandbox|. 1769--- Note: If nested, an outer execute() will not observe output of 1770--- the inner calls. 1771--- Note: Text attributes (highlights) are not captured. 1772--- To execute a command in another window than the current one 1773--- use `win_execute()`. 1774--- 1775--- @param command string|string[] 1776--- @param silent? ''|'silent'|'silent!' 1777--- @return string 1778function vim . fn . execute ( command , silent ) end 1779 1780--- Returns the full path of {expr} if it is an executable and 1781--- given as a (partial or full) path or is found in $PATH. 1782--- Returns empty string otherwise. 1783--- If {expr} starts with "./" the |current-directory| is used. 1784--- 1785--- @param expr string 1786--- @return string 1787function vim . fn . exepath ( expr ) end 1788 1789--- Checks whether the expression {expr} is defined. 1790--- Returns |TRUE| if {expr} is defined, zero otherwise. 1791--- 1792--- For checking for a supported feature use |has()|. 1793--- For checking if a file exists use |filereadable()|. 1794--- 1795--- The {expr} argument is a string, which contains one of these: 1796--- varname internal variable (see 1797--- dict.key |internal-variables|). Also works 1798--- list[i] for |curly-braces-names|, |Dictionary| 1799--- entries, |List| items, etc. 1800--- Beware that evaluating an index may 1801--- cause an error message for an invalid 1802--- expression. E.g.: >vim 1803--- let l = [1, 2, 3] 1804--- echo exists("l[5]") 1805--- < 0 >vim 1806--- echo exists("l[xx]") 1807--- < E121: Undefined variable: xx 1808--- 0 1809--- &option-name Vim option (only checks if it exists, 1810--- not if it really works) 1811--- +option-name Vim option that works. 1812--- $ENVNAME environment variable (could also be 1813--- done by comparing with an empty 1814--- string) 1815--- `*funcname` built-in function (see |functions|) 1816--- or user defined function (see 1817--- |user-function|). Also works for a 1818--- variable that is a Funcref. 1819--- :cmdname Ex command: built-in command, user 1820--- command or command modifier |:command|. 1821--- Returns: 1822--- 1 for match with start of a command 1823--- 2 full match with a command 1824--- 3 matches several user commands 1825--- To check for a supported command 1826--- always check the return value to be 2. 1827--- :2match The |:2match| command. 1828--- :3match The |:3match| command (but you 1829--- probably should not use it, it is 1830--- reserved for internal usage) 1831--- #event autocommand defined for this event 1832--- #event#pattern autocommand defined for this event and 1833--- pattern (the pattern is taken 1834--- literally and compared to the 1835--- autocommand patterns character by 1836--- character) 1837--- #group autocommand group exists 1838--- #group#event autocommand defined for this group and 1839--- event. 1840--- #group#event#pattern 1841--- autocommand defined for this group, 1842--- event and pattern. 1843--- ##event autocommand for this event is 1844--- supported. 1845--- 1846--- Examples: >vim 1847--- echo exists("&mouse") 1848--- echo exists("$HOSTNAME") 1849--- echo exists("*strftime") 1850--- echo exists("*s:MyFunc") 1851--- echo exists("*MyFunc") 1852--- echo exists("*v:lua.Func") 1853--- echo exists("bufcount") 1854--- echo exists(":Make") 1855--- echo exists("#CursorHold") 1856--- echo exists("#BufReadPre#*.gz") 1857--- echo exists("#filetypeindent") 1858--- echo exists("#filetypeindent#FileType") 1859--- echo exists("#filetypeindent#FileType#*") 1860--- echo exists("##ColorScheme") 1861--- <There must be no space between the symbol (&/$/*/#) and the 1862--- name. 1863--- There must be no extra characters after the name, although in 1864--- a few cases this is ignored. That may become stricter in the 1865--- future, thus don't count on it! 1866--- Working example: >vim 1867--- echo exists(":make") 1868--- <NOT working example: >vim 1869--- echo exists(":make install") 1870--- 1871--- <Note that the argument must be a string, not the name of the 1872--- variable itself. For example: >vim 1873--- echo exists(bufcount) 1874--- <This doesn't check for existence of the "bufcount" variable, 1875--- but gets the value of "bufcount", and checks if that exists. 1876--- 1877--- @param expr string 1878--- @return 0|1 1879function vim . fn . exists ( expr ) end 1880 1881--- Lua: Prefer |math.exp()|. 1882--- 1883--- Return the exponential of {expr} as a |Float| in the range 1884--- [0, inf]. 1885--- {expr} must evaluate to a |Float| or a |Number|. 1886--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 1887--- Examples: >vim 1888--- echo exp(2) 1889--- < 7.389056 >vim 1890--- echo exp(-1) 1891--- < 0.367879 1892--- 1893--- @param expr number 1894--- @return any 1895function vim . fn . exp ( expr ) end 1896 1897--- Expand wildcards and the following special keywords in 1898--- {string}. 'wildignorecase' applies. 1899--- 1900--- If {list} is given and it is |TRUE|, a List will be returned. 1901--- Otherwise the result is a String and when there are several 1902--- matches, they are separated by <NL> characters. 1903--- 1904--- If the expansion fails, the result is an empty string. A name 1905--- for a non-existing file is not included, unless {string} does 1906--- not start with '%', '#' or '<', see below. 1907--- 1908--- When {string} starts with '%', '#' or '<', the expansion is 1909--- done like for the |cmdline-special| variables with their 1910--- associated modifiers. Here is a short overview: 1911--- 1912--- % Current file name 1913--- # Alternate file name 1914--- #n Alternate file name n 1915--- <cfile> File name under the cursor 1916--- <afile> Autocmd file name 1917--- <abuf> Autocmd buffer number (as a String!) 1918--- <amatch> Autocmd matched name 1919--- <cexpr> C expression under the cursor 1920--- <sfile> Deprecated, use <script> or <stack> 1921--- <slnum> Sourced script line number or function 1922--- line number 1923--- <sflnum> Script file line number, also when in 1924--- a function 1925--- <SID> "<SNR>123_" where "123" is the 1926--- current script ID |<SID>| 1927--- <script> Sourced script file, or script file 1928--- where the current function was defined. 1929--- Lua: see |lua-script-location|. 1930--- <stack> Call stack 1931--- <cword> Word under the cursor 1932--- <cWORD> WORD under the cursor 1933--- <client> The {clientid} of the last received 1934--- message 1935--- Modifiers: 1936--- :p Expand to full path 1937--- :h Head (last path component removed) 1938--- :t Tail (last path component only) 1939--- :r Root (one extension removed) 1940--- :e Extension only 1941--- 1942--- More modifiers are supported, for the full list see 1943--- |filename-modifiers|. 1944--- 1945--- Example: >vim 1946--- let &tags = expand("%:p:h") .. "/tags" 1947--- <Note that when expanding a string that starts with '%', '#' or 1948--- '<', any following text is ignored. This does NOT work: >vim 1949--- let doesntwork = expand("%:h.bak") 1950--- <Use this: >vim 1951--- let doeswork = expand("%:h") .. ".bak" 1952--- <Also note that expanding "<cfile>" and others only returns the 1953--- referenced file name without further expansion. If "<cfile>" 1954--- is "~/.cshrc", you need to do another expand() to have the 1955--- "~/" expanded into the path of the home directory: >vim 1956--- echo expand(expand("<cfile>")) 1957--- < 1958--- There cannot be white space between the variables and the 1959--- following modifier. The |fnamemodify()| function can be used 1960--- to modify normal file names. 1961--- 1962--- When using '%' or '#', and the current or alternate file name 1963--- is not defined, an empty string is used. Using "%:p" in a 1964--- buffer with no name, results in the current directory, with a 1965--- '/' added. 1966--- When 'verbose' is set then expanding '%', '#' and <> items 1967--- will result in an error message if the argument cannot be 1968--- expanded. 1969--- 1970--- When {string} does not start with '%', '#' or '<', it is 1971--- expanded like a file name is expanded on the command line. 1972--- 'suffixes' and 'wildignore' are used, unless the optional 1973--- {nosuf} argument is given and it is |TRUE|. 1974--- Names for non-existing files are included. The "**" item can 1975--- be used to search in a directory tree. For example, to find 1976--- all "README" files in the current directory and below: >vim 1977--- echo expand("**/README") 1978--- < 1979--- expand() can also be used to expand variables and environment 1980--- variables that are only known in a shell. But this can be 1981--- slow, because a shell may be used to do the expansion. See 1982--- |expr-env-expand|. 1983--- The expanded variable is still handled like a list of file 1984--- names. When an environment variable cannot be expanded, it is 1985--- left unchanged. Thus ":echo expand('$FOOBAR')" results in 1986--- "$FOOBAR". 1987--- 1988--- See |glob()| for finding existing files. See |system()| for 1989--- getting the raw output of an external command. 1990--- 1991--- @overload fun(string: string, nosuf: boolean?, list: true|number|string|table): (string|string[]) 1992--- @param string string 1993--- @param nosuf? boolean 1994--- @param list? nil|false 1995--- @return string 1996function vim . fn . expand ( string , nosuf , list ) end 1997 1998--- Expand special items in String {string} like what is done for 1999--- an Ex command such as `:edit`. This expands special keywords, 2000--- like with |expand()|, and environment variables, anywhere in 2001--- {string}. "~user" and "~/path" are only expanded at the 2002--- start. 2003--- The expansion is done in two steps: the special keywords are 2004--- evaluated first, then "~" and environment variables are 2005--- expanded in the result. Thus `expand('%:~')` keeps the "~", 2006--- while `expandcmd('%:~')` returns the full path. 2007--- 2008--- The following items are supported in the {options} Dict 2009--- argument: 2010--- errmsg If set to TRUE, error messages are displayed 2011--- if an error is encountered during expansion. 2012--- By default, error messages are not displayed. 2013--- 2014--- Returns the expanded string. If an error is encountered 2015--- during expansion, the unmodified {string} is returned. 2016--- 2017--- Example: >vim 2018--- echo expandcmd('make %<.o') 2019--- < > 2020--- make /path/runtime/doc/builtin.o 2021--- < >vim 2022--- echo expandcmd('make %<.o', {'errmsg': v:true}) 2023--- < 2024--- 2025--- @param string string 2026--- @param options? table 2027--- @return any 2028function vim . fn . expandcmd ( string , options ) end 2029 2030--- Lua: Prefer |vim.list_extend()| for lists, or |vim.tbl_extend()| and |vim.tbl_deep_extend()| for dicts; insertion and keep/force/error behavior differ. 2031--- 2032--- {expr1} and {expr2} must be both |Lists| or both 2033--- |Dictionaries|. 2034--- 2035--- If they are |Lists|: Append {expr2} to {expr1}. 2036--- If {expr3} is given insert the items of {expr2} before the 2037--- item with index {expr3} in {expr1}. When {expr3} is zero 2038--- insert before the first item. When {expr3} is equal to 2039--- len({expr1}) then {expr2} is appended. 2040--- Examples: >vim 2041--- echo sort(extend(mylist, [7, 5])) 2042--- call extend(mylist, [2, 3], 1) 2043--- <When {expr1} is the same List as {expr2} then the number of 2044--- items copied is equal to the original length of the List. 2045--- E.g., when {expr3} is 1 you get N new copies of the first item 2046--- (where N is the original length of the List). 2047--- Use |add()| to concatenate one item to a list. To concatenate 2048--- two lists into a new list use the + operator: >vim 2049--- let newlist = [1, 2, 3] + [4, 5] 2050--- < 2051--- If they are |Dictionaries|: 2052--- Add all entries from {expr2} to {expr1}. 2053--- If a key exists in both {expr1} and {expr2} then {expr3} is 2054--- used to decide what to do: 2055--- {expr3} = "keep": keep the value of {expr1} 2056--- {expr3} = "force": use the value of {expr2} 2057--- {expr3} = "error": give an error message *E737* 2058--- When {expr3} is omitted then "force" is assumed. 2059--- 2060--- {expr1} is changed when {expr2} is not empty. If necessary 2061--- make a copy of {expr1} first or use |extendnew()| to return a 2062--- new List/Dictionary. 2063--- {expr2} remains unchanged. 2064--- When {expr1} is locked and {expr2} is not empty the operation 2065--- fails. 2066--- Returns {expr1}. Returns 0 on error. 2067--- 2068--- @param expr1 table 2069--- @param expr2 table 2070--- @param expr3? table 2071--- @return any 2072function vim . fn . extend ( expr1 , expr2 , expr3 ) end 2073 2074--- Lua: Prefer |vim.list_extend()| on a copy for lists, or |vim.tbl_extend()| and |vim.tbl_deep_extend()| for dicts; insertion and keep/force/error behavior differ. 2075--- 2076--- Like |extend()| but instead of adding items to {expr1} a new 2077--- List or Dictionary is created and returned. {expr1} remains 2078--- unchanged. 2079--- 2080--- @param expr1 table 2081--- @param expr2 table 2082--- @param expr3? table 2083--- @return any 2084function vim . fn . extendnew ( expr1 , expr2 , expr3 ) end 2085 2086--- Lua: Prefer |nvim_feedkeys()|. 2087--- 2088--- Characters in {string} are queued for processing as if they 2089--- come from a mapping or were typed by the user. 2090--- 2091--- By default the string is added to the end of the typeahead 2092--- buffer, thus if a mapping is still being executed the 2093--- characters come after them. Use the 'i' flag to insert before 2094--- other characters, they will be executed next, before any 2095--- characters from a mapping. 2096--- 2097--- The function does not wait for processing of keys contained in 2098--- {string}. 2099--- 2100--- To include special keys into {string}, use double-quotes 2101--- and "\..." notation |expr-quote|. For example, 2102--- feedkeys("\<CR>") simulates pressing of the <Enter> key. But 2103--- feedkeys('\<CR>') pushes 5 characters. 2104--- The |<Ignore>| keycode may be used to exit the 2105--- wait-for-character without doing anything. 2106--- 2107--- {mode} is a String, which can contain these character flags: 2108--- 'm' Remap keys. This is default. If {mode} is absent, 2109--- keys are remapped. 2110--- 'n' Do not remap keys. 2111--- 't' Handle keys as if typed; otherwise they are handled as 2112--- if coming from a mapping. This matters for undo, 2113--- opening folds, etc. 2114--- 'L' Lowlevel input. Other flags are not used. 2115--- 'i' Insert the string instead of appending (see above). 2116--- 'x' Execute commands until typeahead is empty. This is 2117--- similar to using ":normal!". You can call feedkeys() 2118--- several times without 'x' and then one time with 'x' 2119--- (possibly with an empty {string}) to execute all the 2120--- typeahead. Note that when Vim ends in Insert mode it 2121--- will behave as if <Esc> is typed, to avoid getting 2122--- stuck, waiting for a character to be typed before the 2123--- script continues. 2124--- Note that if you manage to call feedkeys() while 2125--- executing commands, thus calling it recursively, then 2126--- all typeahead will be consumed by the last call. 2127--- '!' When used with 'x' will not end Insert mode. Can be 2128--- used in a test when a timer is set to exit Insert mode 2129--- a little later. Useful for testing CursorHoldI. 2130--- 2131--- Return value is always 0. 2132--- 2133--- @param string string 2134--- @param mode? string 2135--- @return any 2136function vim . fn . feedkeys ( string , mode ) end 2137 2138--- @deprecated 2139--- Lua: Prefer |uv.fs_access()| with `"R"` and |uv.fs_stat()| to exclude directories. 2140--- 2141--- Obsolete name for |filereadable()|. 2142--- 2143--- @param file string 2144--- @return any 2145function vim . fn . file_readable ( file ) end 2146 2147--- Lua: Prefer |uv.fs_copyfile()| with `{ excl = true }`; return semantics differ. 2148--- 2149--- Copy the file pointed to by the name {from} to {to}. The 2150--- result is a Number, which is |TRUE| if the file was copied 2151--- successfully, and |FALSE| when it failed. 2152--- If a file with name {to} already exists, it will fail. 2153--- Note that it does not handle directories (yet). 2154--- 2155--- This function is not available in the |sandbox|. 2156--- 2157--- @param from string 2158--- @param to string 2159--- @return 0|1 2160function vim . fn . filecopy ( from , to ) end 2161 2162--- Lua: Prefer |uv.fs_access()| with `"R"` and |uv.fs_stat()| to exclude directories. 2163--- 2164--- Returns |TRUE| if {file} exists, can be read, and is not 2165--- a directory, else |FALSE|. 2166--- 2167--- {file} is any expression, which is used as a String. If you 2168--- don't care about the file being readable you can use |glob()|. 2169--- 2170--- {file} is used as-is, you may want to expand wildcards first: >vim 2171--- echo filereadable('~/.vimrc') 2172--- < > 2173--- 0 2174--- < >vim 2175--- echo filereadable(expand('~/.vimrc')) 2176--- < > 2177--- 1 2178--- < 2179--- 2180--- @param file string 2181--- @return 0|1 2182function vim . fn . filereadable ( file ) end 2183 2184--- Lua: Prefer |uv.fs_access()| with `"W"` and |uv.fs_stat()| if you need Vim's `2` return for directories. 2185--- 2186--- Checks whether a file with the name {file} exists and can 2187--- be written. Returns 1 if so. If {file} doesn't exist, or 2188--- is not writable, the result is 0. If {file} is a 2189--- directory, and we can write to it, the result is 2. 2190--- 2191--- @param file string 2192--- @return 0|1 2193function vim . fn . filewritable ( file ) end 2194 2195--- Lua: Prefer |vim.tbl_filter()| for lists; dicts, strings, and blobs differ. 2196--- 2197--- {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 2198--- For each item in {expr1} evaluate {expr2} and when the result 2199--- is zero or false remove the item from the |List| or 2200--- |Dictionary|. Similarly for each byte in a |Blob| and each 2201--- character in a |String|. 2202--- 2203--- {expr2} must be a |string| or |Funcref|. 2204--- 2205--- If {expr2} is a |string|, inside {expr2} |v:val| has the value 2206--- of the current item. For a |Dictionary| |v:key| has the key 2207--- of the current item and for a |List| |v:key| has the index of 2208--- the current item. For a |Blob| |v:key| has the index of the 2209--- current byte. For a |String| |v:key| has the index of the 2210--- current character. 2211--- Examples: >vim 2212--- call filter(mylist, 'v:val !~ "OLD"') 2213--- <Removes the items where "OLD" appears. >vim 2214--- call filter(mydict, 'v:key >= 8') 2215--- <Removes the items with a key below 8. >vim 2216--- call filter(var, 0) 2217--- <Removes all the items, thus clears the |List| or |Dictionary|. 2218--- 2219--- Note that {expr2} is the result of expression and is then 2220--- used as an expression again. Often it is good to use a 2221--- |literal-string| to avoid having to double backslashes. 2222--- 2223--- If {expr2} is a |Funcref| it must take two arguments: 2224--- 1. the key or the index of the current item. 2225--- 2. the value of the current item. 2226--- The function must return |TRUE| if the item should be kept. 2227--- Example that keeps the odd items of a list: >vim 2228--- func Odd(idx, val) 2229--- return a:idx % 2 == 1 2230--- endfunc 2231--- call filter(mylist, function('Odd')) 2232--- <It is shorter when using a |lambda|: >vim 2233--- call filter(myList, {idx, val -> idx * val <= 42}) 2234--- <If you do not use "val" you can leave it out: >vim 2235--- call filter(myList, {idx -> idx % 2 == 1}) 2236--- < 2237--- For a |List| and a |Dictionary| the operation is done 2238--- in-place. If you want it to remain unmodified make a copy 2239--- first: >vim 2240--- let l = filter(copy(mylist), 'v:val =~ "KEEP"') 2241--- 2242--- <Returns {expr1}, the |List| or |Dictionary| that was filtered, 2243--- or a new |Blob| or |String|. 2244--- When an error is encountered while evaluating {expr2} no 2245--- further items in {expr1} are processed. 2246--- When {expr2} is a Funcref errors inside a function are 2247--- ignored, unless it was defined with the "abort" flag. 2248--- 2249--- @param expr1 string|table 2250--- @param expr2 string|function 2251--- @return any 2252function vim . fn . filter ( expr1 , expr2 ) end 2253 2254--- Lua: Prefer |vim.fs.find()| with `type = 'directory'`; `path`, `count`, and return semantics differ. 2255--- 2256--- Find directory {name} in {path}. Supports both downwards and 2257--- upwards recursive directory searches. See |file-searching| 2258--- for the syntax of {path}. 2259--- 2260--- Returns the path of the first found match. When the found 2261--- directory is below the current directory a relative path is 2262--- returned. Otherwise a full path is returned. 2263--- If {path} is omitted or empty then 'path' is used. 2264--- 2265--- If the optional {count} is given, find {count}'s occurrence of 2266--- {name} in {path} instead of the first one. 2267--- When {count} is negative return all the matches in a |List|. 2268--- 2269--- Returns an empty string if the directory is not found. 2270--- 2271--- This is quite similar to the ex-command `:find`. 2272--- 2273--- @param name string 2274--- @param path? string 2275--- @param count? integer 2276--- @return string|string[] 2277function vim . fn . finddir ( name , path , count ) end 2278 2279--- Lua: Prefer |vim.fs.find()|; `path`, `count`, return semantics, and |'suffixesadd'| handling differ. 2280--- 2281--- Just like |finddir()|, but find a file instead of a directory. 2282--- Uses 'suffixesadd'. 2283--- Example: >vim 2284--- echo findfile("tags.vim", ".;") 2285--- <Searches from the directory of the current file upwards until 2286--- it finds the file "tags.vim". 2287--- 2288--- @param name string 2289--- @param path? string 2290--- @param count? integer 2291--- @return string|string[] 2292function vim . fn . findfile ( name , path , count ) end 2293 2294--- Lua: Prefer `vim.iter(list):flatten():totable()` for a new flattened list; in-place updates and `maxdepth` differ. 2295--- 2296--- Flatten {list} up to {maxdepth} levels. Without {maxdepth} 2297--- the result is a |List| without nesting, as if {maxdepth} is 2298--- a very large number. 2299--- The {list} is changed in place, use |flattennew()| if you do 2300--- not want that. 2301--- *E900* 2302--- {maxdepth} means how deep in nested lists changes are made. 2303--- {list} is not modified when {maxdepth} is 0. 2304--- {maxdepth} must be positive number. 2305--- 2306--- If there is an error the number zero is returned. 2307--- 2308--- Example: >vim 2309--- echo flatten([1, [2, [3, 4]], 5]) 2310--- < [1, 2, 3, 4, 5] >vim 2311--- echo flatten([1, [2, [3, 4]], 5], 1) 2312--- < [1, 2, [3, 4], 5] 2313--- 2314--- @param list any[] 2315--- @param maxdepth? integer 2316--- @return any[]|0 2317function vim . fn . flatten ( list , maxdepth ) end 2318 2319--- Lua: Prefer `vim.iter(list):flatten():totable()` for a new flattened list; `maxdepth` differs. 2320--- 2321--- Like |flatten()| but first make a copy of {list}. 2322--- 2323--- @param list any[] 2324--- @param maxdepth? integer 2325--- @return any[]|0 2326function vim . fn . flattennew ( list , maxdepth ) end 2327 2328--- Lua: Prefer |math.modf()| (first return value). 2329--- 2330--- Convert {expr} to a Number by omitting the part after the 2331--- decimal point. 2332--- {expr} must evaluate to a |Float| or a |Number|. 2333--- Returns 0 if {expr} is not a |Float| or a |Number|. 2334--- When the value of {expr} is out of range for a |Number| the 2335--- result is truncated to 0x7fffffff or -0x7fffffff (or when 2336--- 64-bit Number support is enabled, 0x7fffffffffffffff or 2337--- -0x7fffffffffffffff). NaN results in -0x80000000 (or when 2338--- 64-bit Number support is enabled, -0x8000000000000000). 2339--- Examples: >vim 2340--- echo float2nr(3.95) 2341--- < 3 >vim 2342--- echo float2nr(-23.45) 2343--- < -23 >vim 2344--- echo float2nr(1.0e100) 2345--- < 2147483647 (or 9223372036854775807) >vim 2346--- echo float2nr(-1.0e150) 2347--- < -2147483647 (or -9223372036854775807) >vim 2348--- echo float2nr(1.0e-100) 2349--- < 0 2350--- 2351--- @param expr number 2352--- @return any 2353function vim . fn . float2nr ( expr ) end 2354 2355--- Lua: Prefer |math.floor()|. 2356--- 2357--- Return the largest integral value less than or equal to 2358--- {expr} as a |Float| (round down). 2359--- {expr} must evaluate to a |Float| or a |Number|. 2360--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 2361--- Examples: >vim 2362--- echo floor(1.856) 2363--- < 1.0 >vim 2364--- echo floor(-5.456) 2365--- < -6.0 >vim 2366--- echo floor(4.0) 2367--- < 4.0 2368--- 2369--- @param expr number 2370--- @return any 2371function vim . fn . floor ( expr ) end 2372 2373--- Lua: Prefer |math.fmod()|. 2374--- 2375--- Return the remainder of {expr1} / {expr2}, even if the 2376--- division is not representable. Returns {expr1} - i * {expr2} 2377--- for some integer i such that if {expr2} is non-zero, the 2378--- result has the same sign as {expr1} and magnitude less than 2379--- the magnitude of {expr2}. If {expr2} is zero, the value 2380--- returned is zero. The value returned is a |Float|. 2381--- {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 2382--- Returns 0.0 if {expr1} or {expr2} is not a |Float| or a 2383--- |Number|. 2384--- Examples: >vim 2385--- echo fmod(12.33, 1.22) 2386--- < 0.13 >vim 2387--- echo fmod(-12.33, 1.22) 2388--- < -0.13 2389--- 2390--- @param expr1 number 2391--- @param expr2 number 2392--- @return any 2393function vim . fn . fmod ( expr1 , expr2 ) end 2394 2395--- Escapes {filepath} for use as a command argument. 2396--- 2397--- (Note: To open a literal filepath programmatically use 2398--- `bufadd(vim.fs.normalize(…))`, see |open-file|.) 2399--- 2400--- All characters that have a special meaning, such as `'%'` and 2401--- `'|'` are escaped with a backslash. For most systems the 2402--- characters escaped are: > 2403--- \t\n *?[{`$\\%#'\"|!< 2404--- <For systems where a backslash appears in a filename, it 2405--- depends on the value of 'isfname'. A leading '+' and '>' is 2406--- also escaped (special after |:edit| and |:write|). And a "-" 2407--- by itself (special after |:cd|). 2408--- Returns an empty string on error. 2409--- Example: >vim 2410--- let fname = '+some str%nge|name' 2411--- exe "edit " .. fnameescape(fname) 2412--- <results in executing: >vim 2413--- edit \+some\ str\%nge\|name 2414--- < 2415--- 2416--- @param filepath string 2417--- @return string 2418function vim . fn . fnameescape ( filepath ) end 2419 2420--- Lua: Prefer |vim.fs.dirname()|, |vim.fs.basename()|, |vim.fs.abspath()|, and |vim.fs.normalize()| for common path modifiers; modifier coverage differs. 2421--- 2422--- Modify file name {fname} according to {mods}. {mods} is a 2423--- string of characters like it is used for file names on the 2424--- command line. See |filename-modifiers|. 2425--- Example: >vim 2426--- echo fnamemodify("main.c", ":p:h") 2427--- <results in: > 2428--- /home/user/vim/vim/src 2429--- <If {mods} is empty or an unsupported modifier is used then 2430--- {fname} is returned. 2431--- When {fname} is empty then with {mods} ":h" returns ".", so 2432--- that `:cd` can be used with it. This is different from 2433--- expand('%:h') without a buffer name, which returns an empty 2434--- string. 2435--- Note: Environment variables don't work in {fname}, use 2436--- |expand()| first then. 2437--- 2438--- @param fname string 2439--- @param mods string 2440--- @return string 2441function vim . fn . fnamemodify ( fname , mods ) end 2442 2443--- Returns the first line number of the closed fold containing 2444--- line {lnum}. If the line {lnum} is not in a closed fold, 2445--- -1 is returned. 2446--- {lnum} is used like with |getline()|. Thus "." is the current 2447--- line, "'m" mark m, etc. 2448--- 2449--- @param lnum integer|string 2450--- @return integer 2451function vim . fn . foldclosed ( lnum ) end 2452 2453--- Returns the last line number of the closed fold containing 2454--- line {lnum}. If the line {lnum} is not in a closed fold, 2455--- -1 is returned. 2456--- {lnum} is used like with |getline()|. Thus "." is the current 2457--- line, "'m" mark m, etc. 2458--- 2459--- @param lnum integer|string 2460--- @return integer 2461function vim . fn . foldclosedend ( lnum ) end 2462 2463--- Returns the fold nesting level of line {lnum} in the current 2464--- buffer. {lnum} is used like with |getline()| ("." is the 2465--- current line, "'m" mark m, etc). 2466--- 2467--- For nested folds the deepest level is returned. If there is 2468--- no fold at line {lnum}, zero is returned. It doesn't matter 2469--- if the folds are open or closed. When used while updating 2470--- folds (from 'foldexpr') -1 is returned for lines where folds 2471--- are still to be updated and the foldlevel is unknown. As 2472--- a special case the level of the previous line is usually 2473--- available. 2474--- 2475--- @param lnum integer|string 2476--- @return integer 2477function vim . fn . foldlevel ( lnum ) end 2478 2479--- Returns a String, to be displayed for a closed fold. This is 2480--- the default function used for the 'foldtext' option and should 2481--- only be called from evaluating 'foldtext'. It uses the 2482--- |v:foldstart|, |v:foldend| and |v:folddashes| variables. 2483--- The returned string looks like this: > 2484--- +-- 45 lines: abcdef 2485--- <The number of leading dashes depends on the foldlevel. The 2486--- "45" is the number of lines in the fold. "abcdef" is the text 2487--- in the first non-blank line of the fold. Leading white space, 2488--- "//" or "/*" and the text from the 'foldmarker' and 2489--- 'commentstring' options is removed. 2490--- When used to draw the actual foldtext, the rest of the line 2491--- will be filled with the fold char from the 'fillchars' 2492--- setting. 2493--- Returns an empty string when there is no fold. 2494--- 2495--- @return string 2496function vim . fn . foldtext () end 2497 2498--- Returns the text that is displayed for the closed fold at line 2499--- {lnum}. Evaluates 'foldtext' in the appropriate context. 2500--- When there is no closed fold at {lnum} an empty string is 2501--- returned. 2502--- {lnum} is used like with |getline()|. Thus "." is the current 2503--- line, "'m" mark m, etc. 2504--- Useful when exporting folded text, e.g., to HTML. 2505--- 2506--- @param lnum integer|string 2507--- @return string 2508function vim . fn . foldtextresult ( lnum ) end 2509 2510--- Lua: Prefer |pairs()| or |ipairs()|. 2511--- 2512--- {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 2513--- For each item in {expr1} execute {expr2}. {expr1} is not 2514--- modified; its values may be, as with |:lockvar| 1. |E741| 2515--- See |map()| and |filter()| to modify {expr1}. 2516--- 2517--- {expr2} must be a |string| or |Funcref|. 2518--- 2519--- If {expr2} is a |string|, inside {expr2} |v:val| has the value 2520--- of the current item. For a |Dictionary| |v:key| has the key 2521--- of the current item and for a |List| |v:key| has the index of 2522--- the current item. For a |Blob| |v:key| has the index of the 2523--- current byte. For a |String| |v:key| has the index of the 2524--- current character. 2525--- Examples: >vim 2526--- call foreach(mylist, 'let used[v:val] = v:true') 2527--- <This records the items that are in the {expr1} list. 2528--- 2529--- Note that {expr2} is the result of expression and is then used 2530--- as a command. Often it is good to use a |literal-string| to 2531--- avoid having to double backslashes. 2532--- 2533--- If {expr2} is a |Funcref| it must take two arguments: 2534--- 1. the key or the index of the current item. 2535--- 2. the value of the current item. 2536--- With a lambda you don't get an error if it only accepts one 2537--- argument. 2538--- If the function returns a value, it is ignored. 2539--- 2540--- Returns {expr1} in all cases. 2541--- When an error is encountered while executing {expr2} no 2542--- further items in {expr1} are processed. 2543--- When {expr2} is a Funcref errors inside a function are 2544--- ignored, unless it was defined with the "abort" flag. 2545--- 2546--- @param expr1 string|table 2547--- @param expr2 string|function 2548--- @return string|table 2549function vim . fn . foreach ( expr1 , expr2 ) end 2550 2551--- Get the full command name from a short abbreviated command 2552--- name; see |20.2| for details on command abbreviations. 2553--- 2554--- The string argument {name} may start with a `:` and can 2555--- include a [range], these are skipped and not returned. 2556--- Returns an empty string if a command doesn't exist or if it's 2557--- ambiguous (for user-defined commands). 2558--- 2559--- Note: Command validation is not performed. Results depend on 2560--- Vim's internal command-specific identification rules. 2561--- Examples: 2562--- >vim 2563--- echo [fullcommand('s')] |" ['substitute'] 2564--- echo [fullcommand('sub')] |" ['substitute'] 2565--- echo [fullcommand(': mark word')] |" ['mark'] 2566--- echo [fullcommand(': markword')] |" [''] 2567--- echo [fullcommand('en')] |" ['endif'] 2568--- < 2569--- 2570--- @param name string 2571--- @return string 2572function vim . fn . fullcommand ( name ) end 2573 2574--- Just like |function()|, but the returned Funcref will lookup 2575--- the function by reference, not by name. This matters when the 2576--- function {name} is redefined later. 2577--- 2578--- Unlike |function()|, {name} must be an existing user function. 2579--- It only works for an autoloaded function if it has already 2580--- been loaded (to avoid mistakenly loading the autoload script 2581--- when only intending to use the function name, use |function()| 2582--- instead). {name} cannot be a builtin function. 2583--- Returns 0 on error. 2584--- 2585--- @param name string 2586--- @param arglist? any 2587--- @param dict? any 2588--- @return any 2589function vim . fn . funcref ( name , arglist , dict ) end 2590 2591--- Return a |Funcref| variable that refers to function {name}. 2592--- {name} can be the name of a user defined function or an 2593--- internal function. 2594--- 2595--- {name} can also be a Funcref or a partial. When it is a 2596--- partial the dict stored in it will be used and the {dict} 2597--- argument is not allowed. E.g.: >vim 2598--- let FuncWithArg = function(dict.Func, [arg]) 2599--- let Broken = function(dict.Func, [arg], dict) 2600--- < 2601--- When using the Funcref the function will be found by {name}, 2602--- also when it was redefined later. Use |funcref()| to keep the 2603--- same function. 2604--- 2605--- When {arglist} or {dict} is present this creates a partial. 2606--- That means the argument list and/or the dictionary is stored 2607--- in the Funcref and will be used when the Funcref is called. 2608--- 2609--- The arguments are passed to the function in front of other 2610--- arguments, but after any argument from |method|. Example: >vim 2611--- func Callback(arg1, arg2, name) 2612--- "... 2613--- endfunc 2614--- let Partial = function('Callback', ['one', 'two']) 2615--- "... 2616--- call Partial('name') 2617--- <Invokes the function as with: >vim 2618--- call Callback('one', 'two', 'name') 2619--- 2620--- <With a |method|: >vim 2621--- func Callback(one, two, three) 2622--- "... 2623--- endfunc 2624--- let Partial = function('Callback', ['two']) 2625--- "... 2626--- eval 'one'->Partial('three') 2627--- <Invokes the function as with: >vim 2628--- call Callback('one', 'two', 'three') 2629--- 2630--- <The function() call can be nested to add more arguments to the 2631--- Funcref. The extra arguments are appended to the list of 2632--- arguments. Example: >vim 2633--- func Callback(arg1, arg2, name) 2634--- "... 2635--- endfunc 2636--- let Func = function('Callback', ['one']) 2637--- let Func2 = function(Func, ['two']) 2638--- "... 2639--- call Func2('name') 2640--- <Invokes the function as with: >vim 2641--- call Callback('one', 'two', 'name') 2642--- 2643--- <The Dictionary is only useful when calling a "dict" function. 2644--- In that case the {dict} is passed in as "self". Example: >vim 2645--- function Callback() dict 2646--- echo "called for " .. self.name 2647--- endfunction 2648--- "... 2649--- let context = {"name": "example"} 2650--- let Func = function('Callback', context) 2651--- "... 2652--- call Func() " will echo: called for example 2653--- <The use of function() is not needed when there are no extra 2654--- arguments, these two are equivalent, if Callback() is defined 2655--- as context.Callback(): >vim 2656--- let Func = function('Callback', context) 2657--- let Func = context.Callback 2658--- 2659--- <The argument list and the Dictionary can be combined: >vim 2660--- function Callback(arg1, count) dict 2661--- "... 2662--- endfunction 2663--- let context = {"name": "example"} 2664--- let Func = function('Callback', ['one'], context) 2665--- "... 2666--- call Func(500) 2667--- <Invokes the function as with: >vim 2668--- call context.Callback('one', 500) 2669--- < 2670--- Returns 0 on error. 2671--- 2672--- @param name string 2673--- @param arglist? any 2674--- @param dict? any 2675--- @return any 2676vim . fn [ 'function' ] =function ( name , arglist , dict ) end 2677 2678--- Cleanup unused |Lists| and |Dictionaries| that have circular 2679--- references. 2680--- 2681--- There is hardly ever a need to invoke this function, as it is 2682--- automatically done when Vim runs out of memory or is waiting 2683--- for the user to press a key after 'updatetime'. Items without 2684--- circular references are always freed when they become unused. 2685--- This is useful if you have deleted a very big |List| and/or 2686--- |Dictionary| with circular references in a script that runs 2687--- for a long time. 2688--- 2689--- When the optional {atexit} argument is one, garbage 2690--- collection will also be done when exiting Vim, if it wasn't 2691--- done before. This is useful when checking for memory leaks. 2692--- 2693--- The garbage collection is not done immediately but only when 2694--- it's safe to perform. This is when waiting for the user to 2695--- type a character. 2696--- 2697--- @param atexit? boolean 2698--- @return any 2699function vim . fn . garbagecollect ( atexit ) end 2700 2701--- Get item {idx} from |List| {list}. When this item is not 2702--- available return {default}. Return zero when {default} is 2703--- omitted. 2704--- 2705--- Get byte {idx} from |Blob| {blob}. When this byte is not 2706--- available return {default}. Return -1 when {default} is 2707--- omitted. 2708--- 2709--- Get item with key {key} from |Dictionary| {dict}. When this 2710--- item is not available return {default}. Return zero when 2711--- {default} is omitted. Useful example: >vim 2712--- let val = get(g:, 'var_name', 'default') 2713--- <This gets the value of g:var_name if it exists, and uses 2714--- "default" when it does not exist. 2715--- 2716--- Get item {what} from |Funcref| {func}. Possible values for 2717--- {what} are: 2718--- "name" The function name 2719--- "func" The function 2720--- "dict" The dictionary 2721--- "args" The list with arguments 2722--- "arity" A dictionary with information about the number of 2723--- arguments accepted by the function (minus the 2724--- {arglist}) with the following fields: 2725--- required the number of positional arguments 2726--- optional the number of optional arguments, 2727--- in addition to the required ones 2728--- varargs |TRUE| if the function accepts a 2729--- variable number of arguments |...| 2730--- 2731--- Note: There is no error, if the {arglist} of 2732--- the Funcref contains more arguments than the 2733--- Funcref expects, it's not validated. 2734--- 2735--- Returns zero on error. 2736--- 2737--- @overload fun(blob: string, idx: integer, default?: any): (any) 2738--- @overload fun(dict: table<string,any>, key: string, default?: any): (any) 2739--- @overload fun(func: function, what: string): (any) 2740--- @param list any[] 2741--- @param idx integer 2742--- @param default? any 2743--- @return any 2744function vim . fn . get ( list , idx , default ) end 2745 2746--- Get information about buffers as a List of Dictionaries. 2747--- 2748--- Without an argument information about all the buffers is 2749--- returned. 2750--- 2751--- When the argument is a |Dictionary| only the buffers matching 2752--- the specified criteria are returned. The following keys can 2753--- be specified in {dict}: 2754--- buflisted include only listed buffers. 2755--- bufloaded include only loaded buffers. 2756--- bufmodified include only modified buffers. 2757--- 2758--- Otherwise, {buf} specifies a particular buffer to return 2759--- information for. For the use of {buf}, see |bufname()| 2760--- above. If the buffer is found the returned List has one item. 2761--- Otherwise the result is an empty list. 2762--- 2763--- Each returned List item is a dictionary with the following 2764--- entries: 2765--- bufnr Buffer number. 2766--- changed TRUE if the buffer is modified. 2767--- changedtick Number of changes made to the buffer. 2768--- command TRUE if the buffer belongs to the 2769--- command-line window |cmdwin|. 2770--- hidden TRUE if the buffer is hidden. 2771--- lastused Timestamp in seconds, like 2772--- |localtime()|, when the buffer was 2773--- last used. 2774--- listed TRUE if the buffer is listed. 2775--- lnum Line number used for the buffer when 2776--- opened in the current window. 2777--- Only valid if the buffer has been 2778--- displayed in the window in the past. 2779--- If you want the line number of the 2780--- last known cursor position in a given 2781--- window, use |line()|: >vim 2782--- echo line('.', {winid}) 2783--- < 2784--- linecount Number of lines in the buffer (only 2785--- valid when loaded) 2786--- loaded TRUE if the buffer is loaded. 2787--- name Full path to the file in the buffer. 2788--- signs List of signs placed in the buffer. 2789--- Each list item is a dictionary with 2790--- the following fields: 2791--- id sign identifier 2792--- lnum line number 2793--- name sign name 2794--- variables A reference to the dictionary with 2795--- buffer-local variables. 2796--- windows List of |window-ID|s that display this 2797--- buffer 2798--- 2799--- Examples: >vim 2800--- for buf in getbufinfo() 2801--- echo buf.name 2802--- endfor 2803--- for buf in getbufinfo({'buflisted':1}) 2804--- if buf.changed 2805--- " .... 2806--- endif 2807--- endfor 2808--- < 2809--- To get buffer-local options use: >vim 2810--- getbufvar({bufnr}, '&option_name') 2811--- < 2812--- 2813--- @overload fun(dict?: vim.fn.getbufinfo.dict): (vim.fn.getbufinfo.ret.item[]) 2814--- @param buf? integer|string 2815--- @return vim.fn.getbufinfo.ret.item[] 2816function vim . fn . getbufinfo ( buf ) end 2817 2818--- Lua: Prefer |nvim_buf_get_lines()|. 2819--- 2820--- Return a |List| with the lines starting from {lnum} to {end} 2821--- (inclusive) in the buffer {buf}. If {end} is omitted, a 2822--- |List| with only the line {lnum} is returned. See 2823--- `getbufoneline()` for only getting the line. 2824--- 2825--- For the use of {buf}, see |bufname()| above. 2826--- 2827--- For {lnum} and {end} "$" can be used for the last line of the 2828--- buffer. Otherwise a number must be used. 2829--- 2830--- When {lnum} is smaller than 1 or bigger than the number of 2831--- lines in the buffer, an empty |List| is returned. 2832--- 2833--- When {end} is greater than the number of lines in the buffer, 2834--- it is treated as {end} is set to the number of lines in the 2835--- buffer. When {end} is before {lnum} an empty |List| is 2836--- returned. 2837--- 2838--- This function works only for loaded buffers. For unloaded and 2839--- non-existing buffers, an empty |List| is returned. 2840--- 2841--- Example: >vim 2842--- let lines = getbufline(bufnr("myfile"), 1, "$") 2843--- < 2844--- 2845--- @param buf integer|string 2846--- @param lnum integer 2847--- @param end_? integer 2848--- @return string[] 2849function vim . fn . getbufline ( buf , lnum , end_ ) end 2850 2851--- Lua: Prefer |nvim_buf_get_lines()|. 2852--- 2853--- Just like `getbufline()` but only get one line and return it 2854--- as a string. 2855--- 2856--- @param buf integer|string 2857--- @param lnum integer 2858--- @return string 2859function vim . fn . getbufoneline ( buf , lnum ) end 2860 2861--- Lua: Prefer |nvim_buf_get_var()| or |vim.b| after resolving {buf} to a bufnr; option names use |nvim_get_option_value()| or |vim.bo|. 2862--- 2863--- Gets the value of a buffer-local variable or option {varname} 2864--- in buffer {buf}. 2865--- 2866--- {varname} is a string: 2867--- - Name of the variable (without "b:"). 2868--- - If empty, gets a |Dictionary| of all buffer-local variables. 2869--- - If "&", gets a |Dictionary| of all buffer-local options. 2870--- - If it starts with "&", gets the value of a buffer-local 2871--- option. 2872--- 2873--- {buf} has the same form as in |bufname()|. 2874--- 2875--- Also works for a global or buffer-local option. But not for 2876--- a global variable, window-local variable or window-local 2877--- option. 2878--- 2879--- When the buffer or variable doesn't exist, {def} or an empty 2880--- string is returned; there is no error. 2881--- 2882--- Examples: >vim 2883--- let bufmodified = getbufvar(1, "&mod") 2884--- echo "todo myvar = " .. getbufvar("todo", "myvar") 2885--- < 2886--- 2887--- @param buf integer|string 2888--- @param varname string 2889--- @param def? any 2890--- @return any 2891function vim . fn . getbufvar ( buf , varname , def ) end 2892 2893--- Returns a |List| of cell widths of character ranges overridden 2894--- by |setcellwidths()|. The format is equal to the argument of 2895--- |setcellwidths()|. If no character ranges have their cell 2896--- widths overridden, an empty List is returned. 2897--- 2898--- @return any 2899function vim . fn . getcellwidths () end 2900 2901--- Returns the |changelist| for the buffer {buf}. For the use 2902--- of {buf}, see |bufname()| above. If buffer {buf} doesn't 2903--- exist, an empty list is returned. 2904--- 2905--- The returned list contains two entries: a list with the change 2906--- locations and the current position in the list. Each 2907--- entry in the change list is a dictionary with the following 2908--- entries: 2909--- col column number 2910--- coladd column offset for 'virtualedit' 2911--- lnum line number 2912--- If buffer {buf} is the current buffer, then the current 2913--- position refers to the position in the list. For other 2914--- buffers, it is set to the length of the list. 2915--- 2916--- @param buf? integer|string 2917--- @return table[] 2918function vim . fn . getchangelist ( buf ) end 2919 2920--- Get a single character from the user or input stream. 2921--- If {expr} is omitted or is -1, wait until a character is 2922--- available. 2923--- If {expr} is 0, only get a character when one is available. 2924--- Return zero otherwise. 2925--- If {expr} is 1, only check if a character is available, it is 2926--- not consumed. Return zero if no character available. 2927--- To always get a string, specify "number" as |FALSE| in {opts}. 2928--- 2929--- Without {expr} and when {expr} is 0 a whole character or 2930--- special key is returned. If it is a single character, the 2931--- result is a Number. Use |nr2char()| to convert it to a String. 2932--- Otherwise a String is returned with the encoded character. 2933--- For a special key it's a String with a sequence of bytes 2934--- starting with 0x80 (decimal: 128). This is the same value as 2935--- the String "\<Key>", e.g., "\<Left>". The returned value is 2936--- also a String when a modifier (shift, control, alt) was used 2937--- that is not included in the character. |keytrans()| can also 2938--- be used to convert a returned String into a readable form. 2939--- 2940--- When {expr} is 0 and Esc is typed, there will be a short delay 2941--- while Vim waits to see if this is the start of an escape 2942--- sequence. 2943--- 2944--- When {expr} is 1 only the first byte is returned. For a 2945--- one-byte character it is the character itself as a number. 2946--- Use |nr2char()| to convert it to a String. 2947--- 2948--- Use |getcharmod()| to obtain any additional modifiers. 2949--- 2950--- The optional argument {opts} is a Dict and supports the 2951--- following items: 2952--- 2953--- cursor A String specifying cursor behavior 2954--- when waiting for a character. 2955--- "hide": hide the cursor. 2956--- "keep": keep current cursor unchanged. 2957--- "msg": move cursor to message area. 2958--- (default: automagically decide 2959--- between "keep" and "msg") 2960--- 2961--- number If |TRUE|, return a Number when getting 2962--- a single character. 2963--- If |FALSE|, the return value is always 2964--- converted to a String, and an empty 2965--- String (instead of 0) is returned when 2966--- no character is available. 2967--- (default: |TRUE|) 2968--- 2969--- simplify If |TRUE|, include modifiers in the 2970--- character if possible. E.g., return 2971--- the same value for CTRL-I and <Tab>. 2972--- If |FALSE|, don't include modifiers in 2973--- the character. 2974--- (default: |TRUE|) 2975--- 2976--- When the user clicks a mouse button, the mouse event will be 2977--- returned. The position can then be found in |v:mouse_col|, 2978--- |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. 2979--- |getmousepos()| can also be used. Mouse move events will be 2980--- ignored. 2981--- This example positions the mouse as it would normally happen: >vim 2982--- let c = getchar() 2983--- if c == "\<LeftMouse>" && v:mouse_win > 0 2984--- exe v:mouse_win .. "wincmd w" 2985--- exe v:mouse_lnum 2986--- exe "normal " .. v:mouse_col .. "|" 2987--- endif 2988--- < 2989--- There is no prompt, you will somehow have to make clear to the 2990--- user that a character has to be typed. The screen is not 2991--- redrawn, e.g. when resizing the window. 2992--- 2993--- There is no mapping for the character. 2994--- Key codes are replaced, thus when the user presses the <Del> 2995--- key you get the code for the <Del> key, not the raw character 2996--- sequence. Examples: >vim 2997--- getchar() == "\<Del>" 2998--- getchar() == "\<S-Left>" 2999--- <This example redefines "f" to ignore case: >vim 3000--- nmap f :call FindChar()<CR> 3001--- function FindChar() 3002--- let c = nr2char(getchar()) 3003--- while col('.') < col('$') - 1 3004--- normal l 3005--- if getline('.')[col('.') - 1] ==? c 3006--- break 3007--- endif 3008--- endwhile 3009--- endfunction 3010--- < 3011--- 3012--- @param expr? -1|0|1 3013--- @param opts? table 3014--- @return integer|string 3015function vim . fn . getchar ( expr , opts ) end 3016 3017--- Returns the state of the keyboard modifiers for the last 3018--- character obtained with |getchar()| or in another way. 3019--- These values are added together: 3020--- 2 shift 3021--- 4 control 3022--- 8 alt (meta) 3023--- 16 meta (when it's different from ALT) 3024--- 32 mouse double click 3025--- 64 mouse triple click 3026--- 96 mouse quadruple click (== 32 + 64) 3027--- 128 command (Mac) or super 3028--- Only the modifiers that have not been included in the 3029--- character itself are obtained. Thus Shift-a results in "A" 3030--- without a modifier. Returns 0 if no modifiers are used. 3031--- 3032--- @return integer 3033function vim . fn . getcharmod () end 3034 3035--- Same as |getpos()|, except the column-number is 3036--- character-indexed (UTF-8) instead of byte-indexed. 3037--- 3038--- If |getpos()| returns |v:maxcol|, then getcharpos() returns 3039--- the index of the last character. 3040--- 3041--- Example: 3042--- With the cursor on '세' in line 5 with text "여보세요": >vim 3043--- getcharpos('.') returns [0, 5, 3, 0] 3044--- getpos('.') returns [0, 5, 7, 0] 3045--- < 3046--- 3047--- @param expr string 3048--- @return integer[] 3049function vim . fn . getcharpos ( expr ) end 3050 3051--- Return the current character search information as a {dict} 3052--- with the following entries: 3053--- 3054--- char character previously used for a character 3055--- search (|t|, |f|, |T|, or |F|); empty string 3056--- if no character search has been performed 3057--- forward direction of character search; 1 for forward, 3058--- 0 for backward 3059--- until type of character search; 1 for a |t| or |T| 3060--- character search, 0 for an |f| or |F| 3061--- character search 3062--- 3063--- This can be useful to always have |;| and |,| search 3064--- forward/backward regardless of the direction of the previous 3065--- character search: >vim 3066--- nnoremap <expr> ; getcharsearch().forward ? ';' : ',' 3067--- nnoremap <expr> , getcharsearch().forward ? ',' : ';' 3068--- <Also see |setcharsearch()|. 3069--- 3070--- @return { char: string, forward: 1|0, until: 1|0 } 3071function vim . fn . getcharsearch () end 3072 3073--- The same as |getchar()|, except that this always returns a 3074--- String, and "number" isn't allowed in {opts}. 3075--- 3076--- @param expr? -1|0|1 3077--- @param opts? table 3078--- @return string 3079function vim . fn . getcharstr ( expr , opts ) end 3080 3081--- Return completion pattern of the current command-line. 3082--- Only works when the command line is being edited, thus 3083--- requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3084--- Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3085--- |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|. 3086--- Returns an empty string when completion is not defined. 3087--- 3088--- @return string 3089function vim . fn . getcmdcomplpat () end 3090 3091--- Return the type of the current command-line completion. 3092--- Only works when the command line is being edited, thus 3093--- requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3094--- See |:command-completion| for the return string. 3095--- Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3096--- |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|. 3097--- Returns an empty string when completion is not defined. 3098--- 3099--- To get the type of the command-line completion for a specified 3100--- string, use |getcompletiontype()|. 3101--- 3102--- @return string 3103function vim . fn . getcmdcompltype () end 3104 3105--- Return the current command-line input. Only works when the 3106--- command line is being edited, thus requires use of 3107--- |c_CTRL-\_e| or |c_CTRL-R_=|. 3108--- Example: >vim 3109--- cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> 3110--- <Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|, 3111--- |getcmdprompt()| and |setcmdline()|. 3112--- Returns an empty string when entering a password or using 3113--- |inputsecret()|. 3114--- 3115--- @return string 3116function vim . fn . getcmdline () end 3117 3118--- Return the position of the cursor in the command line as a 3119--- byte count. The first column is 1. 3120--- Only works when editing the command line, thus requires use of 3121--- |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3122--- Returns 0 otherwise. 3123--- Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, 3124--- |getcmdprompt()| and |setcmdline()|. 3125--- 3126--- @return integer 3127function vim . fn . getcmdpos () end 3128 3129--- Return the current command-line prompt when using functions 3130--- like |input()| or |confirm()|. 3131--- Only works when the command line is being edited, thus 3132--- requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. 3133--- Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|, 3134--- |setcmdpos()| and |setcmdline()|. 3135--- 3136--- @return string 3137function vim . fn . getcmdprompt () end 3138 3139--- Return the screen position of the cursor in the command line 3140--- as a byte count. The first column is 1. 3141--- Instead of |getcmdpos()|, it adds the prompt position. 3142--- Only works when editing the command line, thus requires use of 3143--- |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3144--- Returns 0 otherwise. 3145--- Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and 3146--- |setcmdline()|. 3147--- 3148--- @return integer 3149function vim . fn . getcmdscreenpos () end 3150 3151--- Return the current command-line type. Possible return values 3152--- are: 3153--- : normal Ex command 3154--- > debug mode command |debug-mode| 3155--- / forward search command 3156--- ? backward search command 3157--- \@ |input()| command 3158--- `-` |:insert| or |:append| command 3159--- = |i_CTRL-R_=| 3160--- Only works when editing the command line, thus requires use of 3161--- |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 3162--- Returns an empty string otherwise. 3163--- Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|. 3164--- 3165--- @return ':'|'>'|'/'|'?'|'@'|'-'|'='|'' 3166function vim . fn . getcmdtype () end 3167 3168--- Return the current |command-line-window| type. Possible return 3169--- values are the same as |getcmdtype()|. Returns an empty string 3170--- when not in the command-line window. 3171--- 3172--- @return ':'|'>'|'/'|'?'|'@'|'-'|'='|'' 3173function vim . fn . getcmdwintype () end 3174 3175--- Return a list of command-line completion matches. The String 3176--- {type} argument specifies what for. The following completion 3177--- types are supported: 3178--- 3179--- arglist file names in argument list 3180--- augroup autocmd groups 3181--- buffer buffer names 3182--- breakpoint |:breakadd| and |:breakdel| suboptions 3183--- cmdline |cmdline-completion| result 3184--- color color schemes 3185--- command Ex command 3186--- compiler compilers 3187--- custom,{func} custom completion, defined via {func} 3188--- customlist,{func} custom completion, defined via {func} 3189--- diff_buffer |:diffget| and |:diffput| completion 3190--- dir directory names 3191--- dir_in_path directory names in 'cdpath' 3192--- environment environment variable names 3193--- event autocommand events 3194--- expression Vim expression 3195--- file file and directory names 3196--- file_in_path file and directory names in 'path' 3197--- filetype filetype names 'filetype' 3198--- filetypecmd |:filetype| suboptions 3199--- function function name 3200--- help help subjects 3201--- highlight highlight groups 3202--- history |:history| suboptions 3203--- keymap keyboard mappings 3204--- locale locale names (as output of locale -a) 3205--- mapclear buffer argument 3206--- mapping mapping name 3207--- menu menus 3208--- messages |:messages| suboptions 3209--- option options 3210--- packadd optional package |pack-add| names 3211--- retab |:retab| suboptions 3212--- runtime |:runtime| completion 3213--- scriptnames sourced script names |:scriptnames| 3214--- shellcmd Shell command 3215--- shellcmdline Shell command line with filename arguments 3216--- sign |:sign| suboptions 3217--- syntax syntax file names 'syntax' 3218--- syntime |:syntime| suboptions 3219--- tag tags 3220--- tag_listfiles tags, file names 3221--- user user names 3222--- var user variables 3223--- 3224--- If {pat} is an empty string, then all the matches are 3225--- returned. Otherwise only items matching {pat} are returned. 3226--- See |wildcards| for the use of special characters in {pat}. 3227--- 3228--- If the optional {filtered} flag is set to 1, then 'wildignore' 3229--- is applied to filter the results. Otherwise all the matches 3230--- are returned. The 'wildignorecase' option always applies. 3231--- 3232--- If the 'wildoptions' option contains "fuzzy", then fuzzy 3233--- matching is used to get the completion matches. Otherwise 3234--- regular expression matching is used. Thus this function 3235--- follows the user preference, what happens on the command line. 3236--- If you do not want this you can make 'wildoptions' empty 3237--- before calling getcompletion() and restore it afterwards. 3238--- 3239--- If {type} is "cmdline", then the |cmdline-completion| result is 3240--- returned. For example, to complete the possible values after 3241--- a ":call" command: >vim 3242--- echo getcompletion('call ', 'cmdline') 3243--- < 3244--- If there are no matches, an empty list is returned. An 3245--- invalid value for {type} produces an error. 3246--- 3247--- @param pat string 3248--- @param type string 3249--- @param filtered? boolean 3250--- @return string[] 3251function vim . fn . getcompletion ( pat , type , filtered ) end 3252 3253--- Return the type of the command-line completion using {pat}. 3254--- When no corresponding completion type is found, an empty 3255--- string is returned. 3256--- To get the current command-line completion type, use 3257--- |getcmdcompltype()|. 3258--- 3259--- @param pat string 3260--- @return string 3261function vim . fn . getcompletiontype ( pat ) end 3262 3263--- Lua: Prefer |nvim_win_get_cursor()|; return shape, 0-based column, and `curswant`/invalid-window semantics differ. 3264--- 3265--- Get the position of the cursor. This is like getpos('.'), but 3266--- includes an extra "curswant" item in the list: 3267--- [0, lnum, col, off, curswant] ~ 3268--- The "curswant" number is the preferred column when moving the 3269--- cursor vertically. After |$| command it will be a very large 3270--- number equal to |v:maxcol|. Also see |getcursorcharpos()| and 3271--- |getpos()|. 3272--- The first "bufnum" item is always zero. The byte position of 3273--- the cursor is returned in "col". To get the character 3274--- position, use |getcursorcharpos()|. 3275--- 3276--- The optional {winid} (|window-number| or |window-ID|) specifies 3277--- the window. The last known cursor position is returned, this 3278--- may be invalid for the current value of the buffer if it is not 3279--- the current window. 3280--- If {winid} is invalid a list with zeroes is returned. 3281--- 3282--- This can be used to save and restore the cursor position: >vim 3283--- let save_cursor = getcurpos() 3284--- MoveTheCursorAround 3285--- call setpos('.', save_cursor) 3286--- <Note that this only works within the window. See 3287--- |winrestview()| for restoring more state. 3288--- 3289--- @param winid? integer 3290--- @return [integer, integer, integer, integer, integer] 3291function vim . fn . getcurpos ( winid ) end 3292 3293--- Same as |getcurpos()| but the column number in the returned 3294--- List is a character index instead of a byte index. 3295--- 3296--- Example: 3297--- With the cursor on '보' in line 3 with text "여보세요": >vim 3298--- getcursorcharpos() " returns [0, 3, 2, 0, 3] 3299--- getcurpos() " returns [0, 3, 4, 0, 3] 3300--- < 3301--- 3302--- @param winid? integer 3303--- @return any 3304function vim . fn . getcursorcharpos ( winid ) end 3305 3306--- Without arguments, returns the effective |current-directory|. 3307--- With {winnr} (|window-number| or |window-ID|), {tabnr} or 3308--- {bufnr} the working directory of that scope is returned, 3309--- ignoring 'autochdir'. 3310--- 3311--- - If {winnr} is -1: gets the tabpage directory. 3312--- - If {winnr} and {tabnr} are both -1: gets the global 3313--- directory. 3314--- - Note: Vim returns an empty string when {tabnr} is -1. 3315--- - If {bufnr} is given: gets the buffer-local directory. 3316--- ({winnr} and {tabnr} must be -1.) 3317--- - An argument may be -1 only if preceding args are -1. *E5001* 3318--- 3319--- Tabs, windows and buffers are identified by their respective 3320--- numbers, 0 means current tab/window/buffer. Missing {tabnr} 3321--- implies 0 (missing {bufnr} does not; see below). Thus the 3322--- following are equivalent: >vim 3323--- getcwd(0) 3324--- getcwd(0, 0) 3325--- < 3326--- Each form reports its own scope or "wider", so e.g. {winnr} 3327--- never reports a buffer-local directory. The {bufnr} form 3328--- falls back to the global directory, because a buffer belongs 3329--- to no particular window or tabpage. 3330--- 3331--- Examples: >vim 3332--- getcwd(-1, -1, 0) " Get current buffer's directory 3333--- getcwd(-1, -1, 3) " Get directory of buffer 3 3334--- getcwd(-1, -1, -1) " Get global directory 3335--- getcwd(-1, -1) " Get global directory 3336--- < 3337--- 3338--- @param winnr? integer 3339--- @param tabnr? integer 3340--- @param bufnr? integer 3341--- @return string 3342function vim . fn . getcwd ( winnr , tabnr , bufnr ) end 3343 3344--- Lua: Prefer |vim.env|. 3345--- 3346--- Return the value of environment variable {name}. The {name} 3347--- argument is a string, without a leading '$'. Example: >vim 3348--- myHome = getenv('HOME') 3349--- 3350--- <When the variable does not exist |v:null| is returned. That 3351--- is different from a variable set to an empty string. 3352--- See also |expr-env|. 3353--- 3354--- @param name string 3355--- @return string 3356function vim . fn . getenv ( name ) end 3357 3358--- Without an argument returns the name of the normal font being 3359--- used. Like what is used for the Normal highlight group 3360--- |hl-Normal|. 3361--- With an argument a check is done whether String {name} is a 3362--- valid font name. If not then an empty string is returned. 3363--- Otherwise the actual font name is returned, or {name} if the 3364--- GUI does not support obtaining the real name. 3365--- Only works when the GUI is running, thus not in your vimrc or 3366--- gvimrc file. Use the |GUIEnter| autocommand to use this 3367--- function just after the GUI has started. 3368--- 3369--- @param name? string 3370--- @return string 3371function vim . fn . getfontname ( name ) end 3372 3373--- Lua: Prefer |uv.fs_stat()|. 3374--- 3375--- Returns the file permissions of the given file {fname} as a 3376--- String. If {fname} does not exist or its directory cannot be 3377--- read, an empty string is returned. 3378--- The result is of the form "rwxrwxrwx", where each group of 3379--- "rwx" flags represent, in turn, the permissions of the owner 3380--- of the file, the group the file belongs to, and other users. 3381--- If a user does not have a given permission the flag for this 3382--- is replaced with the string "-". Examples: >vim 3383--- echo getfperm("/etc/passwd") 3384--- echo getfperm(expand("~/.config/nvim/init.vim")) 3385--- <This will hopefully (from a security point of view) display 3386--- the string "rw-r--r--" or even "rw-------". 3387--- 3388--- For setting permissions use |setfperm()|. 3389--- 3390--- @param fname string 3391--- @return string 3392function vim . fn . getfperm ( fname ) end 3393 3394--- Lua: Prefer |uv.fs_stat()|. 3395--- 3396--- Returns the size in bytes of the given file {fname}. 3397--- If {fname} is a directory, 0 is returned. 3398--- If the file {fname} can't be found, -1 is returned. 3399--- If the size of {fname} is too big to fit in a Number then -2 3400--- is returned. 3401--- 3402--- @param fname string 3403--- @return integer 3404function vim . fn . getfsize ( fname ) end 3405 3406--- Lua: Prefer |uv.fs_stat()|. 3407--- 3408--- Returns the last modification time ("mtime") of file {fname}. 3409--- The value is measured as seconds since 1st Jan 1970, and may 3410--- be passed to |strftime()|. See also 3411--- |localtime()| and |strftime()|. 3412--- If the file {fname} can't be found -1 is returned. 3413--- 3414--- @param fname string 3415--- @return integer 3416function vim . fn . getftime ( fname ) end 3417 3418--- Lua: Prefer |uv.fs_stat()|. 3419--- 3420--- Returns a description of the type of file {fname} as a 3421--- String. If {fname} does not exist an empty string is 3422--- returned. 3423--- Here is a table over different kinds of files and their 3424--- results: 3425--- Normal file "file" 3426--- Directory "dir" 3427--- Symbolic link "link" 3428--- Block device "bdev" 3429--- Character device "cdev" 3430--- Socket "socket" 3431--- FIFO "fifo" 3432--- All other "other" 3433--- Example: >vim 3434--- getftype("/home") 3435--- <Note that a type such as "link" will only be returned on 3436--- systems that support it. On some systems only "dir" and 3437--- "file" are returned. 3438--- 3439--- @param fname string 3440--- @return 'file'|'dir'|'link'|'bdev'|'cdev'|'socket'|'fifo'|'other' 3441function vim . fn . getftype ( fname ) end 3442 3443--- Lua: Prefer |nvim_get_context()| for current jump history; window/tab arguments and return shape differ. 3444--- 3445--- Returns the |jumplist| for the specified window. 3446--- 3447--- Without arguments use the current window. 3448--- With {winnr} (|window-number| or |window-ID|) only use this 3449--- window in the current tabpage. 3450--- With {winnr} and {tabnr} use the window in the specified tab 3451--- page. If {winnr} or {tabnr} is invalid, an empty list is 3452--- returned. 3453--- 3454--- The returned list contains two entries: a list with the jump 3455--- locations and the last used jump position number in the list. 3456--- Each entry in the jump location list is a dictionary with 3457--- the following entries: 3458--- bufnr buffer number 3459--- col column number 3460--- coladd column offset for 'virtualedit' 3461--- filename filename if available 3462--- lnum line number 3463--- 3464--- @param winnr? integer 3465--- @param tabnr? integer 3466--- @return vim.fn.getjumplist.ret 3467function vim . fn . getjumplist ( winnr , tabnr ) end 3468 3469--- Lua: Prefer |nvim_get_current_line()| or |nvim_buf_get_lines()|. 3470--- 3471--- Without {end} the result is a String, which is line {lnum} 3472--- from the current buffer. Example: >vim 3473--- getline(1) 3474--- <When {lnum} is a String that doesn't start with a 3475--- digit, |line()| is called to translate the String into a Number. 3476--- To get the line under the cursor: >vim 3477--- getline(".") 3478--- <When {lnum} is a number smaller than 1 or bigger than the 3479--- number of lines in the buffer, an empty string is returned. 3480--- 3481--- Lua: Prefer |nvim_buf_get_lines()|. 3482--- 3483--- When {end} is given the result is a |List| where each item is 3484--- a line from the current buffer in the range {lnum} to {end}, 3485--- including line {end}. 3486--- {end} is used in the same way as {lnum}. 3487--- Non-existing lines are silently omitted. 3488--- When {end} is before {lnum} an empty |List| is returned. 3489--- Example: >vim 3490--- let start = line('.') 3491--- let end = search("^$") - 1 3492--- let lines = getline(start, end) 3493--- 3494--- <To get lines from another buffer see |getbufline()| and 3495--- |getbufoneline()| 3496--- 3497--- @overload fun(lnum: integer|string, end_: integer|string): (string[]) 3498--- @param lnum integer|string 3499--- @return string 3500function vim . fn . getline ( lnum ) end 3501 3502--- Returns a |List| with all the entries in the location list for 3503--- window {nr} (|window-number| or |window-ID|). 3504--- When {nr} is zero the current window is used. 3505--- 3506--- For a location list window, the displayed location list is 3507--- returned. For an invalid {nr}, an empty list is returned. 3508--- Otherwise, same as |getqflist()|. 3509--- 3510--- If the optional {what} dictionary argument is supplied, then 3511--- returns the items listed in {what} as a dictionary. Refer to 3512--- |getqflist()| for the supported items in {what}. 3513--- 3514--- In addition to the items supported by |getqflist()| in {what}, 3515--- the following item is supported by |getloclist()|: 3516--- 3517--- filewinid id of the window used to display files 3518--- from the location list. This field is 3519--- applicable only when called from a 3520--- location list window. See 3521--- |location-list-file-window| for more 3522--- details. 3523--- 3524--- Returns a |Dictionary| with default values if there is no 3525--- location list for the window {nr}. 3526--- Returns an empty Dictionary if window {nr} does not exist. 3527--- 3528--- Examples (See also |getqflist-examples|): >vim 3529--- echo getloclist(3, {'all': 0}) 3530--- echo getloclist(5, {'filewinid': 0}) 3531--- < 3532--- 3533--- @overload fun(nr: integer, what: vim.fn.getloclist.what): (vim.fn.getloclist.ret) 3534--- @param nr integer 3535--- @return vim.fn.getqflist.ret.item[] 3536function vim . fn . getloclist ( nr ) end 3537 3538--- Without the {buf} argument returns a |List| with information 3539--- about all the global marks. |mark| 3540--- 3541--- If the optional {buf} argument is specified, returns the 3542--- local marks defined in buffer {buf}. For the use of {buf}, 3543--- see |bufname()|. If {buf} is invalid, an empty list is 3544--- returned. For a |prompt-buffer| the result includes the 3545--- |':| mark. 3546--- 3547--- Each item in the returned List is a |Dict| with the following: 3548--- mark name of the mark prefixed by "'" 3549--- pos a |List| with the position of the mark: 3550--- [bufnum, lnum, col, off] 3551--- Refer to |getpos()| for more information. 3552--- file file name 3553--- 3554--- Refer to |getpos()| for getting information about a specific 3555--- mark. 3556--- 3557--- @param buf? integer? 3558--- @return vim.fn.getmarklist.ret.item[] 3559function vim . fn . getmarklist ( buf ) end 3560 3561--- Returns a |List| with all matches previously defined for the 3562--- current window by |matchadd()| and the |:match| commands. 3563--- |getmatches()| is useful in combination with |setmatches()|, 3564--- as |setmatches()| can restore a list of matches saved by 3565--- |getmatches()|. 3566--- If {win} is specified, use this |window-number| or |window-ID| 3567--- instead of the current window. If {win} is invalid, an empty 3568--- list is returned. 3569--- Example: >vim 3570--- echo getmatches() 3571--- < > 3572--- [{"group": "MyGroup1", "pattern": "TODO", 3573--- "priority": 10, "id": 1}, {"group": "MyGroup2", 3574--- "pattern": "FIXME", "priority": 10, "id": 2}] 3575--- < >vim 3576--- let m = getmatches() 3577--- call clearmatches() 3578--- echo getmatches() 3579--- < > 3580--- [] 3581--- < >vim 3582--- call setmatches(m) 3583--- echo getmatches() 3584--- < > 3585--- [{"group": "MyGroup1", "pattern": "TODO", 3586--- "priority": 10, "id": 1}, {"group": "MyGroup2", 3587--- "pattern": "FIXME", "priority": 10, "id": 2}] 3588--- < >vim 3589--- unlet m 3590--- < 3591--- 3592--- @param win? integer 3593--- @return vim.fn.getmatches.ret.item[] 3594function vim . fn . getmatches ( win ) end 3595 3596--- Returns a |Dictionary| with the last known position of the 3597--- mouse. This can be used in a mapping for a mouse click. The 3598--- items are: 3599--- screenrow screen row 3600--- screencol screen column 3601--- winid Window ID of the click 3602--- winrow row inside "winid" 3603--- wincol column inside "winid" 3604--- line text line inside "winid" 3605--- column text column inside "winid" 3606--- coladd offset (in screen columns) from the 3607--- start of the clicked char 3608--- All numbers are 1-based. 3609--- 3610--- If not over a window, e.g. when in the command line, then only 3611--- "screenrow" and "screencol" are valid, the others are zero. 3612--- 3613--- When on the status line below a window or the vertical 3614--- separator right of a window, the "line" and "column" values 3615--- are zero. 3616--- 3617--- When the position is after the text then "column" is the 3618--- length of the text in bytes plus one. 3619--- 3620--- If the mouse is over a focusable floating window then that 3621--- window is used. 3622--- 3623--- When using |getchar()| the Vim variables |v:mouse_lnum|, 3624--- |v:mouse_col| and |v:mouse_winid| also provide these values. 3625--- 3626--- @return vim.fn.getmousepos.ret 3627function vim . fn . getmousepos () end 3628 3629--- Lua: Prefer |uv.os_getpid()|. 3630--- 3631--- Return a Number which is the process ID of the Vim process. 3632--- This is a unique number, until Vim exits. 3633--- 3634--- @return integer 3635function vim . fn . getpid () end 3636 3637--- Lua: Prefer |nvim_win_get_cursor()| for "." or |nvim_buf_get_mark()| for marks; return shape, `off`, and special-position semantics differ. 3638--- 3639--- Gets a position, where {expr} is one of: 3640--- . Cursor position. 3641--- $ Last line in the current buffer. 3642--- 'x Position of mark x (if the mark is not set, 0 is 3643--- returned for all values). 3644--- w0 First line visible in current window (one if the 3645--- display isn't updated, e.g. in |silent-mode|). 3646--- w$ Last line visible in current window (this is one 3647--- less than "w0" if no lines are visible). 3648--- v End of the current Visual selection (unlike |'<| 3649--- |'>| which give the previous, not current, Visual 3650--- selection), or the cursor position if not in Visual 3651--- mode. 3652--- 3653--- To get the current selected region: >vim 3654--- let region = getregionpos(getpos('v'), getpos('.')) 3655--- < 3656--- Explanation: in Visual mode "v" and "." complement each 3657--- other. While "." refers to the cursor position, "v" 3658--- refers to where |v_o| would move the cursor. So you can 3659--- use "v" and "." together to get the selected region. 3660--- 3661--- Note that if a mark in another file is used, the line number 3662--- applies to that buffer. 3663--- 3664--- The result is a |List| with four numbers: 3665--- [bufnum, lnum, col, off] 3666--- "bufnum" is zero, unless a mark like '0 or 'A is used, then it 3667--- is the buffer number of the mark. 3668--- "lnum" and "col" are the position in the buffer. The first 3669--- column is 1. 3670--- The "off" number is zero, unless 'virtualedit' is used. Then 3671--- it is the offset in screen columns from the start of the 3672--- character. E.g., a position within a <Tab> or after the last 3673--- character. 3674--- 3675--- For getting the cursor position see |getcurpos()|. 3676--- The column number in the returned List is the byte position 3677--- within the line. To get the character position in the line, 3678--- use |getcharpos()|. 3679--- 3680--- The visual marks |'<| and |'>| refer to the beginning and end 3681--- of the visual selection relative to the buffer. Note that 3682--- this differs from |setpos()|, where they are relative to the 3683--- cursor position. 3684--- 3685--- Note that for '< and '> Visual mode matters: when it is "V" 3686--- (visual line mode) the column of '< is zero and the column of 3687--- '> is a large number equal to |v:maxcol|. 3688--- A very large column number equal to |v:maxcol| can be returned, 3689--- in which case it means "after the end of the line". 3690--- If {expr} is invalid, returns a list with all zeros. 3691--- 3692--- This can be used to save and restore the position of a mark: >vim 3693--- let save_a_mark = getpos("'a") 3694--- " ... 3695--- call setpos("'a", save_a_mark) 3696--- < 3697--- Also see |getcharpos()|, |getcurpos()| and |setpos()|. 3698--- 3699--- @param expr string 3700--- @return [integer, integer, integer, integer] 3701function vim . fn . getpos ( expr ) end 3702 3703--- Returns a |List| with all the current quickfix errors. Each 3704--- list item is a dictionary with these entries: 3705--- bufnr number of buffer that has the file name, use 3706--- |bufname()| to get the name 3707--- module module name 3708--- lnum line number in the buffer (first line is 1) 3709--- end_lnum 3710--- end of line number if the item is multiline 3711--- col column number (first column is 1) 3712--- end_col end of column number if the item has range 3713--- vcol |TRUE|: "col" is visual column 3714--- |FALSE|: "col" is byte index 3715--- nr error number 3716--- pattern search pattern used to locate the error 3717--- text description of the error 3718--- type type of the error, 'E', '1', etc. 3719--- valid |TRUE|: recognized error message 3720--- user_data 3721--- any type. This entry is present only when 3722--- user data was set for this item. 3723--- 3724--- When there is no error list or it's empty, an empty list is 3725--- returned. Quickfix list entries with a non-existing buffer 3726--- number are returned with "bufnr" set to zero (Note: some 3727--- functions accept buffer number zero for the alternate buffer, 3728--- you may need to explicitly check for zero). 3729--- 3730--- Useful application: Find pattern matches in multiple files and 3731--- do something with them: >vim 3732--- vimgrep /theword/jg *.c 3733--- for d in getqflist() 3734--- echo bufname(d.bufnr) ':' d.lnum '=' d.text 3735--- endfor 3736--- < 3737--- 3738--- If the optional {what} dictionary argument is supplied, then 3739--- returns only the items listed in {what} as a dictionary. The 3740--- following string items are supported in {what}: 3741--- changedtick get the total number of changes made 3742--- to the list |quickfix-changedtick| 3743--- context get the |quickfix-context| 3744--- efm errorformat to use when parsing "lines". If 3745--- not present, then the 'errorformat' option 3746--- value is used. 3747--- id get information for the quickfix list with 3748--- |quickfix-ID|; zero means the id for the 3749--- current list or the list specified by "nr" 3750--- idx get information for the quickfix entry at this 3751--- index in the list specified by "id" or "nr". 3752--- If set to zero, then uses the current entry. 3753--- See |quickfix-index| 3754--- items quickfix list entries 3755--- lines parse a list of lines using 'efm' and return 3756--- the resulting entries. Only a |List| type is 3757--- accepted. The current quickfix list is not 3758--- modified. See |quickfix-parse|. 3759--- nr get information for this quickfix list; zero 3760--- means the current quickfix list and "$" means 3761--- the last quickfix list 3762--- qfbufnr number of the buffer displayed in the quickfix 3763--- window. Returns 0 if the quickfix buffer is 3764--- not present. See |quickfix-buffer|. 3765--- quickfixtextfunc 3766--- function to get the text to display in the 3767--- quickfix window. Returns an empty string if 3768--- this function is not set for the list. See 3769--- |quickfix-window-function|. 3770--- size number of entries in the quickfix list 3771--- title get the list title |quickfix-title| 3772--- winid get the quickfix |window-ID| 3773--- all all of the above quickfix properties 3774--- Non-string items in {what} are ignored. To get the value of a 3775--- particular item, set it to zero. 3776--- If "nr" is not present then the current quickfix list is used. 3777--- If both "nr" and a non-zero "id" are specified, then the list 3778--- specified by "id" is used. 3779--- To get the number of lists in the quickfix stack, set "nr" to 3780--- "$" in {what}. The "nr" value in the returned dictionary 3781--- contains the quickfix stack size. 3782--- When "lines" is specified, all the other items except "efm" 3783--- are ignored. The returned dictionary contains the entry 3784--- "items" with the list of entries. 3785--- 3786--- The returned dictionary contains the following entries: 3787--- changedtick total number of changes made to the 3788--- list |quickfix-changedtick| 3789--- context quickfix list context. See |quickfix-context| 3790--- If not present, set to "". 3791--- id quickfix list ID |quickfix-ID|. If not 3792--- present, set to 0. 3793--- idx index of the quickfix entry in the list. If 3794--- not present, set to 0. 3795--- items quickfix list entries. If not present, set to 3796--- an empty list. 3797--- nr quickfix list number. If not present, set to 3798--- 0 3799--- qfbufnr number of the buffer displayed in the quickfix 3800--- window. If not present, set to 0. 3801--- quickfixtextfunc 3802--- 'quickfixtextfunc' setting of the list. If 3803--- not present, set to "". 3804--- size number of entries in the quickfix list. If 3805--- not present, set to 0. 3806--- title quickfix list title text. If not present, set 3807--- to "". 3808--- winid quickfix |window-ID|. If not present, set to 0 3809--- 3810--- Examples (See also |getqflist-examples|): >vim 3811--- echo getqflist({'all': 1}) 3812--- echo getqflist({'nr': 2, 'title': 1}) 3813--- echo getqflist({'lines' : ["F1:10:L10"]}) 3814--- < 3815--- 3816--- @overload fun(what: vim.fn.getqflist.what): (vim.fn.getqflist.ret) 3817--- @return vim.fn.getqflist.ret.item[] 3818function vim . fn . getqflist () end 3819 3820--- Returns the contents of register {regname} as a String. 3821--- Example: >vim 3822--- let cliptext = getreg('*') 3823--- <When register {regname} was not set the result is an empty 3824--- string. 3825--- The {regname} argument must be a string. 3826--- 3827--- getreg('=') returns the last evaluated value of the expression 3828--- register. (For use in maps.) 3829--- getreg('=', 1) returns the expression itself, so that it can 3830--- be restored with |setreg()|. For other registers the extra 3831--- argument is ignored, thus you can always give it. 3832--- 3833--- If {list} is present and |TRUE|, the result type is changed 3834--- to |List|. Each list item is one text line. Use it if you care 3835--- about zero bytes possibly present inside register: without 3836--- third argument both NLs and zero bytes are represented as NLs 3837--- (see |NL-used-for-Nul|). 3838--- When the register was not set an empty list is returned. 3839--- 3840--- If {regname} is not specified, |v:register| is used. 3841--- 3842--- @overload fun(regname: string, expr: any, list: true|number|string|table): (string[]) 3843--- @param regname? string 3844--- @param expr? any 3845--- @param list? nil|false 3846--- @return string 3847function vim . fn . getreg ( regname , expr , list ) end 3848 3849--- Returns detailed information about register {regname} as a 3850--- Dictionary with the following entries: 3851--- regcontents List of lines contained in register 3852--- {regname}, like 3853--- getreg({regname}, 1, 1). 3854--- regtype the type of register {regname}, as in 3855--- |getregtype()|. 3856--- isunnamed Boolean flag, v:true if this register 3857--- is currently pointed to by the unnamed 3858--- register. 3859--- points_to for the unnamed register, gives the 3860--- single letter name of the register 3861--- currently pointed to (see |quotequote|). 3862--- For example, after deleting a line 3863--- with `dd`, this field will be "1", 3864--- which is the register that got the 3865--- deleted text. 3866--- 3867--- The {regname} argument is a string. If {regname} is invalid 3868--- or not set, an empty Dictionary will be returned. 3869--- If {regname} is not specified, |v:register| is used. 3870--- The returned Dictionary can be passed to |setreg()|. 3871--- 3872--- @param regname? string 3873--- @return table 3874function vim . fn . getreginfo ( regname ) end 3875 3876--- Returns the list of strings from {pos1} to {pos2} from a 3877--- buffer. 3878--- 3879--- {pos1} and {pos2} must both be |List|s with four numbers. 3880--- See |getpos()| for the format of the list. It's possible 3881--- to specify positions from a different buffer, but please 3882--- note the limitations at |getregion-notes|. 3883--- 3884--- The optional argument {opts} is a Dict and supports the 3885--- following items: 3886--- 3887--- type Specify the region's selection type. 3888--- See |getregtype()| for possible values, 3889--- except that the width can be omitted 3890--- and an empty string cannot be used. 3891--- (default: "v") 3892--- 3893--- exclusive If |TRUE|, use exclusive selection 3894--- for the end position. 3895--- (default: follow 'selection') 3896--- 3897--- You can get the last selection type by |visualmode()|. 3898--- If Visual mode is active, use |mode()| to get the Visual mode 3899--- (e.g., in a |:vmap|). 3900--- This function is useful to get text starting and ending in 3901--- different columns, such as a |charwise-visual| selection. 3902--- 3903--- *getregion-notes* 3904--- Note that: 3905--- - Order of {pos1} and {pos2} doesn't matter, it will always 3906--- return content from the upper left position to the lower 3907--- right position. 3908--- - If 'virtualedit' is enabled and the region is past the end 3909--- of the lines, resulting lines are padded with spaces. 3910--- - If the region is blockwise and it starts or ends in the 3911--- middle of a multi-cell character, it is not included but 3912--- its selected part is substituted with spaces. 3913--- - If {pos1} and {pos2} are not in the same buffer, an empty 3914--- list is returned. 3915--- - {pos1} and {pos2} must belong to a |bufloaded()| buffer. 3916--- - It is evaluated in current window context, which makes a 3917--- difference if the buffer is displayed in a window with 3918--- different 'virtualedit' or 'list' values. 3919--- - When specifying an exclusive selection and {pos1} and {pos2} 3920--- are equal, the returned list contains a single character as 3921--- if selection is inclusive, to match the behavior of an empty 3922--- exclusive selection in Visual mode. 3923--- 3924--- Examples: >vim 3925--- xnoremap <CR> 3926--- \ <Cmd>echom getregion( 3927--- \ getpos('v'), getpos('.'), #{ type: mode() })<CR> 3928--- < 3929--- 3930--- @param pos1 [integer, integer, integer, integer] 3931--- @param pos2 [integer, integer, integer, integer] 3932--- @param opts? {type?:string, exclusive?:boolean} 3933--- @return string[] 3934function vim . fn . getregion ( pos1 , pos2 , opts ) end 3935 3936--- Same as |getregion()|, but returns a list of positions 3937--- describing the buffer text segments bound by {pos1} and 3938--- {pos2}. 3939--- The segments are a pair of positions for every line: > 3940--- [[{startpos}, {endpos}], ...] 3941--- < 3942--- The position is a |List| with four numbers: 3943--- [bufnum, lnum, col, off] 3944--- "bufnum" is the buffer number. 3945--- "lnum" and "col" are the position in the buffer. The first 3946--- column is 1. 3947--- If the "off" number of a starting position is non-zero, it is 3948--- the offset in screen columns from the start of the character. 3949--- E.g., a position within a <Tab> or after the last character. 3950--- If the "off" number of an ending position is non-zero, it is 3951--- the offset of the character's first cell not included in the 3952--- selection, otherwise all its cells are included. 3953--- 3954--- To get the current visual selection: >vim 3955--- let region = getregionpos(getpos('v'), getpos('.')) 3956--- < 3957--- The {opts} Dict supports the following items: 3958--- 3959--- type See |getregion()|. 3960--- 3961--- exclusive See |getregion()|. 3962--- 3963--- eol If |TRUE|, indicate positions beyond 3964--- the end of a line with "col" values 3965--- one more than the length of the line. 3966--- If |FALSE|, positions are limited 3967--- within their lines, and if a line is 3968--- empty or the selection is entirely 3969--- beyond the end of a line, a "col" 3970--- value of 0 is used for both positions. 3971--- (default: |FALSE|) 3972--- 3973--- bounds If |TRUE|, return only the outer 3974--- bounds of the region as a single 3975--- pair: > 3976--- [[{startpos}, {endpos}]] 3977--- < {startpos} is the start position on 3978--- the first line of the region and 3979--- {endpos} the end position on its last 3980--- line. The lines in between are not 3981--- visited, which is much faster for a 3982--- large region. 3983--- (default: |FALSE|) 3984--- 3985--- Using "bounds" with the same {opts} is equivalent to taking 3986--- the outer positions of the full result: >vim 3987--- let full = getregionpos(pos1, pos2, opts) 3988--- let bounds = [[full[0][0], full[-1][1]]] 3989--- <When the full result is empty, e.g. because {pos1} and {pos2} 3990--- are in different buffers, the result is empty as well. 3991--- Note that the two positions then come from different lines, so 3992--- they describe a diagonal of the region and not its shape. For 3993--- a blockwise region they are the start of the first line and 3994--- the end of the last line, not the corners of the block. 3995--- Likewise, when the first line is empty and "eol" is |FALSE|, 3996--- {startpos} has a "col" of 0 while {endpos} may not. 3997--- 3998--- @param pos1 [integer, integer, integer, integer] 3999--- @param pos2 [integer, integer, integer, integer] 4000--- @param opts? {type?:string, exclusive?:boolean, eol?:boolean, bounds?:boolean} 4001--- @return [ [integer, integer, integer, integer], [integer, integer, integer, integer] ][] 4002function vim . fn . getregionpos ( pos1 , pos2 , opts ) end 4003 4004--- Returns the type of register {regname} as a String. 4005--- The value will be one of: 4006--- "v" for |charwise| text 4007--- "V" for |linewise| text 4008--- "<CTRL-V>{width}" for |blockwise-visual| text 4009--- "" for an empty or unknown register 4010--- <CTRL-V> is one character with value 0x16. 4011--- The {regname} argument is a string. If {regname} is not 4012--- specified, |v:register| is used. 4013--- 4014--- @param regname? string 4015--- @return string 4016function vim . fn . getregtype ( regname ) end 4017 4018--- Returns a |List| with information about all the sourced Vim 4019--- scripts in the order they were sourced, like what 4020--- `:scriptnames` shows. 4021--- 4022--- The optional Dict argument {opts} supports the following 4023--- optional items: 4024--- name Script name match pattern. If specified, 4025--- and "sid" is not specified, information about 4026--- scripts with a name that match the pattern 4027--- "name" are returned. 4028--- sid Script ID |<SID>|. If specified, only 4029--- information about the script with ID "sid" is 4030--- returned and "name" is ignored. 4031--- 4032--- Each item in the returned List is a |Dict| with the following 4033--- items: 4034--- autoload Always set to FALSE. 4035--- functions List of script-local function names defined in 4036--- the script. Present only when a particular 4037--- script is specified using the "sid" item in 4038--- {opts}. 4039--- name Vim script file name. 4040--- sid Script ID |<SID>|. 4041--- variables A dictionary with the script-local variables. 4042--- Present only when a particular script is 4043--- specified using the "sid" item in {opts}. 4044--- Note that this is a copy, the value of 4045--- script-local variables cannot be changed using 4046--- this dictionary. 4047--- version Vim script version, always 1 4048--- 4049--- Examples: >vim 4050--- echo getscriptinfo({'name': 'myscript'}) 4051--- echo getscriptinfo({'sid': 15})[0].variables 4052--- < 4053--- 4054--- @param opts? table 4055--- @return vim.fn.getscriptinfo.ret[] 4056function vim . fn . getscriptinfo ( opts ) end 4057 4058--- Lua: Prefer |debug.traceback()|. 4059--- 4060--- Returns the current stack trace of Vim scripts. 4061--- Stack trace is a |List|, of which each item is a |Dictionary| 4062--- with the following items: 4063--- funcref The funcref if the stack is at a function, 4064--- otherwise this item is omitted. 4065--- event The string of the event description if the 4066--- stack is at an autocmd event, otherwise this 4067--- item is omitted. 4068--- lnum The line number in the script on the stack. 4069--- filepath The file path of the script on the stack. 4070--- 4071--- @return table[] 4072function vim . fn . getstacktrace () end 4073 4074--- If {tabnr} is not specified, then information about all the 4075--- tabpages is returned as a |List|. Each List item is a 4076--- |Dictionary|. Otherwise, {tabnr} specifies the tabpage 4077--- number and information about that one is returned. If the tab 4078--- page does not exist an empty List is returned. 4079--- 4080--- Each List item is a |Dictionary| with the following entries: 4081--- tabnr |tabpage-number| 4082--- variables a reference to the dictionary with 4083--- tabpage-local variables 4084--- windows List of |window-ID|s in the tabpage. 4085--- 4086--- @param tabnr? integer 4087--- @return any 4088function vim . fn . gettabinfo ( tabnr ) end 4089 4090--- Lua: Prefer |nvim_tabpage_get_var()| or |vim.t|. 4091--- 4092--- Get the value of a tab-local variable {varname} in tabpage 4093--- {tabnr}. |t:var| 4094--- Tabs are numbered starting with one. 4095--- The {varname} argument is a string. When {varname} is empty a 4096--- dictionary with all tab-local variables is returned. 4097--- Note that the name without "t:" must be used. 4098--- When the tab or variable doesn't exist {def} or an empty 4099--- string is returned, there is no error message. 4100--- 4101--- @param tabnr integer 4102--- @param varname string 4103--- @param def? any 4104--- @return any 4105function vim . fn . gettabvar ( tabnr , varname , def ) end 4106 4107--- Lua: Prefer |nvim_win_get_var()| or |vim.w| after resolving {tabnr} and {winnr} to a winid; option names use |nvim_get_option_value()| or |vim.wo|. 4108--- 4109--- Gets the value of window-local variable {varname} in {winnr} 4110--- (|window-number| or |window-ID|) in |tabpage-number| {tabnr}. 4111--- 4112--- {varname} is a string: 4113--- - Name of the variable (without "w:"). 4114--- - If empty, gets a dictionary with all window-local variables. 4115--- - If "&", gets the values of all window-local options in 4116--- a |Dictionary|. 4117--- - If it starts with "&", gets the value of a window-local 4118--- option. 4119--- 4120--- To get window-local variables in the current tabpage use 4121--- |getwinvar()|. 4122--- 4123--- When {winnr} is zero the current window is used. 4124--- 4125--- Also works for a global option, buffer-local option, 4126--- window-local option, and tab-local option ('cmdheight'). 4127--- But not for a global variable or buffer-local variable. 4128--- 4129--- When the tab, window or variable doesn't exist, {def} or an 4130--- empty string is returned; there is no error. 4131--- 4132--- Examples: >vim 4133--- let list_is_on = gettabwinvar(1, 2, '&list') 4134--- echo "myvar = " .. gettabwinvar(3, 1, 'myvar') 4135--- < 4136--- To get all window-local variables: >vim 4137--- gettabwinvar({tabnr}, {winnr}, '&') 4138--- < 4139--- 4140--- @param tabnr integer 4141--- @param winnr integer 4142--- @param varname string 4143--- @param def? any 4144--- @return any 4145function vim . fn . gettabwinvar ( tabnr , winnr , varname , def ) end 4146 4147--- Returns the tag stack of window {winnr} (|window-number| or 4148--- |window-ID|) as a Dict. 4149--- When {winnr} is not specified, the current window is used. 4150--- When window {winnr} doesn't exist, an empty Dict is returned. 4151--- 4152--- The returned dictionary contains the following entries: 4153--- curidx Current index in the stack. When at 4154--- top of the stack, set to (length + 1). 4155--- Index of bottom of the stack is 1. 4156--- items List of items in the stack. Each item 4157--- is a dictionary containing the 4158--- entries described below. 4159--- length Number of entries in the stack. 4160--- 4161--- Each item in the stack is a dictionary with the following 4162--- entries: 4163--- bufnr buffer number of the current jump 4164--- from cursor position before the tag jump. 4165--- See |getpos()| for the format of the 4166--- returned list. 4167--- matchnr current matching tag number. Used 4168--- when multiple matching tags are found 4169--- for a name. 4170--- tagname name of the tag 4171--- 4172--- See |tagstack| for more information about the tag stack. 4173--- 4174--- @param winnr? integer 4175--- @return any 4176function vim . fn . gettagstack ( winnr ) end 4177 4178--- Translate String {text} if possible. 4179--- This is mainly for use in the distributed Vim scripts. When 4180--- generating message translations the {text} is extracted by 4181--- xgettext, the translator can add the translated message in the 4182--- .po file and Vim will lookup the translation when gettext() is 4183--- called. 4184--- For {text} double quoted strings are preferred, because 4185--- xgettext does not understand escaping in single quoted 4186--- strings. 4187--- 4188--- @param text string 4189--- @return string 4190function vim . fn . gettext ( text ) end 4191 4192--- Returns information about windows as a |List| with Dictionaries. 4193--- 4194--- If {winid} is given Information about the window with that ID 4195--- is returned, as a |List| with one item. If the window does not 4196--- exist the result is an empty list. 4197--- 4198--- Without {winid} information about all the windows in all the 4199--- tabpages is returned. 4200--- 4201--- Each List item is a |Dictionary| with the following entries: 4202--- botline last complete displayed buffer line 4203--- bufnr number of buffer in the window 4204--- height window height (excluding winbar) 4205--- leftcol first column displayed; only used when 4206--- 'wrap' is off 4207--- loclist 1 if showing a location list 4208--- quickfix 1 if quickfix or location list window 4209--- status_height status lines height (0 or 1) 4210--- tabnr |tabpage-number| 4211--- terminal 1 if a terminal window 4212--- textoff number of columns occupied by any 4213--- 'foldcolumn', 'signcolumn' and line 4214--- number in front of the text 4215--- topline first displayed buffer line 4216--- variables a reference to the dictionary with 4217--- window-local variables 4218--- width window width 4219--- winbar 1 if the window has a toolbar, 0 4220--- otherwise 4221--- wincol leftmost screen column of the window; 4222--- "col" from |win_screenpos()| 4223--- winid |window-ID| 4224--- winnr |window-number| 4225--- winrow topmost screen line of the window; 4226--- "row" from |win_screenpos()| 4227--- 4228--- @param winid? integer 4229--- @return vim.fn.getwininfo.ret.item[] 4230function vim . fn . getwininfo ( winid ) end 4231 4232--- Returns the [x, y] screen position of the Nvim GUI window as 4233--- a |List| with two numbers (result of |getwinposx()| and 4234--- |getwinposy()| combined). 4235--- 4236--- {timeout} can be used to specify how long to wait in msec for 4237--- a response. When omitted 100 msec is used. 4238--- 4239--- Use a longer time for a remote terminal. 4240--- When using a value less than 10 and no response is received 4241--- within that time, a previously reported position is returned, 4242--- if available. This can be used to poll for the position and 4243--- do some work in the meantime: >vim 4244--- while 1 4245--- let res = getwinpos(1) 4246--- if res[0] >= 0 4247--- break 4248--- endif 4249--- " Do some work here 4250--- endwhile 4251--- < 4252--- 4253--- @param timeout? integer 4254--- @return any 4255function vim . fn . getwinpos ( timeout ) end 4256 4257--- Returns the X coordinate in pixels of the left hand side of 4258--- the Nvim GUI window, or -1 if not available. The value can be 4259--- used with `:winpos`. 4260--- 4261--- @return integer 4262function vim . fn . getwinposx () end 4263 4264--- Returns the Y coordinate in pixels of the top of the Nvim GUI 4265--- window, or -1 if not available. The value can be used with 4266--- `:winpos`. 4267--- 4268--- @return integer 4269function vim . fn . getwinposy () end 4270 4271--- Lua: Prefer |nvim_win_get_var()| or |vim.w| after resolving {winnr}; option names use |nvim_get_option_value()| or |vim.wo|. 4272--- 4273--- Like |gettabwinvar()| for the current tabpage. 4274--- Examples: >vim 4275--- let list_is_on = getwinvar(2, '&list') 4276--- echo "myvar = " .. getwinvar(1, 'myvar') 4277--- < 4278--- 4279--- @param winnr integer 4280--- @param varname string 4281--- @param def? any 4282--- @return any 4283function vim . fn . getwinvar ( winnr , varname , def ) end 4284 4285--- Expand the file wildcards in {expr}. See |wildcards| for the 4286--- use of special characters. 4287--- 4288--- Unless the optional {nosuf} argument is given and is |TRUE|, 4289--- the 'suffixes' and 'wildignore' options apply: Names matching 4290--- one of the patterns in 'wildignore' will be skipped and 4291--- 'suffixes' affect the ordering of matches. 4292--- 'wildignorecase' always applies. 4293--- 4294--- When {list} is present and it is |TRUE| the result is a |List| 4295--- with all matching files. The advantage of using a List is, 4296--- you also get filenames containing newlines correctly. 4297--- Otherwise the result is a String and when there are several 4298--- matches, they are separated by <NL> characters. 4299--- 4300--- If the expansion fails, the result is an empty String or List. 4301--- 4302--- You can also use |readdir()| if you need to do complicated 4303--- things, such as limiting the number of matches. 4304--- 4305--- A name for a non-existing file is not included. A symbolic 4306--- link is only included if it points to an existing file. 4307--- However, when the {alllinks} argument is present and it is 4308--- |TRUE| then all symbolic links are included. 4309--- 4310--- For most systems backticks can be used to get files names from 4311--- any external command. Example: >vim 4312--- let tagfiles = glob("`find . -name tags -print`") 4313--- let &tags = substitute(tagfiles, "\n", ",", "g") 4314--- <The result of the program inside the backticks should be one 4315--- item per line. Spaces inside an item are allowed. 4316--- 4317--- See |expand()| for expanding special Vim variables. See 4318--- |system()| for getting the raw output of an external command. 4319--- 4320--- @param expr string 4321--- @param nosuf? boolean 4322--- @param list? boolean 4323--- @param alllinks? boolean 4324--- @return any 4325function vim . fn . glob ( expr , nosuf , list , alllinks ) end 4326 4327--- Convert a file pattern, as used by |glob()|, into a search 4328--- pattern. The result can be used to match with a string that 4329--- is a file name. E.g. >vim 4330--- if filename =~ glob2regpat('Make*.mak') 4331--- " ... 4332--- endif 4333--- <This is equivalent to: >vim 4334--- if filename =~ '^Make.*\.mak$' 4335--- " ... 4336--- endif 4337--- <When {string} is an empty string the result is "^$", match an 4338--- empty string. 4339--- Note that the result depends on the system. On MS-Windows 4340--- a backslash usually means a path separator. 4341--- 4342--- @param string string 4343--- @return string 4344function vim . fn . glob2regpat ( string ) end 4345 4346--- Perform |glob()| for String {expr} on all directories in {path} 4347--- and concatenate the results. Example: >vim 4348--- echo globpath(&rtp, "syntax/c.vim") 4349--- < 4350--- {path} is a comma-separated list of directory names. Each 4351--- directory name is prepended to {expr} and expanded like with 4352--- |glob()|. A path separator is inserted when needed. 4353--- To add a comma inside a directory name escape it with a 4354--- backslash. Note that on MS-Windows a directory may have a 4355--- trailing backslash, remove it if you put a comma after it. 4356--- If the expansion fails for one of the directories, there is no 4357--- error message. 4358--- 4359--- Unless the optional {nosuf} argument is given and is |TRUE|, 4360--- the 'suffixes' and 'wildignore' options apply: Names matching 4361--- one of the patterns in 'wildignore' will be skipped and 4362--- 'suffixes' affect the ordering of matches. 4363--- 4364--- When {list} is present and it is |TRUE| the result is a |List| 4365--- with all matching files. The advantage of using a List is, 4366--- you also get filenames containing newlines correctly. 4367--- Otherwise the result is a String and when there are several 4368--- matches, they are separated by <NL> characters. Example: >vim 4369--- echo globpath(&rtp, "syntax/c.vim", 0, 1) 4370--- < 4371--- {allinks} is used as with |glob()|. 4372--- 4373--- The "**" item can be used to search in a directory tree. 4374--- For example, to find all "README.txt" files in the directories 4375--- in 'runtimepath' and below: >vim 4376--- echo globpath(&rtp, "**/README.txt") 4377--- <Upwards search and limiting the depth of "**" is not 4378--- supported, thus using 'path' will not always work properly. 4379--- 4380--- @param path string 4381--- @param expr string 4382--- @param nosuf? boolean 4383--- @param list? boolean 4384--- @param allinks? boolean 4385--- @return any 4386function vim . fn . globpath ( path , expr , nosuf , list , allinks ) end 4387 4388--- Returns 1 if {feature} is supported, 0 otherwise. The 4389--- {feature} argument is a feature name like "nvim-0.2.1" or 4390--- "win32", see below. See also |exists()|. 4391--- 4392--- To get the system name use |vim.uv|.os_uname() in Lua: >lua 4393--- print(vim.uv.os_uname().sysname) 4394--- 4395--- <If the code has a syntax error then Vimscript may skip the 4396--- rest of the line. Put |:if| and |:endif| on separate lines to 4397--- avoid the syntax error: >vim 4398--- if has('feature') 4399--- let x = this_breaks_without_the_feature() 4400--- endif 4401--- < 4402--- Vim's compile-time feature-names (prefixed with "+") are not 4403--- recognized because Nvim is always compiled with all possible 4404--- features. |feature-compile| 4405--- 4406--- Feature names can be: 4407--- 1. Nvim version. For example the "nvim-0.2.1" feature means 4408--- that Nvim is version 0.2.1 or later: >vim 4409--- if has("nvim-0.2.1") 4410--- " ... 4411--- endif 4412--- 4413--- <2. Runtime condition or other pseudo-feature. For example the 4414--- "win32" feature checks if the current system is Windows: >vim 4415--- if has("win32") 4416--- " ... 4417--- endif 4418--- < *feature-list* 4419--- List of supported pseudo-feature names: 4420--- acl |ACL| support. 4421--- *android* Android system (not necessarily |termux|). 4422--- bsd BSD system (not macOS, use "mac" for that). 4423--- clipboard |clipboard| provider is available. 4424--- fname_case Case in file names matters (for Darwin and MS-Windows 4425--- this is not present). 4426--- gui_running Nvim has a GUI. 4427--- hurd GNU/Hurd system. 4428--- iconv Can use |iconv()| for conversion. 4429--- linux Linux system. 4430--- mac MacOS system. 4431--- nvim This is Nvim. 4432--- python3 Legacy Vim |python3| interface. |has-python| 4433--- pythonx Legacy Vim |python_x| interface. |has-pythonx| 4434--- sun SunOS system. 4435--- *termux* Termux, an |android| terminal app and packaging environment. 4436--- ttyin input is a terminal (tty). 4437--- ttyout output is a terminal (tty). 4438--- unix Unix system. 4439--- *vim_starting* True during |startup|. 4440--- win32 Windows system (32 or 64 bit). 4441--- win64 Windows system (64 bit). 4442--- wsl WSL (Windows Subsystem for Linux) system. 4443--- 4444--- *has-patch* 4445--- 3. Vim patch. For example the "patch123" feature means that 4446--- Vim patch 123 at the current |v:version| was included: >vim 4447--- if v:version > 602 || v:version == 602 && has("patch148") 4448--- " ... 4449--- endif 4450--- 4451--- <4. Vim version. For example the "patch-7.4.237" feature means 4452--- that Nvim is Vim-compatible to version 7.4.237 or later. >vim 4453--- if has("patch-7.4.237") 4454--- " ... 4455--- endif 4456--- < 4457--- 4458--- @param feature string 4459--- @return 0|1 4460function vim . fn . has ( feature ) end 4461 4462--- Lua: Prefer `dict[key] ~= nil`. 4463--- 4464--- Checks whether |Dictionary| {dict} has an entry with key 4465--- {key}. Returns TRUE if so, FALSE otherwise. The {key} 4466--- argument is a string. 4467--- 4468--- @param dict table 4469--- @param key string 4470--- @return 0|1 4471function vim . fn . has_key ( dict , key ) end 4472 4473--- Checks whether the tabpage, window or buffer has set a local 4474--- working directory. Returns 1 when the window has set a local 4475--- path via |:lcd|, or when {winnr} is -1 and the tabpage has set 4476--- a local path via |:tcd|, or when {winnr} and {tabnr} are -1 4477--- and {bufnr} has set a local path via |:bcd|, otherwise 0. 4478--- 4479--- Tabs, windows and buffers are identified by their respective 4480--- numbers, 0 means current tab/window/buffer. Missing {winnr} 4481--- or {tabnr} implies 0 (missing {bufnr} does not; see below). 4482--- Thus the following are equivalent: >vim 4483--- echo haslocaldir() 4484--- echo haslocaldir(0) 4485--- echo haslocaldir(0, 0) 4486--- <With {winnr} use that window in the current tabpage. 4487--- With {winnr} and {tabnr} use the window in that tabpage. 4488--- {winnr} is a |window-number| or |window-ID|. 4489--- If {winnr} is -1 it is ignored, only the tab is resolved. 4490--- If {bufnr} is provided, {winnr} and {tabnr} must be -1 and 4491--- only the buffer is resolved. An argument may be -1 only if 4492--- all preceding arguments are -1. 4493--- Examples of buffer usage: >vim 4494--- haslocaldir(-1, -1, 0) " Current buf has a local directory? 4495--- haslocaldir(-1, -1, 3) " Buf #3 has a local directory? 4496--- <Throw error if the arguments are invalid. 4497--- |E5000| |E5001| |E5002| |E5006| |E5007| 4498--- 4499--- @param winnr? integer 4500--- @param tabnr? integer 4501--- @param bufnr? integer 4502--- @return 0|1 4503function vim . fn . haslocaldir ( winnr , tabnr , bufnr ) end 4504 4505--- Checks whether a mapping exists whose rhs contains {what}. 4506--- Returns TRUE if there is such a mapping in one of the modes 4507--- indicated by {mode}. 4508--- The arguments {what} and {mode} are strings. 4509--- When {abbr} is there and it is |TRUE| use abbreviations 4510--- instead of mappings. Don't forget to specify Insert and/or 4511--- Command-line mode. 4512--- Both the global mappings and the mappings local to the current 4513--- buffer are checked for a match. 4514--- If no matching mapping is found FALSE is returned. 4515--- The following characters are recognized in {mode}: 4516--- n Normal mode 4517--- v Visual and Select mode 4518--- x Visual mode 4519--- s Select mode 4520--- o Operator-pending mode 4521--- i Insert mode 4522--- l Language-Argument ("r", "f", "t", etc.) 4523--- c Command-line mode 4524--- When {mode} is omitted, "nvo" is used. 4525--- 4526--- This function is useful to check if a mapping already exists 4527--- to a function in a Vim script. Example: >vim 4528--- if !hasmapto('\ABCdoit') 4529--- map <Leader>d \ABCdoit 4530--- endif 4531--- <This installs the mapping to "\ABCdoit" only if there isn't 4532--- already a mapping to "\ABCdoit". 4533--- 4534--- @param what any 4535--- @param mode? string 4536--- @param abbr? boolean 4537--- @return 0|1 4538function vim . fn . hasmapto ( what , mode , abbr ) end 4539 4540--- @deprecated 4541--- Lua: Prefer |nvim_get_hl()|. 4542--- 4543--- Obsolete name for |hlID()|. 4544--- 4545--- @param name string 4546--- @return any 4547function vim . fn . highlightID ( name ) end 4548 4549--- @deprecated 4550--- Lua: Prefer |nvim_get_hl()|. 4551--- 4552--- Obsolete name for |hlexists()|. 4553--- 4554--- @param name string|number|boolean|nil 4555--- @return any 4556function vim . fn . highlight_exists ( name ) end 4557 4558--- Add the String {item} to the history {history} which can be 4559--- one of: *hist-names* 4560--- "cmd" or ":" command line history 4561--- "search" or "/" search pattern history 4562--- "expr" or "=" typed expression history 4563--- "input" or "\@" input line history 4564--- "debug" or ">" debug command history 4565--- empty the current or last used history 4566--- The {history} string does not need to be the whole name, one 4567--- character is sufficient. 4568--- If {item} does already exist in the history, it will be 4569--- shifted to become the newest entry. 4570--- The result is a Number: TRUE if the operation was successful, 4571--- otherwise FALSE is returned. 4572--- 4573--- Example: >vim 4574--- call histadd("input", strftime("%Y %b %d")) 4575--- let date=input("Enter date: ") 4576--- <This function is not available in the |sandbox|. 4577--- 4578--- @param history string 4579--- @param item any 4580--- @return 0|1 4581function vim . fn . histadd ( history , item ) end 4582 4583--- Clear {history}, i.e. delete all its entries. See |hist-names| 4584--- for the possible values of {history}. 4585--- 4586--- If the parameter {item} evaluates to a String, it is used as a 4587--- regular expression. All entries matching that expression will 4588--- be removed from the history (if there are any). 4589--- Upper/lowercase must match, unless "\c" is used |/\c|. 4590--- If {item} evaluates to a Number, it will be interpreted as 4591--- an index, see |:history-indexing|. The respective entry will 4592--- be removed if it exists. 4593--- 4594--- The result is TRUE for a successful operation, otherwise FALSE 4595--- is returned. 4596--- 4597--- Examples: 4598--- Clear expression register history: >vim 4599--- call histdel("expr") 4600--- < 4601--- Remove all entries starting with "*" from the search history: >vim 4602--- call histdel("/", '^\*') 4603--- < 4604--- The following three are equivalent: >vim 4605--- call histdel("search", histnr("search")) 4606--- call histdel("search", -1) 4607--- call histdel("search", '^' .. histget("search", -1) .. '$') 4608--- < 4609--- To delete the last search pattern and use the last-but-one for 4610--- the "n" command and 'hlsearch': >vim 4611--- call histdel("search", -1) 4612--- let \@/ = histget("search", -1) 4613--- < 4614--- 4615--- @param history string 4616--- @param item? any 4617--- @return 0|1 4618function vim . fn . histdel ( history , item ) end 4619 4620--- Returns an entry from the specified command-line {history}. 4621--- See |hist-names| for the possible values of {history}, and 4622--- |:history-indexing| for {index}. If there is 4623--- no such entry, an empty String is returned. When {index} is 4624--- omitted, the most recent item from the history is used. 4625--- 4626--- Examples: 4627--- Redo the second last search from history. >vim 4628--- execute '/' .. histget("search", -2) 4629--- 4630--- <Define an Ex command ":H {num}" that supports re-execution of 4631--- the {num}th entry from the output of |:history|. >vim 4632--- command -nargs=1 H execute histget("cmd", 0+<args>) 4633--- < 4634--- 4635--- @param history string 4636--- @param index? integer|string 4637--- @return string 4638function vim . fn . histget ( history , index ) end 4639 4640--- The result is the Number of the current entry in {history}. 4641--- See |hist-names| for the possible values of {history}. 4642--- If an error occurred, -1 is returned. 4643--- 4644--- Example: >vim 4645--- let inp_index = histnr("expr") 4646--- < 4647--- 4648--- @param history string 4649--- @return integer 4650function vim . fn . histnr ( history ) end 4651 4652--- Lua: Prefer |nvim_get_hl()|. 4653--- 4654--- Returns the numeric ID of the highlight group with name 4655--- {name}. When the highlight group doesn't exist, zero is 4656--- returned. 4657--- This can be used to retrieve information about the highlight 4658--- group. For example, to get the background color of the 4659--- "Comment" group: >vim 4660--- echo synIDattr(synIDtrans(hlID("Comment")), "bg") 4661--- < 4662--- 4663--- @param name string 4664--- @return integer 4665function vim . fn . hlID ( name ) end 4666 4667--- Lua: Prefer |nvim_get_hl()|. 4668--- 4669--- Checks whether a highlight group called {name} exists. 4670--- Returns TRUE if the group has been defined in some way. Not 4671--- necessarily when highlighting has been defined for it, it may 4672--- also have been used for a syntax item. 4673--- 4674--- @param name string|number|boolean|nil 4675--- @return 0|1 4676function vim . fn . hlexists ( name ) end 4677 4678--- Lua: Prefer |uv.os_gethostname()|. 4679--- 4680--- Returns the hostname of the machine on which the Nvim server 4681--- (not the UI client) is currently running. 4682--- 4683--- @return string 4684function vim . fn . hostname () end 4685 4686--- Lua: Prefer |vim.iconv()|. 4687--- 4688--- Converts the encoding of {string} from {from} to {to}. 4689--- Returns the converted String. 4690--- When the conversion completely fails an empty string is 4691--- returned. When some characters could not be converted they 4692--- are replaced with "?". 4693--- The encoding names are whatever the iconv() library function 4694--- can accept, see ":!man 3 iconv". 4695--- Note that Vim uses UTF-8 for all Unicode encodings, conversion 4696--- from/to UCS-2 is automatically changed to use UTF-8. You 4697--- cannot use UCS-2 in a string anyway, because of the NUL bytes. 4698--- 4699--- @param string string 4700--- @param from string 4701--- @param to string 4702--- @return string 4703function vim . fn . iconv ( string , from , to ) end 4704 4705--- Returns a |String| which is a unique identifier of the 4706--- container type (|List|, |Dict|, |Blob| and |Partial|). It is 4707--- guaranteed that for the mentioned types `id(v1) ==# id(v2)` 4708--- returns true iff `type(v1) == type(v2) && v1 is v2`. 4709--- Note that `v:_null_string`, `v:_null_list`, `v:_null_dict` and 4710--- `v:_null_blob` have the same `id()` with different types 4711--- because they are internally represented as NULL pointers. 4712--- `id()` returns a hexadecimal representation of the pointers to 4713--- the containers (i.e. like `0x994a40`), same as `printf("%p", 4714--- {expr})`, but it is advised against counting on the exact 4715--- format of the return value. 4716--- 4717--- It is not guaranteed that `id(no_longer_existing_container)` 4718--- will not be equal to some other `id()`: new containers may 4719--- reuse identifiers of the garbage-collected ones. 4720--- 4721--- @param expr any 4722--- @return string 4723function vim . fn . id ( expr ) end 4724 4725--- Returns the indent of line {lnum} in the current buffer. 4726--- The indent is counted in spaces, the value of 'tabstop' is 4727--- relevant. {lnum} is used just like in 4728--- |getline()|. 4729--- When {lnum} is invalid -1 is returned. 4730--- 4731--- To get or set indent of lines in a string, see |vim.text.indent()|. 4732--- 4733--- @param lnum integer|string 4734--- @return integer 4735function vim . fn . indent ( lnum ) end 4736 4737--- Lua: Prefer |vim.iter()| with |Iter:enumerate()| and |Iter:find()| for lists; result is 1-based, and `start`, `ic`, and Blob semantics differ. 4738--- 4739--- Find {expr} in {object} and return its index. See 4740--- |indexof()| for using a lambda to select the item. 4741--- 4742--- If {object} is a |List| return the lowest index where the item 4743--- has a value equal to {expr}. There is no automatic 4744--- conversion, so the String "4" is different from the Number 4. 4745--- And the Number 4 is different from the Float 4.0. The value 4746--- of 'ignorecase' is not used here, case matters as indicated by 4747--- the {ic} argument. 4748--- 4749--- If {object} is a |Blob| return the lowest index where the byte 4750--- value is equal to {expr}. 4751--- 4752--- If {start} is given then start looking at the item with index 4753--- {start} (may be negative for an item relative to the end). 4754--- 4755--- When {ic} is given and it is |TRUE|, ignore case. Otherwise 4756--- case must match. 4757--- 4758--- -1 is returned when {expr} is not found in {object}. 4759--- Example: >vim 4760--- let idx = index(words, "the") 4761--- if index(numbers, 123) >= 0 4762--- " ... 4763--- endif 4764--- < 4765--- 4766--- @param object any 4767--- @param expr any 4768--- @param start? integer 4769--- @param ic? boolean 4770--- @return integer 4771function vim . fn . index ( object , expr , start , ic ) end 4772 4773--- Lua: Prefer |vim.iter()| with |Iter:enumerate()| and |Iter:find()| for list predicates; result is 1-based, and `startidx` and Blob semantics differ. 4774--- 4775--- Returns the index of an item in {object} where {expr} is 4776--- v:true. {object} must be a |List| or a |Blob|. 4777--- 4778--- If {object} is a |List|, evaluate {expr} for each item in the 4779--- List until the expression is v:true and return the index of 4780--- this item. 4781--- 4782--- If {object} is a |Blob| evaluate {expr} for each byte in the 4783--- Blob until the expression is v:true and return the index of 4784--- this byte. 4785--- 4786--- {expr} must be a |string| or |Funcref|. 4787--- 4788--- If {expr} is a |string|: If {object} is a |List|, inside 4789--- {expr} |v:key| has the index of the current List item and 4790--- |v:val| has the value of the item. If {object} is a |Blob|, 4791--- inside {expr} |v:key| has the index of the current byte and 4792--- |v:val| has the byte value. 4793--- 4794--- If {expr} is a |Funcref| it must take two arguments: 4795--- 1. the key or the index of the current item. 4796--- 2. the value of the current item. 4797--- The function must return |TRUE| if the item is found and the 4798--- search should stop. 4799--- 4800--- The optional argument {opts} is a Dict and supports the 4801--- following items: 4802--- startidx start evaluating {expr} at the item with this 4803--- index; may be negative for an item relative to 4804--- the end 4805--- Returns -1 when {expr} evaluates to v:false for all the items. 4806--- Example: >vim 4807--- let l = [#{n: 10}, #{n: 20}, #{n: 30}] 4808--- echo indexof(l, "v:val.n == 20") 4809--- echo indexof(l, {i, v -> v.n == 30}) 4810--- echo indexof(l, "v:val.n == 20", #{startidx: 1}) 4811--- < 4812--- 4813--- @param object any 4814--- @param expr any 4815--- @param opts? table 4816--- @return integer 4817function vim . fn . indexof ( object , expr , opts ) end 4818 4819--- Lua: Prefer |vim.ui.input()| for callback-based input. 4820--- 4821--- 4822--- Lua: Prefer |vim.ui.input()| for callback-based input. 4823--- 4824--- Prompts the user to enter text on the command-line, and 4825--- returns the text as a String. The {prompt} argument is either 4826--- a prompt string, or a blank string (for no prompt). A '\n' 4827--- can be used in the prompt to start a new line. 4828--- 4829--- In the second form it accepts a single dictionary with the 4830--- following keys, any of which may be omitted: 4831--- 4832--- Key Default Description ~ 4833--- prompt "" Same as {prompt} in the first form. 4834--- default "" Same as {text} in the first form. 4835--- completion nothing Same as {completion} in the first form. 4836--- cancelreturn "" The value returned when the dialog is 4837--- cancelled. 4838--- highlight nothing Highlight handler: |Funcref|. 4839--- 4840--- The highlighting set with |:echohl| is used for the prompt. 4841--- The input is entered just like a command-line, with the same 4842--- editing commands and mappings. There is a separate history 4843--- for lines typed for input(). 4844--- Example: >vim 4845--- if input("Coffee or beer? ") == "beer" 4846--- echo "Cheers!" 4847--- endif 4848--- < 4849--- If the optional {text} argument is present and not empty, this 4850--- is used for the default reply, as if the user typed this. 4851--- Example: >vim 4852--- let color = input("Color? ", "white") 4853--- 4854--- <The optional {completion} argument specifies the type of 4855--- completion supported for the input. Without it completion is 4856--- not performed. The supported completion types are the same as 4857--- that can be supplied to a user-defined command using the 4858--- "-complete=" argument. Refer to |:command-completion| for 4859--- more information. Example: >vim 4860--- let fname = input("File: ", "", "file") 4861--- 4862--- < *input()-highlight* *E5400* *E5402* 4863--- The optional `highlight` key allows specifying function which 4864--- will be used for highlighting user input. This function 4865--- receives user input as its only argument and must return 4866--- a list of 3-tuples [hl_start_col, hl_end_col + 1, hl_group] 4867--- where 4868--- hl_start_col is the first highlighted column, 4869--- hl_end_col is the last highlighted column (+ 1!), 4870--- hl_group is |:hi| group used for highlighting. 4871--- *E5403* *E5404* *E5405* *E5406* 4872--- Both hl_start_col and hl_end_col + 1 must point to the start 4873--- of the multibyte character (highlighting must not break 4874--- multibyte characters), hl_end_col + 1 may be equal to the 4875--- input length. Start column must be in range [0, len(input)), 4876--- end column must be in range (hl_start_col, len(input)], 4877--- sections must be ordered so that next hl_start_col is greater 4878--- then or equal to previous hl_end_col. 4879--- 4880--- Example (try some input with parentheses): >vim 4881--- highlight RBP1 guibg=Red ctermbg=red 4882--- highlight RBP2 guibg=Yellow ctermbg=yellow 4883--- highlight RBP3 guibg=Green ctermbg=green 4884--- highlight RBP4 guibg=Blue ctermbg=blue 4885--- let g:rainbow_levels = 4 4886--- function! RainbowParens(cmdline) 4887--- let ret = [] 4888--- let i = 0 4889--- let lvl = 0 4890--- while i < len(a:cmdline) 4891--- if a:cmdline[i] is# '(' 4892--- call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)]) 4893--- let lvl += 1 4894--- elseif a:cmdline[i] is# ')' 4895--- let lvl -= 1 4896--- call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)]) 4897--- endif 4898--- let i += 1 4899--- endwhile 4900--- return ret 4901--- endfunction 4902--- call input({'prompt':'>','highlight':'RainbowParens'}) 4903--- < 4904--- Highlight function is called at least once for each new 4905--- displayed input string, before command-line is redrawn. It is 4906--- expected that function is pure for the duration of one input() 4907--- call, i.e. it produces the same output for the same input, so 4908--- output may be memoized. Function is run like under |:silent| 4909--- modifier. If the function causes any errors, it will be 4910--- skipped for the duration of the current input() call. 4911--- 4912--- Highlighting is disabled if command-line contains arabic 4913--- characters. 4914--- 4915--- NOTE: This function must not be used in a startup file, for 4916--- the versions that only run in GUI mode (e.g., the Win32 GUI). 4917--- Note: When input() is called from within a mapping it will 4918--- consume remaining characters from that mapping, because a 4919--- mapping is handled like the characters were typed. 4920--- Use |inputsave()| before input() and |inputrestore()| 4921--- after input() to avoid that. Another solution is to avoid 4922--- that further characters follow in the mapping, e.g., by using 4923--- |:execute| or |:normal|. 4924--- 4925--- Example with a mapping: >vim 4926--- nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR> 4927--- function GetFoo() 4928--- call inputsave() 4929--- let g:Foo = input("enter search pattern: ") 4930--- call inputrestore() 4931--- endfunction 4932--- < 4933--- 4934--- @overload fun(opts: table): (string) 4935--- @param prompt string 4936--- @param text? string 4937--- @param completion? string 4938--- @return string 4939function vim . fn . input ( prompt , text , completion ) end 4940 4941--- @deprecated 4942--- Lua: Prefer |vim.ui.input()| for callback-based input. 4943--- 4944--- Use |input()| instead. 4945--- 4946--- @param ... any 4947--- @return any 4948function vim . fn . inputdialog ( ... ) end 4949 4950--- Lua: Prefer |vim.ui.select()| for simple selection menus; callback, returned item, and out-of-range semantics differ. 4951--- 4952--- Displays a list of strings and prompts the user to select 4953--- one by entering a number. {textlist} must be a |List| of 4954--- strings. Returns the number the user entered. 4955--- The user can also select an item by clicking on it with the 4956--- mouse, if the mouse is enabled in the command line ('mouse' is 4957--- "a" or includes "c"). For the first string 0 is returned. 4958--- When clicking above the first item a negative number is 4959--- returned. When clicking on the prompt one more than the 4960--- length of {textlist} is returned. 4961--- Make sure {textlist} has less than 'lines' entries, otherwise 4962--- it won't work. It's a good idea to put the entry number at 4963--- the start of the string. And put a prompt in the first item. 4964--- Example: >vim 4965--- let color = inputlist(['Select color:', '1. red', 4966--- \ '2. green', '3. blue']) 4967--- < 4968--- 4969--- @param textlist string[] 4970--- @return any 4971function vim . fn . inputlist ( textlist ) end 4972 4973--- Restore typeahead that was saved with a previous |inputsave()|. 4974--- Should be called the same number of times |inputsave()| is 4975--- called. Calling it more often is harmless though. 4976--- Returns TRUE when there is nothing to restore, FALSE 4977--- otherwise. 4978--- 4979--- @return integer 4980function vim . fn . inputrestore () end 4981 4982--- Preserve typeahead (also from mappings) and clear it, so that 4983--- a following prompt gets input from the user. Should be 4984--- followed by a matching |inputrestore()| after the prompt. Can 4985--- be used several times, in which case there must be just as 4986--- many |inputrestore()| calls. 4987--- Returns TRUE when out of memory, FALSE otherwise. 4988--- 4989--- @return integer 4990function vim . fn . inputsave () end 4991 4992--- This function acts much like the |input()| function with but 4993--- two exceptions: 4994--- a) the user's response will be displayed as a sequence of 4995--- asterisks ("*") thereby keeping the entry secret, and 4996--- b) the user's response will not be recorded on the input 4997--- |history| stack. 4998--- The result is a String, which is whatever the user actually 4999--- typed on the command-line in response to the issued prompt. 5000--- NOTE: Command-line completion is not supported. 5001--- 5002--- @param prompt string 5003--- @param text? string 5004--- @return string 5005function vim . fn . inputsecret ( prompt , text ) end 5006 5007--- Lua: Prefer |table.insert()| for lists; blob insertion and negative indexes differ. 5008--- 5009--- When {object} is a |List| or a |Blob| insert {item} at the start 5010--- of it. 5011--- 5012--- If {idx} is specified insert {item} before the item with index 5013--- {idx}. If {idx} is zero it goes before the first item, just 5014--- like omitting {idx}. A negative {idx} is also possible, see 5015--- |list-index|. -1 inserts just before the last item. 5016--- 5017--- Returns the resulting |List| or |Blob|. Examples: >vim 5018--- let mylist = insert([2, 3, 5], 1) 5019--- call insert(mylist, 4, -1) 5020--- call insert(mylist, 6, len(mylist)) 5021--- <The last example can be done simpler with |add()|. 5022--- Note that when {item} is a |List| it is inserted as a single 5023--- item. Use |extend()| to concatenate |Lists|. 5024--- 5025--- @param object any 5026--- @param item any 5027--- @param idx? integer 5028--- @return any 5029function vim . fn . insert ( object , item , idx ) end 5030 5031--- Interrupt script execution. It works more or less like the 5032--- user typing CTRL-C, most commands won't execute and control 5033--- returns to the user. This is useful to abort execution 5034--- from lower down, e.g. in an autocommand. Example: >vim 5035--- function s:check_typoname(file) 5036--- if fnamemodify(a:file, ':t') == '[' 5037--- echomsg 'Maybe typo' 5038--- call interrupt() 5039--- endif 5040--- endfunction 5041--- au BufWritePre * call s:check_typoname(expand('<amatch>')) 5042--- < 5043--- 5044--- @return any 5045function vim . fn . interrupt () end 5046 5047--- Lua: Prefer |bit.bnot()|. 5048--- 5049--- Bitwise invert. The argument is converted to a number. A 5050--- List, Dict or Float argument causes an error. Example: >vim 5051--- let bits = invert(bits) 5052--- < 5053--- 5054--- @param expr integer 5055--- @return integer 5056function vim . fn . invert ( expr ) end 5057 5058--- Checks whether {path} is an absolute path. Returns |TRUE| 5059--- if so, |FALSE| otherwise. 5060--- On Unix, a path is considered absolute when it starts with 5061--- '/'. 5062--- On MS-Windows, it is considered absolute when it starts with 5063--- an optional drive prefix and is followed by a '\' or '/'. UNC 5064--- paths are always absolute. 5065--- Example: >vim 5066--- echo isabsolutepath('/usr/share/') " 1 5067--- echo isabsolutepath('./foobar') " 0 5068--- echo isabsolutepath('C:\Windows') " 1 5069--- echo isabsolutepath('foobar') " 0 5070--- echo isabsolutepath('\\remote\file') " 1 5071--- < 5072--- 5073--- @param path string 5074--- @return 0|1 5075function vim . fn . isabsolutepath ( path ) end 5076 5077--- Lua: Prefer |uv.fs_stat()| and check `type == "directory"`. 5078--- 5079--- Returns |TRUE| if {directory} exists, or |FALSE| if it doesn't 5080--- exist or isn't a directory. {directory} is any expression, 5081--- which is used as a String. 5082--- 5083--- @param directory string 5084--- @return 0|1 5085function vim . fn . isdirectory ( directory ) end 5086 5087--- Lua: Prefer `expr == math.huge and 1 or expr == -math.huge and -1 or 0`. 5088--- 5089--- Return 1 if {expr} is a positive infinity, or -1 a negative 5090--- infinity, otherwise 0. >vim 5091--- echo isinf(1.0 / 0.0) 5092--- < 1 >vim 5093--- echo isinf(-1.0 / 0.0) 5094--- < -1 5095--- 5096--- @param expr number 5097--- @return 1|0|-1 5098function vim . fn . isinf ( expr ) end 5099 5100--- Returns |TRUE| if {expr} is the name of a locked variable, 5101--- else |FALSE|. 5102--- The string argument {expr} must be the name of a variable, 5103--- |List| item or |Dictionary| entry, not the variable itself! 5104--- Example: >vim 5105--- let alist = [0, ['a', 'b'], 2, 3] 5106--- lockvar 1 alist 5107--- echo islocked('alist') " 1 5108--- echo islocked('alist[1]') " 0 5109--- 5110--- <When {expr} is a variable that does not exist you get an error 5111--- message. Use |exists()| to check for existence. 5112--- 5113--- @param expr any 5114--- @return 0|1 5115function vim . fn . islocked ( expr ) end 5116 5117--- Lua: Prefer `expr ~= expr`. 5118--- 5119--- Return |TRUE| if {expr} is a float with value NaN. >vim 5120--- echo isnan(0.0 / 0.0) 5121--- < 1 5122--- 5123--- @param expr number 5124--- @return 0|1 5125function vim . fn . isnan ( expr ) end 5126 5127--- Lua: Prefer |pairs()| or |ipairs()|. 5128--- 5129--- Return a |List| with all key/index and value pairs of {expr}. 5130--- Each |List| item is a list with two items: 5131--- - for a |Dict|: the key and the value 5132--- - for a |List|, |Blob| or |String|: the index and the value 5133--- The returned |List| is in arbitrary order for a |Dict|, 5134--- otherwise it's in ascending order of the index. 5135--- 5136--- Also see |keys()| and |values()|. 5137--- 5138--- Example: >vim 5139--- let mydict = #{a: 'red', b: 'blue'} 5140--- for [key, value] in items(mydict) 5141--- echo $"{key} = {value}" 5142--- endfor 5143--- echo items([1, 2, 3]) 5144--- echo items("foobar") 5145--- echo items(0z0102) 5146--- < 5147--- 5148--- @param expr table|string 5149--- @return any 5150function vim . fn . items ( expr ) end 5151 5152--- @deprecated 5153--- Obsolete name for |chanclose()| 5154--- 5155--- @param ... any 5156--- @return any 5157function vim . fn . jobclose ( ... ) end 5158 5159--- Lua: Prefer |vim.system()| object `.pid`; |job-id| and channel semantics differ. 5160--- 5161--- Return the PID (process id) of |job-id| {job}. 5162--- 5163--- @param job integer 5164--- @return integer 5165function vim . fn . jobpid ( job ) end 5166 5167--- Resize the pseudo terminal window of |job-id| {job} to {width} 5168--- columns and {height} rows. 5169--- Fails if the job was not started with `"pty":v:true`. 5170--- 5171--- @param job integer 5172--- @param width integer 5173--- @param height integer 5174--- @return any 5175function vim . fn . jobresize ( job , width , height ) end 5176 5177--- @deprecated 5178--- Lua: Prefer |nvim_chan_send()| for string data; list input and the return value differ. 5179--- 5180--- Obsolete name for |chansend()| 5181--- 5182--- @param ... any 5183--- @return any 5184function vim . fn . jobsend ( ... ) end 5185 5186--- Lua: Prefer |vim.system()| for simple processes; |RPC|, PTY/term, streaming callbacks, and shell-string behavior differ. 5187--- 5188--- Spawns {cmd} as a job. 5189--- If {cmd} is a List it runs directly (no 'shell'). 5190--- If {cmd} is a String it runs in the 'shell', like this: >vim 5191--- call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}']) 5192--- <(See |shell-unquoting| for details.) 5193--- 5194--- Example: start a job and handle its output: >vim 5195--- call jobstart(['nvim', '-h'], {'on_stdout':{j,d,e->append(line('.'),d)}}) 5196--- < 5197--- Example: start a job in a |terminal| connected to the current buffer: >vim 5198--- call jobstart(['nvim', '-h'], {'term':v:true}) 5199--- < 5200--- Returns |job-id| on success, 0 on invalid arguments (or job 5201--- table is full), -1 if {cmd}[0] or 'shell' is not executable. 5202--- The returned job-id is a valid |channel-id| representing the 5203--- job's stdio streams. Use |chansend()| (or |rpcnotify()| and 5204--- |rpcrequest()| if "rpc" was enabled) to send data to stdin and 5205--- |chanclose()| to close the streams without stopping the job. 5206--- 5207--- See |job-control| and |RPC|. 5208--- 5209--- NOTE: on Windows if {cmd} is a List: 5210--- - cmd[0] must be an executable (not a "built-in"). If it is 5211--- in $PATH it can be called by name, without an extension: >vim 5212--- call jobstart(['ping', 'neovim.io']) 5213--- < If it is a full or partial path, extension is required: >vim 5214--- call jobstart(['System32\ping.exe', 'neovim.io']) 5215--- < - {cmd} is collapsed to a string of quoted args as expected 5216--- by CommandLineToArgvW https://msdn.microsoft.com/bb776391 5217--- unless cmd[0] is some form of "cmd.exe". 5218--- 5219--- *jobstart-env* 5220--- The job environment is initialized as follows: 5221--- $NVIM is set to |v:servername| of the parent Nvim 5222--- $NVIM_LISTEN_ADDRESS is unset 5223--- $NVIM_LOG_FILE is unset 5224--- $VIM is unset 5225--- $VIMRUNTIME is unset 5226--- You can set these with the `env` option. 5227--- 5228--- *jobstart-options* 5229--- {opts} is a dictionary with these keys: 5230--- clear_env: (boolean) `env` defines the job environment 5231--- exactly, instead of merging current environment. 5232--- cwd: (string, default=|current-directory|) Working 5233--- directory of the job. 5234--- detach: (boolean) Detach the job process: it will not be 5235--- killed when Nvim exits. If the process exits 5236--- before Nvim, `on_exit` will be invoked. 5237--- env: (dict) Map of environment variable name:value 5238--- pairs extending (or replace with "clear_env") 5239--- the current environment. |jobstart-env| 5240--- height: (number) Height of the `pty` terminal. 5241--- |on_exit|: (function) Callback invoked when the job exits. 5242--- |on_stdout|: (function) Callback invoked when the job emits 5243--- stdout data. 5244--- |on_stderr|: (function) Callback invoked when the job emits 5245--- stderr data. 5246--- overlapped: (boolean) Sets FILE_FLAG_OVERLAPPED for the 5247--- stdio passed to the child process. Only on 5248--- MS-Windows; ignored on other platforms. 5249--- pty: (boolean) Connect the job to a new pseudo 5250--- terminal, and its streams to the master file 5251--- descriptor. `on_stdout` receives all output, 5252--- `on_stderr` is ignored. Note: if the child writes 5253--- a query (DA1, OSC, …), it may hang or timeout waiting 5254--- for a response! To avoid that, `on_stdout` should 5255--- reply via |nvim_chan_send()| on the child's stdin. 5256--- See |terminal-start| |terminal-concepts| 5257--- rpc: (boolean) Use |msgpack-rpc| to communicate with 5258--- the job over stdio. Then `on_stdout` is ignored, 5259--- but `on_stderr` can still be used. 5260--- stderr_buffered: (boolean) Collect data until EOF (stream closed) 5261--- before invoking `on_stderr`. |channel-buffered| 5262--- stdout_buffered: (boolean) Collect data until EOF (stream 5263--- closed) before invoking `on_stdout`. |channel-buffered| 5264--- stdin: (string) Either "pipe" (default) to connect the 5265--- job's stdin to a channel or "null" to disconnect 5266--- stdin. 5267--- term: (boolean) Spawns {cmd} in a new pseudo-terminal 5268--- session connected to the current (unmodified) buffer. 5269--- Implies "pty". Defaults "height" and "width" to the 5270--- current window dimensions. Defaults $TERM to 5271--- "xterm-256color". 5272--- width: (number) Width of the `pty` pseudo-terminal. 5273--- 5274--- {opts} is passed as |self| dictionary to the callback; the 5275--- caller may set other keys to pass application-specific data. 5276--- 5277--- Returns: 5278--- - |channel-id| on success 5279--- - 0 on invalid arguments 5280--- - -1 if {cmd}[0] is not executable. 5281--- See also |job-control|, |channel|, |msgpack-rpc|. 5282--- 5283--- @param cmd string|string[] 5284--- @param opts? table 5285--- @return integer 5286function vim . fn . jobstart ( cmd , opts ) end 5287 5288--- Lua: Prefer |SystemObj:kill()| on a |vim.system()| object; |job-id| semantics differ. 5289--- 5290--- Stop |job-id| {id} by sending SIGTERM to the job process. If 5291--- the process does not terminate after a timeout then SIGKILL 5292--- will be sent. When the job terminates its |on_exit| handler 5293--- (if any) will be invoked. 5294--- See |job-control|. 5295--- 5296--- Returns 1 for valid job id, 0 for invalid id, including jobs have 5297--- exited or stopped. 5298--- 5299--- @param id integer 5300--- @return integer 5301function vim . fn . jobstop ( id ) end 5302 5303--- Lua: Prefer |SystemObj:wait()| on a |vim.system()| object; list input and status values differ. 5304--- 5305--- Waits for jobs and their |on_exit| handlers to complete. 5306--- 5307--- {jobs} is a List of |job-id|s to wait for. 5308--- {timeout} is the maximum waiting time in milliseconds. If 5309--- omitted or -1, wait forever. 5310--- 5311--- Timeout of 0 can be used to check the status of a job: >vim 5312--- let running = jobwait([{job-id}], 0)[0] == -1 5313--- < 5314--- During jobwait() callbacks for jobs not in the {jobs} list may 5315--- be invoked. The screen will not redraw unless |:redraw| is 5316--- invoked by a callback. 5317--- 5318--- Returns a list of len({jobs}) integers, where each integer is 5319--- the status of the corresponding job: 5320--- Exit-code, if the job exited 5321--- -1 if the timeout was exceeded 5322--- -2 if the job was interrupted (by |CTRL-C|) 5323--- -3 if the job-id is invalid 5324--- 5325--- @param jobs integer[] 5326--- @param timeout? integer 5327--- @return integer[] 5328function vim . fn . jobwait ( jobs , timeout ) end 5329 5330--- Lua: Prefer |table.concat()| for string lists; non-string values stringify differently. 5331--- 5332--- Join the items in {list} together into one String. 5333--- When {sep} is specified it is put in between the items. If 5334--- {sep} is omitted a single space is used. 5335--- Note that {sep} is not added at the end. You might want to 5336--- add it there too: >vim 5337--- let lines = join(mylist, "\n") .. "\n" 5338--- <String items are used as-is. |Lists| and |Dictionaries| are 5339--- converted into a string like with |string()|. 5340--- The opposite function is |split()|. 5341--- 5342--- @param list any[] 5343--- @param sep? string 5344--- @return string 5345function vim . fn . join ( list , sep ) end 5346 5347--- Lua: Prefer |vim.json.decode()|. 5348--- 5349--- Convert {expr} from JSON object. Accepts |readfile()|-style 5350--- list as the input, as well as regular string. May output any 5351--- Vim value. In the following cases it will output 5352--- |msgpack-special-dict|: 5353--- 1. Dictionary contains duplicate key. 5354--- 2. String contains NUL byte. Two special dictionaries: for 5355--- dictionary and for string will be emitted in case string 5356--- with NUL byte was a dictionary key. 5357--- 5358--- Note: function treats its input as UTF-8 always. The JSON 5359--- standard allows only a few encodings, of which UTF-8 is 5360--- recommended and the only one required to be supported. 5361--- Non-UTF-8 characters are an error. 5362--- 5363--- @param expr any 5364--- @return any 5365function vim . fn . json_decode ( expr ) end 5366 5367--- Lua: Prefer |vim.json.encode()|. 5368--- 5369--- Convert {expr} into a JSON string. Accepts 5370--- |msgpack-special-dict| as the input. Will not convert 5371--- |Funcref|s, mappings with non-string keys (can be created as 5372--- |msgpack-special-dict|), values with self-referencing 5373--- containers, strings which contain non-UTF-8 characters, 5374--- pseudo-UTF-8 strings which contain codepoints reserved for 5375--- surrogate pairs (such strings are not valid UTF-8 strings). 5376--- Non-printable characters are converted into "\u1234" escapes 5377--- or special escapes like "\t", other are dumped as-is. 5378--- |Blob|s are converted to arrays of the individual bytes. 5379--- 5380--- @param expr any 5381--- @return string 5382function vim . fn . json_encode ( expr ) end 5383 5384--- Lua: Prefer |vim.tbl_keys()|. 5385--- 5386--- Return a |List| with all the keys of {dict}. The |List| is in 5387--- arbitrary order. Also see |items()| and |values()|. 5388--- 5389--- @param dict table 5390--- @return string[] 5391function vim . fn . keys ( dict ) end 5392 5393--- Turn the internal byte representation of keys into a form that 5394--- can be used for |:map|. E.g. >vim 5395--- let xx = "\<C-Home>" 5396--- echo keytrans(xx) 5397--- < <C-Home> 5398--- 5399--- @param string string 5400--- @return string 5401function vim . fn . keytrans ( string ) end 5402 5403--- @deprecated 5404--- Obsolete name for bufnr("$"). 5405--- 5406--- @return any 5407function vim . fn . last_buffer_nr () end 5408 5409--- Lua: Prefer Lua `#` operator for strings and lists or `#vim.tbl_keys(expr)` for dicts. 5410--- 5411--- Returns the length of the argument. 5412--- When {expr} is a String or a Number the length in bytes is 5413--- used, as with |strlen()|. 5414--- When {expr} is a |List| the number of items in the |List| is 5415--- returned. 5416--- When {expr} is a |Blob| the number of bytes is returned. 5417--- When {expr} is a |Dictionary| the number of entries in the 5418--- |Dictionary| is returned. 5419--- Otherwise an error is given and returns zero. 5420--- 5421--- @param expr any[] 5422--- @return integer 5423function vim . fn . len ( expr ) end 5424 5425--- Lua: Prefer |package.loadlib()| or `ffi.load()`. 5426--- 5427--- Call function {funcname} in the run-time library {libname} 5428--- with single argument {argument}. 5429--- This is useful to call functions in a library that you 5430--- especially made to be used with Vim. Since only one argument 5431--- is possible, calling standard library functions is rather 5432--- limited. 5433--- The result is the String returned by the function. If the 5434--- function returns NULL, this will appear as an empty string "" 5435--- to Vim. 5436--- If the function returns a number, use |libcallnr()|! 5437--- If {argument} is a number, it is passed to the function as an 5438--- int; if {argument} is a string, it is passed as a 5439--- null-terminated string. 5440--- 5441--- libcall() allows you to write your own 'plug-in' extensions to 5442--- Vim without having to recompile the program. It is NOT a 5443--- means to call system functions! If you try to do so Vim will 5444--- very probably crash. 5445--- 5446--- For Win32, the functions you write must be placed in a DLL 5447--- and use the normal C calling convention (NOT Pascal which is 5448--- used in Windows System DLLs). The function must take exactly 5449--- one parameter, either a character pointer or a long integer, 5450--- and must return a character pointer or NULL. The character 5451--- pointer returned must point to memory that will remain valid 5452--- after the function has returned (e.g. in static data in the 5453--- DLL). If it points to allocated memory, that memory will 5454--- leak away. Using a static buffer in the function should work, 5455--- it's then freed when the DLL is unloaded. 5456--- 5457--- WARNING: If the function returns a non-valid pointer, Vim may 5458--- crash! This also happens if the function returns a number, 5459--- because Vim thinks it's a pointer. 5460--- For Win32 systems, {libname} should be the filename of the DLL 5461--- without the ".DLL" suffix. A full path is only required if 5462--- the DLL is not in the usual places. 5463--- For Unix: When compiling your own plugins, remember that the 5464--- object code must be compiled as position-independent ('PIC'). 5465--- Examples: >vim 5466--- echo libcall("libc.so", "getenv", "HOME") 5467--- < 5468--- 5469--- @param libname string 5470--- @param funcname string 5471--- @param argument any 5472--- @return any 5473function vim . fn . libcall ( libname , funcname , argument ) end 5474 5475--- Lua: Prefer |package.loadlib()| or `ffi.load()`. 5476--- 5477--- Just like |libcall()|, but used for a function that returns an 5478--- int instead of a string. 5479--- Examples: >vim 5480--- echo libcallnr("/usr/lib/libc.so", "getpid", "") 5481--- call libcallnr("libc.so", "printf", "Hello World!\n") 5482--- call libcallnr("libc.so", "sleep", 10) 5483--- < 5484--- 5485--- @param libname string 5486--- @param funcname string 5487--- @param argument any 5488--- @return any 5489function vim . fn . libcallnr ( libname , funcname , argument ) end 5490 5491--- Lua: Prefer |nvim_win_get_cursor()| for "." or |nvim_buf_line_count()| for "$"; marks, lists, and other position expressions differ. 5492--- 5493--- See |getpos()| for accepted positions. 5494--- 5495--- To get the column number use |col()|. To get both use 5496--- |getpos()|. 5497--- 5498--- With the optional {winid} argument the values are obtained for 5499--- that window instead of the current window. 5500--- 5501--- Returns 0 for invalid values of {expr} and {winid}. 5502--- 5503--- Examples: >vim 5504--- echo line(".") " line number of the cursor 5505--- echo line(".", winid) " idem, in window "winid" 5506--- echo line("'t") " line number of mark t 5507--- echo line("'" .. marker) " line number of mark marker 5508--- < 5509--- To jump to the last known position when opening a file see 5510--- |last-position-jump|. 5511--- 5512--- @param expr string|integer[] 5513--- @param winid? integer 5514--- @return integer 5515function vim . fn . line ( expr , winid ) end 5516 5517--- Lua: Prefer |nvim_buf_get_offset()| with `lnum - 1`; 'fileformat' and invalid-line semantics differ. 5518--- 5519--- Return the byte count from the start of the buffer for line 5520--- {lnum}. This includes the end-of-line character, depending on 5521--- the 'fileformat' option for the current buffer. The first 5522--- line returns 1. UTF-8 encoding is used, 'fileencoding' is 5523--- ignored. This can also be used to get the byte count for the 5524--- line just below the last line: >vim 5525--- echo line2byte(line("$") + 1) 5526--- <This is the buffer size plus one. If 'fileencoding' is empty 5527--- it is the file size plus one. {lnum} is used like with 5528--- |getline()|. When {lnum} is invalid -1 is returned. 5529--- Also see |byte2line()|, |go| and |:goto|. 5530--- 5531--- @param lnum integer|string 5532--- @return integer 5533function vim . fn . line2byte ( lnum ) end 5534 5535--- Get the amount of indent for line {lnum} according the lisp 5536--- indenting rules, as with 'lisp'. 5537--- The indent is counted in spaces, the value of 'tabstop' is 5538--- relevant. {lnum} is used just like in |getline()|. 5539--- When {lnum} is invalid, -1 is returned. 5540--- 5541--- @param lnum integer|string 5542--- @return integer 5543function vim . fn . lispindent ( lnum ) end 5544 5545--- Return a Blob concatenating all the number values in {list}. 5546--- Examples: >vim 5547--- echo list2blob([1, 2, 3, 4]) " returns 0z01020304 5548--- echo list2blob([]) " returns 0z 5549--- <Returns an empty Blob on error. If one of the numbers is 5550--- negative or more than 255 error *E1239* is given. 5551--- 5552--- |blob2list()| does the opposite. 5553--- 5554--- @param list any[] 5555--- @return string 5556function vim . fn . list2blob ( list ) end 5557 5558--- Converts each codepoint in {list} to a UTF-8 character and 5559--- returns the concatenated string. Examples: >vim 5560--- echo list2str([32]) " returns " " 5561--- echo list2str([65, 66, 67]) " returns "ABC" 5562--- <The same can be done (slowly) with: >vim 5563--- echo join(map(list, {nr, val -> nr2char(val)}), '') 5564--- <|str2list()| does the opposite. 5565--- 5566--- UTF-8 encoding is always used, {utf8} option has no effect, 5567--- and exists only for backwards-compatibility. 5568--- With UTF-8 composing characters work as expected: >vim 5569--- echo list2str([97, 769]) " returns "á" 5570--- < 5571--- Returns an empty string on error. 5572--- 5573--- @param list any[] 5574--- @param utf8? boolean 5575--- @return string 5576function vim . fn . list2str ( list , utf8 ) end 5577 5578--- Lua: Prefer |os.time()|. 5579--- 5580--- Return the current time, measured as seconds since 1st Jan 5581--- 1970. See also |strftime()|, |strptime()| and |getftime()|. 5582--- 5583--- @return integer 5584function vim . fn . localtime () end 5585 5586--- Lua: Prefer |math.log()|. 5587--- 5588--- Return the natural logarithm (base e) of {expr} as a |Float|. 5589--- {expr} must evaluate to a |Float| or a |Number| in the range 5590--- (0, inf]. 5591--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 5592--- Examples: >vim 5593--- echo log(10) 5594--- < 2.302585 >vim 5595--- echo log(exp(5)) 5596--- < 5.0 5597--- 5598--- @param expr number 5599--- @return number 5600function vim . fn . log ( expr ) end 5601 5602--- Lua: Prefer |math.log10()|. 5603--- 5604--- Return the logarithm of Float {expr} to base 10 as a |Float|. 5605--- {expr} must evaluate to a |Float| or a |Number|. 5606--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 5607--- Examples: >vim 5608--- echo log10(1000) 5609--- < 3.0 >vim 5610--- echo log10(0.01) 5611--- < -2.0 5612--- 5613--- @param expr number 5614--- @return number 5615function vim . fn . log10 ( expr ) end 5616 5617--- Lua: Prefer |vim.tbl_map()| for array-like tables; dict, string, blob, and in-place behavior differ. 5618--- 5619--- {expr1} must be a |List|, |String|, |Blob| or |Dictionary|. 5620--- When {expr1} is a |List| or |Dictionary|, replace each 5621--- item in {expr1} with the result of evaluating {expr2}. 5622--- For a |Blob| each byte is replaced. 5623--- For a |String|, each character, including composing 5624--- characters, is replaced. 5625--- If the item type changes you may want to use |mapnew()| to 5626--- create a new List or Dictionary. 5627--- 5628--- {expr2} must be a |String| or |Funcref|. 5629--- 5630--- If {expr2} is a |String|, inside {expr2} |v:val| has the value 5631--- of the current item. For a |Dictionary| |v:key| has the key 5632--- of the current item and for a |List| |v:key| has the index of 5633--- the current item. For a |Blob| |v:key| has the index of the 5634--- current byte. For a |String| |v:key| has the index of the 5635--- current character. 5636--- Example: >vim 5637--- call map(mylist, '"> " .. v:val .. " <"') 5638--- <This puts "> " before and " <" after each item in "mylist". 5639--- 5640--- Note that {expr2} is the result of an expression and is then 5641--- used as an expression again. Often it is good to use a 5642--- |literal-string| to avoid having to double backslashes. You 5643--- still have to double single (') quotes, though. 5644--- 5645--- If {expr2} is a |Funcref| it is called with two arguments: 5646--- 1. The key or the index of the current item. 5647--- 2. the value of the current item. 5648--- The function must return the new value of the item. Example 5649--- that changes each value by "key-value": >vim 5650--- func KeyValue(key, val) 5651--- return a:key .. '-' .. a:val 5652--- endfunc 5653--- call map(myDict, function('KeyValue')) 5654--- <It is shorter when using a |lambda|: >vim 5655--- call map(myDict, {key, val -> key .. '-' .. val}) 5656--- <If you do not use "val" you can leave it out: >vim 5657--- call map(myDict, {key -> 'item: ' .. key}) 5658--- <If you do not use "key" you can use a short name: >vim 5659--- call map(myDict, {_, val -> 'item: ' .. val}) 5660--- < 5661--- The operation is done in-place for a |List| and |Dictionary|. 5662--- If you want it to remain unmodified make a copy first: >vim 5663--- let tlist = map(copy(mylist), ' v:val .. "\t"') 5664--- 5665--- <Returns {expr1}, the |List| or |Dictionary| that was filtered, 5666--- or a new |Blob| or |String|. 5667--- When an error is encountered while evaluating {expr2} no 5668--- further items in {expr1} are processed. 5669--- When {expr2} is a Funcref errors inside a function are 5670--- ignored, unless it was defined with the "abort" flag. 5671--- 5672--- @param expr1 string|table|any[] 5673--- @param expr2 string|function 5674--- @return any 5675function vim . fn . map ( expr1 , expr2 ) end 5676 5677--- When {dict} is omitted or zero: Return the rhs of mapping 5678--- {name} in mode {mode}. The returned String has special 5679--- characters translated like in the output of the ":map" command 5680--- listing. When {dict} is TRUE a dictionary is returned, see 5681--- below. To get a list of all mappings see |maplist()|. 5682--- 5683--- When there is no mapping for {name}, an empty String is 5684--- returned if {dict} is FALSE, otherwise returns an empty Dict. 5685--- When the mapping for {name} is empty, then "<Nop>" is 5686--- returned. 5687--- 5688--- The {name} can have special key names, like in the ":map" 5689--- command. 5690--- 5691--- {mode} can be one of these strings: 5692--- "n" Normal 5693--- "v" Visual (including Select) 5694--- "o" Operator-pending 5695--- "i" Insert 5696--- "c" Cmd-line 5697--- "s" Select 5698--- "x" Visual 5699--- "l" langmap |language-mapping| 5700--- "t" Terminal 5701--- "" Normal, Visual and Operator-pending 5702--- When {mode} is omitted, the modes for "" are used. 5703--- 5704--- When {abbr} is there and it is |TRUE| use abbreviations 5705--- instead of mappings. 5706--- 5707--- When {dict} is |TRUE|, return a dictionary describing the 5708--- mapping, with these items: *mapping-dict* 5709--- "lhs" The {lhs} of the mapping as it would be typed 5710--- "lhsraw" The {lhs} of the mapping as raw bytes 5711--- "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate 5712--- form, only present when it differs from "lhsraw" 5713--- "rhs" The {rhs} of the mapping as typed. 5714--- "callback" Lua function, if RHS was defined as such. 5715--- "silent" 1 for a |:map-silent| mapping, else 0. 5716--- "noremap" 1 if the {rhs} of the mapping is not remappable. 5717--- "script" 1 if mapping was defined with <script>. 5718--- "expr" 1 for an expression mapping (|:map-<expr>|). 5719--- "buffer" 1 for a buffer local mapping (|:map-local|). 5720--- "mode" Modes for which the mapping is defined. In 5721--- addition to the modes mentioned above, these 5722--- characters will be used: 5723--- " " Normal, Visual and Operator-pending 5724--- "!" Insert and Commandline mode 5725--- (|mapmode-ic|) 5726--- "sid" The script local ID, used for <sid> mappings 5727--- (|<SID>|). Negative for special contexts. 5728--- "scriptversion" The version of the script, always 1. 5729--- "lnum" The line number in "sid", zero if unknown. 5730--- "nowait" Do not wait for other, longer mappings. 5731--- (|:map-<nowait>|). 5732--- "abbr" True if this is an |abbreviation|. 5733--- "mode_bits" Nvim's internal binary representation of "mode". 5734--- |mapset()| ignores this; only "mode" is used. 5735--- See |maplist()| for usage examples. The values 5736--- are from src/nvim/state_defs.h and may change in 5737--- the future. 5738--- 5739--- The dictionary can be used to restore a mapping with 5740--- |mapset()|. 5741--- 5742--- The mappings local to the current buffer are checked first, 5743--- then the global mappings. 5744--- This function can be used to map a key even when it's already 5745--- mapped, and have it do the original mapping too. Sketch: >vim 5746--- exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n') 5747--- < 5748--- 5749--- @overload fun(name: string, mode: string, abbr: boolean, dict: true): (table<string,any>) 5750--- @param name string 5751--- @param mode? string 5752--- @param abbr? boolean 5753--- @param dict? false 5754--- @return string 5755function vim . fn . maparg ( name , mode , abbr , dict ) end 5756 5757--- Check if there is a mapping that matches with {name} in mode 5758--- {mode}. See |maparg()| for {mode} and special names in 5759--- {name}. 5760--- When {abbr} is there and it is non-zero use abbreviations 5761--- instead of mappings. 5762--- A match happens with a mapping that starts with {name} and 5763--- with a mapping which is equal to the start of {name}. 5764--- 5765--- matches mapping "a" "ab" "abc" ~ 5766--- mapcheck("a") yes yes yes 5767--- mapcheck("abc") yes yes yes 5768--- mapcheck("ax") yes no no 5769--- mapcheck("b") no no no 5770--- 5771--- The difference with |maparg()| is that mapcheck() finds a 5772--- mapping that matches with {name}, while |maparg()| only finds a 5773--- mapping for {name} exactly. 5774--- When there is no mapping that starts with {name}, an empty 5775--- String is returned. If there is one, the RHS of that mapping 5776--- is returned. If there are several mappings that start with 5777--- {name}, the RHS of one of them is returned. This will be 5778--- "<Nop>" if the RHS is empty. 5779--- The mappings local to the current buffer are checked first, 5780--- then the global mappings. 5781--- This function can be used to check if a mapping can be added 5782--- without being ambiguous. Example: >vim 5783--- if mapcheck("_vv") == "" 5784--- map _vv :set guifont=7x13<CR> 5785--- endif 5786--- <This avoids adding the "_vv" mapping when there already is a 5787--- mapping for "_v" or for "_vvv". 5788--- 5789--- @param name string 5790--- @param mode? string 5791--- @param abbr? boolean 5792--- @return any 5793function vim . fn . mapcheck ( name , mode , abbr ) end 5794 5795--- Returns a |List| of all mappings. Each List item is a |Dict|, 5796--- the same as what is returned by |maparg()|, see 5797--- |mapping-dict|. When {abbr} is there and it is |TRUE| use 5798--- abbreviations instead of mappings. 5799--- 5800--- Example to show all mappings with "MultiMatch" in rhs: >vim 5801--- echo maplist()->filter({_, m -> 5802--- \ match(get(m, 'rhs', ''), 'MultiMatch') >= 0 5803--- \ }) 5804--- <It can be tricky to find mappings for particular |:map-modes|. 5805--- |mapping-dict|'s "mode_bits" can simplify this. For example, 5806--- the mode_bits for Normal, Insert or Command-line modes are 5807--- 0x19. To find all the mappings available in those modes you 5808--- can do: >vim 5809--- let saved_maps = [] 5810--- for m in maplist() 5811--- if and(m.mode_bits, 0x19) != 0 5812--- eval saved_maps->add(m) 5813--- endif 5814--- endfor 5815--- echo saved_maps->mapnew({_, m -> m.lhs}) 5816--- <The values of the mode_bits are defined in Nvim's 5817--- src/nvim/state_defs.h file and they can be discovered at 5818--- runtime using |:map-commands| and "maplist()". Example: >vim 5819--- omap xyzzy <Nop> 5820--- let op_bit = maplist()->filter( 5821--- \ {_, m -> m.lhs == 'xyzzy'})[0].mode_bits 5822--- ounmap xyzzy 5823--- echo printf("Operator-pending mode bit: 0x%x", op_bit) 5824--- < 5825--- 5826--- @param abbr? 0|1 5827--- @return table[] 5828function vim . fn . maplist ( abbr ) end 5829 5830--- Lua: Prefer |vim.tbl_map()| for tables; string, blob, and `v:key` callback behavior differ. 5831--- 5832--- Like |map()| but instead of replacing items in {expr1} a new 5833--- List or Dictionary is created and returned. {expr1} remains 5834--- unchanged. Items can still be changed by {expr2}, if you 5835--- don't want that use |deepcopy()| first. 5836--- 5837--- @param expr1 any 5838--- @param expr2 any 5839--- @return any 5840function vim . fn . mapnew ( expr1 , expr2 ) end 5841 5842--- Restore a mapping from a dictionary, possibly returned by 5843--- |maparg()| or |maplist()|. A buffer mapping, when dict.buffer 5844--- is true, is set on the current buffer; it is up to the caller 5845--- to ensure that the intended buffer is the current buffer. 5846--- This feature allows copying mappings from one buffer to 5847--- another. 5848--- The dict.mode value may restore a single mapping that covers 5849--- more than one mode, like with mode values of '!', ' ', "nox", 5850--- or 'v'. *E1276* 5851--- 5852--- In the first form, {mode} and {abbr} should be the same as 5853--- for the call to |maparg()|. *E460* 5854--- {mode} is used to define the mode in which the mapping is set, 5855--- not the "mode" entry in {dict}. 5856--- Example for saving and restoring a mapping: >vim 5857--- let save_map = maparg('K', 'n', 0, 1) 5858--- nnoremap K somethingelse 5859--- " ... 5860--- call mapset('n', 0, save_map) 5861--- <Note that if you are going to replace a map in several modes, 5862--- e.g. with `:map!`, you need to save/restore the mapping for 5863--- all of them, when they might differ. 5864--- 5865--- In the second form, with {dict} as the only argument, mode 5866--- and abbr are taken from the dict. 5867--- Example: >vim 5868--- let save_maps = maplist()->filter( 5869--- \ {_, m -> m.lhs == 'K'}) 5870--- nnoremap K somethingelse 5871--- cnoremap K somethingelse2 5872--- " ... 5873--- unmap K 5874--- for d in save_maps 5875--- call mapset(d) 5876--- endfor 5877--- < 5878--- 5879--- @overload fun(dict: table<string,any>): (any) 5880--- @param mode string 5881--- @param abbr? boolean 5882--- @param dict? table<string,any> 5883--- @return any 5884function vim . fn . mapset ( mode , abbr , dict ) end 5885 5886--- When {expr} is a |List| then this returns the index of the 5887--- first item where {pat} matches. Each item is used as a 5888--- String, |Lists| and |Dictionaries| are used as echoed. 5889--- 5890--- Otherwise, {expr} is used as a String. The result is a 5891--- Number, which gives the index (byte offset) in {expr} where 5892--- {pat} matches. 5893--- 5894--- A match at the first character or |List| item returns zero. 5895--- If there is no match -1 is returned. 5896--- 5897--- For getting submatches see |matchlist()|. 5898--- Example: >vim 5899--- echo match("testing", "ing") " results in 4 5900--- echo match([1, 'x'], '\a') " results in 1 5901--- <See |string-match| for how {pat} is used. 5902--- *strpbrk()* 5903--- Vim doesn't have a strpbrk() function. But you can do: >vim 5904--- let sepidx = match(line, '[.,;: \t]') 5905--- < *strcasestr()* 5906--- Vim doesn't have a strcasestr() function. But you can add 5907--- "\c" to the pattern to ignore case: >vim 5908--- let idx = match(haystack, '\cneedle') 5909--- < 5910--- If {start} is given, the search starts from byte index 5911--- {start} in a String or item {start} in a |List|. 5912--- The result, however, is still the index counted from the 5913--- first character/item. Example: >vim 5914--- echo match("testing", "ing", 2) 5915--- <result is again "4". >vim 5916--- echo match("testing", "ing", 4) 5917--- <result is again "4". >vim 5918--- echo match("testing", "t", 2) 5919--- <result is "3". 5920--- For a String, if {start} > 0 then it is like the string starts 5921--- {start} bytes later, thus "^" will match at {start}. Except 5922--- when {count} is given, then it's like matches before the 5923--- {start} byte are ignored (this is a bit complicated to keep it 5924--- backwards compatible). 5925--- For a String, if {start} < 0, it will be set to 0. For a list 5926--- the index is counted from the end. 5927--- If {start} is out of range ({start} > strlen({expr}) for a 5928--- String or {start} > len({expr}) for a |List|) -1 is returned. 5929--- 5930--- When {count} is given use the {count}th match. When a match 5931--- is found in a String the search for the next one starts one 5932--- character further. Thus this example results in 1: >vim 5933--- echo match("testing", "..", 0, 2) 5934--- <In a |List| the search continues in the next item. 5935--- Note that when {count} is added the way {start} works changes, 5936--- see above. 5937--- 5938--- *match-pattern* 5939--- See |pattern| for the patterns that are accepted. 5940--- The 'ignorecase' option is used to set the ignore-caseness of 5941--- the pattern. 'smartcase' is NOT used. The matching is always 5942--- done like 'magic' is set and 'cpoptions' is empty. 5943--- Note that a match at the start is preferred, thus when the 5944--- pattern is using "*" (any number of matches) it tends to find 5945--- zero matches at the start instead of a number of matches 5946--- further down in the text. 5947--- 5948--- @param expr string|any[] 5949--- @param pat string 5950--- @param start? integer 5951--- @param count? integer 5952--- @return integer 5953function vim . fn . match ( expr , pat , start , count ) end 5954 5955--- Defines a pattern to be highlighted in the current window (a 5956--- "match"). It will be highlighted with {group}. Returns an 5957--- identification number (ID), which can be used to delete the 5958--- match using |matchdelete()|. The ID is bound to the window. 5959--- Matching is case sensitive and magic, unless case sensitivity 5960--- or magicness are explicitly overridden in {pattern}. The 5961--- 'magic', 'smartcase' and 'ignorecase' options are not used. 5962--- The "Conceal" value is special, it causes the match to be 5963--- concealed. 5964--- 5965--- The optional {priority} argument assigns a priority to the 5966--- match. A match with a high priority will have its 5967--- highlighting overrule that of a match with a lower priority. 5968--- A priority is specified as an integer (negative numbers are no 5969--- exception). If the {priority} argument is not specified, the 5970--- default priority is 10. The priority of 'hlsearch' is zero, 5971--- hence all matches with a priority greater than zero will 5972--- overrule it. Syntax highlighting (see 'syntax') is a separate 5973--- mechanism, and regardless of the chosen priority a match will 5974--- always overrule syntax highlighting. 5975--- 5976--- The optional {id} argument allows the request for a specific 5977--- match ID. If a specified ID is already taken, an error 5978--- message will appear and the match will not be added. An ID 5979--- is specified as a positive integer (zero excluded). IDs 1, 2 5980--- and 3 are reserved for |:match|, |:2match| and |:3match|, 5981--- respectively. 3 is reserved for use by the |matchparen| 5982--- plugin. 5983--- If the {id} argument is not specified or -1, |matchadd()| 5984--- automatically chooses a free ID, which is at least 1000. 5985--- 5986--- The optional {dict} argument allows for further custom 5987--- values. Currently this is used to specify a match specific 5988--- conceal character that will be shown for |hl-Conceal| 5989--- highlighted matches. The dict can have the following members: 5990--- 5991--- conceal Special character to show instead of the 5992--- match (only for |hl-Conceal| highlighted 5993--- matches, see |:syn-cchar|) 5994--- window Use this |window-number| or |window-ID| instead 5995--- of the current window. 5996--- 5997--- The number of matches is not limited, as it is the case with 5998--- the |:match| commands. 5999--- 6000--- Returns -1 on error. 6001--- 6002--- Example: >vim 6003--- highlight MyGroup ctermbg=green guibg=green 6004--- let m = matchadd("MyGroup", "TODO") 6005--- <Deletion of the pattern: >vim 6006--- call matchdelete(m) 6007--- 6008--- <A list of matches defined by |matchadd()| and |:match| are 6009--- available from |getmatches()|. All matches can be deleted in 6010--- one operation by |clearmatches()|. 6011--- 6012--- @param group integer|string 6013--- @param pattern string 6014--- @param priority? integer 6015--- @param id? integer 6016--- @param dict? table 6017--- @return integer 6018function vim . fn . matchadd ( group , pattern , priority , id , dict ) end 6019 6020--- Same as |matchadd()|, but requires a list of positions {pos} 6021--- instead of a pattern. This command is faster than |matchadd()| 6022--- because it does not handle regular expressions and it sets 6023--- buffer line boundaries to redraw screen. It is supposed to be 6024--- used when fast match additions and deletions are required, for 6025--- example to highlight matching parentheses. 6026--- *E5030* *E5031* 6027--- {pos} is a list of positions. Each position can be one of 6028--- these: 6029--- - A number. This whole line will be highlighted. The first 6030--- line has number 1. 6031--- - A list with one number, e.g., [23]. The whole line with 6032--- this number will be highlighted. 6033--- - A list with two numbers, e.g., [23, 11]. The first number 6034--- is the line number, the second one is the column number 6035--- (first column is 1, the value must correspond to the byte 6036--- index as |col()| would return). The character at this 6037--- position will be highlighted. 6038--- - A list with three numbers, e.g., [23, 11, 3]. As above, but 6039--- the third number gives the length of the highlight in bytes. 6040--- 6041--- Entries with zero and negative line numbers are silently 6042--- ignored, as well as entries with negative column numbers and 6043--- lengths. 6044--- 6045--- Returns -1 on error. 6046--- 6047--- Example: >vim 6048--- highlight MyGroup ctermbg=green guibg=green 6049--- let m = matchaddpos("MyGroup", [[23, 24], 34]) 6050--- <Deletion of the pattern: >vim 6051--- call matchdelete(m) 6052--- 6053--- <Matches added by |matchaddpos()| are returned by 6054--- |getmatches()|. 6055--- 6056--- @param group integer|string 6057--- @param pos any[] 6058--- @param priority? integer 6059--- @param id? integer 6060--- @param dict? table 6061--- @return integer|table 6062function vim . fn . matchaddpos ( group , pos , priority , id , dict ) end 6063 6064--- Selects the {nr} match item, as set with a |:match|, 6065--- |:2match| or |:3match| command. 6066--- Return a |List| with two elements: 6067--- The name of the highlight group used 6068--- The pattern used. 6069--- When {nr} is not 1, 2 or 3 returns an empty |List|. 6070--- When there is no match item set returns ['', '']. 6071--- This is useful to save and restore a |:match|. 6072--- Highlighting matches using the |:match| commands are limited 6073--- to three matches. |matchadd()| does not have this limitation. 6074--- 6075--- @param nr integer 6076--- @return string[] 6077function vim . fn . matcharg ( nr ) end 6078 6079--- Returns the |List| of matches in lines from {lnum} to {end} in 6080--- buffer {buf} where {pat} matches. 6081--- 6082--- {lnum} and {end} can either be a line number or the string "$" 6083--- to refer to the last line in {buf}. 6084--- 6085--- The {dict} argument supports following items: 6086--- submatches include submatch information (|/\(|) 6087--- 6088--- For each match, a |Dict| with the following items is returned: 6089--- byteidx starting byte index of the match 6090--- lnum line number where there is a match 6091--- text matched string 6092--- Note that there can be multiple matches in a single line. 6093--- 6094--- This function works only for loaded buffers. First call 6095--- |bufload()| if needed. 6096--- 6097--- See |match-pattern| for information about the effect of some 6098--- option settings on the pattern. 6099--- 6100--- When {buf} is not a valid buffer, the buffer is not loaded or 6101--- {lnum} or {end} is not valid then an error is given and an 6102--- empty |List| is returned. 6103--- 6104--- Examples: >vim 6105--- " Assuming line 3 in buffer 5 contains "a" 6106--- echo matchbufline(5, '\<\k\+\>', 3, 3) 6107--- < `[{'lnum': 3, 'byteidx': 0, 'text': 'a'}]` >vim 6108--- " Assuming line 4 in buffer 10 contains "tik tok" 6109--- echo matchbufline(10, '\<\k\+\>', 1, 4) 6110--- < `[{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]` 6111--- 6112--- If {submatch} is present and is v:true, then submatches like 6113--- "\1", "\2", etc. are also returned. Example: >vim 6114--- " Assuming line 2 in buffer 2 contains "acd" 6115--- echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2 6116--- \ {'submatches': v:true}) 6117--- < `[{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]` 6118--- The "submatches" List always contains 9 items. If a submatch 6119--- is not found, then an empty string is returned for that 6120--- submatch. 6121--- 6122--- @param buf string|integer 6123--- @param pat string 6124--- @param lnum string|integer 6125--- @param end_ string|integer 6126--- @param dict? table 6127--- @return string[] 6128function vim . fn . matchbufline ( buf , pat , lnum , end_ , dict ) end 6129 6130--- Deletes a match with ID {id} previously defined by |matchadd()| 6131--- or one of the |:match| commands. Returns 0 if successful, 6132--- otherwise -1. See example for |matchadd()|. All matches can 6133--- be deleted in one operation by |clearmatches()|. 6134--- {win} (if given) is a |window-number| or |window-ID|. 6135--- 6136--- @param id integer 6137--- @param win? integer 6138--- @return any 6139function vim . fn . matchdelete ( id , win ) end 6140 6141--- Same as |match()|, but return the index of first character 6142--- after the match. Example: >vim 6143--- echo matchend("testing", "ing") 6144--- <results in "7". 6145--- *strspn()* *strcspn()* 6146--- Vim doesn't have a strspn() or strcspn() function, but you can 6147--- do it with matchend(): >vim 6148--- let span = matchend(line, '[a-zA-Z]') 6149--- let span = matchend(line, '[^a-zA-Z]') 6150--- <Except that -1 is returned when there are no matches. 6151--- 6152--- The {start}, if given, has the same meaning as for |match()|. >vim 6153--- echo matchend("testing", "ing", 2) 6154--- <results in "7". >vim 6155--- echo matchend("testing", "ing", 5) 6156--- <result is "-1". 6157--- When {expr} is a |List| the result is equal to |match()|. 6158--- 6159--- @param expr any 6160--- @param pat string 6161--- @param start? integer 6162--- @param count? integer 6163--- @return integer 6164function vim . fn . matchend ( expr , pat , start , count ) end 6165 6166--- If {list} is a list of strings, then returns a |List| with all 6167--- the strings in {list} that fuzzy match {str}. The strings in 6168--- the returned list are sorted based on the matching score. 6169--- 6170--- The optional {dict} argument always supports the following 6171--- items: 6172--- matchseq When this item is present return only matches 6173--- that contain the characters in {str} in the 6174--- given sequence. 6175--- limit Maximum number of matches in {list} to be 6176--- returned. Zero means no limit. 6177--- 6178--- If {list} is a list of dictionaries, then the optional {dict} 6179--- argument supports the following additional items: 6180--- key Key of the item which is fuzzy matched against 6181--- {str}. The value of this item should be a 6182--- string. 6183--- text_cb |Funcref| that will be called for every item 6184--- in {list} to get the text for fuzzy matching. 6185--- This should accept a dictionary item as the 6186--- argument and return the text for that item to 6187--- use for fuzzy matching. 6188--- 6189--- {str} is treated as a literal string and regular expression 6190--- matching is NOT supported. Only the first 1024 characters of 6191--- {str} and of each item in {list} are used for matching; 6192--- characters beyond that are ignored. 6193--- 6194--- When {str} has multiple words each separated by white space, 6195--- then the list of strings that have all the words is returned. 6196--- 6197--- If there are no matching strings or there is an error, then an 6198--- empty list is returned. 6199--- 6200--- When {limit} is given, matchfuzzy() will find up to this 6201--- number of matches in {list} and return them in sorted order. 6202--- 6203--- Refer to |fuzzy-matching| for more information about fuzzy 6204--- matching strings. 6205--- 6206--- Example: >vim 6207--- echo matchfuzzy(["clay", "crow"], "cay") 6208--- <results in ["clay"]. >vim 6209--- echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") 6210--- <results in a list of buffer names fuzzy matching "ndl". >vim 6211--- echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'}) 6212--- <results in a list of buffer information dicts with buffer 6213--- names fuzzy matching "ndl". >vim 6214--- echo getbufinfo()->matchfuzzy("spl", 6215--- \ {'text_cb' : {v -> v.name}}) 6216--- <results in a list of buffer information dicts with buffer 6217--- names fuzzy matching "spl". >vim 6218--- echo v:oldfiles->matchfuzzy("test") 6219--- <results in a list of file names fuzzy matching "test". >vim 6220--- let l = readfile("buffer.c")->matchfuzzy("str") 6221--- <results in a list of lines in "buffer.c" fuzzy matching "str". >vim 6222--- echo ['one two', 'two one']->matchfuzzy('two one') 6223--- <results in `['two one', 'one two']` . >vim 6224--- echo ['one two', 'two one']->matchfuzzy('two one', 6225--- \ {'matchseq': 1}) 6226--- <results in `['two one']`. 6227--- 6228--- @param list any[] 6229--- @param str string 6230--- @param dict? table 6231--- @return table 6232function vim . fn . matchfuzzy ( list , str , dict ) end 6233 6234--- Same as |matchfuzzy()|, but returns the list of matched 6235--- strings, the list of character positions where characters 6236--- in {str} matches and a list of matching scores. You can 6237--- use |byteidx()| to convert a character position to a byte 6238--- position. 6239--- 6240--- If {str} matches multiple times in a string, then only the 6241--- positions for the best match is returned. 6242--- 6243--- If there are no matching strings or there is an error, then a 6244--- list with three empty list items is returned. 6245--- 6246--- Example: >vim 6247--- echo matchfuzzypos(['testing'], 'tsg') 6248--- <results in [["testing"], [[0, 2, 6]], [99]] >vim 6249--- echo matchfuzzypos(['clay', 'lacy'], 'la') 6250--- <results in [["lacy", "clay"], [[0, 1], [1, 2]], [153, 133]] >vim 6251--- echo [{'text': 'hello', 'id' : 10}] 6252--- \ ->matchfuzzypos('ll', {'key' : 'text'}) 6253--- <results in `[[{"id": 10, "text": "hello"}], [[2, 3]], [127]]` 6254--- 6255--- @param list any[] 6256--- @param str string 6257--- @param dict? table 6258--- @return table 6259function vim . fn . matchfuzzypos ( list , str , dict ) end 6260 6261--- Same as |match()|, but return a |List|. The first item in the 6262--- list is the matched string, same as what |matchstr()| would 6263--- return. Following items are submatches, like "\1", "\2", etc. 6264--- in |:substitute|. When an optional submatch didn't match an 6265--- empty string is used. Example: >vim 6266--- echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)') 6267--- <Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] 6268--- When there is no match an empty list is returned. 6269--- 6270--- You can pass in a List, but that is not very useful. 6271--- 6272--- @param expr any 6273--- @param pat string 6274--- @param start? integer 6275--- @param count? integer 6276--- @return string[] 6277function vim . fn . matchlist ( expr , pat , start , count ) end 6278 6279--- Same as |match()|, but return the matched string. Example: >vim 6280--- echo matchstr("testing", "ing") 6281--- <results in "ing". 6282--- When there is no match "" is returned. 6283--- The {start}, if given, has the same meaning as for |match()|. >vim 6284--- echo matchstr("testing", "ing", 2) 6285--- <results in "ing". >vim 6286--- echo matchstr("testing", "ing", 5) 6287--- <result is "". 6288--- When {expr} is a |List| then the matching item is returned. 6289--- The type isn't changed, it's not necessarily a String. 6290--- 6291--- @param expr any 6292--- @param pat string 6293--- @param start? integer 6294--- @param count? integer 6295--- @return string 6296function vim . fn . matchstr ( expr , pat , start , count ) end 6297 6298--- Returns the |List| of matches in {list} where {pat} matches. 6299--- {list} is a |List| of strings. {pat} is matched against each 6300--- string in {list}. 6301--- 6302--- The {dict} argument supports following items: 6303--- submatches include submatch information (|/\(|) 6304--- 6305--- For each match, a |Dict| with the following items is returned: 6306--- byteidx starting byte index of the match. 6307--- idx index in {list} of the match. 6308--- text matched string 6309--- submatches a List of submatches. Present only if 6310--- "submatches" is set to v:true in {dict}. 6311--- 6312--- See |match-pattern| for information about the effect of some 6313--- option settings on the pattern. 6314--- 6315--- Example: >vim 6316--- echo matchstrlist(['tik tok'], '\<\k\+\>') 6317--- < `[{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]` >vim 6318--- echo matchstrlist(['a', 'b'], '\<\k\+\>') 6319--- < `[{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]` 6320--- 6321--- If "submatches" is present and is v:true, then submatches like 6322--- "\1", "\2", etc. are also returned. Example: >vim 6323--- echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 6324--- \ #{submatches: v:true}) 6325--- < `[{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]` 6326--- The "submatches" List always contains 9 items. If a submatch 6327--- is not found, then an empty string is returned for that 6328--- submatch. 6329--- 6330--- @param list string[] 6331--- @param pat string 6332--- @param dict? table 6333--- @return string[] 6334function vim . fn . matchstrlist ( list , pat , dict ) end 6335 6336--- Same as |matchstr()|, but return the matched string, the start 6337--- position and the end position of the match. Example: >vim 6338--- echo matchstrpos("testing", "ing") 6339--- <results in ["ing", 4, 7]. 6340--- When there is no match ["", -1, -1] is returned. 6341--- The {start}, if given, has the same meaning as for |match()|. >vim 6342--- echo matchstrpos("testing", "ing", 2) 6343--- <results in ["ing", 4, 7]. >vim 6344--- echo matchstrpos("testing", "ing", 5) 6345--- <result is ["", -1, -1]. 6346--- When {expr} is a |List| then the matching item, the index 6347--- of first item where {pat} matches, the start position and the 6348--- end position of the match are returned. >vim 6349--- echo matchstrpos([1, '__x'], '\a') 6350--- <result is ["x", 1, 2, 3]. 6351--- The type isn't changed, it's not necessarily a String. 6352--- 6353--- @param expr any 6354--- @param pat string 6355--- @param start? integer 6356--- @param count? integer 6357--- @return table 6358function vim . fn . matchstrpos ( expr , pat , start , count ) end 6359 6360--- Lua: Prefer |math.max()| with `unpack(expr)` for lists; dict values and empty inputs need custom handling. 6361--- 6362--- Return the maximum value of all items in {expr}. Example: >vim 6363--- echo max([apples, pears, oranges]) 6364--- 6365--- <{expr} can be a |List| or a |Dictionary|. For a Dictionary, 6366--- it returns the maximum of all values in the Dictionary. 6367--- If {expr} is neither a List nor a Dictionary, or one of the 6368--- items in {expr} cannot be used as a Number this results in 6369--- an error. An empty |List| or |Dictionary| results in zero. 6370--- 6371--- @param expr any 6372--- @return number 6373function vim . fn . max ( expr ) end 6374 6375--- Returns a |List| of |Dictionaries| describing |menus| (defined 6376--- by |:menu|, |:amenu|, …), including |hidden-menus|. 6377--- 6378--- {path} matches a menu by name, or all menus if {path} is an 6379--- empty string. Example: >vim 6380--- echo menu_get('File','') 6381--- echo menu_get('') 6382--- < 6383--- {modes} is a string of zero or more modes (see |maparg()| or 6384--- |creating-menus| for the list of modes). "a" means "all". 6385--- 6386--- Example: >vim 6387--- nnoremenu &Test.Test inormal 6388--- inoremenu Test.Test insert 6389--- vnoremenu Test.Test x 6390--- echo menu_get("") 6391--- 6392--- <returns something like this: > 6393--- 6394--- [ { 6395--- "hidden": 0, 6396--- "name": "Test", 6397--- "priority": 500, 6398--- "shortcut": 84, 6399--- "submenus": [ { 6400--- "hidden": 0, 6401--- "mappings": { 6402--- i": { 6403--- "enabled": 1, 6404--- "noremap": 1, 6405--- "rhs": "insert", 6406--- "sid": 1, 6407--- "silent": 0 6408--- }, 6409--- n": { ... }, 6410--- s": { ... }, 6411--- v": { ... } 6412--- }, 6413--- "name": "Test", 6414--- "priority": 500, 6415--- "shortcut": 0 6416--- } ] 6417--- } ] 6418--- < 6419--- 6420--- @param path string 6421--- @param modes? string 6422--- @return any 6423function vim . fn . menu_get ( path , modes ) end 6424 6425--- Return information about the specified menu {name} in 6426--- mode {mode}. The menu name should be specified without the 6427--- shortcut character ('&'). If {name} is "", then the top-level 6428--- menu names are returned. 6429--- 6430--- {mode} can be one of these strings: 6431--- "n" Normal 6432--- "v" Visual (including Select) 6433--- "o" Operator-pending 6434--- "i" Insert 6435--- "c" Cmd-line 6436--- "s" Select 6437--- "x" Visual 6438--- "t" Terminal-Job 6439--- "" Normal, Visual and Operator-pending 6440--- "!" Insert and Cmd-line 6441--- When {mode} is omitted, the modes for "" are used. 6442--- 6443--- Returns a |Dictionary| containing the following items: 6444--- accel menu item accelerator text |menu-text| 6445--- display display name (name without '&') 6446--- enabled v:true if this menu item is enabled 6447--- Refer to |:menu-enable| 6448--- icon name of the icon file (for toolbar) 6449--- |toolbar-icon| 6450--- iconidx index of a built-in icon 6451--- modes modes for which the menu is defined. In 6452--- addition to the modes mentioned above, these 6453--- characters will be used: 6454--- " " Normal, Visual and Operator-pending 6455--- name menu item name. 6456--- noremenu v:true if the {rhs} of the menu item is not 6457--- remappable else v:false. 6458--- priority menu order priority |menu-priority| 6459--- rhs right-hand-side of the menu item. The 6460--- returned string has special characters 6461--- translated like in the output of the ":menu" 6462--- command listing. When the {rhs} of a menu 6463--- item is empty, then "<Nop>" is returned. 6464--- script v:true if script-local remapping of {rhs} is 6465--- allowed else v:false. See |:menu-script|. 6466--- shortcut shortcut key (character after '&' in 6467--- the menu name) |menu-shortcut| 6468--- silent v:true if the menu item is created 6469--- with <silent> argument |:menu-silent| 6470--- submenus |List| containing the names of 6471--- all the submenus. Present only if the menu 6472--- item has submenus. 6473--- 6474--- Returns an empty dictionary if the menu item is not found. 6475--- 6476--- Examples: >vim 6477--- echo menu_info('Edit.Cut') 6478--- echo menu_info('File.Save', 'n') 6479--- 6480--- " Display the entire menu hierarchy in a buffer 6481--- func ShowMenu(name, pfx) 6482--- let m = menu_info(a:name) 6483--- call append(line('$'), a:pfx .. m.display) 6484--- for child in m->get('submenus', []) 6485--- call ShowMenu(a:name .. '.' .. escape(child, '.'), 6486--- \ a:pfx .. ' ') 6487--- endfor 6488--- endfunc 6489--- new 6490--- for topmenu in menu_info('').submenus 6491--- call ShowMenu(topmenu, '') 6492--- endfor 6493--- < 6494--- 6495--- @param name string 6496--- @param mode? string 6497--- @return any 6498function vim . fn . menu_info ( name , mode ) end 6499 6500--- Lua: Prefer |math.min()| with `unpack(expr)` for lists; dict values and empty inputs need custom handling. 6501--- 6502--- Return the minimum value of all items in {expr}. Example: >vim 6503--- echo min([apples, pears, oranges]) 6504--- 6505--- <{expr} can be a |List| or a |Dictionary|. For a Dictionary, 6506--- it returns the minimum of all values in the Dictionary. 6507--- If {expr} is neither a List nor a Dictionary, or one of the 6508--- items in {expr} cannot be used as a Number this results in 6509--- an error. An empty |List| or |Dictionary| results in zero. 6510--- 6511--- @param expr any 6512--- @return number 6513function vim . fn . min ( expr ) end 6514 6515--- Lua: Prefer |vim.fs.mkdir()|; `"D"`, `"R"`, and return semantics differ. 6516--- 6517--- Create directory {name}. 6518--- 6519--- When {flags} is present it must be a string. An empty string 6520--- has no effect. 6521--- 6522--- {flags} can contain these character flags: 6523--- "p" intermediate directories will be created as necessary 6524--- "D" {name} will be deleted at the end of the current 6525--- function, but not recursively |:defer| 6526--- "R" {name} will be deleted recursively at the end of the 6527--- current function |:defer| 6528--- 6529--- Note that when {name} has more than one part and "p" is used 6530--- some directories may already exist. Only the first one that 6531--- is created and what it contains is scheduled to be deleted. 6532--- E.g. when using: >vim 6533--- call mkdir('subdir/tmp/autoload', 'pR') 6534--- <and "subdir" already exists then "subdir/tmp" will be 6535--- scheduled for deletion, like with: >vim 6536--- defer delete('subdir/tmp', 'rf') 6537--- < 6538--- If {prot} is given it is used to set the protection bits of 6539--- the new directory. The default is 0o755 (rwxr-xr-x: r/w for 6540--- the user, readable for others). Use 0o700 to make it 6541--- unreadable for others. This is used for the newly created 6542--- directories. Note: umask is applied to {prot} (on Unix). 6543--- Example: >vim 6544--- call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700) 6545--- 6546--- <This function is not available in the |sandbox|. 6547--- 6548--- If you try to create an existing directory with {flags} set to 6549--- "p" mkdir() will silently exit. 6550--- 6551--- The function result is a Number, which is TRUE if the call was 6552--- successful or FALSE if the directory creation failed or partly 6553--- failed. 6554--- 6555--- @param name string 6556--- @param flags? string 6557--- @param prot? string 6558--- @return integer 6559function vim . fn . mkdir ( name , flags , prot ) end 6560 6561--- Lua: Prefer |nvim_get_mode()|; use the `.mode` field. It always returns the full mode string, unlike |mode()| without a non-zero {expr}. 6562--- 6563--- Return a string that indicates the current mode. 6564--- If {expr} is supplied and it evaluates to a non-zero Number or 6565--- a non-empty String (|non-zero-arg|), then the full mode is 6566--- returned, otherwise only the first letter is returned. 6567--- Also see |state()|. 6568--- 6569--- n Normal 6570--- no Operator-pending 6571--- nov Operator-pending (forced charwise |o_v|) 6572--- noV Operator-pending (forced linewise |o_V|) 6573--- noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|) 6574--- CTRL-V is one character 6575--- niI Normal using |i_CTRL-O| in |Insert-mode| 6576--- niR Normal using |i_CTRL-O| in |Replace-mode| 6577--- niV Normal using |i_CTRL-O| in |Virtual-Replace-mode| 6578--- nt Normal in |terminal-emulator| (insert goes to 6579--- Terminal mode) 6580--- ntT Normal using |t_CTRL-\_CTRL-O| in |Terminal-mode| 6581--- v Visual by character 6582--- vs Visual by character using |v_CTRL-O| in Select mode 6583--- V Visual by line 6584--- Vs Visual by line using |v_CTRL-O| in Select mode 6585--- CTRL-V Visual blockwise 6586--- CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode 6587--- s Select by character 6588--- S Select by line 6589--- CTRL-S Select blockwise 6590--- i Insert 6591--- ic Insert mode completion |compl-generic| 6592--- ix Insert mode |i_CTRL-X| completion 6593--- R Replace |R| 6594--- Rc Replace mode completion |compl-generic| 6595--- Rx Replace mode |i_CTRL-X| completion 6596--- Rv Virtual Replace |gR| 6597--- Rvc Virtual Replace mode completion |compl-generic| 6598--- Rvx Virtual Replace mode |i_CTRL-X| completion 6599--- c Command-line editing 6600--- cr Command-line editing overstrike mode |c_<Insert>| 6601--- cv Non-interactive Ex mode |-es| 6602--- r Hit-enter prompt 6603--- rm The -- more -- prompt 6604--- r? A |:confirm| query of some sort 6605--- ! Shell or external command is executing 6606--- t Terminal mode: keys go to the job 6607--- 6608--- This is useful in the 'statusline' option or RPC calls. In 6609--- most other places it always returns "c" or "n". 6610--- Note that in the future more modes and more specific modes may 6611--- be added. It's better not to compare the whole string but 6612--- only the leading character(s). 6613--- Also see |visualmode()|. 6614--- 6615--- @param expr? any 6616--- @return any 6617function vim . fn . mode ( expr ) end 6618 6619--- Lua: Prefer |vim.mpack.encode()|; list wrapping, return shape, and special-dict semantics differ. 6620--- 6621--- Convert a list of Vimscript objects to msgpack. Returned value is a 6622--- |readfile()|-style list. When {type} contains "B", a |Blob| is 6623--- returned instead. Example: >vim 6624--- call writefile(msgpackdump([{}]), 'fname.mpack', 'b') 6625--- <or, using a |Blob|: >vim 6626--- call writefile(msgpackdump([{}], 'B'), 'fname.mpack') 6627--- < 6628--- This will write the single 0x80 byte to a `fname.mpack` file 6629--- (dictionary with zero items is represented by 0x80 byte in 6630--- messagepack). 6631--- 6632--- Limitations: *E5004* *E5005* 6633--- 1. |Funcref|s cannot be dumped. 6634--- 2. Containers that reference themselves cannot be dumped. 6635--- 3. Dictionary keys are always dumped as STR strings. 6636--- 4. Other strings and |Blob|s are always dumped as BIN strings. 6637--- 5. Points 3. and 4. do not apply to |msgpack-special-dict|s. 6638--- 6639--- @param list any 6640--- @param type? any 6641--- @return any 6642function vim . fn . msgpackdump ( list , type ) end 6643 6644--- Lua: Prefer |vim.mpack.decode()|; input and special-dict semantics differ. 6645--- 6646--- Convert a |readfile()|-style list or a |Blob| to a list of 6647--- Vimscript objects. 6648--- Example: >vim 6649--- let fname = expand('~/.config/nvim/shada/main.shada') 6650--- let mpack = readfile(fname, 'b') 6651--- let shada_objects = msgpackparse(mpack) 6652--- <This will read ~/.config/nvim/shada/main.shada file to 6653--- `shada_objects` list. 6654--- 6655--- Limitations: 6656--- 1. Mapping ordering is not preserved unless messagepack 6657--- mapping is dumped using generic mapping 6658--- (|msgpack-special-map|). 6659--- 2. Since the parser aims to preserve all data untouched 6660--- (except for 1.) some strings are parsed to 6661--- |msgpack-special-dict| format which is not convenient to 6662--- use. 6663--- *msgpack-special-dict* 6664--- Some messagepack strings may be parsed to special 6665--- dictionaries. Special dictionaries are dictionaries which 6666--- 6667--- 1. Contain exactly two keys: `_TYPE` and `_VAL`. 6668--- 2. `_TYPE` key is one of the types found in |v:msgpack_types| 6669--- variable. 6670--- 3. Value for `_VAL` has the following format (Key column 6671--- contains name of the key from |v:msgpack_types|): 6672--- 6673--- Key Value ~ 6674--- nil Zero, ignored when dumping. Not returned by 6675--- |msgpackparse()| since |v:null| was introduced. 6676--- boolean One or zero. When dumping it is only checked that 6677--- value is a |Number|. Not returned by |msgpackparse()| 6678--- since |v:true| and |v:false| were introduced. 6679--- integer |List| with four numbers: sign (-1 or 1), highest two 6680--- bits, number with bits from 62nd to 31st, lowest 31 6681--- bits. I.e. to get actual number one will need to use 6682--- code like > 6683--- _VAL[0] * ((_VAL[1] << 62) 6684--- & (_VAL[2] << 31) 6685--- & _VAL[3]) 6686--- < Special dictionary with this type will appear in 6687--- |msgpackparse()| output under one of the following 6688--- circumstances: 6689--- 1. |Number| is 32-bit and value is either above 6690--- INT32_MAX or below INT32_MIN. 6691--- 2. |Number| is 64-bit and value is above INT64_MAX. It 6692--- cannot possibly be below INT64_MIN because msgpack 6693--- C parser does not support such values. 6694--- float |Float|. This value cannot possibly appear in 6695--- |msgpackparse()| output. 6696--- string |String|, or |Blob| if binary string contains zero 6697--- byte. This value cannot appear in |msgpackparse()| 6698--- output since blobs were introduced. 6699--- array |List|. This value cannot appear in |msgpackparse()| 6700--- output. 6701--- *msgpack-special-map* 6702--- map |List| of |List|s with two items (key and value) each. 6703--- This value will appear in |msgpackparse()| output if 6704--- parsed mapping contains one of the following keys: 6705--- 1. Any key that is not a string (including keys which 6706--- are binary strings). 6707--- 2. String with NUL byte inside. 6708--- 3. Duplicate key. 6709--- ext |List| with two values: first is a signed integer 6710--- representing extension type. Second is 6711--- |readfile()|-style list of strings. 6712--- 6713--- @param data any 6714--- @return any 6715function vim . fn . msgpackparse ( data ) end 6716 6717--- Return the line number of the first line at or below {lnum} 6718--- that is not blank. Example: >vim 6719--- if getline(nextnonblank(1)) =~ "Java" | endif 6720--- <When {lnum} is invalid or there is no non-blank line at or 6721--- below it, zero is returned. 6722--- {lnum} is used like with |getline()|. 6723--- See also |prevnonblank()|. 6724--- 6725--- @param lnum integer|string 6726--- @return integer 6727function vim . fn . nextnonblank ( lnum ) end 6728 6729--- Lua: Prefer |string.char()|: only works with ASCII. 6730--- 6731--- Gets a UTF-8 string for a single codepoint {expr}. 6732--- Examples: >vim 6733--- echo nr2char(64) " returns '\@' 6734--- echo nr2char(32) " returns ' ' 6735--- echo nr2char(300) " returns I with bow character 6736--- < 6737--- UTF-8 encoding is always used, {utf8} option has no effect, 6738--- and exists only for backwards-compatibility. 6739--- Note that a NUL character in the file is specified with 6740--- nr2char(10), because NULs are represented with newline 6741--- characters. nr2char(0) is a real NUL and terminates the 6742--- string, thus results in an empty string. 6743--- 6744--- @param expr integer 6745--- @param utf8? boolean 6746--- @return string 6747function vim . fn . nr2char ( expr , utf8 ) end 6748 6749--- Lua: Prefer |bit.bor()|. 6750--- 6751--- Bitwise OR on the two arguments. The arguments are converted 6752--- to a number. A List, Dict or Float argument causes an error. 6753--- Also see `and()` and `xor()`. 6754--- Example: >vim 6755--- let bits = or(bits, 0x80) 6756--- 6757--- <Rationale: The reason this is a function and not using the "|" 6758--- character like many languages, is that Vi has always used "|" 6759--- to separate commands. In many places it would not be clear if 6760--- "|" is an operator or a command separator. 6761--- 6762--- @param expr number 6763--- @param expr1 number 6764--- @return any 6765vim . fn [ 'or' ] =function ( expr , expr1 ) end 6766 6767--- Shorten directory names in the path {path} and return the 6768--- result. The tail, the file name, is kept as-is. The other 6769--- components in the path are reduced to {len} letters in length. 6770--- If {len} is omitted or smaller than 1 then 1 is used (single 6771--- letters). Leading '~' and '.' characters are kept. Examples: >vim 6772--- echo pathshorten('~/.config/nvim/autoload/file1.vim') 6773--- < ~/.c/n/a/file1.vim ~ 6774--- >vim 6775--- echo pathshorten('~/.config/nvim/autoload/file2.vim', 2) 6776--- < ~/.co/nv/au/file2.vim ~ 6777--- It doesn't matter if the path exists or not. 6778--- Returns an empty string on error. 6779--- 6780--- @param path string 6781--- @param len? integer 6782--- @return string 6783function vim . fn . pathshorten ( path , len ) end 6784 6785--- Evaluate |perl| expression {expr} and return its result 6786--- converted to Vim data structures. 6787--- Numbers and strings are returned as they are (strings are 6788--- copied though). 6789--- Lists are represented as Vim |List| type. 6790--- Dictionaries are represented as Vim |Dictionary| type, 6791--- non-string keys result in error. 6792--- 6793--- Note: If you want an array or hash, {expr} must return a 6794--- reference to it. 6795--- Example: >vim 6796--- echo perleval('[1 .. 4]') 6797--- < [1, 2, 3, 4] 6798--- 6799--- @param expr any 6800--- @return any 6801function vim . fn . perleval ( expr ) end 6802 6803--- Lua: Prefer |math.pow()|. 6804--- 6805--- Return the power of {x} to the exponent {y} as a |Float|. 6806--- {x} and {y} must evaluate to a |Float| or a |Number|. 6807--- Returns 0.0 if {x} or {y} is not a |Float| or a |Number|. 6808--- Examples: >vim 6809--- echo pow(3, 3) 6810--- < 27.0 >vim 6811--- echo pow(2, 16) 6812--- < 65536.0 >vim 6813--- echo pow(32, 0.20) 6814--- < 2.0 6815--- 6816--- @param x number 6817--- @param y number 6818--- @return number 6819function vim . fn . pow ( x , y ) end 6820 6821--- Returns non-zero if text has been inserted after the cursor 6822--- because "preinsert" is present in 'completeopt', or because 6823--- "longest" is present in 'completeopt' while 'autocomplete' 6824--- is active. Otherwise returns zero. 6825--- 6826--- @return number 6827function vim . fn . preinserted () end 6828 6829--- Return the line number of the first line at or above {lnum} 6830--- that is not blank. Example: >vim 6831--- let ind = indent(prevnonblank(v:lnum - 1)) 6832--- <When {lnum} is invalid or there is no non-blank line at or 6833--- above it, zero is returned. 6834--- {lnum} is used like with |getline()|. 6835--- Also see |nextnonblank()|. 6836--- 6837--- @param lnum integer|string 6838--- @return integer 6839function vim . fn . prevnonblank ( lnum ) end 6840 6841--- Lua: Prefer |string.format()|. 6842--- 6843--- Return a String with {fmt}, where "%" items are replaced by 6844--- the formatted form of their respective arguments. Example: >vim 6845--- echo printf("%4d: E%d %.30s", lnum, errno, msg) 6846--- <May result in: 6847--- " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ 6848--- 6849--- When used as a |method| the base is passed as the second 6850--- argument: >vim 6851--- Compute()->printf("result: %d") 6852--- < 6853--- You can use `call()` to pass the items as a list. 6854--- 6855--- Often used items are: 6856--- %s string 6857--- %6S string right-aligned in 6 display cells 6858--- %6s string right-aligned in 6 bytes 6859--- %.9s string truncated to 9 bytes 6860--- %c single byte 6861--- %d decimal number 6862--- %5d decimal number padded with spaces to 5 characters 6863--- %b binary number 6864--- %08b binary number padded with zeros to at least 8 characters 6865--- %B binary number using upper case letters 6866--- %x hex number 6867--- %04x hex number padded with zeros to at least 4 characters 6868--- %X hex number using upper case letters 6869--- %o octal number 6870--- %f floating point number as 12.23, inf, -inf or nan 6871--- %F floating point number as 12.23, INF, -INF or NAN 6872--- %e floating point number as 1.23e3, inf, -inf or nan 6873--- %E floating point number as 1.23E3, INF, -INF or NAN 6874--- %g floating point number, as %f or %e depending on value 6875--- %G floating point number, as %F or %E depending on value 6876--- %% the % character itself 6877--- %p representation of the pointer to the container 6878--- 6879--- Conversion specifications start with '%' and end with the 6880--- conversion type. All other characters are copied unchanged to 6881--- the result. 6882--- 6883--- The "%" starts a conversion specification. The following 6884--- arguments appear in sequence: 6885--- 6886--- % [pos-argument] [flags] [field-width] [.precision] type 6887--- 6888--- pos-argument 6889--- At most one positional argument specifier. These take 6890--- the form {n$}, where n is >= 1. 6891--- 6892--- flags 6893--- Zero or more of the following flags: 6894--- 6895--- # The value should be converted to an "alternate 6896--- form". For c, d, and s conversions, this option 6897--- has no effect. For o conversions, the precision 6898--- of the number is increased to force the first 6899--- character of the output string to a zero (except 6900--- if a zero value is printed with an explicit 6901--- precision of zero). 6902--- For x and X conversions, a non-zero result has 6903--- the string "0x" (or "0X" for X conversions) 6904--- prepended to it. 6905--- 6906--- 0 (zero) Zero padding. For all conversions the converted 6907--- value is padded on the left with zeros rather 6908--- than blanks. If a precision is given with a 6909--- numeric conversion (d, o, x, and X), the 0 flag 6910--- is ignored. 6911--- 6912--- - A negative field width flag; the converted value 6913--- is to be left adjusted on the field boundary. 6914--- The converted value is padded on the right with 6915--- blanks, rather than on the left with blanks or 6916--- zeros. A - overrides a 0 if both are given. 6917--- 6918--- ' ' (space) A blank should be left before a positive 6919--- number produced by a signed conversion (d). 6920--- 6921--- + A sign must always be placed before a number 6922--- produced by a signed conversion. A + overrides 6923--- a space if both are used. 6924--- 6925--- field-width 6926--- An optional decimal digit string specifying a minimum 6927--- field width. If the converted value has fewer bytes 6928--- than the field width, it will be padded with spaces on 6929--- the left (or right, if the left-adjustment flag has 6930--- been given) to fill out the field width. For the S 6931--- conversion the count is in cells. 6932--- 6933--- .precision 6934--- An optional precision, in the form of a period '.' 6935--- followed by an optional digit string. If the digit 6936--- string is omitted, the precision is taken as zero. 6937--- This gives the minimum number of digits to appear for 6938--- d, o, x, and X conversions, the maximum number of 6939--- bytes to be printed from a string for s conversions, 6940--- or the maximum number of cells to be printed from a 6941--- string for S conversions. 6942--- For floating point it is the number of digits after 6943--- the decimal point. 6944--- 6945--- type 6946--- A character that specifies the type of conversion to 6947--- be applied, see below. 6948--- 6949--- A field width or precision, or both, may be indicated by an 6950--- asterisk "*" instead of a digit string. In this case, a 6951--- Number argument supplies the field width or precision. A 6952--- negative field width is treated as a left adjustment flag 6953--- followed by a positive field width; a negative precision is 6954--- treated as though it were missing. Example: >vim 6955--- echo printf("%d: %.*s", nr, width, line) 6956--- <This limits the length of the text used from "line" to 6957--- "width" bytes. 6958--- 6959--- If the argument to be formatted is specified using a 6960--- positional argument specifier, and a '*' is used to indicate 6961--- that a number argument is to be used to specify the width or 6962--- precision, the argument(s) to be used must also be specified 6963--- using a {n$} positional argument specifier. See |printf-$|. 6964--- 6965--- The conversion specifiers and their meanings are: 6966--- 6967--- *printf-d* *printf-b* *printf-B* *printf-o* *printf-x* *printf-X* 6968--- dbBoxX The Number argument is converted to signed decimal (d), 6969--- unsigned binary (b and B), unsigned octal (o), or 6970--- unsigned hexadecimal (x and X) notation. The letters 6971--- "abcdef" are used for x conversions; the letters 6972--- "ABCDEF" are used for X conversions. The precision, if 6973--- any, gives the minimum number of digits that must 6974--- appear; if the converted value requires fewer digits, it 6975--- is padded on the left with zeros. In no case does a 6976--- non-existent or small field width cause truncation of a 6977--- numeric field; if the result of a conversion is wider 6978--- than the field width, the field is expanded to contain 6979--- the conversion result. 6980--- The 'h' modifier indicates the argument is 16 bits. 6981--- The 'l' modifier indicates the argument is a long 6982--- integer. The size will be 32 bits or 64 bits 6983--- depending on your platform. 6984--- The "ll" modifier indicates the argument is 64 bits. 6985--- The b and B conversion specifiers never take a width 6986--- modifier and always assume their argument is a 64 bit 6987--- integer. 6988--- Generally, these modifiers are not useful. They are 6989--- ignored when type is known from the argument. 6990--- 6991--- i alias for d 6992--- D alias for ld 6993--- U alias for lu 6994--- O alias for lo 6995--- 6996--- *printf-c* 6997--- c The Number argument is converted to a byte, and the 6998--- resulting character is written. 6999--- 7000--- *printf-s* 7001--- s The text of the String argument is used. If a 7002--- precision is specified, no more bytes than the number 7003--- specified are used. 7004--- If the argument is not a String type, it is 7005--- automatically converted to text with the same format 7006--- as ":echo". 7007--- *printf-S* 7008--- S The text of the String argument is used. If a 7009--- precision is specified, no more display cells than the 7010--- number specified are used. 7011--- 7012--- *printf-f* *E807* 7013--- f F The Float argument is converted into a string of the 7014--- form 123.456. The precision specifies the number of 7015--- digits after the decimal point. When the precision is 7016--- zero the decimal point is omitted. When the precision 7017--- is not specified 6 is used. A really big number 7018--- (out of range or dividing by zero) results in "inf" 7019--- or "-inf" with %f (INF or -INF with %F). 7020--- "0.0 / 0.0" results in "nan" with %f (NAN with %F). 7021--- Example: >vim 7022--- echo printf("%.2f", 12.115) 7023--- < 12.12 7024--- Note that roundoff depends on the system libraries. 7025--- Use |round()| when in doubt. 7026--- 7027--- *printf-e* *printf-E* 7028--- e E The Float argument is converted into a string of the 7029--- form 1.234e+03 or 1.234E+03 when using 'E'. The 7030--- precision specifies the number of digits after the 7031--- decimal point, like with 'f'. 7032--- 7033--- *printf-g* *printf-G* 7034--- g G The Float argument is converted like with 'f' if the 7035--- value is between 0.001 (inclusive) and 10000000.0 7036--- (exclusive). Otherwise 'e' is used for 'g' and 'E' 7037--- for 'G'. When no precision is specified superfluous 7038--- zeroes and '+' signs are removed, except for the zero 7039--- immediately after the decimal point. Thus 10000000.0 7040--- results in 1.0e7. 7041--- 7042--- *printf-%* 7043--- % A '%' is written. No argument is converted. The 7044--- complete conversion specification is "%%". 7045--- 7046--- When a Number argument is expected a String argument is also 7047--- accepted and automatically converted. 7048--- When a Float or String argument is expected a Number argument 7049--- is also accepted and automatically converted. 7050--- Any other argument type results in an error message. 7051--- 7052--- *E766* *E767* 7053--- The number of {exprN} arguments must exactly match the number 7054--- of "%" items. If there are not sufficient or too many 7055--- arguments an error is given. Up to 18 arguments can be used. 7056--- 7057--- *printf-$* 7058--- In certain languages, error and informative messages are 7059--- more readable when the order of words is different from the 7060--- corresponding message in English. To accommodate translations 7061--- having a different word order, positional arguments may be 7062--- used to indicate this. For instance: >vim 7063--- 7064--- #, c-format 7065--- msgid "%s returning %s" 7066--- msgstr "waarde %2$s komt terug van %1$s" 7067--- < 7068--- In this example, the sentence has its 2 string arguments 7069--- reversed in the output. >vim 7070--- 7071--- echo printf( 7072--- "In The Netherlands, vim's creator's name is: %1$s %2$s", 7073--- "Bram", "Moolenaar") 7074--- < In The Netherlands, vim's creator's name is: Bram Moolenaar >vim 7075--- 7076--- echo printf( 7077--- "In Belgium, vim's creator's name is: %2$s %1$s", 7078--- "Bram", "Moolenaar") 7079--- < In Belgium, vim's creator's name is: Moolenaar Bram 7080--- 7081--- Width (and precision) can be specified using the '*' 7082--- specifier. In this case, you must specify the field width 7083--- position in the argument list. >vim 7084--- 7085--- echo printf("%1$*2$.*3$d", 1, 2, 3) 7086--- < 001 >vim 7087--- echo printf("%2$*3$.*1$d", 1, 2, 3) 7088--- < 2 >vim 7089--- echo printf("%3$*1$.*2$d", 1, 2, 3) 7090--- < 03 >vim 7091--- echo printf("%1$*2$.*3$g", 1.4142, 2, 3) 7092--- < 1.414 7093--- 7094--- You can mix specifying the width and/or precision directly 7095--- and via positional arguments: >vim 7096--- 7097--- echo printf("%1$4.*2$f", 1.4142135, 6) 7098--- < 1.414214 >vim 7099--- echo printf("%1$*2$.4f", 1.4142135, 6) 7100--- < 1.4142 >vim 7101--- echo printf("%1$*2$.*3$f", 1.4142135, 6, 2) 7102--- < 1.41 7103--- 7104--- You will get an overflow error |E1510|, when the field-width 7105--- or precision will result in a string longer than 1 MiB 7106--- (1024*1024 = 1048576) chars. 7107--- 7108--- *E1500* 7109--- You cannot mix positional and non-positional arguments: >vim 7110--- echo printf("%s%1$s", "One", "Two") 7111--- " E1500: Cannot mix positional and non-positional arguments: 7112--- " %s%1$s 7113--- < 7114--- *E1501* 7115--- You cannot skip a positional argument in a format string: >vim 7116--- echo printf("%3$s%1$s", "One", "Two", "Three") 7117--- " E1501: format argument 2 unused in $-style format: 7118--- " %3$s%1$s 7119--- < 7120--- *E1502* 7121--- You can re-use a [field-width] (or [precision]) argument: >vim 7122--- echo printf("%1$d at width %2$d is: %1$0*2$d", 1, 2) 7123--- " 1 at width 2 is: 01 7124--- < 7125--- However, you can't use it as a different type: >vim 7126--- echo printf("%1$d at width %2$ld is: %1$0*2$d", 1, 2) 7127--- " E1502: Positional argument 2 used as field width reused as 7128--- " different type: long int/int 7129--- < 7130--- *E1503* 7131--- When a positional argument is used, but not the correct number 7132--- or arguments is given, an error is raised: >vim 7133--- echo printf("%1$d at width %2$d is: %1$0*2$.*3$d", 1, 2) 7134--- " E1503: Positional argument 3 out of bounds: %1$d at width 7135--- " %2$d is: %1$0*2$.*3$d 7136--- < 7137--- Only the first error is reported: >vim 7138--- echo printf("%1$0*2$.*3$d %4$d", 1, 2) 7139--- " E1503: Positional argument 3 out of bounds: %1$0*2$.*3$d 7140--- " %4$d 7141--- < 7142--- *E1504* 7143--- A positional argument can be used more than once: >vim 7144--- echo printf("%1$s %2$s %1$s", "One", "Two") 7145--- " One Two One 7146--- < 7147--- However, you can't use a different type the second time: >vim 7148--- echo printf("%1$s %2$s %1$d", "One", "Two") 7149--- " E1504: Positional argument 1 type used inconsistently: 7150--- " int/string 7151--- < 7152--- *E1505* 7153--- Various other errors that lead to a format string being 7154--- wrongly formatted lead to: >vim 7155--- echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2) 7156--- " E1505: Invalid format specifier: %1$d at width %2$d is: 7157--- " %01$*2$.3$d 7158--- < 7159--- *E1507* 7160--- This internal error indicates that the logic to parse a 7161--- positional format argument ran into a problem that couldn't be 7162--- otherwise reported. Please file a bug against Vim if you run 7163--- into this, copying the exact format string and parameters that 7164--- were used. 7165--- 7166--- @param fmt string 7167--- @param expr1? any 7168--- @return string 7169function vim . fn . printf ( fmt , expr1 ) end 7170 7171--- Appends text to prompt buffer before current prompt. When {text} is 7172--- a |List|: Append each item of the |List| as a text line above 7173--- prompt-line in the buffer. Any type of item is accepted and converted 7174--- to a String. Returns 1 for failure ({buf} not a prmopt buffer), 7175--- 0 for success. When {text} is an empty list zero is returned. 7176--- 7177--- Example: >vim 7178--- func TextEntered(text) 7179--- call prompt_appendbuf(bufnr(''), split('Entered: "' . a:text . '"', '\n')) 7180--- endfunc 7181--- 7182--- set buftype=prompt 7183--- call prompt_setcallback(bufnr(''), function("TextEntered")) 7184--- eval bufnr("")->prompt_setprompt("cmd: ") 7185--- startinsert 7186--- < 7187--- 7188--- @param buf integer|string 7189--- @param text string|string[] 7190--- @return 0|1 7191function vim . fn . prompt_appendbuf ( buf , text ) end 7192 7193--- Gets the current user-input in |prompt-buffer| {buf} without invoking 7194--- prompt_callback. {buf} can be a buffer name or number. 7195--- 7196--- If the buffer doesn't exist or isn't a prompt buffer, an empty 7197--- string is returned. 7198--- 7199--- @param buf integer|string 7200--- @return any 7201function vim . fn . prompt_getinput ( buf ) end 7202 7203--- Returns the effective prompt text for buffer {buf}. {buf} can 7204--- be a buffer name or number. See |prompt-buffer|. 7205--- 7206--- If the buffer doesn't exist or isn't a prompt buffer, an empty 7207--- string is returned. 7208--- 7209--- @param buf integer|string 7210--- @return any 7211function vim . fn . prompt_getprompt ( buf ) end 7212 7213--- Set prompt callback for buffer {buf} to {expr}. When {expr} 7214--- is an empty string the callback is removed. This has only 7215--- effect if {buf} has 'buftype' set to "prompt". 7216--- 7217--- The callback is invoked when pressing Enter. The current 7218--- buffer will always be the prompt buffer. A new line for a 7219--- prompt is added before invoking the callback, thus the prompt 7220--- for which the callback was invoked will be in the last but one 7221--- line. 7222--- If the callback wants to add text to the buffer, it must 7223--- insert it above the last line, since that is where the current 7224--- prompt is. This can also be done asynchronously. 7225--- The callback is invoked with one argument, which is the text 7226--- that was entered at the prompt. This can be an empty string 7227--- if the user only typed Enter. 7228--- Example: >vim 7229--- func s:TextEntered(text) 7230--- if a:text == 'exit' || a:text == 'quit' 7231--- stopinsert 7232--- " Reset 'modified' to allow the buffer to be closed. 7233--- " We assume there is nothing useful to be saved. 7234--- set nomodified 7235--- close 7236--- else 7237--- " Do something useful with "a:text". In this example 7238--- " we just repeat it. 7239--- call append(line('$') - 1, 'Entered: "' .. a:text .. '"') 7240--- endif 7241--- endfunc 7242--- call prompt_setcallback(bufnr(), function('s:TextEntered')) 7243--- < 7244--- 7245--- @param buf integer|string 7246--- @param expr string|function 7247--- @return any 7248function vim . fn . prompt_setcallback ( buf , expr ) end 7249 7250--- Set a callback for buffer {buf} to {expr}. When {expr} is an 7251--- empty string the callback is removed. This has only effect if 7252--- {buf} has 'buftype' set to "prompt". 7253--- 7254--- This callback will be invoked when pressing CTRL-C in Insert 7255--- mode. Without setting a callback Vim will exit Insert mode, 7256--- as in any buffer. 7257--- 7258--- @param buf integer|string 7259--- @param expr string|function 7260--- @return any 7261function vim . fn . prompt_setinterrupt ( buf , expr ) end 7262 7263--- Set prompt for buffer {buf} to {text}. You most likely want 7264--- {text} to end in a space. 7265--- The result is only visible if {buf} has 'buftype' set to 7266--- "prompt". Example: >vim 7267--- call prompt_setprompt(bufnr(''), 'command: ') 7268--- < 7269--- 7270--- @param buf integer|string 7271--- @param text string 7272--- @return any 7273function vim . fn . prompt_setprompt ( buf , text ) end 7274 7275--- If the popup menu (see |ins-completion-menu|) is not visible, 7276--- returns an empty |Dictionary|, otherwise, returns a 7277--- |Dictionary| with the following keys: 7278--- height nr of items visible 7279--- width screen cells 7280--- row top screen row (0 first row) 7281--- col leftmost screen column (0 first col) 7282--- size total nr of items 7283--- scrollbar |TRUE| if scrollbar is visible 7284--- 7285--- The values are the same as in |v:event| during |CompleteChanged|. 7286--- 7287--- @return any 7288function vim . fn . pum_getpos () end 7289 7290--- Returns non-zero when the popup menu is visible, zero 7291--- otherwise. See |ins-completion-menu|. 7292--- This can be used to avoid some things that would remove the 7293--- popup menu. 7294--- 7295--- @return any 7296function vim . fn . pumvisible () end 7297 7298--- Evaluate Python expression {expr} and return its result 7299--- converted to Vim data structures. 7300--- Numbers and strings are returned as they are (strings are 7301--- copied though, Unicode strings are additionally converted to 7302--- UTF-8). 7303--- Lists are represented as Vim |List| type. 7304--- Dictionaries are represented as Vim |Dictionary| type with 7305--- keys converted to strings. 7306--- 7307--- @param expr any 7308--- @return any 7309function vim . fn . py3eval ( expr ) end 7310 7311--- Evaluate Python expression {expr} and return its result 7312--- converted to Vim data structures. 7313--- Numbers and strings are returned as they are (strings are 7314--- copied though). 7315--- Lists are represented as Vim |List| type. 7316--- Dictionaries are represented as Vim |Dictionary| type, 7317--- non-string keys result in error. 7318--- 7319--- @param expr any 7320--- @return any 7321function vim . fn . pyeval ( expr ) end 7322 7323--- Evaluate Python expression {expr} and return its result 7324--- converted to Vim data structures. 7325--- Uses Python 2 or 3, see |python_x| and 'pyxversion'. 7326--- See also: |pyeval()|, |py3eval()| 7327--- 7328--- @param expr any 7329--- @return any 7330function vim . fn . pyxeval ( expr ) end 7331 7332--- Lua: Prefer |math.random()|. 7333--- 7334--- Return a pseudo-random Number generated with an xoshiro128** 7335--- algorithm using seed {expr}. The returned number is 32 bits, 7336--- also on 64 bits systems, for consistency. 7337--- {expr} can be initialized by |srand()| and will be updated by 7338--- rand(). If {expr} is omitted, an internal seed value is used 7339--- and updated. 7340--- Returns -1 if {expr} is invalid. 7341--- 7342--- Examples: >vim 7343--- echo rand() 7344--- let seed = srand() 7345--- echo rand(seed) 7346--- echo rand(seed) % 16 " random number 0 - 15 7347--- < 7348--- 7349--- @param expr? number 7350--- @return any 7351function vim . fn . rand ( expr ) end 7352 7353--- Returns a |List| with Numbers: 7354--- - If only {expr} is specified: [0, 1, ..., {expr} - 1] 7355--- - If {max} is specified: [{expr}, {expr} + 1, ..., {max}] 7356--- - If {stride} is specified: [{expr}, {expr} + {stride}, ..., 7357--- {max}] (increasing {expr} with {stride} each time, not 7358--- producing a value past {max}). 7359--- When the maximum is one before the start the result is an 7360--- empty list. When the maximum is more than one before the 7361--- start this is an error. 7362--- Examples: >vim 7363--- echo range(4) " [0, 1, 2, 3] 7364--- echo range(2, 4) " [2, 3, 4] 7365--- echo range(2, 9, 3) " [2, 5, 8] 7366--- echo range(2, -2, -1) " [2, 1, 0, -1, -2] 7367--- echo range(0) " [] 7368--- echo range(2, 0) " error! 7369--- < 7370--- 7371--- @param expr any 7372--- @param max? integer 7373--- @param stride? integer 7374--- @return any 7375function vim . fn . range ( expr , max , stride ) end 7376 7377--- Lua: Prefer |io.open()| with `:read("*a")` in binary mode for whole-file reads; offset, size, and Blob return differ. 7378--- 7379--- Read file {fname} in binary mode and return a |Blob|. 7380--- If {offset} is specified, read the file from the specified 7381--- offset. If it is a negative value, it is used as an offset 7382--- from the end of the file. E.g., to read the last 12 bytes: >vim 7383--- echo readblob('file.bin', -12) 7384--- <If {size} is specified, only the specified size will be read. 7385--- E.g. to read the first 100 bytes of a file: >vim 7386--- echo readblob('file.bin', 0, 100) 7387--- <If {size} is -1 or omitted, the whole data starting from 7388--- {offset} will be read. 7389--- This can be also used to read the data from a character device 7390--- on Unix when {size} is explicitly set. Only if the device 7391--- supports seeking {offset} can be used. Otherwise it should be 7392--- zero. E.g. to read 10 bytes from a serial console: >vim 7393--- echo readblob('/dev/ttyS0', 0, 10) 7394--- <When the file can't be opened an error message is given and 7395--- the result is an empty |Blob|. 7396--- When the offset is beyond the end of the file the result is an 7397--- empty blob. 7398--- When trying to read more bytes than are available the result 7399--- is truncated. 7400--- Also see |readfile()| and |writefile()|. 7401--- 7402--- @param fname string 7403--- @param offset? integer 7404--- @param size? integer 7405--- @return any 7406function vim . fn . readblob ( fname , offset , size ) end 7407 7408--- Lua: Prefer |vim.fs.dir()| as an iterator, then collect and filter results as needed. 7409--- 7410--- Return a list with file and directory names in {directory}. 7411--- You can also use |glob()| if you don't need to do complicated 7412--- things, such as limiting the number of matches. 7413--- 7414--- When {expr} is omitted all entries are included. 7415--- When {expr} is given, it is evaluated to check what to do: 7416--- If {expr} results in -1 then no further entries will 7417--- be handled. 7418--- If {expr} results in 0 then this entry will not be 7419--- added to the list. 7420--- If {expr} results in 1 then this entry will be added 7421--- to the list. 7422--- Each time {expr} is evaluated |v:val| is set to the entry name. 7423--- When {expr} is a function the name is passed as the argument. 7424--- For example, to get a list of files ending in ".txt": >vim 7425--- echo readdir(dirname, {n -> n =~ '\.txt$'}) 7426--- <To skip hidden and backup files: >vim 7427--- echo readdir(dirname, {n -> n !~ '^\.\|\~$'}) 7428--- 7429--- <If you want to get a directory tree: >vim 7430--- function! s:tree(dir) 7431--- return {a:dir : map(readdir(a:dir), 7432--- \ {_, x -> isdirectory(x) ? 7433--- \ {x : s:tree(a:dir .. '/' .. x)} : x})} 7434--- endfunction 7435--- echo s:tree(".") 7436--- < 7437--- Returns an empty List on error. 7438--- 7439--- @param directory string 7440--- @param expr? integer|string|fun(name: string): integer 7441--- @return any 7442function vim . fn . readdir ( directory , expr ) end 7443 7444--- Lua: Prefer |io.open()| with `:read("*a")`, then split lines as needed; `{type}`, `{max}`, and Blob return differ. 7445--- 7446--- Read file {fname} and return a |List|, each line of the file 7447--- as an item. Lines are broken at NL characters. Macintosh 7448--- files separated with CR will result in a single long line 7449--- (unless a NL appears somewhere). 7450--- All NUL characters are replaced with a NL character. 7451--- When {type} contains "b" binary mode is used: 7452--- - When the last line ends in a NL an extra empty list item is 7453--- added. 7454--- - No CR characters are removed. 7455--- Otherwise: 7456--- - CR characters that appear before a NL are removed. 7457--- - Whether the last line ends in a NL or not does not matter. 7458--- - Any UTF-8 byte order mark is removed from the text. 7459--- When {max} is given this specifies the maximum number of lines 7460--- to be read. Useful if you only want to check the first ten 7461--- lines of a file: >vim 7462--- for line in readfile(fname, '', 10) 7463--- if line =~ 'Date' | echo line | endif 7464--- endfor 7465--- <When {max} is negative -{max} lines from the end of the file 7466--- are returned, or as many as there are. 7467--- When {max} is zero the result is an empty list. 7468--- Note that without {max} the whole file is read into memory. 7469--- Also note that there is no recognition of encoding. Read a 7470--- file into a buffer if you need to. 7471--- Deprecated (use |readblob()| instead): When {type} contains 7472--- "B" a |Blob| is returned with the binary data of the file 7473--- unmodified. 7474--- When the file can't be opened an error message is given and 7475--- the result is an empty list. 7476--- Also see |writefile()|. 7477--- 7478--- @param fname string 7479--- @param type? string 7480--- @param max? integer 7481--- @return string[] 7482function vim . fn . readfile ( fname , type , max ) end 7483 7484--- Lua: Prefer |Iter:fold()|. 7485--- 7486--- {func} is called for every item in {object}, which can be a 7487--- |String|, |List| or a |Blob|. {func} is called with two 7488--- arguments: the result so far and current item. After 7489--- processing all items the result is returned. *E1132* 7490--- 7491--- {initial} is the initial result. When omitted, the first item 7492--- in {object} is used and {func} is first called for the second 7493--- item. If {initial} is not given and {object} is empty no 7494--- result can be computed, an E998 error is given. 7495--- 7496--- Examples: >vim 7497--- echo reduce([1, 3, 5], { acc, val -> acc + val }) 7498--- echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') 7499--- echo reduce(0z1122, { acc, val -> 2 * acc + val }) 7500--- echo reduce('xyz', { acc, val -> acc .. ',' .. val }) 7501--- < 7502--- 7503--- @generic T 7504--- @param object any 7505--- @param func fun(accumulator: T, current: any): any 7506--- @param initial? any 7507--- @return T 7508function vim . fn . reduce ( object , func , initial ) end 7509 7510--- Returns the single letter name of the register being executed. 7511--- Returns an empty string when no register is being executed. 7512--- See |\@|. 7513--- 7514--- @return any 7515function vim . fn . reg_executing () end 7516 7517--- Returns the single letter name of the last recorded register. 7518--- Returns an empty string when nothing was recorded yet. 7519--- See |q| and |Q|. 7520--- 7521--- @return any 7522function vim . fn . reg_recorded () end 7523 7524--- Returns the single letter name of the register being recorded. 7525--- Returns an empty string when not recording. See |q|. 7526--- 7527--- @return any 7528function vim . fn . reg_recording () end 7529 7530--- Lua: Prefer |uv.hrtime()|. 7531--- 7532--- Return an item that represents a time value. The item is a 7533--- list with items that depend on the system. 7534--- The item can be passed to |reltimestr()| to convert it to a 7535--- string or |reltimefloat()| to convert to a Float. 7536--- 7537--- Without an argument it returns the current "relative time", an 7538--- implementation-defined value meaningful only when used as an 7539--- argument to |reltime()|, |reltimestr()| and |reltimefloat()|. 7540--- 7541--- With one argument it returns the time passed since the time 7542--- specified in the argument. 7543--- With two arguments it returns the time passed between {start} 7544--- and {end}. 7545--- 7546--- The {start} and {end} arguments must be values returned by 7547--- reltime(). Returns zero on error. 7548--- 7549--- Note: |localtime()| returns the current (non-relative) time. 7550--- 7551--- @overload fun(start?: any): (any) 7552--- @overload fun(start?: any, end_?: any): (any) 7553--- @return any 7554function vim . fn . reltime () end 7555 7556--- Lua: Prefer |uv.hrtime()| with `(finish - start) / 1e9` for elapsed seconds. 7557--- 7558--- Return a Float that represents the time value of {time}. 7559--- Unit of time is seconds. 7560--- Example: 7561--- let start = reltime() 7562--- call MyFunction() 7563--- let seconds = reltimefloat(reltime(start)) 7564--- See the note of |reltimestr()| about overhead. 7565--- Also see |profiling|. 7566--- If there is an error an empty string is returned 7567--- 7568--- @param time any 7569--- @return any 7570function vim . fn . reltimefloat ( time ) end 7571 7572--- Return a String that represents the time value of {time}. 7573--- This is the number of seconds, a dot and the number of 7574--- microseconds. Example: >vim 7575--- let start = reltime() 7576--- call MyFunction() 7577--- echo reltimestr(reltime(start)) 7578--- <Note that overhead for the commands will be added to the time. 7579--- Leading spaces are used to make the string align nicely. You 7580--- can use |split()| to remove it. >vim 7581--- echo split(reltimestr(reltime(start)))[0] 7582--- <Also see |profiling|. 7583--- If there is an error an empty string is returned 7584--- 7585--- @param time any 7586--- @return any 7587function vim . fn . reltimestr ( time ) end 7588 7589--- Lua: Prefer |table.remove()|. 7590--- 7591--- Without {end}: Remove the item at {idx} from |List| {list} and 7592--- return the item. 7593--- With {end}: Remove items from {idx} to {end} (inclusive) and 7594--- return a |List| with these items. When {idx} points to the same 7595--- item as {end} a list with one item is returned. When {end} 7596--- points to an item before {idx} this is an error. 7597--- See |list-index| for possible values of {idx} and {end}. 7598--- Returns zero on error. 7599--- Example: >vim 7600--- echo "last item: " .. remove(mylist, -1) 7601--- call remove(mylist, 0, 9) 7602--- < 7603--- Use |delete()| to remove a file. 7604--- 7605--- Without {end}: Remove the byte at {idx} from |Blob| {blob} and 7606--- return the byte. 7607--- With {end}: Remove bytes from {idx} to {end} (inclusive) and 7608--- return a |Blob| with these bytes. When {idx} points to the same 7609--- byte as {end} a |Blob| with one byte is returned. When {end} 7610--- points to a byte before {idx} this is an error. 7611--- Returns zero on error. 7612--- Example: >vim 7613--- echo "last byte: " .. remove(myblob, -1) 7614--- call remove(mylist, 0, 9) 7615--- < 7616--- 7617--- Lua: Prefer `local value = dict[key]; dict[key] = nil` for dicts; missing-key behavior differs. 7618--- 7619--- Remove the entry from {dict} with key {key} and return it. 7620--- Example: >vim 7621--- echo "removed " .. remove(dict, "one") 7622--- <If there is no {key} in {dict} this is an error. 7623--- Returns zero on error. 7624--- 7625--- @overload fun(list: any[], idx: integer, end_?: integer): (any) 7626--- @overload fun(blob: any, idx: integer): (any) 7627--- @overload fun(blob: any, idx: integer, end_?: integer): (any) 7628--- @overload fun(dict: any, key: string): (any) 7629--- @param list any 7630--- @param idx integer 7631--- @return any 7632function vim . fn . remove ( list , idx ) end 7633 7634--- Lua: Prefer |uv.fs_rename()| or |os.rename()|. 7635--- 7636--- Rename the file by the name {from} to the name {to}. This 7637--- should also work to move files across file systems. The 7638--- result is a Number, which is 0 if the file was renamed 7639--- successfully, and non-zero when the renaming failed. 7640--- NOTE: If {to} exists it is overwritten without warning. 7641--- This function is not available in the |sandbox|. 7642--- 7643--- @param from string 7644--- @param to string 7645--- @return integer 7646function vim . fn . rename ( from , to ) end 7647 7648--- Lua: Prefer |string.rep()| for strings; lists need manual repetition. 7649--- 7650--- Repeat {expr} {count} times and return the concatenated 7651--- result. Example: >vim 7652--- let separator = repeat('-', 80) 7653--- <When {count} is zero or negative the result is empty. 7654--- When {expr} is a |List| or a |Blob| the result is {expr} 7655--- concatenated {count} times. Example: >vim 7656--- let longlist = repeat(['a', 'b'], 3) 7657--- <Results in ['a', 'b', 'a', 'b', 'a', 'b']. 7658--- 7659--- @param expr any 7660--- @param count integer 7661--- @return any 7662vim . fn [ 'repeat' ] =function ( expr , count ) end 7663 7664--- On MS-Windows, when {filename} is a shortcut (a .lnk file), 7665--- returns the path the shortcut points to in a simplified form. 7666--- On Unix, repeat resolving symbolic links in all path 7667--- components of {filename} and return the simplified result. 7668--- To cope with link cycles, resolving of symbolic links is 7669--- stopped after 100 iterations. 7670--- On other systems, return the simplified {filename}. 7671--- The simplification step is done as by |simplify()|. 7672--- resolve() keeps a leading path component specifying the 7673--- current directory (provided the result is still a relative 7674--- path name) and also keeps a trailing path separator. 7675--- 7676--- @param filename string 7677--- @return string 7678function vim . fn . resolve ( filename ) end 7679 7680--- Lua: Prefer `vim.iter(list):rev():totable()` for lists; strings, blobs, and in-place behavior differ. 7681--- 7682--- Reverse the order of items in {object}. {object} can be a 7683--- |List|, a |Blob| or a |String|. For a List and a Blob the 7684--- items are reversed in-place and {object} is returned. 7685--- For a String a new String is returned. 7686--- Returns zero if {object} is not a List, Blob or a String. 7687--- If you want a List or Blob to remain unmodified make a copy 7688--- first: >vim 7689--- let revlist = reverse(copy(mylist)) 7690--- < 7691--- 7692--- @generic T 7693--- @param object T[] 7694--- @return T[] 7695function vim . fn . reverse ( object ) end 7696 7697--- Lua: Prefer `expr >= 0 and math.floor(expr + 0.5) or math.ceil(expr - 0.5)` for half-away-from-zero rounding. 7698--- 7699--- Round off {expr} to the nearest integral value and return it 7700--- as a |Float|. If {expr} lies halfway between two integral 7701--- values, then use the larger one (away from zero). 7702--- {expr} must evaluate to a |Float| or a |Number|. 7703--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 7704--- Examples: >vim 7705--- echo round(0.456) 7706--- < 0.0 >vim 7707--- echo round(4.5) 7708--- < 5.0 >vim 7709--- echo round(-4.5) 7710--- < -5.0 7711--- 7712--- @param expr number 7713--- @return number 7714function vim . fn . round ( expr ) end 7715 7716--- Lua: Prefer |vim.rpcnotify()|. 7717--- 7718--- Sends {event} to {channel} via |RPC| and returns immediately. 7719--- If {channel} is 0, the event is broadcast to all channels. 7720--- Example: >vim 7721--- au VimLeave call rpcnotify(0, "leaving") 7722--- < 7723--- 7724--- @param channel integer 7725--- @param event string 7726--- @param ... any 7727--- @return integer 7728function vim . fn . rpcnotify ( channel , event , ... ) end 7729 7730--- Lua: Prefer |vim.rpcrequest()|. 7731--- 7732--- Sends a request to {channel} to invoke {method} via 7733--- |RPC| and blocks until a response is received. 7734--- Example: >vim 7735--- let result = rpcrequest(rpc_chan, "func", 1, 2, 3) 7736--- < 7737--- 7738--- @param channel integer 7739--- @param method string 7740--- @param ... any 7741--- @return any 7742function vim . fn . rpcrequest ( channel , method , ... ) end 7743 7744--- @deprecated 7745--- Deprecated. Replace >vim 7746--- let id = rpcstart('prog', ['arg1', 'arg2']) 7747--- <with >vim 7748--- let id = jobstart(['prog', 'arg1', 'arg2'], {'rpc': v:true}) 7749--- < 7750--- 7751--- @param prog string 7752--- @param argv? any 7753--- @return any 7754function vim . fn . rpcstart ( prog , argv ) end 7755 7756--- @deprecated 7757--- Use |jobstop()| instead to stop any job, or 7758--- `chanclose(id, "rpc")` to close RPC communication 7759--- without stopping the job. Use chanclose(id) to close 7760--- any socket. 7761--- 7762--- @param ... any 7763--- @return any 7764function vim . fn . rpcstop ( ... ) end 7765 7766--- Evaluate Ruby expression {expr} and return its result 7767--- converted to Vim data structures. 7768--- Numbers, floats and strings are returned as they are (strings 7769--- are copied though). 7770--- Arrays are represented as Vim |List| type. 7771--- Hashes are represented as Vim |Dictionary| type. 7772--- Other objects are represented as strings resulted from their 7773--- "Object#to_s" method. 7774--- 7775--- @param expr any 7776--- @return any 7777function vim . fn . rubyeval ( expr ) end 7778 7779--- Like |screenchar()|, but return the attribute. This is a rather 7780--- arbitrary number that can only be used to compare to the 7781--- attribute at other positions. 7782--- Returns -1 when row or col is out of range. 7783--- 7784--- @param row integer 7785--- @param col integer 7786--- @return integer 7787function vim . fn . screenattr ( row , col ) end 7788 7789--- Returns the character at screen position [row, col] as a 7790--- Number. This works for every possible screen position, also 7791--- status lines, window separators and the command line. The 7792--- top left position is row one, column one. The character 7793--- excludes composing characters. For double-byte 7794--- encodings it may only be the first byte. 7795--- This is mainly to be used for testing. 7796--- Returns -1 when row or col is out of range. 7797--- 7798--- @param row integer 7799--- @param col integer 7800--- @return integer 7801function vim . fn . screenchar ( row , col ) end 7802 7803--- Returns the character and any composing characters at screen 7804--- position [row, col] as a |List| of Numbers. The first number 7805--- is the same as what |screenchar()| returns; further numbers 7806--- are composing characters on top of the base character. 7807--- This is mainly to be used for testing. 7808--- Returns an empty List when row or col is out of range. 7809--- 7810--- @param row integer 7811--- @param col integer 7812--- @return integer[] 7813function vim . fn . screenchars ( row , col ) end 7814 7815--- Returns the current screen column of the cursor. The 7816--- leftmost column has number 1. 7817--- This function is mainly used for testing. 7818--- 7819--- Note: Always returns the current screen column, thus if used 7820--- in a command (e.g. ":echo screencol()") it will return the 7821--- column inside the command line, which is 1 when the command is 7822--- executed. To get the cursor position in the file use one of 7823--- the following mappings: >vim 7824--- nnoremap <expr> GG ":echom " .. screencol() .. "\n" 7825--- nnoremap <silent> GG :echom screencol()<CR> 7826--- noremap GG <Cmd>echom screencol()<CR> 7827--- < 7828--- 7829--- @return integer 7830function vim . fn . screencol () end 7831 7832--- Returns the screen position of the text character in window 7833--- {winid} at buffer line {lnum} and column {col} as a Dict. 7834--- {col} is a one-based byte index. 7835--- The Dict has these members: 7836--- row screen row 7837--- col first screen column 7838--- endcol last screen column 7839--- curscol cursor screen column 7840--- If the specified position is not visible, all values are zero. 7841--- The "endcol" value differs from "col" when the character 7842--- occupies more than one screen cell. E.g. for a Tab "col" can 7843--- be 1 and "endcol" can be 8. 7844--- The "curscol" value is where the cursor would be placed. For 7845--- a Tab it would be the same as "endcol", while for a double 7846--- width character it would be the same as "col". 7847--- The |conceal| feature is ignored here, the column numbers are 7848--- as if 'conceallevel' is zero. You can set the cursor to the 7849--- right position and use |screencol()| to get the value with 7850--- |conceal| taken into account. 7851--- If the position is in a closed fold the screen position of the 7852--- first character is returned, {col} is not used. 7853--- Returns an empty Dict if {winid} is invalid. 7854--- 7855--- @param winid integer 7856--- @param lnum integer 7857--- @param col integer 7858--- @return { col: integer, curscol: integer, endcol: integer, row: integer } 7859function vim . fn . screenpos ( winid , lnum , col ) end 7860 7861--- Returns the current screen row of the cursor. The top line 7862--- has number one. 7863--- This function is mainly used for testing. 7864--- Alternatively you can use |winline()|. 7865--- 7866--- Note: Same restrictions as with |screencol()|. 7867--- 7868--- @return integer 7869function vim . fn . screenrow () end 7870 7871--- Returns the base character and any composing characters at 7872--- screen position [row, col] as a String. This is like 7873--- |screenchars()| but returning a String with the characters. 7874--- This is mainly to be used for testing. 7875--- Returns an empty String when row or col is out of range. 7876--- 7877--- @param row integer 7878--- @param col integer 7879--- @return string 7880function vim . fn . screenstring ( row , col ) end 7881 7882--- Search for regexp pattern {pattern}. The search starts at the 7883--- cursor position (you can use |cursor()| to set it). 7884--- 7885--- When a match has been found its line number is returned. 7886--- If there is no match a 0 is returned and the cursor doesn't 7887--- move. No error message is given. 7888--- To get the matched string, use |matchbufline()|. 7889--- 7890--- {flags} is a String, which can contain these character flags: 7891--- 'b' search Backward instead of forward 7892--- 'c' accept a match at the Cursor position 7893--- 'e' move to the End of the match 7894--- 'n' do Not move the cursor 7895--- 'p' return number of matching sub-Pattern (see below) 7896--- 's' Set the ' mark at the previous location of the cursor 7897--- 'w' Wrap around the end of the file 7898--- 'W' don't Wrap around the end of the file 7899--- 'z' start searching at the cursor column instead of Zero 7900--- If neither 'w' or 'W' is given, the 'wrapscan' option applies. 7901--- 7902--- If the 's' flag is supplied, the ' mark is set, only if the 7903--- cursor is moved. The 's' flag cannot be combined with the 'n' 7904--- flag. 7905--- 7906--- 'ignorecase', 'smartcase' and 'magic' are used. 7907--- 7908--- When the 'z' flag is not given, forward searching always 7909--- starts in column zero and then matches before the cursor are 7910--- skipped. When the 'c' flag is present in 'cpo' the next 7911--- search starts after the match. Without the 'c' flag the next 7912--- search starts one column after the start of the match. This 7913--- matters for overlapping matches. See |cpo-c|. You can also 7914--- insert "\ze" to change where the match ends, see |/\ze|. 7915--- 7916--- When searching backwards and the 'z' flag is given then the 7917--- search starts in column zero, thus no match in the current 7918--- line will be found (unless wrapping around the end of the 7919--- file). 7920--- 7921--- When the {stopline} argument is given then the search stops 7922--- after searching this line. This is useful to restrict the 7923--- search to a range of lines. Examples: >vim 7924--- let match = search('(', 'b', line("w0")) 7925--- let end = search('END', '', line("w$")) 7926--- <When {stopline} is used and it is not zero this also implies 7927--- that the search does not wrap around the end of the file. 7928--- A zero value is equal to not giving the argument. 7929--- 7930--- When the {timeout} argument is given the search stops when 7931--- more than this many milliseconds have passed. Thus when 7932--- {timeout} is 500 the search stops after half a second. 7933--- The value must not be negative. A zero value is like not 7934--- giving the argument. 7935--- 7936--- Note: the timeout is only considered when searching, not 7937--- while evaluating the {skip} expression. 7938--- 7939--- If the {skip} expression is given it is evaluated with the 7940--- cursor positioned on the start of a match. If it evaluates to 7941--- non-zero this match is skipped. This can be used, for 7942--- example, to skip a match in a comment or a string. 7943--- {skip} can be a string, which is evaluated as an expression, a 7944--- function reference or a lambda. 7945--- When {skip} is omitted or empty, every match is accepted. 7946--- When evaluating {skip} causes an error the search is aborted 7947--- and -1 returned. 7948--- *search()-sub-match* 7949--- With the 'p' flag the returned value is one more than the 7950--- first sub-match in \(\). One if none of them matched but the 7951--- whole pattern did match. 7952--- To get the column number too use |searchpos()|. 7953--- 7954--- The cursor will be positioned at the match, unless the 'n' 7955--- flag is used. 7956--- 7957--- Example (goes over all files in the argument list): >vim 7958--- let n = 1 7959--- while n <= argc() " loop over all files in arglist 7960--- exe "argument " .. n 7961--- " start at the last char in the file and wrap for the 7962--- " first search to find match at start of file 7963--- normal G$ 7964--- let flags = "w" 7965--- while search("foo", flags) > 0 7966--- s/foo/bar/g 7967--- let flags = "W" 7968--- endwhile 7969--- update " write the file if modified 7970--- let n = n + 1 7971--- endwhile 7972--- < 7973--- Example for using some flags: >vim 7974--- echo search('\<if\|\(else\)\|\(endif\)', 'ncpe') 7975--- <This will search for the keywords "if", "else", and "endif" 7976--- under or after the cursor. Because of the 'p' flag, it 7977--- returns 1, 2, or 3 depending on which keyword is found, or 0 7978--- if the search fails. With the cursor on the first word of the 7979--- line: 7980--- if (foo == 0) | let foo = foo + 1 | endif ~ 7981--- the function returns 1. Without the 'c' flag, the function 7982--- finds the "endif" and returns 3. The same thing happens 7983--- without the 'e' flag if the cursor is on the "f" of "if". 7984--- The 'n' flag tells the function not to move the cursor. 7985--- 7986--- @param pattern string 7987--- @param flags? string 7988--- @param stopline? integer 7989--- @param timeout? integer 7990--- @param skip? string|function 7991--- @return integer 7992function vim . fn . search ( pattern , flags , stopline , timeout , skip ) end 7993 7994--- Get or update the last search count, like what is displayed 7995--- without the "S" flag in 'shortmess'. This works even if 7996--- 'shortmess' does contain the "S" flag. 7997--- 7998--- This returns a |Dictionary|. The dictionary is empty if the 7999--- previous pattern was not set and "pattern" was not specified. 8000--- 8001--- key type meaning ~ 8002--- current |Number| current position of match; 8003--- 0 if the cursor position is 8004--- before the first match 8005--- exact_match |Boolean| 1 if "current" is matched on 8006--- "pos", otherwise 0 8007--- total |Number| total count of matches found 8008--- incomplete |Number| 0: search was fully completed 8009--- 1: recomputing was timed out 8010--- 2: max count exceeded 8011--- 8012--- For {options} see further down. 8013--- 8014--- To get the last search count when |n| or |N| was pressed, call 8015--- this function with `recompute: 0` . This sometimes returns 8016--- wrong information because of 'maxsearchcount'. 8017--- If the count exceeded 'maxsearchcount', the result must be 8018--- 'maxsearchcount' + 1. If you want to get correct information, 8019--- specify `recompute: 1`: >vim 8020--- 8021--- " result == 'maxsearchcount' + 1 when many matches 8022--- let result = searchcount(#{recompute: 0}) 8023--- 8024--- " Below returns correct result (recompute defaults 8025--- " to 1) 8026--- let result = searchcount() 8027--- < 8028--- The function is useful to add the count to 'statusline': >vim 8029--- function! LastSearchCount() abort 8030--- let result = searchcount(#{recompute: 0}) 8031--- if empty(result) 8032--- return '' 8033--- endif 8034--- if result.incomplete ==# 1 " timed out 8035--- return printf(' /%s [?/??]', \@/) 8036--- elseif result.incomplete ==# 2 " max count exceeded 8037--- if result.total > result.maxcount && 8038--- \ result.current > result.maxcount 8039--- return printf(' /%s [>%d/>%d]', \@/, 8040--- \ result.current, result.total) 8041--- elseif result.total > result.maxcount 8042--- return printf(' /%s [%d/>%d]', \@/, 8043--- \ result.current, result.total) 8044--- endif 8045--- endif 8046--- return printf(' /%s [%d/%d]', \@/, 8047--- \ result.current, result.total) 8048--- endfunction 8049--- let &statusline ..= '%{LastSearchCount()}' 8050--- 8051--- " Or if you want to show the count only when 8052--- " 'hlsearch' was on 8053--- " let &statusline ..= 8054--- " \ '%{v:hlsearch ? LastSearchCount() : ""}' 8055--- < 8056--- You can also update the search count, which can be useful in a 8057--- |CursorMoved| or |CursorMovedI| autocommand: >vim 8058--- 8059--- autocmd CursorMoved,CursorMovedI * 8060--- \ let s:searchcount_timer = timer_start( 8061--- \ 200, function('s:update_searchcount')) 8062--- function! s:update_searchcount(timer) abort 8063--- if a:timer ==# s:searchcount_timer 8064--- call searchcount(#{ 8065--- \ recompute: 1, maxcount: 0, timeout: 100}) 8066--- redrawstatus 8067--- endif 8068--- endfunction 8069--- < 8070--- This can also be used to count matched texts with specified 8071--- pattern in the current buffer using "pattern": >vim 8072--- 8073--- " Count '\<foo\>' in this buffer 8074--- " (Note that it also updates search count) 8075--- let result = searchcount(#{pattern: '\<foo\>'}) 8076--- 8077--- " To restore old search count by old pattern, 8078--- " search again 8079--- call searchcount() 8080--- < 8081--- {options} must be a |Dictionary|. It can contain: 8082--- key type meaning ~ 8083--- recompute |Boolean| if |TRUE|, recompute the count 8084--- like |n| or |N| was executed. 8085--- otherwise returns the last 8086--- computed result (when |n| or 8087--- |N| was used when "S" is not 8088--- in 'shortmess', or this 8089--- function was called). 8090--- (default: |TRUE|) 8091--- pattern |String| recompute if this was given 8092--- and different with |\@/|. 8093--- this works as same as the 8094--- below command is executed 8095--- before calling this function >vim 8096--- let \@/ = pattern 8097--- < (default: |\@/|) 8098--- timeout |Number| 0 or negative number is no 8099--- timeout. timeout milliseconds 8100--- for recomputing the result 8101--- (default: 0) 8102--- maxcount |Number| 0 or negative number is no 8103--- limit. max count of matched 8104--- text while recomputing the 8105--- result. if search exceeded 8106--- total count, "total" value 8107--- becomes `maxcount + 1` 8108--- (default: 'maxsearchcount') 8109--- pos |List| `[lnum, col, off]` value 8110--- when recomputing the result. 8111--- this changes "current" result 8112--- value. see |cursor()|, |getpos()| 8113--- (default: cursor's position) 8114--- 8115--- @param options? table 8116--- @return any 8117function vim . fn . searchcount ( options ) end 8118 8119--- Search for the declaration of {name}. 8120--- 8121--- With a non-zero {global} argument it works like |gD|, find 8122--- first match in the file. Otherwise it works like |gd|, find 8123--- first match in the function. 8124--- 8125--- With a non-zero {thisblock} argument matches in a {} block 8126--- that ends before the cursor position are ignored. Avoids 8127--- finding variable declarations only valid in another scope. 8128--- 8129--- Moves the cursor to the found match. 8130--- Returns zero for success, non-zero for failure. 8131--- Example: >vim 8132--- if searchdecl('myvar') == 0 8133--- echo getline('.') 8134--- endif 8135--- < 8136--- 8137--- @param name string 8138--- @param global? boolean 8139--- @param thisblock? boolean 8140--- @return any 8141function vim . fn . searchdecl ( name , global , thisblock ) end 8142 8143--- Search for the match of a nested start-end pair. This can be 8144--- used to find the "endif" that matches an "if", while other 8145--- if/endif pairs in between are ignored. 8146--- The search starts at the cursor. The default is to search 8147--- forward, include 'b' in {flags} to search backward. 8148--- If a match is found, the cursor is positioned at it and the 8149--- line number is returned. If no match is found 0 or -1 is 8150--- returned and the cursor doesn't move. No error message is 8151--- given. 8152--- 8153--- {start}, {middle} and {end} are patterns, see |pattern|. They 8154--- must not contain \( \) pairs. Use of \%( \) is allowed. When 8155--- {middle} is not empty, it is found when searching from either 8156--- direction, but only when not in a nested start-end pair. A 8157--- typical use is: >vim 8158--- echo searchpair('\<if\>', '\<else\>', '\<endif\>') 8159--- <By leaving {middle} empty the "else" is skipped. 8160--- 8161--- {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with 8162--- |search()|. Additionally: 8163--- 'r' Repeat until no more matches found; will find the 8164--- outer pair. Implies the 'W' flag. 8165--- 'm' Return number of matches instead of line number with 8166--- the match; will be > 1 when 'r' is used. 8167--- Note: it's nearly always a good idea to use the 'W' flag, to 8168--- avoid wrapping around the end of the file. 8169--- 8170--- When a match for {start}, {middle} or {end} is found, the 8171--- {skip} expression is evaluated with the cursor positioned on 8172--- the start of the match. It should return non-zero if this 8173--- match is to be skipped. E.g., because it is inside a comment 8174--- or a string. 8175--- When {skip} is omitted or empty, every match is accepted. 8176--- When evaluating {skip} causes an error the search is aborted 8177--- and -1 returned. 8178--- {skip} can be a string, a lambda, a funcref or a partial. 8179--- Anything else makes the function fail. 8180--- 8181--- For {stopline} and {timeout} see |search()|. 8182--- 8183--- The value of 'ignorecase' is used. 'magic' is ignored, the 8184--- patterns are used like it's on. 8185--- 8186--- The search starts exactly at the cursor. A match with 8187--- {start}, {middle} or {end} at the next character, in the 8188--- direction of searching, is the first one found. Example: >vim 8189--- if 1 8190--- if 2 8191--- endif 2 8192--- endif 1 8193--- <When starting at the "if 2", with the cursor on the "i", and 8194--- searching forwards, the "endif 2" is found. When starting on 8195--- the character just before the "if 2", the "endif 1" will be 8196--- found. That's because the "if 2" will be found first, and 8197--- then this is considered to be a nested if/endif from "if 2" to 8198--- "endif 2". 8199--- When searching backwards and {end} is more than one character, 8200--- it may be useful to put "\zs" at the end of the pattern, so 8201--- that when the cursor is inside a match with the end it finds 8202--- the matching start. 8203--- 8204--- Example, to find the "endif" command in a Vim script: >vim 8205--- 8206--- echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W', 8207--- \ 'getline(".") =~ "^\\s*\""') 8208--- 8209--- <The cursor must be at or after the "if" for which a match is 8210--- to be found. Note that single-quote strings are used to avoid 8211--- having to double the backslashes. The skip expression only 8212--- catches comments at the start of a line, not after a command. 8213--- Also, a word "en" or "if" halfway through a line is considered 8214--- a match. 8215--- Another example, to search for the matching "{" of a "}": >vim 8216--- 8217--- echo searchpair('{', '', '}', 'bW') 8218--- 8219--- <This works when the cursor is at or before the "}" for which a 8220--- match is to be found. To reject matches that syntax 8221--- highlighting recognized as strings: >vim 8222--- 8223--- echo searchpair('{', '', '}', 'bW', 8224--- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"') 8225--- < 8226--- 8227--- @param start string 8228--- @param middle string 8229--- @param end_ string 8230--- @param flags? string 8231--- @param skip? string|function 8232--- @param stopline? integer 8233--- @param timeout? integer 8234--- @return integer 8235function vim . fn . searchpair ( start , middle , end_ , flags , skip , stopline , timeout ) end 8236 8237--- Same as |searchpair()|, but returns a |List| with the line and 8238--- column position of the match. The first element of the |List| 8239--- is the line number and the second element is the byte index of 8240--- the column position of the match. If no match is found, 8241--- returns [0, 0]. >vim 8242--- 8243--- let [lnum,col] = searchpairpos('{', '', '}', 'n') 8244--- < 8245--- See |match-parens| for a bigger and more useful example. 8246--- 8247--- @param start string 8248--- @param middle string 8249--- @param end_ string 8250--- @param flags? string 8251--- @param skip? string|function 8252--- @param stopline? integer 8253--- @param timeout? integer 8254--- @return [integer, integer] 8255function vim . fn . searchpairpos ( start , middle , end_ , flags , skip , stopline , timeout ) end 8256 8257--- Same as |search()|, but returns a |List| with the line and 8258--- column position of the match. The first element of the |List| 8259--- is the line number and the second element is the byte index of 8260--- the column position of the match. If no match is found, 8261--- returns [0, 0]. 8262--- Example: >vim 8263--- let [lnum, col] = searchpos('mypattern', 'n') 8264--- 8265--- <When the 'p' flag is given then there is an extra item with 8266--- the sub-pattern match number |search()-sub-match|. Example: >vim 8267--- let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np') 8268--- <In this example "submatch" is 2 when a lowercase letter is 8269--- found |/\l|, 3 when an uppercase letter is found |/\u|. 8270--- 8271--- @param pattern string 8272--- @param flags? string 8273--- @param stopline? integer 8274--- @param timeout? integer 8275--- @param skip? string|function 8276--- @return { [1]: integer, [2]: integer, [3]: integer? } 8277function vim . fn . searchpos ( pattern , flags , stopline , timeout , skip ) end 8278 8279--- Returns a list of server addresses, or empty if all servers 8280--- were stopped. |serverstart()| |serverstop()| 8281--- 8282--- The optional argument {opts} is a Dict and supports the following items: 8283--- 8284--- peer : If |TRUE|, servers not started by |serverstart()| 8285--- will also be returned. (default: |FALSE|) 8286--- Not supported on Windows yet. 8287--- 8288--- info : If |TRUE|, return a list of Dicts with detailed info 8289--- instead of addresses. Implies `peer=true`. Each Dict 8290--- has the following items: 8291--- addr (string) Server address. 8292--- pid (number) PID of the Nvim process. 8293--- own (bool) Whether this server belongs to 8294--- the current Nvim instance. 8295--- active (number) |v:useractive| of the server. 8296--- (default: |FALSE|) 8297--- 8298--- Example: >vim 8299--- echo serverlist() 8300--- echo serverlist(#{info: v:true}) 8301--- < 8302--- 8303--- @param opts? table 8304--- @return string[]|vim.ServerInfo[] 8305function vim . fn . serverlist ( opts ) end 8306 8307--- Opens a socket or named pipe at {address} and listens for 8308--- |RPC| messages. Clients can send |API| commands to the 8309--- returned address to control Nvim. 8310--- 8311--- Returns the address string (which may differ from the 8312--- {address} argument, see below). 8313--- 8314--- - If {address} has a colon (":") it is a TCP/IPv4/IPv6 address 8315--- where the last ":" separates host and port (empty or zero 8316--- assigns a random port). 8317--- - Else {address} is the path to a named pipe (except on Windows). 8318--- - If {address} has no slashes ("/") it is treated as the 8319--- "name" part of a generated path in this format: >vim 8320--- stdpath("run").."/{name}.{pid}.{counter}" 8321--- < - If {address} is omitted the name is "nvim". >vim 8322--- echo serverstart() 8323--- < > 8324--- => /tmp/nvim.bram/oknANW/nvim.15430.5 8325--- < 8326--- Example bash command to list all Nvim servers: >bash 8327--- ls ${XDG_RUNTIME_DIR:-${TMPDIR}nvim.${USER}}/*/nvim.*.0 8328--- 8329--- <Example named pipe: >vim 8330--- if has('win32') 8331--- echo serverstart('//./pipe/nvim-pipe-1234') 8332--- else 8333--- echo serverstart('nvim.sock') 8334--- endif 8335--- < 8336--- Example TCP/IP address: >vim 8337--- echo serverstart('::1:12345') 8338--- < 8339--- 8340--- @param address? string 8341--- @return string 8342function vim . fn . serverstart ( address ) end 8343 8344--- Closes the pipe or socket at {address}. 8345--- Returns TRUE if {address} is valid, else FALSE. 8346--- If |v:servername| is stopped it is set to the next available 8347--- address in |serverlist()|. 8348--- 8349--- @param address string 8350--- @return integer 8351function vim . fn . serverstop ( address ) end 8352 8353--- Lua: Prefer |nvim_buf_set_lines()|. 8354--- 8355--- Set line {lnum} to {text} in buffer {buf}. This works like 8356--- |setline()| for the specified buffer. 8357--- 8358--- This function works only for loaded buffers. First call 8359--- |bufload()| if needed. 8360--- 8361--- To insert lines use |appendbufline()|. 8362--- 8363--- {text} can be a string to set one line, or a List of strings 8364--- to set multiple lines. If the List extends below the last 8365--- line then those lines are added. If the List is empty then 8366--- nothing is changed and zero is returned. 8367--- 8368--- For the use of {buf}, see |bufname()| above. 8369--- 8370--- {lnum} is used like with |setline()|. 8371--- Use "$" to refer to the last line in buffer {buf}. 8372--- When {lnum} is just below the last line the {text} will be 8373--- added below the last line. 8374--- On success 0 is returned, on failure 1 is returned. 8375--- 8376--- If {buf} is not a valid buffer or {lnum} is not valid, an 8377--- error message is given. 8378--- 8379--- @param buf integer|string 8380--- @param lnum integer 8381--- @param text string|string[] 8382--- @return integer 8383function vim . fn . setbufline ( buf , lnum , text ) end 8384 8385--- Lua: Prefer |nvim_buf_set_var()| or |vim.b| after resolving {buf} to a bufnr; option names use |nvim_set_option_value()|. 8386--- 8387--- Set option or local variable {varname} (string, without "b:") 8388--- in buffer {buf} to {val}. Also works for a global or 8389--- window-local option (not variable). A window-local option is 8390--- set in a window of the current tabpage that displays {buf}, 8391--- and the global value is unchanged. When no window in the 8392--- current tabpage displays {buf} the option is not set and no 8393--- error is given; use |setwinvar()| or |win_execute()| for that. 8394--- 8395--- For the use of {buf}, see |bufname()| above. 8396--- 8397--- Examples: >vim 8398--- call setbufvar(1, "&mod", 1) 8399--- call setbufvar("todo", "myvar", "foobar") 8400--- <This function is not available in the |sandbox|. 8401--- 8402--- @param buf integer|string 8403--- @param varname string 8404--- @param val any 8405--- @return any 8406function vim . fn . setbufvar ( buf , varname , val ) end 8407 8408--- Specify overrides for cell widths of character ranges. This 8409--- tells Vim how wide characters are when displayed in the 8410--- terminal, counted in screen cells. The values override 8411--- 'ambiwidth'. Example: >vim 8412--- call setcellwidths([ 8413--- \ [0x111, 0x111, 1], 8414--- \ [0x2194, 0x2199, 2], 8415--- \ ]) 8416--- 8417--- <The {list} argument is a List of Lists with each three 8418--- numbers: [{low}, {high}, {width}]. *E1109* *E1110* 8419--- {low} and {high} can be the same, in which case this refers to 8420--- one character. Otherwise it is the range of characters from 8421--- {low} to {high} (inclusive). *E1111* *E1114* 8422--- Only characters with value 0x80 and higher can be used. 8423--- 8424--- {width} must be either 1 or 2, indicating the character width 8425--- in screen cells. *E1112* 8426--- An error is given if the argument is invalid, also when a 8427--- range overlaps with another. *E1113* 8428--- 8429--- If the new value causes 'fillchars' or 'listchars' to become 8430--- invalid it is rejected and an error is given. 8431--- 8432--- To clear the overrides pass an empty {list}: >vim 8433--- call setcellwidths([]) 8434--- 8435--- <You can use the script $VIMRUNTIME/scripts/emoji_list.lua to see 8436--- the effect for known emoji characters. Move the cursor 8437--- through the text to check if the cell widths of your terminal 8438--- match with what Vim knows about each emoji. If it doesn't 8439--- look right you need to adjust the {list} argument. 8440--- 8441--- |getcellwidths()| can be used to get the overrides later. 8442--- 8443--- @param list any[] 8444--- @return any 8445function vim . fn . setcellwidths ( list ) end 8446 8447--- Lua: Prefer |nvim_win_set_cursor()| or |nvim_buf_set_mark()| with |vim.str_byteindex()|; special positions, `off`, and `curswant` differ. 8448--- 8449--- Same as |setpos()| but uses the specified column number as the 8450--- character index instead of the byte index in the line. 8451--- 8452--- Example: 8453--- With the text "여보세요" in line 8: >vim 8454--- call setcharpos('.', [0, 8, 4, 0]) 8455--- <positions the cursor on the fourth character '요'. >vim 8456--- call setpos('.', [0, 8, 4, 0]) 8457--- <positions the cursor on the second character '보'. 8458--- 8459--- @param expr string 8460--- @param list integer[] 8461--- @return any 8462function vim . fn . setcharpos ( expr , list ) end 8463 8464--- Set the current character search information to {dict}, 8465--- which contains one or more of the following entries: 8466--- 8467--- char character which will be used for a subsequent 8468--- |,| or |;| command; an empty string clears the 8469--- character search 8470--- forward direction of character search; 1 for forward, 8471--- 0 for backward 8472--- until type of character search; 1 for a |t| or |T| 8473--- character search, 0 for an |f| or |F| 8474--- character search 8475--- 8476--- This can be useful to save/restore a user's character search 8477--- from a script: >vim 8478--- let prevsearch = getcharsearch() 8479--- " Perform a command which clobbers user's search 8480--- call setcharsearch(prevsearch) 8481--- <Also see |getcharsearch()|. 8482--- 8483--- @param dict { char?: string, forward?: 1|0, until?: 1|0 } 8484--- @return any 8485function vim . fn . setcharsearch ( dict ) end 8486 8487--- Set the command line to {str} and set the cursor position to 8488--- {pos}. 8489--- If {pos} is omitted, the cursor is positioned after the text. 8490--- Returns 0 when successful, 1 when not editing the command 8491--- line. 8492--- 8493--- @param str string 8494--- @param pos? integer 8495--- @return integer 8496function vim . fn . setcmdline ( str , pos ) end 8497 8498--- Set the cursor position in the command line to byte position 8499--- {pos}. The first position is 1. 8500--- Use |getcmdpos()| to obtain the current position. 8501--- Only works while editing the command line, thus you must use 8502--- |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For 8503--- |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is 8504--- set after the command line is set to the expression. For 8505--- |c_CTRL-R_=| it is set after evaluating the expression but 8506--- before inserting the resulting text. 8507--- When the number is too big the cursor is put at the end of the 8508--- line. A number smaller than one has undefined results. 8509--- Returns 0 when successful, 1 when not editing the command 8510--- line. 8511--- 8512--- @param pos integer 8513--- @return any 8514function vim . fn . setcmdpos ( pos ) end 8515 8516--- Lua: Prefer |nvim_win_set_cursor()| with |vim.str_byteindex()|; `off`, return values, and special line forms differ. 8517--- 8518--- Lua: Prefer |nvim_win_set_cursor()| with |vim.str_byteindex()|; list shape, `off`, and return values differ. 8519--- 8520--- Same as |cursor()| but uses the specified column number as the 8521--- character index instead of the byte index in the line. 8522--- 8523--- Example: 8524--- With the text "여보세요" in line 4: >vim 8525--- call setcursorcharpos(4, 3) 8526--- <positions the cursor on the third character '세'. >vim 8527--- call cursor(4, 3) 8528--- <positions the cursor on the first character '여'. 8529--- 8530--- Returns 0 when the position could be set, -1 otherwise. 8531--- 8532--- @overload fun(list: integer[]): (any) 8533--- @param lnum integer|string 8534--- @param col? integer 8535--- @param off? integer 8536--- @return any 8537function vim . fn . setcursorcharpos ( lnum , col , off ) end 8538 8539--- Lua: Prefer |vim.env|. 8540--- 8541--- Set environment variable {name} to {val}. Example: >vim 8542--- call setenv('HOME', '/home/myhome') 8543--- 8544--- <When {val} is |v:null| the environment variable is deleted. 8545--- See also |expr-env|. 8546--- 8547--- @param name string 8548--- @param val string 8549--- @return any 8550function vim . fn . setenv ( name , val ) end 8551 8552--- Lua: Prefer |uv.fs_chmod()|. 8553--- 8554--- Set the file permissions for {fname} to {mode}. 8555--- {mode} must be a string with 9 characters. It is of the form 8556--- "rwxrwxrwx", where each group of "rwx" flags represent, in 8557--- turn, the permissions of the owner of the file, the group the 8558--- file belongs to, and other users. A '-' character means the 8559--- permission is off, any other character means on. Multi-byte 8560--- characters are not supported. 8561--- 8562--- For example "rw-r-----" means read-write for the user, 8563--- readable by the group, not accessible by others. "xx-x-----" 8564--- would do the same thing. 8565--- 8566--- Returns non-zero for success, zero for failure. 8567--- 8568--- To read permissions see |getfperm()|. 8569--- 8570--- @param fname string 8571--- @param mode string 8572--- @return any 8573function vim . fn . setfperm ( fname , mode ) end 8574 8575--- Lua: Prefer |nvim_set_current_line()| or |nvim_buf_set_lines()|. 8576--- 8577--- Set line {lnum} of the current buffer to {text}. To insert 8578--- lines use |append()|. To set lines in another buffer use 8579--- |setbufline()|. 8580--- 8581--- {lnum} is used like with |getline()|. 8582--- When {lnum} is just below the last line the {text} will be 8583--- added below the last line. 8584--- {text} can be any type or a List of any type, each item is 8585--- converted to a String. When {text} is an empty List then 8586--- nothing is changed and FALSE is returned. 8587--- 8588--- If this succeeds, FALSE is returned. If this fails (most 8589--- likely because {lnum} is invalid) TRUE is returned. 8590--- 8591--- Example: >vim 8592--- call setline(5, strftime("%c")) 8593--- 8594--- <When {text} is a |List| then line {lnum} and following lines 8595--- will be set to the items in the list. Example: >vim 8596--- call setline(5, ['aaa', 'bbb', 'ccc']) 8597--- <This is equivalent to: >vim 8598--- for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']] 8599--- call setline(n, l) 8600--- endfor 8601--- 8602--- <Note: The '[ and '] marks are not set. 8603--- 8604--- @param lnum integer|string 8605--- @param text any 8606--- @return any 8607function vim . fn . setline ( lnum , text ) end 8608 8609--- Create or replace or add to the location list for window {nr} 8610--- (|window-number| or |window-ID|). 8611--- When {nr} is zero the current window is used. 8612--- 8613--- For a location list window, the displayed location list is 8614--- modified. For an invalid {nr}, -1 is returned. 8615--- Otherwise, same as |setqflist()|. 8616--- Also see |location-list|. 8617--- 8618--- For {action} see |setqflist-action|. 8619--- 8620--- If the optional {what} dictionary argument is supplied, then 8621--- only the items listed in {what} are set. Refer to |setqflist()| 8622--- for the list of supported keys in {what}. 8623--- 8624--- @param nr integer 8625--- @param list vim.quickfix.entry[] 8626--- @param action? string 8627--- @param what? vim.fn.setqflist.what 8628--- @return any 8629function vim . fn . setloclist ( nr , list , action , what ) end 8630 8631--- Restores a list of matches saved by |getmatches()| for the 8632--- current window. Returns 0 if successful, otherwise -1. All 8633--- current matches are cleared before the list is restored. See 8634--- example for |getmatches()|. 8635--- {win} (if given) is a |window-number| or |window-ID|. 8636--- 8637--- @param list vim.fn.getmatches.ret.item[] 8638--- @param win? integer 8639--- @return any 8640function vim . fn . setmatches ( list , win ) end 8641 8642--- Lua: Prefer |nvim_win_set_cursor()| for "." or |nvim_buf_set_mark()| for marks; special positions, `off`, and `curswant` differ. 8643--- 8644--- Set the position for String {expr}. Possible values: 8645--- . the cursor 8646--- 'x mark x 8647--- 8648--- {list} must be a |List| with four or five numbers: 8649--- [bufnum, lnum, col, off] 8650--- [bufnum, lnum, col, off, curswant] 8651--- 8652--- "bufnum" is the buffer number. Zero can be used for the 8653--- current buffer. When setting an uppercase mark "bufnum" is 8654--- used for the mark position. For other marks it specifies the 8655--- buffer to set the mark in. You can use the |bufnr()| function 8656--- to turn a file name into a buffer number. 8657--- For setting the cursor and the ' mark "bufnum" is ignored, 8658--- since these are associated with a window, not a buffer. 8659--- Does not change the jumplist. 8660--- 8661--- "lnum" and "col" are the position in the buffer. The first 8662--- column is 1. Use a zero "lnum" to delete a mark. If "col" is 8663--- smaller than 1 then 1 is used. To use the character count 8664--- instead of the byte count, use |setcharpos()|. 8665--- 8666--- The "off" number is only used when 'virtualedit' is set. Then 8667--- it is the offset in screen columns from the start of the 8668--- character. E.g., a position within a <Tab> or after the last 8669--- character. 8670--- 8671--- The "curswant" number is only used when setting the cursor 8672--- position. It sets the preferred column for when moving the 8673--- cursor vertically. When the "curswant" number is missing the 8674--- preferred column is not set. When it is present and setting a 8675--- mark position it is not used. 8676--- 8677--- Note that for |'<| and |'>| changing the line number may 8678--- result in the marks to be effectively swapped, so that |'<| is 8679--- always before |'>|. 8680--- 8681--- The visual marks |'<| and |'>| refer to the beginning and end 8682--- of the visual selection relative to the cursor position. 8683--- Note that this differs from |getpos()|, where they are 8684--- relative to the buffer. 8685--- 8686--- Returns 0 when the position could be set, -1 otherwise. 8687--- An error message is given if {expr} is invalid. 8688--- 8689--- Also see |setcharpos()|, |getpos()| and |getcurpos()|. 8690--- 8691--- This does not restore the preferred column for moving 8692--- vertically; if you set the cursor position with this, |j| and 8693--- |k| motions will jump to previous columns! Use |cursor()| to 8694--- also set the preferred column. Also see the "curswant" key in 8695--- |winrestview()|. 8696--- 8697--- @param expr string 8698--- @param list integer[] 8699--- @return any 8700function vim . fn . setpos ( expr , list ) end 8701 8702--- Create or replace or add to the quickfix list. 8703--- 8704--- If the optional {what} dictionary argument is supplied, then 8705--- only the items listed in {what} are set. The first {list} 8706--- argument is ignored. See below for the supported items in 8707--- {what}. 8708--- *setqflist-what* 8709--- When {what} is not present, the items in {list} are used. 8710--- Each item must be a dictionary. Non-dictionary items in 8711--- {list} are ignored. Each dictionary item can contain the 8712--- following entries: 8713--- 8714--- bufnr buffer number; must be the number of a valid 8715--- buffer 8716--- filename name of a file; only used when "bufnr" is not 8717--- present or it is invalid. 8718--- module name of a module; if given it will be used in 8719--- quickfix error window instead of the filename. 8720--- lnum line number in the file 8721--- end_lnum end of lines, if the item spans multiple lines 8722--- pattern search pattern used to locate the error 8723--- col column number 8724--- vcol when non-zero: "col" is visual column 8725--- when zero: "col" is byte index 8726--- end_col end column, if the item spans multiple columns 8727--- nr error number 8728--- text description of the error 8729--- type single-character error type, 'E', 'W', etc. 8730--- valid recognized error message 8731--- user_data 8732--- custom data associated with the item, can be 8733--- any type. 8734--- 8735--- The "col", "vcol", "nr", "type" and "text" entries are 8736--- optional. Either "lnum" or "pattern" entry can be used to 8737--- locate a matching error line. 8738--- If the "filename" and "bufnr" entries are not present or 8739--- neither the "lnum" or "pattern" entries are present, then the 8740--- item will not be handled as an error line. 8741--- If both "pattern" and "lnum" are present then "pattern" will 8742--- be used. 8743--- If the "valid" entry is not supplied, then the valid flag is 8744--- set when "bufnr" is a valid buffer or "filename" exists. 8745--- If you supply an empty {list}, the quickfix list will be 8746--- cleared. 8747--- Note that the list is not exactly the same as what 8748--- |getqflist()| returns. 8749--- 8750--- {action} values: *setqflist-action* *E927* 8751--- 'a' The items from {list} are added to the existing 8752--- quickfix list. If there is no existing list, then a 8753--- new list is created. 8754--- 8755--- 'r' The items from the current quickfix list are replaced 8756--- with the items from {list}. This can also be used to 8757--- clear the list: >vim 8758--- call setqflist([], 'r') 8759--- < 8760--- 'u' Like 'r', but tries to preserve the current selection 8761--- in the quickfix list. The entry nearest to the 8762--- previously selected one becomes the current entry. 8763--- Proximity is determined by comparing the file, then 8764--- the line number and then the column number. 8765--- 'f' All the quickfix lists in the quickfix stack are 8766--- freed. 8767--- 8768--- If {action} is not present or is set to ' ', then a new list 8769--- is created. The new quickfix list is added after the current 8770--- quickfix list in the stack and all the following lists are 8771--- freed. To add a new quickfix list at the end of the stack, 8772--- set "nr" in {what} to "$". 8773--- 8774--- The following items can be specified in dictionary {what}: 8775--- context quickfix list context. See |quickfix-context| 8776--- efm errorformat to use when parsing text from 8777--- "lines". If this is not present, then the 8778--- 'errorformat' option value is used. 8779--- See |quickfix-parse| 8780--- id quickfix list identifier |quickfix-ID| 8781--- idx index of the current entry in the quickfix 8782--- list specified by "id" or "nr". If set to 8783--- '$', then the last entry in the list is set as 8784--- the current entry. See |quickfix-index| 8785--- items list of quickfix entries. Same as the {list} 8786--- argument. 8787--- lines use 'errorformat' to parse a list of lines and 8788--- add the resulting entries to the quickfix list 8789--- {nr} or {id}. Only a |List| value is supported. 8790--- See |quickfix-parse| 8791--- nr list number in the quickfix stack; zero 8792--- means the current quickfix list and "$" means 8793--- the last quickfix list. 8794--- quickfixtextfunc 8795--- function to get the text to display in the 8796--- quickfix window. The value can be the name of 8797--- a function or a funcref or a lambda. Refer to 8798--- |quickfix-window-function| for an explanation 8799--- of how to write the function and an example. 8800--- title quickfix list title text. See |quickfix-title| 8801--- Unsupported keys in {what} are ignored. 8802--- If the "nr" item is not present, then the current quickfix 8803--- list is modified. When creating a new quickfix list, "nr" can 8804--- be set to a value one greater than the quickfix stack size. 8805--- When modifying a quickfix list, to guarantee that the correct 8806--- list is modified, "id" should be used instead of "nr" to 8807--- specify the list. 8808--- 8809--- Examples (See also |setqflist-examples|): >vim 8810--- call setqflist([], 'r', {'title': 'My search'}) 8811--- call setqflist([], 'r', {'nr': 2, 'title': 'Errors'}) 8812--- call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]}) 8813--- < 8814--- Returns zero for success, -1 for failure. 8815--- 8816--- This function can be used to create a quickfix list 8817--- independent of the 'errorformat' setting. Use a command like 8818--- `:cc 1` to jump to the first position. 8819--- 8820--- @param list vim.quickfix.entry[] 8821--- @param action? string 8822--- @param what? vim.fn.setqflist.what 8823--- @return integer 8824function vim . fn . setqflist ( list , action , what ) end 8825 8826--- Set the register {regname} to {value}. 8827--- If {regname} is "" or "\@", the unnamed register '"' is used. 8828--- The {regname} argument is a string. 8829--- 8830--- {value} may be any value returned by |getreg()| or 8831--- |getreginfo()|, including a |List| or |Dict|. 8832--- If {options} contains "a" or {regname} is upper case, 8833--- then the value is appended. 8834--- 8835--- {options} can also contain a register type specification: 8836--- "c" or "v" |charwise| mode 8837--- "l" or "V" |linewise| mode 8838--- "b" or "<CTRL-V>" |blockwise-visual| mode 8839--- If a number immediately follows "b" or "<CTRL-V>" then this is 8840--- used as the width of the selection - if it is not specified 8841--- then the width of the block is set to the number of characters 8842--- in the longest line (counting a <Tab> as 1 character). 8843--- If {options} contains "u" or '"', then the unnamed register is 8844--- set to point to register {regname}. 8845--- 8846--- If {options} contains no register settings, then the default 8847--- is to use character mode unless {value} ends in a <NL> for 8848--- string {value} and linewise mode for list {value}. Blockwise 8849--- mode is never selected automatically. 8850--- Returns zero for success, non-zero for failure. 8851--- 8852--- *E883* 8853--- Note: you may not use |List| containing more than one item to 8854--- set search and expression registers. Lists containing 8855--- no items act like empty strings. 8856--- 8857--- Examples: >vim 8858--- call setreg(v:register, \@*) 8859--- call setreg('*', \@%, 'ac') 8860--- call setreg('a', "1\n2\n3", 'b5') 8861--- call setreg('"', { 'points_to': 'a'}) 8862--- 8863--- <This example shows using the functions to save and restore a 8864--- register: >vim 8865--- let var_a = getreginfo() 8866--- call setreg('a', var_a) 8867--- <or: >vim 8868--- let var_a = getreg('a', 1, 1) 8869--- let var_amode = getregtype('a') 8870--- " .... 8871--- call setreg('a', var_a, var_amode) 8872--- <Note: you may not reliably restore register value 8873--- without using the third argument to |getreg()| as without it 8874--- newlines are represented as newlines AND Nul bytes are 8875--- represented as newlines as well, see |NL-used-for-Nul|. 8876--- 8877--- You can also change the type of a register by appending 8878--- nothing: >vim 8879--- call setreg('a', '', 'al') 8880--- < 8881--- 8882--- @param regname string 8883--- @param value any 8884--- @param options? string 8885--- @return any 8886function vim . fn . setreg ( regname , value , options ) end 8887 8888--- Lua: Prefer |nvim_tabpage_set_var()| or |vim.t|. 8889--- 8890--- Set tab-local variable {varname} to {val} in tabpage {tabnr}. 8891--- |t:var| 8892--- The {varname} argument is a string. 8893--- Note that the variable name without "t:" must be used. 8894--- Tabs are numbered starting with one. 8895--- This function is not available in the |sandbox|. 8896--- 8897--- @param tabnr integer 8898--- @param varname string 8899--- @param val any 8900--- @return any 8901function vim . fn . settabvar ( tabnr , varname , val ) end 8902 8903--- Lua: Prefer |nvim_win_set_var()| or |vim.w| after resolving {tabnr} and {winnr} to a winid; option names use |nvim_set_option_value()|. 8904--- 8905--- Set option or local variable {varname} in window {winnr} to 8906--- {val}. 8907--- Tabs are numbered starting with one. For the current tabpage 8908--- use |setwinvar()|. 8909--- {winnr} is a |window-number| or |window-ID|. 8910--- When {winnr} is zero the current window is used. 8911--- This also works for a global or local buffer option, but it 8912--- doesn't work for a global or local buffer variable. 8913--- For a local buffer option the global value is unchanged. 8914--- Note that the variable name without "w:" must be used. 8915--- Examples: >vim 8916--- call settabwinvar(1, 1, "&list", 0) 8917--- call settabwinvar(3, 2, "myvar", "foobar") 8918--- <This function is not available in the |sandbox|. 8919--- 8920--- @param tabnr integer 8921--- @param winnr integer 8922--- @param varname string 8923--- @param val any 8924--- @return any 8925function vim . fn . settabwinvar ( tabnr , winnr , varname , val ) end 8926 8927--- Modify the tag stack of the window {nr} (|window-number| or 8928--- |window-ID|) using {dict}. 8929--- 8930--- For a list of supported items in {dict}, refer to 8931--- |gettagstack()|. "curidx" takes effect before changing the tag 8932--- stack. 8933--- *E962* 8934--- How the tag stack is modified depends on the {action} 8935--- argument: 8936--- - If {action} is not present or is set to 'r', then the tag 8937--- stack is replaced. 8938--- - If {action} is set to 'a', then new entries from {dict} are 8939--- pushed (added) onto the tag stack. 8940--- - If {action} is set to 't', then all the entries from the 8941--- current entry in the tag stack or "curidx" in {dict} are 8942--- removed and then new entries are pushed to the stack. 8943--- 8944--- The current index is set to one after the length of the tag 8945--- stack after the modification. 8946--- 8947--- Returns zero for success, -1 for failure. 8948--- 8949--- Examples (for more examples see |tagstack-examples|): 8950--- Empty the tag stack of window 3: >vim 8951--- call settagstack(3, {'items' : []}) 8952--- 8953--- < Save and restore the tag stack: >vim 8954--- let stack = gettagstack(1003) 8955--- " do something else 8956--- call settagstack(1003, stack) 8957--- unlet stack 8958--- < 8959--- 8960--- @param nr integer 8961--- @param dict any 8962--- @param action? string 8963--- @return any 8964function vim . fn . settagstack ( nr , dict , action ) end 8965 8966--- Lua: Prefer |nvim_win_set_var()| or |vim.w| after resolving {nr} to a winid; option names use |nvim_set_option_value()|. 8967--- 8968--- Like |settabwinvar()| for the current tabpage. 8969--- Examples: >vim 8970--- call setwinvar(1, "&list", 0) 8971--- call setwinvar(2, "myvar", "foobar") 8972--- < 8973--- 8974--- @param nr integer 8975--- @param varname string 8976--- @param val any 8977--- @return any 8978function vim . fn . setwinvar ( nr , varname , val ) end 8979 8980--- Returns a String with 64 hex characters, which is the SHA256 8981--- checksum of {expr}. 8982--- {expr} is a String or a Blob. 8983--- 8984--- @param expr string 8985--- @return string 8986function vim . fn . sha256 ( expr ) end 8987 8988--- Lua: Prefer |vim.system()| with list args to avoid shell escaping; `:!` and {special} semantics differ. 8989--- 8990--- Escape {string} for use as a shell command argument. 8991--- 8992--- On Windows when 'shellslash' is not set, encloses {string} in 8993--- double-quotes and doubles all double-quotes within {string}. 8994--- Otherwise encloses {string} in single-quotes and replaces all 8995--- "'" with "'\''". 8996--- 8997--- The {special} argument adds additional escaping of keywords 8998--- used in Vim commands. If it is a |non-zero-arg|: 8999--- - Special items such as "!", "%", "#" and "<cword>" (as listed 9000--- in |expand()|) will be preceded by a backslash. 9001--- The backslash will be removed again by the |:!| command. 9002--- - The <NL> character is escaped. 9003--- 9004--- If 'shell' contains "csh" in the tail: 9005--- - The "!" character will be escaped. This is because csh and 9006--- tcsh use "!" for history replacement even in single-quotes. 9007--- - The <NL> character is escaped (twice if {special} is 9008--- a |non-zero-arg|). 9009--- 9010--- If 'shell' contains "fish" in the tail, the "\" character will 9011--- be escaped because in fish it is used as an escape character 9012--- inside single quotes. 9013--- 9014--- Example of use with a |:!| command: >vim 9015--- exe '!dir ' .. shellescape(expand('<cfile>'), 1) 9016--- <This results in a directory listing for the file under the 9017--- cursor. Example of use with |system()|: >vim 9018--- call system("chmod +w -- " .. shellescape(expand("%"))) 9019--- <See also |::S|. 9020--- 9021--- @param string string 9022--- @param special? boolean 9023--- @return string 9024function vim . fn . shellescape ( string , special ) end 9025 9026--- Lua: Prefer |vim.bo| for simple cases: `vim.bo.shiftwidth > 0 and vim.bo.shiftwidth or vim.bo.tabstop`; `{col}` and 'vartabstop' semantics differ. 9027--- 9028--- Returns the effective value of 'shiftwidth'. This is the 9029--- 'shiftwidth' value unless it is zero, in which case it is the 9030--- 'tabstop' value. To be backwards compatible in indent 9031--- plugins, use this: >vim 9032--- if exists('*shiftwidth') 9033--- func s:sw() 9034--- return shiftwidth() 9035--- endfunc 9036--- else 9037--- func s:sw() 9038--- return &sw 9039--- endfunc 9040--- endif 9041--- <And then use s:sw() instead of &sw. 9042--- 9043--- for which to return the 'shiftwidth' value. This matters for 9044--- the 'vartabstop' feature. If the 'vartabstop' setting is 9045--- enabled and no {col} argument is given, column 1 will be 9046--- assumed. 9047--- 9048--- @param col? integer 9049--- @return integer 9050function vim . fn . shiftwidth ( col ) end 9051 9052--- Define a new sign named {name} or modify the attributes of an 9053--- existing sign. This is similar to the |:sign-define| command. 9054--- 9055--- Prefix {name} with a unique text to avoid name collisions. 9056--- There is no {group} like with placing signs. 9057--- 9058--- The {name} can be a String or a Number. The optional {dict} 9059--- argument specifies the sign attributes. The following values 9060--- are supported: 9061--- icon full path to the bitmap file for the sign. 9062--- linehl highlight group used for the whole line the 9063--- sign is placed in. 9064--- priority default priority value of the sign 9065--- numhl highlight group used for the line number where 9066--- the sign is placed. 9067--- text text that is displayed when there is no icon 9068--- or the GUI is not being used. 9069--- texthl highlight group used for the text item 9070--- culhl highlight group used for the text item when 9071--- the cursor is on the same line as the sign and 9072--- 'cursorline' is enabled. 9073--- 9074--- If the sign named {name} already exists, then the attributes 9075--- of the sign are updated. 9076--- 9077--- The one argument {list} can be used to define a list of signs. 9078--- Each list item is a dictionary with the above items in {dict} 9079--- and a "name" item for the sign name. 9080--- 9081--- Returns 0 on success and -1 on failure. When the one argument 9082--- {list} is used, then returns a List of values one for each 9083--- defined sign. 9084--- 9085--- Examples: >vim 9086--- call sign_define("mySign", { 9087--- \ "text" : "=>", 9088--- \ "texthl" : "Error", 9089--- \ "linehl" : "Search"}) 9090--- call sign_define([ 9091--- \ {'name' : 'sign1', 9092--- \ 'text' : '=>'}, 9093--- \ {'name' : 'sign2', 9094--- \ 'text' : '!!'} 9095--- \ ]) 9096--- < 9097--- 9098--- @overload fun(list: vim.fn.sign_define.dict[]): ((0|-1)[]) 9099--- @param name string 9100--- @param dict? vim.fn.sign_define.dict 9101--- @return 0|-1 9102function vim . fn . sign_define ( name , dict ) end 9103 9104--- Get a list of defined signs and their attributes. 9105--- This is similar to the |:sign-list| command. 9106--- 9107--- If the {name} is not supplied, then a list of all the defined 9108--- signs is returned. Otherwise the attribute of the specified 9109--- sign is returned. 9110--- 9111--- Each list item in the returned value is a dictionary with the 9112--- following entries: 9113--- icon full path to the bitmap file of the sign 9114--- linehl highlight group used for the whole line the 9115--- sign is placed in; not present if not set. 9116--- name name of the sign 9117--- priority default priority value of the sign 9118--- numhl highlight group used for the line number where 9119--- the sign is placed; not present if not set. 9120--- text text that is displayed when there is no icon 9121--- or the GUI is not being used. 9122--- texthl highlight group used for the text item; not 9123--- present if not set. 9124--- culhl highlight group used for the text item when 9125--- the cursor is on the same line as the sign and 9126--- 'cursorline' is enabled; not present if not 9127--- set. 9128--- 9129--- Returns an empty List if there are no signs and when {name} is 9130--- not found. 9131--- 9132--- Examples: >vim 9133--- " Get a list of all the defined signs 9134--- echo sign_getdefined() 9135--- 9136--- " Get the attribute of the sign named mySign 9137--- echo sign_getdefined("mySign") 9138--- < 9139--- 9140--- @param name? string 9141--- @return vim.fn.sign_getdefined.ret.item[] 9142function vim . fn . sign_getdefined ( name ) end 9143 9144--- Return a list of signs placed in a buffer or all the buffers. 9145--- This is similar to the |:sign-place-list| command. 9146--- 9147--- If the optional buffer name {buf} is specified, then only the 9148--- list of signs placed in that buffer is returned. For the use 9149--- of {buf}, see |bufname()|. The optional {dict} can contain 9150--- the following entries: 9151--- group select only signs in this group 9152--- id select sign with this identifier 9153--- lnum select signs placed in this line. For the use 9154--- of {lnum}, see |line()|. 9155--- If {group} is "*", then signs in all the groups including the 9156--- global group are returned. If {group} is not supplied or is 9157--- an empty string, then only signs in the global group are 9158--- returned. If no arguments are supplied, then signs in the 9159--- global group placed in all the buffers are returned. 9160--- See |sign-group|. 9161--- 9162--- Each list item in the returned value is a dictionary with the 9163--- following entries: 9164--- bufnr number of the buffer with the sign 9165--- signs list of signs placed in {bufnr}. Each list 9166--- item is a dictionary with the below listed 9167--- entries 9168--- 9169--- The dictionary for each sign contains the following entries: 9170--- group sign group. Set to '' for the global group. 9171--- id identifier of the sign 9172--- lnum line number where the sign is placed 9173--- name name of the defined sign 9174--- priority sign priority 9175--- 9176--- The returned signs in a buffer are ordered by their line 9177--- number and priority. 9178--- 9179--- Returns an empty list on failure or if there are no placed 9180--- signs. 9181--- 9182--- Examples: >vim 9183--- " Get a List of signs placed in eval.c in the 9184--- " global group 9185--- echo sign_getplaced("eval.c") 9186--- 9187--- " Get a List of signs in group 'g1' placed in eval.c 9188--- echo sign_getplaced("eval.c", {'group' : 'g1'}) 9189--- 9190--- " Get a List of signs placed at line 10 in eval.c 9191--- echo sign_getplaced("eval.c", {'lnum' : 10}) 9192--- 9193--- " Get sign with identifier 10 placed in a.py 9194--- echo sign_getplaced("a.py", {'id' : 10}) 9195--- 9196--- " Get sign with id 20 in group 'g1' placed in a.py 9197--- echo sign_getplaced("a.py", {'group' : 'g1', 9198--- \ 'id' : 20}) 9199--- 9200--- " Get a List of all the placed signs 9201--- echo sign_getplaced() 9202--- < 9203--- 9204--- @param buf? integer|string 9205--- @param dict? vim.fn.sign_getplaced.dict 9206--- @return vim.fn.sign_getplaced.ret.item[] 9207function vim . fn . sign_getplaced ( buf , dict ) end 9208 9209--- Open the buffer {buf} or jump to the window that contains 9210--- {buf} and position the cursor at sign {id} in group {group}. 9211--- This is similar to the |:sign-jump| command. 9212--- 9213--- If {group} is an empty string, then the global group is used. 9214--- For the use of {buf}, see |bufname()|. 9215--- 9216--- Returns the line number of the sign. Returns -1 if the 9217--- arguments are invalid. 9218--- 9219--- Example: >vim 9220--- " Jump to sign 10 in the current buffer 9221--- call sign_jump(10, '', '') 9222--- < 9223--- 9224--- @param id integer 9225--- @param group string 9226--- @param buf integer|string 9227--- @return integer 9228function vim . fn . sign_jump ( id , group , buf ) end 9229 9230--- Place the sign defined as {name} at line {lnum} in file or 9231--- buffer {buf} and assign {id} and {group} to sign. This is 9232--- similar to the |:sign-place| command. 9233--- 9234--- If the sign identifier {id} is zero, then a new identifier is 9235--- allocated. Otherwise the specified number is used. {group} 9236--- is the sign group name. To use the global sign group, use an 9237--- empty string. {group} functions as a namespace for {id}, thus 9238--- two groups can use the same IDs. Refer to |sign-identifier| 9239--- and |sign-group| for more information. 9240--- 9241--- {name} refers to a defined sign. 9242--- {buf} refers to a buffer name or number. For the accepted 9243--- values, see |bufname()|. 9244--- 9245--- The optional {dict} argument supports the following entries: 9246--- lnum line number in the file or buffer 9247--- {buf} where the sign is to be placed. 9248--- For the accepted values, see |line()|. 9249--- priority priority of the sign. See 9250--- |sign-priority| for more information. 9251--- 9252--- If the optional {dict} is not specified, then it modifies the 9253--- placed sign {id} in group {group} to use the defined sign 9254--- {name}. 9255--- 9256--- Returns the sign identifier on success and -1 on failure. 9257--- 9258--- Examples: >vim 9259--- " Place a sign named sign1 with id 5 at line 20 in 9260--- " buffer json.c 9261--- call sign_place(5, '', 'sign1', 'json.c', 9262--- \ {'lnum' : 20}) 9263--- 9264--- " Updates sign 5 in buffer json.c to use sign2 9265--- call sign_place(5, '', 'sign2', 'json.c') 9266--- 9267--- " Place a sign named sign3 at line 30 in 9268--- " buffer json.c with a new identifier 9269--- let id = sign_place(0, '', 'sign3', 'json.c', 9270--- \ {'lnum' : 30}) 9271--- 9272--- " Place a sign named sign4 with id 10 in group 'g3' 9273--- " at line 40 in buffer json.c with priority 90 9274--- call sign_place(10, 'g3', 'sign4', 'json.c', 9275--- \ {'lnum' : 40, 'priority' : 90}) 9276--- < 9277--- 9278--- @param id integer 9279--- @param group string 9280--- @param name string 9281--- @param buf integer|string 9282--- @param dict? vim.fn.sign_place.dict 9283--- @return integer 9284function vim . fn . sign_place ( id , group , name , buf , dict ) end 9285 9286--- Place one or more signs. This is similar to the 9287--- |sign_place()| function. The {list} argument specifies the 9288--- List of signs to place. Each list item is a dict with the 9289--- following sign attributes: 9290--- buffer Buffer name or number. For the accepted 9291--- values, see |bufname()|. 9292--- group Sign group. {group} functions as a namespace 9293--- for {id}, thus two groups can use the same 9294--- IDs. If not specified or set to an empty 9295--- string, then the global group is used. See 9296--- |sign-group| for more information. 9297--- id Sign identifier. If not specified or zero, 9298--- then a new unique identifier is allocated. 9299--- Otherwise the specified number is used. See 9300--- |sign-identifier| for more information. 9301--- lnum Line number in the buffer where the sign is to 9302--- be placed. For the accepted values, see 9303--- |line()|. 9304--- name Name of the sign to place. See |sign_define()| 9305--- for more information. 9306--- priority Priority of the sign. When multiple signs are 9307--- placed on a line, the sign with the highest 9308--- priority is used. If not specified, the 9309--- default value of 10 is used, unless specified 9310--- otherwise by the sign definition. See 9311--- |sign-priority| for more information. 9312--- 9313--- If {id} refers to an existing sign, then the existing sign is 9314--- modified to use the specified {name} and/or {priority}. 9315--- 9316--- Returns a List of sign identifiers. If failed to place a 9317--- sign, the corresponding list item is set to -1. 9318--- 9319--- Examples: >vim 9320--- " Place sign s1 with id 5 at line 20 and id 10 at line 9321--- " 30 in buffer a.c 9322--- let [n1, n2] = sign_placelist([ 9323--- \ {'id' : 5, 9324--- \ 'name' : 's1', 9325--- \ 'buffer' : 'a.c', 9326--- \ 'lnum' : 20}, 9327--- \ {'id' : 10, 9328--- \ 'name' : 's1', 9329--- \ 'buffer' : 'a.c', 9330--- \ 'lnum' : 30} 9331--- \ ]) 9332--- 9333--- " Place sign s1 in buffer a.c at line 40 and 50 9334--- " with auto-generated identifiers 9335--- let [n1, n2] = sign_placelist([ 9336--- \ {'name' : 's1', 9337--- \ 'buffer' : 'a.c', 9338--- \ 'lnum' : 40}, 9339--- \ {'name' : 's1', 9340--- \ 'buffer' : 'a.c', 9341--- \ 'lnum' : 50} 9342--- \ ]) 9343--- < 9344--- 9345--- @param list vim.fn.sign_placelist.list.item[] 9346--- @return integer[] 9347function vim . fn . sign_placelist ( list ) end 9348 9349--- Deletes a previously defined sign {name}. This is similar to 9350--- the |:sign-undefine| command. If {name} is not supplied, then 9351--- deletes all the defined signs. 9352--- 9353--- The one argument {list} can be used to undefine a list of 9354--- signs. Each list item is the name of a sign. 9355--- 9356--- Returns 0 on success and -1 on failure. For the one argument 9357--- {list} call, returns a list of values one for each undefined 9358--- sign. 9359--- 9360--- Examples: >vim 9361--- " Delete a sign named mySign 9362--- call sign_undefine("mySign") 9363--- 9364--- " Delete signs 'sign1' and 'sign2' 9365--- call sign_undefine(["sign1", "sign2"]) 9366--- 9367--- " Delete all the signs 9368--- call sign_undefine() 9369--- < 9370--- 9371--- @overload fun(list?: string[]): (integer[]) 9372--- @param name? string 9373--- @return 0|-1 9374function vim . fn . sign_undefine ( name ) end 9375 9376--- Remove a previously placed sign in one or more buffers. This 9377--- is similar to the |:sign-unplace| command. 9378--- 9379--- {group} is the sign group name. To use the global sign group, 9380--- use an empty string. If {group} is set to "*", then all the 9381--- groups including the global group are used. 9382--- The signs in {group} are selected based on the entries in 9383--- {dict}. The following optional entries in {dict} are 9384--- supported: 9385--- buffer buffer name or number. See |bufname()|. 9386--- id sign identifier 9387--- If {dict} is not supplied, then all the signs in {group} are 9388--- removed. 9389--- 9390--- Returns 0 on success and -1 on failure. 9391--- 9392--- Examples: >vim 9393--- " Remove sign 10 from buffer a.vim 9394--- call sign_unplace('', {'buffer' : "a.vim", 'id' : 10}) 9395--- 9396--- " Remove sign 20 in group 'g1' from buffer 3 9397--- call sign_unplace('g1', {'buffer' : 3, 'id' : 20}) 9398--- 9399--- " Remove all the signs in group 'g2' from buffer 10 9400--- call sign_unplace('g2', {'buffer' : 10}) 9401--- 9402--- " Remove sign 30 in group 'g3' from all the buffers 9403--- call sign_unplace('g3', {'id' : 30}) 9404--- 9405--- " Remove all the signs placed in buffer 5 9406--- call sign_unplace('*', {'buffer' : 5}) 9407--- 9408--- " Remove the signs in group 'g4' from all the buffers 9409--- call sign_unplace('g4') 9410--- 9411--- " Remove sign 40 from all the buffers 9412--- call sign_unplace('*', {'id' : 40}) 9413--- 9414--- " Remove all the placed signs from all the buffers 9415--- call sign_unplace('*') 9416--- < 9417--- 9418--- @param group string 9419--- @param dict? vim.fn.sign_unplace.dict 9420--- @return 0|-1 9421function vim . fn . sign_unplace ( group , dict ) end 9422 9423--- Remove previously placed signs from one or more buffers. This 9424--- is similar to the |sign_unplace()| function. 9425--- 9426--- The {list} argument specifies the List of signs to remove. 9427--- Each list item is a dict with the following sign attributes: 9428--- buffer buffer name or number. For the accepted 9429--- values, see |bufname()|. If not specified, 9430--- then the specified sign is removed from all 9431--- the buffers. 9432--- group sign group name. If not specified or set to an 9433--- empty string, then the global sign group is 9434--- used. If set to "*", then all the groups 9435--- including the global group are used. 9436--- id sign identifier. If not specified, then all 9437--- the signs in the specified group are removed. 9438--- 9439--- Returns a List where an entry is set to 0 if the corresponding 9440--- sign was successfully removed or -1 on failure. 9441--- 9442--- Example: >vim 9443--- " Remove sign with id 10 from buffer a.vim and sign 9444--- " with id 20 from buffer b.vim 9445--- call sign_unplacelist([ 9446--- \ {'id' : 10, 'buffer' : "a.vim"}, 9447--- \ {'id' : 20, 'buffer' : 'b.vim'}, 9448--- \ ]) 9449--- < 9450--- 9451--- @param list vim.fn.sign_unplacelist.list.item 9452--- @return (0|-1)[] 9453function vim . fn . sign_unplacelist ( list ) end 9454 9455--- Lua: Prefer |vim.fs.normalize()|; `~`/$VAR expansion and leading `./` or trailing `/` handling differ. 9456--- 9457--- Simplify the file name as much as possible without changing 9458--- the meaning. Shortcuts (on MS-Windows) or symbolic links (on 9459--- Unix) are not resolved. If the first path component in 9460--- {filename} designates the current directory, this will be 9461--- valid for the result as well. A trailing path separator is 9462--- not removed either. On Unix "//path" is unchanged, but 9463--- "///path" is simplified to "/path" (this follows the Posix 9464--- standard). 9465--- Example: >vim 9466--- simplify("./dir/.././/file/") == "./file/" 9467--- <Note: The combination "dir/.." is only removed if "dir" is 9468--- a searchable directory or does not exist. On Unix, it is also 9469--- removed when "dir" is a symbolic link within the same 9470--- directory. In order to resolve all the involved symbolic 9471--- links before simplifying the path name, use |resolve()|. 9472--- 9473--- @param filename string 9474--- @return string 9475function vim . fn . simplify ( filename ) end 9476 9477--- Lua: Prefer |math.sin()|. 9478--- 9479--- Return the sine of {expr}, measured in radians, as a |Float|. 9480--- {expr} must evaluate to a |Float| or a |Number|. 9481--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 9482--- Examples: >vim 9483--- echo sin(100) 9484--- < -0.506366 >vim 9485--- echo sin(-4.01) 9486--- < 0.763301 9487--- 9488--- @param expr number 9489--- @return number 9490function vim . fn . sin ( expr ) end 9491 9492--- Lua: Prefer |math.sinh()|. 9493--- 9494--- Return the hyperbolic sine of {expr} as a |Float| in the range 9495--- [-inf, inf]. 9496--- {expr} must evaluate to a |Float| or a |Number|. 9497--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 9498--- Examples: >vim 9499--- echo sinh(0.5) 9500--- < 0.521095 >vim 9501--- echo sinh(-0.9) 9502--- < -1.026517 9503--- 9504--- @param expr number 9505--- @return any 9506function vim . fn . sinh ( expr ) end 9507 9508--- Similar to using a |slice| "expr[start : end]", but "end" is 9509--- used exclusive. And for a string the indexes are used as 9510--- character indexes instead of byte indexes. 9511--- Also, composing characters are treated as a part of the 9512--- preceding base character. 9513--- When {end} is omitted the slice continues to the last item. 9514--- When {end} is -1 the last item is omitted. 9515--- Returns an empty value if {start} or {end} are invalid. 9516--- 9517--- @param expr any 9518--- @param start integer 9519--- @param end_? integer 9520--- @return any 9521function vim . fn . slice ( expr , start , end_ ) end 9522 9523--- Connect a socket to an address. If {mode} is "pipe" then 9524--- {address} should be the path of a local domain socket (on 9525--- unix) or named pipe (on Windows). If {mode} is "tcp" then 9526--- {address} should be of the form "host:port" where the host 9527--- should be an ip address or host name, and port the port 9528--- number. 9529--- 9530--- For "pipe" mode, see |luv-pipe-handle|. For "tcp" mode, see 9531--- |luv-tcp-handle|. 9532--- 9533--- Returns a |channel| ID. Close the socket with |chanclose()|. 9534--- Use |chansend()| to send data over a bytes socket, and 9535--- |rpcrequest()| and |rpcnotify()| to communicate with a RPC 9536--- socket. 9537--- 9538--- {opts} is an optional dictionary with these keys: 9539--- |on_data| : callback invoked when data was read from socket 9540--- data_buffered : read socket data in |channel-buffered| mode. 9541--- rpc : If set, |msgpack-rpc| will be used to communicate 9542--- over the socket. 9543--- Returns: 9544--- - The channel ID on success (greater than zero) 9545--- - 0 on invalid arguments or connection failure. 9546--- 9547--- @param mode string 9548--- @param address string 9549--- @param opts? table 9550--- @return any 9551function vim . fn . sockconnect ( mode , address , opts ) end 9552 9553--- Lua: Prefer |table.sort()| with a custom comparator; it is not stable and Vim's `i`/`l`/`n`/`N`/`f` modes differ. 9554--- 9555--- Sort the items in {list} in-place. Returns {list}. 9556--- 9557--- If you want a list to remain unmodified make a copy first: >vim 9558--- let sortedlist = sort(copy(mylist)) 9559--- 9560--- <When {how} is omitted or is a string, then sort() uses the 9561--- string representation of each item to sort on. Numbers sort 9562--- after Strings, |Lists| after Numbers. For sorting text in the 9563--- current buffer use |:sort|. 9564--- 9565--- When {how} is given and it is 'i' then case is ignored. 9566--- For backwards compatibility, the value one can be used to 9567--- ignore case. Zero means to not ignore case. 9568--- 9569--- When {how} is given and it is 'l' then the current collation 9570--- locale is used for ordering. Implementation details: 9571--- strcoll() is used to compare strings. See |:language| to check 9572--- or set the collation locale. |v:collate| can also be used to 9573--- check the current locale. Sorting using the locale typically 9574--- ignores case. Example: >vim 9575--- " ö is sorted similarly to o with English locale. 9576--- language collate en_US.UTF8 9577--- echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 9578--- < ['n', 'o', 'O', 'ö', 'p', 'z'] ~ 9579--- >vim 9580--- " ö is sorted after z with Swedish locale. 9581--- language collate sv_SE.UTF8 9582--- echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 9583--- < ['n', 'o', 'O', 'p', 'z', 'ö'] ~ 9584--- This does not work properly on Mac. 9585--- 9586--- When {how} is given and it is 'n' then all items will be 9587--- sorted numerical (Implementation detail: this uses the 9588--- strtod() function to parse numbers, Strings, Lists, Dicts and 9589--- Funcrefs will be considered as being 0). 9590--- 9591--- When {how} is given and it is 'N' then all items will be 9592--- sorted numerical. This is like 'n' but a string containing 9593--- digits will be used as the number they represent. 9594--- 9595--- When {how} is given and it is 'f' then all items will be 9596--- sorted numerical. All values must be a Number or a Float. 9597--- 9598--- When {how} is a |Funcref| or a function name, this function 9599--- is called to compare items. The function is invoked with two 9600--- items as argument and must return zero if they are equal, 1 or 9601--- bigger if the first one sorts after the second one, -1 or 9602--- smaller if the first one sorts before the second one. 9603--- 9604--- {dict} is for functions with the "dict" attribute. It will be 9605--- used to set the local variable "self". |Dictionary-function| 9606--- 9607--- The sort is stable, items which compare equal (as number or as 9608--- string) will keep their relative position. E.g., when sorting 9609--- on numbers, text strings will sort next to each other, in the 9610--- same order as they were originally. 9611--- 9612--- 9613--- Example: >vim 9614--- func MyCompare(i1, i2) 9615--- return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 9616--- endfunc 9617--- eval mylist->sort("MyCompare") 9618--- <A shorter compare version for this specific simple case, which 9619--- ignores overflow: >vim 9620--- func MyCompare(i1, i2) 9621--- return a:i1 - a:i2 9622--- endfunc 9623--- <For a simple expression you can use a lambda: >vim 9624--- eval mylist->sort({i1, i2 -> i1 - i2}) 9625--- < 9626--- 9627--- @generic T 9628--- @param list T[] 9629--- @param how? string|function 9630--- @param dict? any 9631--- @return T[] 9632function vim . fn . sort ( list , how , dict ) end 9633 9634--- Return the sound-folded equivalent of {word}. Uses the first 9635--- language in 'spelllang' for the current window that supports 9636--- soundfolding. 'spell' must be set. When no sound folding is 9637--- possible the {word} is returned unmodified. 9638--- This can be used for making spelling suggestions. Note that 9639--- the method can be quite slow. 9640--- 9641--- @param word string 9642--- @return string 9643function vim . fn . soundfold ( word ) end 9644 9645--- Lua: Prefer |vim.spell.check()| for string input; it returns all matches with positions, not just the first one or cursor-moving behavior. 9646--- 9647--- Without argument: The result is the badly spelled word under 9648--- or after the cursor. The cursor is moved to the start of the 9649--- bad word. When no bad word is found in the cursor line the 9650--- result is an empty string and the cursor doesn't move. 9651--- 9652--- With argument: The result is the first word in {sentence} that 9653--- is badly spelled. If there are no spelling mistakes the 9654--- result is an empty string. 9655--- 9656--- The return value is a list with two items: 9657--- - The badly spelled word or an empty string. 9658--- - The type of the spelling error: 9659--- "bad" spelling mistake 9660--- "rare" rare word 9661--- "local" word only valid in another region 9662--- "caps" word should start with Capital 9663--- Example: >vim 9664--- echo spellbadword("the quik brown fox") 9665--- < ['quik', 'bad'] ~ 9666--- 9667--- The spelling information for the current window and the value 9668--- of 'spelllang' are used. 9669--- 9670--- @param sentence? string 9671--- @return any 9672function vim . fn . spellbadword ( sentence ) end 9673 9674--- Return a |List| with spelling suggestions to replace {word}. 9675--- When {max} is given up to this number of suggestions are 9676--- returned. Otherwise up to 25 suggestions are returned. 9677--- 9678--- When the {capital} argument is given and it's non-zero only 9679--- suggestions with a leading capital will be given. Use this 9680--- after a match with 'spellcapcheck'. 9681--- 9682--- {word} can be a badly spelled word followed by other text. 9683--- This allows for joining two words that were split. The 9684--- suggestions also include the following text, thus you can 9685--- replace a line. 9686--- 9687--- {word} may also be a good word. Similar words will then be 9688--- returned. {word} itself is not included in the suggestions, 9689--- although it may appear capitalized. 9690--- 9691--- The spelling information for the current window is used. The 9692--- values of 'spelllang' and 'spellsuggest' are used. 9693--- 9694--- @param word string 9695--- @param max? integer 9696--- @param capital? boolean 9697--- @return string[] 9698function vim . fn . spellsuggest ( word , max , capital ) end 9699 9700--- Lua: Prefer |vim.split()|. 9701--- 9702--- Make a |List| out of {string}. When {pattern} is omitted or 9703--- empty each white space separated sequence of characters 9704--- becomes an item. 9705--- Otherwise the string is split where {pattern} matches, 9706--- removing the matched characters. 'ignorecase' is not used 9707--- here, add \c to ignore case. |/\c| 9708--- When the first or last item is empty it is omitted, unless the 9709--- {keepempty} argument is given and it's non-zero. 9710--- Other empty items are kept when {pattern} matches at least one 9711--- character or when {keepempty} is non-zero. 9712--- Example: >vim 9713--- let words = split(getline('.'), '\W\+') 9714--- <To split a string in individual characters: >vim 9715--- for c in split(mystring, '\zs') | endfor 9716--- <If you want to keep the separator you can also use '\zs' at 9717--- the end of the pattern: >vim 9718--- echo split('abc:def:ghi', ':\zs') 9719--- < > 9720--- ['abc:', 'def:', 'ghi'] 9721--- < 9722--- Splitting a table where the first element can be empty: >vim 9723--- let items = split(line, ':', 1) 9724--- <The opposite function is |join()|. 9725--- 9726--- @param string string 9727--- @param pattern? string 9728--- @param keepempty? boolean 9729--- @return string[] 9730function vim . fn . split ( string , pattern , keepempty ) end 9731 9732--- Lua: Prefer |math.sqrt()|. 9733--- 9734--- Return the non-negative square root of Float {expr} as a 9735--- |Float|. 9736--- {expr} must evaluate to a |Float| or a |Number|. When {expr} 9737--- is negative the result is NaN (Not a Number). Returns 0.0 if 9738--- {expr} is not a |Float| or a |Number|. 9739--- Examples: >vim 9740--- echo sqrt(100) 9741--- < 10.0 >vim 9742--- echo sqrt(-4.01) 9743--- < str2float("nan") 9744--- NaN may be different, it depends on system libraries. 9745--- 9746--- @param expr number 9747--- @return any 9748function vim . fn . sqrt ( expr ) end 9749 9750--- Lua: Prefer |math.randomseed()|. 9751--- 9752--- Initialize seed used by |rand()|: 9753--- - If {expr} is not given, seed values are initialized by 9754--- reading from /dev/urandom, if possible, or using time(NULL) 9755--- a.k.a. epoch time otherwise; this only has second accuracy. 9756--- - If {expr} is given it must be a Number. It is used to 9757--- initialize the seed values. This is useful for testing or 9758--- when a predictable sequence is intended. 9759--- 9760--- Examples: >vim 9761--- let seed = srand() 9762--- let seed = srand(userinput) 9763--- echo rand(seed) 9764--- < 9765--- 9766--- @param expr? number 9767--- @return any 9768function vim . fn . srand ( expr ) end 9769 9770--- Return a string which contains characters indicating the 9771--- current state. Mostly useful in callbacks that want to do 9772--- work that may not always be safe. Roughly this works like: 9773--- - callback uses state() to check if work is safe to do. 9774--- Yes: then do it right away. 9775--- No: add to work queue and add a |SafeState| autocommand. 9776--- - When SafeState is triggered and executes your autocommand, 9777--- check with `state()` if the work can be done now, and if yes 9778--- remove it from the queue and execute. 9779--- Remove the autocommand if the queue is now empty. 9780--- Also see |mode()|. 9781--- 9782--- When {what} is given only characters in this string will be 9783--- added. E.g, this checks if the screen has scrolled: >vim 9784--- if state('s') == '' 9785--- " screen has not scrolled 9786--- < 9787--- These characters indicate the state, generally indicating that 9788--- something is busy: 9789--- m halfway a mapping, :normal command, |feedkeys()| or 9790--- stuffed command 9791--- o operator pending, e.g. after |d| 9792--- a Insert mode autocomplete active 9793--- x executing an autocommand 9794--- S not triggering SafeState, e.g. after |f| or a count 9795--- c callback invoked, including timer (repeats for 9796--- recursiveness up to "ccc") 9797--- s screen has scrolled for messages 9798--- 9799--- @param what? string 9800--- @return any 9801function vim . fn . state ( what ) end 9802 9803--- With |--headless| this opens stdin and stdout as a |channel|. 9804--- May be called only once. See |channel-stdio|. stderr is not 9805--- handled by this function, see |v:stderr|. 9806--- 9807--- Close the stdio handles with |chanclose()|. Use |chansend()| 9808--- to send data to stdout, and |rpcrequest()| and |rpcnotify()| 9809--- to communicate over RPC. 9810--- 9811--- {opts} is a dictionary with these keys: 9812--- |on_stdin| : callback invoked when stdin is written to. 9813--- on_print : callback invoked when Nvim needs to print a 9814--- message, with the message (whose type is string) 9815--- as sole argument. 9816--- stdin_buffered : read stdin in |channel-buffered| mode. 9817--- rpc : If set, |msgpack-rpc| will be used to communicate 9818--- over stdio 9819--- Returns: 9820--- - |channel-id| on success (value is always 1) 9821--- - 0 on invalid arguments 9822--- 9823--- @param opts table 9824--- @return any 9825function vim . fn . stdioopen ( opts ) end 9826 9827--- Returns |standard-path| locations of various default files and 9828--- directories. The locations are driven by |base-directories| 9829--- which you can configure via |$NVIM_APPNAME| or the `$XDG_…` 9830--- environment variables. 9831--- 9832--- {what} Type Description ~ 9833--- cache String Cache directory: arbitrary temporary 9834--- storage for plugins, etc. 9835--- config String User configuration directory. |init.vim| 9836--- is stored here. 9837--- config_dirs List Other configuration directories. 9838--- data String User data directory. 9839--- data_dirs List Other data directories. 9840--- log String Logs directory (for use by plugins too). 9841--- run String Run directory: temporary, local storage 9842--- for sockets, named pipes, etc. 9843--- state String Session state: storage for backupdir, 9844--- file drafts, |shada|, swap, undo, 'viewdir'. 9845--- 9846--- Example: >vim 9847--- echo stdpath("config") 9848--- < 9849--- 9850--- @overload fun(what: 'cache'|'config'|'data'|'log'|'run'|'state'): (string) 9851--- @overload fun(what: 'config_dirs'|'data_dirs'): (string[]) 9852--- @param what 'cache'|'config'|'config_dirs'|'data'|'data_dirs'|'log'|'run'|'state' 9853--- @return string|string[] 9854function vim . fn . stdpath ( what ) end 9855 9856--- Lua: Prefer |tonumber()| for simple numbers; quoted digits, hex forms, and trailing text differ. 9857--- 9858--- Convert String {string} to a Float. This mostly works the 9859--- same as when using a floating point number in an expression, 9860--- see |floating-point-format|. But it's a bit more permissive. 9861--- E.g., "1e40" is accepted, while in an expression you need to 9862--- write "1.0e40". The hexadecimal form "0x123" is also 9863--- accepted, but not others, like binary or octal. 9864--- When {quoted} is present and non-zero then embedded single 9865--- quotes before the dot are ignored, thus "1'000.0" is a 9866--- thousand. 9867--- Text after the number is silently ignored. 9868--- The decimal point is always '.', no matter what the locale is 9869--- set to. A comma ends the number: "12,345.67" is converted to 9870--- 12.0. You can strip out thousands separators with 9871--- |substitute()|: >vim 9872--- let f = str2float(substitute(text, ',', '', 'g')) 9873--- < 9874--- Returns 0.0 if the conversion fails. 9875--- 9876--- @param string string 9877--- @param quoted? boolean 9878--- @return any 9879function vim . fn . str2float ( string , quoted ) end 9880 9881--- Return a list containing the number values which represent 9882--- each character in String {string}. Examples: >vim 9883--- echo str2list(" ") " returns [32] 9884--- echo str2list("ABC") " returns [65, 66, 67] 9885--- <|list2str()| does the opposite. 9886--- 9887--- UTF-8 encoding is always used, {utf8} option has no effect, 9888--- and exists only for backwards-compatibility. 9889--- With UTF-8 composing characters are handled properly: >vim 9890--- echo str2list("á") " returns [97, 769] 9891--- < 9892--- 9893--- @param string string 9894--- @param utf8? boolean 9895--- @return any 9896function vim . fn . str2list ( string , utf8 ) end 9897 9898--- Lua: Prefer |tonumber()| for simple numbers; quoted digits, base prefixes, and trailing text differ. 9899--- 9900--- Convert string {string} to a number. 9901--- {base} is the conversion base, it can be 2, 8, 10 or 16. 9902--- When {quoted} is present and non-zero then embedded single 9903--- quotes are ignored, thus "1'000'000" is a million. 9904--- 9905--- When {base} is omitted base 10 is used. This also means that 9906--- a leading zero doesn't cause octal conversion to be used, as 9907--- with the default String to Number conversion. Example: >vim 9908--- let nr = str2nr('0123') 9909--- < 9910--- When {base} is 16 a leading "0x" or "0X" is ignored. With a 9911--- different base the result will be zero. Similarly, when 9912--- {base} is 8 a leading "0", "0o" or "0O" is ignored, and when 9913--- {base} is 2 a leading "0b" or "0B" is ignored. 9914--- Text after the number is silently ignored. 9915--- 9916--- Returns 0 if {string} is empty or on error. 9917--- 9918--- @param string string 9919--- @param base? integer 9920--- @return any 9921function vim . fn . str2nr ( string , base ) end 9922 9923--- Returns the number of characters in String {string}, ignoring 9924--- composing characters. Returns 0 on error or empty {string}. 9925--- 9926--- |strchars()| can count the number of characters, counting 9927--- composing characters separately. 9928--- 9929--- Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 9930--- 9931--- @param string string 9932--- @return integer 9933function vim . fn . strcharlen ( string ) end 9934 9935--- Like |strpart()| but using character index and length instead 9936--- of byte index and length. 9937--- When {skipcc} is omitted or zero, composing characters are 9938--- counted separately. 9939--- When {skipcc} set to 1, composing characters are treated as a 9940--- part of the preceding base character, similar to |slice()|. 9941--- When a character index is used where a character does not 9942--- exist it is omitted and counted as one character. For 9943--- example: >vim 9944--- echo strcharpart('abc', -1, 2) 9945--- <results in 'a'. 9946--- 9947--- Returns an empty string on error. 9948--- 9949--- @param src string 9950--- @param start integer 9951--- @param len? integer 9952--- @param skipcc? 0|1|boolean 9953--- @return string 9954function vim . fn . strcharpart ( src , start , len , skipcc ) end 9955 9956--- Lua: Prefer |vim.str_utfindex()| for codepoint counts; `skipcc` handling differs. 9957--- 9958--- Returns the number of characters in String {string}. 9959--- When {skipcc} is omitted or zero, composing characters are 9960--- counted separately. 9961--- When {skipcc} set to 1, composing characters are ignored. 9962--- |strcharlen()| always does this. 9963--- 9964--- Returns zero on error. 9965--- 9966--- Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 9967--- 9968--- {skipcc} is only available after 7.4.755. For backward 9969--- compatibility, you can define a wrapper function: >vim 9970--- if has("patch-7.4.755") 9971--- function s:strchars(str, skipcc) 9972--- return strchars(a:str, a:skipcc) 9973--- endfunction 9974--- else 9975--- function s:strchars(str, skipcc) 9976--- if a:skipcc 9977--- return strlen(substitute(a:str, ".", "x", "g")) 9978--- else 9979--- return strchars(a:str) 9980--- endif 9981--- endfunction 9982--- endif 9983--- < 9984--- 9985--- @param string string 9986--- @param skipcc? 0|1|boolean 9987--- @return integer 9988function vim . fn . strchars ( string , skipcc ) end 9989 9990--- Lua: Prefer |nvim_strwidth()| when `{col}` is 0; Tab expansion and window-option semantics differ. 9991--- 9992--- Returns the number of display cells String {string} occupies 9993--- on the screen when it starts at {col} (first column is zero). 9994--- Returns zero on error. 9995--- 9996--- When {col} is omitted zero is used. Otherwise it is the screen 9997--- column where to start. This matters for Tab characters. 9998--- The option settings of the current window are used. This 9999--- matters for anything that's displayed differently, such as 10000--- 'tabstop' and 'display'. 10001--- 10002--- When {string} contains characters with East Asian Width Class 10003--- Ambiguous, this function's return value depends on 10004--- 'ambiwidth'. 10005--- 10006--- Also see |strlen()|, |strwidth()| and |strchars()|. 10007--- 10008--- @param string string 10009--- @param col? integer 10010--- @return integer 10011function vim . fn . strdisplaywidth ( string , col ) end 10012 10013--- Lua: Prefer |os.date()|. 10014--- 10015--- Formats a date and time String specified by {format}. The 10016--- given {time} is used, or the current time if no time is given. 10017--- The {format} depends on your system, this is not portable! 10018--- See the manual page of the C function strftime() for the 10019--- format. The maximum length of the result is 80 characters. 10020--- See also |localtime()|, |getftime()| and |strptime()|. 10021--- The language can be changed with the |:language| command. 10022--- Examples: >vim 10023--- echo strftime("%c") " Sun Apr 27 11:49:23 1997 10024--- echo strftime("%Y %b %d %X") " 1997 Apr 27 11:53:25 10025--- echo strftime("%y%m%d %T") " 970427 11:53:55 10026--- echo strftime("%H:%M") " 11:55 10027--- echo strftime("%c", getftime("file.c")) 10028--- " Show mod time of file.c. 10029--- < 10030--- 10031--- @param format string 10032--- @param time? number 10033--- @return string 10034function vim . fn . strftime ( format , time ) end 10035 10036--- Get a Number corresponding to the character at {index} in 10037--- {str}. This uses a zero-based character index, not a byte 10038--- index. Composing characters are considered separate 10039--- characters here. Use |nr2char()| to convert the Number to a 10040--- String. 10041--- Returns -1 if {index} is invalid. 10042--- Also see |strcharpart()| and |strchars()|. 10043--- 10044--- @param str string 10045--- @param index integer 10046--- @return integer 10047function vim . fn . strgetchar ( str , index ) end 10048 10049--- Lua: Prefer |string.find()| with `plain = true` and `start + 1`, then subtract 1; missing matches return nil instead of -1. 10050--- 10051--- Returns the byte index of the first occurrence of {needle} 10052--- in {haystack}. 10053--- If {start} is specified, the search starts at index {start}. 10054--- This can be used to find a second match: >vim 10055--- let colon1 = stridx(line, ":") 10056--- let colon2 = stridx(line, ":", colon1 + 1) 10057--- <The search is done case-sensitive. 10058--- For pattern searches use |match()|. 10059--- -1 is returned if the {needle} does not occur in {haystack}. 10060--- See also |strridx()|. 10061--- Examples: >vim 10062--- echo stridx("An Example", "Example") " 3 10063--- echo stridx("Starting point", "Start") " 0 10064--- echo stridx("Starting point", "start") " -1 10065--- < *strstr()* *strchr()* 10066--- stridx() works similar to the C function strstr(). When used 10067--- with a single character it works similar to strchr(). 10068--- 10069--- @param haystack string 10070--- @param needle string 10071--- @param start? integer 10072--- @return integer 10073function vim . fn . stridx ( haystack , needle , start ) end 10074 10075--- Lua: Prefer |vim.inspect()| for tables, or |tostring()| for scalars. 10076--- 10077--- Converts {expr} to a String. If {expr} is a Number, Float, 10078--- String, Blob or a composition of them, the result can be 10079--- parsed back with |eval()|. 10080--- 10081--- {expr} type result ~ 10082--- String `'string'` 10083--- Number 123 10084--- Float 123.123456 or 1.123456e8 or 10085--- `str2float('inf')` 10086--- Funcref `function('name')` 10087--- Blob 0z00112233.44556677.8899 10088--- List [item, item] 10089--- Dictionary `{key: value, key: value}` 10090--- 10091--- Note: in String values the ' character is doubled. 10092--- Also see |strtrans()|. 10093--- 10094--- Note: Output format is mostly compatible with YAML, except for 10095--- infinite and NaN floating-point values representations which 10096--- use |str2float()|. Strings are also dumped literally, only 10097--- single quote is escaped, which does not allow using YAML for 10098--- parsing back binary strings. |eval()| should always work for 10099--- strings and floats though, and this is the only official 10100--- method. Use |msgpackdump()| or |json_encode()| if you need to 10101--- share data with other applications. 10102--- 10103--- @param expr any 10104--- @return string 10105function vim . fn . string ( expr ) end 10106 10107--- Lua: Prefer |string.len()|. 10108--- 10109--- Returns the length of String {string} in bytes. 10110--- If the argument is a Number it is first converted to a String. 10111--- For other types an error is given and zero is returned. 10112--- If you want to count the number of multibyte characters use 10113--- |strchars()|. 10114--- Also see |len()|, |strdisplaywidth()| and |strwidth()|. 10115--- 10116--- @param string string 10117--- @return integer 10118function vim . fn . strlen ( string ) end 10119 10120--- Lua: Prefer |string.sub()| for byte slices; negative `start` and the `chars` flag differ. 10121--- 10122--- Gets a substring from {src}, starting from byte {start}, with 10123--- byte length {len}. Returns empty string on error. 10124--- 10125--- When {chars} is present and TRUE then {len} is the number of 10126--- characters positions (composing characters are not counted 10127--- separately, thus "1" means one base character and any 10128--- following composing characters). 10129--- 10130--- To count {start} as characters instead of bytes use 10131--- |strcharpart()|. 10132--- 10133--- When bytes are selected which do not exist, this doesn't 10134--- result in an error, the bytes are simply omitted. 10135--- If {len} is missing, the copy continues from {start} till the 10136--- end of the {src}. >vim 10137--- echo strpart("abcdefg", 3, 2) " returns 'de' 10138--- echo strpart("abcdefg", -2, 4) " returns 'ab' 10139--- echo strpart("abcdefg", 5, 4) " returns 'fg' 10140--- echo strpart("abcdefg", 3) " returns 'defg' 10141--- 10142--- <Note: To get the first character, {start} must be 0. For 10143--- example, to get the character under the cursor: >vim 10144--- strpart(getline("."), col(".") - 1, 1, v:true) 10145--- < 10146--- 10147--- @param src string 10148--- @param start integer 10149--- @param len? integer 10150--- @param chars? 0|1 10151--- @return string 10152function vim . fn . strpart ( src , start , len , chars ) end 10153 10154--- Parses a date/time string and returns a unix timestamp. 10155--- {timestring} must match the format specified in {format}. 10156--- 10157--- The {format} depends on your system, this is not portable! 10158--- See the strptime() manpage for the format. Especially avoid 10159--- "%c". The value of $TZ also matters. 10160--- 10161--- If the {timestring} cannot be parsed with {format} zero is 10162--- returned. If you do not know the format of {timestring} you 10163--- can try different {format} values until you get a non-zero 10164--- result. 10165--- 10166--- See also |strftime()|. 10167--- Examples: >vim 10168--- echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23") 10169--- < 862156163 >vim 10170--- echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55")) 10171--- < Sun Apr 27 11:53:55 1997 >vim 10172--- echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600) 10173--- < Sun Apr 27 12:53:55 1997 10174--- 10175--- @param format string 10176--- @param timestring string 10177--- @return integer 10178function vim . fn . strptime ( format , timestring ) end 10179 10180--- Lua: Prefer |string.find()| in a loop with `plain = true`, then subtract 1; empty-needle and missing-match semantics differ. 10181--- 10182--- Returns the byte index of the last occurrence of {needle} 10183--- in {haystack}. 10184--- When {start} is specified, matches beyond this index are 10185--- ignored. This can be used to find a match before a previous 10186--- match: >vim 10187--- let lastcomma = strridx(line, ",") 10188--- let comma2 = strridx(line, ",", lastcomma - 1) 10189--- <The search is done case-sensitive. 10190--- For pattern searches use |match()|. 10191--- -1 is returned if the {needle} does not occur in {haystack}. 10192--- If the {needle} is empty the length of {haystack} is returned. 10193--- See also |stridx()|. Examples: >vim 10194--- echo strridx("an angry armadillo", "an") 3 10195--- < *strrchr()* 10196--- When used with a single character it works similar to the C 10197--- function strrchr(). 10198--- 10199--- @param haystack string 10200--- @param needle string 10201--- @param start? integer 10202--- @return integer 10203function vim . fn . strridx ( haystack , needle , start ) end 10204 10205--- Translates all unprintable characters in {string} into 10206--- printable characters, like they are shown in a 10207--- window. Example: >vim 10208--- echo strtrans(\@a) 10209--- <This displays a newline in register a as "^\@" instead of 10210--- starting a new line. 10211--- 10212--- Returns an empty string on error. 10213--- 10214--- @param string string 10215--- @return string 10216function vim . fn . strtrans ( string ) end 10217 10218--- Lua: Prefer |vim.str_utfindex()| with `"utf-16"`; `countcc = false` semantics differ. 10219--- 10220--- Returns the number of UTF-16 code units in String {string} 10221--- (after converting it to UTF-16). 10222--- 10223--- When {countcc} is TRUE, composing characters are counted 10224--- separately. 10225--- When {countcc} is omitted or FALSE, composing characters are 10226--- ignored. 10227--- 10228--- Returns zero on error. 10229--- 10230--- Also see |strlen()| and |strcharlen()|. 10231--- Examples: >vim 10232--- echo strutf16len('a') " returns 1 10233--- echo strutf16len('©') " returns 1 10234--- echo strutf16len('😊') " returns 2 10235--- echo strutf16len('ą́') " returns 1 10236--- echo strutf16len('ą́', v:true) " returns 3 10237--- < 10238--- 10239--- @param string string 10240--- @param countcc? 0|1 10241--- @return integer 10242function vim . fn . strutf16len ( string , countcc ) end 10243 10244--- Lua: Prefer |nvim_strwidth()|. 10245--- 10246--- Returns the number of display cells String {string} occupies. 10247--- A Tab character is counted as one cell, alternatively use 10248--- |strdisplaywidth()|. 10249--- When {string} contains characters with East Asian Width Class 10250--- Ambiguous, this function's return value depends on 10251--- 'ambiwidth'. 10252--- Returns zero on error. 10253--- Also see |strlen()|, |strdisplaywidth()| and |strchars()|. 10254--- 10255--- @param string string 10256--- @return integer 10257function vim . fn . strwidth ( string ) end 10258 10259--- Only for an expression in a |:substitute| command or 10260--- |substitute()| function. 10261--- Returns the {nr}th submatch of the matched text. When {nr} 10262--- is 0 the whole matched text is returned. 10263--- Note that a NL in the string can stand for a line break of a 10264--- multi-line match or a NUL character in the text. 10265--- Also see |sub-replace-expression|. 10266--- 10267--- If {list} is present and non-zero then submatch() returns 10268--- a list of strings, similar to |getline()| with two arguments. 10269--- NL characters in the text represent NUL characters in the 10270--- text. 10271--- Only returns more than one item for |:substitute|, inside 10272--- |substitute()| this list will always contain one or zero 10273--- items, since there are no real line breaks. 10274--- 10275--- When |substitute()| is used recursively only the submatches in 10276--- the current (deepest) call can be obtained. 10277--- 10278--- Returns an empty string or list on error. 10279--- 10280--- Examples: >vim 10281--- s/\d\+/\=submatch(0) + 1/ 10282--- echo substitute(text, '\d\+', '\=submatch(0) + 1', '') 10283--- <This finds the first number in the line and adds one to it. 10284--- A line break is included as a newline character. 10285--- 10286--- @overload fun(nr: integer, list: integer): (string|string[]) 10287--- @param nr integer 10288--- @param list? nil 10289--- @return string 10290function vim . fn . submatch ( nr , list ) end 10291 10292--- Lua: Prefer |string.gsub()| for common substitutions; Vim patterns, flags, and replacement semantics differ. 10293--- 10294--- Performs string substitution. Returns a copy of {string} 10295--- in which the first match of {pat} is replaced with {sub}. 10296--- When {flags} is "g", all matches of {pat} in {string} are 10297--- replaced. Otherwise {flags} should be "". 10298--- 10299--- This works like the ":substitute" command (without any flags). 10300--- But the matching with {pat} is always done like the 'magic' 10301--- option is set and 'cpoptions' is empty (to make scripts 10302--- portable). 'ignorecase' is still relevant, use |/\c| or |/\C| 10303--- if you want to ignore or match case and ignore 'ignorecase'. 10304--- 'smartcase' is not used. See |string-match| for how {pat} is 10305--- used. 10306--- 10307--- A "~" in {sub} is not replaced with the previous {sub}. 10308--- Note that some codes in {sub} have a special meaning 10309--- |sub-replace-special|. For example, to replace something with 10310--- "\n" (two characters), use "\\\\n" or '\\n'. 10311--- 10312--- When {pat} does not match in {string}, {string} is returned 10313--- unmodified. 10314--- 10315--- Example: >vim 10316--- let &path = substitute(&path, ",\\=[^,]*$", "", "") 10317--- <This removes the last component of the 'path' option. >vim 10318--- echo substitute("testing", ".*", "\\U\\0", "") 10319--- <results in "TESTING". 10320--- 10321--- When {sub} starts with "\=", the remainder is interpreted as 10322--- an expression. See |sub-replace-expression|. Example: >vim 10323--- echo substitute(s, '%\(\x\x\)', 10324--- \ '\=nr2char("0x" .. submatch(1))', 'g') 10325--- 10326--- <When {sub} is a Funcref that function is called, with one 10327--- optional argument. Example: >vim 10328--- echo substitute(s, '%\(\x\x\)', SubNr, 'g') 10329--- <The optional argument is a list which contains the whole 10330--- matched string and up to nine submatches, like what 10331--- |submatch()| returns. Example: >vim 10332--- echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g') 10333--- 10334--- <Returns an empty string on error. 10335--- 10336--- @param string string 10337--- @param pat string 10338--- @param sub string 10339--- @param flags string 10340--- @return string 10341function vim . fn . substitute ( string , pat , sub , flags ) end 10342 10343--- Returns a list of swap file names, like what "vim -r" shows. 10344--- See the |-r| command argument. The 'directory' option is used 10345--- for the directories to inspect. If you only want to get a 10346--- list of swap files in the current directory then temporarily 10347--- set 'directory' to a dot: >vim 10348--- let save_dir = &directory 10349--- let &directory = '.' 10350--- let swapfiles = swapfilelist() 10351--- let &directory = save_dir 10352--- < 10353--- 10354--- @return string[] 10355function vim . fn . swapfilelist () end 10356 10357--- Returns information about the swapfile {fname} as a 10358--- dictionary. The available fields are: 10359--- version Vim version 10360--- user user name 10361--- host host name 10362--- fname original file name 10363--- pid PID of the Nvim process that created the swap 10364--- file, or zero if not running. 10365--- mtime last modification time in seconds 10366--- inode Optional: INODE number of the file 10367--- dirty 1 if file was modified, 0 if not 10368--- In case of failure an "error" item is added with the reason: 10369--- Cannot open file: file not found or in accessible 10370--- Cannot read file: cannot read first block 10371--- Not a swap file: does not contain correct block ID 10372--- Magic number mismatch: Info in first block is invalid 10373--- 10374--- @param fname string 10375--- @return any 10376function vim . fn . swapinfo ( fname ) end 10377 10378--- The result is the swap file path of the buffer {buf}. 10379--- For the use of {buf}, see |bufname()| above. 10380--- If buffer {buf} is the current buffer, the result is equal to 10381--- |:swapname| (unless there is no swap file). 10382--- If buffer {buf} has no swap file, returns an empty string. 10383--- 10384--- @param buf integer|string 10385--- @return string 10386function vim . fn . swapname ( buf ) end 10387 10388--- Returns the syntax ID at position {lnum} and {col} in the 10389--- current window. The syntax ID can be used with |synIDattr()| 10390--- and |synIDtrans()| to obtain syntax information about text. 10391--- 10392--- {col} is 1 for the leftmost column, {lnum} is 1 for the first 10393--- line. 'synmaxcol' applies, in a longer line zero is returned. 10394--- Note that when the position is after the last character, 10395--- that's where the cursor can be in Insert mode, synID() returns 10396--- zero. {lnum} is used like with |getline()|. 10397--- 10398--- When {trans} is |TRUE|, transparent items are reduced to the 10399--- item that they reveal. This is useful when wanting to know 10400--- the effective color. When {trans} is |FALSE|, the transparent 10401--- item is returned. This is useful when wanting to know which 10402--- syntax item is effective (e.g. inside parens). 10403--- Warning: This function can be very slow. Best speed is 10404--- obtained by going through the file in forward direction. 10405--- 10406--- Returns zero on error. 10407--- 10408--- Example (echoes the name of the syntax item under the cursor): >vim 10409--- echo synIDattr(synID(line("."), col("."), 1), "name") 10410--- < 10411--- 10412--- @param lnum integer|string 10413--- @param col integer 10414--- @param trans 0|1 10415--- @return integer 10416function vim . fn . synID ( lnum , col , trans ) end 10417 10418--- Returns the {what} attribute of syntax ID {synID} as a 10419--- String. This can be used to obtain information about a 10420--- syntax item. 10421--- {mode} can be "gui" or "cterm", to get the attributes 10422--- for that mode. When {mode} is omitted, or an invalid value is 10423--- used, the attributes for the currently active highlighting are 10424--- used (GUI or cterm). 10425--- Use |synIDtrans()| to follow linked highlight groups. 10426--- {what} result 10427--- "name" the name of the syntax item 10428--- "fg" foreground color (GUI: color name used to set 10429--- the color, cterm: color number as a string, 10430--- term: empty string) 10431--- "bg" background color (as with "fg") 10432--- "font" font name (only available in the GUI) 10433--- |highlight-font| 10434--- "sp" special color (as with "fg") |guisp| 10435--- "fg#" like "fg", but for the GUI and the GUI is 10436--- running the name in "#RRGGBB" form 10437--- "bg#" like "fg#" for "bg" 10438--- "sp#" like "fg#" for "sp" 10439--- "bold" "1" if bold 10440--- "italic" "1" if italic 10441--- "reverse" "1" if reverse 10442--- "inverse" "1" if inverse (= reverse) 10443--- "standout" "1" if standout 10444--- "underline" "1" if underlined 10445--- "undercurl" "1" if undercurled 10446--- "underdouble" "1" if double underlined 10447--- "underdotted" "1" if dotted underlined 10448--- "underdashed" "1" if dashed underlined 10449--- "strikethrough" "1" if struckthrough 10450--- "altfont" "1" if alternative font 10451--- "nocombine" "1" if nocombine 10452--- "dim" "1" if half-bright/dimmed 10453--- "blink" "1" if blinking 10454--- "conceal" "1" if concealed 10455--- "overline" "1" if overlined 10456--- 10457--- Returns an empty string on error. 10458--- 10459--- Example (echoes the color of the syntax item under the 10460--- cursor): >vim 10461--- echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") 10462--- < 10463--- Can also be used as a |method|: >vim 10464--- echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") 10465--- < 10466--- 10467--- @param synID integer 10468--- @param what string 10469--- @param mode? string 10470--- @return string 10471function vim . fn . synIDattr ( synID , what , mode ) end 10472 10473--- Returns the translated syntax ID of {synID}, following 10474--- highlight links. This is the syntax group ID of what is 10475--- being used to highlight the character. Highlight links given with 10476--- ":highlight link" are followed. 10477--- 10478--- Returns zero on error. 10479--- 10480--- @param synID integer 10481--- @return integer 10482function vim . fn . synIDtrans ( synID ) end 10483 10484--- Returns conceal information for the character at position 10485--- {lnum} and {col} as a |List| with three items: 10486--- 1. The first item in the list is 0 if the character is not 10487--- part of a concealable region, 1 if it is. {lnum} is used 10488--- like with |getline()|. 10489--- 2. The second item in the list is a string. If the first item 10490--- is 1, the second item contains the text which will be 10491--- displayed in place of the concealed text, depending on the 10492--- current setting of 'conceallevel' and 'listchars'. 10493--- 3. The third and final item in the list is a number 10494--- representing the specific syntax region matched in the 10495--- line. When the character is not concealed the value is 10496--- zero. This allows detection of the beginning of a new 10497--- concealable region if there are two consecutive regions 10498--- with the same replacement character. For an example, if 10499--- the text is "123456" and both "23" and "45" are concealed 10500--- and replaced by the character "X", then: 10501--- call returns ~ 10502--- synconcealed(lnum, 1) [0, '', 0] 10503--- synconcealed(lnum, 2) [1, 'X', 1] 10504--- synconcealed(lnum, 3) [1, 'X', 1] 10505--- synconcealed(lnum, 4) [1, 'X', 2] 10506--- synconcealed(lnum, 5) [1, 'X', 2] 10507--- synconcealed(lnum, 6) [0, '', 0] 10508--- 10509--- Note: Doesn't consider |matchadd()| highlighting items, 10510--- since syntax and matching highlighting are two different 10511--- mechanisms |syntax-vs-match|. 10512--- 10513--- @param lnum integer|string 10514--- @param col integer 10515--- @return [integer, string, integer] 10516function vim . fn . synconcealed ( lnum , col ) end 10517 10518--- Return a |List|, which is the stack of syntax items at the 10519--- position {lnum} and {col} in the current window. {lnum} is 10520--- used like with |getline()|. Each item in the List is an ID 10521--- like what |synID()| returns. 10522--- The first item in the List is the outer region, following are 10523--- items contained in that one. The last one is what |synID()| 10524--- returns, unless not the whole item is highlighted or it is a 10525--- transparent item. 10526--- This function is useful for debugging a syntax file. 10527--- Example that shows the syntax stack under the cursor: >vim 10528--- for id in synstack(line("."), col(".")) 10529--- echo synIDattr(id, "name") 10530--- endfor 10531--- <When the position specified with {lnum} and {col} is invalid 10532--- an empty list is returned. The position just after the last 10533--- character in a line and the first column in an empty line are 10534--- valid positions. 10535--- 10536--- @param lnum integer|string 10537--- @param col integer 10538--- @return integer[] 10539function vim . fn . synstack ( lnum , col ) end 10540 10541--- Lua: Prefer `vim.system(...):wait().stdout` for string output; string commands use the shell in Vimscript, not by default in Lua. 10542--- 10543--- Gets the output of {cmd} as a |string| (|systemlist()| returns 10544--- a |List|) and sets |v:shell_error| to the error code. 10545--- {cmd} is treated as in |jobstart()|: 10546--- If {cmd} is a List it runs directly (no 'shell'). 10547--- If {cmd} is a String it runs in the 'shell', like this: >vim 10548--- call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}']) 10549--- 10550--- <Not to be used for interactive commands. 10551--- 10552--- Result is a String, filtered to avoid platform-specific quirks: 10553--- - <CR><NL> is replaced with <NL> 10554--- - NUL characters are replaced with SOH (0x01) 10555--- 10556--- Example: >vim 10557--- echo system(['ls', expand('%:h')]) 10558--- 10559--- <If {input} is a string it is written to a pipe and passed as 10560--- stdin to the command. The string is written as-is, line 10561--- separators are not changed. 10562--- If {input} is a |List| it is written to the pipe as 10563--- |writefile()| does with {binary} set to "b" (i.e. with 10564--- a newline between each list item, and newlines inside list 10565--- items converted to NULs). 10566--- When {input} is given and is a valid buffer id, the content of 10567--- the buffer is written to the file line by line, each line 10568--- terminated by NL (and NUL where the text has NL). 10569--- *E5677* 10570--- Note: system() cannot write to or read from backgrounded ("&") 10571--- shell commands, e.g.: >vim 10572--- echo system("cat - &", "foo") 10573--- <which is equivalent to: > 10574--- $ echo foo | bash -c 'cat - &' 10575--- <The pipes are disconnected (unless overridden by shell 10576--- redirection syntax) before input can reach it. Use 10577--- |jobstart()| instead. 10578--- 10579--- Note: Use |shellescape()| or |::S| with |expand()| or 10580--- |fnamemodify()| to escape special characters in a command 10581--- argument. 'shellquote' and 'shellxquote' must be properly 10582--- configured. Example: >vim 10583--- echo system('ls '..shellescape(expand('%:h'))) 10584--- echo system('ls '..expand('%:h:S')) 10585--- 10586--- <Unlike ":!cmd" there is no automatic check for changed files. 10587--- Use |:checktime| to force a check. 10588--- 10589--- @param cmd string|string[] 10590--- @param input? string|string[]|integer 10591--- @return string 10592function vim . fn . system ( cmd , input ) end 10593 10594--- Lua: Prefer `vim.system(...):wait().stdout` split into lines; string commands use the shell in Vimscript, not by default in Lua. 10595--- 10596--- Same as |system()|, but returns a |List| with lines (parts of 10597--- output separated by NL) with NULs transformed into NLs. 10598--- Output is the same as |readfile()| will output with {binary} 10599--- argument set to "b", except that a final newline is not 10600--- preserved, unless {keepempty} is non-zero. 10601--- Note that on MS-Windows you may get trailing CR characters. 10602--- 10603--- To see the difference between "echo hello" and "echo -n hello" 10604--- use |system()| and |split()|: >vim 10605--- echo split(system('echo hello'), '\n', 1) 10606--- < 10607--- Returns an empty string on error. 10608--- 10609--- @param cmd string|string[] 10610--- @param input? string|string[]|integer 10611--- @param keepempty? integer 10612--- @return string[] 10613function vim . fn . systemlist ( cmd , input , keepempty ) end 10614 10615--- Lua: Prefer |nvim_tabpage_list_wins()| with |nvim_win_get_buf()|; invalid tabpages error instead of returning 0. 10616--- 10617--- Returns a |List| of buffer numbers, one for each window in 10618--- the specified tabpage. 10619--- {arg} specifies the number of the tabpage to be used. When 10620--- omitted the current tabpage is used. 10621--- When {arg} is invalid the number zero is returned. 10622--- To get a list of all buffers in all tabs use this: >vim 10623--- let buflist = [] 10624--- for i in range(tabpagenr('$')) 10625--- call extend(buflist, tabpagebuflist(i + 1)) 10626--- endfor 10627--- <Note that a buffer may appear in more than one window. 10628--- 10629--- @param arg? integer 10630--- @return any 10631function vim . fn . tabpagebuflist ( arg ) end 10632 10633--- Lua: Prefer |nvim_tabpage_get_number()| with |nvim_get_current_tabpage()| for the current tab, or `#vim.api.nvim_list_tabpages()` for "$"; "#" differs. 10634--- 10635--- Returns the current |tabpage-number|. 10636--- 10637--- The optional argument {arg} supports the following values: 10638--- $ the last |tabpage-number| (the tabpage count). 10639--- # the last-accessed |tabpage-number| (where |g<Tab>| 10640--- goes to), or 0 if there is no previous tabpage. 10641--- The number can be used with the |:tab| command. 10642--- 10643--- Returns zero on error. 10644--- 10645--- @param arg? '$'|'#' 10646--- @return integer 10647function vim . fn . tabpagenr ( arg ) end 10648 10649--- Lua: Prefer |nvim_win_get_number()| with |nvim_tabpage_get_win()| for the current window, or the length of |nvim_tabpage_list_wins()| for "$"; "#" and invalid-tab behavior differ. 10650--- 10651--- Like |winnr()| but for tabpage {tabarg}. 10652--- {tabarg} specifies the |tabpage-number| to be used. 10653--- {arg} is used like with |winnr()|: 10654--- - When omitted the current window number is returned. This is 10655--- the window which will be used when going to this tabpage. 10656--- - When "$" the number of windows is returned. 10657--- - When "#" the previous window nr is returned. 10658--- Useful examples: >vim 10659--- tabpagewinnr(1) " current window of tabpage 1 10660--- tabpagewinnr(4, '$') " number of windows in tabpage 4 10661--- <When {tabarg} is invalid zero is returned. 10662--- 10663--- @param tabarg integer 10664--- @param arg? '$'|'#' 10665--- @return integer 10666function vim . fn . tabpagewinnr ( tabarg , arg ) end 10667 10668--- Returns a |List| with the file names used to search for tags 10669--- for the current buffer. This is the 'tags' option expanded. 10670--- 10671--- @return string[] 10672function vim . fn . tagfiles () end 10673 10674--- Returns a |List| of tags matching the regular expression {expr}. 10675--- 10676--- If {filename} is passed it is used to prioritize the results 10677--- in the same way that |:tselect| does. See |tag-priority|. 10678--- {filename} should be the full path of the file. 10679--- 10680--- Each list item is a dictionary with at least the following 10681--- entries: 10682--- name Name of the tag. 10683--- filename Name of the file where the tag is 10684--- defined. It is either relative to the 10685--- current directory or a full path. 10686--- cmd Ex command used to locate the tag in 10687--- the file. 10688--- kind Type of the tag. The value for this 10689--- entry depends on the language specific 10690--- kind values. Only available when 10691--- using a tags file generated by 10692--- Universal/Exuberant ctags or hdrtag. 10693--- static A file specific tag. Refer to 10694--- |static-tag| for more information. 10695--- More entries may be present, depending on the content of the 10696--- tags file: access, implementation, inherits and signature. 10697--- Refer to the ctags documentation for information about these 10698--- fields. For C code the fields "struct", "class" and "enum" 10699--- may appear, they give the name of the entity the tag is 10700--- contained in. 10701--- 10702--- The ex-command "cmd" can be either an ex search pattern, a 10703--- line number or a line number followed by a byte number. 10704--- 10705--- If there are no matching tags, then an empty list is returned. 10706--- 10707--- To get an exact tag match, the anchors '^' and '$' should be 10708--- used in {expr}. This also make the function work faster. 10709--- Refer to |tag-regexp| for more information about the tag 10710--- search regular expression pattern. 10711--- 10712--- Refer to 'tags' for information about how the tags file is 10713--- located by Vim. Refer to |tags-file-format| for the format of 10714--- the tags file generated by the different ctags tools. 10715--- 10716--- @param expr any 10717--- @param filename? string 10718--- @return any 10719function vim . fn . taglist ( expr , filename ) end 10720 10721--- Lua: Prefer |math.tan()|. 10722--- 10723--- Return the tangent of {expr}, measured in radians, as a |Float| 10724--- in the range [-inf, inf]. 10725--- {expr} must evaluate to a |Float| or a |Number|. 10726--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 10727--- Examples: >vim 10728--- echo tan(10) 10729--- < 0.648361 >vim 10730--- echo tan(-4.01) 10731--- < -1.181502 10732--- 10733--- @param expr number 10734--- @return number 10735function vim . fn . tan ( expr ) end 10736 10737--- Lua: Prefer |math.tanh()|. 10738--- 10739--- Return the hyperbolic tangent of {expr} as a |Float| in the 10740--- range [-1, 1]. 10741--- {expr} must evaluate to a |Float| or a |Number|. 10742--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 10743--- Examples: >vim 10744--- echo tanh(0.5) 10745--- < 0.462117 >vim 10746--- echo tanh(-1) 10747--- < -0.761594 10748--- 10749--- @param expr number 10750--- @return number 10751function vim . fn . tanh ( expr ) end 10752 10753--- Lua: Prefer |os.tmpname()| for a temporary name; Nvim's |tempdir| and nonexistence are not guaranteed. 10754--- 10755--- Generates a (non-existent) filename located in the Nvim root 10756--- |tempdir|. Scripts can use the filename as a temporary file. 10757--- Example: >vim 10758--- let tmpfile = tempname() 10759--- exe "redir > " .. tmpfile 10760--- < 10761--- 10762--- @return string 10763function vim . fn . tempname () end 10764 10765--- @deprecated 10766--- Use |jobstart()| with `{term: v:true}` instead. 10767--- 10768--- @param cmd string|string[] 10769--- @param opts? table 10770--- @return integer 10771function vim . fn . termopen ( cmd , opts ) end 10772 10773--- Return a list with information about timers. 10774--- When {id} is given only information about this timer is 10775--- returned. When timer {id} does not exist an empty list is 10776--- returned. 10777--- When {id} is omitted information about all timers is returned. 10778--- 10779--- For each timer the information is stored in a |Dictionary| with 10780--- these items: 10781--- "id" the timer ID 10782--- "time" time the timer was started with 10783--- "repeat" number of times the timer will still fire; 10784--- -1 means forever 10785--- "callback" the callback 10786--- 10787--- @param id? integer 10788--- @return any 10789function vim . fn . timer_info ( id ) end 10790 10791--- Pause or unpause a timer. A paused timer does not invoke its 10792--- callback when its time expires. Unpausing a timer may cause 10793--- the callback to be invoked almost immediately if enough time 10794--- has passed. 10795--- 10796--- Pausing a timer is useful to avoid the callback to be called 10797--- for a short time. 10798--- 10799--- If {paused} evaluates to a non-zero Number or a non-empty 10800--- String, then the timer is paused, otherwise it is unpaused. 10801--- See |non-zero-arg|. 10802--- 10803--- @param timer integer 10804--- @param paused boolean 10805--- @return any 10806function vim . fn . timer_pause ( timer , paused ) end 10807 10808--- Lua: Prefer |vim.defer_fn()| for one-shot timers, or |uv.new_timer()| for repeating timers; callback and handle semantics differ. 10809--- 10810--- Create a timer and return the timer ID. 10811--- 10812--- {time} is the waiting time in milliseconds. This is the 10813--- minimum time before invoking the callback. When the system is 10814--- busy or Vim is not waiting for input the time will be longer. 10815--- Zero can be used to execute the callback when Vim is back in 10816--- the main loop. 10817--- 10818--- {callback} is the function to call. It can be the name of a 10819--- function or a |Funcref|. It is called with one argument, which 10820--- is the timer ID. The callback is only invoked when Vim is 10821--- waiting for input. 10822--- 10823--- {options} is a dictionary. Supported entries: 10824--- "repeat" Number of times to repeat the callback. 10825--- -1 means forever. Default is 1. 10826--- If the timer causes an error three times in a 10827--- row the repeat is cancelled. 10828--- 10829--- Returns -1 on error. 10830--- 10831--- Example: >vim 10832--- func MyHandler(timer) 10833--- echo 'Handler called' 10834--- endfunc 10835--- let timer = timer_start(500, 'MyHandler', 10836--- \ {'repeat': 3}) 10837--- <This invokes MyHandler() three times at 500 msec intervals. 10838--- 10839--- @param time number 10840--- @param callback string|function 10841--- @param options? table 10842--- @return any 10843function vim . fn . timer_start ( time , callback , options ) end 10844 10845--- Lua: Prefer |uv.timer_stop()| and |uv.close()| on a stored |uv.new_timer()| handle; timer IDs differ. 10846--- 10847--- Stop a timer. The timer callback will no longer be invoked. 10848--- {timer} is an ID returned by |timer_start()|, thus it must be a 10849--- Number. If {timer} does not exist there is no error. 10850--- 10851--- @param timer integer 10852--- @return any 10853function vim . fn . timer_stop ( timer ) end 10854 10855--- Stop all timers. The timer callbacks will no longer be 10856--- invoked. Useful if some timers is misbehaving. If there are 10857--- no timers there is no error. 10858--- 10859--- @return any 10860function vim . fn . timer_stopall () end 10861 10862--- Lua: Prefer |string.lower()|. 10863--- 10864--- Converts a String to lowercase (like applying |gu|). 10865--- Returns empty string on error. 10866--- 10867--- @param expr string 10868--- @return string 10869function vim . fn . tolower ( expr ) end 10870 10871--- Lua: Prefer |string.upper()|. 10872--- 10873--- Converts a String to uppercase (like applying |gU|). 10874--- Returns empty string on error. 10875--- 10876--- @param expr string 10877--- @return string 10878function vim . fn . toupper ( expr ) end 10879 10880--- Translates characters in {src}, replacing each character that 10881--- appears in {fromstr} with the corresponding character in 10882--- {tostr}. Exactly like the unix "tr" command. 10883--- This code also deals with multibyte characters properly. 10884--- 10885--- Returns an empty string on error. 10886--- 10887--- Examples: >vim 10888--- echo tr("hello there", "ht", "HT") 10889--- <returns "Hello THere" >vim 10890--- echo tr("<blob>", "<>", "{}") 10891--- <returns "{blob}" 10892--- 10893--- @param src string 10894--- @param fromstr string 10895--- @param tostr string 10896--- @return string 10897function vim . fn . tr ( src , fromstr , tostr ) end 10898 10899--- Lua: Prefer |vim.trim()|. 10900--- 10901--- Return {text} as a String where any character in {mask} is 10902--- removed from the beginning and/or end of {text}. 10903--- 10904--- If {mask} is not given, or is an empty string, {mask} is all 10905--- characters up to 0x20, which includes Tab, space, NL and CR, 10906--- plus the non-breaking space character 0xa0. 10907--- 10908--- The optional {dir} argument specifies where to remove the 10909--- characters: 10910--- 0 remove from the beginning and end of {text} 10911--- 1 remove only at the beginning of {text} 10912--- 2 remove only at the end of {text} 10913--- When omitted both ends are trimmed. 10914--- 10915--- This function deals with multibyte characters properly. 10916--- Returns an empty string on error. 10917--- 10918--- Examples: >vim 10919--- echo trim(" some text ") 10920--- <returns "some text" >vim 10921--- echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL" 10922--- <returns "RESERVE_TAIL" >vim 10923--- echo trim("rm<Xrm<>X>rrm", "rm<>") 10924--- <returns "Xrm<>X" (characters in the middle are not removed) >vim 10925--- echo trim(" vim ", " ", 2) 10926--- <returns " vim" 10927--- 10928--- @param text string 10929--- @param mask? string 10930--- @param dir? 0|1|2 10931--- @return string 10932function vim . fn . trim ( text , mask , dir ) end 10933 10934--- Lua: Prefer |math.modf()| (first return value). 10935--- 10936--- Return the largest integral value with magnitude less than or 10937--- equal to {expr} as a |Float| (truncate towards zero). 10938--- {expr} must evaluate to a |Float| or a |Number|. 10939--- Returns 0.0 if {expr} is not a |Float| or a |Number|. 10940--- Examples: >vim 10941--- echo trunc(1.456) 10942--- < 1.0 >vim 10943--- echo trunc(-5.456) 10944--- < -5.0 >vim 10945--- echo trunc(4.0) 10946--- < 4.0 10947--- 10948--- @param expr number 10949--- @return integer 10950function vim . fn . trunc ( expr ) end 10951 10952--- Lua: Prefer |lua-type()| for most Lua type checks; Vim type IDs differ. 10953--- 10954--- Returns the type of {expr} as a Number. 10955--- Instead of using the number directly, it is better to use the 10956--- v:t_ variable that has the value: 10957--- Number: 0 |v:t_number| 10958--- String: 1 |v:t_string| 10959--- Funcref: 2 |v:t_func| 10960--- List: 3 |v:t_list| 10961--- Dictionary: 4 |v:t_dict| 10962--- Float: 5 |v:t_float| 10963--- Boolean: 6 |v:t_bool| (|v:false| and |v:true|) 10964--- Null: 7 (|v:null|) 10965--- Blob: 10 |v:t_blob| 10966--- For backward compatibility, this method can be used: >vim 10967--- if type(myvar) == type(0) | endif 10968--- if type(myvar) == type("") | endif 10969--- if type(myvar) == type(function("tr")) | endif 10970--- if type(myvar) == type([]) | endif 10971--- if type(myvar) == type({}) | endif 10972--- if type(myvar) == type(0.0) | endif 10973--- if type(myvar) == type(v:true) | endif 10974--- <In place of checking for |v:null| type it is better to check 10975--- for |v:null| directly as it is the only value of this type: >vim 10976--- if myvar is v:null | endif 10977--- <To check if the v:t_ variables exist use this: >vim 10978--- if exists('v:t_number') | endif 10979--- < 10980--- 10981--- @param expr any 10982--- @return integer 10983function vim . fn . type ( expr ) end 10984 10985--- Return the name of the undo file that would be used for a file 10986--- with name {name} when writing. This uses the 'undodir' 10987--- option, finding directories that exist. It does not check if 10988--- the undo file exists. 10989--- {name} is always expanded to the full path, since that is what 10990--- is used internally. 10991--- If {name} is empty undofile() returns an empty string, since a 10992--- buffer without a file name will not write an undo file. 10993--- Useful in combination with |:wundo| and |:rundo|. 10994--- 10995--- @param name string 10996--- @return string 10997function vim . fn . undofile ( name ) end 10998 10999--- Return the current state of the undo tree for the current 11000--- buffer, or for a specific buffer if {buf} is given. The 11001--- result is a dictionary with the following items: 11002--- "seq_last" The highest undo sequence number used. 11003--- "seq_cur" The sequence number of the current position in 11004--- the undo tree. This differs from "seq_last" 11005--- when some changes were undone. 11006--- "time_cur" Time last used for |:earlier| and related 11007--- commands. Use |strftime()| to convert to 11008--- something readable. 11009--- "save_last" Number of the last file write. Zero when no 11010--- write yet. 11011--- "save_cur" Number of the current position in the undo 11012--- tree. 11013--- "synced" Non-zero when the last undo block was synced. 11014--- This happens when waiting from input from the 11015--- user. See |undo-blocks|. 11016--- "entries" A list of dictionaries with information about 11017--- undo blocks. 11018--- 11019--- The first item in the "entries" list is the oldest undo item. 11020--- Each List item is a |Dictionary| with these items: 11021--- "seq" Undo sequence number. Same as what appears in 11022--- |:undolist|. 11023--- "time" Timestamp when the change happened. Use 11024--- |strftime()| to convert to something readable. 11025--- "newhead" Only appears in the item that is the last one 11026--- that was added. This marks the last change 11027--- and where further changes will be added. 11028--- "curhead" Only appears in the item that is the last one 11029--- that was undone. This marks the current 11030--- position in the undo tree, the block that will 11031--- be used by a redo command. When nothing was 11032--- undone after the last change this item will 11033--- not appear anywhere. 11034--- "save" Only appears on the last block before a file 11035--- write. The number is the write count. The 11036--- first write has number 1, the last one the 11037--- "save_last" mentioned above. 11038--- "alt" Alternate entry. This is again a List of undo 11039--- blocks. Each item may again have an "alt" 11040--- item. 11041--- 11042--- @param buf? integer|string 11043--- @return vim.fn.undotree.ret 11044function vim . fn . undotree ( buf ) end 11045 11046--- Lua: Prefer |vim.list.unique()|. 11047--- 11048--- Remove second and succeeding copies of repeated adjacent 11049--- {list} items in-place. Returns {list}. If you want a list 11050--- to remain unmodified make a copy first: >vim 11051--- let newlist = uniq(copy(mylist)) 11052--- <The default compare function uses the string representation of 11053--- each item. For the use of {func} and {dict} see |sort()|. 11054--- For deduplicating text in the current buffer see |:uniq|. 11055--- 11056--- Returns zero if {list} is not a |List|. 11057--- 11058--- @param list any 11059--- @param func? any 11060--- @param dict? any 11061--- @return any[]|0 11062function vim . fn . uniq ( list , func , dict ) end 11063 11064--- Lua: Prefer |vim.str_utfindex()| with `"utf-16"` and `strict_indexing = false`; `countcc` and `charidx` semantics differ. 11065--- 11066--- Same as |charidx()| but returns the UTF-16 code unit index of 11067--- the byte at {idx} in {string} (after converting it to UTF-16). 11068--- 11069--- When {charidx} is present and TRUE, {idx} is used as the 11070--- character index in the String {string} instead of as the byte 11071--- index. 11072--- An {idx} in the middle of a UTF-8 sequence is rounded 11073--- downwards to the beginning of that sequence. 11074--- 11075--- Returns -1 if the arguments are invalid or if there are less 11076--- than {idx} bytes in {string}. If there are exactly {idx} 11077--- bytes, the length of the string in UTF-16 code units is 11078--- returned. 11079--- 11080--- See |byteidx()| and |byteidxcomp()| for getting the byte index 11081--- from the UTF-16 index and |charidx()| for getting the 11082--- character index from the UTF-16 index. 11083--- Refer to |string-offset-encoding| for more information. 11084--- Examples: >vim 11085--- echo utf16idx('a😊😊', 3) " returns 2 11086--- echo utf16idx('a😊😊', 7) " returns 4 11087--- echo utf16idx('a😊😊', 1, 0, 1) " returns 2 11088--- echo utf16idx('a😊😊', 2, 0, 1) " returns 4 11089--- echo utf16idx('aą́c', 6) " returns 2 11090--- echo utf16idx('aą́c', 6, 1) " returns 4 11091--- echo utf16idx('a😊😊', 9) " returns -1 11092--- < 11093--- 11094--- @param string string 11095--- @param idx integer 11096--- @param countcc? boolean 11097--- @param charidx? boolean 11098--- @return integer 11099function vim . fn . utf16idx ( string , idx , countcc , charidx ) end 11100 11101--- Lua: Prefer |vim.tbl_values()|. 11102--- 11103--- Return a |List| with all the values of {dict}. The |List| is 11104--- in arbitrary order. Also see |items()| and |keys()|. 11105--- Returns zero if {dict} is not a |Dict|. 11106--- 11107--- @param dict any 11108--- @return any 11109function vim . fn . values ( dict ) end 11110 11111--- Returns the virtual (screen) column of the file position 11112--- given with {expr}. That is, the total number of screen cells 11113--- occupied by the part of the line until the end of the 11114--- character at that position. When there is a <Tab> at the 11115--- position, the returned Number will be the column at the end of 11116--- the <Tab>. For example, for a <Tab> in column 1, with 'ts' 11117--- set to 8, it returns 8. |conceal| is ignored. 11118--- For the byte position use |col()|. 11119--- 11120--- For the use of {expr} see |getpos()| and |col()|. 11121--- When {expr} is "$", it means the end of the cursor line, so 11122--- the result is the number of cells in the cursor line plus one. 11123--- 11124--- When 'virtualedit' is used {expr} can be [lnum, col, off], 11125--- where "off" is the offset in screen columns from the start of 11126--- the character. E.g., a position within a <Tab> or after the 11127--- last character. When "off" is omitted zero is used. When 11128--- Virtual editing is active in the current mode, a position 11129--- beyond the end of the line can be returned. Also see 11130--- 'virtualedit' 11131--- 11132--- If {list} is present and non-zero then virtcol() returns a 11133--- List with the first and last screen position occupied by the 11134--- character. 11135--- 11136--- With the optional {winid} argument the values are obtained for 11137--- that window instead of the current window. 11138--- 11139--- Note that only marks in the current file can be used. 11140--- Examples: >vim 11141--- " With text "foo^Lbar" and cursor on the "^L": 11142--- 11143--- echo virtcol(".") " returns 5 11144--- echo virtcol(".", 1) " returns [4, 5] 11145--- echo virtcol("$") " returns 9 11146--- 11147--- " With text " there", with 't at 'h': 11148--- 11149--- echo virtcol("'t") " returns 6 11150--- < 11151--- The first column is 1. 0 or [0, 0] is returned for an error. 11152--- 11153--- A more advanced example that echoes the maximum length of 11154--- all lines: >vim 11155--- echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) 11156--- < 11157--- 11158--- @param expr string|any[] 11159--- @param list? boolean 11160--- @param winid? integer 11161--- @return integer|[integer, integer] 11162function vim . fn . virtcol ( expr , list , winid ) end 11163 11164--- Converts a virtual column to a byte index. Returns the byte 11165--- index of the character in window {winid} at buffer line 11166--- {lnum} and virtual column {col}. 11167--- 11168--- If buffer line {lnum} is an empty line, 0 is returned. 11169--- 11170--- If {col} is greater than the last virtual column in line 11171--- {lnum}, then the byte index of the character at the last 11172--- virtual column is returned. 11173--- 11174--- For a multi-byte character, the column number of the first 11175--- byte in the character is returned. 11176--- 11177--- {winid} is a |window-number| or |window-ID|. If zero, the 11178--- current window is used. 11179--- 11180--- Returns -1 if the window {winid} doesn't exist or the buffer 11181--- line {lnum} or virtual column {col} is invalid. 11182--- 11183--- See also |screenpos()|, |virtcol()| and |col()|. 11184--- 11185--- @param winid integer 11186--- @param lnum integer 11187--- @param col integer 11188--- @return integer 11189function vim . fn . virtcol2col ( winid , lnum , col ) end 11190 11191--- Returns a String describing the last Visual mode used in the 11192--- current buffer. Initially it returns an empty string, but 11193--- once Visual mode has been used, it returns "v", 11194--- "V", or "<CTRL-V>" (a single CTRL-V character) for 11195--- character-wise, line-wise, or block-wise Visual mode 11196--- respectively. 11197--- Example: >vim 11198--- exe "normal " .. visualmode() 11199--- <This enters the same Visual mode as before. It is also useful 11200--- in scripts if you wish to act differently depending on the 11201--- Visual mode that was used. 11202--- If Visual mode is active, use |mode()| to get the Visual mode 11203--- (e.g., in a |:vmap|). 11204--- If {expr} is supplied and it evaluates to a non-zero Number or 11205--- a non-empty String, then the Visual mode will be cleared and 11206--- the old value is returned. See |non-zero-arg|. 11207--- 11208--- @param expr? boolean 11209--- @return string 11210function vim . fn . visualmode ( expr ) end 11211 11212--- Lua: Prefer |vim.wait()|. 11213--- 11214--- Waits until {condition} evaluates to |TRUE|, where {condition} 11215--- is a |Funcref| or |string| containing an expression. 11216--- 11217--- {timeout} is the maximum waiting time in milliseconds, -1 11218--- means forever. 11219--- 11220--- Condition is evaluated on user events, internal events, and 11221--- every {interval} milliseconds (default: 200). 11222--- 11223--- Returns a status integer: 11224--- 0 if the condition was satisfied before timeout 11225--- -1 if the timeout was exceeded 11226--- -2 if the function was interrupted (by |CTRL-C|) 11227--- -3 if an error occurred 11228--- 11229--- @param timeout integer 11230--- @param condition any 11231--- @param interval? number 11232--- @return any 11233function vim . fn . wait ( timeout , condition , interval ) end 11234 11235--- Returns |TRUE| when the wildmenu is active and |FALSE| 11236--- otherwise. See 'wildmenu' and 'wildmode'. 11237--- This can be used in mappings to handle the 'wildcharm' option 11238--- gracefully. (Makes only sense with |mapmode-c| mappings). 11239--- 11240--- For example to make <c-j> work like <down> in wildmode, use: >vim 11241--- cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>" 11242--- < 11243--- (Note: this needs the 'wildcharm' option set appropriately). 11244--- 11245--- @return any 11246function vim . fn . wildmenumode () end 11247 11248--- Start wildcard expansion in the command-line, using the 11249--- behavior defined by the 'wildmode' and 'wildoptions' settings. 11250--- 11251--- This function also enables completion in search patterns such 11252--- as |/|, |?|, |:s|, |:g|, |:v| and |:vimgrep|. 11253--- 11254--- Unlike pressing 'wildchar' manually, this function does not 11255--- produce a beep when no matches are found and generally 11256--- operates more quietly. This makes it suitable for triggering 11257--- completion automatically. 11258--- 11259--- Note: After navigating command-line history, the first call to 11260--- wildtrigger() is a no-op; a second call is needed to start 11261--- expansion. This is to support history navigation in 11262--- command-line autocompletion. 11263--- 11264--- See |cmdline-autocompletion|. 11265--- 11266--- Return value is always 0. 11267--- 11268--- @return number 11269function vim . fn . wildtrigger () end 11270 11271--- Lua: Prefer |nvim_win_call()|. 11272--- 11273--- Like `execute()` but in the context of window {id}. 11274--- The window will temporarily be made the current window, 11275--- without triggering autocommands or changing directory. When 11276--- executing {command} autocommands will be triggered, this may 11277--- have unexpected side effects. Use `:noautocmd` if needed. 11278--- Example: >vim 11279--- call win_execute(winid, 'syntax enable') 11280--- <Doing the same with `setwinvar()` would not trigger 11281--- autocommands and not actually show syntax highlighting. 11282--- 11283--- When window {id} does not exist then no error is given and 11284--- an empty string is returned. 11285--- 11286--- @param id integer 11287--- @param command string 11288--- @param silent? boolean 11289--- @return any 11290function vim . fn . win_execute ( id , command , silent ) end 11291 11292--- Lua: Prefer |nvim_list_wins()| with |nvim_win_get_buf()|. 11293--- 11294--- Returns a |List| with |window-ID|s for windows that contain 11295--- buffer {bufnr}. When there is none the list is empty. 11296--- 11297--- @param bufnr integer 11298--- @return integer[] 11299function vim . fn . win_findbuf ( bufnr ) end 11300 11301--- Lua: Prefer |nvim_get_current_win()| when omitted, or |nvim_tabpage_list_wins()| with |nvim_win_get_number()| after resolving {tab}; invalid windows return 0 in Vimscript. 11302--- 11303--- Get the |window-ID| for the specified window. 11304--- When {win} is missing use the current window. 11305--- With {win} this is the |window-number|. 11306--- Without {tab} use the current tab, otherwise the 11307--- |tabpage-number| given by {tab}. 11308--- Return zero if the window cannot be found. 11309--- 11310--- @param win? integer 11311--- @param tab? integer 11312--- @return integer 11313function vim . fn . win_getid ( win , tab ) end 11314 11315--- Gets the type of the given window, or current window if {nr} 11316--- is omitted: 11317--- - (empty) Normal window 11318--- - "autocmd" Internal "context-switch" window. 11319--- - "command" Command-line window |cmdwin| 11320--- - "loclist" |location-list-window| 11321--- - "popup" Floating window |api-floatwin| 11322--- - "preview" Preview window |preview-window| 11323--- - "quickfix" |quickfix-window| 11324--- - "unknown" Window {nr} not found 11325--- 11326--- See also the 'buftype' option. 11327--- 11328--- @param nr? integer 11329--- @return 'autocmd'|'command'|''|'loclist'|'popup'|'preview'|'quickfix'|'unknown' 11330function vim . fn . win_gettype ( nr ) end 11331 11332--- Lua: Prefer |nvim_set_current_win()|; invalid IDs error instead of returning FALSE. 11333--- 11334--- Go to |window-ID| {expr}. May change the current tabpage. 11335--- Return TRUE if successful, FALSE if the window cannot be 11336--- found. 11337--- 11338--- @param expr integer 11339--- @return 0|1 11340function vim . fn . win_gotoid ( expr ) end 11341 11342--- Lua: Prefer |nvim_win_get_tabpage()| and |nvim_win_get_number()| for valid windows; invalid IDs error instead of returning `[0, 0]`. 11343--- 11344--- Return [tabnr, winnr] for window with |window-ID| {expr}, where 11345--- tabnr is the |tabpage-number| and winnr is the |window-number|. 11346--- Return [0, 0] if the window cannot be found. 11347--- 11348--- @param expr integer 11349--- @return any 11350function vim . fn . win_id2tabwin ( expr ) end 11351 11352--- Lua: Prefer |nvim_win_get_number()| for valid windows; windows outside the current tabpage and invalid IDs differ. 11353--- 11354--- Return the |window-number| of for the given |window-ID| {expr}. 11355--- Return 0 if the window cannot be found in the current tabpage. 11356--- 11357--- @param expr integer 11358--- @return integer 11359function vim . fn . win_id2win ( expr ) end 11360 11361--- Move window {nr}'s vertical separator (i.e., the right border) 11362--- by {offset} columns, as if being dragged by the mouse. {nr} 11363--- is a |window-number| or |window-ID|. A positive {offset} 11364--- moves right and a negative {offset} moves left. Moving a 11365--- window's vertical separator will change the width of the 11366--- window and the width of other windows adjacent to the vertical 11367--- separator. The magnitude of movement may be smaller than 11368--- specified (e.g., as a consequence of maintaining 11369--- 'winminwidth'). Returns TRUE if the window can be found and 11370--- FALSE otherwise. 11371--- This will fail for the rightmost window and a full-width 11372--- window, since it has no separator on the right. 11373--- Only works for the current tabpage. *E1308* 11374--- 11375--- @param nr integer 11376--- @param offset integer 11377--- @return any 11378function vim . fn . win_move_separator ( nr , offset ) end 11379 11380--- Move window {nr}'s status line (i.e., the bottom border) by 11381--- {offset} rows, as if being dragged by the mouse. {nr} is a 11382--- |window-number| or |window-ID|. A positive {offset} moves 11383--- down and a negative {offset} moves up. Moving a window's 11384--- status line will change the height of the window and the 11385--- height of other windows adjacent to the status line. The 11386--- magnitude of movement may be smaller than specified (e.g., as 11387--- a consequence of maintaining 'winminheight'). Returns TRUE if 11388--- the window can be found and FALSE otherwise. 11389--- Only works for the current tabpage. 11390--- 11391--- @param nr integer 11392--- @param offset integer 11393--- @return any 11394function vim . fn . win_move_statusline ( nr , offset ) end 11395 11396--- Lua: Prefer |nvim_win_get_position()| and add 1 to row and col; invalid-window semantics differ. 11397--- 11398--- Return the screen position of window {nr} as a list with two 11399--- numbers: [row, col]. The first window always has position 11400--- [1, 1], unless there is a tabline, then it is [2, 1]. 11401--- {nr} is a |window-number| or |window-ID|. Use zero for the 11402--- current window. 11403--- Returns [0, 0] if the window cannot be found. 11404--- 11405--- @param nr integer 11406--- @return any 11407function vim . fn . win_screenpos ( nr ) end 11408 11409--- Temporarily switch to window {target}, then move window {nr} 11410--- to a new split adjacent to {target}. 11411--- Unlike commands such as |:split|, no new windows are created 11412--- (the |window-ID| of window {nr} is unchanged after the move). 11413--- 11414--- Both {nr} and {target} are a |window-number| or |window-ID|. 11415--- Both must be in the current tabpage. 11416--- 11417--- Returns zero for success, non-zero for failure. 11418--- 11419--- {options} is a |Dictionary| with the following optional entries: 11420--- "vertical" When TRUE, the split is created vertically, 11421--- like with |:vsplit|. 11422--- "rightbelow" When TRUE, the split is made below or to the 11423--- right (if vertical). When FALSE, it is done 11424--- above or to the left (if vertical). When not 11425--- present, the values of 'splitbelow' and 11426--- 'splitright' are used. 11427--- 11428--- @param nr integer 11429--- @param target integer 11430--- @param options? table 11431--- @return any 11432function vim . fn . win_splitmove ( nr , target , options ) end 11433 11434--- Lua: Prefer |nvim_win_get_buf()|. 11435--- 11436--- Returns the buffer number associated with window {nr} 11437--- (|window-number| or |window-ID|). 11438--- When {nr} is zero, the number of the buffer in the current 11439--- window is returned. 11440--- When window {nr} doesn't exist, -1 is returned. 11441--- Example: >vim 11442--- echo "The file in the current window is " .. bufname(winbufnr(0)) 11443--- < 11444--- 11445--- @param nr integer 11446--- @return integer 11447function vim . fn . winbufnr ( nr ) end 11448 11449--- Returns the virtual column of the cursor in the window. 11450--- This is counting screen cells from the left side of the 11451--- window. The leftmost column is one. 11452--- 11453--- @return integer 11454function vim . fn . wincol () end 11455 11456--- Returns the Windows OS version as a String. E.g, Windows 10 11457--- is "10.0", Windows 8 is "6.2", Windows XP is "5.1". For 11458--- non-MS-Windows systems the result is an empty string. 11459--- 11460--- Lua: see |uv.os_uname()|. 11461--- 11462--- @return string 11463function vim . fn . windowsversion () end 11464 11465--- Gets the height of |window-ID| {nr} (zero for "current 11466--- window"), excluding any 'winbar' and 'statusline'. Returns -1 11467--- if window {nr} doesn't exist. An existing window always has 11468--- a height of zero or more. 11469--- 11470--- Examples: >vim 11471--- echo "Current window has " .. winheight(0) .. " lines." 11472--- < 11473--- 11474--- @param nr integer 11475--- @return integer 11476function vim . fn . winheight ( nr ) end 11477 11478--- Returns the layout of windows in a tabpage as a nested List. 11479--- 11480--- Without {tabnr} use the current tabpage, otherwise the tabpage 11481--- with number {tabnr}. If the tabpage {tabnr} is not found, 11482--- returns an empty list. 11483--- 11484--- For a leaf window, it returns: > 11485--- ["leaf", {winid}] 11486--- < 11487--- For horizontally split windows, which form a column, it 11488--- returns: > 11489--- ["col", [{nested list of windows}]] 11490--- <For vertically split windows, which form a row, it returns: > 11491--- ["row", [{nested list of windows}]] 11492--- < 11493--- Example: >vim 11494--- " Only one window in the tabpage 11495--- echo winlayout() 11496--- < > 11497--- ['leaf', 1000] 11498--- < >vim 11499--- " Two horizontally split windows 11500--- echo winlayout() 11501--- < > 11502--- ['col', [['leaf', 1000], ['leaf', 1001]]] 11503--- < >vim 11504--- " The second tabpage, with three horizontally split 11505--- " windows, with two vertically split windows in the 11506--- " middle window 11507--- echo winlayout(2) 11508--- < > 11509--- ['col', [['leaf', 1002], ['row', [['leaf', 1003], 11510--- ['leaf', 1001]]], ['leaf', 1000]]] 11511--- < 11512--- 11513--- @param tabnr? integer 11514--- @return vim.fn.winlayout.ret 11515function vim . fn . winlayout ( tabnr ) end 11516 11517--- Returns the screen line of the cursor in the window. This is 11518--- counting screen lines from the top of the window. The first 11519--- line is one. 11520--- If the cursor was moved the view on the file will be updated 11521--- first, this may cause a scroll. 11522--- 11523--- @return integer 11524function vim . fn . winline () end 11525 11526--- Lua: Prefer |nvim_win_get_number()| with |nvim_get_current_win()| for the current window, or |nvim_tabpage_list_wins()| with |nvim_get_current_tabpage()| for "$"; "#", motion args, and hidden windows differ. 11527--- 11528--- Returns the number of the current window. The top window has 11529--- number 1. Returns zero for a hidden or non |focusable| 11530--- window, unless it is the current window. 11531--- 11532--- The optional argument {arg} supports the following values: 11533--- $ the number of the last window (the window 11534--- count). 11535--- # the number of the last accessed window (where 11536--- |CTRL-W_p| goes to). If there is no previous 11537--- window or it is in another tabpage, 0 is 11538--- returned. May refer to the current window in 11539--- some cases (e.g. when evaluating 'statusline' 11540--- expressions). 11541--- {N}j the number of the Nth window below the 11542--- current window (where |CTRL-W_j| goes to). 11543--- {N}k the number of the Nth window above the current 11544--- window (where |CTRL-W_k| goes to). 11545--- {N}h the number of the Nth window left of the 11546--- current window (where |CTRL-W_h| goes to). 11547--- {N}l the number of the Nth window right of the 11548--- current window (where |CTRL-W_l| goes to). 11549--- The number can be used with |CTRL-W_w| and ":wincmd w" 11550--- |:wincmd|. 11551--- When {arg} is invalid an error is given and zero is returned. 11552--- Also see |tabpagewinnr()| and |win_getid()|. 11553--- Examples: >vim 11554--- let window_count = winnr('$') 11555--- let prev_window = winnr('#') 11556--- let wnum = winnr('3k') 11557--- < 11558--- 11559--- @param arg? string|integer 11560--- @return integer 11561function vim . fn . winnr ( arg ) end 11562 11563--- Returns a sequence of |:resize| commands that should restore 11564--- the current window sizes. Only works properly when no windows 11565--- are opened or closed and the current window and tabpage is 11566--- unchanged. 11567--- Example: >vim 11568--- let cmd = winrestcmd() 11569--- call MessWithWindowSizes() 11570--- exe cmd 11571--- < 11572--- 11573--- @return string 11574function vim . fn . winrestcmd () end 11575 11576--- Uses the |Dictionary| returned by |winsaveview()| to restore 11577--- the view of the current window. 11578--- Note: The {dict} does not have to contain all values, that are 11579--- returned by |winsaveview()|. If values are missing, those 11580--- settings won't be restored. So you can use: >vim 11581--- call winrestview({'curswant': 4}) 11582--- < 11583--- This will only set the curswant value (the column the cursor 11584--- wants to move on vertical movements) of the cursor to column 5 11585--- (yes, that is 5), while all other settings will remain the 11586--- same. This is useful, if you set the cursor position 11587--- manually. 11588--- 11589--- If you have changed the values the result is unpredictable. 11590--- If the window size changed the result won't be the same. 11591--- 11592--- @param dict vim.fn.winrestview.dict 11593--- @return any 11594function vim . fn . winrestview ( dict ) end 11595 11596--- Returns a |Dictionary| that contains information to restore 11597--- the view of the current window. Use |winrestview()| to 11598--- restore the view. 11599--- This is useful if you have a mapping that jumps around in the 11600--- buffer and you want to go back to the original view. 11601--- This does not save fold information. Use the 'foldenable' 11602--- option to temporarily switch off folding, so that folds are 11603--- not opened when moving around. This may have side effects. 11604--- The return value includes: 11605--- lnum cursor line number 11606--- col cursor column (Note: the first column 11607--- zero, as opposed to what |getcurpos()| 11608--- returns) 11609--- coladd cursor column offset for 'virtualedit' 11610--- curswant column for vertical movement (Note: 11611--- the first column is zero, as opposed 11612--- to what |getcurpos()| returns). After 11613--- |$| command it will be a very large 11614--- number equal to |v:maxcol|. 11615--- topline first line in the window 11616--- topfill filler lines, only in diff mode 11617--- leftcol first column displayed; only used when 11618--- 'wrap' is off 11619--- skipcol columns skipped 11620--- Note that no option values are saved. 11621--- 11622--- @return vim.fn.winsaveview.ret 11623function vim . fn . winsaveview () end 11624 11625--- Gets the width of |window-ID| {nr} (zero for "current 11626--- window"), including columns (|sign-column|, 'statuscolumn', 11627--- etc.). Returns -1 if window {nr} doesn't exist. An existing 11628--- window always has a width of zero or more. 11629--- 11630--- Example: >vim 11631--- echo "Current window has " .. winwidth(0) .. " columns." 11632--- if winwidth(0) <= 50 11633--- 50 wincmd | 11634--- endif 11635--- < 11636--- To get the buffer "viewport", use |getwininfo()|: >vim 11637--- :echo getwininfo(win_getid())[0].width - getwininfo(win_getid())[0].textoff 11638--- < 11639--- To get the Nvim screen size, see the 'columns' option. 11640--- 11641--- @param nr integer 11642--- @return integer 11643function vim . fn . winwidth ( nr ) end 11644 11645--- Returns a dictionary of byte/chars/word statistics for the 11646--- current buffer. This is the same info provided by |g_CTRL-G|. 11647--- The return value includes: 11648--- bytes Number of bytes in the buffer 11649--- chars Number of chars in the buffer 11650--- words Number of words in the buffer 11651--- cursor_bytes Number of bytes before cursor position 11652--- (not in Visual mode) 11653--- cursor_chars Number of chars before cursor position 11654--- (not in Visual mode) 11655--- cursor_words Number of words before cursor position 11656--- (not in Visual mode) 11657--- visual_bytes Number of bytes visually selected 11658--- (only in Visual mode) 11659--- visual_chars Number of chars visually selected 11660--- (only in Visual mode) 11661--- visual_words Number of words visually selected 11662--- (only in Visual mode) 11663--- 11664--- @return any 11665function vim . fn . wordcount () end 11666 11667--- Writes {data} to file {fname}. 11668--- 11669--- - When {data} is a |Blob| its bytes are written unmodified 11670--- (even if binary mode "b" is not specified). 11671--- - When {data} is a Lua string, it is treated as a blob. 11672--- - When {data} is a |List|, each list item is treated as a text 11673--- line (terminated with a newline). Each list item must be 11674--- a String or Number. 11675--- - Any NL (newline) chars in the line are treated as a NUL 11676--- character. (This is a workaround to allow Vimscript to 11677--- write binary data, and is irrelevant for Lua, which should 11678--- just pass a string instead.) 11679--- 11680--- {flags} must be a String. These characters are recognized: 11681--- 11682--- 'b' Binary mode is used: There will not be a NL after the 11683--- last list item. An empty item at the end does cause the 11684--- last line in the file to end in a NL. 11685--- 11686--- 'a' Append mode is used, lines are appended to the file: >vim 11687--- call writefile(["foo"], "event.log", "a") 11688--- call writefile(["bar"], "event.log", "a") 11689--- < 11690--- 'D' Delete the file when the current function ends. This 11691--- works like: >vim 11692--- defer delete({fname}) 11693--- < Fails when not in a function. Also see |:defer|. 11694--- 11695--- 's' fsync() is called after writing the file. This flushes 11696--- the file to disk, if possible. This takes more time but 11697--- avoids losing the file if the system crashes. 11698--- 11699--- 'S' fsync() is not called, even when 'fsync' is set. 11700--- 11701--- When {flags} does not contain "S" or "s" then fsync() is 11702--- called if the 'fsync' option is set. 11703--- 11704--- An existing file is overwritten, if possible. 11705--- 11706--- When the write fails -1 is returned, otherwise 0. There is an 11707--- error message if the file can't be created or when writing 11708--- fails. 11709--- 11710--- Also see |readfile()|. 11711--- To copy a file byte for byte: >vim 11712--- let fl = readfile("foo", "b") 11713--- call writefile(fl, "foocopy", "b") 11714--- < 11715--- 11716--- @param data any 11717--- @param fname string 11718--- @param flags? string 11719--- @return any 11720function vim . fn . writefile ( data , fname , flags ) end 11721 11722--- Lua: Prefer |bit.bxor()|. 11723--- 11724--- Bitwise XOR on the two arguments. The arguments are converted 11725--- to a number. A List, Dict or Float argument causes an error. 11726--- Also see `and()` and `or()`. 11727--- Example: >vim 11728--- let bits = xor(bits, 0x80) 11729--- < 11730--- 11731--- @param expr integer 11732--- @param expr1 integer 11733--- @return integer 11734function vim . fn . xor ( expr , expr1 ) end