1*eval.txt* For Vim version 8.2. Last change: 2021 Nov 14 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7Expression evaluation *expression* *expr* *E15* *eval* 8 9Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|. 10 11Note: Expression evaluation can be disabled at compile time. If this has been 12done, the features in this document are not available. See |+eval| and 13|no-eval-feature|. 14 15This file is about the backwards compatible Vim script. For Vim9 script, 16which executes much faster, supports type checking and much more, see 17|vim9.txt|. 18 191. Variables |variables| 20 1.1 Variable types 21 1.2 Function references |Funcref| 22 1.3 Lists |Lists| 23 1.4 Dictionaries |Dictionaries| 24 1.5 Blobs |Blobs| 25 1.6 More about variables |more-variables| 262. Expression syntax |expression-syntax| 273. Internal variable |internal-variables| 284. Builtin Functions |functions| 295. Defining functions |user-functions| 306. Curly braces names |curly-braces-names| 317. Commands |expression-commands| 328. Exception handling |exception-handling| 339. Examples |eval-examples| 3410. Vim script version |vimscript-version| 3511. No +eval feature |no-eval-feature| 3612. The sandbox |eval-sandbox| 3713. Textlock |textlock| 38 39Testing support is documented in |testing.txt|. 40Profiling is documented at |profiling|. 41 42============================================================================== 431. Variables *variables* 44 451.1 Variable types ~ 46 *E712* *E896* *E897* *E899* 47There are ten types of variables: 48 49 *Number* *Integer* 50Number A 32 or 64 bit signed number. |expr-number| 51 The number of bits is available in |v:numbersize|. 52 Examples: -123 0x10 0177 0o177 0b1011 53 54Float A floating point number. |floating-point-format| *Float* 55 {only when compiled with the |+float| feature} 56 Examples: 123.456 1.15e-6 -1.1e3 57 58String A NUL terminated string of 8-bit unsigned characters (bytes). 59 |expr-string| Examples: "ab\txx\"--" 'x-z''a,c' 60 61List An ordered sequence of items, see |List| for details. 62 Example: [1, 2, ['a', 'b']] 63 64Dictionary An associative, unordered array: Each entry has a key and a 65 value. |Dictionary| 66 Examples: 67 {'blue': "#0000ff", 'red': "#ff0000"} 68 #{blue: "#0000ff", red: "#ff0000"} 69 70Funcref A reference to a function |Funcref|. 71 Example: function("strlen") 72 It can be bound to a dictionary and arguments, it then works 73 like a Partial. 74 Example: function("Callback", [arg], myDict) 75 76Special |v:false|, |v:true|, |v:none| and |v:null|. *Special* 77 78Job Used for a job, see |job_start()|. *Job* *Jobs* 79 80Channel Used for a channel, see |ch_open()|. *Channel* *Channels* 81 82Blob Binary Large Object. Stores any sequence of bytes. See |Blob| 83 for details 84 Example: 0zFF00ED015DAF 85 0z is an empty Blob. 86 87The Number and String types are converted automatically, depending on how they 88are used. 89 90Conversion from a Number to a String is by making the ASCII representation of 91the Number. Examples: 92 Number 123 --> String "123" ~ 93 Number 0 --> String "0" ~ 94 Number -1 --> String "-1" ~ 95 *octal* 96Conversion from a String to a Number only happens in legacy Vim script, not in 97Vim9 script. It is done by converting the first digits to a number. 98Hexadecimal "0xf9", Octal "017" or "0o17", and Binary "0b10" 99numbers are recognized 100NOTE: when using |scriptversion-4| octal with a leading "0" is not recognized. 101The 0o notation requires patch 8.2.0886. 102If the String doesn't start with digits, the result is zero. 103Examples: 104 String "456" --> Number 456 ~ 105 String "6bar" --> Number 6 ~ 106 String "foo" --> Number 0 ~ 107 String "0xf1" --> Number 241 ~ 108 String "0100" --> Number 64 ~ 109 String "0o100" --> Number 64 ~ 110 String "0b101" --> Number 5 ~ 111 String "-8" --> Number -8 ~ 112 String "+8" --> Number 0 ~ 113 114To force conversion from String to Number, add zero to it: > 115 :echo "0100" + 0 116< 64 ~ 117 118To avoid a leading zero to cause octal conversion, or for using a different 119base, use |str2nr()|. 120 121 *TRUE* *FALSE* *Boolean* 122For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE. 123You can also use |v:false| and |v:true|, in Vim9 script |false| and |true|. 124When TRUE is returned from a function it is the Number one, FALSE is the 125number zero. 126 127Note that in the command: > 128 :if "foo" 129 :" NOT executed 130"foo" is converted to 0, which means FALSE. If the string starts with a 131non-zero number it means TRUE: > 132 :if "8foo" 133 :" executed 134To test for a non-empty string, use empty(): > 135 :if !empty("foo") 136 137< *falsy* *truthy* 138An expression can be used as a condition, ignoring the type and only using 139whether the value is "sort of true" or "sort of false". Falsy is: 140 the number zero 141 empty string, blob, list or dictionary 142Other values are truthy. Examples: 143 0 falsy 144 1 truthy 145 -1 truthy 146 0.0 falsy 147 0.1 truthy 148 '' falsy 149 'x' truthy 150 [] falsy 151 [0] truthy 152 {} falsy 153 #{x: 1} truthy 154 0z falsy 155 0z00 truthy 156 157 *non-zero-arg* 158Function arguments often behave slightly different from |TRUE|: If the 159argument is present and it evaluates to a non-zero Number, |v:true| or a 160non-empty String, then the value is considered to be TRUE. 161Note that " " and "0" are also non-empty strings, thus considered to be TRUE. 162A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE. 163 164 *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* 165 *E974* *E975* *E976* 166|List|, |Dictionary|, |Funcref|, |Job|, |Channel| and |Blob| types are not 167automatically converted. 168 169 *E805* *E806* *E808* 170When mixing Number and Float the Number is converted to Float. Otherwise 171there is no automatic conversion of Float. You can use str2float() for String 172to Float, printf() for Float to String and float2nr() for Float to Number. 173 174 *E891* *E892* *E893* *E894* *E907* *E911* *E914* 175When expecting a Float a Number can also be used, but nothing else. 176 177 *no-type-checking* 178You will not get an error if you try to change the type of a variable. 179 180 1811.2 Function references ~ 182 *Funcref* *E695* *E718* 183A Funcref variable is obtained with the |function()| function, the |funcref()| 184function or created with the lambda expression |expr-lambda|. It can be used 185in an expression in the place of a function name, before the parenthesis 186around the arguments, to invoke the function it refers to. Example: > 187 188 :let Fn = function("MyFunc") 189 :echo Fn() 190< *E704* *E705* *E707* 191A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:". You 192can use "g:" but the following name must still start with a capital. You 193cannot have both a Funcref variable and a function with the same name. 194 195A special case is defining a function and directly assigning its Funcref to a 196Dictionary entry. Example: > 197 :function dict.init() dict 198 : let self.val = 0 199 :endfunction 200 201The key of the Dictionary can start with a lower case letter. The actual 202function name is not used here. Also see |numbered-function|. 203 204A Funcref can also be used with the |:call| command: > 205 :call Fn() 206 :call dict.init() 207 208The name of the referenced function can be obtained with |string()|. > 209 :let func = string(Fn) 210 211You can use |call()| to invoke a Funcref and use a list variable for the 212arguments: > 213 :let r = call(Fn, mylist) 214< 215 *Partial* 216A Funcref optionally binds a Dictionary and/or arguments. This is also called 217a Partial. This is created by passing the Dictionary and/or arguments to 218function() or funcref(). When calling the function the Dictionary and/or 219arguments will be passed to the function. Example: > 220 221 let Cb = function('Callback', ['foo'], myDict) 222 call Cb('bar') 223 224This will invoke the function as if using: > 225 call myDict.Callback('foo', 'bar') 226 227This is very useful when passing a function around, e.g. in the arguments of 228|ch_open()|. 229 230Note that binding a function to a Dictionary also happens when the function is 231a member of the Dictionary: > 232 233 let myDict.myFunction = MyFunction 234 call myDict.myFunction() 235 236Here MyFunction() will get myDict passed as "self". This happens when the 237"myFunction" member is accessed. When making assigning "myFunction" to 238otherDict and calling it, it will be bound to otherDict: > 239 240 let otherDict.myFunction = myDict.myFunction 241 call otherDict.myFunction() 242 243Now "self" will be "otherDict". But when the dictionary was bound explicitly 244this won't happen: > 245 246 let myDict.myFunction = function(MyFunction, myDict) 247 let otherDict.myFunction = myDict.myFunction 248 call otherDict.myFunction() 249 250Here "self" will be "myDict", because it was bound explicitly. 251 252 2531.3 Lists ~ 254 *list* *List* *Lists* *E686* 255A List is an ordered sequence of items. An item can be of any type. Items 256can be accessed by their index number. Items can be added and removed at any 257position in the sequence. 258 259 260List creation ~ 261 *E696* *E697* 262A List is created with a comma separated list of items in square brackets. 263Examples: > 264 :let mylist = [1, two, 3, "four"] 265 :let emptylist = [] 266 267An item can be any expression. Using a List for an item creates a 268List of Lists: > 269 :let nestlist = [[11, 12], [21, 22], [31, 32]] 270 271An extra comma after the last item is ignored. 272 273 274List index ~ 275 *list-index* *E684* 276An item in the List can be accessed by putting the index in square brackets 277after the List. Indexes are zero-based, thus the first item has index zero. > 278 :let item = mylist[0] " get the first item: 1 279 :let item = mylist[2] " get the third item: 3 280 281When the resulting item is a list this can be repeated: > 282 :let item = nestlist[0][1] " get the first list, second item: 12 283< 284A negative index is counted from the end. Index -1 refers to the last item in 285the List, -2 to the last but one item, etc. > 286 :let last = mylist[-1] " get the last item: "four" 287 288To avoid an error for an invalid index use the |get()| function. When an item 289is not available it returns zero or the default value you specify: > 290 :echo get(mylist, idx) 291 :echo get(mylist, idx, "NONE") 292 293 294List concatenation ~ 295 *list-concatenation* 296Two lists can be concatenated with the "+" operator: > 297 :let longlist = mylist + [5, 6] 298 :let mylist += [7, 8] 299 300To prepend or append an item, turn the item into a list by putting [] around 301it. To change a list in-place, refer to |list-modification| below. 302 303 304Sublist ~ 305 *sublist* 306A part of the List can be obtained by specifying the first and last index, 307separated by a colon in square brackets: > 308 :let shortlist = mylist[2:-1] " get List [3, "four"] 309 310Omitting the first index is similar to zero. Omitting the last index is 311similar to -1. > 312 :let endlist = mylist[2:] " from item 2 to the end: [3, "four"] 313 :let shortlist = mylist[2:2] " List with one item: [3] 314 :let otherlist = mylist[:] " make a copy of the List 315 316Notice that the last index is inclusive. If you prefer using an exclusive 317index use the |slice()| method. 318 319If the first index is beyond the last item of the List or the second item is 320before the first item, the result is an empty list. There is no error 321message. 322 323If the second index is equal to or greater than the length of the list the 324length minus one is used: > 325 :let mylist = [0, 1, 2, 3] 326 :echo mylist[2:8] " result: [2, 3] 327 328NOTE: mylist[s:e] means using the variable "s:e" as index. Watch out for 329using a single letter variable before the ":". Insert a space when needed: 330mylist[s : e]. 331 332 333List identity ~ 334 *list-identity* 335When variable "aa" is a list and you assign it to another variable "bb", both 336variables refer to the same list. Thus changing the list "aa" will also 337change "bb": > 338 :let aa = [1, 2, 3] 339 :let bb = aa 340 :call add(aa, 4) 341 :echo bb 342< [1, 2, 3, 4] 343 344Making a copy of a list is done with the |copy()| function. Using [:] also 345works, as explained above. This creates a shallow copy of the list: Changing 346a list item in the list will also change the item in the copied list: > 347 :let aa = [[1, 'a'], 2, 3] 348 :let bb = copy(aa) 349 :call add(aa, 4) 350 :let aa[0][1] = 'aaa' 351 :echo aa 352< [[1, aaa], 2, 3, 4] > 353 :echo bb 354< [[1, aaa], 2, 3] 355 356To make a completely independent list use |deepcopy()|. This also makes a 357copy of the values in the list, recursively. Up to a hundred levels deep. 358 359The operator "is" can be used to check if two variables refer to the same 360List. "isnot" does the opposite. In contrast "==" compares if two lists have 361the same value. > 362 :let alist = [1, 2, 3] 363 :let blist = [1, 2, 3] 364 :echo alist is blist 365< 0 > 366 :echo alist == blist 367< 1 368 369Note about comparing lists: Two lists are considered equal if they have the 370same length and all items compare equal, as with using "==". There is one 371exception: When comparing a number with a string they are considered 372different. There is no automatic type conversion, as with using "==" on 373variables. Example: > 374 echo 4 == "4" 375< 1 > 376 echo [4] == ["4"] 377< 0 378 379Thus comparing Lists is more strict than comparing numbers and strings. You 380can compare simple values this way too by putting them in a list: > 381 382 :let a = 5 383 :let b = "5" 384 :echo a == b 385< 1 > 386 :echo [a] == [b] 387< 0 388 389 390List unpack ~ 391 392To unpack the items in a list to individual variables, put the variables in 393square brackets, like list items: > 394 :let [var1, var2] = mylist 395 396When the number of variables does not match the number of items in the list 397this produces an error. To handle any extra items from the list append ";" 398and a variable name: > 399 :let [var1, var2; rest] = mylist 400 401This works like: > 402 :let var1 = mylist[0] 403 :let var2 = mylist[1] 404 :let rest = mylist[2:] 405 406Except that there is no error if there are only two items. "rest" will be an 407empty list then. 408 409 410List modification ~ 411 *list-modification* 412To change a specific item of a list use |:let| this way: > 413 :let list[4] = "four" 414 :let listlist[0][3] = item 415 416To change part of a list you can specify the first and last item to be 417modified. The value must at least have the number of items in the range: > 418 :let list[3:5] = [3, 4, 5] 419 420Adding and removing items from a list is done with functions. Here are a few 421examples: > 422 :call insert(list, 'a') " prepend item 'a' 423 :call insert(list, 'a', 3) " insert item 'a' before list[3] 424 :call add(list, "new") " append String item 425 :call add(list, [1, 2]) " append a List as one new item 426 :call extend(list, [1, 2]) " extend the list with two more items 427 :let i = remove(list, 3) " remove item 3 428 :unlet list[3] " idem 429 :let l = remove(list, 3, -1) " remove items 3 to last item 430 :unlet list[3 : ] " idem 431 :call filter(list, 'v:val !~ "x"') " remove items with an 'x' 432 433Changing the order of items in a list: > 434 :call sort(list) " sort a list alphabetically 435 :call reverse(list) " reverse the order of items 436 :call uniq(sort(list)) " sort and remove duplicates 437 438 439For loop ~ 440 441The |:for| loop executes commands for each item in a List, String or Blob. 442A variable is set to each item in sequence. Example with a List: > 443 :for item in mylist 444 : call Doit(item) 445 :endfor 446 447This works like: > 448 :let index = 0 449 :while index < len(mylist) 450 : let item = mylist[index] 451 : :call Doit(item) 452 : let index = index + 1 453 :endwhile 454 455If all you want to do is modify each item in the list then the |map()| 456function will be a simpler method than a for loop. 457 458Just like the |:let| command, |:for| also accepts a list of variables. This 459requires the argument to be a List of Lists. > 460 :for [lnum, col] in [[1, 3], [2, 8], [3, 0]] 461 : call Doit(lnum, col) 462 :endfor 463 464This works like a |:let| command is done for each list item. Again, the types 465must remain the same to avoid an error. 466 467It is also possible to put remaining items in a List variable: > 468 :for [i, j; rest] in listlist 469 : call Doit(i, j) 470 : if !empty(rest) 471 : echo "remainder: " . string(rest) 472 : endif 473 :endfor 474 475For a Blob one byte at a time is used. 476 477For a String one character, including any composing characters, is used as a 478String. Example: > 479 for c in text 480 echo 'This character is ' .. c 481 endfor 482 483 484List functions ~ 485 *E714* 486Functions that are useful with a List: > 487 :let r = call(funcname, list) " call a function with an argument list 488 :if empty(list) " check if list is empty 489 :let l = len(list) " number of items in list 490 :let big = max(list) " maximum value in list 491 :let small = min(list) " minimum value in list 492 :let xs = count(list, 'x') " count nr of times 'x' appears in list 493 :let i = index(list, 'x') " index of first 'x' in list 494 :let lines = getline(1, 10) " get ten text lines from buffer 495 :call append('$', lines) " append text lines in buffer 496 :let list = split("a b c") " create list from items in a string 497 :let string = join(list, ', ') " create string from list items 498 :let s = string(list) " String representation of list 499 :call map(list, '">> " . v:val') " prepend ">> " to each item 500 501Don't forget that a combination of features can make things simple. For 502example, to add up all the numbers in a list: > 503 :exe 'let sum = ' . join(nrlist, '+') 504 505 5061.4 Dictionaries ~ 507 *dict* *Dict* *Dictionaries* *Dictionary* 508A Dictionary is an associative array: Each entry has a key and a value. The 509entry can be located with the key. The entries are stored without a specific 510ordering. 511 512 513Dictionary creation ~ 514 *E720* *E721* *E722* *E723* 515A Dictionary is created with a comma separated list of entries in curly 516braces. Each entry has a key and a value, separated by a colon. Each key can 517only appear once. Examples: > 518 :let mydict = {1: 'one', 2: 'two', 3: 'three'} 519 :let emptydict = {} 520< *E713* *E716* *E717* 521A key is always a String. You can use a Number, it will be converted to a 522String automatically. Thus the String '4' and the number 4 will find the same 523entry. Note that the String '04' and the Number 04 are different, since the 524Number will be converted to the String '4'. The empty string can also be used 525as a key. 526 *literal-Dict* *#{}* 527To avoid having to put quotes around every key the #{} form can be used. This 528does require the key to consist only of ASCII letters, digits, '-' and '_'. 529Example: > 530 :let mydict = #{zero: 0, one_key: 1, two-key: 2, 333: 3} 531Note that 333 here is the string "333". Empty keys are not possible with #{}. 532 533A value can be any expression. Using a Dictionary for a value creates a 534nested Dictionary: > 535 :let nestdict = {1: {11: 'a', 12: 'b'}, 2: {21: 'c'}} 536 537An extra comma after the last entry is ignored. 538 539 540Accessing entries ~ 541 542The normal way to access an entry is by putting the key in square brackets: > 543 :let val = mydict["one"] 544 :let mydict["four"] = 4 545 546You can add new entries to an existing Dictionary this way, unlike Lists. 547 548For keys that consist entirely of letters, digits and underscore the following 549form can be used |expr-entry|: > 550 :let val = mydict.one 551 :let mydict.four = 4 552 553Since an entry can be any type, also a List and a Dictionary, the indexing and 554key lookup can be repeated: > 555 :echo dict.key[idx].key 556 557 558Dictionary to List conversion ~ 559 560You may want to loop over the entries in a dictionary. For this you need to 561turn the Dictionary into a List and pass it to |:for|. 562 563Most often you want to loop over the keys, using the |keys()| function: > 564 :for key in keys(mydict) 565 : echo key . ': ' . mydict[key] 566 :endfor 567 568The List of keys is unsorted. You may want to sort them first: > 569 :for key in sort(keys(mydict)) 570 571To loop over the values use the |values()| function: > 572 :for v in values(mydict) 573 : echo "value: " . v 574 :endfor 575 576If you want both the key and the value use the |items()| function. It returns 577a List in which each item is a List with two items, the key and the value: > 578 :for [key, value] in items(mydict) 579 : echo key . ': ' . value 580 :endfor 581 582 583Dictionary identity ~ 584 *dict-identity* 585Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a 586Dictionary. Otherwise, assignment results in referring to the same 587Dictionary: > 588 :let onedict = {'a': 1, 'b': 2} 589 :let adict = onedict 590 :let adict['a'] = 11 591 :echo onedict['a'] 592 11 593 594Two Dictionaries compare equal if all the key-value pairs compare equal. For 595more info see |list-identity|. 596 597 598Dictionary modification ~ 599 *dict-modification* 600To change an already existing entry of a Dictionary, or to add a new entry, 601use |:let| this way: > 602 :let dict[4] = "four" 603 :let dict['one'] = item 604 605Removing an entry from a Dictionary is done with |remove()| or |:unlet|. 606Three ways to remove the entry with key "aaa" from dict: > 607 :let i = remove(dict, 'aaa') 608 :unlet dict.aaa 609 :unlet dict['aaa'] 610 611Merging a Dictionary with another is done with |extend()|: > 612 :call extend(adict, bdict) 613This extends adict with all entries from bdict. Duplicate keys cause entries 614in adict to be overwritten. An optional third argument can change this. 615Note that the order of entries in a Dictionary is irrelevant, thus don't 616expect ":echo adict" to show the items from bdict after the older entries in 617adict. 618 619Weeding out entries from a Dictionary can be done with |filter()|: > 620 :call filter(dict, 'v:val =~ "x"') 621This removes all entries from "dict" with a value not matching 'x'. 622This can also be used to remove all entries: > 623 call filter(dict, 0) 624 625 626Dictionary function ~ 627 *Dictionary-function* *self* *E725* *E862* 628When a function is defined with the "dict" attribute it can be used in a 629special way with a dictionary. Example: > 630 :function Mylen() dict 631 : return len(self.data) 632 :endfunction 633 :let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} 634 :echo mydict.len() 635 636This is like a method in object oriented programming. The entry in the 637Dictionary is a |Funcref|. The local variable "self" refers to the dictionary 638the function was invoked from. 639 640It is also possible to add a function without the "dict" attribute as a 641Funcref to a Dictionary, but the "self" variable is not available then. 642 643 *numbered-function* *anonymous-function* 644To avoid the extra name for the function it can be defined and directly 645assigned to a Dictionary in this way: > 646 :let mydict = {'data': [0, 1, 2, 3]} 647 :function mydict.len() 648 : return len(self.data) 649 :endfunction 650 :echo mydict.len() 651 652The function will then get a number and the value of dict.len is a |Funcref| 653that references this function. The function can only be used through a 654|Funcref|. It will automatically be deleted when there is no |Funcref| 655remaining that refers to it. 656 657It is not necessary to use the "dict" attribute for a numbered function. 658 659If you get an error for a numbered function, you can find out what it is with 660a trick. Assuming the function is 42, the command is: > 661 :function g:42 662 663 664Functions for Dictionaries ~ 665 *E715* 666Functions that can be used with a Dictionary: > 667 :if has_key(dict, 'foo') " TRUE if dict has entry with key "foo" 668 :if empty(dict) " TRUE if dict is empty 669 :let l = len(dict) " number of items in dict 670 :let big = max(dict) " maximum value in dict 671 :let small = min(dict) " minimum value in dict 672 :let xs = count(dict, 'x') " count nr of times 'x' appears in dict 673 :let s = string(dict) " String representation of dict 674 :call map(dict, '">> " . v:val') " prepend ">> " to each item 675 676 6771.5 Blobs ~ 678 *blob* *Blob* *Blobs* *E978* 679A Blob is a binary object. It can be used to read an image from a file and 680send it over a channel, for example. 681 682A Blob mostly behaves like a |List| of numbers, where each number has the 683value of an 8-bit byte, from 0 to 255. 684 685 686Blob creation ~ 687 688A Blob can be created with a |blob-literal|: > 689 :let b = 0zFF00ED015DAF 690Dots can be inserted between bytes (pair of hex characters) for readability, 691they don't change the value: > 692 :let b = 0zFF00.ED01.5DAF 693 694A blob can be read from a file with |readfile()| passing the {type} argument 695set to "B", for example: > 696 :let b = readfile('image.png', 'B') 697 698A blob can be read from a channel with the |ch_readblob()| function. 699 700 701Blob index ~ 702 *blob-index* *E979* 703A byte in the Blob can be accessed by putting the index in square brackets 704after the Blob. Indexes are zero-based, thus the first byte has index zero. > 705 :let myblob = 0z00112233 706 :let byte = myblob[0] " get the first byte: 0x00 707 :let byte = myblob[2] " get the third byte: 0x22 708 709A negative index is counted from the end. Index -1 refers to the last byte in 710the Blob, -2 to the last but one byte, etc. > 711 :let last = myblob[-1] " get the last byte: 0x33 712 713To avoid an error for an invalid index use the |get()| function. When an item 714is not available it returns -1 or the default value you specify: > 715 :echo get(myblob, idx) 716 :echo get(myblob, idx, 999) 717 718 719Blob iteration ~ 720 721The |:for| loop executes commands for each byte of a Blob. The loop variable is 722set to each byte in the Blob. Example: > 723 :for byte in 0z112233 724 : call Doit(byte) 725 :endfor 726This calls Doit() with 0x11, 0x22 and 0x33. 727 728 729Blob concatenation ~ 730 731Two blobs can be concatenated with the "+" operator: > 732 :let longblob = myblob + 0z4455 733 :let myblob += 0z6677 734 735To change a blob in-place see |blob-modification| below. 736 737 738Part of a blob ~ 739 740A part of the Blob can be obtained by specifying the first and last index, 741separated by a colon in square brackets: > 742 :let myblob = 0z00112233 743 :let shortblob = myblob[1:2] " get 0z1122 744 :let shortblob = myblob[2:-1] " get 0z2233 745 746Omitting the first index is similar to zero. Omitting the last index is 747similar to -1. > 748 :let endblob = myblob[2:] " from item 2 to the end: 0z2233 749 :let shortblob = myblob[2:2] " Blob with one byte: 0z22 750 :let otherblob = myblob[:] " make a copy of the Blob 751 752If the first index is beyond the last byte of the Blob or the second index is 753before the first index, the result is an empty Blob. There is no error 754message. 755 756If the second index is equal to or greater than the length of the list the 757length minus one is used: > 758 :echo myblob[2:8] " result: 0z2233 759 760 761Blob modification ~ 762 *blob-modification* 763To change a specific byte of a blob use |:let| this way: > 764 :let blob[4] = 0x44 765 766When the index is just one beyond the end of the Blob, it is appended. Any 767higher index is an error. 768 769To change a sequence of bytes the [:] notation can be used: > 770 let blob[1:3] = 0z445566 771The length of the replaced bytes must be exactly the same as the value 772provided. *E972* 773 774To change part of a blob you can specify the first and last byte to be 775modified. The value must have the same number of bytes in the range: > 776 :let blob[3:5] = 0z334455 777 778You can also use the functions |add()|, |remove()| and |insert()|. 779 780 781Blob identity ~ 782 783Blobs can be compared for equality: > 784 if blob == 0z001122 785And for equal identity: > 786 if blob is otherblob 787< *blob-identity* *E977* 788When variable "aa" is a Blob and you assign it to another variable "bb", both 789variables refer to the same Blob. Then the "is" operator returns true. 790 791When making a copy using [:] or |copy()| the values are the same, but the 792identity is different: > 793 :let blob = 0z112233 794 :let blob2 = blob 795 :echo blob == blob2 796< 1 > 797 :echo blob is blob2 798< 1 > 799 :let blob3 = blob[:] 800 :echo blob == blob3 801< 1 > 802 :echo blob is blob3 803< 0 804 805Making a copy of a Blob is done with the |copy()| function. Using [:] also 806works, as explained above. 807 808 8091.6 More about variables ~ 810 *more-variables* 811If you need to know the type of a variable or expression, use the |type()| 812function. 813 814When the '!' flag is included in the 'viminfo' option, global variables that 815start with an uppercase letter, and don't contain a lowercase letter, are 816stored in the viminfo file |viminfo-file|. 817 818When the 'sessionoptions' option contains "global", global variables that 819start with an uppercase letter and contain at least one lowercase letter are 820stored in the session file |session-file|. 821 822variable name can be stored where ~ 823my_var_6 not 824My_Var_6 session file 825MY_VAR_6 viminfo file 826 827 828It's possible to form a variable name with curly braces, see 829|curly-braces-names|. 830 831============================================================================== 8322. Expression syntax *expression-syntax* 833 834Expression syntax summary, from least to most significant: 835 836|expr1| expr2 837 expr2 ? expr1 : expr1 if-then-else 838 839|expr2| expr3 840 expr3 || expr3 ... logical OR 841 842|expr3| expr4 843 expr4 && expr4 ... logical AND 844 845|expr4| expr5 846 expr5 == expr5 equal 847 expr5 != expr5 not equal 848 expr5 > expr5 greater than 849 expr5 >= expr5 greater than or equal 850 expr5 < expr5 smaller than 851 expr5 <= expr5 smaller than or equal 852 expr5 =~ expr5 regexp matches 853 expr5 !~ expr5 regexp doesn't match 854 855 expr5 ==? expr5 equal, ignoring case 856 expr5 ==# expr5 equal, match case 857 etc. As above, append ? for ignoring case, # for 858 matching case 859 860 expr5 is expr5 same |List|, |Dictionary| or |Blob| instance 861 expr5 isnot expr5 different |List|, |Dictionary| or |Blob| 862 instance 863 864|expr5| expr6 865 expr6 + expr6 ... number addition, list or blob concatenation 866 expr6 - expr6 ... number subtraction 867 expr6 . expr6 ... string concatenation 868 expr6 .. expr6 ... string concatenation 869 870|expr6| expr7 871 expr7 * expr7 ... number multiplication 872 expr7 / expr7 ... number division 873 expr7 % expr7 ... number modulo 874 875|expr7| expr8 876 ! expr7 logical NOT 877 - expr7 unary minus 878 + expr7 unary plus 879 880|expr8| expr9 881 expr8[expr1] byte of a String or item of a |List| 882 expr8[expr1 : expr1] substring of a String or sublist of a |List| 883 expr8.name entry in a |Dictionary| 884 expr8(expr1, ...) function call with |Funcref| variable 885 expr8->name(expr1, ...) |method| call 886 887|expr9| number number constant 888 "string" string constant, backslash is special 889 'string' string constant, ' is doubled 890 [expr1, ...] |List| 891 {expr1: expr1, ...} |Dictionary| 892 #{key: expr1, ...} |Dictionary| 893 &option option value 894 (expr1) nested expression 895 variable internal variable 896 va{ria}ble internal variable with curly braces 897 $VAR environment variable 898 @r contents of register 'r' 899 function(expr1, ...) function call 900 func{ti}on(expr1, ...) function call with curly braces 901 {args -> expr1} lambda expression 902 903 904"..." indicates that the operations in this level can be concatenated. 905Example: > 906 &nu || &list && &shell == "csh" 907 908All expressions within one level are parsed from left to right. 909 910 911expr1 *expr1* *trinary* *falsy-operator* *??* *E109* 912----- 913 914The trinary operator: expr2 ? expr1 : expr1 915The falsy operator: expr2 ?? expr1 916 917Trinary operator ~ 918 919The expression before the '?' is evaluated to a number. If it evaluates to 920|TRUE|, the result is the value of the expression between the '?' and ':', 921otherwise the result is the value of the expression after the ':'. 922Example: > 923 :echo lnum == 1 ? "top" : lnum 924 925Since the first expression is an "expr2", it cannot contain another ?:. The 926other two expressions can, thus allow for recursive use of ?:. 927Example: > 928 :echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum 929 930To keep this readable, using |line-continuation| is suggested: > 931 :echo lnum == 1 932 :\ ? "top" 933 :\ : lnum == 1000 934 :\ ? "last" 935 :\ : lnum 936 937You should always put a space before the ':', otherwise it can be mistaken for 938use in a variable such as "a:1". 939 940Falsy operator ~ 941 942This is also known as the "null coalescing operator", but that's too 943complicated, thus we just call it the falsy operator. 944 945The expression before the '??' is evaluated. If it evaluates to 946|truthy|, this is used as the result. Otherwise the expression after the '??' 947is evaluated and used as the result. This is most useful to have a default 948value for an expression that may result in zero or empty: > 949 echo theList ?? 'list is empty' 950 echo GetName() ?? 'unknown' 951 952These are similar, but not equal: > 953 expr2 ?? expr1 954 expr2 ? expr2 : expr1 955In the second line "expr2" is evaluated twice. 956 957 958expr2 and expr3 *expr2* *expr3* 959--------------- 960 961expr3 || expr3 .. logical OR *expr-barbar* 962expr4 && expr4 .. logical AND *expr-&&* 963 964The "||" and "&&" operators take one argument on each side. The arguments 965are (converted to) Numbers. The result is: 966 967 input output ~ 968n1 n2 n1 || n2 n1 && n2 ~ 969|FALSE| |FALSE| |FALSE| |FALSE| 970|FALSE| |TRUE| |TRUE| |FALSE| 971|TRUE| |FALSE| |TRUE| |FALSE| 972|TRUE| |TRUE| |TRUE| |TRUE| 973 974The operators can be concatenated, for example: > 975 976 &nu || &list && &shell == "csh" 977 978Note that "&&" takes precedence over "||", so this has the meaning of: > 979 980 &nu || (&list && &shell == "csh") 981 982Once the result is known, the expression "short-circuits", that is, further 983arguments are not evaluated. This is like what happens in C. For example: > 984 985 let a = 1 986 echo a || b 987 988This is valid even if there is no variable called "b" because "a" is |TRUE|, 989so the result must be |TRUE|. Similarly below: > 990 991 echo exists("b") && b == "yes" 992 993This is valid whether "b" has been defined or not. The second clause will 994only be evaluated if "b" has been defined. 995 996 997expr4 *expr4* 998----- 999 1000expr5 {cmp} expr5 1001 1002Compare two expr5 expressions, resulting in a 0 if it evaluates to false, or 1 1003if it evaluates to true. 1004 1005 *expr-==* *expr-!=* *expr->* *expr->=* 1006 *expr-<* *expr-<=* *expr-=~* *expr-!~* 1007 *expr-==#* *expr-!=#* *expr->#* *expr->=#* 1008 *expr-<#* *expr-<=#* *expr-=~#* *expr-!~#* 1009 *expr-==?* *expr-!=?* *expr->?* *expr->=?* 1010 *expr-<?* *expr-<=?* *expr-=~?* *expr-!~?* 1011 *expr-is* *expr-isnot* *expr-is#* *expr-isnot#* 1012 *expr-is?* *expr-isnot?* 1013 use 'ignorecase' match case ignore case ~ 1014equal == ==# ==? 1015not equal != !=# !=? 1016greater than > ># >? 1017greater than or equal >= >=# >=? 1018smaller than < <# <? 1019smaller than or equal <= <=# <=? 1020regexp matches =~ =~# =~? 1021regexp doesn't match !~ !~# !~? 1022same instance is is# is? 1023different instance isnot isnot# isnot? 1024 1025Examples: 1026"abc" ==# "Abc" evaluates to 0 1027"abc" ==? "Abc" evaluates to 1 1028"abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise 1029 1030 *E691* *E692* 1031A |List| can only be compared with a |List| and only "equal", "not equal", 1032"is" and "isnot" can be used. This compares the values of the list, 1033recursively. Ignoring case means case is ignored when comparing item values. 1034 1035 *E735* *E736* 1036A |Dictionary| can only be compared with a |Dictionary| and only "equal", "not 1037equal", "is" and "isnot" can be used. This compares the key/values of the 1038|Dictionary| recursively. Ignoring case means case is ignored when comparing 1039item values. 1040 1041 *E694* 1042A |Funcref| can only be compared with a |Funcref| and only "equal", "not 1043equal", "is" and "isnot" can be used. Case is never ignored. Whether 1044arguments or a Dictionary are bound (with a partial) matters. The 1045Dictionaries must also be equal (or the same, in case of "is") and the 1046arguments must be equal (or the same). 1047 1048To compare Funcrefs to see if they refer to the same function, ignoring bound 1049Dictionary and arguments, use |get()| to get the function name: > 1050 if get(Part1, 'name') == get(Part2, 'name') 1051 " Part1 and Part2 refer to the same function 1052 1053Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether 1054the expressions are referring to the same |List|, |Dictionary| or |Blob| 1055instance. A copy of a |List| is different from the original |List|. When 1056using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to 1057using "equal", using "isnot" equivalent to using "not equal". Except that 1058a different type means the values are different: > 1059 echo 4 == '4' 1060 1 1061 echo 4 is '4' 1062 0 1063 echo 0 is [] 1064 0 1065"is#"/"isnot#" and "is?"/"isnot?" can be used to match and ignore case. 1066 1067When comparing a String with a Number, the String is converted to a Number, 1068and the comparison is done on Numbers. This means that: > 1069 echo 0 == 'x' 1070 1 1071because 'x' converted to a Number is zero. However: > 1072 echo [0] == ['x'] 1073 0 1074Inside a List or Dictionary this conversion is not used. 1075 1076When comparing two Strings, this is done with strcmp() or stricmp(). This 1077results in the mathematical difference (comparing byte values), not 1078necessarily the alphabetical difference in the local language. 1079 1080When using the operators with a trailing '#', or the short version and 1081'ignorecase' is off, the comparing is done with strcmp(): case matters. 1082 1083When using the operators with a trailing '?', or the short version and 1084'ignorecase' is set, the comparing is done with stricmp(): case is ignored. 1085 1086'smartcase' is not used. 1087 1088The "=~" and "!~" operators match the lefthand argument with the righthand 1089argument, which is used as a pattern. See |pattern| for what a pattern is. 1090This matching is always done like 'magic' was set and 'cpoptions' is empty, no 1091matter what the actual value of 'magic' or 'cpoptions' is. This makes scripts 1092portable. To avoid backslashes in the regexp pattern to be doubled, use a 1093single-quote string, see |literal-string|. 1094Since a string is considered to be a single line, a multi-line pattern 1095(containing \n, backslash-n) will not match. However, a literal NL character 1096can be matched like an ordinary character. Examples: 1097 "foo\nbar" =~ "\n" evaluates to 1 1098 "foo\nbar" =~ "\\n" evaluates to 0 1099 1100 1101expr5 and expr6 *expr5* *expr6* 1102--------------- 1103expr6 + expr6 Number addition, |List| or |Blob| concatenation *expr-+* 1104expr6 - expr6 Number subtraction *expr--* 1105expr6 . expr6 String concatenation *expr-.* 1106expr6 .. expr6 String concatenation *expr-..* 1107 1108For |Lists| only "+" is possible and then both expr6 must be a list. The 1109result is a new list with the two lists Concatenated. 1110 1111For String concatenation ".." is preferred, since "." is ambiguous, it is also 1112used for |Dict| member access and floating point numbers. 1113When |vimscript-version| is 2 or higher, using "." is not allowed. 1114 1115expr7 * expr7 Number multiplication *expr-star* 1116expr7 / expr7 Number division *expr-/* 1117expr7 % expr7 Number modulo *expr-%* 1118 1119For all, except "." and "..", Strings are converted to Numbers. 1120For bitwise operators see |and()|, |or()| and |xor()|. 1121 1122Note the difference between "+" and ".": 1123 "123" + "456" = 579 1124 "123" . "456" = "123456" 1125 1126Since '.' has the same precedence as '+' and '-', you need to read: > 1127 1 . 90 + 90.0 1128As: > 1129 (1 . 90) + 90.0 1130That works, since the String "190" is automatically converted to the Number 1131190, which can be added to the Float 90.0. However: > 1132 1 . 90 * 90.0 1133Should be read as: > 1134 1 . (90 * 90.0) 1135Since '.' has lower precedence than '*'. This does NOT work, since this 1136attempts to concatenate a Float and a String. 1137 1138When dividing a Number by zero the result depends on the value: 1139 0 / 0 = -0x80000000 (like NaN for Float) 1140 >0 / 0 = 0x7fffffff (like positive infinity) 1141 <0 / 0 = -0x7fffffff (like negative infinity) 1142 (before Vim 7.2 it was always 0x7fffffff) 1143 1144When 64-bit Number support is enabled: 1145 0 / 0 = -0x8000000000000000 (like NaN for Float) 1146 >0 / 0 = 0x7fffffffffffffff (like positive infinity) 1147 <0 / 0 = -0x7fffffffffffffff (like negative infinity) 1148 1149When the righthand side of '%' is zero, the result is 0. 1150 1151None of these work for |Funcref|s. 1152 1153. and % do not work for Float. *E804* 1154 1155 1156expr7 *expr7* 1157----- 1158! expr7 logical NOT *expr-!* 1159- expr7 unary minus *expr-unary--* 1160+ expr7 unary plus *expr-unary-+* 1161 1162For '!' |TRUE| becomes |FALSE|, |FALSE| becomes |TRUE| (one). 1163For '-' the sign of the number is changed. 1164For '+' the number is unchanged. Note: "++" has no effect. 1165 1166A String will be converted to a Number first. 1167 1168These three can be repeated and mixed. Examples: 1169 !-1 == 0 1170 !!8 == 1 1171 --9 == 9 1172 1173 1174expr8 *expr8* 1175----- 1176This expression is either |expr9| or a sequence of the alternatives below, 1177in any order. E.g., these are all possible: 1178 expr8[expr1].name 1179 expr8.name[expr1] 1180 expr8(expr1, ...)[expr1].name 1181 expr8->(expr1, ...)[expr1] 1182Evaluation is always from left to right. 1183 1184expr8[expr1] item of String or |List| *expr-[]* *E111* 1185 *E909* *subscript* 1186In legacy Vim script: 1187If expr8 is a Number or String this results in a String that contains the 1188expr1'th single byte from expr8. expr8 is used as a String (a number is 1189automatically converted to a String), expr1 as a Number. This doesn't 1190recognize multibyte encodings, see `byteidx()` for an alternative, or use 1191`split()` to turn the string into a list of characters. Example, to get the 1192byte under the cursor: > 1193 :let c = getline(".")[col(".") - 1] 1194 1195In Vim9 script: 1196If expr8 is a String this results in a String that contains the expr1'th 1197single character (including any composing characters) from expr8. To use byte 1198indexes use |strpart()|. 1199 1200Index zero gives the first byte or character. Careful: text column numbers 1201start with one! 1202 1203If the length of the String is less than the index, the result is an empty 1204String. A negative index always results in an empty string (reason: backward 1205compatibility). Use [-1:] to get the last byte or character. 1206In Vim9 script a negative index is used like with a list: count from the end. 1207 1208If expr8 is a |List| then it results the item at index expr1. See |list-index| 1209for possible index values. If the index is out of range this results in an 1210error. Example: > 1211 :let item = mylist[-1] " get last item 1212 1213Generally, if a |List| index is equal to or higher than the length of the 1214|List|, or more negative than the length of the |List|, this results in an 1215error. 1216 1217 1218expr8[expr1a : expr1b] substring or sublist *expr-[:]* 1219 1220If expr8 is a String this results in the substring with the bytes or 1221characters from expr1a to and including expr1b. expr8 is used as a String, 1222expr1a and expr1b are used as a Number. 1223 1224In legacy Vim script the indexes are byte indexes. This doesn't recognize 1225multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is 1226a Number it is first converted to a String. 1227 1228In Vim9 script the indexes are character indexes and include composing 1229characters. To use byte indexes use |strpart()|. To use character indexes 1230without including composing characters use |strcharpart()|. 1231 1232The item at index expr1b is included, it is inclusive. For an exclusive index 1233use the |slice()| function. 1234 1235If expr1a is omitted zero is used. If expr1b is omitted the length of the 1236string minus one is used. 1237 1238A negative number can be used to measure from the end of the string. -1 is 1239the last character, -2 the last but one, etc. 1240 1241If an index goes out of range for the string characters are omitted. If 1242expr1b is smaller than expr1a the result is an empty string. 1243 1244Examples: > 1245 :let c = name[-1:] " last byte of a string 1246 :let c = name[0:-1] " the whole string 1247 :let c = name[-2:-2] " last but one byte of a string 1248 :let s = line(".")[4:] " from the fifth byte to the end 1249 :let s = s[:-3] " remove last two bytes 1250< 1251 *slice* 1252If expr8 is a |List| this results in a new |List| with the items indicated by 1253the indexes expr1a and expr1b. This works like with a String, as explained 1254just above. Also see |sublist| below. Examples: > 1255 :let l = mylist[:3] " first four items 1256 :let l = mylist[4:4] " List with one item 1257 :let l = mylist[:] " shallow copy of a List 1258 1259If expr8 is a |Blob| this results in a new |Blob| with the bytes in the 1260indexes expr1a and expr1b, inclusive. Examples: > 1261 :let b = 0zDEADBEEF 1262 :let bs = b[1:2] " 0zADBE 1263 :let bs = b[:] " copy of 0zDEADBEEF 1264 1265Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an 1266error. 1267 1268Watch out for confusion between a namespace and a variable followed by a colon 1269for a sublist: > 1270 mylist[n:] " uses variable n 1271 mylist[s:] " uses namespace s:, error! 1272 1273 1274expr8.name entry in a |Dictionary| *expr-entry* 1275 1276If expr8 is a |Dictionary| and it is followed by a dot, then the following 1277name will be used as a key in the |Dictionary|. This is just like: 1278expr8[name]. 1279 1280The name must consist of alphanumeric characters, just like a variable name, 1281but it may start with a number. Curly braces cannot be used. 1282 1283There must not be white space before or after the dot. 1284 1285Examples: > 1286 :let dict = {"one": 1, 2: "two"} 1287 :echo dict.one " shows "1" 1288 :echo dict.2 " shows "two" 1289 :echo dict .2 " error because of space before the dot 1290 1291Note that the dot is also used for String concatenation. To avoid confusion 1292always put spaces around the dot for String concatenation. 1293 1294 1295expr8(expr1, ...) |Funcref| function call 1296 1297When expr8 is a |Funcref| type variable, invoke the function it refers to. 1298 1299 1300expr8->name([args]) method call *method* *->* 1301expr8->{lambda}([args]) 1302 *E276* 1303For methods that are also available as global functions this is the same as: > 1304 name(expr8 [, args]) 1305There can also be methods specifically for the type of "expr8". 1306 1307This allows for chaining, passing the value that one method returns to the 1308next method: > 1309 mylist->filter(filterexpr)->map(mapexpr)->sort()->join() 1310< 1311Example of using a lambda: > 1312 GetPercentage()->{x -> x * 100}()->printf('%d%%') 1313< 1314When using -> the |expr7| operators will be applied first, thus: > 1315 -1.234->string() 1316Is equivalent to: > 1317 (-1.234)->string() 1318And NOT: > 1319 -(1.234->string()) 1320< 1321 *E274* 1322"->name(" must not contain white space. There can be white space before the 1323"->" and after the "(", thus you can split the lines like this: > 1324 mylist 1325 \ ->filter(filterexpr) 1326 \ ->map(mapexpr) 1327 \ ->sort() 1328 \ ->join() 1329 1330When using the lambda form there must be no white space between the } and the 1331(. 1332 1333 1334 *expr9* 1335number 1336------ 1337number number constant *expr-number* 1338 1339 *0x* *hex-number* *0o* *octal-number* *binary-number* 1340Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B) 1341and Octal (starting with 0, 0o or 0O). 1342 1343 *floating-point-format* 1344Floating point numbers can be written in two forms: 1345 1346 [-+]{N}.{M} 1347 [-+]{N}.{M}[eE][-+]{exp} 1348 1349{N} and {M} are numbers. Both {N} and {M} must be present and can only 1350contain digits, except that in |Vim9| script in {N} single quotes between 1351digits are ignored. 1352[-+] means there is an optional plus or minus sign. 1353{exp} is the exponent, power of 10. 1354Only a decimal point is accepted, not a comma. No matter what the current 1355locale is. 1356{only when compiled with the |+float| feature} 1357 1358Examples: 1359 123.456 1360 +0.0001 1361 55.0 1362 -0.123 1363 1.234e03 1364 1.0E-6 1365 -3.1416e+88 1366 1367These are INVALID: 1368 3. empty {M} 1369 1e40 missing .{M} 1370 1371Rationale: 1372Before floating point was introduced, the text "123.456" was interpreted as 1373the two numbers "123" and "456", both converted to a string and concatenated, 1374resulting in the string "123456". Since this was considered pointless, and we 1375could not find it intentionally being used in Vim scripts, this backwards 1376incompatibility was accepted in favor of being able to use the normal notation 1377for floating point numbers. 1378 1379 *float-pi* *float-e* 1380A few useful values to copy&paste: > 1381 :let pi = 3.14159265359 1382 :let e = 2.71828182846 1383Or, if you don't want to write them in as floating-point literals, you can 1384also use functions, like the following: > 1385 :let pi = acos(-1.0) 1386 :let e = exp(1.0) 1387< 1388 *floating-point-precision* 1389The precision and range of floating points numbers depends on what "double" 1390means in the library Vim was compiled with. There is no way to change this at 1391runtime. 1392 1393The default for displaying a |Float| is to use 6 decimal places, like using 1394printf("%g", f). You can select something else when using the |printf()| 1395function. Example: > 1396 :echo printf('%.15e', atan(1)) 1397< 7.853981633974483e-01 1398 1399 1400 1401string *string* *String* *expr-string* *E114* 1402------ 1403"string" string constant *expr-quote* 1404 1405Note that double quotes are used. 1406 1407A string constant accepts these special characters: 1408\... three-digit octal number (e.g., "\316") 1409\.. two-digit octal number (must be followed by non-digit) 1410\. one-digit octal number (must be followed by non-digit) 1411\x.. byte specified with two hex numbers (e.g., "\x1f") 1412\x. byte specified with one hex number (must be followed by non-hex char) 1413\X.. same as \x.. 1414\X. same as \x. 1415\u.... character specified with up to 4 hex numbers, stored according to the 1416 current value of 'encoding' (e.g., "\u02a4") 1417\U.... same as \u but allows up to 8 hex numbers. 1418\b backspace <BS> 1419\e escape <Esc> 1420\f formfeed 0x0C 1421\n newline <NL> 1422\r return <CR> 1423\t tab <Tab> 1424\\ backslash 1425\" double quote 1426\<xxx> Special key named "xxx". e.g. "\<C-W>" for CTRL-W. This is for use 1427 in mappings, the 0x80 byte is escaped. 1428 To use the double quote character it must be escaped: "<M-\">". 1429 Don't use <Char-xxxx> to get a UTF-8 character, use \uxxxx as 1430 mentioned above. 1431\<*xxx> Like \<xxx> but prepends a modifier instead of including it in the 1432 character. E.g. "\<C-w>" is one character 0x17 while "\<*C-w>" is four 1433 bytes: 3 for the CTRL modifier and then character "W". 1434 1435Note that "\xff" is stored as the byte 255, which may be invalid in some 1436encodings. Use "\u00ff" to store character 255 according to the current value 1437of 'encoding'. 1438 1439Note that "\000" and "\x00" force the end of the string. 1440 1441 1442blob-literal *blob-literal* *E973* 1443------------ 1444 1445Hexadecimal starting with 0z or 0Z, with an arbitrary number of bytes. 1446The sequence must be an even number of hex characters. Example: > 1447 :let b = 0zFF00ED015DAF 1448 1449 1450literal-string *literal-string* *E115* 1451--------------- 1452'string' string constant *expr-'* 1453 1454Note that single quotes are used. 1455 1456This string is taken as it is. No backslashes are removed or have a special 1457meaning. The only exception is that two quotes stand for one quote. 1458 1459Single quoted strings are useful for patterns, so that backslashes do not need 1460to be doubled. These two commands are equivalent: > 1461 if a =~ "\\s*" 1462 if a =~ '\s*' 1463 1464 1465option *expr-option* *E112* *E113* 1466------ 1467&option option value, local value if possible 1468&g:option global option value 1469&l:option local option value 1470 1471Examples: > 1472 echo "tabstop is " . &tabstop 1473 if &insertmode 1474 1475Any option name can be used here. See |options|. When using the local value 1476and there is no buffer-local or window-local value, the global value is used 1477anyway. 1478 1479 1480register *expr-register* *@r* 1481-------- 1482@r contents of register 'r' 1483 1484The result is the contents of the named register, as a single string. 1485Newlines are inserted where required. To get the contents of the unnamed 1486register use @" or @@. See |registers| for an explanation of the available 1487registers. 1488 1489When using the '=' register you get the expression itself, not what it 1490evaluates to. Use |eval()| to evaluate it. 1491 1492 1493nesting *expr-nesting* *E110* 1494------- 1495(expr1) nested expression 1496 1497 1498environment variable *expr-env* 1499-------------------- 1500$VAR environment variable 1501 1502The String value of any environment variable. When it is not defined, the 1503result is an empty string. 1504 1505The functions `getenv()` and `setenv()` can also be used and work for 1506environment variables with non-alphanumeric names. 1507The function `environ()` can be used to get a Dict with all environment 1508variables. 1509 1510 1511 *expr-env-expand* 1512Note that there is a difference between using $VAR directly and using 1513expand("$VAR"). Using it directly will only expand environment variables that 1514are known inside the current Vim session. Using expand() will first try using 1515the environment variables known inside the current Vim session. If that 1516fails, a shell will be used to expand the variable. This can be slow, but it 1517does expand all variables that the shell knows about. Example: > 1518 :echo $shell 1519 :echo expand("$shell") 1520The first one probably doesn't echo anything, the second echoes the $shell 1521variable (if your shell supports it). 1522 1523 1524internal variable *expr-variable* 1525----------------- 1526variable internal variable 1527See below |internal-variables|. 1528 1529 1530function call *expr-function* *E116* *E118* *E119* *E120* 1531------------- 1532function(expr1, ...) function call 1533See below |functions|. 1534 1535 1536lambda expression *expr-lambda* *lambda* 1537----------------- 1538{args -> expr1} lambda expression 1539 1540A lambda expression creates a new unnamed function which returns the result of 1541evaluating |expr1|. Lambda expressions differ from |user-functions| in 1542the following ways: 1543 15441. The body of the lambda expression is an |expr1| and not a sequence of |Ex| 1545 commands. 15462. The prefix "a:" should not be used for arguments. E.g.: > 1547 :let F = {arg1, arg2 -> arg1 - arg2} 1548 :echo F(5, 2) 1549< 3 1550 1551The arguments are optional. Example: > 1552 :let F = {-> 'error function'} 1553 :echo F('ignored') 1554< error function 1555 1556Note that in Vim9 script another kind of lambda can be used: |vim9-lambda|. 1557 1558 *closure* 1559Lambda expressions can access outer scope variables and arguments. This is 1560often called a closure. Example where "i" and "a:arg" are used in a lambda 1561while they already exist in the function scope. They remain valid even after 1562the function returns: > 1563 :function Foo(arg) 1564 : let i = 3 1565 : return {x -> x + i - a:arg} 1566 :endfunction 1567 :let Bar = Foo(4) 1568 :echo Bar(6) 1569< 5 1570 1571Note that the variables must exist in the outer scope before the lambda is 1572defined for this to work. See also |:func-closure|. 1573 1574Lambda and closure support can be checked with: > 1575 if has('lambda') 1576 1577Examples for using a lambda expression with |sort()|, |map()| and |filter()|: > 1578 :echo map([1, 2, 3], {idx, val -> val + 1}) 1579< [2, 3, 4] > 1580 :echo sort([3,7,2,1,4], {a, b -> a - b}) 1581< [1, 2, 3, 4, 7] 1582 1583The lambda expression is also useful for Channel, Job and timer: > 1584 :let timer = timer_start(500, 1585 \ {-> execute("echo 'Handler called'", "")}, 1586 \ {'repeat': 3}) 1587< Handler called 1588 Handler called 1589 Handler called 1590 1591Note that it is possible to cause memory to be used and not freed if the 1592closure is referenced by the context it depends on: > 1593 function Function() 1594 let x = 0 1595 let F = {-> x} 1596 endfunction 1597The closure uses "x" from the function scope, and "F" in that same scope 1598refers to the closure. This cycle results in the memory not being freed. 1599Recommendation: don't do this. 1600 1601Notice how execute() is used to execute an Ex command. That's ugly though. 1602In Vim9 script you can use a command block, see |inline-function|. 1603 1604Lambda expressions have internal names like '<lambda>42'. If you get an error 1605for a lambda expression, you can find what it is with the following command: > 1606 :function <lambda>42 1607See also: |numbered-function| 1608 1609============================================================================== 16103. Internal variable *internal-variables* *E461* 1611 1612An internal variable name can be made up of letters, digits and '_'. But it 1613cannot start with a digit. It's also possible to use curly braces, see 1614|curly-braces-names|. 1615 1616An internal variable is created with the ":let" command |:let|. 1617An internal variable is explicitly destroyed with the ":unlet" command 1618|:unlet|. 1619Using a name that is not an internal variable or refers to a variable that has 1620been destroyed results in an error. 1621 1622 *variable-scope* 1623There are several name spaces for variables. Which one is to be used is 1624specified by what is prepended: 1625 1626 (nothing) In a function: local to a function; otherwise: global 1627|buffer-variable| b: Local to the current buffer. 1628|window-variable| w: Local to the current window. 1629|tabpage-variable| t: Local to the current tab page. 1630|global-variable| g: Global. 1631|local-variable| l: Local to a function. 1632|script-variable| s: Local to a |:source|'ed Vim script. 1633|function-argument| a: Function argument (only inside a function). 1634|vim-variable| v: Global, predefined by Vim. 1635 1636The scope name by itself can be used as a |Dictionary|. For example, to 1637delete all script-local variables: > 1638 :for k in keys(s:) 1639 : unlet s:[k] 1640 :endfor 1641 1642Note: in Vim9 script this is different, see |vim9-scopes|. 1643 1644 *buffer-variable* *b:var* *b:* 1645A variable name that is preceded with "b:" is local to the current buffer. 1646Thus you can have several "b:foo" variables, one for each buffer. 1647This kind of variable is deleted when the buffer is wiped out or deleted with 1648|:bdelete|. 1649 1650One local buffer variable is predefined: 1651 *b:changedtick* *changetick* 1652b:changedtick The total number of changes to the current buffer. It is 1653 incremented for each change. An undo command is also a change 1654 in this case. Resetting 'modified' when writing the buffer is 1655 also counted. 1656 This can be used to perform an action only when the buffer has 1657 changed. Example: > 1658 :if my_changedtick != b:changedtick 1659 : let my_changedtick = b:changedtick 1660 : call My_Update() 1661 :endif 1662< You cannot change or delete the b:changedtick variable. 1663 1664 *window-variable* *w:var* *w:* 1665A variable name that is preceded with "w:" is local to the current window. It 1666is deleted when the window is closed. 1667 1668 *tabpage-variable* *t:var* *t:* 1669A variable name that is preceded with "t:" is local to the current tab page, 1670It is deleted when the tab page is closed. {not available when compiled 1671without the |+windows| feature} 1672 1673 *global-variable* *g:var* *g:* 1674Inside functions global variables are accessed with "g:". Omitting this will 1675access a variable local to a function. But "g:" can also be used in any other 1676place if you like. 1677 1678 *local-variable* *l:var* *l:* 1679Inside functions local variables are accessed without prepending anything. 1680But you can also prepend "l:" if you like. However, without prepending "l:" 1681you may run into reserved variable names. For example "count". By itself it 1682refers to "v:count". Using "l:count" you can have a local variable with the 1683same name. 1684 1685 *script-variable* *s:var* 1686In a Vim script variables starting with "s:" can be used. They cannot be 1687accessed from outside of the scripts, thus are local to the script. 1688 1689They can be used in: 1690- commands executed while the script is sourced 1691- functions defined in the script 1692- autocommands defined in the script 1693- functions and autocommands defined in functions and autocommands which were 1694 defined in the script (recursively) 1695- user defined commands defined in the script 1696Thus not in: 1697- other scripts sourced from this one 1698- mappings 1699- menus 1700- etc. 1701 1702Script variables can be used to avoid conflicts with global variable names. 1703Take this example: > 1704 1705 let s:counter = 0 1706 function MyCounter() 1707 let s:counter = s:counter + 1 1708 echo s:counter 1709 endfunction 1710 command Tick call MyCounter() 1711 1712You can now invoke "Tick" from any script, and the "s:counter" variable in 1713that script will not be changed, only the "s:counter" in the script where 1714"Tick" was defined is used. 1715 1716Another example that does the same: > 1717 1718 let s:counter = 0 1719 command Tick let s:counter = s:counter + 1 | echo s:counter 1720 1721When calling a function and invoking a user-defined command, the context for 1722script variables is set to the script where the function or command was 1723defined. 1724 1725The script variables are also available when a function is defined inside a 1726function that is defined in a script. Example: > 1727 1728 let s:counter = 0 1729 function StartCounting(incr) 1730 if a:incr 1731 function MyCounter() 1732 let s:counter = s:counter + 1 1733 endfunction 1734 else 1735 function MyCounter() 1736 let s:counter = s:counter - 1 1737 endfunction 1738 endif 1739 endfunction 1740 1741This defines the MyCounter() function either for counting up or counting down 1742when calling StartCounting(). It doesn't matter from where StartCounting() is 1743called, the s:counter variable will be accessible in MyCounter(). 1744 1745When the same script is sourced again it will use the same script variables. 1746They will remain valid as long as Vim is running. This can be used to 1747maintain a counter: > 1748 1749 if !exists("s:counter") 1750 let s:counter = 1 1751 echo "script executed for the first time" 1752 else 1753 let s:counter = s:counter + 1 1754 echo "script executed " . s:counter . " times now" 1755 endif 1756 1757Note that this means that filetype plugins don't get a different set of script 1758variables for each buffer. Use local buffer variables instead |b:var|. 1759 1760 1761PREDEFINED VIM VARIABLES *vim-variable* *v:var* *v:* 1762 *E963* 1763Some variables can be set by the user, but the type cannot be changed. 1764 1765 *v:argv* *argv-variable* 1766v:argv The command line arguments Vim was invoked with. This is a 1767 list of strings. The first item is the Vim command. 1768 1769 *v:beval_col* *beval_col-variable* 1770v:beval_col The number of the column, over which the mouse pointer is. 1771 This is the byte index in the |v:beval_lnum| line. 1772 Only valid while evaluating the 'balloonexpr' option. 1773 1774 *v:beval_bufnr* *beval_bufnr-variable* 1775v:beval_bufnr The number of the buffer, over which the mouse pointer is. Only 1776 valid while evaluating the 'balloonexpr' option. 1777 1778 *v:beval_lnum* *beval_lnum-variable* 1779v:beval_lnum The number of the line, over which the mouse pointer is. Only 1780 valid while evaluating the 'balloonexpr' option. 1781 1782 *v:beval_text* *beval_text-variable* 1783v:beval_text The text under or after the mouse pointer. Usually a word as 1784 it is useful for debugging a C program. 'iskeyword' applies, 1785 but a dot and "->" before the position is included. When on a 1786 ']' the text before it is used, including the matching '[' and 1787 word before it. When on a Visual area within one line the 1788 highlighted text is used. Also see |<cexpr>|. 1789 Only valid while evaluating the 'balloonexpr' option. 1790 1791 *v:beval_winnr* *beval_winnr-variable* 1792v:beval_winnr The number of the window, over which the mouse pointer is. Only 1793 valid while evaluating the 'balloonexpr' option. The first 1794 window has number zero (unlike most other places where a 1795 window gets a number). 1796 1797 *v:beval_winid* *beval_winid-variable* 1798v:beval_winid The |window-ID| of the window, over which the mouse pointer 1799 is. Otherwise like v:beval_winnr. 1800 1801 *v:char* *char-variable* 1802v:char Argument for evaluating 'formatexpr' and used for the typed 1803 character when using <expr> in an abbreviation |:map-<expr>|. 1804 It is also used by the |InsertCharPre| and |InsertEnter| events. 1805 1806 *v:charconvert_from* *charconvert_from-variable* 1807v:charconvert_from 1808 The name of the character encoding of a file to be converted. 1809 Only valid while evaluating the 'charconvert' option. 1810 1811 *v:charconvert_to* *charconvert_to-variable* 1812v:charconvert_to 1813 The name of the character encoding of a file after conversion. 1814 Only valid while evaluating the 'charconvert' option. 1815 1816 *v:cmdarg* *cmdarg-variable* 1817v:cmdarg This variable is used for two purposes: 1818 1. The extra arguments given to a file read/write command. 1819 Currently these are "++enc=" and "++ff=". This variable is 1820 set before an autocommand event for a file read/write 1821 command is triggered. There is a leading space to make it 1822 possible to append this variable directly after the 1823 read/write command. Note: The "+cmd" argument isn't 1824 included here, because it will be executed anyway. 1825 2. When printing a PostScript file with ":hardcopy" this is 1826 the argument for the ":hardcopy" command. This can be used 1827 in 'printexpr'. 1828 1829 *v:cmdbang* *cmdbang-variable* 1830v:cmdbang Set like v:cmdarg for a file read/write command. When a "!" 1831 was used the value is 1, otherwise it is 0. Note that this 1832 can only be used in autocommands. For user commands |<bang>| 1833 can be used. 1834 *v:collate* *collate-variable* 1835v:collate The current locale setting for collation order of the runtime 1836 environment. This allows Vim scripts to be aware of the 1837 current locale encoding. Technical: it's the value of 1838 LC_COLLATE. When not using a locale the value is "C". 1839 This variable can not be set directly, use the |:language| 1840 command. 1841 See |multi-lang|. 1842 1843 *v:colornames* 1844v:colornames A dictionary that maps color names to hex color strings. These 1845 color names can be used with the |highlight-guifg|, 1846 |highlight-guibg|, and |highlight-guisp| parameters. Updating 1847 an entry in v:colornames has no immediate effect on the syntax 1848 highlighting. The highlight commands (probably in a 1849 colorscheme script) need to be re-evaluated in order to use 1850 the updated color values. For example: > 1851 1852 :let v:colornames['fuscia'] = '#cf3ab4' 1853 :let v:colornames['mauve'] = '#915f6d' 1854 :highlight Normal guifg=fuscia guibg=mauve 1855< 1856 This cannot be used to override the |cterm-colors| but it can 1857 be used to override other colors. For example, the X11 colors 1858 defined in the `colors/lists/default.vim` (previously defined 1859 in |rgb.txt|). When defining new color names in a plugin, the 1860 recommended practice is to set a color entry only when it does 1861 not already exist. For example: > 1862 1863 :call extend(v:colornames, { 1864 \ 'fuscia': '#cf3ab4', 1865 \ 'mauve': '#915f6d, 1866 \ }, 'keep') 1867< 1868 Using |extend()| with the 'keep' option updates each color only 1869 if it did not exist in |v:colornames|. Doing so allows the 1870 user to choose the precise color value for a common name 1871 by setting it in their |.vimrc|. 1872 1873 It is possible to remove entries from this dictionary but 1874 doing so is NOT recommended, because it is disruptive to 1875 other scripts. It is also unlikely to achieve the desired 1876 result because the |:colorscheme| and |:highlight| commands will 1877 both automatically load all `colors/lists/default.vim` color 1878 scripts. 1879 1880 *v:completed_item* *completed_item-variable* 1881v:completed_item 1882 |Dictionary| containing the |complete-items| for the most 1883 recently completed word after |CompleteDone|. The 1884 |Dictionary| is empty if the completion failed. 1885 1886 *v:count* *count-variable* 1887v:count The count given for the last Normal mode command. Can be used 1888 to get the count before a mapping. Read-only. Example: > 1889 :map _x :<C-U>echo "the count is " . v:count<CR> 1890< Note: The <C-U> is required to remove the line range that you 1891 get when typing ':' after a count. 1892 When there are two counts, as in "3d2w", they are multiplied, 1893 just like what happens in the command, "d6w" for the example. 1894 Also used for evaluating the 'formatexpr' option. 1895 "count" also works, for backwards compatibility, unless 1896 |scriptversion| is 3 or higher. 1897 1898 *v:count1* *count1-variable* 1899v:count1 Just like "v:count", but defaults to one when no count is 1900 used. 1901 1902 *v:ctype* *ctype-variable* 1903v:ctype The current locale setting for characters of the runtime 1904 environment. This allows Vim scripts to be aware of the 1905 current locale encoding. Technical: it's the value of 1906 LC_CTYPE. When not using a locale the value is "C". 1907 This variable can not be set directly, use the |:language| 1908 command. 1909 See |multi-lang|. 1910 1911 *v:dying* *dying-variable* 1912v:dying Normally zero. When a deadly signal is caught it's set to 1913 one. When multiple signals are caught the number increases. 1914 Can be used in an autocommand to check if Vim didn't 1915 terminate normally. {only works on Unix} 1916 Example: > 1917 :au VimLeave * if v:dying | echo "\nAAAAaaaarrrggghhhh!!!\n" | endif 1918< Note: if another deadly signal is caught when v:dying is one, 1919 VimLeave autocommands will not be executed. 1920 1921 *v:exiting* *exiting-variable* 1922v:exiting Vim exit code. Normally zero, non-zero when something went 1923 wrong. The value is v:null before invoking the |VimLeavePre| 1924 and |VimLeave| autocmds. See |:q|, |:x| and |:cquit|. 1925 Example: > 1926 :au VimLeave * echo "Exit value is " .. v:exiting 1927< 1928 *v:echospace* *echospace-variable* 1929v:echospace Number of screen cells that can be used for an `:echo` message 1930 in the last screen line before causing the |hit-enter-prompt|. 1931 Depends on 'showcmd', 'ruler' and 'columns'. You need to 1932 check 'cmdheight' for whether there are full-width lines 1933 available above the last line. 1934 1935 *v:errmsg* *errmsg-variable* 1936v:errmsg Last given error message. It's allowed to set this variable. 1937 Example: > 1938 :let v:errmsg = "" 1939 :silent! next 1940 :if v:errmsg != "" 1941 : ... handle error 1942< "errmsg" also works, for backwards compatibility, unless 1943 |scriptversion| is 3 or higher. 1944 1945 *v:errors* *errors-variable* *assert-return* 1946v:errors Errors found by assert functions, such as |assert_true()|. 1947 This is a list of strings. 1948 The assert functions append an item when an assert fails. 1949 The return value indicates this: a one is returned if an item 1950 was added to v:errors, otherwise zero is returned. 1951 To remove old results make it empty: > 1952 :let v:errors = [] 1953< If v:errors is set to anything but a list it is made an empty 1954 list by the assert function. 1955 1956 *v:event* *event-variable* 1957v:event Dictionary containing information about the current 1958 |autocommand|. See the specific event for what it puts in 1959 this dictionary. 1960 The dictionary is emptied when the |autocommand| finishes, 1961 please refer to |dict-identity| for how to get an independent 1962 copy of it. Use |deepcopy()| if you want to keep the 1963 information after the event triggers. Example: > 1964 au TextYankPost * let g:foo = deepcopy(v:event) 1965< 1966 *v:exception* *exception-variable* 1967v:exception The value of the exception most recently caught and not 1968 finished. See also |v:throwpoint| and |throw-variables|. 1969 Example: > 1970 :try 1971 : throw "oops" 1972 :catch /.*/ 1973 : echo "caught " .. v:exception 1974 :endtry 1975< Output: "caught oops". 1976 1977 *v:false* *false-variable* 1978v:false A Number with value zero. Used to put "false" in JSON. See 1979 |json_encode()|. 1980 When used as a string this evaluates to "v:false". > 1981 echo v:false 1982< v:false ~ 1983 That is so that eval() can parse the string back to the same 1984 value. Read-only. 1985 1986 *v:fcs_reason* *fcs_reason-variable* 1987v:fcs_reason The reason why the |FileChangedShell| event was triggered. 1988 Can be used in an autocommand to decide what to do and/or what 1989 to set v:fcs_choice to. Possible values: 1990 deleted file no longer exists 1991 conflict file contents, mode or timestamp was 1992 changed and buffer is modified 1993 changed file contents has changed 1994 mode mode of file changed 1995 time only file timestamp changed 1996 1997 *v:fcs_choice* *fcs_choice-variable* 1998v:fcs_choice What should happen after a |FileChangedShell| event was 1999 triggered. Can be used in an autocommand to tell Vim what to 2000 do with the affected buffer: 2001 reload Reload the buffer (does not work if 2002 the file was deleted). 2003 ask Ask the user what to do, as if there 2004 was no autocommand. Except that when 2005 only the timestamp changed nothing 2006 will happen. 2007 <empty> Nothing, the autocommand should do 2008 everything that needs to be done. 2009 The default is empty. If another (invalid) value is used then 2010 Vim behaves like it is empty, there is no warning message. 2011 2012 *v:fname* *fname-variable* 2013v:fname When evaluating 'includeexpr': the file name that was 2014 detected. Empty otherwise. 2015 2016 *v:fname_in* *fname_in-variable* 2017v:fname_in The name of the input file. Valid while evaluating: 2018 option used for ~ 2019 'charconvert' file to be converted 2020 'diffexpr' original file 2021 'patchexpr' original file 2022 'printexpr' file to be printed 2023 And set to the swap file name for |SwapExists|. 2024 2025 *v:fname_out* *fname_out-variable* 2026v:fname_out The name of the output file. Only valid while 2027 evaluating: 2028 option used for ~ 2029 'charconvert' resulting converted file (*) 2030 'diffexpr' output of diff 2031 'patchexpr' resulting patched file 2032 (*) When doing conversion for a write command (e.g., ":w 2033 file") it will be equal to v:fname_in. When doing conversion 2034 for a read command (e.g., ":e file") it will be a temporary 2035 file and different from v:fname_in. 2036 2037 *v:fname_new* *fname_new-variable* 2038v:fname_new The name of the new version of the file. Only valid while 2039 evaluating 'diffexpr'. 2040 2041 *v:fname_diff* *fname_diff-variable* 2042v:fname_diff The name of the diff (patch) file. Only valid while 2043 evaluating 'patchexpr'. 2044 2045 *v:folddashes* *folddashes-variable* 2046v:folddashes Used for 'foldtext': dashes representing foldlevel of a closed 2047 fold. 2048 Read-only in the |sandbox|. |fold-foldtext| 2049 2050 *v:foldlevel* *foldlevel-variable* 2051v:foldlevel Used for 'foldtext': foldlevel of closed fold. 2052 Read-only in the |sandbox|. |fold-foldtext| 2053 2054 *v:foldend* *foldend-variable* 2055v:foldend Used for 'foldtext': last line of closed fold. 2056 Read-only in the |sandbox|. |fold-foldtext| 2057 2058 *v:foldstart* *foldstart-variable* 2059v:foldstart Used for 'foldtext': first line of closed fold. 2060 Read-only in the |sandbox|. |fold-foldtext| 2061 2062 *v:hlsearch* *hlsearch-variable* 2063v:hlsearch Variable that indicates whether search highlighting is on. 2064 Setting it makes sense only if 'hlsearch' is enabled which 2065 requires |+extra_search|. Setting this variable to zero acts 2066 like the |:nohlsearch| command, setting it to one acts like > 2067 let &hlsearch = &hlsearch 2068< Note that the value is restored when returning from a 2069 function. |function-search-undo|. 2070 2071 *v:insertmode* *insertmode-variable* 2072v:insertmode Used for the |InsertEnter| and |InsertChange| autocommand 2073 events. Values: 2074 i Insert mode 2075 r Replace mode 2076 v Virtual Replace mode 2077 2078 *v:key* *key-variable* 2079v:key Key of the current item of a |Dictionary|. Only valid while 2080 evaluating the expression used with |map()| and |filter()|. 2081 Read-only. 2082 2083 *v:lang* *lang-variable* 2084v:lang The current locale setting for messages of the runtime 2085 environment. This allows Vim scripts to be aware of the 2086 current language. Technical: it's the value of LC_MESSAGES. 2087 The value is system dependent. 2088 This variable can not be set directly, use the |:language| 2089 command. 2090 It can be different from |v:ctype| when messages are desired 2091 in a different language than what is used for character 2092 encoding. See |multi-lang|. 2093 2094 *v:lc_time* *lc_time-variable* 2095v:lc_time The current locale setting for time messages of the runtime 2096 environment. This allows Vim scripts to be aware of the 2097 current language. Technical: it's the value of LC_TIME. 2098 This variable can not be set directly, use the |:language| 2099 command. See |multi-lang|. 2100 2101 *v:lnum* *lnum-variable* 2102v:lnum Line number for the 'foldexpr' |fold-expr|, 'formatexpr' and 2103 'indentexpr' expressions, tab page number for 'guitablabel' 2104 and 'guitabtooltip'. Only valid while one of these 2105 expressions is being evaluated. Read-only when in the 2106 |sandbox|. 2107 2108 *v:mouse_win* *mouse_win-variable* 2109v:mouse_win Window number for a mouse click obtained with |getchar()|. 2110 First window has number 1, like with |winnr()|. The value is 2111 zero when there was no mouse button click. 2112 2113 *v:mouse_winid* *mouse_winid-variable* 2114v:mouse_winid Window ID for a mouse click obtained with |getchar()|. 2115 The value is zero when there was no mouse button click. 2116 2117 *v:mouse_lnum* *mouse_lnum-variable* 2118v:mouse_lnum Line number for a mouse click obtained with |getchar()|. 2119 This is the text line number, not the screen line number. The 2120 value is zero when there was no mouse button click. 2121 2122 *v:mouse_col* *mouse_col-variable* 2123v:mouse_col Column number for a mouse click obtained with |getchar()|. 2124 This is the screen column number, like with |virtcol()|. The 2125 value is zero when there was no mouse button click. 2126 2127 *v:none* *none-variable* *None* 2128v:none An empty String. Used to put an empty item in JSON. See 2129 |json_encode()|. 2130 This can also be used as a function argument to use the 2131 default value, see |none-function_argument|. 2132 When used as a number this evaluates to zero. 2133 When used as a string this evaluates to "v:none". > 2134 echo v:none 2135< v:none ~ 2136 That is so that eval() can parse the string back to the same 2137 value. Read-only. 2138 2139 *v:null* *null-variable* 2140v:null An empty String. Used to put "null" in JSON. See 2141 |json_encode()|. 2142 When used as a number this evaluates to zero. 2143 When used as a string this evaluates to "v:null". > 2144 echo v:null 2145< v:null ~ 2146 That is so that eval() can parse the string back to the same 2147 value. Read-only. 2148 2149 *v:numbermax* *numbermax-variable* 2150v:numbermax Maximum value of a number. 2151 2152 *v:numbermin* *numbermin-variable* 2153v:numbermin Minimum value of a number (negative). 2154 2155 *v:numbersize* *numbersize-variable* 2156v:numbersize Number of bits in a Number. This is normally 64, but on some 2157 systems it may be 32. 2158 2159 *v:oldfiles* *oldfiles-variable* 2160v:oldfiles List of file names that is loaded from the |viminfo| file on 2161 startup. These are the files that Vim remembers marks for. 2162 The length of the List is limited by the ' argument of the 2163 'viminfo' option (default is 100). 2164 When the |viminfo| file is not used the List is empty. 2165 Also see |:oldfiles| and |c_#<|. 2166 The List can be modified, but this has no effect on what is 2167 stored in the |viminfo| file later. If you use values other 2168 than String this will cause trouble. 2169 {only when compiled with the |+viminfo| feature} 2170 2171 *v:option_new* 2172v:option_new New value of the option. Valid while executing an |OptionSet| 2173 autocommand. 2174 *v:option_old* 2175v:option_old Old value of the option. Valid while executing an |OptionSet| 2176 autocommand. Depending on the command used for setting and the 2177 kind of option this is either the local old value or the 2178 global old value. 2179 *v:option_oldlocal* 2180v:option_oldlocal 2181 Old local value of the option. Valid while executing an 2182 |OptionSet| autocommand. 2183 *v:option_oldglobal* 2184v:option_oldglobal 2185 Old global value of the option. Valid while executing an 2186 |OptionSet| autocommand. 2187 *v:option_type* 2188v:option_type Scope of the set command. Valid while executing an 2189 |OptionSet| autocommand. Can be either "global" or "local" 2190 *v:option_command* 2191v:option_command 2192 Command used to set the option. Valid while executing an 2193 |OptionSet| autocommand. 2194 value option was set via ~ 2195 "setlocal" |:setlocal| or ":let l:xxx" 2196 "setglobal" |:setglobal| or ":let g:xxx" 2197 "set" |:set| or |:let| 2198 "modeline" |modeline| 2199 *v:operator* *operator-variable* 2200v:operator The last operator given in Normal mode. This is a single 2201 character except for commands starting with <g> or <z>, 2202 in which case it is two characters. Best used alongside 2203 |v:prevcount| and |v:register|. Useful if you want to cancel 2204 Operator-pending mode and then use the operator, e.g.: > 2205 :omap O <Esc>:call MyMotion(v:operator)<CR> 2206< The value remains set until another operator is entered, thus 2207 don't expect it to be empty. 2208 v:operator is not set for |:delete|, |:yank| or other Ex 2209 commands. 2210 Read-only. 2211 2212 *v:prevcount* *prevcount-variable* 2213v:prevcount The count given for the last but one Normal mode command. 2214 This is the v:count value of the previous command. Useful if 2215 you want to cancel Visual or Operator-pending mode and then 2216 use the count, e.g.: > 2217 :vmap % <Esc>:call MyFilter(v:prevcount)<CR> 2218< Read-only. 2219 2220 *v:profiling* *profiling-variable* 2221v:profiling Normally zero. Set to one after using ":profile start". 2222 See |profiling|. 2223 2224 *v:progname* *progname-variable* 2225v:progname Contains the name (with path removed) with which Vim was 2226 invoked. Allows you to do special initialisations for |view|, 2227 |evim| etc., or any other name you might symlink to Vim. 2228 Read-only. 2229 2230 *v:progpath* *progpath-variable* 2231v:progpath Contains the command with which Vim was invoked, in a form 2232 that when passed to the shell will run the same Vim executable 2233 as the current one (if $PATH remains unchanged). 2234 Useful if you want to message a Vim server using a 2235 |--remote-expr|. 2236 To get the full path use: > 2237 echo exepath(v:progpath) 2238< If the command has a relative path it will be expanded to the 2239 full path, so that it still works after `:cd`. Thus starting 2240 "./vim" results in "/home/user/path/to/vim/src/vim". 2241 On Linux and other systems it will always be the full path. 2242 On Mac it may just be "vim" and using exepath() as mentioned 2243 above should be used to get the full path. 2244 On MS-Windows the executable may be called "vim.exe", but the 2245 ".exe" is not added to v:progpath. 2246 Read-only. 2247 2248 *v:register* *register-variable* 2249v:register The name of the register in effect for the current normal mode 2250 command (regardless of whether that command actually used a 2251 register). Or for the currently executing normal mode mapping 2252 (use this in custom commands that take a register). 2253 If none is supplied it is the default register '"', unless 2254 'clipboard' contains "unnamed" or "unnamedplus", then it is 2255 '*' or '+'. 2256 Also see |getreg()| and |setreg()| 2257 2258 *v:scrollstart* *scrollstart-variable* 2259v:scrollstart String describing the script or function that caused the 2260 screen to scroll up. It's only set when it is empty, thus the 2261 first reason is remembered. It is set to "Unknown" for a 2262 typed command. 2263 This can be used to find out why your script causes the 2264 hit-enter prompt. 2265 2266 *v:servername* *servername-variable* 2267v:servername The resulting registered |client-server-name| if any. 2268 Read-only. 2269 2270 2271v:searchforward *v:searchforward* *searchforward-variable* 2272 Search direction: 1 after a forward search, 0 after a 2273 backward search. It is reset to forward when directly setting 2274 the last search pattern, see |quote/|. 2275 Note that the value is restored when returning from a 2276 function. |function-search-undo|. 2277 Read-write. 2278 2279 *v:shell_error* *shell_error-variable* 2280v:shell_error Result of the last shell command. When non-zero, the last 2281 shell command had an error. When zero, there was no problem. 2282 This only works when the shell returns the error code to Vim. 2283 The value -1 is often used when the command could not be 2284 executed. Read-only. 2285 Example: > 2286 :!mv foo bar 2287 :if v:shell_error 2288 : echo 'could not rename "foo" to "bar"!' 2289 :endif 2290< "shell_error" also works, for backwards compatibility, unless 2291 |scriptversion| is 3 or higher. 2292 2293 *v:sizeofint* *sizeofint-variable* 2294v:sizeofint Number of bytes in an int. Depends on how Vim was compiled. 2295 This is only useful for deciding whether a test will give the 2296 expected result. 2297 2298 *v:sizeoflong* *sizeoflong-variable* 2299v:sizeoflong Number of bytes in a long. Depends on how Vim was compiled. 2300 This is only useful for deciding whether a test will give the 2301 expected result. 2302 2303 *v:sizeofpointer* *sizeofpointer-variable* 2304v:sizeofpointer Number of bytes in a pointer. Depends on how Vim was compiled. 2305 This is only useful for deciding whether a test will give the 2306 expected result. 2307 2308 *v:statusmsg* *statusmsg-variable* 2309v:statusmsg Last given status message. It's allowed to set this variable. 2310 2311 *v:swapname* *swapname-variable* 2312v:swapname Only valid when executing |SwapExists| autocommands: Name of 2313 the swap file found. Read-only. 2314 2315 *v:swapchoice* *swapchoice-variable* 2316v:swapchoice |SwapExists| autocommands can set this to the selected choice 2317 for handling an existing swap file: 2318 'o' Open read-only 2319 'e' Edit anyway 2320 'r' Recover 2321 'd' Delete swapfile 2322 'q' Quit 2323 'a' Abort 2324 The value should be a single-character string. An empty value 2325 results in the user being asked, as would happen when there is 2326 no SwapExists autocommand. The default is empty. 2327 2328 *v:swapcommand* *swapcommand-variable* 2329v:swapcommand Normal mode command to be executed after a file has been 2330 opened. Can be used for a |SwapExists| autocommand to have 2331 another Vim open the file and jump to the right place. For 2332 example, when jumping to a tag the value is ":tag tagname\r". 2333 For ":edit +cmd file" the value is ":cmd\r". 2334 2335 *v:t_TYPE* *v:t_bool* *t_bool-variable* 2336v:t_bool Value of |Boolean| type. Read-only. See: |type()| 2337 *v:t_channel* *t_channel-variable* 2338v:t_channel Value of |Channel| type. Read-only. See: |type()| 2339 *v:t_dict* *t_dict-variable* 2340v:t_dict Value of |Dictionary| type. Read-only. See: |type()| 2341 *v:t_float* *t_float-variable* 2342v:t_float Value of |Float| type. Read-only. See: |type()| 2343 *v:t_func* *t_func-variable* 2344v:t_func Value of |Funcref| type. Read-only. See: |type()| 2345 *v:t_job* *t_job-variable* 2346v:t_job Value of |Job| type. Read-only. See: |type()| 2347 *v:t_list* *t_list-variable* 2348v:t_list Value of |List| type. Read-only. See: |type()| 2349 *v:t_none* *t_none-variable* 2350v:t_none Value of |None| type. Read-only. See: |type()| 2351 *v:t_number* *t_number-variable* 2352v:t_number Value of |Number| type. Read-only. See: |type()| 2353 *v:t_string* *t_string-variable* 2354v:t_string Value of |String| type. Read-only. See: |type()| 2355 *v:t_blob* *t_blob-variable* 2356v:t_blob Value of |Blob| type. Read-only. See: |type()| 2357 2358 *v:termresponse* *termresponse-variable* 2359v:termresponse The escape sequence returned by the terminal for the |t_RV| 2360 termcap entry. It is set when Vim receives an escape sequence 2361 that starts with ESC [ or CSI, then '>' or '?' and ends in a 2362 'c', with only digits and ';' in between. 2363 When this option is set, the TermResponse autocommand event is 2364 fired, so that you can react to the response from the 2365 terminal. You can use |terminalprops()| to see what Vim 2366 figured out about the terminal. 2367 The response from a new xterm is: "<Esc>[> Pp ; Pv ; Pc c". Pp 2368 is the terminal type: 0 for vt100 and 1 for vt220. Pv is the 2369 patch level (since this was introduced in patch 95, it's 2370 always 95 or bigger). Pc is always zero. 2371 {only when compiled with |+termresponse| feature} 2372 2373 *v:termblinkresp* 2374v:termblinkresp The escape sequence returned by the terminal for the |t_RC| 2375 termcap entry. This is used to find out whether the terminal 2376 cursor is blinking. This is used by |term_getcursor()|. 2377 2378 *v:termstyleresp* 2379v:termstyleresp The escape sequence returned by the terminal for the |t_RS| 2380 termcap entry. This is used to find out what the shape of the 2381 cursor is. This is used by |term_getcursor()|. 2382 2383 *v:termrbgresp* 2384v:termrbgresp The escape sequence returned by the terminal for the |t_RB| 2385 termcap entry. This is used to find out what the terminal 2386 background color is, see 'background'. 2387 2388 *v:termrfgresp* 2389v:termrfgresp The escape sequence returned by the terminal for the |t_RF| 2390 termcap entry. This is used to find out what the terminal 2391 foreground color is. 2392 2393 *v:termu7resp* 2394v:termu7resp The escape sequence returned by the terminal for the |t_u7| 2395 termcap entry. This is used to find out what the terminal 2396 does with ambiguous width characters, see 'ambiwidth'. 2397 2398 *v:testing* *testing-variable* 2399v:testing Must be set before using `test_garbagecollect_now()`. 2400 Also, when set certain error messages won't be shown for 2 2401 seconds. (e.g. "'dictionary' option is empty") 2402 2403 *v:this_session* *this_session-variable* 2404v:this_session Full filename of the last loaded or saved session file. See 2405 |:mksession|. It is allowed to set this variable. When no 2406 session file has been saved, this variable is empty. 2407 "this_session" also works, for backwards compatibility, unless 2408 |scriptversion| is 3 or higher 2409 2410 *v:throwpoint* *throwpoint-variable* 2411v:throwpoint The point where the exception most recently caught and not 2412 finished was thrown. Not set when commands are typed. See 2413 also |v:exception| and |throw-variables|. 2414 Example: > 2415 :try 2416 : throw "oops" 2417 :catch /.*/ 2418 : echo "Exception from" v:throwpoint 2419 :endtry 2420< Output: "Exception from test.vim, line 2" 2421 2422 *v:true* *true-variable* 2423v:true A Number with value one. Used to put "true" in JSON. See 2424 |json_encode()|. 2425 When used as a string this evaluates to "v:true". > 2426 echo v:true 2427< v:true ~ 2428 That is so that eval() can parse the string back to the same 2429 value. Read-only. 2430 *v:val* *val-variable* 2431v:val Value of the current item of a |List| or |Dictionary|. Only 2432 valid while evaluating the expression used with |map()| and 2433 |filter()|. Read-only. 2434 2435 *v:version* *version-variable* 2436v:version Version number of Vim: Major version number times 100 plus 2437 minor version number. Version 5.0 is 500. Version 5.1 2438 is 501. Read-only. "version" also works, for backwards 2439 compatibility, unless |scriptversion| is 3 or higher. 2440 Use |has()| to check if a certain patch was included, e.g.: > 2441 if has("patch-7.4.123") 2442< Note that patch numbers are specific to the version, thus both 2443 version 5.0 and 5.1 may have a patch 123, but these are 2444 completely different. 2445 2446 *v:versionlong* *versionlong-variable* 2447v:versionlong Like v:version, but also including the patchlevel in the last 2448 four digits. Version 8.1 with patch 123 has value 8010123. 2449 This can be used like this: > 2450 if v:versionlong >= 8010123 2451< However, if there are gaps in the list of patches included 2452 this will not work well. This can happen if a recent patch 2453 was included into an older version, e.g. for a security fix. 2454 Use the has() function to make sure the patch is actually 2455 included. 2456 2457 *v:vim_did_enter* *vim_did_enter-variable* 2458v:vim_did_enter Zero until most of startup is done. It is set to one just 2459 before |VimEnter| autocommands are triggered. 2460 2461 *v:warningmsg* *warningmsg-variable* 2462v:warningmsg Last given warning message. It's allowed to set this variable. 2463 2464 *v:windowid* *windowid-variable* 2465v:windowid When any X11 based GUI is running or when running in a 2466 terminal and Vim connects to the X server (|-X|) this will be 2467 set to the window ID. 2468 When an MS-Windows GUI is running this will be set to the 2469 window handle. 2470 Otherwise the value is zero. 2471 Note: for windows inside Vim use |winnr()| or |win_getid()|, 2472 see |window-ID|. 2473 2474============================================================================== 24754. Builtin Functions *functions* 2476 2477See |function-list| for a list grouped by what the function is used for. 2478 2479(Use CTRL-] on the function name to jump to the full explanation.) 2480 2481USAGE RESULT DESCRIPTION ~ 2482 2483abs({expr}) Float or Number absolute value of {expr} 2484acos({expr}) Float arc cosine of {expr} 2485add({object}, {item}) List/Blob append {item} to {object} 2486and({expr}, {expr}) Number bitwise AND 2487append({lnum}, {text}) Number append {text} below line {lnum} 2488appendbufline({expr}, {lnum}, {text}) 2489 Number append {text} below line {lnum} 2490 in buffer {expr} 2491argc([{winid}]) Number number of files in the argument list 2492argidx() Number current index in the argument list 2493arglistid([{winnr} [, {tabnr}]]) Number argument list id 2494argv({nr} [, {winid}]) String {nr} entry of the argument list 2495argv([-1, {winid}]) List the argument list 2496asin({expr}) Float arc sine of {expr} 2497assert_beeps({cmd}) Number assert {cmd} causes a beep 2498assert_equal({exp}, {act} [, {msg}]) 2499 Number assert {exp} is equal to {act} 2500assert_equalfile({fname-one}, {fname-two} [, {msg}]) 2501 Number assert file contents are equal 2502assert_exception({error} [, {msg}]) 2503 Number assert {error} is in v:exception 2504assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]]) 2505 Number assert {cmd} fails 2506assert_false({actual} [, {msg}]) 2507 Number assert {actual} is false 2508assert_inrange({lower}, {upper}, {actual} [, {msg}]) 2509 Number assert {actual} is inside the range 2510assert_match({pat}, {text} [, {msg}]) 2511 Number assert {pat} matches {text} 2512assert_nobeep({cmd}) Number assert {cmd} does not cause a beep 2513assert_notequal({exp}, {act} [, {msg}]) 2514 Number assert {exp} is not equal {act} 2515assert_notmatch({pat}, {text} [, {msg}]) 2516 Number assert {pat} not matches {text} 2517assert_report({msg}) Number report a test failure 2518assert_true({actual} [, {msg}]) Number assert {actual} is true 2519atan({expr}) Float arc tangent of {expr} 2520atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2} 2521balloon_gettext() String current text in the balloon 2522balloon_show({expr}) none show {expr} inside the balloon 2523balloon_split({msg}) List split {msg} as used for a balloon 2524blob2list({blob}) List convert {blob} into a list of numbers 2525browse({save}, {title}, {initdir}, {default}) 2526 String put up a file requester 2527browsedir({title}, {initdir}) String put up a directory requester 2528bufadd({name}) Number add a buffer to the buffer list 2529bufexists({buf}) Number |TRUE| if buffer {buf} exists 2530buflisted({buf}) Number |TRUE| if buffer {buf} is listed 2531bufload({buf}) Number load buffer {buf} if not loaded yet 2532bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded 2533bufname([{buf}]) String Name of the buffer {buf} 2534bufnr([{buf} [, {create}]]) Number Number of the buffer {buf} 2535bufwinid({buf}) Number window ID of buffer {buf} 2536bufwinnr({buf}) Number window number of buffer {buf} 2537byte2line({byte}) Number line number at byte count {byte} 2538byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr} 2539byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr} 2540call({func}, {arglist} [, {dict}]) 2541 any call {func} with arguments {arglist} 2542ceil({expr}) Float round {expr} up 2543ch_canread({handle}) Number check if there is something to read 2544ch_close({handle}) none close {handle} 2545ch_close_in({handle}) none close in part of {handle} 2546ch_evalexpr({handle}, {expr} [, {options}]) 2547 any evaluate {expr} on JSON {handle} 2548ch_evalraw({handle}, {string} [, {options}]) 2549 any evaluate {string} on raw {handle} 2550ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what} 2551ch_getjob({channel}) Job get the Job of {channel} 2552ch_info({handle}) String info about channel {handle} 2553ch_log({msg} [, {handle}]) none write {msg} in the channel log file 2554ch_logfile({fname} [, {mode}]) none start logging channel activity 2555ch_open({address} [, {options}]) 2556 Channel open a channel to {address} 2557ch_read({handle} [, {options}]) String read from {handle} 2558ch_readblob({handle} [, {options}]) 2559 Blob read Blob from {handle} 2560ch_readraw({handle} [, {options}]) 2561 String read raw from {handle} 2562ch_sendexpr({handle}, {expr} [, {options}]) 2563 any send {expr} over JSON {handle} 2564ch_sendraw({handle}, {expr} [, {options}]) 2565 any send {expr} over raw {handle} 2566ch_setoptions({handle}, {options}) 2567 none set options for {handle} 2568ch_status({handle} [, {options}]) 2569 String status of channel {handle} 2570changenr() Number current change number 2571char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr} 2572charclass({string}) Number character class of {string} 2573charcol({expr}) Number column number of cursor or mark 2574charidx({string}, {idx} [, {countcc}]) 2575 Number char index of byte {idx} in {string} 2576chdir({dir}) String change current working directory 2577cindent({lnum}) Number C indent for line {lnum} 2578clearmatches([{win}]) none clear all matches 2579col({expr}) Number column byte index of cursor or mark 2580complete({startcol}, {matches}) none set Insert mode completion 2581complete_add({expr}) Number add completion match 2582complete_check() Number check for key typed during completion 2583complete_info([{what}]) Dict get current completion information 2584confirm({msg} [, {choices} [, {default} [, {type}]]]) 2585 Number number of choice picked by user 2586copy({expr}) any make a shallow copy of {expr} 2587cos({expr}) Float cosine of {expr} 2588cosh({expr}) Float hyperbolic cosine of {expr} 2589count({comp}, {expr} [, {ic} [, {start}]]) 2590 Number count how many {expr} are in {comp} 2591cscope_connection([{num}, {dbpath} [, {prepend}]]) 2592 Number checks existence of cscope connection 2593cursor({lnum}, {col} [, {off}]) 2594 Number move cursor to {lnum}, {col}, {off} 2595cursor({list}) Number move cursor to position in {list} 2596debugbreak({pid}) Number interrupt process being debugged 2597deepcopy({expr} [, {noref}]) any make a full copy of {expr} 2598delete({fname} [, {flags}]) Number delete the file or directory {fname} 2599deletebufline({buf}, {first} [, {last}]) 2600 Number delete lines from buffer {buf} 2601did_filetype() Number |TRUE| if FileType autocmd event used 2602diff_filler({lnum}) Number diff filler lines about {lnum} 2603diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col} 2604digraph_get({chars}) String get the |digraph| of {chars} 2605digraph_getlist([{listall}]) List get all |digraph|s 2606digraph_set({chars}, {digraph}) Boolean register |digraph| 2607digraph_setlist({digraphlist}) Boolean register multiple |digraph|s 2608echoraw({expr}) none output {expr} as-is 2609empty({expr}) Number |TRUE| if {expr} is empty 2610environ() Dict return environment variables 2611escape({string}, {chars}) String escape {chars} in {string} with '\' 2612eval({string}) any evaluate {string} into its value 2613eventhandler() Number |TRUE| if inside an event handler 2614executable({expr}) Number 1 if executable {expr} exists 2615execute({command}) String execute {command} and get the output 2616exepath({expr}) String full path of the command {expr} 2617exists({expr}) Number |TRUE| if {expr} exists 2618exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time 2619exp({expr}) Float exponential of {expr} 2620expand({expr} [, {nosuf} [, {list}]]) 2621 any expand special keywords in {expr} 2622expandcmd({expr}) String expand {expr} like with `:edit` 2623extend({expr1}, {expr2} [, {expr3}]) 2624 List/Dict insert items of {expr2} into {expr1} 2625extendnew({expr1}, {expr2} [, {expr3}]) 2626 List/Dict like |extend()| but creates a new 2627 List or Dictionary 2628feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer 2629filereadable({file}) Number |TRUE| if {file} is a readable file 2630filewritable({file}) Number |TRUE| if {file} is a writable file 2631filter({expr1}, {expr2}) List/Dict remove items from {expr1} where 2632 {expr2} is 0 2633finddir({name} [, {path} [, {count}]]) 2634 String find directory {name} in {path} 2635findfile({name} [, {path} [, {count}]]) 2636 String find file {name} in {path} 2637flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels 2638flattennew({list} [, {maxdepth}]) 2639 List flatten a copy of {list} 2640float2nr({expr}) Number convert Float {expr} to a Number 2641floor({expr}) Float round {expr} down 2642fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2} 2643fnameescape({fname}) String escape special characters in {fname} 2644fnamemodify({fname}, {mods}) String modify file name 2645foldclosed({lnum}) Number first line of fold at {lnum} if closed 2646foldclosedend({lnum}) Number last line of fold at {lnum} if closed 2647foldlevel({lnum}) Number fold level at {lnum} 2648foldtext() String line displayed for closed fold 2649foldtextresult({lnum}) String text for closed fold at {lnum} 2650foreground() Number bring the Vim window to the foreground 2651fullcommand({name}) String get full command from {name} 2652funcref({name} [, {arglist}] [, {dict}]) 2653 Funcref reference to function {name} 2654function({name} [, {arglist}] [, {dict}]) 2655 Funcref named reference to function {name} 2656garbagecollect([{atexit}]) none free memory, breaking cyclic references 2657get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def} 2658get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def} 2659get({func}, {what}) any get property of funcref/partial {func} 2660getbufinfo([{buf}]) List information about buffers 2661getbufline({buf}, {lnum} [, {end}]) 2662 List lines {lnum} to {end} of buffer {buf} 2663getbufvar({buf}, {varname} [, {def}]) 2664 any variable {varname} in buffer {buf} 2665getchangelist([{buf}]) List list of change list items 2666getchar([expr]) Number or String 2667 get one character from the user 2668getcharmod() Number modifiers for the last typed character 2669getcharpos({expr}) List position of cursor, mark, etc. 2670getcharsearch() Dict last character search 2671getcharstr([expr]) String get one character from the user 2672getcmdline() String return the current command-line 2673getcmdpos() Number return cursor position in command-line 2674getcmdtype() String return current command-line type 2675getcmdwintype() String return current command-line window type 2676getcompletion({pat}, {type} [, {filtered}]) 2677 List list of cmdline completion matches 2678getcurpos([{winnr}]) List position of the cursor 2679getcursorcharpos([{winnr}]) List character position of the cursor 2680getcwd([{winnr} [, {tabnr}]]) String get the current working directory 2681getenv({name}) String return environment variable 2682getfontname([{name}]) String name of font being used 2683getfperm({fname}) String file permissions of file {fname} 2684getfsize({fname}) Number size in bytes of file {fname} 2685getftime({fname}) Number last modification time of file 2686getftype({fname}) String description of type of file {fname} 2687getimstatus() Number |TRUE| if the IME status is active 2688getjumplist([{winnr} [, {tabnr}]]) 2689 List list of jump list items 2690getline({lnum}) String line {lnum} of current buffer 2691getline({lnum}, {end}) List lines {lnum} to {end} of current buffer 2692getloclist({nr}) List list of location list items 2693getloclist({nr}, {what}) Dict get specific location list properties 2694getmarklist([{buf}]) List list of global/local marks 2695getmatches([{win}]) List list of current matches 2696getmousepos() Dict last known mouse position 2697getpid() Number process ID of Vim 2698getpos({expr}) List position of cursor, mark, etc. 2699getqflist() List list of quickfix items 2700getqflist({what}) Dict get specific quickfix list properties 2701getreg([{regname} [, 1 [, {list}]]]) 2702 String or List contents of a register 2703getreginfo([{regname}]) Dict information about a register 2704getregtype([{regname}]) String type of a register 2705gettabinfo([{expr}]) List list of tab pages 2706gettabvar({nr}, {varname} [, {def}]) 2707 any variable {varname} in tab {nr} or {def} 2708gettabwinvar({tabnr}, {winnr}, {name} [, {def}]) 2709 any {name} in {winnr} in tab page {tabnr} 2710gettagstack([{nr}]) Dict get the tag stack of window {nr} 2711gettext({text}) String lookup translation of {text} 2712getwininfo([{winid}]) List list of info about each window 2713getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window 2714getwinposx() Number X coord in pixels of the Vim window 2715getwinposy() Number Y coord in pixels of the Vim window 2716getwinvar({nr}, {varname} [, {def}]) 2717 any variable {varname} in window {nr} 2718glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) 2719 any expand file wildcards in {expr} 2720glob2regpat({expr}) String convert a glob pat into a search pat 2721globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) 2722 String do glob({expr}) for all dirs in {path} 2723has({feature} [, {check}]) Number |TRUE| if feature {feature} supported 2724has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key} 2725haslocaldir([{winnr} [, {tabnr}]]) 2726 Number |TRUE| if the window executed |:lcd| 2727 or |:tcd| 2728hasmapto({what} [, {mode} [, {abbr}]]) 2729 Number |TRUE| if mapping to {what} exists 2730histadd({history}, {item}) Number add an item to a history 2731histdel({history} [, {item}]) Number remove an item from a history 2732histget({history} [, {index}]) String get the item {index} from a history 2733histnr({history}) Number highest index of a history 2734hlID({name}) Number syntax ID of highlight group {name} 2735hlexists({name}) Number |TRUE| if highlight group {name} exists 2736hlget([{name} [, {resolve}]]) List get highlight group attributes 2737hlset({list}) Number set highlight group attributes 2738hostname() String name of the machine Vim is running on 2739iconv({expr}, {from}, {to}) String convert encoding of {expr} 2740indent({lnum}) Number indent of line {lnum} 2741index({object}, {expr} [, {start} [, {ic}]]) 2742 Number index in {object} where {expr} appears 2743input({prompt} [, {text} [, {completion}]]) 2744 String get input from the user 2745inputdialog({prompt} [, {text} [, {completion}]]) 2746 String like input() but in a GUI dialog 2747inputlist({textlist}) Number let the user pick from a choice list 2748inputrestore() Number restore typeahead 2749inputsave() Number save and clear typeahead 2750inputsecret({prompt} [, {text}]) String like input() but hiding the text 2751insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}] 2752interrupt() none interrupt script execution 2753invert({expr}) Number bitwise invert 2754isdirectory({directory}) Number |TRUE| if {directory} is a directory 2755isinf({expr}) Number determine if {expr} is infinity value 2756 (positive or negative) 2757islocked({expr}) Number |TRUE| if {expr} is locked 2758isnan({expr}) Number |TRUE| if {expr} is NaN 2759items({dict}) List key-value pairs in {dict} 2760job_getchannel({job}) Channel get the channel handle for {job} 2761job_info([{job}]) Dict get information about {job} 2762job_setoptions({job}, {options}) none set options for {job} 2763job_start({command} [, {options}]) 2764 Job start a job 2765job_status({job}) String get the status of {job} 2766job_stop({job} [, {how}]) Number stop {job} 2767join({list} [, {sep}]) String join {list} items into one String 2768js_decode({string}) any decode JS style JSON 2769js_encode({expr}) String encode JS style JSON 2770json_decode({string}) any decode JSON 2771json_encode({expr}) String encode JSON 2772keys({dict}) List keys in {dict} 2773len({expr}) Number the length of {expr} 2774libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg} 2775libcallnr({lib}, {func}, {arg}) Number idem, but return a Number 2776line({expr} [, {winid}]) Number line nr of cursor, last line or mark 2777line2byte({lnum}) Number byte count of line {lnum} 2778lispindent({lnum}) Number Lisp indent for line {lnum} 2779list2blob({list}) Blob turn {list} of numbers into a Blob 2780list2str({list} [, {utf8}]) String turn {list} of numbers into a String 2781listener_add({callback} [, {buf}]) 2782 Number add a callback to listen to changes 2783listener_flush([{buf}]) none invoke listener callbacks 2784listener_remove({id}) none remove a listener callback 2785localtime() Number current time 2786log({expr}) Float natural logarithm (base e) of {expr} 2787log10({expr}) Float logarithm of Float {expr} to base 10 2788luaeval({expr} [, {expr}]) any evaluate |Lua| expression 2789map({expr1}, {expr2}) List/Dict change each item in {expr1} to {expr} 2790maparg({name} [, {mode} [, {abbr} [, {dict}]]]) 2791 String or Dict 2792 rhs of mapping {name} in mode {mode} 2793mapcheck({name} [, {mode} [, {abbr}]]) 2794 String check for mappings matching {name} 2795mapnew({expr1}, {expr2}) List/Dict like |map()| but creates a new List 2796 or Dictionary 2797mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result 2798match({expr}, {pat} [, {start} [, {count}]]) 2799 Number position where {pat} matches in {expr} 2800matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) 2801 Number highlight {pattern} with {group} 2802matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) 2803 Number highlight positions with {group} 2804matcharg({nr}) List arguments of |:match| 2805matchdelete({id} [, {win}]) Number delete match identified by {id} 2806matchend({expr}, {pat} [, {start} [, {count}]]) 2807 Number position where {pat} ends in {expr} 2808matchfuzzy({list}, {str} [, {dict}]) 2809 List fuzzy match {str} in {list} 2810matchfuzzypos({list}, {str} [, {dict}]) 2811 List fuzzy match {str} in {list} 2812matchlist({expr}, {pat} [, {start} [, {count}]]) 2813 List match and submatches of {pat} in {expr} 2814matchstr({expr}, {pat} [, {start} [, {count}]]) 2815 String {count}'th match of {pat} in {expr} 2816matchstrpos({expr}, {pat} [, {start} [, {count}]]) 2817 List {count}'th match of {pat} in {expr} 2818max({expr}) Number maximum value of items in {expr} 2819menu_info({name} [, {mode}]) Dict get menu item information 2820min({expr}) Number minimum value of items in {expr} 2821mkdir({name} [, {path} [, {prot}]]) 2822 Number create directory {name} 2823mode([expr]) String current editing mode 2824mzeval({expr}) any evaluate |MzScheme| expression 2825nextnonblank({lnum}) Number line nr of non-blank line >= {lnum} 2826nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr} 2827or({expr}, {expr}) Number bitwise OR 2828pathshorten({expr} [, {len}]) String shorten directory names in a path 2829perleval({expr}) any evaluate |Perl| expression 2830popup_atcursor({what}, {options}) Number create popup window near the cursor 2831popup_beval({what}, {options}) Number create popup window for 'ballooneval' 2832popup_clear() none close all popup windows 2833popup_close({id} [, {result}]) none close popup window {id} 2834popup_create({what}, {options}) Number create a popup window 2835popup_dialog({what}, {options}) Number create a popup window used as a dialog 2836popup_filter_menu({id}, {key}) Number filter for a menu popup window 2837popup_filter_yesno({id}, {key}) Number filter for a dialog popup window 2838popup_findinfo() Number get window ID of info popup window 2839popup_findpreview() Number get window ID of preview popup window 2840popup_getoptions({id}) Dict get options of popup window {id} 2841popup_getpos({id}) Dict get position of popup window {id} 2842popup_hide({id}) none hide popup menu {id} 2843popup_list() List get a list of window IDs of all popups 2844popup_locate({row}, {col}) Number get window ID of popup at position 2845popup_menu({what}, {options}) Number create a popup window used as a menu 2846popup_move({id}, {options}) none set position of popup window {id} 2847popup_notification({what}, {options}) 2848 Number create a notification popup window 2849popup_setoptions({id}, {options}) 2850 none set options for popup window {id} 2851popup_settext({id}, {text}) none set the text of popup window {id} 2852popup_show({id}) none unhide popup window {id} 2853pow({x}, {y}) Float {x} to the power of {y} 2854prevnonblank({lnum}) Number line nr of non-blank line <= {lnum} 2855printf({fmt}, {expr1}...) String format text 2856prompt_getprompt({buf}) String get prompt text 2857prompt_setcallback({buf}, {expr}) none set prompt callback function 2858prompt_setinterrupt({buf}, {text}) none set prompt interrupt function 2859prompt_setprompt({buf}, {text}) none set prompt text 2860prop_add({lnum}, {col}, {props}) none add one text property 2861prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...]) 2862 none add multiple text properties 2863prop_clear({lnum} [, {lnum-end} [, {props}]]) 2864 none remove all text properties 2865prop_find({props} [, {direction}]) 2866 Dict search for a text property 2867prop_list({lnum} [, {props}]) List text properties in {lnum} 2868prop_remove({props} [, {lnum} [, {lnum-end}]]) 2869 Number remove a text property 2870prop_type_add({name}, {props}) none define a new property type 2871prop_type_change({name}, {props}) 2872 none change an existing property type 2873prop_type_delete({name} [, {props}]) 2874 none delete a property type 2875prop_type_get({name} [, {props}]) 2876 Dict get property type values 2877prop_type_list([{props}]) List get list of property types 2878pum_getpos() Dict position and size of pum if visible 2879pumvisible() Number whether popup menu is visible 2880py3eval({expr}) any evaluate |python3| expression 2881pyeval({expr}) any evaluate |Python| expression 2882pyxeval({expr}) any evaluate |python_x| expression 2883rand([{expr}]) Number get pseudo-random number 2884range({expr} [, {max} [, {stride}]]) 2885 List items from {expr} to {max} 2886readblob({fname}) Blob read a |Blob| from {fname} 2887readdir({dir} [, {expr} [, {dict}]]) 2888 List file names in {dir} selected by {expr} 2889readdirex({dir} [, {expr} [, {dict}]]) 2890 List file info in {dir} selected by {expr} 2891readfile({fname} [, {type} [, {max}]]) 2892 List get list of lines from file {fname} 2893reduce({object}, {func} [, {initial}]) 2894 any reduce {object} using {func} 2895reg_executing() String get the executing register name 2896reg_recording() String get the recording register name 2897reltime([{start} [, {end}]]) List get time value 2898reltimefloat({time}) Float turn the time value into a Float 2899reltimestr({time}) String turn time value into a String 2900remote_expr({server}, {string} [, {idvar} [, {timeout}]]) 2901 String send expression 2902remote_foreground({server}) Number bring Vim server to the foreground 2903remote_peek({serverid} [, {retvar}]) 2904 Number check for reply string 2905remote_read({serverid} [, {timeout}]) 2906 String read reply string 2907remote_send({server}, {string} [, {idvar}]) 2908 String send key sequence 2909remote_startserver({name}) none become server {name} 2910remove({list}, {idx} [, {end}]) any/List 2911 remove items {idx}-{end} from {list} 2912remove({blob}, {idx} [, {end}]) Number/Blob 2913 remove bytes {idx}-{end} from {blob} 2914remove({dict}, {key}) any remove entry {key} from {dict} 2915rename({from}, {to}) Number rename (move) file from {from} to {to} 2916repeat({expr}, {count}) String repeat {expr} {count} times 2917resolve({filename}) String get filename a shortcut points to 2918reverse({list}) List reverse {list} in-place 2919round({expr}) Float round off {expr} 2920rubyeval({expr}) any evaluate |Ruby| expression 2921screenattr({row}, {col}) Number attribute at screen position 2922screenchar({row}, {col}) Number character at screen position 2923screenchars({row}, {col}) List List of characters at screen position 2924screencol() Number current cursor column 2925screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character 2926screenrow() Number current cursor row 2927screenstring({row}, {col}) String characters at screen position 2928search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) 2929 Number search for {pattern} 2930searchcount([{options}]) Dict get or update search stats 2931searchdecl({name} [, {global} [, {thisblock}]]) 2932 Number search for variable declaration 2933searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]]) 2934 Number search for other end of start/end pair 2935searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]]) 2936 List search for other end of start/end pair 2937searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) 2938 List search for {pattern} 2939server2client({clientid}, {string}) 2940 Number send reply string 2941serverlist() String get a list of available servers 2942setbufline({expr}, {lnum}, {text}) 2943 Number set line {lnum} to {text} in buffer 2944 {expr} 2945setbufvar({buf}, {varname}, {val}) 2946 none set {varname} in buffer {buf} to {val} 2947setcellwidths({list}) none set character cell width overrides 2948setcharpos({expr}, {list}) Number set the {expr} position to {list} 2949setcharsearch({dict}) Dict set character search from {dict} 2950setcmdpos({pos}) Number set cursor position in command-line 2951setcursorcharpos({list}) Number move cursor to position in {list} 2952setenv({name}, {val}) none set environment variable 2953setfperm({fname}, {mode}) Number set {fname} file permissions to {mode} 2954setline({lnum}, {line}) Number set line {lnum} to {line} 2955setloclist({nr}, {list} [, {action}]) 2956 Number modify location list using {list} 2957setloclist({nr}, {list}, {action}, {what}) 2958 Number modify specific location list props 2959setmatches({list} [, {win}]) Number restore a list of matches 2960setpos({expr}, {list}) Number set the {expr} position to {list} 2961setqflist({list} [, {action}]) Number modify quickfix list using {list} 2962setqflist({list}, {action}, {what}) 2963 Number modify specific quickfix list props 2964setreg({n}, {v} [, {opt}]) Number set register to value and type 2965settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val} 2966settabwinvar({tabnr}, {winnr}, {varname}, {val}) 2967 none set {varname} in window {winnr} in tab 2968 page {tabnr} to {val} 2969settagstack({nr}, {dict} [, {action}]) 2970 Number modify tag stack using {dict} 2971setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val} 2972sha256({string}) String SHA256 checksum of {string} 2973shellescape({string} [, {special}]) 2974 String escape {string} for use as shell 2975 command argument 2976shiftwidth([{col}]) Number effective value of 'shiftwidth' 2977sign_define({name} [, {dict}]) Number define or update a sign 2978sign_define({list}) List define or update a list of signs 2979sign_getdefined([{name}]) List get a list of defined signs 2980sign_getplaced([{buf} [, {dict}]]) 2981 List get a list of placed signs 2982sign_jump({id}, {group}, {buf}) 2983 Number jump to a sign 2984sign_place({id}, {group}, {name}, {buf} [, {dict}]) 2985 Number place a sign 2986sign_placelist({list}) List place a list of signs 2987sign_undefine([{name}]) Number undefine a sign 2988sign_undefine({list}) List undefine a list of signs 2989sign_unplace({group} [, {dict}]) 2990 Number unplace a sign 2991sign_unplacelist({list}) List unplace a list of signs 2992simplify({filename}) String simplify filename as much as possible 2993sin({expr}) Float sine of {expr} 2994sinh({expr}) Float hyperbolic sine of {expr} 2995slice({expr}, {start} [, {end}]) String, List or Blob 2996 slice of a String, List or Blob 2997sort({list} [, {func} [, {dict}]]) 2998 List sort {list}, using {func} to compare 2999sound_clear() none stop playing all sounds 3000sound_playevent({name} [, {callback}]) 3001 Number play an event sound 3002sound_playfile({path} [, {callback}]) 3003 Number play sound file {path} 3004sound_stop({id}) none stop playing sound {id} 3005soundfold({word}) String sound-fold {word} 3006spellbadword() String badly spelled word at cursor 3007spellsuggest({word} [, {max} [, {capital}]]) 3008 List spelling suggestions 3009split({expr} [, {pat} [, {keepempty}]]) 3010 List make |List| from {pat} separated {expr} 3011sqrt({expr}) Float square root of {expr} 3012srand([{expr}]) List get seed for |rand()| 3013state([{what}]) String current state of Vim 3014str2float({expr} [, {quoted}]) Float convert String to Float 3015str2list({expr} [, {utf8}]) List convert each character of {expr} to 3016 ASCII/UTF-8 value 3017str2nr({expr} [, {base} [, {quoted}]]) 3018 Number convert String to Number 3019strcharlen({expr}) Number character length of the String {expr} 3020strcharpart({str}, {start} [, {len} [, {skipcc}]]) 3021 String {len} characters of {str} at 3022 character {start} 3023strchars({expr} [, {skipcc}]) Number character count of the String {expr} 3024strdisplaywidth({expr} [, {col}]) Number display length of the String {expr} 3025strftime({format} [, {time}]) String format time with a specified format 3026strgetchar({str}, {index}) Number get char {index} from {str} 3027stridx({haystack}, {needle} [, {start}]) 3028 Number index of {needle} in {haystack} 3029string({expr}) String String representation of {expr} value 3030strlen({expr}) Number length of the String {expr} 3031strpart({str}, {start} [, {len} [, {chars}]]) 3032 String {len} bytes/chars of {str} at 3033 byte {start} 3034strptime({format}, {timestring}) 3035 Number Convert {timestring} to unix timestamp 3036strridx({haystack}, {needle} [, {start}]) 3037 Number last index of {needle} in {haystack} 3038strtrans({expr}) String translate string to make it printable 3039strwidth({expr}) Number display cell length of the String {expr} 3040submatch({nr} [, {list}]) String or List 3041 specific match in ":s" or substitute() 3042substitute({expr}, {pat}, {sub}, {flags}) 3043 String all {pat} in {expr} replaced with {sub} 3044swapinfo({fname}) Dict information about swap file {fname} 3045swapname({buf}) String swap file of buffer {buf} 3046synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col} 3047synIDattr({synID}, {what} [, {mode}]) 3048 String attribute {what} of syntax ID {synID} 3049synIDtrans({synID}) Number translated syntax ID of {synID} 3050synconcealed({lnum}, {col}) List info about concealing 3051synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col} 3052system({expr} [, {input}]) String output of shell command/filter {expr} 3053systemlist({expr} [, {input}]) List output of shell command/filter {expr} 3054tabpagebuflist([{arg}]) List list of buffer numbers in tab page 3055tabpagenr([{arg}]) Number number of current or last tab page 3056tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page 3057tagfiles() List tags files used 3058taglist({expr} [, {filename}]) List list of tags matching {expr} 3059tan({expr}) Float tangent of {expr} 3060tanh({expr}) Float hyperbolic tangent of {expr} 3061tempname() String name for a temporary file 3062term_dumpdiff({filename}, {filename} [, {options}]) 3063 Number display difference between two dumps 3064term_dumpload({filename} [, {options}]) 3065 Number displaying a screen dump 3066term_dumpwrite({buf}, {filename} [, {options}]) 3067 none dump terminal window contents 3068term_getaltscreen({buf}) Number get the alternate screen flag 3069term_getansicolors({buf}) List get ANSI palette in GUI color mode 3070term_getattr({attr}, {what}) Number get the value of attribute {what} 3071term_getcursor({buf}) List get the cursor position of a terminal 3072term_getjob({buf}) Job get the job associated with a terminal 3073term_getline({buf}, {row}) String get a line of text from a terminal 3074term_getscrolled({buf}) Number get the scroll count of a terminal 3075term_getsize({buf}) List get the size of a terminal 3076term_getstatus({buf}) String get the status of a terminal 3077term_gettitle({buf}) String get the title of a terminal 3078term_gettty({buf}, [{input}]) String get the tty name of a terminal 3079term_list() List get the list of terminal buffers 3080term_scrape({buf}, {row}) List get row of a terminal screen 3081term_sendkeys({buf}, {keys}) none send keystrokes to a terminal 3082term_setansicolors({buf}, {colors}) 3083 none set ANSI palette in GUI color mode 3084term_setapi({buf}, {expr}) none set |terminal-api| function name prefix 3085term_setkill({buf}, {how}) none set signal to stop job in terminal 3086term_setrestore({buf}, {command}) none set command to restore terminal 3087term_setsize({buf}, {rows}, {cols}) 3088 none set the size of a terminal 3089term_start({cmd} [, {options}]) Number open a terminal window and run a job 3090term_wait({buf} [, {time}]) Number wait for screen to be updated 3091terminalprops() Dict properties of the terminal 3092test_alloc_fail({id}, {countdown}, {repeat}) 3093 none make memory allocation fail 3094test_autochdir() none enable 'autochdir' during startup 3095test_feedinput({string}) none add key sequence to input buffer 3096test_garbagecollect_now() none free memory right now for testing 3097test_garbagecollect_soon() none free memory soon for testing 3098test_getvalue({string}) any get value of an internal variable 3099test_gui_drop_files({list}, {row}, {col}, {mods}) 3100 none drop a list of files in a window 3101test_gui_mouse_event({button}, {row}, {col}, {repeated}, {mods}) 3102 none add a mouse event to the input buffer 3103test_ignore_error({expr}) none ignore a specific error 3104test_null_blob() Blob null value for testing 3105test_null_channel() Channel null value for testing 3106test_null_dict() Dict null value for testing 3107test_null_function() Funcref null value for testing 3108test_null_job() Job null value for testing 3109test_null_list() List null value for testing 3110test_null_partial() Funcref null value for testing 3111test_null_string() String null value for testing 3112test_option_not_set({name}) none reset flag indicating option was set 3113test_override({expr}, {val}) none test with Vim internal overrides 3114test_refcount({expr}) Number get the reference count of {expr} 3115test_scrollbar({which}, {value}, {dragging}) 3116 none scroll in the GUI for testing 3117test_setmouse({row}, {col}) none set the mouse position for testing 3118test_settime({expr}) none set current time for testing 3119test_srand_seed([seed]) none set seed for testing srand() 3120test_unknown() any unknown value for testing 3121test_void() any void value for testing 3122timer_info([{id}]) List information about timers 3123timer_pause({id}, {pause}) none pause or unpause a timer 3124timer_start({time}, {callback} [, {options}]) 3125 Number create a timer 3126timer_stop({timer}) none stop a timer 3127timer_stopall() none stop all timers 3128tolower({expr}) String the String {expr} switched to lowercase 3129toupper({expr}) String the String {expr} switched to uppercase 3130tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr} 3131 to chars in {tostr} 3132trim({text} [, {mask} [, {dir}]]) 3133 String trim characters in {mask} from {text} 3134trunc({expr}) Float truncate Float {expr} 3135type({expr}) Number type of value {expr} 3136typename({expr}) String representation of the type of {expr} 3137undofile({name}) String undo file name for {name} 3138undotree() List undo file tree 3139uniq({list} [, {func} [, {dict}]]) 3140 List remove adjacent duplicates from a list 3141values({dict}) List values in {dict} 3142virtcol({expr}) Number screen column of cursor or mark 3143visualmode([expr]) String last visual mode used 3144wildmenumode() Number whether 'wildmenu' mode is active 3145win_execute({id}, {command} [, {silent}]) 3146 String execute {command} in window {id} 3147win_findbuf({bufnr}) List find windows containing {bufnr} 3148win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab} 3149win_gettype([{nr}]) String type of window {nr} 3150win_gotoid({expr}) Number go to window with ID {expr} 3151win_id2tabwin({expr}) List get tab and window nr from window ID 3152win_id2win({expr}) Number get window nr from window ID 3153win_screenpos({nr}) List get screen position of window {nr} 3154win_splitmove({nr}, {target} [, {options}]) 3155 Number move window {nr} to split of {target} 3156winbufnr({nr}) Number buffer number of window {nr} 3157wincol() Number window column of the cursor 3158windowsversion() String MS-Windows OS version 3159winheight({nr}) Number height of window {nr} 3160winlayout([{tabnr}]) List layout of windows in tab {tabnr} 3161winline() Number window line of the cursor 3162winnr([{expr}]) Number number of current window 3163winrestcmd() String returns command to restore window sizes 3164winrestview({dict}) none restore view of current window 3165winsaveview() Dict save view of current window 3166winwidth({nr}) Number width of window {nr} 3167wordcount() Dict get byte/char/word statistics 3168writefile({object}, {fname} [, {flags}]) 3169 Number write |Blob| or |List| of lines to file 3170xor({expr}, {expr}) Number bitwise XOR 3171 3172 3173abs({expr}) *abs()* 3174 Return the absolute value of {expr}. When {expr} evaluates to 3175 a |Float| abs() returns a |Float|. When {expr} can be 3176 converted to a |Number| abs() returns a |Number|. Otherwise 3177 abs() gives an error message and returns -1. 3178 Examples: > 3179 echo abs(1.456) 3180< 1.456 > 3181 echo abs(-5.456) 3182< 5.456 > 3183 echo abs(-4) 3184< 4 3185 3186 Can also be used as a |method|: > 3187 Compute()->abs() 3188 3189< {only available when compiled with the |+float| feature} 3190 3191 3192acos({expr}) *acos()* 3193 Return the arc cosine of {expr} measured in radians, as a 3194 |Float| in the range of [0, pi]. 3195 {expr} must evaluate to a |Float| or a |Number| in the range 3196 [-1, 1]. 3197 Examples: > 3198 :echo acos(0) 3199< 1.570796 > 3200 :echo acos(-0.5) 3201< 2.094395 3202 3203 Can also be used as a |method|: > 3204 Compute()->acos() 3205 3206< {only available when compiled with the |+float| feature} 3207 3208 3209add({object}, {expr}) *add()* 3210 Append the item {expr} to |List| or |Blob| {object}. Returns 3211 the resulting |List| or |Blob|. Examples: > 3212 :let alist = add([1, 2, 3], item) 3213 :call add(mylist, "woodstock") 3214< Note that when {expr} is a |List| it is appended as a single 3215 item. Use |extend()| to concatenate |Lists|. 3216 When {object} is a |Blob| then {expr} must be a number. 3217 Use |insert()| to add an item at another position. 3218 3219 Can also be used as a |method|: > 3220 mylist->add(val1)->add(val2) 3221 3222 3223and({expr}, {expr}) *and()* 3224 Bitwise AND on the two arguments. The arguments are converted 3225 to a number. A List, Dict or Float argument causes an error. 3226 Example: > 3227 :let flag = and(bits, 0x80) 3228< Can also be used as a |method|: > 3229 :let flag = bits->and(0x80) 3230 3231 3232append({lnum}, {text}) *append()* 3233 When {text} is a |List|: Append each item of the |List| as a 3234 text line below line {lnum} in the current buffer. 3235 Otherwise append {text} as one text line below line {lnum} in 3236 the current buffer. 3237 Any type of item is accepted and converted to a String. 3238 {lnum} can be zero to insert a line before the first one. 3239 {lnum} is used like with |getline()|. 3240 Returns 1 for failure ({lnum} out of range or out of memory), 3241 0 for success. Example: > 3242 :let failed = append(line('$'), "# THE END") 3243 :let failed = append(0, ["Chapter 1", "the beginning"]) 3244 3245< Can also be used as a |method| after a List, the base is 3246 passed as the second argument: > 3247 mylist->append(lnum) 3248 3249 3250appendbufline({buf}, {lnum}, {text}) *appendbufline()* 3251 Like |append()| but append the text in buffer {buf}. 3252 3253 This function works only for loaded buffers. First call 3254 |bufload()| if needed. 3255 3256 For the use of {buf}, see |bufname()|. 3257 3258 {lnum} is used like with |append()|. Note that using |line()| 3259 would use the current buffer, not the one appending to. 3260 Use "$" to append at the end of the buffer. 3261 3262 On success 0 is returned, on failure 1 is returned. 3263 3264 If {buf} is not a valid buffer or {lnum} is not valid, an 3265 error message is given. Example: > 3266 :let failed = appendbufline(13, 0, "# THE START") 3267< 3268 Can also be used as a |method| after a List, the base is 3269 passed as the second argument: > 3270 mylist->appendbufline(buf, lnum) 3271 3272 3273argc([{winid}]) *argc()* 3274 The result is the number of files in the argument list. See 3275 |arglist|. 3276 If {winid} is not supplied, the argument list of the current 3277 window is used. 3278 If {winid} is -1, the global argument list is used. 3279 Otherwise {winid} specifies the window of which the argument 3280 list is used: either the window number or the window ID. 3281 Returns -1 if the {winid} argument is invalid. 3282 3283 *argidx()* 3284argidx() The result is the current index in the argument list. 0 is 3285 the first file. argc() - 1 is the last one. See |arglist|. 3286 3287 *arglistid()* 3288arglistid([{winnr} [, {tabnr}]]) 3289 Return the argument list ID. This is a number which 3290 identifies the argument list being used. Zero is used for the 3291 global argument list. See |arglist|. 3292 Returns -1 if the arguments are invalid. 3293 3294 Without arguments use the current window. 3295 With {winnr} only use this window in the current tab page. 3296 With {winnr} and {tabnr} use the window in the specified tab 3297 page. 3298 {winnr} can be the window number or the |window-ID|. 3299 3300 *argv()* 3301argv([{nr} [, {winid}]]) 3302 The result is the {nr}th file in the argument list. See 3303 |arglist|. "argv(0)" is the first one. Example: > 3304 :let i = 0 3305 :while i < argc() 3306 : let f = escape(fnameescape(argv(i)), '.') 3307 : exe 'amenu Arg.' . f . ' :e ' . f . '<CR>' 3308 : let i = i + 1 3309 :endwhile 3310< Without the {nr} argument, or when {nr} is -1, a |List| with 3311 the whole |arglist| is returned. 3312 3313 The {winid} argument specifies the window ID, see |argc()|. 3314 For the Vim command line arguments see |v:argv|. 3315 3316asin({expr}) *asin()* 3317 Return the arc sine of {expr} measured in radians, as a |Float| 3318 in the range of [-pi/2, pi/2]. 3319 {expr} must evaluate to a |Float| or a |Number| in the range 3320 [-1, 1]. 3321 Examples: > 3322 :echo asin(0.8) 3323< 0.927295 > 3324 :echo asin(-0.5) 3325< -0.523599 3326 3327 Can also be used as a |method|: > 3328 Compute()->asin() 3329< 3330 {only available when compiled with the |+float| feature} 3331 3332 3333assert_ functions are documented here: |assert-functions-details| 3334 3335 3336 3337atan({expr}) *atan()* 3338 Return the principal value of the arc tangent of {expr}, in 3339 the range [-pi/2, +pi/2] radians, as a |Float|. 3340 {expr} must evaluate to a |Float| or a |Number|. 3341 Examples: > 3342 :echo atan(100) 3343< 1.560797 > 3344 :echo atan(-4.01) 3345< -1.326405 3346 3347 Can also be used as a |method|: > 3348 Compute()->atan() 3349< 3350 {only available when compiled with the |+float| feature} 3351 3352 3353atan2({expr1}, {expr2}) *atan2()* 3354 Return the arc tangent of {expr1} / {expr2}, measured in 3355 radians, as a |Float| in the range [-pi, pi]. 3356 {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 3357 Examples: > 3358 :echo atan2(-1, 1) 3359< -0.785398 > 3360 :echo atan2(1, -1) 3361< 2.356194 3362 3363 Can also be used as a |method|: > 3364 Compute()->atan2(1) 3365< 3366 {only available when compiled with the |+float| feature} 3367 3368balloon_gettext() *balloon_gettext()* 3369 Return the current text in the balloon. Only for the string, 3370 not used for the List. 3371 3372balloon_show({expr}) *balloon_show()* 3373 Show {expr} inside the balloon. For the GUI {expr} is used as 3374 a string. For a terminal {expr} can be a list, which contains 3375 the lines of the balloon. If {expr} is not a list it will be 3376 split with |balloon_split()|. 3377 If {expr} is an empty string any existing balloon is removed. 3378 3379 Example: > 3380 func GetBalloonContent() 3381 " ... initiate getting the content 3382 return '' 3383 endfunc 3384 set balloonexpr=GetBalloonContent() 3385 3386 func BalloonCallback(result) 3387 call balloon_show(a:result) 3388 endfunc 3389< Can also be used as a |method|: > 3390 GetText()->balloon_show() 3391< 3392 The intended use is that fetching the content of the balloon 3393 is initiated from 'balloonexpr'. It will invoke an 3394 asynchronous method, in which a callback invokes 3395 balloon_show(). The 'balloonexpr' itself can return an 3396 empty string or a placeholder. 3397 3398 When showing a balloon is not possible nothing happens, no 3399 error message. 3400 {only available when compiled with the |+balloon_eval| or 3401 |+balloon_eval_term| feature} 3402 3403balloon_split({msg}) *balloon_split()* 3404 Split String {msg} into lines to be displayed in a balloon. 3405 The splits are made for the current window size and optimize 3406 to show debugger output. 3407 Returns a |List| with the split lines. 3408 Can also be used as a |method|: > 3409 GetText()->balloon_split()->balloon_show() 3410 3411< {only available when compiled with the |+balloon_eval_term| 3412 feature} 3413 3414blob2list({blob}) *blob2list()* 3415 Return a List containing the number value of each byte in Blob 3416 {blob}. Examples: > 3417 blob2list(0z0102.0304) returns [1, 2, 3, 4] 3418 blob2list(0z) returns [] 3419< Returns an empty List on error. |list2blob()| does the 3420 opposite. 3421 3422 Can also be used as a |method|: > 3423 GetBlob()->blob2list() 3424 3425 *browse()* 3426browse({save}, {title}, {initdir}, {default}) 3427 Put up a file requester. This only works when "has("browse")" 3428 returns |TRUE| (only in some GUI versions). 3429 The input fields are: 3430 {save} when |TRUE|, select file to write 3431 {title} title for the requester 3432 {initdir} directory to start browsing in 3433 {default} default file name 3434 An empty string is returned when the "Cancel" button is hit, 3435 something went wrong, or browsing is not possible. 3436 3437 *browsedir()* 3438browsedir({title}, {initdir}) 3439 Put up a directory requester. This only works when 3440 "has("browse")" returns |TRUE| (only in some GUI versions). 3441 On systems where a directory browser is not supported a file 3442 browser is used. In that case: select a file in the directory 3443 to be used. 3444 The input fields are: 3445 {title} title for the requester 3446 {initdir} directory to start browsing in 3447 When the "Cancel" button is hit, something went wrong, or 3448 browsing is not possible, an empty string is returned. 3449 3450bufadd({name}) *bufadd()* 3451 Add a buffer to the buffer list with String {name}. 3452 If a buffer for file {name} already exists, return that buffer 3453 number. Otherwise return the buffer number of the newly 3454 created buffer. When {name} is an empty string then a new 3455 buffer is always created. 3456 The buffer will not have 'buflisted' set and not be loaded 3457 yet. To add some text to the buffer use this: > 3458 let bufnr = bufadd('someName') 3459 call bufload(bufnr) 3460 call setbufline(bufnr, 1, ['some', 'text']) 3461< Can also be used as a |method|: > 3462 let bufnr = 'somename'->bufadd() 3463 3464bufexists({buf}) *bufexists()* 3465 The result is a Number, which is |TRUE| if a buffer called 3466 {buf} exists. 3467 If the {buf} argument is a number, buffer numbers are used. 3468 Number zero is the alternate buffer for the current window. 3469 3470 If the {buf} argument is a string it must match a buffer name 3471 exactly. The name can be: 3472 - Relative to the current directory. 3473 - A full path. 3474 - The name of a buffer with 'buftype' set to "nofile". 3475 - A URL name. 3476 Unlisted buffers will be found. 3477 Note that help files are listed by their short name in the 3478 output of |:buffers|, but bufexists() requires using their 3479 long name to be able to find them. 3480 bufexists() may report a buffer exists, but to use the name 3481 with a |:buffer| command you may need to use |expand()|. Esp 3482 for MS-Windows 8.3 names in the form "c:\DOCUME~1" 3483 Use "bufexists(0)" to test for the existence of an alternate 3484 file name. 3485 3486 Can also be used as a |method|: > 3487 let exists = 'somename'->bufexists() 3488< 3489 Obsolete name: buffer_exists(). *buffer_exists()* 3490 3491buflisted({buf}) *buflisted()* 3492 The result is a Number, which is |TRUE| if a buffer called 3493 {buf} exists and is listed (has the 'buflisted' option set). 3494 The {buf} argument is used like with |bufexists()|. 3495 3496 Can also be used as a |method|: > 3497 let listed = 'somename'->buflisted() 3498 3499bufload({buf}) *bufload()* 3500 Ensure the buffer {buf} is loaded. When the buffer name 3501 refers to an existing file then the file is read. Otherwise 3502 the buffer will be empty. If the buffer was already loaded 3503 then there is no change. 3504 If there is an existing swap file for the file of the buffer, 3505 there will be no dialog, the buffer will be loaded anyway. 3506 The {buf} argument is used like with |bufexists()|. 3507 3508 Can also be used as a |method|: > 3509 eval 'somename'->bufload() 3510 3511bufloaded({buf}) *bufloaded()* 3512 The result is a Number, which is |TRUE| if a buffer called 3513 {buf} exists and is loaded (shown in a window or hidden). 3514 The {buf} argument is used like with |bufexists()|. 3515 3516 Can also be used as a |method|: > 3517 let loaded = 'somename'->bufloaded() 3518 3519bufname([{buf}]) *bufname()* 3520 The result is the name of a buffer. Mostly as it is displayed 3521 by the `:ls` command, but not using special names such as 3522 "[No Name]". 3523 If {buf} is omitted the current buffer is used. 3524 If {buf} is a Number, that buffer number's name is given. 3525 Number zero is the alternate buffer for the current window. 3526 If {buf} is a String, it is used as a |file-pattern| to match 3527 with the buffer names. This is always done like 'magic' is 3528 set and 'cpoptions' is empty. When there is more than one 3529 match an empty string is returned. 3530 "" or "%" can be used for the current buffer, "#" for the 3531 alternate buffer. 3532 A full match is preferred, otherwise a match at the start, end 3533 or middle of the buffer name is accepted. If you only want a 3534 full match then put "^" at the start and "$" at the end of the 3535 pattern. 3536 Listed buffers are found first. If there is a single match 3537 with a listed buffer, that one is returned. Next unlisted 3538 buffers are searched for. 3539 If the {buf} is a String, but you want to use it as a buffer 3540 number, force it to be a Number by adding zero to it: > 3541 :echo bufname("3" + 0) 3542< Can also be used as a |method|: > 3543 echo bufnr->bufname() 3544 3545< If the buffer doesn't exist, or doesn't have a name, an empty 3546 string is returned. > 3547 bufname("#") alternate buffer name 3548 bufname(3) name of buffer 3 3549 bufname("%") name of current buffer 3550 bufname("file2") name of buffer where "file2" matches. 3551< *buffer_name()* 3552 Obsolete name: buffer_name(). 3553 3554 *bufnr()* 3555bufnr([{buf} [, {create}]]) 3556 The result is the number of a buffer, as it is displayed by 3557 the `:ls` command. For the use of {buf}, see |bufname()| 3558 above. 3559 3560 If the buffer doesn't exist, -1 is returned. Or, if the 3561 {create} argument is present and TRUE, a new, unlisted, 3562 buffer is created and its number is returned. Example: > 3563 let newbuf = bufnr('Scratch001', 1) 3564< Using an empty name uses the current buffer. To create a new 3565 buffer with an empty name use |bufadd()|. 3566 3567 bufnr("$") is the last buffer: > 3568 :let last_buffer = bufnr("$") 3569< The result is a Number, which is the highest buffer number 3570 of existing buffers. Note that not all buffers with a smaller 3571 number necessarily exist, because ":bwipeout" may have removed 3572 them. Use bufexists() to test for the existence of a buffer. 3573 3574 Can also be used as a |method|: > 3575 echo bufref->bufnr() 3576< 3577 Obsolete name: buffer_number(). *buffer_number()* 3578 *last_buffer_nr()* 3579 Obsolete name for bufnr("$"): last_buffer_nr(). 3580 3581bufwinid({buf}) *bufwinid()* 3582 The result is a Number, which is the |window-ID| of the first 3583 window associated with buffer {buf}. For the use of {buf}, 3584 see |bufname()| above. If buffer {buf} doesn't exist or 3585 there is no such window, -1 is returned. Example: > 3586 3587 echo "A window containing buffer 1 is " . (bufwinid(1)) 3588< 3589 Only deals with the current tab page. 3590 3591 Can also be used as a |method|: > 3592 FindBuffer()->bufwinid() 3593 3594bufwinnr({buf}) *bufwinnr()* 3595 Like |bufwinid()| but return the window number instead of the 3596 |window-ID|. 3597 If buffer {buf} doesn't exist or there is no such window, -1 3598 is returned. Example: > 3599 3600 echo "A window containing buffer 1 is " . (bufwinnr(1)) 3601 3602< The number can be used with |CTRL-W_w| and ":wincmd w" 3603 |:wincmd|. 3604 3605 Can also be used as a |method|: > 3606 FindBuffer()->bufwinnr() 3607 3608byte2line({byte}) *byte2line()* 3609 Return the line number that contains the character at byte 3610 count {byte} in the current buffer. This includes the 3611 end-of-line character, depending on the 'fileformat' option 3612 for the current buffer. The first character has byte count 3613 one. 3614 Also see |line2byte()|, |go| and |:goto|. 3615 3616 Can also be used as a |method|: > 3617 GetOffset()->byte2line() 3618 3619< {not available when compiled without the |+byte_offset| 3620 feature} 3621 3622byteidx({expr}, {nr}) *byteidx()* 3623 Return byte index of the {nr}'th character in the String 3624 {expr}. Use zero for the first character, it then returns 3625 zero. 3626 If there are no multibyte characters the returned value is 3627 equal to {nr}. 3628 Composing characters are not counted separately, their byte 3629 length is added to the preceding base character. See 3630 |byteidxcomp()| below for counting composing characters 3631 separately. 3632 Example : > 3633 echo matchstr(str, ".", byteidx(str, 3)) 3634< will display the fourth character. Another way to do the 3635 same: > 3636 let s = strpart(str, byteidx(str, 3)) 3637 echo strpart(s, 0, byteidx(s, 1)) 3638< Also see |strgetchar()| and |strcharpart()|. 3639 3640 If there are less than {nr} characters -1 is returned. 3641 If there are exactly {nr} characters the length of the string 3642 in bytes is returned. 3643 3644 Can also be used as a |method|: > 3645 GetName()->byteidx(idx) 3646 3647byteidxcomp({expr}, {nr}) *byteidxcomp()* 3648 Like byteidx(), except that a composing character is counted 3649 as a separate character. Example: > 3650 let s = 'e' . nr2char(0x301) 3651 echo byteidx(s, 1) 3652 echo byteidxcomp(s, 1) 3653 echo byteidxcomp(s, 2) 3654< The first and third echo result in 3 ('e' plus composing 3655 character is 3 bytes), the second echo results in 1 ('e' is 3656 one byte). 3657 Only works differently from byteidx() when 'encoding' is set 3658 to a Unicode encoding. 3659 3660 Can also be used as a |method|: > 3661 GetName()->byteidxcomp(idx) 3662 3663call({func}, {arglist} [, {dict}]) *call()* *E699* 3664 Call function {func} with the items in |List| {arglist} as 3665 arguments. 3666 {func} can either be a |Funcref| or the name of a function. 3667 a:firstline and a:lastline are set to the cursor line. 3668 Returns the return value of the called function. 3669 {dict} is for functions with the "dict" attribute. It will be 3670 used to set the local variable "self". |Dictionary-function| 3671 3672 Can also be used as a |method|: > 3673 GetFunc()->call([arg, arg], dict) 3674 3675ceil({expr}) *ceil()* 3676 Return the smallest integral value greater than or equal to 3677 {expr} as a |Float| (round up). 3678 {expr} must evaluate to a |Float| or a |Number|. 3679 Examples: > 3680 echo ceil(1.456) 3681< 2.0 > 3682 echo ceil(-5.456) 3683< -5.0 > 3684 echo ceil(4.0) 3685< 4.0 3686 3687 Can also be used as a |method|: > 3688 Compute()->ceil() 3689< 3690 {only available when compiled with the |+float| feature} 3691 3692 3693ch_ functions are documented here: |channel-functions-details| 3694 3695 3696changenr() *changenr()* 3697 Return the number of the most recent change. This is the same 3698 number as what is displayed with |:undolist| and can be used 3699 with the |:undo| command. 3700 When a change was made it is the number of that change. After 3701 redo it is the number of the redone change. After undo it is 3702 one less than the number of the undone change. 3703 3704char2nr({string} [, {utf8}]) *char2nr()* 3705 Return number value of the first char in {string}. 3706 Examples: > 3707 char2nr(" ") returns 32 3708 char2nr("ABC") returns 65 3709< When {utf8} is omitted or zero, the current 'encoding' is used. 3710 Example for "utf-8": > 3711 char2nr("á") returns 225 3712 char2nr("á"[0]) returns 195 3713< When {utf8} is TRUE, always treat as UTF-8 characters. 3714 A combining character is a separate character. 3715 |nr2char()| does the opposite. 3716 To turn a string into a list of character numbers: > 3717 let str = "ABC" 3718 let list = map(split(str, '\zs'), {_, val -> char2nr(val)}) 3719< Result: [65, 66, 67] 3720 3721 Can also be used as a |method|: > 3722 GetChar()->char2nr() 3723 3724 3725charclass({string}) *charclass()* 3726 Return the character class of the first character in {string}. 3727 The character class is one of: 3728 0 blank 3729 1 punctuation 3730 2 word character 3731 3 emoji 3732 other specific Unicode class 3733 The class is used in patterns and word motions. 3734 3735 3736charcol({expr}) *charcol()* 3737 Same as |col()| but returns the character index of the column 3738 position given with {expr} instead of the byte position. 3739 3740 Example: 3741 With the cursor on '세' in line 5 with text "여보세요": > 3742 charcol('.') returns 3 3743 col('.') returns 7 3744 3745< Can also be used as a |method|: > 3746 GetPos()->col() 3747< 3748 *charidx()* 3749charidx({string}, {idx} [, {countcc}]) 3750 Return the character index of the byte at {idx} in {string}. 3751 The index of the first character is zero. 3752 If there are no multibyte characters the returned value is 3753 equal to {idx}. 3754 When {countcc} is omitted or |FALSE|, then composing characters 3755 are not counted separately, their byte length is 3756 added to the preceding base character. 3757 When {countcc} is |TRUE|, then composing characters are 3758 counted as separate characters. 3759 Returns -1 if the arguments are invalid or if {idx} is greater 3760 than the index of the last byte in {string}. An error is 3761 given if the first argument is not a string, the second 3762 argument is not a number or when the third argument is present 3763 and is not zero or one. 3764 See |byteidx()| and |byteidxcomp()| for getting the byte index 3765 from the character index. 3766 Examples: > 3767 echo charidx('áb́ć', 3) returns 1 3768 echo charidx('áb́ć', 6, 1) returns 4 3769 echo charidx('áb́ć', 16) returns -1 3770< 3771 Can also be used as a |method|: > 3772 GetName()->charidx(idx) 3773 3774chdir({dir}) *chdir()* 3775 Change the current working directory to {dir}. The scope of 3776 the directory change depends on the directory of the current 3777 window: 3778 - If the current window has a window-local directory 3779 (|:lcd|), then changes the window local directory. 3780 - Otherwise, if the current tabpage has a local 3781 directory (|:tcd|) then changes the tabpage local 3782 directory. 3783 - Otherwise, changes the global directory. 3784 {dir} must be a String. 3785 If successful, returns the previous working directory. Pass 3786 this to another chdir() to restore the directory. 3787 On failure, returns an empty string. 3788 3789 Example: > 3790 let save_dir = chdir(newdir) 3791 if save_dir != "" 3792 " ... do some work 3793 call chdir(save_dir) 3794 endif 3795 3796< Can also be used as a |method|: > 3797 GetDir()->chdir() 3798< 3799cindent({lnum}) *cindent()* 3800 Get the amount of indent for line {lnum} according the C 3801 indenting rules, as with 'cindent'. 3802 The indent is counted in spaces, the value of 'tabstop' is 3803 relevant. {lnum} is used just like in |getline()|. 3804 When {lnum} is invalid or Vim was not compiled the |+cindent| 3805 feature, -1 is returned. 3806 See |C-indenting|. 3807 3808 Can also be used as a |method|: > 3809 GetLnum()->cindent() 3810 3811clearmatches([{win}]) *clearmatches()* 3812 Clears all matches previously defined for the current window 3813 by |matchadd()| and the |:match| commands. 3814 If {win} is specified, use the window with this number or 3815 window ID instead of the current window. 3816 3817 Can also be used as a |method|: > 3818 GetWin()->clearmatches() 3819< 3820 *col()* 3821col({expr}) The result is a Number, which is the byte index of the column 3822 position given with {expr}. The accepted positions are: 3823 . the cursor position 3824 $ the end of the cursor line (the result is the 3825 number of bytes in the cursor line plus one) 3826 'x position of mark x (if the mark is not set, 0 is 3827 returned) 3828 v In Visual mode: the start of the Visual area (the 3829 cursor is the end). When not in Visual mode 3830 returns the cursor position. Differs from |'<| in 3831 that it's updated right away. 3832 Additionally {expr} can be [lnum, col]: a |List| with the line 3833 and column number. Most useful when the column is "$", to get 3834 the last column of a specific line. When "lnum" or "col" is 3835 out of range then col() returns zero. 3836 To get the line number use |line()|. To get both use 3837 |getpos()|. 3838 For the screen column position use |virtcol()|. For the 3839 character position use |charcol()|. 3840 Note that only marks in the current file can be used. 3841 Examples: > 3842 col(".") column of cursor 3843 col("$") length of cursor line plus one 3844 col("'t") column of mark t 3845 col("'" . markname) column of mark markname 3846< The first column is 1. 0 is returned for an error. 3847 For an uppercase mark the column may actually be in another 3848 buffer. 3849 For the cursor position, when 'virtualedit' is active, the 3850 column is one higher if the cursor is after the end of the 3851 line. This can be used to obtain the column in Insert mode: > 3852 :imap <F2> <C-O>:let save_ve = &ve<CR> 3853 \<C-O>:set ve=all<CR> 3854 \<C-O>:echo col(".") . "\n" <Bar> 3855 \let &ve = save_ve<CR> 3856 3857< Can also be used as a |method|: > 3858 GetPos()->col() 3859< 3860 3861complete({startcol}, {matches}) *complete()* *E785* 3862 Set the matches for Insert mode completion. 3863 Can only be used in Insert mode. You need to use a mapping 3864 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O 3865 or with an expression mapping. 3866 {startcol} is the byte offset in the line where the completed 3867 text start. The text up to the cursor is the original text 3868 that will be replaced by the matches. Use col('.') for an 3869 empty string. "col('.') - 1" will replace one character by a 3870 match. 3871 {matches} must be a |List|. Each |List| item is one match. 3872 See |complete-items| for the kind of items that are possible. 3873 "longest" in 'completeopt' is ignored. 3874 Note that the after calling this function you need to avoid 3875 inserting anything that would cause completion to stop. 3876 The match can be selected with CTRL-N and CTRL-P as usual with 3877 Insert mode completion. The popup menu will appear if 3878 specified, see |ins-completion-menu|. 3879 Example: > 3880 inoremap <F5> <C-R>=ListMonths()<CR> 3881 3882 func! ListMonths() 3883 call complete(col('.'), ['January', 'February', 'March', 3884 \ 'April', 'May', 'June', 'July', 'August', 'September', 3885 \ 'October', 'November', 'December']) 3886 return '' 3887 endfunc 3888< This isn't very useful, but it shows how it works. Note that 3889 an empty string is returned to avoid a zero being inserted. 3890 3891 Can also be used as a |method|, the base is passed as the 3892 second argument: > 3893 GetMatches()->complete(col('.')) 3894 3895complete_add({expr}) *complete_add()* 3896 Add {expr} to the list of matches. Only to be used by the 3897 function specified with the 'completefunc' option. 3898 Returns 0 for failure (empty string or out of memory), 3899 1 when the match was added, 2 when the match was already in 3900 the list. 3901 See |complete-functions| for an explanation of {expr}. It is 3902 the same as one item in the list that 'omnifunc' would return. 3903 3904 Can also be used as a |method|: > 3905 GetMoreMatches()->complete_add() 3906 3907complete_check() *complete_check()* 3908 Check for a key typed while looking for completion matches. 3909 This is to be used when looking for matches takes some time. 3910 Returns |TRUE| when searching for matches is to be aborted, 3911 zero otherwise. 3912 Only to be used by the function specified with the 3913 'completefunc' option. 3914 3915 3916complete_info([{what}]) *complete_info()* 3917 Returns a |Dictionary| with information about Insert mode 3918 completion. See |ins-completion|. 3919 The items are: 3920 mode Current completion mode name string. 3921 See |complete_info_mode| for the values. 3922 pum_visible |TRUE| if popup menu is visible. 3923 See |pumvisible()|. 3924 items List of completion matches. Each item is a 3925 dictionary containing the entries "word", 3926 "abbr", "menu", "kind", "info" and "user_data". 3927 See |complete-items|. 3928 selected Selected item index. First index is zero. 3929 Index is -1 if no item is selected (showing 3930 typed text only, or the last completion after 3931 no item is selected when using the <Up> or 3932 <Down> keys) 3933 inserted Inserted string. [NOT IMPLEMENT YET] 3934 3935 *complete_info_mode* 3936 mode values are: 3937 "" Not in completion mode 3938 "keyword" Keyword completion |i_CTRL-X_CTRL-N| 3939 "ctrl_x" Just pressed CTRL-X |i_CTRL-X| 3940 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or 3941 |i_CTRL-X_CTRL-Y| 3942 "whole_line" Whole lines |i_CTRL-X_CTRL-L| 3943 "files" File names |i_CTRL-X_CTRL-F| 3944 "tags" Tags |i_CTRL-X_CTRL-]| 3945 "path_defines" Definition completion |i_CTRL-X_CTRL-D| 3946 "path_patterns" Include completion |i_CTRL-X_CTRL-I| 3947 "dictionary" Dictionary |i_CTRL-X_CTRL-K| 3948 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T| 3949 "cmdline" Vim Command line |i_CTRL-X_CTRL-V| 3950 "function" User defined completion |i_CTRL-X_CTRL-U| 3951 "omni" Omni completion |i_CTRL-X_CTRL-O| 3952 "spell" Spelling suggestions |i_CTRL-X_s| 3953 "eval" |complete()| completion 3954 "unknown" Other internal modes 3955 3956 If the optional {what} list argument is supplied, then only 3957 the items listed in {what} are returned. Unsupported items in 3958 {what} are silently ignored. 3959 3960 To get the position and size of the popup menu, see 3961 |pum_getpos()|. It's also available in |v:event| during the 3962 |CompleteChanged| event. 3963 3964 Examples: > 3965 " Get all items 3966 call complete_info() 3967 " Get only 'mode' 3968 call complete_info(['mode']) 3969 " Get only 'mode' and 'pum_visible' 3970 call complete_info(['mode', 'pum_visible']) 3971 3972< Can also be used as a |method|: > 3973 GetItems()->complete_info() 3974< 3975 *confirm()* 3976confirm({msg} [, {choices} [, {default} [, {type}]]]) 3977 confirm() offers the user a dialog, from which a choice can be 3978 made. It returns the number of the choice. For the first 3979 choice this is 1. 3980 Note: confirm() is only supported when compiled with dialog 3981 support, see |+dialog_con| and |+dialog_gui|. 3982 3983 {msg} is displayed in a |dialog| with {choices} as the 3984 alternatives. When {choices} is missing or empty, "&OK" is 3985 used (and translated). 3986 {msg} is a String, use '\n' to include a newline. Only on 3987 some systems the string is wrapped when it doesn't fit. 3988 3989 {choices} is a String, with the individual choices separated 3990 by '\n', e.g. > 3991 confirm("Save changes?", "&Yes\n&No\n&Cancel") 3992< The letter after the '&' is the shortcut key for that choice. 3993 Thus you can type 'c' to select "Cancel". The shortcut does 3994 not need to be the first letter: > 3995 confirm("file has been modified", "&Save\nSave &All") 3996< For the console, the first letter of each choice is used as 3997 the default shortcut key. Case is ignored. 3998 3999 The optional {default} argument is the number of the choice 4000 that is made if the user hits <CR>. Use 1 to make the first 4001 choice the default one. Use 0 to not set a default. If 4002 {default} is omitted, 1 is used. 4003 4004 The optional {type} String argument gives the type of dialog. 4005 This is only used for the icon of the GTK, Mac, Motif and 4006 Win32 GUI. It can be one of these values: "Error", 4007 "Question", "Info", "Warning" or "Generic". Only the first 4008 character is relevant. When {type} is omitted, "Generic" is 4009 used. 4010 4011 If the user aborts the dialog by pressing <Esc>, CTRL-C, 4012 or another valid interrupt key, confirm() returns 0. 4013 4014 An example: > 4015 :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2) 4016 :if choice == 0 4017 : echo "make up your mind!" 4018 :elseif choice == 3 4019 : echo "tasteful" 4020 :else 4021 : echo "I prefer bananas myself." 4022 :endif 4023< In a GUI dialog, buttons are used. The layout of the buttons 4024 depends on the 'v' flag in 'guioptions'. If it is included, 4025 the buttons are always put vertically. Otherwise, confirm() 4026 tries to put the buttons in one horizontal line. If they 4027 don't fit, a vertical layout is used anyway. For some systems 4028 the horizontal layout is always used. 4029 4030 Can also be used as a |method|in: > 4031 BuildMessage()->confirm("&Yes\n&No") 4032< 4033 *copy()* 4034copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't 4035 different from using {expr} directly. 4036 When {expr} is a |List| a shallow copy is created. This means 4037 that the original |List| can be changed without changing the 4038 copy, and vice versa. But the items are identical, thus 4039 changing an item changes the contents of both |Lists|. 4040 A |Dictionary| is copied in a similar way as a |List|. 4041 Also see |deepcopy()|. 4042 Can also be used as a |method|: > 4043 mylist->copy() 4044 4045cos({expr}) *cos()* 4046 Return the cosine of {expr}, measured in radians, as a |Float|. 4047 {expr} must evaluate to a |Float| or a |Number|. 4048 Examples: > 4049 :echo cos(100) 4050< 0.862319 > 4051 :echo cos(-4.01) 4052< -0.646043 4053 4054 Can also be used as a |method|: > 4055 Compute()->cos() 4056< 4057 {only available when compiled with the |+float| feature} 4058 4059 4060cosh({expr}) *cosh()* 4061 Return the hyperbolic cosine of {expr} as a |Float| in the range 4062 [1, inf]. 4063 {expr} must evaluate to a |Float| or a |Number|. 4064 Examples: > 4065 :echo cosh(0.5) 4066< 1.127626 > 4067 :echo cosh(-0.5) 4068< -1.127626 4069 4070 Can also be used as a |method|: > 4071 Compute()->cosh() 4072< 4073 {only available when compiled with the |+float| feature} 4074 4075 4076count({comp}, {expr} [, {ic} [, {start}]]) *count()* 4077 Return the number of times an item with value {expr} appears 4078 in |String|, |List| or |Dictionary| {comp}. 4079 4080 If {start} is given then start with the item with this index. 4081 {start} can only be used with a |List|. 4082 4083 When {ic} is given and it's |TRUE| then case is ignored. 4084 4085 When {comp} is a string then the number of not overlapping 4086 occurrences of {expr} is returned. Zero is returned when 4087 {expr} is an empty string. 4088 4089 Can also be used as a |method|: > 4090 mylist->count(val) 4091< 4092 *cscope_connection()* 4093cscope_connection([{num} , {dbpath} [, {prepend}]]) 4094 Checks for the existence of a |cscope| connection. If no 4095 parameters are specified, then the function returns: 4096 0, if cscope was not available (not compiled in), or 4097 if there are no cscope connections; 4098 1, if there is at least one cscope connection. 4099 4100 If parameters are specified, then the value of {num} 4101 determines how existence of a cscope connection is checked: 4102 4103 {num} Description of existence check 4104 ----- ------------------------------ 4105 0 Same as no parameters (e.g., "cscope_connection()"). 4106 1 Ignore {prepend}, and use partial string matches for 4107 {dbpath}. 4108 2 Ignore {prepend}, and use exact string matches for 4109 {dbpath}. 4110 3 Use {prepend}, use partial string matches for both 4111 {dbpath} and {prepend}. 4112 4 Use {prepend}, use exact string matches for both 4113 {dbpath} and {prepend}. 4114 4115 Note: All string comparisons are case sensitive! 4116 4117 Examples. Suppose we had the following (from ":cs show"): > 4118 4119 # pid database name prepend path 4120 0 27664 cscope.out /usr/local 4121< 4122 Invocation Return Val ~ 4123 ---------- ---------- > 4124 cscope_connection() 1 4125 cscope_connection(1, "out") 1 4126 cscope_connection(2, "out") 0 4127 cscope_connection(3, "out") 0 4128 cscope_connection(3, "out", "local") 1 4129 cscope_connection(4, "out") 0 4130 cscope_connection(4, "out", "local") 0 4131 cscope_connection(4, "cscope.out", "/usr/local") 1 4132< 4133cursor({lnum}, {col} [, {off}]) *cursor()* 4134cursor({list}) 4135 Positions the cursor at the column (byte count) {col} in the 4136 line {lnum}. The first column is one. 4137 4138 When there is one argument {list} this is used as a |List| 4139 with two, three or four item: 4140 [{lnum}, {col}] 4141 [{lnum}, {col}, {off}] 4142 [{lnum}, {col}, {off}, {curswant}] 4143 This is like the return value of |getpos()| or |getcurpos()|, 4144 but without the first item. 4145 4146 To position the cursor using the character count, use 4147 |setcursorcharpos()|. 4148 4149 Does not change the jumplist. 4150 {lnum} is used like with |getline()|. 4151 If {lnum} is greater than the number of lines in the buffer, 4152 the cursor will be positioned at the last line in the buffer. 4153 If {lnum} is zero, the cursor will stay in the current line. 4154 If {col} is greater than the number of bytes in the line, 4155 the cursor will be positioned at the last character in the 4156 line. 4157 If {col} is zero, the cursor will stay in the current column. 4158 If {curswant} is given it is used to set the preferred column 4159 for vertical movement. Otherwise {col} is used. 4160 4161 When 'virtualedit' is used {off} specifies the offset in 4162 screen columns from the start of the character. E.g., a 4163 position within a <Tab> or after the last character. 4164 Returns 0 when the position could be set, -1 otherwise. 4165 4166 Can also be used as a |method|: > 4167 GetCursorPos()->cursor() 4168 4169debugbreak({pid}) *debugbreak()* 4170 Specifically used to interrupt a program being debugged. It 4171 will cause process {pid} to get a SIGTRAP. Behavior for other 4172 processes is undefined. See |terminal-debugger|. 4173 {only available on MS-Windows} 4174 4175 Can also be used as a |method|: > 4176 GetPid()->debugbreak() 4177 4178deepcopy({expr} [, {noref}]) *deepcopy()* *E698* 4179 Make a copy of {expr}. For Numbers and Strings this isn't 4180 different from using {expr} directly. 4181 When {expr} is a |List| a full copy is created. This means 4182 that the original |List| can be changed without changing the 4183 copy, and vice versa. When an item is a |List| or 4184 |Dictionary|, a copy for it is made, recursively. Thus 4185 changing an item in the copy does not change the contents of 4186 the original |List|. 4187 A |Dictionary| is copied in a similar way as a |List|. 4188 4189 When {noref} is omitted or zero a contained |List| or 4190 |Dictionary| is only copied once. All references point to 4191 this single copy. With {noref} set to 1 every occurrence of a 4192 |List| or |Dictionary| results in a new copy. This also means 4193 that a cyclic reference causes deepcopy() to fail. 4194 *E724* 4195 Nesting is possible up to 100 levels. When there is an item 4196 that refers back to a higher level making a deep copy with 4197 {noref} set to 1 will fail. 4198 Also see |copy()|. 4199 4200 Can also be used as a |method|: > 4201 GetObject()->deepcopy() 4202 4203delete({fname} [, {flags}]) *delete()* 4204 Without {flags} or with {flags} empty: Deletes the file by the 4205 name {fname}. This also works when {fname} is a symbolic link. 4206 4207 When {flags} is "d": Deletes the directory by the name 4208 {fname}. This fails when directory {fname} is not empty. 4209 4210 When {flags} is "rf": Deletes the directory by the name 4211 {fname} and everything in it, recursively. BE CAREFUL! 4212 Note: on MS-Windows it is not possible to delete a directory 4213 that is being used. 4214 4215 A symbolic link itself is deleted, not what it points to. 4216 4217 The result is a Number, which is 0/false if the delete 4218 operation was successful and -1/true when the deletion failed 4219 or partly failed. 4220 4221 Use |remove()| to delete an item from a |List|. 4222 To delete a line from the buffer use |:delete| or 4223 |deletebufline()|. 4224 4225 Can also be used as a |method|: > 4226 GetName()->delete() 4227 4228deletebufline({buf}, {first} [, {last}]) *deletebufline()* 4229 Delete lines {first} to {last} (inclusive) from buffer {buf}. 4230 If {last} is omitted then delete line {first} only. 4231 On success 0 is returned, on failure 1 is returned. 4232 4233 This function works only for loaded buffers. First call 4234 |bufload()| if needed. 4235 4236 For the use of {buf}, see |bufname()| above. 4237 4238 {first} and {last} are used like with |getline()|. Note that 4239 when using |line()| this refers to the current buffer. Use "$" 4240 to refer to the last line in buffer {buf}. 4241 4242 Can also be used as a |method|: > 4243 GetBuffer()->deletebufline(1) 4244< 4245 *did_filetype()* 4246did_filetype() Returns |TRUE| when autocommands are being executed and the 4247 FileType event has been triggered at least once. Can be used 4248 to avoid triggering the FileType event again in the scripts 4249 that detect the file type. |FileType| 4250 Returns |FALSE| when `:setf FALLBACK` was used. 4251 When editing another file, the counter is reset, thus this 4252 really checks if the FileType event has been triggered for the 4253 current buffer. This allows an autocommand that starts 4254 editing another buffer to set 'filetype' and load a syntax 4255 file. 4256 4257diff_filler({lnum}) *diff_filler()* 4258 Returns the number of filler lines above line {lnum}. 4259 These are the lines that were inserted at this point in 4260 another diff'ed window. These filler lines are shown in the 4261 display but don't exist in the buffer. 4262 {lnum} is used like with |getline()|. Thus "." is the current 4263 line, "'m" mark m, etc. 4264 Returns 0 if the current window is not in diff mode. 4265 4266 Can also be used as a |method|: > 4267 GetLnum()->diff_filler() 4268 4269diff_hlID({lnum}, {col}) *diff_hlID()* 4270 Returns the highlight ID for diff mode at line {lnum} column 4271 {col} (byte index). When the current line does not have a 4272 diff change zero is returned. 4273 {lnum} is used like with |getline()|. Thus "." is the current 4274 line, "'m" mark m, etc. 4275 {col} is 1 for the leftmost column, {lnum} is 1 for the first 4276 line. 4277 The highlight ID can be used with |synIDattr()| to obtain 4278 syntax information about the highlighting. 4279 4280 Can also be used as a |method|: > 4281 GetLnum()->diff_hlID(col) 4282< 4283 4284digraph_get({chars}) *digraph_get()* *E1214* 4285 Return the digraph of {chars}. This should be a string with 4286 exactly two characters. If {chars} are not just two 4287 characters, or the digraph of {chars} does not exist, an error 4288 is given and an empty string is returned. 4289 4290 The character will be converted from Unicode to 'encoding' 4291 when needed. This does require the conversion to be 4292 available, it might fail. 4293 4294 Also see |digraph_getlist()|. 4295 4296 Examples: > 4297 " Get a built-in digraph 4298 :echo digraph_get('00') " Returns '∞' 4299 4300 " Get a user-defined digraph 4301 :call digraph_set('aa', 'あ') 4302 :echo digraph_get('aa') " Returns 'あ' 4303< 4304 Can also be used as a |method|: > 4305 GetChars()->digraph_get() 4306< 4307 This function works only when compiled with the |+digraphs| 4308 feature. If this feature is disabled, this function will 4309 display an error message. 4310 4311 4312digraph_getlist([{listall}]) *digraph_getlist()* 4313 Return a list of digraphs. If the {listall} argument is given 4314 and it is TRUE, return all digraphs, including the default 4315 digraphs. Otherwise, return only user-defined digraphs. 4316 4317 The characters will be converted from Unicode to 'encoding' 4318 when needed. This does require the conservation to be 4319 available, it might fail. 4320 4321 Also see |digraph_get()|. 4322 4323 Examples: > 4324 " Get user-defined digraphs 4325 :echo digraph_getlist() 4326 4327 " Get all the digraphs, including default digraphs 4328 :echo digraph_getlist(1) 4329< 4330 Can also be used as a |method|: > 4331 GetNumber()->digraph_getlist() 4332< 4333 This function works only when compiled with the |+digraphs| 4334 feature. If this feature is disabled, this function will 4335 display an error message. 4336 4337 4338digraph_set({chars}, {digraph}) *digraph_set()* *E1205* 4339 Add digraph {chars} to the list. {chars} must be a string 4340 with two characters. {digraph} is a string with one UTF-8 4341 encoded character. Be careful, composing characters are NOT 4342 ignored. This function is similar to |:digraphs| command, but 4343 useful to add digraphs start with a white space. 4344 4345 The function result is v:true if |digraph| is registered. If 4346 this fails an error message is given and v:false is returned. 4347 4348 If you want to define multiple digraphs at once, you can use 4349 |digraph_setlist()|. 4350 4351 Example: > 4352 call digraph_set(' ', 'あ') 4353< 4354 Can be used as a |method|: > 4355 GetString()->digraph_set('あ') 4356< 4357 This function works only when compiled with the |+digraphs| 4358 feature. If this feature is disabled, this function will 4359 display an error message. 4360 4361 4362digraph_setlist({digraphlist}) *digraph_setlist()* 4363 Similar to |digraph_set()| but this function can add multiple 4364 digraphs at once. {digraphlist} is a list composed of lists, 4365 where each list contains two strings with {chars} and 4366 {digraph} as in |digraph_set()|. 4367 Example: > 4368 call digraph_setlist([['aa', 'あ'], ['ii', 'い']]) 4369< 4370 It is similar to the following: > 4371 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']] 4372 call digraph_set(chars, digraph) 4373 endfor 4374< Except that the function returns after the first error, 4375 following digraphs will not be added. 4376 4377 Can be used as a |method|: > 4378 GetList()->digraph_setlist() 4379< 4380 This function works only when compiled with the |+digraphs| 4381 feature. If this feature is disabled, this function will 4382 display an error message. 4383 4384 4385echoraw({string}) *echoraw()* 4386 Output {string} as-is, including unprintable characters. 4387 This can be used to output a terminal code. For example, to 4388 disable modifyOtherKeys: > 4389 call echoraw(&t_TE) 4390< and to enable it again: > 4391 call echoraw(&t_TI) 4392< Use with care, you can mess up the terminal this way. 4393 4394 4395empty({expr}) *empty()* 4396 Return the Number 1 if {expr} is empty, zero otherwise. 4397 - A |List| or |Dictionary| is empty when it does not have any 4398 items. 4399 - A |String| is empty when its length is zero. 4400 - A |Number| and |Float| are empty when their value is zero. 4401 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not. 4402 - A |Job| is empty when it failed to start. 4403 - A |Channel| is empty when it is closed. 4404 - A |Blob| is empty when its length is zero. 4405 4406 For a long |List| this is much faster than comparing the 4407 length with zero. 4408 4409 Can also be used as a |method|: > 4410 mylist->empty() 4411 4412environ() *environ()* 4413 Return all of environment variables as dictionary. You can 4414 check if an environment variable exists like this: > 4415 :echo has_key(environ(), 'HOME') 4416< Note that the variable name may be CamelCase; to ignore case 4417 use this: > 4418 :echo index(keys(environ()), 'HOME', 0, 1) != -1 4419 4420escape({string}, {chars}) *escape()* 4421 Escape the characters in {chars} that occur in {string} with a 4422 backslash. Example: > 4423 :echo escape('c:\program files\vim', ' \') 4424< results in: > 4425 c:\\program\ files\\vim 4426< Also see |shellescape()| and |fnameescape()|. 4427 4428 Can also be used as a |method|: > 4429 GetText()->escape(' \') 4430< 4431 *eval()* 4432eval({string}) Evaluate {string} and return the result. Especially useful to 4433 turn the result of |string()| back into the original value. 4434 This works for Numbers, Floats, Strings, Blobs and composites 4435 of them. Also works for |Funcref|s that refer to existing 4436 functions. 4437 4438 Can also be used as a |method|: > 4439 argv->join()->eval() 4440 4441eventhandler() *eventhandler()* 4442 Returns 1 when inside an event handler. That is that Vim got 4443 interrupted while waiting for the user to type a character, 4444 e.g., when dropping a file on Vim. This means interactive 4445 commands cannot be used. Otherwise zero is returned. 4446 4447executable({expr}) *executable()* 4448 This function checks if an executable with the name {expr} 4449 exists. {expr} must be the name of the program without any 4450 arguments. 4451 executable() uses the value of $PATH and/or the normal 4452 searchpath for programs. *PATHEXT* 4453 On MS-Windows the ".exe", ".bat", etc. can optionally be 4454 included. Then the extensions in $PATHEXT are tried. Thus if 4455 "foo.exe" does not exist, "foo.exe.bat" can be found. If 4456 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot 4457 by itself can be used in $PATHEXT to try using the name 4458 without an extension. When 'shell' looks like a Unix shell, 4459 then the name is also tried without adding an extension. 4460 On MS-Windows it only checks if the file exists and is not a 4461 directory, not if it's really executable. 4462 On MS-Windows an executable in the same directory as Vim is 4463 always found. Since this directory is added to $PATH it 4464 should also work to execute it |win32-PATH|. 4465 The result is a Number: 4466 1 exists 4467 0 does not exist 4468 -1 not implemented on this system 4469 |exepath()| can be used to get the full path of an executable. 4470 4471 Can also be used as a |method|: > 4472 GetCommand()->executable() 4473 4474execute({command} [, {silent}]) *execute()* 4475 Execute an Ex command or commands and return the output as a 4476 string. 4477 {command} can be a string or a List. In case of a List the 4478 lines are executed one by one. 4479 This is equivalent to: > 4480 redir => var 4481 {command} 4482 redir END 4483< 4484 The optional {silent} argument can have these values: 4485 "" no `:silent` used 4486 "silent" `:silent` used 4487 "silent!" `:silent!` used 4488 The default is "silent". Note that with "silent!", unlike 4489 `:redir`, error messages are dropped. When using an external 4490 command the screen may be messed up, use `system()` instead. 4491 *E930* 4492 It is not possible to use `:redir` anywhere in {command}. 4493 4494 To get a list of lines use |split()| on the result: > 4495 split(execute('args'), "\n") 4496 4497< To execute a command in another window than the current one 4498 use `win_execute()`. 4499 4500 When used recursively the output of the recursive call is not 4501 included in the output of the higher level call. 4502 4503 Can also be used as a |method|: > 4504 GetCommand()->execute() 4505 4506exepath({expr}) *exepath()* 4507 If {expr} is an executable and is either an absolute path, a 4508 relative path or found in $PATH, return the full path. 4509 Note that the current directory is used when {expr} starts 4510 with "./", which may be a problem for Vim: > 4511 echo exepath(v:progpath) 4512< If {expr} cannot be found in $PATH or is not executable then 4513 an empty string is returned. 4514 4515 Can also be used as a |method|: > 4516 GetCommand()->exepath() 4517< 4518 *exists()* 4519exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined, 4520 zero otherwise. 4521 4522 Note: In a compiled |:def| function the evaluation is done at 4523 runtime. Use `exists_compiled()` to evaluate the expression 4524 at compile time. 4525 4526 For checking for a supported feature use |has()|. 4527 For checking if a file exists use |filereadable()|. 4528 4529 The {expr} argument is a string, which contains one of these: 4530 &option-name Vim option (only checks if it exists, 4531 not if it really works) 4532 +option-name Vim option that works. 4533 $ENVNAME environment variable (could also be 4534 done by comparing with an empty 4535 string) 4536 *funcname built-in function (see |functions|) 4537 or user defined function (see 4538 |user-functions|) that is implemented. 4539 Also works for a variable that is a 4540 Funcref. 4541 ?funcname built-in function that could be 4542 implemented; to be used to check if 4543 "funcname" is valid 4544 varname internal variable (see 4545 |internal-variables|). Also works 4546 for |curly-braces-names|, |Dictionary| 4547 entries, |List| items, etc. 4548 Does not work for local variables in a 4549 compiled `:def` function. 4550 Beware that evaluating an index may 4551 cause an error message for an invalid 4552 expression. E.g.: > 4553 :let l = [1, 2, 3] 4554 :echo exists("l[5]") 4555< 0 > 4556 :echo exists("l[xx]") 4557< E121: Undefined variable: xx 4558 0 4559 :cmdname Ex command: built-in command, user 4560 command or command modifier |:command|. 4561 Returns: 4562 1 for match with start of a command 4563 2 full match with a command 4564 3 matches several user commands 4565 To check for a supported command 4566 always check the return value to be 2. 4567 :2match The |:2match| command. 4568 :3match The |:3match| command. 4569 #event autocommand defined for this event 4570 #event#pattern autocommand defined for this event and 4571 pattern (the pattern is taken 4572 literally and compared to the 4573 autocommand patterns character by 4574 character) 4575 #group autocommand group exists 4576 #group#event autocommand defined for this group and 4577 event. 4578 #group#event#pattern 4579 autocommand defined for this group, 4580 event and pattern. 4581 ##event autocommand for this event is 4582 supported. 4583 4584 Examples: > 4585 exists("&shortname") 4586 exists("$HOSTNAME") 4587 exists("*strftime") 4588 exists("*s:MyFunc") 4589 exists("bufcount") 4590 exists(":Make") 4591 exists("#CursorHold") 4592 exists("#BufReadPre#*.gz") 4593 exists("#filetypeindent") 4594 exists("#filetypeindent#FileType") 4595 exists("#filetypeindent#FileType#*") 4596 exists("##ColorScheme") 4597< There must be no space between the symbol (&/$/*/#) and the 4598 name. 4599 There must be no extra characters after the name, although in 4600 a few cases this is ignored. That may become more strict in 4601 the future, thus don't count on it! 4602 Working example: > 4603 exists(":make") 4604< NOT working example: > 4605 exists(":make install") 4606 4607< Note that the argument must be a string, not the name of the 4608 variable itself. For example: > 4609 exists(bufcount) 4610< This doesn't check for existence of the "bufcount" variable, 4611 but gets the value of "bufcount", and checks if that exists. 4612 4613 Can also be used as a |method|: > 4614 Varname()->exists() 4615< 4616 4617exists_compiled({expr}) *exists_compiled()* 4618 Like `exists()` but evaluated at compile time. This is useful 4619 to skip a block where a function is used that would otherwise 4620 give an error: > 4621 if exists_compiled('*ThatFunction') 4622 ThatFunction('works') 4623 endif 4624< If `exists()` were used then a compilation error would be 4625 given if ThatFunction() is not defined. 4626 4627 {expr} must be a literal string. *E1232* 4628 Can only be used in a |:def| function. *E1233* 4629 This does not work to check for arguments or local variables. 4630 4631 4632exp({expr}) *exp()* 4633 Return the exponential of {expr} as a |Float| in the range 4634 [0, inf]. 4635 {expr} must evaluate to a |Float| or a |Number|. 4636 Examples: > 4637 :echo exp(2) 4638< 7.389056 > 4639 :echo exp(-1) 4640< 0.367879 4641 4642 Can also be used as a |method|: > 4643 Compute()->exp() 4644< 4645 {only available when compiled with the |+float| feature} 4646 4647 4648expand({string} [, {nosuf} [, {list}]]) *expand()* 4649 Expand wildcards and the following special keywords in 4650 {string}. 'wildignorecase' applies. 4651 4652 If {list} is given and it is |TRUE|, a List will be returned. 4653 Otherwise the result is a String and when there are several 4654 matches, they are separated by <NL> characters. [Note: in 4655 version 5.0 a space was used, which caused problems when a 4656 file name contains a space] 4657 4658 If the expansion fails, the result is an empty string. A name 4659 for a non-existing file is not included, unless {string} does 4660 not start with '%', '#' or '<', see below. 4661 4662 When {string} starts with '%', '#' or '<', the expansion is 4663 done like for the |cmdline-special| variables with their 4664 associated modifiers. Here is a short overview: 4665 4666 % current file name 4667 # alternate file name 4668 #n alternate file name n 4669 <cfile> file name under the cursor 4670 <afile> autocmd file name 4671 <abuf> autocmd buffer number (as a String!) 4672 <amatch> autocmd matched name 4673 <cexpr> C expression under the cursor 4674 <sfile> sourced script file or function name 4675 <slnum> sourced script line number or function 4676 line number 4677 <sflnum> script file line number, also when in 4678 a function 4679 <SID> "<SNR>123_" where "123" is the 4680 current script ID |<SID>| 4681 <stack> call stack 4682 <cword> word under the cursor 4683 <cWORD> WORD under the cursor 4684 <client> the {clientid} of the last received 4685 message |server2client()| 4686 Modifiers: 4687 :p expand to full path 4688 :h head (last path component removed) 4689 :t tail (last path component only) 4690 :r root (one extension removed) 4691 :e extension only 4692 4693 Example: > 4694 :let &tags = expand("%:p:h") . "/tags" 4695< Note that when expanding a string that starts with '%', '#' or 4696 '<', any following text is ignored. This does NOT work: > 4697 :let doesntwork = expand("%:h.bak") 4698< Use this: > 4699 :let doeswork = expand("%:h") . ".bak" 4700< Also note that expanding "<cfile>" and others only returns the 4701 referenced file name without further expansion. If "<cfile>" 4702 is "~/.cshrc", you need to do another expand() to have the 4703 "~/" expanded into the path of the home directory: > 4704 :echo expand(expand("<cfile>")) 4705< 4706 There cannot be white space between the variables and the 4707 following modifier. The |fnamemodify()| function can be used 4708 to modify normal file names. 4709 4710 When using '%' or '#', and the current or alternate file name 4711 is not defined, an empty string is used. Using "%:p" in a 4712 buffer with no name, results in the current directory, with a 4713 '/' added. 4714 4715 When {string} does not start with '%', '#' or '<', it is 4716 expanded like a file name is expanded on the command line. 4717 'suffixes' and 'wildignore' are used, unless the optional 4718 {nosuf} argument is given and it is |TRUE|. 4719 Names for non-existing files are included. The "**" item can 4720 be used to search in a directory tree. For example, to find 4721 all "README" files in the current directory and below: > 4722 :echo expand("**/README") 4723< 4724 expand() can also be used to expand variables and environment 4725 variables that are only known in a shell. But this can be 4726 slow, because a shell may be used to do the expansion. See 4727 |expr-env-expand|. 4728 The expanded variable is still handled like a list of file 4729 names. When an environment variable cannot be expanded, it is 4730 left unchanged. Thus ":echo expand('$FOOBAR')" results in 4731 "$FOOBAR". 4732 4733 See |glob()| for finding existing files. See |system()| for 4734 getting the raw output of an external command. 4735 4736 Can also be used as a |method|: > 4737 Getpattern()->expand() 4738 4739expandcmd({string}) *expandcmd()* 4740 Expand special items in String {string} like what is done for 4741 an Ex command such as `:edit`. This expands special keywords, 4742 like with |expand()|, and environment variables, anywhere in 4743 {string}. "~user" and "~/path" are only expanded at the 4744 start. 4745 Returns the expanded string. Example: > 4746 :echo expandcmd('make %<.o') 4747 4748< Can also be used as a |method|: > 4749 GetCommand()->expandcmd() 4750< 4751extend({expr1}, {expr2} [, {expr3}]) *extend()* 4752 {expr1} and {expr2} must be both |Lists| or both 4753 |Dictionaries|. 4754 4755 If they are |Lists|: Append {expr2} to {expr1}. 4756 If {expr3} is given insert the items of {expr2} before the 4757 item with index {expr3} in {expr1}. When {expr3} is zero 4758 insert before the first item. When {expr3} is equal to 4759 len({expr1}) then {expr2} is appended. 4760 Examples: > 4761 :echo sort(extend(mylist, [7, 5])) 4762 :call extend(mylist, [2, 3], 1) 4763< When {expr1} is the same List as {expr2} then the number of 4764 items copied is equal to the original length of the List. 4765 E.g., when {expr3} is 1 you get N new copies of the first item 4766 (where N is the original length of the List). 4767 Use |add()| to concatenate one item to a list. To concatenate 4768 two lists into a new list use the + operator: > 4769 :let newlist = [1, 2, 3] + [4, 5] 4770< 4771 If they are |Dictionaries|: 4772 Add all entries from {expr2} to {expr1}. 4773 If a key exists in both {expr1} and {expr2} then {expr3} is 4774 used to decide what to do: 4775 {expr3} = "keep": keep the value of {expr1} 4776 {expr3} = "force": use the value of {expr2} 4777 {expr3} = "error": give an error message *E737* 4778 When {expr3} is omitted then "force" is assumed. 4779 4780 {expr1} is changed when {expr2} is not empty. If necessary 4781 make a copy of {expr1} first. 4782 {expr2} remains unchanged. 4783 When {expr1} is locked and {expr2} is not empty the operation 4784 fails. 4785 Returns {expr1}. 4786 4787 Can also be used as a |method|: > 4788 mylist->extend(otherlist) 4789 4790 4791extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()* 4792 Like |extend()| but instead of adding items to {expr1} a new 4793 List or Dictionary is created and returned. {expr1} remains 4794 unchanged. Items can still be changed by {expr2}, if you 4795 don't want that use |deepcopy()| first. 4796 4797 4798feedkeys({string} [, {mode}]) *feedkeys()* 4799 Characters in {string} are queued for processing as if they 4800 come from a mapping or were typed by the user. 4801 4802 By default the string is added to the end of the typeahead 4803 buffer, thus if a mapping is still being executed the 4804 characters come after them. Use the 'i' flag to insert before 4805 other characters, they will be executed next, before any 4806 characters from a mapping. 4807 4808 The function does not wait for processing of keys contained in 4809 {string}. 4810 4811 To include special keys into {string}, use double-quotes 4812 and "\..." notation |expr-quote|. For example, 4813 feedkeys("\<CR>") simulates pressing of the <Enter> key. But 4814 feedkeys('\<CR>') pushes 5 characters. 4815 A special code that might be useful is <Ignore>, it exits the 4816 wait for a character without doing anything. *<Ignore>* 4817 4818 {mode} is a String, which can contain these character flags: 4819 'm' Remap keys. This is default. If {mode} is absent, 4820 keys are remapped. 4821 'n' Do not remap keys. 4822 't' Handle keys as if typed; otherwise they are handled as 4823 if coming from a mapping. This matters for undo, 4824 opening folds, etc. 4825 'L' Lowlevel input. Only works for Unix or when using the 4826 GUI. Keys are used as if they were coming from the 4827 terminal. Other flags are not used. *E980* 4828 When a CTRL-C interrupts and 't' is included it sets 4829 the internal "got_int" flag. 4830 'i' Insert the string instead of appending (see above). 4831 'x' Execute commands until typeahead is empty. This is 4832 similar to using ":normal!". You can call feedkeys() 4833 several times without 'x' and then one time with 'x' 4834 (possibly with an empty {string}) to execute all the 4835 typeahead. Note that when Vim ends in Insert mode it 4836 will behave as if <Esc> is typed, to avoid getting 4837 stuck, waiting for a character to be typed before the 4838 script continues. 4839 Note that if you manage to call feedkeys() while 4840 executing commands, thus calling it recursively, then 4841 all typeahead will be consumed by the last call. 4842 '!' When used with 'x' will not end Insert mode. Can be 4843 used in a test when a timer is set to exit Insert mode 4844 a little later. Useful for testing CursorHoldI. 4845 4846 Return value is always 0. 4847 4848 Can also be used as a |method|: > 4849 GetInput()->feedkeys() 4850 4851filereadable({file}) *filereadable()* 4852 The result is a Number, which is |TRUE| when a file with the 4853 name {file} exists, and can be read. If {file} doesn't exist, 4854 or is a directory, the result is |FALSE|. {file} is any 4855 expression, which is used as a String. 4856 If you don't care about the file being readable you can use 4857 |glob()|. 4858 {file} is used as-is, you may want to expand wildcards first: > 4859 echo filereadable('~/.vimrc') 4860 0 4861 echo filereadable(expand('~/.vimrc')) 4862 1 4863 4864< Can also be used as a |method|: > 4865 GetName()->filereadable() 4866< *file_readable()* 4867 Obsolete name: file_readable(). 4868 4869 4870filewritable({file}) *filewritable()* 4871 The result is a Number, which is 1 when a file with the 4872 name {file} exists, and can be written. If {file} doesn't 4873 exist, or is not writable, the result is 0. If {file} is a 4874 directory, and we can write to it, the result is 2. 4875 4876 Can also be used as a |method|: > 4877 GetName()->filewritable() 4878 4879 4880filter({expr1}, {expr2}) *filter()* 4881 {expr1} must be a |List|, |Blob| or |Dictionary|. 4882 For each item in {expr1} evaluate {expr2} and when the result 4883 is zero remove the item from the |List| or |Dictionary|. For a 4884 |Blob| each byte is removed. 4885 4886 {expr2} must be a |string| or |Funcref|. 4887 4888 If {expr2} is a |string|, inside {expr2} |v:val| has the value 4889 of the current item. For a |Dictionary| |v:key| has the key 4890 of the current item and for a |List| |v:key| has the index of 4891 the current item. For a |Blob| |v:key| has the index of the 4892 current byte. 4893 Examples: > 4894 call filter(mylist, 'v:val !~ "OLD"') 4895< Removes the items where "OLD" appears. > 4896 call filter(mydict, 'v:key >= 8') 4897< Removes the items with a key below 8. > 4898 call filter(var, 0) 4899< Removes all the items, thus clears the |List| or |Dictionary|. 4900 4901 Note that {expr2} is the result of expression and is then 4902 used as an expression again. Often it is good to use a 4903 |literal-string| to avoid having to double backslashes. 4904 4905 If {expr2} is a |Funcref| it must take two arguments: 4906 1. the key or the index of the current item. 4907 2. the value of the current item. 4908 The function must return |TRUE| if the item should be kept. 4909 Example that keeps the odd items of a list: > 4910 func Odd(idx, val) 4911 return a:idx % 2 == 1 4912 endfunc 4913 call filter(mylist, function('Odd')) 4914< It is shorter when using a |lambda|: > 4915 call filter(myList, {idx, val -> idx * val <= 42}) 4916< If you do not use "val" you can leave it out: > 4917 call filter(myList, {idx -> idx % 2 == 1}) 4918< 4919 The operation is done in-place. If you want a |List| or 4920 |Dictionary| to remain unmodified make a copy first: > 4921 :let l = filter(copy(mylist), 'v:val =~ "KEEP"') 4922 4923< Returns {expr1}, the |List| , |Blob| or |Dictionary| that was 4924 filtered. When an error is encountered while evaluating 4925 {expr2} no further items in {expr1} are processed. When 4926 {expr2} is a Funcref errors inside a function are ignored, 4927 unless it was defined with the "abort" flag. 4928 4929 Can also be used as a |method|: > 4930 mylist->filter(expr2) 4931 4932finddir({name} [, {path} [, {count}]]) *finddir()* 4933 Find directory {name} in {path}. Supports both downwards and 4934 upwards recursive directory searches. See |file-searching| 4935 for the syntax of {path}. 4936 4937 Returns the path of the first found match. When the found 4938 directory is below the current directory a relative path is 4939 returned. Otherwise a full path is returned. 4940 If {path} is omitted or empty then 'path' is used. 4941 4942 If the optional {count} is given, find {count}'s occurrence of 4943 {name} in {path} instead of the first one. 4944 When {count} is negative return all the matches in a |List|. 4945 4946 This is quite similar to the ex-command `:find`. 4947 {only available when compiled with the |+file_in_path| 4948 feature} 4949 4950 Can also be used as a |method|: > 4951 GetName()->finddir() 4952 4953findfile({name} [, {path} [, {count}]]) *findfile()* 4954 Just like |finddir()|, but find a file instead of a directory. 4955 Uses 'suffixesadd'. 4956 Example: > 4957 :echo findfile("tags.vim", ".;") 4958< Searches from the directory of the current file upwards until 4959 it finds the file "tags.vim". 4960 4961 Can also be used as a |method|: > 4962 GetName()->findfile() 4963 4964flatten({list} [, {maxdepth}]) *flatten()* 4965 Flatten {list} up to {maxdepth} levels. Without {maxdepth} 4966 the result is a |List| without nesting, as if {maxdepth} is 4967 a very large number. 4968 The {list} is changed in place, use |flattennew()| if you do 4969 not want that. 4970 In Vim9 script flatten() cannot be used, you must always use 4971 |flattennew()|. 4972 *E900* 4973 {maxdepth} means how deep in nested lists changes are made. 4974 {list} is not modified when {maxdepth} is 0. 4975 {maxdepth} must be positive number. 4976 4977 If there is an error the number zero is returned. 4978 4979 Example: > 4980 :echo flatten([1, [2, [3, 4]], 5]) 4981< [1, 2, 3, 4, 5] > 4982 :echo flatten([1, [2, [3, 4]], 5], 1) 4983< [1, 2, [3, 4], 5] 4984 4985 Can also be used as a |method|: > 4986 mylist->flatten() 4987< 4988flattennew({list} [, {maxdepth}]) *flattennew()* 4989 Like |flatten()| but first make a copy of {list}. 4990 4991 4992float2nr({expr}) *float2nr()* 4993 Convert {expr} to a Number by omitting the part after the 4994 decimal point. 4995 {expr} must evaluate to a |Float| or a Number. 4996 When the value of {expr} is out of range for a |Number| the 4997 result is truncated to 0x7fffffff or -0x7fffffff (or when 4998 64-bit Number support is enabled, 0x7fffffffffffffff or 4999 -0x7fffffffffffffff). NaN results in -0x80000000 (or when 5000 64-bit Number support is enabled, -0x8000000000000000). 5001 Examples: > 5002 echo float2nr(3.95) 5003< 3 > 5004 echo float2nr(-23.45) 5005< -23 > 5006 echo float2nr(1.0e100) 5007< 2147483647 (or 9223372036854775807) > 5008 echo float2nr(-1.0e150) 5009< -2147483647 (or -9223372036854775807) > 5010 echo float2nr(1.0e-100) 5011< 0 5012 5013 Can also be used as a |method|: > 5014 Compute()->float2nr() 5015< 5016 {only available when compiled with the |+float| feature} 5017 5018 5019floor({expr}) *floor()* 5020 Return the largest integral value less than or equal to 5021 {expr} as a |Float| (round down). 5022 {expr} must evaluate to a |Float| or a |Number|. 5023 Examples: > 5024 echo floor(1.856) 5025< 1.0 > 5026 echo floor(-5.456) 5027< -6.0 > 5028 echo floor(4.0) 5029< 4.0 5030 5031 Can also be used as a |method|: > 5032 Compute()->floor() 5033< 5034 {only available when compiled with the |+float| feature} 5035 5036 5037fmod({expr1}, {expr2}) *fmod()* 5038 Return the remainder of {expr1} / {expr2}, even if the 5039 division is not representable. Returns {expr1} - i * {expr2} 5040 for some integer i such that if {expr2} is non-zero, the 5041 result has the same sign as {expr1} and magnitude less than 5042 the magnitude of {expr2}. If {expr2} is zero, the value 5043 returned is zero. The value returned is a |Float|. 5044 {expr1} and {expr2} must evaluate to a |Float| or a |Number|. 5045 Examples: > 5046 :echo fmod(12.33, 1.22) 5047< 0.13 > 5048 :echo fmod(-12.33, 1.22) 5049< -0.13 5050 5051 Can also be used as a |method|: > 5052 Compute()->fmod(1.22) 5053< 5054 {only available when compiled with |+float| feature} 5055 5056 5057fnameescape({string}) *fnameescape()* 5058 Escape {string} for use as file name command argument. All 5059 characters that have a special meaning, such as '%' and '|' 5060 are escaped with a backslash. 5061 For most systems the characters escaped are 5062 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash 5063 appears in a filename, it depends on the value of 'isfname'. 5064 A leading '+' and '>' is also escaped (special after |:edit| 5065 and |:write|). And a "-" by itself (special after |:cd|). 5066 Example: > 5067 :let fname = '+some str%nge|name' 5068 :exe "edit " . fnameescape(fname) 5069< results in executing: > 5070 edit \+some\ str\%nge\|name 5071< 5072 Can also be used as a |method|: > 5073 GetName()->fnameescape() 5074 5075fnamemodify({fname}, {mods}) *fnamemodify()* 5076 Modify file name {fname} according to {mods}. {mods} is a 5077 string of characters like it is used for file names on the 5078 command line. See |filename-modifiers|. 5079 Example: > 5080 :echo fnamemodify("main.c", ":p:h") 5081< results in: > 5082 /home/mool/vim/vim/src 5083< If {mods} is empty then {fname} is returned. 5084 Note: Environment variables don't work in {fname}, use 5085 |expand()| first then. 5086 5087 Can also be used as a |method|: > 5088 GetName()->fnamemodify(':p:h') 5089 5090foldclosed({lnum}) *foldclosed()* 5091 The result is a Number. If the line {lnum} is in a closed 5092 fold, the result is the number of the first line in that fold. 5093 If the line {lnum} is not in a closed fold, -1 is returned. 5094 {lnum} is used like with |getline()|. Thus "." is the current 5095 line, "'m" mark m, etc. 5096 5097 Can also be used as a |method|: > 5098 GetLnum()->foldclosed() 5099 5100foldclosedend({lnum}) *foldclosedend()* 5101 The result is a Number. If the line {lnum} is in a closed 5102 fold, the result is the number of the last line in that fold. 5103 If the line {lnum} is not in a closed fold, -1 is returned. 5104 {lnum} is used like with |getline()|. Thus "." is the current 5105 line, "'m" mark m, etc. 5106 5107 Can also be used as a |method|: > 5108 GetLnum()->foldclosedend() 5109 5110foldlevel({lnum}) *foldlevel()* 5111 The result is a Number, which is the foldlevel of line {lnum} 5112 in the current buffer. For nested folds the deepest level is 5113 returned. If there is no fold at line {lnum}, zero is 5114 returned. It doesn't matter if the folds are open or closed. 5115 When used while updating folds (from 'foldexpr') -1 is 5116 returned for lines where folds are still to be updated and the 5117 foldlevel is unknown. As a special case the level of the 5118 previous line is usually available. 5119 {lnum} is used like with |getline()|. Thus "." is the current 5120 line, "'m" mark m, etc. 5121 5122 Can also be used as a |method|: > 5123 GetLnum()->foldlevel() 5124< 5125 *foldtext()* 5126foldtext() Returns a String, to be displayed for a closed fold. This is 5127 the default function used for the 'foldtext' option and should 5128 only be called from evaluating 'foldtext'. It uses the 5129 |v:foldstart|, |v:foldend| and |v:folddashes| variables. 5130 The returned string looks like this: > 5131 +-- 45 lines: abcdef 5132< The number of leading dashes depends on the foldlevel. The 5133 "45" is the number of lines in the fold. "abcdef" is the text 5134 in the first non-blank line of the fold. Leading white space, 5135 "//" or "/*" and the text from the 'foldmarker' and 5136 'commentstring' options is removed. 5137 When used to draw the actual foldtext, the rest of the line 5138 will be filled with the fold char from the 'fillchars' 5139 setting. 5140 {not available when compiled without the |+folding| feature} 5141 5142foldtextresult({lnum}) *foldtextresult()* 5143 Returns the text that is displayed for the closed fold at line 5144 {lnum}. Evaluates 'foldtext' in the appropriate context. 5145 When there is no closed fold at {lnum} an empty string is 5146 returned. 5147 {lnum} is used like with |getline()|. Thus "." is the current 5148 line, "'m" mark m, etc. 5149 Useful when exporting folded text, e.g., to HTML. 5150 {not available when compiled without the |+folding| feature} 5151 5152 5153 Can also be used as a |method|: > 5154 GetLnum()->foldtextresult() 5155< 5156 *foreground()* 5157foreground() Move the Vim window to the foreground. Useful when sent from 5158 a client to a Vim server. |remote_send()| 5159 On Win32 systems this might not work, the OS does not always 5160 allow a window to bring itself to the foreground. Use 5161 |remote_foreground()| instead. 5162 {only in the Win32, Athena, Motif and GTK GUI versions and the 5163 Win32 console version} 5164 5165fullcommand({name}) *fullcommand()* 5166 Get the full command name from a short abbreviated command 5167 name; see |20.2| for details on command abbreviations. 5168 5169 The string argument {name} may start with a `:` and can 5170 include a [range], these are skipped and not returned. 5171 Returns an empty string if a command doesn't exist or if it's 5172 ambiguous (for user-defined commands). 5173 5174 For example `fullcommand('s')`, `fullcommand('sub')`, 5175 `fullcommand(':%substitute')` all return "substitute". 5176 5177 Can also be used as a |method|: > 5178 GetName()->fullcommand() 5179< 5180 *funcref()* 5181funcref({name} [, {arglist}] [, {dict}]) 5182 Just like |function()|, but the returned Funcref will lookup 5183 the function by reference, not by name. This matters when the 5184 function {name} is redefined later. 5185 5186 Unlike |function()|, {name} must be an existing user function. 5187 Also for autoloaded functions. {name} cannot be a builtin 5188 function. 5189 5190 Can also be used as a |method|: > 5191 GetFuncname()->funcref([arg]) 5192< 5193 *function()* *partial* *E700* *E922* *E923* 5194function({name} [, {arglist}] [, {dict}]) 5195 Return a |Funcref| variable that refers to function {name}. 5196 {name} can be the name of a user defined function or an 5197 internal function. 5198 5199 {name} can also be a Funcref or a partial. When it is a 5200 partial the dict stored in it will be used and the {dict} 5201 argument is not allowed. E.g.: > 5202 let FuncWithArg = function(dict.Func, [arg]) 5203 let Broken = function(dict.Func, [arg], dict) 5204< 5205 When using the Funcref the function will be found by {name}, 5206 also when it was redefined later. Use |funcref()| to keep the 5207 same function. 5208 5209 When {arglist} or {dict} is present this creates a partial. 5210 That means the argument list and/or the dictionary is stored in 5211 the Funcref and will be used when the Funcref is called. 5212 5213 The arguments are passed to the function in front of other 5214 arguments, but after any argument from |method|. Example: > 5215 func Callback(arg1, arg2, name) 5216 ... 5217 let Partial = function('Callback', ['one', 'two']) 5218 ... 5219 call Partial('name') 5220< Invokes the function as with: > 5221 call Callback('one', 'two', 'name') 5222 5223< With a |method|: > 5224 func Callback(one, two, three) 5225 ... 5226 let Partial = function('Callback', ['two']) 5227 ... 5228 eval 'one'->Partial('three') 5229< Invokes the function as with: > 5230 call Callback('one', 'two', 'three') 5231 5232< The function() call can be nested to add more arguments to the 5233 Funcref. The extra arguments are appended to the list of 5234 arguments. Example: > 5235 func Callback(arg1, arg2, name) 5236 ... 5237 let Func = function('Callback', ['one']) 5238 let Func2 = function(Func, ['two']) 5239 ... 5240 call Func2('name') 5241< Invokes the function as with: > 5242 call Callback('one', 'two', 'name') 5243 5244< The Dictionary is only useful when calling a "dict" function. 5245 In that case the {dict} is passed in as "self". Example: > 5246 function Callback() dict 5247 echo "called for " . self.name 5248 endfunction 5249 ... 5250 let context = {"name": "example"} 5251 let Func = function('Callback', context) 5252 ... 5253 call Func() " will echo: called for example 5254< The use of function() is not needed when there are no extra 5255 arguments, these two are equivalent: > 5256 let Func = function('Callback', context) 5257 let Func = context.Callback 5258 5259< The argument list and the Dictionary can be combined: > 5260 function Callback(arg1, count) dict 5261 ... 5262 let context = {"name": "example"} 5263 let Func = function('Callback', ['one'], context) 5264 ... 5265 call Func(500) 5266< Invokes the function as with: > 5267 call context.Callback('one', 500) 5268< 5269 Can also be used as a |method|: > 5270 GetFuncname()->function([arg]) 5271 5272 5273garbagecollect([{atexit}]) *garbagecollect()* 5274 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs| 5275 that have circular references. 5276 5277 There is hardly ever a need to invoke this function, as it is 5278 automatically done when Vim runs out of memory or is waiting 5279 for the user to press a key after 'updatetime'. Items without 5280 circular references are always freed when they become unused. 5281 This is useful if you have deleted a very big |List| and/or 5282 |Dictionary| with circular references in a script that runs 5283 for a long time. 5284 5285 When the optional {atexit} argument is one, garbage 5286 collection will also be done when exiting Vim, if it wasn't 5287 done before. This is useful when checking for memory leaks. 5288 5289 The garbage collection is not done immediately but only when 5290 it's safe to perform. This is when waiting for the user to 5291 type a character. To force garbage collection immediately use 5292 |test_garbagecollect_now()|. 5293 5294get({list}, {idx} [, {default}]) *get()* 5295 Get item {idx} from |List| {list}. When this item is not 5296 available return {default}. Return zero when {default} is 5297 omitted. 5298 Preferably used as a |method|: > 5299 mylist->get(idx) 5300get({blob}, {idx} [, {default}]) 5301 Get byte {idx} from |Blob| {blob}. When this byte is not 5302 available return {default}. Return -1 when {default} is 5303 omitted. 5304 Preferably used as a |method|: > 5305 myblob->get(idx) 5306get({dict}, {key} [, {default}]) 5307 Get item with key {key} from |Dictionary| {dict}. When this 5308 item is not available return {default}. Return zero when 5309 {default} is omitted. Useful example: > 5310 let val = get(g:, 'var_name', 'default') 5311< This gets the value of g:var_name if it exists, and uses 5312 'default' when it does not exist. 5313 Preferably used as a |method|: > 5314 mydict->get(key) 5315get({func}, {what}) 5316 Get an item with from Funcref {func}. Possible values for 5317 {what} are: 5318 "name" The function name 5319 "func" The function 5320 "dict" The dictionary 5321 "args" The list with arguments 5322 Preferably used as a |method|: > 5323 myfunc->get(what) 5324< 5325 *getbufinfo()* 5326getbufinfo([{buf}]) 5327getbufinfo([{dict}]) 5328 Get information about buffers as a List of Dictionaries. 5329 5330 Without an argument information about all the buffers is 5331 returned. 5332 5333 When the argument is a |Dictionary| only the buffers matching 5334 the specified criteria are returned. The following keys can 5335 be specified in {dict}: 5336 buflisted include only listed buffers. 5337 bufloaded include only loaded buffers. 5338 bufmodified include only modified buffers. 5339 5340 Otherwise, {buf} specifies a particular buffer to return 5341 information for. For the use of {buf}, see |bufname()| 5342 above. If the buffer is found the returned List has one item. 5343 Otherwise the result is an empty list. 5344 5345 Each returned List item is a dictionary with the following 5346 entries: 5347 bufnr Buffer number. 5348 changed TRUE if the buffer is modified. 5349 changedtick Number of changes made to the buffer. 5350 hidden TRUE if the buffer is hidden. 5351 lastused Timestamp in seconds, like 5352 |localtime()|, when the buffer was 5353 last used. 5354 {only with the |+viminfo| feature} 5355 listed TRUE if the buffer is listed. 5356 lnum Line number used for the buffer when 5357 opened in the current window. 5358 Only valid if the buffer has been 5359 displayed in the window in the past. 5360 If you want the line number of the 5361 last known cursor position in a given 5362 window, use |line()|: > 5363 :echo line('.', {winid}) 5364< 5365 linecount Number of lines in the buffer (only 5366 valid when loaded) 5367 loaded TRUE if the buffer is loaded. 5368 name Full path to the file in the buffer. 5369 signs List of signs placed in the buffer. 5370 Each list item is a dictionary with 5371 the following fields: 5372 id sign identifier 5373 lnum line number 5374 name sign name 5375 variables A reference to the dictionary with 5376 buffer-local variables. 5377 windows List of |window-ID|s that display this 5378 buffer 5379 popups List of popup |window-ID|s that 5380 display this buffer 5381 5382 Examples: > 5383 for buf in getbufinfo() 5384 echo buf.name 5385 endfor 5386 for buf in getbufinfo({'buflisted':1}) 5387 if buf.changed 5388 .... 5389 endif 5390 endfor 5391< 5392 To get buffer-local options use: > 5393 getbufvar({bufnr}, '&option_name') 5394< 5395 Can also be used as a |method|: > 5396 GetBufnr()->getbufinfo() 5397< 5398 5399 *getbufline()* 5400getbufline({buf}, {lnum} [, {end}]) 5401 Return a |List| with the lines starting from {lnum} to {end} 5402 (inclusive) in the buffer {buf}. If {end} is omitted, a 5403 |List| with only the line {lnum} is returned. 5404 5405 For the use of {buf}, see |bufname()| above. 5406 5407 For {lnum} and {end} "$" can be used for the last line of the 5408 buffer. Otherwise a number must be used. 5409 5410 When {lnum} is smaller than 1 or bigger than the number of 5411 lines in the buffer, an empty |List| is returned. 5412 5413 When {end} is greater than the number of lines in the buffer, 5414 it is treated as {end} is set to the number of lines in the 5415 buffer. When {end} is before {lnum} an empty |List| is 5416 returned. 5417 5418 This function works only for loaded buffers. For unloaded and 5419 non-existing buffers, an empty |List| is returned. 5420 5421 Example: > 5422 :let lines = getbufline(bufnr("myfile"), 1, "$") 5423 5424< Can also be used as a |method|: > 5425 GetBufnr()->getbufline(lnum) 5426 5427getbufvar({buf}, {varname} [, {def}]) *getbufvar()* 5428 The result is the value of option or local buffer variable 5429 {varname} in buffer {buf}. Note that the name without "b:" 5430 must be used. 5431 The {varname} argument is a string. 5432 When {varname} is empty returns a |Dictionary| with all the 5433 buffer-local variables. 5434 When {varname} is equal to "&" returns a |Dictionary| with all 5435 the buffer-local options. 5436 Otherwise, when {varname} starts with "&" returns the value of 5437 a buffer-local option. 5438 This also works for a global or buffer-local option, but it 5439 doesn't work for a global variable, window-local variable or 5440 window-local option. 5441 For the use of {buf}, see |bufname()| above. 5442 When the buffer or variable doesn't exist {def} or an empty 5443 string is returned, there is no error message. 5444 Examples: > 5445 :let bufmodified = getbufvar(1, "&mod") 5446 :echo "todo myvar = " . getbufvar("todo", "myvar") 5447 5448< Can also be used as a |method|: > 5449 GetBufnr()->getbufvar(varname) 5450< 5451getchangelist([{buf}]) *getchangelist()* 5452 Returns the |changelist| for the buffer {buf}. For the use 5453 of {buf}, see |bufname()| above. If buffer {buf} doesn't 5454 exist, an empty list is returned. 5455 5456 The returned list contains two entries: a list with the change 5457 locations and the current position in the list. Each 5458 entry in the change list is a dictionary with the following 5459 entries: 5460 col column number 5461 coladd column offset for 'virtualedit' 5462 lnum line number 5463 If buffer {buf} is the current buffer, then the current 5464 position refers to the position in the list. For other 5465 buffers, it is set to the length of the list. 5466 5467 Can also be used as a |method|: > 5468 GetBufnr()->getchangelist() 5469 5470getchar([expr]) *getchar()* 5471 Get a single character from the user or input stream. 5472 If [expr] is omitted, wait until a character is available. 5473 If [expr] is 0, only get a character when one is available. 5474 Return zero otherwise. 5475 If [expr] is 1, only check if a character is available, it is 5476 not consumed. Return zero if no character available. 5477 If you prefer always getting a string use |getcharstr()|. 5478 5479 Without [expr] and when [expr] is 0 a whole character or 5480 special key is returned. If it is a single character, the 5481 result is a number. Use nr2char() to convert it to a String. 5482 Otherwise a String is returned with the encoded character. 5483 For a special key it's a String with a sequence of bytes 5484 starting with 0x80 (decimal: 128). This is the same value as 5485 the String "\<Key>", e.g., "\<Left>". The returned value is 5486 also a String when a modifier (shift, control, alt) was used 5487 that is not included in the character. 5488 5489 When [expr] is 0 and Esc is typed, there will be a short delay 5490 while Vim waits to see if this is the start of an escape 5491 sequence. 5492 5493 When [expr] is 1 only the first byte is returned. For a 5494 one-byte character it is the character itself as a number. 5495 Use nr2char() to convert it to a String. 5496 5497 Use getcharmod() to obtain any additional modifiers. 5498 5499 When the user clicks a mouse button, the mouse event will be 5500 returned. The position can then be found in |v:mouse_col|, 5501 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|. 5502 |getmousepos()| can also be used. Mouse move events will be 5503 ignored. 5504 This example positions the mouse as it would normally happen: > 5505 let c = getchar() 5506 if c == "\<LeftMouse>" && v:mouse_win > 0 5507 exe v:mouse_win . "wincmd w" 5508 exe v:mouse_lnum 5509 exe "normal " . v:mouse_col . "|" 5510 endif 5511< 5512 When using bracketed paste only the first character is 5513 returned, the rest of the pasted text is dropped. 5514 |xterm-bracketed-paste|. 5515 5516 There is no prompt, you will somehow have to make clear to the 5517 user that a character has to be typed. The screen is not 5518 redrawn, e.g. when resizing the window. When using a popup 5519 window it should work better with a |popup-filter|. 5520 5521 There is no mapping for the character. 5522 Key codes are replaced, thus when the user presses the <Del> 5523 key you get the code for the <Del> key, not the raw character 5524 sequence. Examples: > 5525 getchar() == "\<Del>" 5526 getchar() == "\<S-Left>" 5527< This example redefines "f" to ignore case: > 5528 :nmap f :call FindChar()<CR> 5529 :function FindChar() 5530 : let c = nr2char(getchar()) 5531 : while col('.') < col('$') - 1 5532 : normal l 5533 : if getline('.')[col('.') - 1] ==? c 5534 : break 5535 : endif 5536 : endwhile 5537 :endfunction 5538< 5539 You may also receive synthetic characters, such as 5540 |<CursorHold>|. Often you will want to ignore this and get 5541 another character: > 5542 :function GetKey() 5543 : let c = getchar() 5544 : while c == "\<CursorHold>" 5545 : let c = getchar() 5546 : endwhile 5547 : return c 5548 :endfunction 5549 5550getcharmod() *getcharmod()* 5551 The result is a Number which is the state of the modifiers for 5552 the last obtained character with getchar() or in another way. 5553 These values are added together: 5554 2 shift 5555 4 control 5556 8 alt (meta) 5557 16 meta (when it's different from ALT) 5558 32 mouse double click 5559 64 mouse triple click 5560 96 mouse quadruple click (== 32 + 64) 5561 128 command (Macintosh only) 5562 Only the modifiers that have not been included in the 5563 character itself are obtained. Thus Shift-a results in "A" 5564 without a modifier. 5565 5566 *getcharpos()* 5567getcharpos({expr}) 5568 Get the position for String {expr}. Same as |getpos()| but the 5569 column number in the returned List is a character index 5570 instead of a byte index. 5571 If |getpos()| returns a very large column number, such as 5572 2147483647, then getcharpos() will return the character index 5573 of the last character. 5574 5575 Example: 5576 With the cursor on '세' in line 5 with text "여보세요": > 5577 getcharpos('.') returns [0, 5, 3, 0] 5578 getpos('.') returns [0, 5, 7, 0] 5579< 5580 Can also be used as a |method|: > 5581 GetMark()->getcharpos() 5582 5583getcharsearch() *getcharsearch()* 5584 Return the current character search information as a {dict} 5585 with the following entries: 5586 5587 char character previously used for a character 5588 search (|t|, |f|, |T|, or |F|); empty string 5589 if no character search has been performed 5590 forward direction of character search; 1 for forward, 5591 0 for backward 5592 until type of character search; 1 for a |t| or |T| 5593 character search, 0 for an |f| or |F| 5594 character search 5595 5596 This can be useful to always have |;| and |,| search 5597 forward/backward regardless of the direction of the previous 5598 character search: > 5599 :nnoremap <expr> ; getcharsearch().forward ? ';' : ',' 5600 :nnoremap <expr> , getcharsearch().forward ? ',' : ';' 5601< Also see |setcharsearch()|. 5602 5603 5604getcharstr([expr]) *getcharstr()* 5605 Get a single character from the user or input stream as a 5606 string. 5607 If [expr] is omitted, wait until a character is available. 5608 If [expr] is 0 or false, only get a character when one is 5609 available. Return an empty string otherwise. 5610 If [expr] is 1 or true, only check if a character is 5611 available, it is not consumed. Return an empty string 5612 if no character is available. 5613 Otherwise this works like |getchar()|, except that a number 5614 result is converted to a string. 5615 5616 5617getcmdline() *getcmdline()* 5618 Return the current command-line. Only works when the command 5619 line is being edited, thus requires use of |c_CTRL-\_e| or 5620 |c_CTRL-R_=|. 5621 Example: > 5622 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> 5623< Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|. 5624 Returns an empty string when entering a password or using 5625 |inputsecret()|. 5626 5627getcmdpos() *getcmdpos()* 5628 Return the position of the cursor in the command line as a 5629 byte count. The first column is 1. 5630 Only works when editing the command line, thus requires use of 5631 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 5632 Returns 0 otherwise. 5633 Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|. 5634 5635getcmdtype() *getcmdtype()* 5636 Return the current command-line type. Possible return values 5637 are: 5638 : normal Ex command 5639 > debug mode command |debug-mode| 5640 / forward search command 5641 ? backward search command 5642 @ |input()| command 5643 - |:insert| or |:append| command 5644 = |i_CTRL-R_=| 5645 Only works when editing the command line, thus requires use of 5646 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. 5647 Returns an empty string otherwise. 5648 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|. 5649 5650getcmdwintype() *getcmdwintype()* 5651 Return the current |command-line-window| type. Possible return 5652 values are the same as |getcmdtype()|. Returns an empty string 5653 when not in the command-line window. 5654 5655getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* 5656 Return a list of command-line completion matches. The String 5657 {type} argument specifies what for. The following completion 5658 types are supported: 5659 5660 arglist file names in argument list 5661 augroup autocmd groups 5662 buffer buffer names 5663 behave :behave suboptions 5664 color color schemes 5665 command Ex command 5666 cmdline |cmdline-completion| result 5667 compiler compilers 5668 cscope |:cscope| suboptions 5669 diff_buffer |:diffget| and |:diffput| completion 5670 dir directory names 5671 environment environment variable names 5672 event autocommand events 5673 expression Vim expression 5674 file file and directory names 5675 file_in_path file and directory names in |'path'| 5676 filetype filetype names |'filetype'| 5677 function function name 5678 help help subjects 5679 highlight highlight groups 5680 history :history suboptions 5681 locale locale names (as output of locale -a) 5682 mapclear buffer argument 5683 mapping mapping name 5684 menu menus 5685 messages |:messages| suboptions 5686 option options 5687 packadd optional package |pack-add| names 5688 shellcmd Shell command 5689 sign |:sign| suboptions 5690 syntax syntax file names |'syntax'| 5691 syntime |:syntime| suboptions 5692 tag tags 5693 tag_listfiles tags, file names 5694 user user names 5695 var user variables 5696 5697 If {pat} is an empty string, then all the matches are 5698 returned. Otherwise only items matching {pat} are returned. 5699 See |wildcards| for the use of special characters in {pat}. 5700 5701 If the optional {filtered} flag is set to 1, then 'wildignore' 5702 is applied to filter the results. Otherwise all the matches 5703 are returned. The 'wildignorecase' option always applies. 5704 5705 If {type} is "cmdline", then the |cmdline-completion| result is 5706 returned. For example, to complete the possible values after 5707 a ":call" command: > 5708 echo getcompletion('call ', 'cmdline') 5709< 5710 If there are no matches, an empty list is returned. An 5711 invalid value for {type} produces an error. 5712 5713 Can also be used as a |method|: > 5714 GetPattern()->getcompletion('color') 5715< 5716 *getcurpos()* 5717getcurpos([{winid}]) 5718 Get the position of the cursor. This is like getpos('.'), but 5719 includes an extra "curswant" item in the list: 5720 [0, lnum, col, off, curswant] ~ 5721 The "curswant" number is the preferred column when moving the 5722 cursor vertically. Also see |getcursorcharpos()| and 5723 |getpos()|. 5724 The first "bufnum" item is always zero. The byte position of 5725 the cursor is returned in 'col'. To get the character 5726 position, use |getcursorcharpos()|. 5727 5728 The optional {winid} argument can specify the window. It can 5729 be the window number or the |window-ID|. The last known 5730 cursor position is returned, this may be invalid for the 5731 current value of the buffer if it is not the current window. 5732 If {winid} is invalid a list with zeroes is returned. 5733 5734 This can be used to save and restore the cursor position: > 5735 let save_cursor = getcurpos() 5736 MoveTheCursorAround 5737 call setpos('.', save_cursor) 5738< Note that this only works within the window. See 5739 |winrestview()| for restoring more state. 5740 5741 Can also be used as a |method|: > 5742 GetWinid()->getcurpos() 5743< 5744 *getcursorcharpos()* 5745getcursorcharpos([{winid}]) 5746 Same as |getcurpos()| but the column number in the returned 5747 List is a character index instead of a byte index. 5748 5749 Example: 5750 With the cursor on '보' in line 3 with text "여보세요": > 5751 getcursorcharpos() returns [0, 3, 2, 0, 3] 5752 getcurpos() returns [0, 3, 4, 0, 3] 5753< 5754 Can also be used as a |method|: > 5755 GetWinid()->getcursorcharpos() 5756 5757< *getcwd()* 5758getcwd([{winnr} [, {tabnr}]]) 5759 The result is a String, which is the name of the current 5760 working directory. 'autochdir' is ignored. 5761 5762 With {winnr} return the local current directory of this window 5763 in the current tab page. {winnr} can be the window number or 5764 the |window-ID|. 5765 If {winnr} is -1 return the name of the global working 5766 directory. See also |haslocaldir()|. 5767 5768 With {winnr} and {tabnr} return the local current directory of 5769 the window in the specified tab page. If {winnr} is -1 return 5770 the working directory of the tabpage. 5771 If {winnr} is zero use the current window, if {tabnr} is zero 5772 use the current tabpage. 5773 Without any arguments, return the actual working directory of 5774 the current window. 5775 Return an empty string if the arguments are invalid. 5776 5777 Examples: > 5778 " Get the working directory of the current window 5779 :echo getcwd() 5780 :echo getcwd(0) 5781 :echo getcwd(0, 0) 5782 " Get the working directory of window 3 in tabpage 2 5783 :echo getcwd(3, 2) 5784 " Get the global working directory 5785 :echo getcwd(-1) 5786 " Get the working directory of tabpage 3 5787 :echo getcwd(-1, 3) 5788 " Get the working directory of current tabpage 5789 :echo getcwd(-1, 0) 5790 5791< Can also be used as a |method|: > 5792 GetWinnr()->getcwd() 5793 5794getenv({name}) *getenv()* 5795 Return the value of environment variable {name}. The {name} 5796 argument is a string, without a leading '$'. Example: > 5797 myHome = getenv('HOME') 5798 5799< When the variable does not exist |v:null| is returned. That 5800 is different from a variable set to an empty string, although 5801 some systems interpret the empty value as the variable being 5802 deleted. See also |expr-env|. 5803 5804 Can also be used as a |method|: > 5805 GetVarname()->getenv() 5806 5807getfontname([{name}]) *getfontname()* 5808 Without an argument returns the name of the normal font being 5809 used. Like what is used for the Normal highlight group 5810 |hl-Normal|. 5811 With an argument a check is done whether String {name} is a 5812 valid font name. If not then an empty string is returned. 5813 Otherwise the actual font name is returned, or {name} if the 5814 GUI does not support obtaining the real name. 5815 Only works when the GUI is running, thus not in your vimrc or 5816 gvimrc file. Use the |GUIEnter| autocommand to use this 5817 function just after the GUI has started. 5818 Note that the GTK GUI accepts any font name, thus checking for 5819 a valid name does not work. 5820 5821getfperm({fname}) *getfperm()* 5822 The result is a String, which is the read, write, and execute 5823 permissions of the given file {fname}. 5824 If {fname} does not exist or its directory cannot be read, an 5825 empty string is returned. 5826 The result is of the form "rwxrwxrwx", where each group of 5827 "rwx" flags represent, in turn, the permissions of the owner 5828 of the file, the group the file belongs to, and other users. 5829 If a user does not have a given permission the flag for this 5830 is replaced with the string "-". Examples: > 5831 :echo getfperm("/etc/passwd") 5832 :echo getfperm(expand("~/.vimrc")) 5833< This will hopefully (from a security point of view) display 5834 the string "rw-r--r--" or even "rw-------". 5835 5836 Can also be used as a |method|: > 5837 GetFilename()->getfperm() 5838< 5839 For setting permissions use |setfperm()|. 5840 5841getfsize({fname}) *getfsize()* 5842 The result is a Number, which is the size in bytes of the 5843 given file {fname}. 5844 If {fname} is a directory, 0 is returned. 5845 If the file {fname} can't be found, -1 is returned. 5846 If the size of {fname} is too big to fit in a Number then -2 5847 is returned. 5848 5849 Can also be used as a |method|: > 5850 GetFilename()->getfsize() 5851 5852getftime({fname}) *getftime()* 5853 The result is a Number, which is the last modification time of 5854 the given file {fname}. The value is measured as seconds 5855 since 1st Jan 1970, and may be passed to strftime(). See also 5856 |localtime()| and |strftime()|. 5857 If the file {fname} can't be found -1 is returned. 5858 5859 Can also be used as a |method|: > 5860 GetFilename()->getftime() 5861 5862getftype({fname}) *getftype()* 5863 The result is a String, which is a description of the kind of 5864 file of the given file {fname}. 5865 If {fname} does not exist an empty string is returned. 5866 Here is a table over different kinds of files and their 5867 results: 5868 Normal file "file" 5869 Directory "dir" 5870 Symbolic link "link" 5871 Block device "bdev" 5872 Character device "cdev" 5873 Socket "socket" 5874 FIFO "fifo" 5875 All other "other" 5876 Example: > 5877 getftype("/home") 5878< Note that a type such as "link" will only be returned on 5879 systems that support it. On some systems only "dir" and 5880 "file" are returned. On MS-Windows a symbolic link to a 5881 directory returns "dir" instead of "link". 5882 5883 Can also be used as a |method|: > 5884 GetFilename()->getftype() 5885 5886getimstatus() *getimstatus()* 5887 The result is a Number, which is |TRUE| when the IME status is 5888 active. 5889 See 'imstatusfunc'. 5890 5891getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* 5892 Returns the |jumplist| for the specified window. 5893 5894 Without arguments use the current window. 5895 With {winnr} only use this window in the current tab page. 5896 {winnr} can also be a |window-ID|. 5897 With {winnr} and {tabnr} use the window in the specified tab 5898 page. 5899 5900 The returned list contains two entries: a list with the jump 5901 locations and the last used jump position number in the list. 5902 Each entry in the jump location list is a dictionary with 5903 the following entries: 5904 bufnr buffer number 5905 col column number 5906 coladd column offset for 'virtualedit' 5907 filename filename if available 5908 lnum line number 5909 5910 Can also be used as a |method|: > 5911 GetWinnr()->getjumplist() 5912 5913< *getline()* 5914getline({lnum} [, {end}]) 5915 Without {end} the result is a String, which is line {lnum} 5916 from the current buffer. Example: > 5917 getline(1) 5918< When {lnum} is a String that doesn't start with a 5919 digit, |line()| is called to translate the String into a Number. 5920 To get the line under the cursor: > 5921 getline(".") 5922< When {lnum} is smaller than 1 or bigger than the number of 5923 lines in the buffer, an empty string is returned. 5924 5925 When {end} is given the result is a |List| where each item is 5926 a line from the current buffer in the range {lnum} to {end}, 5927 including line {end}. 5928 {end} is used in the same way as {lnum}. 5929 Non-existing lines are silently omitted. 5930 When {end} is before {lnum} an empty |List| is returned. 5931 Example: > 5932 :let start = line('.') 5933 :let end = search("^$") - 1 5934 :let lines = getline(start, end) 5935 5936< Can also be used as a |method|: > 5937 ComputeLnum()->getline() 5938 5939< To get lines from another buffer see |getbufline()| 5940 5941getloclist({nr} [, {what}]) *getloclist()* 5942 Returns a |List| with all the entries in the location list for 5943 window {nr}. {nr} can be the window number or the |window-ID|. 5944 When {nr} is zero the current window is used. 5945 5946 For a location list window, the displayed location list is 5947 returned. For an invalid window number {nr}, an empty list is 5948 returned. Otherwise, same as |getqflist()|. 5949 5950 If the optional {what} dictionary argument is supplied, then 5951 returns the items listed in {what} as a dictionary. Refer to 5952 |getqflist()| for the supported items in {what}. 5953 5954 In addition to the items supported by |getqflist()| in {what}, 5955 the following item is supported by |getloclist()|: 5956 5957 filewinid id of the window used to display files 5958 from the location list. This field is 5959 applicable only when called from a 5960 location list window. See 5961 |location-list-file-window| for more 5962 details. 5963 5964 Returns a |Dictionary| with default values if there is no 5965 location list for the window {nr}. 5966 Returns an empty Dictionary if window {nr} does not exist. 5967 5968 Examples (See also |getqflist-examples|): > 5969 :echo getloclist(3, {'all': 0}) 5970 :echo getloclist(5, {'filewinid': 0}) 5971 5972 5973getmarklist([{buf}]) *getmarklist()* 5974 Without the {buf} argument returns a |List| with information 5975 about all the global marks. |mark| 5976 5977 If the optional {buf} argument is specified, returns the 5978 local marks defined in buffer {buf}. For the use of {buf}, 5979 see |bufname()|. 5980 5981 Each item in the returned List is a |Dict| with the following: 5982 mark name of the mark prefixed by "'" 5983 pos a |List| with the position of the mark: 5984 [bufnum, lnum, col, off] 5985 Refer to |getpos()| for more information. 5986 file file name 5987 5988 Refer to |getpos()| for getting information about a specific 5989 mark. 5990 5991 Can also be used as a |method|: > 5992 GetBufnr()->getmarklist() 5993 5994getmatches([{win}]) *getmatches()* 5995 Returns a |List| with all matches previously defined for the 5996 current window by |matchadd()| and the |:match| commands. 5997 |getmatches()| is useful in combination with |setmatches()|, 5998 as |setmatches()| can restore a list of matches saved by 5999 |getmatches()|. 6000 If {win} is specified, use the window with this number or 6001 window ID instead of the current window. 6002 Example: > 6003 :echo getmatches() 6004< [{'group': 'MyGroup1', 'pattern': 'TODO', 6005 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 6006 'pattern': 'FIXME', 'priority': 10, 'id': 2}] > 6007 :let m = getmatches() 6008 :call clearmatches() 6009 :echo getmatches() 6010< [] > 6011 :call setmatches(m) 6012 :echo getmatches() 6013< [{'group': 'MyGroup1', 'pattern': 'TODO', 6014 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 6015 'pattern': 'FIXME', 'priority': 10, 'id': 2}] > 6016 :unlet m 6017< 6018getmousepos() *getmousepos()* 6019 Returns a |Dictionary| with the last known position of the 6020 mouse. This can be used in a mapping for a mouse click or in 6021 a filter of a popup window. The items are: 6022 screenrow screen row 6023 screencol screen column 6024 winid Window ID of the click 6025 winrow row inside "winid" 6026 wincol column inside "winid" 6027 line text line inside "winid" 6028 column text column inside "winid" 6029 All numbers are 1-based. 6030 6031 If not over a window, e.g. when in the command line, then only 6032 "screenrow" and "screencol" are valid, the others are zero. 6033 6034 When on the status line below a window or the vertical 6035 separator right of a window, the "line" and "column" values 6036 are zero. 6037 6038 When the position is after the text then "column" is the 6039 length of the text in bytes plus one. 6040 6041 If the mouse is over a popup window then that window is used. 6042 6043 When using |getchar()| the Vim variables |v:mouse_lnum|, 6044 |v:mouse_col| and |v:mouse_winid| also provide these values. 6045 6046 *getpid()* 6047getpid() Return a Number which is the process ID of the Vim process. 6048 On Unix and MS-Windows this is a unique number, until Vim 6049 exits. 6050 6051 *getpos()* 6052getpos({expr}) Get the position for String {expr}. For possible values of 6053 {expr} see |line()|. For getting the cursor position see 6054 |getcurpos()|. 6055 The result is a |List| with four numbers: 6056 [bufnum, lnum, col, off] 6057 "bufnum" is zero, unless a mark like '0 or 'A is used, then it 6058 is the buffer number of the mark. 6059 "lnum" and "col" are the position in the buffer. The first 6060 column is 1. 6061 The "off" number is zero, unless 'virtualedit' is used. Then 6062 it is the offset in screen columns from the start of the 6063 character. E.g., a position within a <Tab> or after the last 6064 character. 6065 Note that for '< and '> Visual mode matters: when it is "V" 6066 (visual line mode) the column of '< is zero and the column of 6067 '> is a large number. 6068 The column number in the returned List is the byte position 6069 within the line. To get the character position in the line, 6070 use |getcharpos()|. 6071 The column number can be very large, e.g. 2147483647, in which 6072 case it means "after the end of the line". 6073 This can be used to save and restore the position of a mark: > 6074 let save_a_mark = getpos("'a") 6075 ... 6076 call setpos("'a", save_a_mark) 6077< Also see |getcharpos()|, |getcurpos()| and |setpos()|. 6078 6079 Can also be used as a |method|: > 6080 GetMark()->getpos() 6081 6082getqflist([{what}]) *getqflist()* 6083 Returns a |List| with all the current quickfix errors. Each 6084 list item is a dictionary with these entries: 6085 bufnr number of buffer that has the file name, use 6086 bufname() to get the name 6087 module module name 6088 lnum line number in the buffer (first line is 1) 6089 end_lnum 6090 end of line number if the item is multiline 6091 col column number (first column is 1) 6092 end_col end of column number if the item has range 6093 vcol |TRUE|: "col" is visual column 6094 |FALSE|: "col" is byte index 6095 nr error number 6096 pattern search pattern used to locate the error 6097 text description of the error 6098 type type of the error, 'E', '1', etc. 6099 valid |TRUE|: recognized error message 6100 6101 When there is no error list or it's empty, an empty list is 6102 returned. Quickfix list entries with a non-existing buffer 6103 number are returned with "bufnr" set to zero (Note: some 6104 functions accept buffer number zero for the alternate buffer, 6105 you may need to explicitly check for zero). 6106 6107 Useful application: Find pattern matches in multiple files and 6108 do something with them: > 6109 :vimgrep /theword/jg *.c 6110 :for d in getqflist() 6111 : echo bufname(d.bufnr) ':' d.lnum '=' d.text 6112 :endfor 6113< 6114 If the optional {what} dictionary argument is supplied, then 6115 returns only the items listed in {what} as a dictionary. The 6116 following string items are supported in {what}: 6117 changedtick get the total number of changes made 6118 to the list |quickfix-changedtick| 6119 context get the |quickfix-context| 6120 efm errorformat to use when parsing "lines". If 6121 not present, then the 'errorformat' option 6122 value is used. 6123 id get information for the quickfix list with 6124 |quickfix-ID|; zero means the id for the 6125 current list or the list specified by "nr" 6126 idx get information for the quickfix entry at this 6127 index in the list specified by 'id' or 'nr'. 6128 If set to zero, then uses the current entry. 6129 See |quickfix-index| 6130 items quickfix list entries 6131 lines parse a list of lines using 'efm' and return 6132 the resulting entries. Only a |List| type is 6133 accepted. The current quickfix list is not 6134 modified. See |quickfix-parse|. 6135 nr get information for this quickfix list; zero 6136 means the current quickfix list and "$" means 6137 the last quickfix list 6138 qfbufnr number of the buffer displayed in the quickfix 6139 window. Returns 0 if the quickfix buffer is 6140 not present. See |quickfix-buffer|. 6141 size number of entries in the quickfix list 6142 title get the list title |quickfix-title| 6143 winid get the quickfix |window-ID| 6144 all all of the above quickfix properties 6145 Non-string items in {what} are ignored. To get the value of a 6146 particular item, set it to zero. 6147 If "nr" is not present then the current quickfix list is used. 6148 If both "nr" and a non-zero "id" are specified, then the list 6149 specified by "id" is used. 6150 To get the number of lists in the quickfix stack, set "nr" to 6151 "$" in {what}. The "nr" value in the returned dictionary 6152 contains the quickfix stack size. 6153 When "lines" is specified, all the other items except "efm" 6154 are ignored. The returned dictionary contains the entry 6155 "items" with the list of entries. 6156 6157 The returned dictionary contains the following entries: 6158 changedtick total number of changes made to the 6159 list |quickfix-changedtick| 6160 context quickfix list context. See |quickfix-context| 6161 If not present, set to "". 6162 id quickfix list ID |quickfix-ID|. If not 6163 present, set to 0. 6164 idx index of the quickfix entry in the list. If not 6165 present, set to 0. 6166 items quickfix list entries. If not present, set to 6167 an empty list. 6168 nr quickfix list number. If not present, set to 0 6169 qfbufnr number of the buffer displayed in the quickfix 6170 window. If not present, set to 0. 6171 size number of entries in the quickfix list. If not 6172 present, set to 0. 6173 title quickfix list title text. If not present, set 6174 to "". 6175 winid quickfix |window-ID|. If not present, set to 0 6176 6177 Examples (See also |getqflist-examples|): > 6178 :echo getqflist({'all': 1}) 6179 :echo getqflist({'nr': 2, 'title': 1}) 6180 :echo getqflist({'lines' : ["F1:10:L10"]}) 6181< 6182getreg([{regname} [, 1 [, {list}]]]) *getreg()* 6183 The result is a String, which is the contents of register 6184 {regname}. Example: > 6185 :let cliptext = getreg('*') 6186< When {regname} was not set the result is an empty string. 6187 The {regname} argument is a string. 6188 6189 getreg('=') returns the last evaluated value of the expression 6190 register. (For use in maps.) 6191 getreg('=', 1) returns the expression itself, so that it can 6192 be restored with |setreg()|. For other registers the extra 6193 argument is ignored, thus you can always give it. 6194 6195 If {list} is present and |TRUE|, the result type is changed 6196 to |List|. Each list item is one text line. Use it if you care 6197 about zero bytes possibly present inside register: without 6198 third argument both NLs and zero bytes are represented as NLs 6199 (see |NL-used-for-Nul|). 6200 When the register was not set an empty list is returned. 6201 6202 If {regname} is "", the unnamed register '"' is used. 6203 If {regname} is not specified, |v:register| is used. 6204 In |Vim9-script| {regname} must be one character. 6205 6206 Can also be used as a |method|: > 6207 GetRegname()->getreg() 6208 6209getreginfo([{regname}]) *getreginfo()* 6210 Returns detailed information about register {regname} as a 6211 Dictionary with the following entries: 6212 regcontents List of lines contained in register 6213 {regname}, like 6214 |getreg|({regname}, 1, 1). 6215 regtype the type of register {regname}, as in 6216 |getregtype()|. 6217 isunnamed Boolean flag, v:true if this register 6218 is currently pointed to by the unnamed 6219 register. 6220 points_to for the unnamed register, gives the 6221 single letter name of the register 6222 currently pointed to (see |quotequote|). 6223 For example, after deleting a line 6224 with `dd`, this field will be "1", 6225 which is the register that got the 6226 deleted text. 6227 6228 The {regname} argument is a string. If {regname} is invalid 6229 or not set, an empty Dictionary will be returned. 6230 If {regname} is "" or "@", the unnamed register '"' is used. 6231 If {regname} is not specified, |v:register| is used. 6232 The returned Dictionary can be passed to |setreg()|. 6233 In |Vim9-script| {regname} must be one character. 6234 6235 Can also be used as a |method|: > 6236 GetRegname()->getreginfo() 6237 6238getregtype([{regname}]) *getregtype()* 6239 The result is a String, which is type of register {regname}. 6240 The value will be one of: 6241 "v" for |characterwise| text 6242 "V" for |linewise| text 6243 "<CTRL-V>{width}" for |blockwise-visual| text 6244 "" for an empty or unknown register 6245 <CTRL-V> is one character with value 0x16. 6246 The {regname} argument is a string. If {regname} is "", the 6247 unnamed register '"' is used. If {regname} is not specified, 6248 |v:register| is used. 6249 In |Vim9-script| {regname} must be one character. 6250 6251 Can also be used as a |method|: > 6252 GetRegname()->getregtype() 6253 6254gettabinfo([{tabnr}]) *gettabinfo()* 6255 If {tabnr} is not specified, then information about all the 6256 tab pages is returned as a |List|. Each List item is a 6257 |Dictionary|. Otherwise, {tabnr} specifies the tab page 6258 number and information about that one is returned. If the tab 6259 page does not exist an empty List is returned. 6260 6261 Each List item is a |Dictionary| with the following entries: 6262 tabnr tab page number. 6263 variables a reference to the dictionary with 6264 tabpage-local variables 6265 windows List of |window-ID|s in the tab page. 6266 6267 Can also be used as a |method|: > 6268 GetTabnr()->gettabinfo() 6269 6270gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()* 6271 Get the value of a tab-local variable {varname} in tab page 6272 {tabnr}. |t:var| 6273 Tabs are numbered starting with one. 6274 The {varname} argument is a string. When {varname} is empty a 6275 dictionary with all tab-local variables is returned. 6276 Note that the name without "t:" must be used. 6277 When the tab or variable doesn't exist {def} or an empty 6278 string is returned, there is no error message. 6279 6280 Can also be used as a |method|: > 6281 GetTabnr()->gettabvar(varname) 6282 6283gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()* 6284 Get the value of window-local variable {varname} in window 6285 {winnr} in tab page {tabnr}. 6286 The {varname} argument is a string. When {varname} is empty a 6287 dictionary with all window-local variables is returned. 6288 When {varname} is equal to "&" get the values of all 6289 window-local options in a |Dictionary|. 6290 Otherwise, when {varname} starts with "&" get the value of a 6291 window-local option. 6292 Note that {varname} must be the name without "w:". 6293 Tabs are numbered starting with one. For the current tabpage 6294 use |getwinvar()|. 6295 {winnr} can be the window number or the |window-ID|. 6296 When {winnr} is zero the current window is used. 6297 This also works for a global option, buffer-local option and 6298 window-local option, but it doesn't work for a global variable 6299 or buffer-local variable. 6300 When the tab, window or variable doesn't exist {def} or an 6301 empty string is returned, there is no error message. 6302 Examples: > 6303 :let list_is_on = gettabwinvar(1, 2, '&list') 6304 :echo "myvar = " . gettabwinvar(3, 1, 'myvar') 6305< 6306 To obtain all window-local variables use: > 6307 gettabwinvar({tabnr}, {winnr}, '&') 6308 6309< Can also be used as a |method|: > 6310 GetTabnr()->gettabwinvar(winnr, varname) 6311 6312gettagstack([{winnr}]) *gettagstack()* 6313 The result is a Dict, which is the tag stack of window {winnr}. 6314 {winnr} can be the window number or the |window-ID|. 6315 When {winnr} is not specified, the current window is used. 6316 When window {winnr} doesn't exist, an empty Dict is returned. 6317 6318 The returned dictionary contains the following entries: 6319 curidx Current index in the stack. When at 6320 top of the stack, set to (length + 1). 6321 Index of bottom of the stack is 1. 6322 items List of items in the stack. Each item 6323 is a dictionary containing the 6324 entries described below. 6325 length Number of entries in the stack. 6326 6327 Each item in the stack is a dictionary with the following 6328 entries: 6329 bufnr buffer number of the current jump 6330 from cursor position before the tag jump. 6331 See |getpos()| for the format of the 6332 returned list. 6333 matchnr current matching tag number. Used when 6334 multiple matching tags are found for a 6335 name. 6336 tagname name of the tag 6337 6338 See |tagstack| for more information about the tag stack. 6339 6340 Can also be used as a |method|: > 6341 GetWinnr()->gettagstack() 6342 6343 6344gettext({text}) *gettext()* 6345 Translate String {text} if possible. 6346 This is mainly for use in the distributed Vim scripts. When 6347 generating message translations the {text} is extracted by 6348 xgettext, the translator can add the translated message in the 6349 .po file and Vim will lookup the translation when gettext() is 6350 called. 6351 For {text} double quoted strings are preferred, because 6352 xgettext does not understand escaping in single quoted 6353 strings. 6354 6355 6356getwininfo([{winid}]) *getwininfo()* 6357 Returns information about windows as a |List| with Dictionaries. 6358 6359 If {winid} is given Information about the window with that ID 6360 is returned, as a |List| with one item. If the window does not 6361 exist the result is an empty list. 6362 6363 Without {winid} information about all the windows in all the 6364 tab pages is returned. 6365 6366 Each List item is a |Dictionary| with the following entries: 6367 botline last complete displayed buffer line 6368 bufnr number of buffer in the window 6369 height window height (excluding winbar) 6370 loclist 1 if showing a location list 6371 {only with the +quickfix feature} 6372 quickfix 1 if quickfix or location list window 6373 {only with the +quickfix feature} 6374 terminal 1 if a terminal window 6375 {only with the +terminal feature} 6376 tabnr tab page number 6377 topline first displayed buffer line 6378 variables a reference to the dictionary with 6379 window-local variables 6380 width window width 6381 winbar 1 if the window has a toolbar, 0 6382 otherwise 6383 wincol leftmost screen column of the window; 6384 "col" from |win_screenpos()| 6385 textoff number of columns occupied by any 6386 'foldcolumn', 'signcolumn' and line 6387 number in front of the text 6388 winid |window-ID| 6389 winnr window number 6390 winrow topmost screen line of the window; 6391 "row" from |win_screenpos()| 6392 6393 Can also be used as a |method|: > 6394 GetWinnr()->getwininfo() 6395 6396getwinpos([{timeout}]) *getwinpos()* 6397 The result is a |List| with two numbers, the result of 6398 |getwinposx()| and |getwinposy()| combined: 6399 [x-pos, y-pos] 6400 {timeout} can be used to specify how long to wait in msec for 6401 a response from the terminal. When omitted 100 msec is used. 6402 Use a longer time for a remote terminal. 6403 When using a value less than 10 and no response is received 6404 within that time, a previously reported position is returned, 6405 if available. This can be used to poll for the position and 6406 do some work in the meantime: > 6407 while 1 6408 let res = getwinpos(1) 6409 if res[0] >= 0 6410 break 6411 endif 6412 " Do some work here 6413 endwhile 6414< 6415 6416 Can also be used as a |method|: > 6417 GetTimeout()->getwinpos() 6418< 6419 *getwinposx()* 6420getwinposx() The result is a Number, which is the X coordinate in pixels of 6421 the left hand side of the GUI Vim window. Also works for an 6422 xterm (uses a timeout of 100 msec). 6423 The result will be -1 if the information is not available. 6424 The value can be used with `:winpos`. 6425 6426 *getwinposy()* 6427getwinposy() The result is a Number, which is the Y coordinate in pixels of 6428 the top of the GUI Vim window. Also works for an xterm (uses 6429 a timeout of 100 msec). 6430 The result will be -1 if the information is not available. 6431 The value can be used with `:winpos`. 6432 6433getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* 6434 Like |gettabwinvar()| for the current tabpage. 6435 Examples: > 6436 :let list_is_on = getwinvar(2, '&list') 6437 :echo "myvar = " . getwinvar(1, 'myvar') 6438 6439< Can also be used as a |method|: > 6440 GetWinnr()->getwinvar(varname) 6441< 6442glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* 6443 Expand the file wildcards in {expr}. See |wildcards| for the 6444 use of special characters. 6445 6446 Unless the optional {nosuf} argument is given and is |TRUE|, 6447 the 'suffixes' and 'wildignore' options apply: Names matching 6448 one of the patterns in 'wildignore' will be skipped and 6449 'suffixes' affect the ordering of matches. 6450 'wildignorecase' always applies. 6451 6452 When {list} is present and it is |TRUE| the result is a |List| 6453 with all matching files. The advantage of using a List is, 6454 you also get filenames containing newlines correctly. 6455 Otherwise the result is a String and when there are several 6456 matches, they are separated by <NL> characters. 6457 6458 If the expansion fails, the result is an empty String or List. 6459 6460 You can also use |readdir()| if you need to do complicated 6461 things, such as limiting the number of matches. 6462 6463 A name for a non-existing file is not included. A symbolic 6464 link is only included if it points to an existing file. 6465 However, when the {alllinks} argument is present and it is 6466 |TRUE| then all symbolic links are included. 6467 6468 For most systems backticks can be used to get files names from 6469 any external command. Example: > 6470 :let tagfiles = glob("`find . -name tags -print`") 6471 :let &tags = substitute(tagfiles, "\n", ",", "g") 6472< The result of the program inside the backticks should be one 6473 item per line. Spaces inside an item are allowed. 6474 6475 See |expand()| for expanding special Vim variables. See 6476 |system()| for getting the raw output of an external command. 6477 6478 Can also be used as a |method|: > 6479 GetExpr()->glob() 6480 6481glob2regpat({string}) *glob2regpat()* 6482 Convert a file pattern, as used by glob(), into a search 6483 pattern. The result can be used to match with a string that 6484 is a file name. E.g. > 6485 if filename =~ glob2regpat('Make*.mak') 6486< This is equivalent to: > 6487 if filename =~ '^Make.*\.mak$' 6488< When {string} is an empty string the result is "^$", match an 6489 empty string. 6490 Note that the result depends on the system. On MS-Windows 6491 a backslash usually means a path separator. 6492 6493 Can also be used as a |method|: > 6494 GetExpr()->glob2regpat() 6495< *globpath()* 6496globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) 6497 Perform glob() for String {expr} on all directories in {path} 6498 and concatenate the results. Example: > 6499 :echo globpath(&rtp, "syntax/c.vim") 6500< 6501 {path} is a comma-separated list of directory names. Each 6502 directory name is prepended to {expr} and expanded like with 6503 |glob()|. A path separator is inserted when needed. 6504 To add a comma inside a directory name escape it with a 6505 backslash. Note that on MS-Windows a directory may have a 6506 trailing backslash, remove it if you put a comma after it. 6507 If the expansion fails for one of the directories, there is no 6508 error message. 6509 6510 Unless the optional {nosuf} argument is given and is |TRUE|, 6511 the 'suffixes' and 'wildignore' options apply: Names matching 6512 one of the patterns in 'wildignore' will be skipped and 6513 'suffixes' affect the ordering of matches. 6514 6515 When {list} is present and it is |TRUE| the result is a |List| 6516 with all matching files. The advantage of using a List is, you 6517 also get filenames containing newlines correctly. Otherwise 6518 the result is a String and when there are several matches, 6519 they are separated by <NL> characters. Example: > 6520 :echo globpath(&rtp, "syntax/c.vim", 0, 1) 6521< 6522 {alllinks} is used as with |glob()|. 6523 6524 The "**" item can be used to search in a directory tree. 6525 For example, to find all "README.txt" files in the directories 6526 in 'runtimepath' and below: > 6527 :echo globpath(&rtp, "**/README.txt") 6528< Upwards search and limiting the depth of "**" is not 6529 supported, thus using 'path' will not always work properly. 6530 6531 Can also be used as a |method|, the base is passed as the 6532 second argument: > 6533 GetExpr()->globpath(&rtp) 6534< 6535 *has()* 6536has({feature} [, {check}]) 6537 When {check} is omitted or is zero: The result is a Number, 6538 which is 1 if the feature {feature} is supported, zero 6539 otherwise. The {feature} argument is a string, case is 6540 ignored. See |feature-list| below. 6541 6542 When {check} is present and not zero: The result is a Number, 6543 which is 1 if the feature {feature} could ever be supported, 6544 zero otherwise. This is useful to check for a typo in 6545 {feature} and to detect dead code. Keep in mind that an older 6546 Vim version will not know about a feature added later and 6547 features that have been abandoned will not be known by the 6548 current Vim version. 6549 6550 Also see |exists()| and |exists_compiled()|. 6551 6552 Note that to skip code that has a syntax error when the 6553 feature is not available, Vim may skip the rest of the line 6554 and miss a following `endif`. Therefore put the `endif` on a 6555 separate line: > 6556 if has('feature') 6557 let x = this->breaks->without->the->feature 6558 endif 6559< If the `endif` would be moved to the second line as "| endif" it 6560 would not be found. 6561 6562 6563has_key({dict}, {key}) *has_key()* 6564 The result is a Number, which is TRUE if |Dictionary| {dict} 6565 has an entry with key {key}. FALSE otherwise. The {key} 6566 argument is a string. 6567 6568 Can also be used as a |method|: > 6569 mydict->has_key(key) 6570 6571haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()* 6572 The result is a Number: 6573 1 when the window has set a local directory via |:lcd| 6574 2 when the tab-page has set a local directory via |:tcd| 6575 0 otherwise. 6576 6577 Without arguments use the current window. 6578 With {winnr} use this window in the current tab page. 6579 With {winnr} and {tabnr} use the window in the specified tab 6580 page. 6581 {winnr} can be the window number or the |window-ID|. 6582 If {winnr} is -1 it is ignored and only the tabpage is used. 6583 Return 0 if the arguments are invalid. 6584 Examples: > 6585 if haslocaldir() == 1 6586 " window local directory case 6587 elseif haslocaldir() == 2 6588 " tab-local directory case 6589 else 6590 " global directory case 6591 endif 6592 6593 " current window 6594 :echo haslocaldir() 6595 :echo haslocaldir(0) 6596 :echo haslocaldir(0, 0) 6597 " window n in current tab page 6598 :echo haslocaldir(n) 6599 :echo haslocaldir(n, 0) 6600 " window n in tab page m 6601 :echo haslocaldir(n, m) 6602 " tab page m 6603 :echo haslocaldir(-1, m) 6604< 6605 Can also be used as a |method|: > 6606 GetWinnr()->haslocaldir() 6607 6608hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* 6609 The result is a Number, which is TRUE if there is a mapping 6610 that contains {what} in somewhere in the rhs (what it is 6611 mapped to) and this mapping exists in one of the modes 6612 indicated by {mode}. 6613 The arguments {what} and {mode} are strings. 6614 When {abbr} is there and it is |TRUE| use abbreviations 6615 instead of mappings. Don't forget to specify Insert and/or 6616 Command-line mode. 6617 Both the global mappings and the mappings local to the current 6618 buffer are checked for a match. 6619 If no matching mapping is found FALSE is returned. 6620 The following characters are recognized in {mode}: 6621 n Normal mode 6622 v Visual and Select mode 6623 x Visual mode 6624 s Select mode 6625 o Operator-pending mode 6626 i Insert mode 6627 l Language-Argument ("r", "f", "t", etc.) 6628 c Command-line mode 6629 When {mode} is omitted, "nvo" is used. 6630 6631 This function is useful to check if a mapping already exists 6632 to a function in a Vim script. Example: > 6633 :if !hasmapto('\ABCdoit') 6634 : map <Leader>d \ABCdoit 6635 :endif 6636< This installs the mapping to "\ABCdoit" only if there isn't 6637 already a mapping to "\ABCdoit". 6638 6639 Can also be used as a |method|: > 6640 GetRHS()->hasmapto() 6641 6642histadd({history}, {item}) *histadd()* 6643 Add the String {item} to the history {history} which can be 6644 one of: *hist-names* 6645 "cmd" or ":" command line history 6646 "search" or "/" search pattern history 6647 "expr" or "=" typed expression history 6648 "input" or "@" input line history 6649 "debug" or ">" debug command history 6650 empty the current or last used history 6651 The {history} string does not need to be the whole name, one 6652 character is sufficient. 6653 If {item} does already exist in the history, it will be 6654 shifted to become the newest entry. 6655 The result is a Number: TRUE if the operation was successful, 6656 otherwise FALSE is returned. 6657 6658 Example: > 6659 :call histadd("input", strftime("%Y %b %d")) 6660 :let date=input("Enter date: ") 6661< This function is not available in the |sandbox|. 6662 6663 Can also be used as a |method|, the base is passed as the 6664 second argument: > 6665 GetHistory()->histadd('search') 6666 6667histdel({history} [, {item}]) *histdel()* 6668 Clear {history}, i.e. delete all its entries. See |hist-names| 6669 for the possible values of {history}. 6670 6671 If the parameter {item} evaluates to a String, it is used as a 6672 regular expression. All entries matching that expression will 6673 be removed from the history (if there are any). 6674 Upper/lowercase must match, unless "\c" is used |/\c|. 6675 If {item} evaluates to a Number, it will be interpreted as 6676 an index, see |:history-indexing|. The respective entry will 6677 be removed if it exists. 6678 6679 The result is TRUE for a successful operation, otherwise FALSE 6680 is returned. 6681 6682 Examples: 6683 Clear expression register history: > 6684 :call histdel("expr") 6685< 6686 Remove all entries starting with "*" from the search history: > 6687 :call histdel("/", '^\*') 6688< 6689 The following three are equivalent: > 6690 :call histdel("search", histnr("search")) 6691 :call histdel("search", -1) 6692 :call histdel("search", '^'.histget("search", -1).'$') 6693< 6694 To delete the last search pattern and use the last-but-one for 6695 the "n" command and 'hlsearch': > 6696 :call histdel("search", -1) 6697 :let @/ = histget("search", -1) 6698< 6699 Can also be used as a |method|: > 6700 GetHistory()->histdel() 6701 6702histget({history} [, {index}]) *histget()* 6703 The result is a String, the entry with Number {index} from 6704 {history}. See |hist-names| for the possible values of 6705 {history}, and |:history-indexing| for {index}. If there is 6706 no such entry, an empty String is returned. When {index} is 6707 omitted, the most recent item from the history is used. 6708 6709 Examples: 6710 Redo the second last search from history. > 6711 :execute '/' . histget("search", -2) 6712 6713< Define an Ex command ":H {num}" that supports re-execution of 6714 the {num}th entry from the output of |:history|. > 6715 :command -nargs=1 H execute histget("cmd", 0+<args>) 6716< 6717 Can also be used as a |method|: > 6718 GetHistory()->histget() 6719 6720histnr({history}) *histnr()* 6721 The result is the Number of the current entry in {history}. 6722 See |hist-names| for the possible values of {history}. 6723 If an error occurred, -1 is returned. 6724 6725 Example: > 6726 :let inp_index = histnr("expr") 6727 6728< Can also be used as a |method|: > 6729 GetHistory()->histnr() 6730< 6731hlexists({name}) *hlexists()* 6732 The result is a Number, which is TRUE if a highlight group 6733 called {name} exists. This is when the group has been 6734 defined in some way. Not necessarily when highlighting has 6735 been defined for it, it may also have been used for a syntax 6736 item. 6737 *highlight_exists()* 6738 Obsolete name: highlight_exists(). 6739 6740 Can also be used as a |method|: > 6741 GetName()->hlexists() 6742< 6743hlget([{name} [, {resolve}]]) *hlget()* 6744 Returns a List of all the highlight group attributes. If the 6745 optional {name} is specified, then returns a List with only 6746 the attributes of the specified highlight group. Returns an 6747 empty List if the highlight group {name} is not present. 6748 6749 If the optional {resolve} argument is set to v:true and the 6750 highlight group {name} is linked to another group, then the 6751 link is resolved recursively and the attributes of the 6752 resolved highlight group are returned. 6753 6754 Each entry in the returned List is a Dictionary with the 6755 following items: 6756 cleared boolean flag, set to v:true if the highlight 6757 group attributes are cleared or not yet 6758 specified. See |highlight-clear|. 6759 cterm cterm attributes. See |highlight-cterm|. 6760 ctermbg cterm background color. 6761 See |highlight-ctermbg|. 6762 ctermfg cterm foreground color. 6763 See |highlight-ctermfg|. 6764 ctermul cterm underline color. See |highlight-ctermul|. 6765 default boolean flag, set to v:true if the highlight 6766 group link is a default link. See 6767 |highlight-default|. 6768 font highlight group font. See |highlight-font|. 6769 gui gui attributes. See |highlight-gui|. 6770 guibg gui background color. See |highlight-guibg|. 6771 guifg gui foreground color. See |highlight-guifg|. 6772 guisp gui special color. See |highlight-guisp|. 6773 id highlight group ID. 6774 linksto linked highlight group name. 6775 See |:highlight-link|. 6776 name highlight group name. See |group-name|. 6777 start start terminal keycode. See |highlight-start|. 6778 stop stop terminal keycode. See |highlight-stop|. 6779 term term attributes. See |highlight-term|. 6780 6781 The 'term', 'cterm' and 'gui' items in the above Dictionary 6782 have a dictionary value with the following optional boolean 6783 items: 'bold', 'standout', 'underline', 'undercurl', 'italic', 6784 'reverse', 'inverse' and 'strikethrough'. 6785 6786 Example(s): > 6787 :echo hlget() 6788 :echo hlget('ModeMsg') 6789 :echo hlget('Number', v:true) 6790< 6791 Can also be used as a |method|: > 6792 GetName()->hlget() 6793< 6794hlset({list}) *hlset()* 6795 Creates or modifies the attributes of a List of highlight 6796 groups. Each item in {list} is a dictionary containing the 6797 attributes of a highlight group. See |hlget()| for the list of 6798 supported items in this dictionary. 6799 6800 In addition to the items described in |hlget()|, the following 6801 additional items are supported in the dictionary: 6802 6803 force boolean flag to force the creation of 6804 a link for an existing highlight group 6805 with attributes. 6806 6807 The highlight group is identified using the 'name' item and 6808 the 'id' item (if supplied) is ignored. If a highlight group 6809 with a specified name doesn't exist, then it is created. 6810 Otherwise the attributes of an existing highlight group are 6811 modified. 6812 6813 If an empty dictionary value is used for the 'term' or 'cterm' 6814 or 'gui' entries, then the corresponding attributes are 6815 cleared. If the 'cleared' item is set to v:true, then all the 6816 attributes of the highlight group are cleared. 6817 6818 The 'linksto' item can be used to link a highlight group to 6819 another highlight group. See |:highlight-link|. 6820 6821 Returns zero for success, -1 for failure. 6822 6823 Example(s): > 6824 " add bold attribute to the Visual highlight group 6825 :call hlset([#{name: 'Visual', 6826 \ term: #{reverse: 1 , bold: 1}}]) 6827 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}]) 6828 :let l = hlget() 6829 :call hlset(l) 6830 " clear the Search highlight group 6831 :call hlset([#{name: 'Search', cleared: v:true}]) 6832 " clear the 'term' attributes for a highlight group 6833 :call hlset([#{name: 'Title', term: {}}]) 6834 " create the MyHlg group linking it to DiffAdd 6835 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}]) 6836 " remove the MyHlg group link 6837 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}]) 6838 " clear the attributes and a link 6839 :call hlset([#{name: 'MyHlg', cleared: v:true, 6840 \ linksto: 'NONE'}]) 6841< 6842 Can also be used as a |method|: > 6843 GetAttrList()->hlset() 6844< 6845 *hlID()* 6846hlID({name}) The result is a Number, which is the ID of the highlight group 6847 with name {name}. When the highlight group doesn't exist, 6848 zero is returned. 6849 This can be used to retrieve information about the highlight 6850 group. For example, to get the background color of the 6851 "Comment" group: > 6852 :echo synIDattr(synIDtrans(hlID("Comment")), "bg") 6853< *highlightID()* 6854 Obsolete name: highlightID(). 6855 6856 Can also be used as a |method|: > 6857 GetName()->hlID() 6858 6859hostname() *hostname()* 6860 The result is a String, which is the name of the machine on 6861 which Vim is currently running. Machine names greater than 6862 256 characters long are truncated. 6863 6864iconv({string}, {from}, {to}) *iconv()* 6865 The result is a String, which is the text {string} converted 6866 from encoding {from} to encoding {to}. 6867 When the conversion completely fails an empty string is 6868 returned. When some characters could not be converted they 6869 are replaced with "?". 6870 The encoding names are whatever the iconv() library function 6871 can accept, see ":!man 3 iconv". 6872 Most conversions require Vim to be compiled with the |+iconv| 6873 feature. Otherwise only UTF-8 to latin1 conversion and back 6874 can be done. 6875 This can be used to display messages with special characters, 6876 no matter what 'encoding' is set to. Write the message in 6877 UTF-8 and use: > 6878 echo iconv(utf8_str, "utf-8", &enc) 6879< Note that Vim uses UTF-8 for all Unicode encodings, conversion 6880 from/to UCS-2 is automatically changed to use UTF-8. You 6881 cannot use UCS-2 in a string anyway, because of the NUL bytes. 6882 6883 Can also be used as a |method|: > 6884 GetText()->iconv('latin1', 'utf-8') 6885< 6886 *indent()* 6887indent({lnum}) The result is a Number, which is indent of line {lnum} in the 6888 current buffer. The indent is counted in spaces, the value 6889 of 'tabstop' is relevant. {lnum} is used just like in 6890 |getline()|. 6891 When {lnum} is invalid -1 is returned. 6892 6893 Can also be used as a |method|: > 6894 GetLnum()->indent() 6895 6896index({object}, {expr} [, {start} [, {ic}]]) *index()* 6897 If {object} is a |List| return the lowest index where the item 6898 has a value equal to {expr}. There is no automatic 6899 conversion, so the String "4" is different from the Number 4. 6900 And the number 4 is different from the Float 4.0. The value 6901 of 'ignorecase' is not used here, case always matters. 6902 6903 If {object} is |Blob| return the lowest index where the byte 6904 value is equal to {expr}. 6905 6906 If {start} is given then start looking at the item with index 6907 {start} (may be negative for an item relative to the end). 6908 When {ic} is given and it is |TRUE|, ignore case. Otherwise 6909 case must match. 6910 -1 is returned when {expr} is not found in {object}. 6911 Example: > 6912 :let idx = index(words, "the") 6913 :if index(numbers, 123) >= 0 6914 6915< Can also be used as a |method|: > 6916 GetObject()->index(what) 6917 6918input({prompt} [, {text} [, {completion}]]) *input()* 6919 The result is a String, which is whatever the user typed on 6920 the command-line. The {prompt} argument is either a prompt 6921 string, or a blank string (for no prompt). A '\n' can be used 6922 in the prompt to start a new line. 6923 The highlighting set with |:echohl| is used for the prompt. 6924 The input is entered just like a command-line, with the same 6925 editing commands and mappings. There is a separate history 6926 for lines typed for input(). 6927 Example: > 6928 :if input("Coffee or beer? ") == "beer" 6929 : echo "Cheers!" 6930 :endif 6931< 6932 If the optional {text} argument is present and not empty, this 6933 is used for the default reply, as if the user typed this. 6934 Example: > 6935 :let color = input("Color? ", "white") 6936 6937< The optional {completion} argument specifies the type of 6938 completion supported for the input. Without it completion is 6939 not performed. The supported completion types are the same as 6940 that can be supplied to a user-defined command using the 6941 "-complete=" argument. Refer to |:command-completion| for 6942 more information. Example: > 6943 let fname = input("File: ", "", "file") 6944< 6945 NOTE: This function must not be used in a startup file, for 6946 the versions that only run in GUI mode (e.g., the Win32 GUI). 6947 Note: When input() is called from within a mapping it will 6948 consume remaining characters from that mapping, because a 6949 mapping is handled like the characters were typed. 6950 Use |inputsave()| before input() and |inputrestore()| 6951 after input() to avoid that. Another solution is to avoid 6952 that further characters follow in the mapping, e.g., by using 6953 |:execute| or |:normal|. 6954 6955 Example with a mapping: > 6956 :nmap \x :call GetFoo()<CR>:exe "/" . Foo<CR> 6957 :function GetFoo() 6958 : call inputsave() 6959 : let g:Foo = input("enter search pattern: ") 6960 : call inputrestore() 6961 :endfunction 6962 6963< Can also be used as a |method|: > 6964 GetPrompt()->input() 6965 6966inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()* 6967 Like |input()|, but when the GUI is running and text dialogs 6968 are supported, a dialog window pops up to input the text. 6969 Example: > 6970 :let n = inputdialog("value for shiftwidth", shiftwidth()) 6971 :if n != "" 6972 : let &sw = n 6973 :endif 6974< When the dialog is cancelled {cancelreturn} is returned. When 6975 omitted an empty string is returned. 6976 Hitting <Enter> works like pressing the OK button. Hitting 6977 <Esc> works like pressing the Cancel button. 6978 NOTE: Command-line completion is not supported. 6979 6980 Can also be used as a |method|: > 6981 GetPrompt()->inputdialog() 6982 6983inputlist({textlist}) *inputlist()* 6984 {textlist} must be a |List| of strings. This |List| is 6985 displayed, one string per line. The user will be prompted to 6986 enter a number, which is returned. 6987 The user can also select an item by clicking on it with the 6988 mouse, if the mouse is enabled in the command line ('mouse' is 6989 "a" or includes "c"). For the first string 0 is returned. 6990 When clicking above the first item a negative number is 6991 returned. When clicking on the prompt one more than the 6992 length of {textlist} is returned. 6993 Make sure {textlist} has less than 'lines' entries, otherwise 6994 it won't work. It's a good idea to put the entry number at 6995 the start of the string. And put a prompt in the first item. 6996 Example: > 6997 let color = inputlist(['Select color:', '1. red', 6998 \ '2. green', '3. blue']) 6999 7000< Can also be used as a |method|: > 7001 GetChoices()->inputlist() 7002 7003inputrestore() *inputrestore()* 7004 Restore typeahead that was saved with a previous |inputsave()|. 7005 Should be called the same number of times inputsave() is 7006 called. Calling it more often is harmless though. 7007 Returns TRUE when there is nothing to restore, FALSE otherwise. 7008 7009inputsave() *inputsave()* 7010 Preserve typeahead (also from mappings) and clear it, so that 7011 a following prompt gets input from the user. Should be 7012 followed by a matching inputrestore() after the prompt. Can 7013 be used several times, in which case there must be just as 7014 many inputrestore() calls. 7015 Returns TRUE when out of memory, FALSE otherwise. 7016 7017inputsecret({prompt} [, {text}]) *inputsecret()* 7018 This function acts much like the |input()| function with but 7019 two exceptions: 7020 a) the user's response will be displayed as a sequence of 7021 asterisks ("*") thereby keeping the entry secret, and 7022 b) the user's response will not be recorded on the input 7023 |history| stack. 7024 The result is a String, which is whatever the user actually 7025 typed on the command-line in response to the issued prompt. 7026 NOTE: Command-line completion is not supported. 7027 7028 Can also be used as a |method|: > 7029 GetPrompt()->inputsecret() 7030 7031insert({object}, {item} [, {idx}]) *insert()* 7032 When {object} is a |List| or a |Blob| insert {item} at the start 7033 of it. 7034 7035 If {idx} is specified insert {item} before the item with index 7036 {idx}. If {idx} is zero it goes before the first item, just 7037 like omitting {idx}. A negative {idx} is also possible, see 7038 |list-index|. -1 inserts just before the last item. 7039 7040 Returns the resulting |List| or |Blob|. Examples: > 7041 :let mylist = insert([2, 3, 5], 1) 7042 :call insert(mylist, 4, -1) 7043 :call insert(mylist, 6, len(mylist)) 7044< The last example can be done simpler with |add()|. 7045 Note that when {item} is a |List| it is inserted as a single 7046 item. Use |extend()| to concatenate |Lists|. 7047 7048 Can also be used as a |method|: > 7049 mylist->insert(item) 7050 7051interrupt() *interrupt()* 7052 Interrupt script execution. It works more or less like the 7053 user typing CTRL-C, most commands won't execute and control 7054 returns to the user. This is useful to abort execution 7055 from lower down, e.g. in an autocommand. Example: > 7056 :function s:check_typoname(file) 7057 : if fnamemodify(a:file, ':t') == '[' 7058 : echomsg 'Maybe typo' 7059 : call interrupt() 7060 : endif 7061 :endfunction 7062 :au BufWritePre * call s:check_typoname(expand('<amatch>')) 7063 7064invert({expr}) *invert()* 7065 Bitwise invert. The argument is converted to a number. A 7066 List, Dict or Float argument causes an error. Example: > 7067 :let bits = invert(bits) 7068< Can also be used as a |method|: > 7069 :let bits = bits->invert() 7070 7071isdirectory({directory}) *isdirectory()* 7072 The result is a Number, which is |TRUE| when a directory 7073 with the name {directory} exists. If {directory} doesn't 7074 exist, or isn't a directory, the result is |FALSE|. {directory} 7075 is any expression, which is used as a String. 7076 7077 Can also be used as a |method|: > 7078 GetName()->isdirectory() 7079 7080isinf({expr}) *isinf()* 7081 Return 1 if {expr} is a positive infinity, or -1 a negative 7082 infinity, otherwise 0. > 7083 :echo isinf(1.0 / 0.0) 7084< 1 > 7085 :echo isinf(-1.0 / 0.0) 7086< -1 7087 7088 Can also be used as a |method|: > 7089 Compute()->isinf() 7090< 7091 {only available when compiled with the |+float| feature} 7092 7093islocked({expr}) *islocked()* *E786* 7094 The result is a Number, which is |TRUE| when {expr} is the 7095 name of a locked variable. 7096 The string argument {expr} must be the name of a variable, 7097 |List| item or |Dictionary| entry, not the variable itself! 7098 Example: > 7099 :let alist = [0, ['a', 'b'], 2, 3] 7100 :lockvar 1 alist 7101 :echo islocked('alist') " 1 7102 :echo islocked('alist[1]') " 0 7103 7104< When {expr} is a variable that does not exist you get an error 7105 message. Use |exists()| to check for existence. 7106 In Vim9 script it does not work for local variables. 7107 7108 Can also be used as a |method|: > 7109 GetName()->islocked() 7110 7111isnan({expr}) *isnan()* 7112 Return |TRUE| if {expr} is a float with value NaN. > 7113 echo isnan(0.0 / 0.0) 7114< 1 7115 7116 Can also be used as a |method|: > 7117 Compute()->isnan() 7118< 7119 {only available when compiled with the |+float| feature} 7120 7121items({dict}) *items()* 7122 Return a |List| with all the key-value pairs of {dict}. Each 7123 |List| item is a list with two items: the key of a {dict} 7124 entry and the value of this entry. The |List| is in arbitrary 7125 order. Also see |keys()| and |values()|. 7126 Example: > 7127 for [key, value] in items(mydict) 7128 echo key . ': ' . value 7129 endfor 7130 7131< Can also be used as a |method|: > 7132 mydict->items() 7133 7134job_ functions are documented here: |job-functions-details| 7135 7136 7137join({list} [, {sep}]) *join()* 7138 Join the items in {list} together into one String. 7139 When {sep} is specified it is put in between the items. If 7140 {sep} is omitted a single space is used. 7141 Note that {sep} is not added at the end. You might want to 7142 add it there too: > 7143 let lines = join(mylist, "\n") . "\n" 7144< String items are used as-is. |Lists| and |Dictionaries| are 7145 converted into a string like with |string()|. 7146 The opposite function is |split()|. 7147 7148 Can also be used as a |method|: > 7149 mylist->join() 7150 7151js_decode({string}) *js_decode()* 7152 This is similar to |json_decode()| with these differences: 7153 - Object key names do not have to be in quotes. 7154 - Strings can be in single quotes. 7155 - Empty items in an array (between two commas) are allowed and 7156 result in v:none items. 7157 7158 Can also be used as a |method|: > 7159 ReadObject()->js_decode() 7160 7161js_encode({expr}) *js_encode()* 7162 This is similar to |json_encode()| with these differences: 7163 - Object key names are not in quotes. 7164 - v:none items in an array result in an empty item between 7165 commas. 7166 For example, the Vim object: 7167 [1,v:none,{"one":1},v:none] ~ 7168 Will be encoded as: 7169 [1,,{one:1},,] ~ 7170 While json_encode() would produce: 7171 [1,null,{"one":1},null] ~ 7172 This encoding is valid for JavaScript. It is more efficient 7173 than JSON, especially when using an array with optional items. 7174 7175 Can also be used as a |method|: > 7176 GetObject()->js_encode() 7177 7178json_decode({string}) *json_decode()* 7179 This parses a JSON formatted string and returns the equivalent 7180 in Vim values. See |json_encode()| for the relation between 7181 JSON and Vim values. 7182 The decoding is permissive: 7183 - A trailing comma in an array and object is ignored, e.g. 7184 "[1, 2, ]" is the same as "[1, 2]". 7185 - Integer keys are accepted in objects, e.g. {1:2} is the 7186 same as {"1":2}. 7187 - More floating point numbers are recognized, e.g. "1." for 7188 "1.0", or "001.2" for "1.2". Special floating point values 7189 "Infinity", "-Infinity" and "NaN" (capitalization ignored) 7190 are accepted. 7191 - Leading zeroes in integer numbers are ignored, e.g. "012" 7192 for "12" or "-012" for "-12". 7193 - Capitalization is ignored in literal names null, true or 7194 false, e.g. "NULL" for "null", "True" for "true". 7195 - Control characters U+0000 through U+001F which are not 7196 escaped in strings are accepted, e.g. " " (tab 7197 character in string) for "\t". 7198 - An empty JSON expression or made of only spaces is accepted 7199 and results in v:none. 7200 - Backslash in an invalid 2-character sequence escape is 7201 ignored, e.g. "\a" is decoded as "a". 7202 - A correct surrogate pair in JSON strings should normally be 7203 a 12 character sequence such as "\uD834\uDD1E", but 7204 json_decode() silently accepts truncated surrogate pairs 7205 such as "\uD834" or "\uD834\u" 7206 *E938* 7207 A duplicate key in an object, valid in rfc7159, is not 7208 accepted by json_decode() as the result must be a valid Vim 7209 type, e.g. this fails: {"a":"b", "a":"c"} 7210 7211 Can also be used as a |method|: > 7212 ReadObject()->json_decode() 7213 7214json_encode({expr}) *json_encode()* 7215 Encode {expr} as JSON and return this as a string. 7216 The encoding is specified in: 7217 https://tools.ietf.org/html/rfc7159.html 7218 Vim values are converted as follows: 7219 |Number| decimal number 7220 |Float| floating point number 7221 Float nan "NaN" 7222 Float inf "Infinity" 7223 Float -inf "-Infinity" 7224 |String| in double quotes (possibly null) 7225 |Funcref| not possible, error 7226 |List| as an array (possibly null); when 7227 used recursively: [] 7228 |Dict| as an object (possibly null); when 7229 used recursively: {} 7230 |Blob| as an array of the individual bytes 7231 v:false "false" 7232 v:true "true" 7233 v:none "null" 7234 v:null "null" 7235 Note that NaN and Infinity are passed on as values. This is 7236 missing in the JSON standard, but several implementations do 7237 allow it. If not then you will get an error. 7238 7239 Can also be used as a |method|: > 7240 GetObject()->json_encode() 7241 7242keys({dict}) *keys()* 7243 Return a |List| with all the keys of {dict}. The |List| is in 7244 arbitrary order. Also see |items()| and |values()|. 7245 7246 Can also be used as a |method|: > 7247 mydict->keys() 7248 7249< *len()* *E701* 7250len({expr}) The result is a Number, which is the length of the argument. 7251 When {expr} is a String or a Number the length in bytes is 7252 used, as with |strlen()|. 7253 When {expr} is a |List| the number of items in the |List| is 7254 returned. 7255 When {expr} is a |Blob| the number of bytes is returned. 7256 When {expr} is a |Dictionary| the number of entries in the 7257 |Dictionary| is returned. 7258 Otherwise an error is given. 7259 7260 Can also be used as a |method|: > 7261 mylist->len() 7262 7263< *libcall()* *E364* *E368* 7264libcall({libname}, {funcname}, {argument}) 7265 Call function {funcname} in the run-time library {libname} 7266 with single argument {argument}. 7267 This is useful to call functions in a library that you 7268 especially made to be used with Vim. Since only one argument 7269 is possible, calling standard library functions is rather 7270 limited. 7271 The result is the String returned by the function. If the 7272 function returns NULL, this will appear as an empty string "" 7273 to Vim. 7274 If the function returns a number, use libcallnr()! 7275 If {argument} is a number, it is passed to the function as an 7276 int; if {argument} is a string, it is passed as a 7277 null-terminated string. 7278 This function will fail in |restricted-mode|. 7279 7280 libcall() allows you to write your own 'plug-in' extensions to 7281 Vim without having to recompile the program. It is NOT a 7282 means to call system functions! If you try to do so Vim will 7283 very probably crash. 7284 7285 For Win32, the functions you write must be placed in a DLL 7286 and use the normal C calling convention (NOT Pascal which is 7287 used in Windows System DLLs). The function must take exactly 7288 one parameter, either a character pointer or a long integer, 7289 and must return a character pointer or NULL. The character 7290 pointer returned must point to memory that will remain valid 7291 after the function has returned (e.g. in static data in the 7292 DLL). If it points to allocated memory, that memory will 7293 leak away. Using a static buffer in the function should work, 7294 it's then freed when the DLL is unloaded. 7295 7296 WARNING: If the function returns a non-valid pointer, Vim may 7297 crash! This also happens if the function returns a number, 7298 because Vim thinks it's a pointer. 7299 For Win32 systems, {libname} should be the filename of the DLL 7300 without the ".DLL" suffix. A full path is only required if 7301 the DLL is not in the usual places. 7302 For Unix: When compiling your own plugins, remember that the 7303 object code must be compiled as position-independent ('PIC'). 7304 {only in Win32 and some Unix versions, when the |+libcall| 7305 feature is present} 7306 Examples: > 7307 :echo libcall("libc.so", "getenv", "HOME") 7308 7309< Can also be used as a |method|, the base is passed as the 7310 third argument: > 7311 GetValue()->libcall("libc.so", "getenv") 7312< 7313 *libcallnr()* 7314libcallnr({libname}, {funcname}, {argument}) 7315 Just like |libcall()|, but used for a function that returns an 7316 int instead of a string. 7317 {only in Win32 on some Unix versions, when the |+libcall| 7318 feature is present} 7319 Examples: > 7320 :echo libcallnr("/usr/lib/libc.so", "getpid", "") 7321 :call libcallnr("libc.so", "printf", "Hello World!\n") 7322 :call libcallnr("libc.so", "sleep", 10) 7323< 7324 Can also be used as a |method|, the base is passed as the 7325 third argument: > 7326 GetValue()->libcallnr("libc.so", "printf") 7327< 7328 7329line({expr} [, {winid}]) *line()* 7330 The result is a Number, which is the line number of the file 7331 position given with {expr}. The {expr} argument is a string. 7332 The accepted positions are: 7333 . the cursor position 7334 $ the last line in the current buffer 7335 'x position of mark x (if the mark is not set, 0 is 7336 returned) 7337 w0 first line visible in current window (one if the 7338 display isn't updated, e.g. in silent Ex mode) 7339 w$ last line visible in current window (this is one 7340 less than "w0" if no lines are visible) 7341 v In Visual mode: the start of the Visual area (the 7342 cursor is the end). When not in Visual mode 7343 returns the cursor position. Differs from |'<| in 7344 that it's updated right away. 7345 Note that a mark in another file can be used. The line number 7346 then applies to another buffer. 7347 To get the column number use |col()|. To get both use 7348 |getpos()|. 7349 With the optional {winid} argument the values are obtained for 7350 that window instead of the current window. 7351 Examples: > 7352 line(".") line number of the cursor 7353 line(".", winid) idem, in window "winid" 7354 line("'t") line number of mark t 7355 line("'" . marker) line number of mark marker 7356< 7357 To jump to the last known position when opening a file see 7358 |last-position-jump|. 7359 7360 Can also be used as a |method|: > 7361 GetValue()->line() 7362 7363line2byte({lnum}) *line2byte()* 7364 Return the byte count from the start of the buffer for line 7365 {lnum}. This includes the end-of-line character, depending on 7366 the 'fileformat' option for the current buffer. The first 7367 line returns 1. 'encoding' matters, 'fileencoding' is ignored. 7368 This can also be used to get the byte count for the line just 7369 below the last line: > 7370 line2byte(line("$") + 1) 7371< This is the buffer size plus one. If 'fileencoding' is empty 7372 it is the file size plus one. {lnum} is used like with 7373 |getline()|. When {lnum} is invalid, or the |+byte_offset| 7374 feature has been disabled at compile time, -1 is returned. 7375 Also see |byte2line()|, |go| and |:goto|. 7376 7377 Can also be used as a |method|: > 7378 GetLnum()->line2byte() 7379 7380lispindent({lnum}) *lispindent()* 7381 Get the amount of indent for line {lnum} according the lisp 7382 indenting rules, as with 'lisp'. 7383 The indent is counted in spaces, the value of 'tabstop' is 7384 relevant. {lnum} is used just like in |getline()|. 7385 When {lnum} is invalid or Vim was not compiled the 7386 |+lispindent| feature, -1 is returned. 7387 7388 Can also be used as a |method|: > 7389 GetLnum()->lispindent() 7390 7391list2blob({list}) *list2blob()* 7392 Return a Blob concatenating all the number values in {list}. 7393 Examples: > 7394 list2blob([1, 2, 3, 4]) returns 0z01020304 7395 list2blob([]) returns 0z 7396< Returns an empty Blob on error. If one of the numbers is 7397 negative or more than 255 error *E1239* is given. 7398 7399 |blob2list()| does the opposite. 7400 7401 Can also be used as a |method|: > 7402 GetList()->list2blob() 7403 7404list2str({list} [, {utf8}]) *list2str()* 7405 Convert each number in {list} to a character string can 7406 concatenate them all. Examples: > 7407 list2str([32]) returns " " 7408 list2str([65, 66, 67]) returns "ABC" 7409< The same can be done (slowly) with: > 7410 join(map(list, {nr, val -> nr2char(val)}), '') 7411< |str2list()| does the opposite. 7412 7413 When {utf8} is omitted or zero, the current 'encoding' is used. 7414 When {utf8} is TRUE, always return UTF-8 characters. 7415 With UTF-8 composing characters work as expected: > 7416 list2str([97, 769]) returns "á" 7417< 7418 Can also be used as a |method|: > 7419 GetList()->list2str() 7420 7421listener_add({callback} [, {buf}]) *listener_add()* 7422 Add a callback function that will be invoked when changes have 7423 been made to buffer {buf}. 7424 {buf} refers to a buffer name or number. For the accepted 7425 values, see |bufname()|. When {buf} is omitted the current 7426 buffer is used. 7427 Returns a unique ID that can be passed to |listener_remove()|. 7428 7429 The {callback} is invoked with five arguments: 7430 a:bufnr the buffer that was changed 7431 a:start first changed line number 7432 a:end first line number below the change 7433 a:added number of lines added, negative if lines were 7434 deleted 7435 a:changes a List of items with details about the changes 7436 7437 Example: > 7438 func Listener(bufnr, start, end, added, changes) 7439 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed' 7440 endfunc 7441 call listener_add('Listener', bufnr) 7442 7443< The List cannot be changed. Each item in a:changes is a 7444 dictionary with these entries: 7445 lnum the first line number of the change 7446 end the first line below the change 7447 added number of lines added; negative if lines were 7448 deleted 7449 col first column in "lnum" that was affected by 7450 the change; one if unknown or the whole line 7451 was affected; this is a byte index, first 7452 character has a value of one. 7453 When lines are inserted the values are: 7454 lnum line above which the new line is added 7455 end equal to "lnum" 7456 added number of lines inserted 7457 col 1 7458 When lines are deleted the values are: 7459 lnum the first deleted line 7460 end the line below the first deleted line, before 7461 the deletion was done 7462 added negative, number of lines deleted 7463 col 1 7464 When lines are changed: 7465 lnum the first changed line 7466 end the line below the last changed line 7467 added 0 7468 col first column with a change or 1 7469 7470 The entries are in the order the changes were made, thus the 7471 most recent change is at the end. The line numbers are valid 7472 when the callback is invoked, but later changes may make them 7473 invalid, thus keeping a copy for later might not work. 7474 7475 The {callback} is invoked just before the screen is updated, 7476 when |listener_flush()| is called or when a change is being 7477 made that changes the line count in a way it causes a line 7478 number in the list of changes to become invalid. 7479 7480 The {callback} is invoked with the text locked, see 7481 |textlock|. If you do need to make changes to the buffer, use 7482 a timer to do this later |timer_start()|. 7483 7484 The {callback} is not invoked when the buffer is first loaded. 7485 Use the |BufReadPost| autocmd event to handle the initial text 7486 of a buffer. 7487 The {callback} is also not invoked when the buffer is 7488 unloaded, use the |BufUnload| autocmd event for that. 7489 7490 Can also be used as a |method|, the base is passed as the 7491 second argument: > 7492 GetBuffer()->listener_add(callback) 7493 7494listener_flush([{buf}]) *listener_flush()* 7495 Invoke listener callbacks for buffer {buf}. If there are no 7496 pending changes then no callbacks are invoked. 7497 7498 {buf} refers to a buffer name or number. For the accepted 7499 values, see |bufname()|. When {buf} is omitted the current 7500 buffer is used. 7501 7502 Can also be used as a |method|: > 7503 GetBuffer()->listener_flush() 7504 7505listener_remove({id}) *listener_remove()* 7506 Remove a listener previously added with listener_add(). 7507 Returns FALSE when {id} could not be found, TRUE when {id} was 7508 removed. 7509 7510 Can also be used as a |method|: > 7511 GetListenerId()->listener_remove() 7512 7513localtime() *localtime()* 7514 Return the current time, measured as seconds since 1st Jan 7515 1970. See also |strftime()|, |strptime()| and |getftime()|. 7516 7517 7518log({expr}) *log()* 7519 Return the natural logarithm (base e) of {expr} as a |Float|. 7520 {expr} must evaluate to a |Float| or a |Number| in the range 7521 (0, inf]. 7522 Examples: > 7523 :echo log(10) 7524< 2.302585 > 7525 :echo log(exp(5)) 7526< 5.0 7527 7528 Can also be used as a |method|: > 7529 Compute()->log() 7530< 7531 {only available when compiled with the |+float| feature} 7532 7533 7534log10({expr}) *log10()* 7535 Return the logarithm of Float {expr} to base 10 as a |Float|. 7536 {expr} must evaluate to a |Float| or a |Number|. 7537 Examples: > 7538 :echo log10(1000) 7539< 3.0 > 7540 :echo log10(0.01) 7541< -2.0 7542 7543 Can also be used as a |method|: > 7544 Compute()->log10() 7545< 7546 {only available when compiled with the |+float| feature} 7547 7548luaeval({expr} [, {expr}]) *luaeval()* 7549 Evaluate Lua expression {expr} and return its result converted 7550 to Vim data structures. Second {expr} may hold additional 7551 argument accessible as _A inside first {expr}. 7552 Strings are returned as they are. 7553 Boolean objects are converted to numbers. 7554 Numbers are converted to |Float| values if vim was compiled 7555 with |+float| and to numbers otherwise. 7556 Dictionaries and lists obtained by vim.eval() are returned 7557 as-is. 7558 Other objects are returned as zero without any errors. 7559 See |lua-luaeval| for more details. 7560 Note that in a `:def` function local variables are not visible 7561 to {expr}. 7562 7563 Can also be used as a |method|: > 7564 GetExpr()->luaeval() 7565 7566< {only available when compiled with the |+lua| feature} 7567 7568map({expr1}, {expr2}) *map()* 7569 {expr1} must be a |List|, |Blob| or |Dictionary|. 7570 Replace each item in {expr1} with the result of evaluating 7571 {expr2}. For a |Blob| each byte is replaced. 7572 If the item type changes you may want to use |mapnew()| to 7573 create a new List or Dictionary. This is required when using 7574 Vim9 script. 7575 7576 {expr2} must be a |string| or |Funcref|. 7577 7578 If {expr2} is a |string|, inside {expr2} |v:val| has the value 7579 of the current item. For a |Dictionary| |v:key| has the key 7580 of the current item and for a |List| |v:key| has the index of 7581 the current item. For a |Blob| |v:key| has the index of the 7582 current byte. 7583 Example: > 7584 :call map(mylist, '"> " . v:val . " <"') 7585< This puts "> " before and " <" after each item in "mylist". 7586 7587 Note that {expr2} is the result of an expression and is then 7588 used as an expression again. Often it is good to use a 7589 |literal-string| to avoid having to double backslashes. You 7590 still have to double ' quotes 7591 7592 If {expr2} is a |Funcref| it is called with two arguments: 7593 1. The key or the index of the current item. 7594 2. the value of the current item. 7595 The function must return the new value of the item. Example 7596 that changes each value by "key-value": > 7597 func KeyValue(key, val) 7598 return a:key . '-' . a:val 7599 endfunc 7600 call map(myDict, function('KeyValue')) 7601< It is shorter when using a |lambda|: > 7602 call map(myDict, {key, val -> key . '-' . val}) 7603< If you do not use "val" you can leave it out: > 7604 call map(myDict, {key -> 'item: ' . key}) 7605< If you do not use "key" you can use a short name: > 7606 call map(myDict, {_, val -> 'item: ' . val}) 7607< 7608 The operation is done in-place. If you want a |List| or 7609 |Dictionary| to remain unmodified make a copy first: > 7610 :let tlist = map(copy(mylist), ' v:val . "\t"') 7611 7612< Returns {expr1}, the |List|, |Blob| or |Dictionary| that was 7613 filtered. When an error is encountered while evaluating 7614 {expr2} no further items in {expr1} are processed. When 7615 {expr2} is a Funcref errors inside a function are ignored, 7616 unless it was defined with the "abort" flag. 7617 7618 Can also be used as a |method|: > 7619 mylist->map(expr2) 7620 7621 7622maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* 7623 When {dict} is omitted or zero: Return the rhs of mapping 7624 {name} in mode {mode}. The returned String has special 7625 characters translated like in the output of the ":map" command 7626 listing. 7627 7628 When there is no mapping for {name}, an empty String is 7629 returned. When the mapping for {name} is empty, then "<Nop>" 7630 is returned. 7631 7632 The {name} can have special key names, like in the ":map" 7633 command. 7634 7635 {mode} can be one of these strings: 7636 "n" Normal 7637 "v" Visual (including Select) 7638 "o" Operator-pending 7639 "i" Insert 7640 "c" Cmd-line 7641 "s" Select 7642 "x" Visual 7643 "l" langmap |language-mapping| 7644 "t" Terminal-Job 7645 "" Normal, Visual and Operator-pending 7646 When {mode} is omitted, the modes for "" are used. 7647 7648 When {abbr} is there and it is |TRUE| use abbreviations 7649 instead of mappings. 7650 7651 When {dict} is there and it is |TRUE| return a dictionary 7652 containing all the information of the mapping with the 7653 following items: 7654 "lhs" The {lhs} of the mapping as it would be typed 7655 "lhsraw" The {lhs} of the mapping as raw bytes 7656 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate 7657 form, only present when it differs from "lhsraw" 7658 "rhs" The {rhs} of the mapping as typed. 7659 "silent" 1 for a |:map-silent| mapping, else 0. 7660 "noremap" 1 if the {rhs} of the mapping is not remappable. 7661 "script" 1 if mapping was defined with <script>. 7662 "expr" 1 for an expression mapping (|:map-<expr>|). 7663 "buffer" 1 for a buffer local mapping (|:map-local|). 7664 "mode" Modes for which the mapping is defined. In 7665 addition to the modes mentioned above, these 7666 characters will be used: 7667 " " Normal, Visual and Operator-pending 7668 "!" Insert and Commandline mode 7669 (|mapmode-ic|) 7670 "sid" The script local ID, used for <sid> mappings 7671 (|<SID>|). 7672 "lnum" The line number in "sid", zero if unknown. 7673 "nowait" Do not wait for other, longer mappings. 7674 (|:map-<nowait>|). 7675 7676 The dictionary can be used to restore a mapping with 7677 |mapset()|. 7678 7679 The mappings local to the current buffer are checked first, 7680 then the global mappings. 7681 This function can be used to map a key even when it's already 7682 mapped, and have it do the original mapping too. Sketch: > 7683 exe 'nnoremap <Tab> ==' . maparg('<Tab>', 'n') 7684 7685< Can also be used as a |method|: > 7686 GetKey()->maparg('n') 7687 7688mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()* 7689 Check if there is a mapping that matches with {name} in mode 7690 {mode}. See |maparg()| for {mode} and special names in 7691 {name}. 7692 When {abbr} is there and it is |TRUE| use abbreviations 7693 instead of mappings. 7694 A match happens with a mapping that starts with {name} and 7695 with a mapping which is equal to the start of {name}. 7696 7697 matches mapping "a" "ab" "abc" ~ 7698 mapcheck("a") yes yes yes 7699 mapcheck("abc") yes yes yes 7700 mapcheck("ax") yes no no 7701 mapcheck("b") no no no 7702 7703 The difference with maparg() is that mapcheck() finds a 7704 mapping that matches with {name}, while maparg() only finds a 7705 mapping for {name} exactly. 7706 When there is no mapping that starts with {name}, an empty 7707 String is returned. If there is one, the RHS of that mapping 7708 is returned. If there are several mappings that start with 7709 {name}, the RHS of one of them is returned. This will be 7710 "<Nop>" if the RHS is empty. 7711 The mappings local to the current buffer are checked first, 7712 then the global mappings. 7713 This function can be used to check if a mapping can be added 7714 without being ambiguous. Example: > 7715 :if mapcheck("_vv") == "" 7716 : map _vv :set guifont=7x13<CR> 7717 :endif 7718< This avoids adding the "_vv" mapping when there already is a 7719 mapping for "_v" or for "_vvv". 7720 7721 Can also be used as a |method|: > 7722 GetKey()->mapcheck('n') 7723 7724 7725mapnew({expr1}, {expr2}) *mapnew()* 7726 Like |map()| but instead of replacing items in {expr1} a new 7727 List or Dictionary is created and returned. {expr1} remains 7728 unchanged. Items can still be changed by {expr2}, if you 7729 don't want that use |deepcopy()| first. 7730 7731 7732mapset({mode}, {abbr}, {dict}) *mapset()* 7733 Restore a mapping from a dictionary returned by |maparg()|. 7734 {mode} and {abbr} should be the same as for the call to 7735 |maparg()|. *E460* 7736 {mode} is used to define the mode in which the mapping is set, 7737 not the "mode" entry in {dict}. 7738 Example for saving and restoring a mapping: > 7739 let save_map = maparg('K', 'n', 0, 1) 7740 nnoremap K somethingelse 7741 ... 7742 call mapset('n', 0, save_map) 7743< Note that if you are going to replace a map in several modes, 7744 e.g. with `:map!`, you need to save the mapping for all of 7745 them, since they can differ. 7746 7747 7748match({expr}, {pat} [, {start} [, {count}]]) *match()* 7749 When {expr} is a |List| then this returns the index of the 7750 first item where {pat} matches. Each item is used as a 7751 String, |Lists| and |Dictionaries| are used as echoed. 7752 7753 Otherwise, {expr} is used as a String. The result is a 7754 Number, which gives the index (byte offset) in {expr} where 7755 {pat} matches. 7756 7757 A match at the first character or |List| item returns zero. 7758 If there is no match -1 is returned. 7759 7760 For getting submatches see |matchlist()|. 7761 Example: > 7762 :echo match("testing", "ing") " results in 4 7763 :echo match([1, 'x'], '\a') " results in 1 7764< See |string-match| for how {pat} is used. 7765 *strpbrk()* 7766 Vim doesn't have a strpbrk() function. But you can do: > 7767 :let sepidx = match(line, '[.,;: \t]') 7768< *strcasestr()* 7769 Vim doesn't have a strcasestr() function. But you can add 7770 "\c" to the pattern to ignore case: > 7771 :let idx = match(haystack, '\cneedle') 7772< 7773 If {start} is given, the search starts from byte index 7774 {start} in a String or item {start} in a |List|. 7775 The result, however, is still the index counted from the 7776 first character/item. Example: > 7777 :echo match("testing", "ing", 2) 7778< result is again "4". > 7779 :echo match("testing", "ing", 4) 7780< result is again "4". > 7781 :echo match("testing", "t", 2) 7782< result is "3". 7783 For a String, if {start} > 0 then it is like the string starts 7784 {start} bytes later, thus "^" will match at {start}. Except 7785 when {count} is given, then it's like matches before the 7786 {start} byte are ignored (this is a bit complicated to keep it 7787 backwards compatible). 7788 For a String, if {start} < 0, it will be set to 0. For a list 7789 the index is counted from the end. 7790 If {start} is out of range ({start} > strlen({expr}) for a 7791 String or {start} > len({expr}) for a |List|) -1 is returned. 7792 7793 When {count} is given use the {count}'th match. When a match 7794 is found in a String the search for the next one starts one 7795 character further. Thus this example results in 1: > 7796 echo match("testing", "..", 0, 2) 7797< In a |List| the search continues in the next item. 7798 Note that when {count} is added the way {start} works changes, 7799 see above. 7800 7801 See |pattern| for the patterns that are accepted. 7802 The 'ignorecase' option is used to set the ignore-caseness of 7803 the pattern. 'smartcase' is NOT used. The matching is always 7804 done like 'magic' is set and 'cpoptions' is empty. 7805 Note that a match at the start is preferred, thus when the 7806 pattern is using "*" (any number of matches) it tends to find 7807 zero matches at the start instead of a number of matches 7808 further down in the text. 7809 7810 Can also be used as a |method|: > 7811 GetText()->match('word') 7812 GetList()->match('word') 7813< 7814 *matchadd()* *E798* *E799* *E801* *E957* 7815matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) 7816 Defines a pattern to be highlighted in the current window (a 7817 "match"). It will be highlighted with {group}. Returns an 7818 identification number (ID), which can be used to delete the 7819 match using |matchdelete()|. The ID is bound to the window. 7820 Matching is case sensitive and magic, unless case sensitivity 7821 or magicness are explicitly overridden in {pattern}. The 7822 'magic', 'smartcase' and 'ignorecase' options are not used. 7823 The "Conceal" value is special, it causes the match to be 7824 concealed. 7825 7826 The optional {priority} argument assigns a priority to the 7827 match. A match with a high priority will have its 7828 highlighting overrule that of a match with a lower priority. 7829 A priority is specified as an integer (negative numbers are no 7830 exception). If the {priority} argument is not specified, the 7831 default priority is 10. The priority of 'hlsearch' is zero, 7832 hence all matches with a priority greater than zero will 7833 overrule it. Syntax highlighting (see 'syntax') is a separate 7834 mechanism, and regardless of the chosen priority a match will 7835 always overrule syntax highlighting. 7836 7837 The optional {id} argument allows the request for a specific 7838 match ID. If a specified ID is already taken, an error 7839 message will appear and the match will not be added. An ID 7840 is specified as a positive integer (zero excluded). IDs 1, 2 7841 and 3 are reserved for |:match|, |:2match| and |:3match|, 7842 respectively. If the {id} argument is not specified or -1, 7843 |matchadd()| automatically chooses a free ID. 7844 7845 The optional {dict} argument allows for further custom 7846 values. Currently this is used to specify a match specific 7847 conceal character that will be shown for |hl-Conceal| 7848 highlighted matches. The dict can have the following members: 7849 7850 conceal Special character to show instead of the 7851 match (only for |hl-Conceal| highlighted 7852 matches, see |:syn-cchar|) 7853 window Instead of the current window use the 7854 window with this number or window ID. 7855 7856 The number of matches is not limited, as it is the case with 7857 the |:match| commands. 7858 7859 Example: > 7860 :highlight MyGroup ctermbg=green guibg=green 7861 :let m = matchadd("MyGroup", "TODO") 7862< Deletion of the pattern: > 7863 :call matchdelete(m) 7864 7865< A list of matches defined by |matchadd()| and |:match| are 7866 available from |getmatches()|. All matches can be deleted in 7867 one operation by |clearmatches()|. 7868 7869 Can also be used as a |method|: > 7870 GetGroup()->matchadd('TODO') 7871< 7872 *matchaddpos()* 7873matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) 7874 Same as |matchadd()|, but requires a list of positions {pos} 7875 instead of a pattern. This command is faster than |matchadd()| 7876 because it does not require to handle regular expressions and 7877 sets buffer line boundaries to redraw screen. It is supposed 7878 to be used when fast match additions and deletions are 7879 required, for example to highlight matching parentheses. 7880 7881 {pos} is a list of positions. Each position can be one of 7882 these: 7883 - A number. This whole line will be highlighted. The first 7884 line has number 1. 7885 - A list with one number, e.g., [23]. The whole line with this 7886 number will be highlighted. 7887 - A list with two numbers, e.g., [23, 11]. The first number is 7888 the line number, the second one is the column number (first 7889 column is 1, the value must correspond to the byte index as 7890 |col()| would return). The character at this position will 7891 be highlighted. 7892 - A list with three numbers, e.g., [23, 11, 3]. As above, but 7893 the third number gives the length of the highlight in bytes. 7894 7895 The maximum number of positions in {pos} is 8. 7896 7897 Example: > 7898 :highlight MyGroup ctermbg=green guibg=green 7899 :let m = matchaddpos("MyGroup", [[23, 24], 34]) 7900< Deletion of the pattern: > 7901 :call matchdelete(m) 7902 7903< Matches added by |matchaddpos()| are returned by 7904 |getmatches()|. 7905 7906 Can also be used as a |method|: > 7907 GetGroup()->matchaddpos([23, 11]) 7908 7909matcharg({nr}) *matcharg()* 7910 Selects the {nr} match item, as set with a |:match|, 7911 |:2match| or |:3match| command. 7912 Return a |List| with two elements: 7913 The name of the highlight group used 7914 The pattern used. 7915 When {nr} is not 1, 2 or 3 returns an empty |List|. 7916 When there is no match item set returns ['', '']. 7917 This is useful to save and restore a |:match|. 7918 Highlighting matches using the |:match| commands are limited 7919 to three matches. |matchadd()| does not have this limitation. 7920 7921 Can also be used as a |method|: > 7922 GetMatch()->matcharg() 7923 7924matchdelete({id} [, {win}) *matchdelete()* *E802* *E803* 7925 Deletes a match with ID {id} previously defined by |matchadd()| 7926 or one of the |:match| commands. Returns 0 if successful, 7927 otherwise -1. See example for |matchadd()|. All matches can 7928 be deleted in one operation by |clearmatches()|. 7929 If {win} is specified, use the window with this number or 7930 window ID instead of the current window. 7931 7932 Can also be used as a |method|: > 7933 GetMatch()->matchdelete() 7934 7935matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()* 7936 Same as |match()|, but return the index of first character 7937 after the match. Example: > 7938 :echo matchend("testing", "ing") 7939< results in "7". 7940 *strspn()* *strcspn()* 7941 Vim doesn't have a strspn() or strcspn() function, but you can 7942 do it with matchend(): > 7943 :let span = matchend(line, '[a-zA-Z]') 7944 :let span = matchend(line, '[^a-zA-Z]') 7945< Except that -1 is returned when there are no matches. 7946 7947 The {start}, if given, has the same meaning as for |match()|. > 7948 :echo matchend("testing", "ing", 2) 7949< results in "7". > 7950 :echo matchend("testing", "ing", 5) 7951< result is "-1". 7952 When {expr} is a |List| the result is equal to |match()|. 7953 7954 Can also be used as a |method|: > 7955 GetText()->matchend('word') 7956 7957 7958matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()* 7959 If {list} is a list of strings, then returns a |List| with all 7960 the strings in {list} that fuzzy match {str}. The strings in 7961 the returned list are sorted based on the matching score. 7962 7963 The optional {dict} argument always supports the following 7964 items: 7965 matchseq When this item is present and {str} contains 7966 multiple words separated by white space, then 7967 returns only matches that contain the words in 7968 the given sequence. 7969 7970 If {list} is a list of dictionaries, then the optional {dict} 7971 argument supports the following additional items: 7972 key key of the item which is fuzzy matched against 7973 {str}. The value of this item should be a 7974 string. 7975 text_cb |Funcref| that will be called for every item 7976 in {list} to get the text for fuzzy matching. 7977 This should accept a dictionary item as the 7978 argument and return the text for that item to 7979 use for fuzzy matching. 7980 7981 {str} is treated as a literal string and regular expression 7982 matching is NOT supported. The maximum supported {str} length 7983 is 256. 7984 7985 When {str} has multiple words each separated by white space, 7986 then the list of strings that have all the words is returned. 7987 7988 If there are no matching strings or there is an error, then an 7989 empty list is returned. If length of {str} is greater than 7990 256, then returns an empty list. 7991 7992 Refer to |fuzzy-match| for more information about fuzzy 7993 matching strings. 7994 7995 Example: > 7996 :echo matchfuzzy(["clay", "crow"], "cay") 7997< results in ["clay"]. > 7998 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl") 7999< results in a list of buffer names fuzzy matching "ndl". > 8000 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'}) 8001< results in a list of buffer information dicts with buffer 8002 names fuzzy matching "ndl". > 8003 :echo getbufinfo()->matchfuzzy("spl", 8004 \ {'text_cb' : {v -> v.name}}) 8005< results in a list of buffer information dicts with buffer 8006 names fuzzy matching "spl". > 8007 :echo v:oldfiles->matchfuzzy("test") 8008< results in a list of file names fuzzy matching "test". > 8009 :let l = readfile("buffer.c")->matchfuzzy("str") 8010< results in a list of lines in "buffer.c" fuzzy matching "str". > 8011 :echo ['one two', 'two one']->matchfuzzy('two one') 8012< results in ['two one', 'one two']. > 8013 :echo ['one two', 'two one']->matchfuzzy('two one', 8014 \ {'matchseq': 1}) 8015< results in ['two one']. 8016 8017matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()* 8018 Same as |matchfuzzy()|, but returns the list of matched 8019 strings, the list of character positions where characters 8020 in {str} matches and a list of matching scores. You can 8021 use |byteidx()| to convert a character position to a byte 8022 position. 8023 8024 If {str} matches multiple times in a string, then only the 8025 positions for the best match is returned. 8026 8027 If there are no matching strings or there is an error, then a 8028 list with three empty list items is returned. 8029 8030 Example: > 8031 :echo matchfuzzypos(['testing'], 'tsg') 8032< results in [['testing'], [[0, 2, 6]], [99]] > 8033 :echo matchfuzzypos(['clay', 'lacy'], 'la') 8034< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] > 8035 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'}) 8036< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]] 8037 8038matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()* 8039 Same as |match()|, but return a |List|. The first item in the 8040 list is the matched string, same as what matchstr() would 8041 return. Following items are submatches, like "\1", "\2", etc. 8042 in |:substitute|. When an optional submatch didn't match an 8043 empty string is used. Example: > 8044 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)') 8045< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] 8046 When there is no match an empty list is returned. 8047 8048 You can pass in a List, but that is not very useful. 8049 8050 Can also be used as a |method|: > 8051 GetText()->matchlist('word') 8052 8053matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()* 8054 Same as |match()|, but return the matched string. Example: > 8055 :echo matchstr("testing", "ing") 8056< results in "ing". 8057 When there is no match "" is returned. 8058 The {start}, if given, has the same meaning as for |match()|. > 8059 :echo matchstr("testing", "ing", 2) 8060< results in "ing". > 8061 :echo matchstr("testing", "ing", 5) 8062< result is "". 8063 When {expr} is a |List| then the matching item is returned. 8064 The type isn't changed, it's not necessarily a String. 8065 8066 Can also be used as a |method|: > 8067 GetText()->matchstr('word') 8068 8069matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()* 8070 Same as |matchstr()|, but return the matched string, the start 8071 position and the end position of the match. Example: > 8072 :echo matchstrpos("testing", "ing") 8073< results in ["ing", 4, 7]. 8074 When there is no match ["", -1, -1] is returned. 8075 The {start}, if given, has the same meaning as for |match()|. > 8076 :echo matchstrpos("testing", "ing", 2) 8077< results in ["ing", 4, 7]. > 8078 :echo matchstrpos("testing", "ing", 5) 8079< result is ["", -1, -1]. 8080 When {expr} is a |List| then the matching item, the index 8081 of first item where {pat} matches, the start position and the 8082 end position of the match are returned. > 8083 :echo matchstrpos([1, '__x'], '\a') 8084< result is ["x", 1, 2, 3]. 8085 The type isn't changed, it's not necessarily a String. 8086 8087 Can also be used as a |method|: > 8088 GetText()->matchstrpos('word') 8089< 8090 8091 *max()* 8092max({expr}) Return the maximum value of all items in {expr}. Example: > 8093 echo max([apples, pears, oranges]) 8094 8095< {expr} can be a |List| or a |Dictionary|. For a Dictionary, 8096 it returns the maximum of all values in the Dictionary. 8097 If {expr} is neither a List nor a Dictionary, or one of the 8098 items in {expr} cannot be used as a Number this results in 8099 an error. An empty |List| or |Dictionary| results in zero. 8100 8101 Can also be used as a |method|: > 8102 mylist->max() 8103 8104 8105menu_info({name} [, {mode}]) *menu_info()* 8106 Return information about the specified menu {name} in 8107 mode {mode}. The menu name should be specified without the 8108 shortcut character ('&'). If {name} is "", then the top-level 8109 menu names are returned. 8110 8111 {mode} can be one of these strings: 8112 "n" Normal 8113 "v" Visual (including Select) 8114 "o" Operator-pending 8115 "i" Insert 8116 "c" Cmd-line 8117 "s" Select 8118 "x" Visual 8119 "t" Terminal-Job 8120 "" Normal, Visual and Operator-pending 8121 "!" Insert and Cmd-line 8122 When {mode} is omitted, the modes for "" are used. 8123 8124 Returns a |Dictionary| containing the following items: 8125 accel menu item accelerator text |menu-text| 8126 display display name (name without '&') 8127 enabled v:true if this menu item is enabled 8128 Refer to |:menu-enable| 8129 icon name of the icon file (for toolbar) 8130 |toolbar-icon| 8131 iconidx index of a built-in icon 8132 modes modes for which the menu is defined. In 8133 addition to the modes mentioned above, these 8134 characters will be used: 8135 " " Normal, Visual and Operator-pending 8136 name menu item name. 8137 noremenu v:true if the {rhs} of the menu item is not 8138 remappable else v:false. 8139 priority menu order priority |menu-priority| 8140 rhs right-hand-side of the menu item. The returned 8141 string has special characters translated like 8142 in the output of the ":menu" command listing. 8143 When the {rhs} of a menu item is empty, then 8144 "<Nop>" is returned. 8145 script v:true if script-local remapping of {rhs} is 8146 allowed else v:false. See |:menu-script|. 8147 shortcut shortcut key (character after '&' in 8148 the menu name) |menu-shortcut| 8149 silent v:true if the menu item is created 8150 with <silent> argument |:menu-silent| 8151 submenus |List| containing the names of 8152 all the submenus. Present only if the menu 8153 item has submenus. 8154 8155 Returns an empty dictionary if the menu item is not found. 8156 8157 Examples: > 8158 :echo menu_info('Edit.Cut') 8159 :echo menu_info('File.Save', 'n') 8160 8161 " Display the entire menu hierarchy in a buffer 8162 func ShowMenu(name, pfx) 8163 let m = menu_info(a:name) 8164 call append(line('$'), a:pfx .. m.display) 8165 for child in m->get('submenus', []) 8166 call ShowMenu(a:name .. '.' .. escape(child, '.'), 8167 \ a:pfx .. ' ') 8168 endfor 8169 endfunc 8170 new 8171 for topmenu in menu_info('').submenus 8172 call ShowMenu(topmenu, '') 8173 endfor 8174< 8175 Can also be used as a |method|: > 8176 GetMenuName()->menu_info('v') 8177 8178 8179< *min()* 8180min({expr}) Return the minimum value of all items in {expr}. Example: > 8181 echo min([apples, pears, oranges]) 8182 8183< {expr} can be a |List| or a |Dictionary|. For a Dictionary, 8184 it returns the minimum of all values in the Dictionary. 8185 If {expr} is neither a List nor a Dictionary, or one of the 8186 items in {expr} cannot be used as a Number this results in 8187 an error. An empty |List| or |Dictionary| results in zero. 8188 8189 Can also be used as a |method|: > 8190 mylist->min() 8191 8192< *mkdir()* *E739* 8193mkdir({name} [, {path} [, {prot}]]) 8194 Create directory {name}. 8195 8196 If {path} is "p" then intermediate directories are created as 8197 necessary. Otherwise it must be "". 8198 8199 If {prot} is given it is used to set the protection bits of 8200 the new directory. The default is 0o755 (rwxr-xr-x: r/w for 8201 the user, readable for others). Use 0o700 to make it 8202 unreadable for others. This is only used for the last part of 8203 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be 8204 created with 0o755. 8205 Example: > 8206 :call mkdir($HOME . "/tmp/foo/bar", "p", 0o700) 8207 8208< This function is not available in the |sandbox|. 8209 8210 There is no error if the directory already exists and the "p" 8211 flag is passed (since patch 8.0.1708). However, without the 8212 "p" option the call will fail. 8213 8214 The function result is a Number, which is TRUE if the call was 8215 successful or FALSE if the directory creation failed or partly 8216 failed. 8217 8218 Not available on all systems. To check use: > 8219 :if exists("*mkdir") 8220 8221< Can also be used as a |method|: > 8222 GetName()->mkdir() 8223< 8224 *mode()* 8225mode([expr]) Return a string that indicates the current mode. 8226 If [expr] is supplied and it evaluates to a non-zero Number or 8227 a non-empty String (|non-zero-arg|), then the full mode is 8228 returned, otherwise only the first letter is returned. 8229 Also see |state()|. 8230 8231 n Normal 8232 no Operator-pending 8233 nov Operator-pending (forced characterwise |o_v|) 8234 noV Operator-pending (forced linewise |o_V|) 8235 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|); 8236 CTRL-V is one character 8237 niI Normal using |i_CTRL-O| in |Insert-mode| 8238 niR Normal using |i_CTRL-O| in |Replace-mode| 8239 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode| 8240 nt Terminal-Normal (insert goes to Terminal-Job mode) 8241 v Visual by character 8242 vs Visual by character using |v_CTRL-O| in Select mode 8243 V Visual by line 8244 Vs Visual by line using |v_CTRL-O| in Select mode 8245 CTRL-V Visual blockwise 8246 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode 8247 s Select by character 8248 S Select by line 8249 CTRL-S Select blockwise 8250 i Insert 8251 ic Insert mode completion |compl-generic| 8252 ix Insert mode |i_CTRL-X| completion 8253 R Replace |R| 8254 Rc Replace mode completion |compl-generic| 8255 Rx Replace mode |i_CTRL-X| completion 8256 Rv Virtual Replace |gR| 8257 Rvc Virtual Replace mode completion |compl-generic| 8258 Rvx Virtual Replace mode |i_CTRL-X| completion 8259 c Command-line editing 8260 cv Vim Ex mode |gQ| 8261 ce Normal Ex mode |Q| 8262 r Hit-enter prompt 8263 rm The -- more -- prompt 8264 r? A |:confirm| query of some sort 8265 ! Shell or external command is executing 8266 t Terminal-Job mode: keys go to the job 8267 8268 This is useful in the 'statusline' option or when used 8269 with |remote_expr()| In most other places it always returns 8270 "c" or "n". 8271 Note that in the future more modes and more specific modes may 8272 be added. It's better not to compare the whole string but only 8273 the leading character(s). 8274 Also see |visualmode()|. 8275 8276 Can also be used as a |method|: > 8277 DoFull()->mode() 8278 8279mzeval({expr}) *mzeval()* 8280 Evaluate MzScheme expression {expr} and return its result 8281 converted to Vim data structures. 8282 Numbers and strings are returned as they are. 8283 Pairs (including lists and improper lists) and vectors are 8284 returned as Vim |Lists|. 8285 Hash tables are represented as Vim |Dictionary| type with keys 8286 converted to strings. 8287 All other types are converted to string with display function. 8288 Examples: > 8289 :mz (define l (list 1 2 3)) 8290 :mz (define h (make-hash)) (hash-set! h "list" l) 8291 :echo mzeval("l") 8292 :echo mzeval("h") 8293< 8294 Note that in a `:def` function local variables are not visible 8295 to {expr}. 8296 8297 Can also be used as a |method|: > 8298 GetExpr()->mzeval() 8299< 8300 {only available when compiled with the |+mzscheme| feature} 8301 8302nextnonblank({lnum}) *nextnonblank()* 8303 Return the line number of the first line at or below {lnum} 8304 that is not blank. Example: > 8305 if getline(nextnonblank(1)) =~ "Java" 8306< When {lnum} is invalid or there is no non-blank line at or 8307 below it, zero is returned. 8308 {lnum} is used like with |getline()|. 8309 See also |prevnonblank()|. 8310 8311 Can also be used as a |method|: > 8312 GetLnum()->nextnonblank() 8313 8314nr2char({expr} [, {utf8}]) *nr2char()* 8315 Return a string with a single character, which has the number 8316 value {expr}. Examples: > 8317 nr2char(64) returns "@" 8318 nr2char(32) returns " " 8319< When {utf8} is omitted or zero, the current 'encoding' is used. 8320 Example for "utf-8": > 8321 nr2char(300) returns I with bow character 8322< When {utf8} is TRUE, always return UTF-8 characters. 8323 Note that a NUL character in the file is specified with 8324 nr2char(10), because NULs are represented with newline 8325 characters. nr2char(0) is a real NUL and terminates the 8326 string, thus results in an empty string. 8327 To turn a list of character numbers into a string: > 8328 let list = [65, 66, 67] 8329 let str = join(map(list, {_, val -> nr2char(val)}), '') 8330< Result: "ABC" 8331 8332 Can also be used as a |method|: > 8333 GetNumber()->nr2char() 8334 8335or({expr}, {expr}) *or()* 8336 Bitwise OR on the two arguments. The arguments are converted 8337 to a number. A List, Dict or Float argument causes an error. 8338 Example: > 8339 :let bits = or(bits, 0x80) 8340< Can also be used as a |method|: > 8341 :let bits = bits->or(0x80) 8342 8343 8344pathshorten({path} [, {len}]) *pathshorten()* 8345 Shorten directory names in the path {path} and return the 8346 result. The tail, the file name, is kept as-is. The other 8347 components in the path are reduced to {len} letters in length. 8348 If {len} is omitted or smaller than 1 then 1 is used (single 8349 letters). Leading '~' and '.' characters are kept. Examples: > 8350 :echo pathshorten('~/.vim/autoload/myfile.vim') 8351< ~/.v/a/myfile.vim ~ 8352> 8353 :echo pathshorten('~/.vim/autoload/myfile.vim', 2) 8354< ~/.vi/au/myfile.vim ~ 8355 It doesn't matter if the path exists or not. 8356 8357 Can also be used as a |method|: > 8358 GetDirectories()->pathshorten() 8359 8360perleval({expr}) *perleval()* 8361 Evaluate Perl expression {expr} in scalar context and return 8362 its result converted to Vim data structures. If value can't be 8363 converted, it is returned as a string Perl representation. 8364 Note: If you want an array or hash, {expr} must return a 8365 reference to it. 8366 Example: > 8367 :echo perleval('[1 .. 4]') 8368< [1, 2, 3, 4] 8369 8370 Note that in a `:def` function local variables are not visible 8371 to {expr}. 8372 8373 Can also be used as a |method|: > 8374 GetExpr()->perleval() 8375 8376< {only available when compiled with the |+perl| feature} 8377 8378 8379popup_ functions are documented here: |popup-functions| 8380 8381 8382pow({x}, {y}) *pow()* 8383 Return the power of {x} to the exponent {y} as a |Float|. 8384 {x} and {y} must evaluate to a |Float| or a |Number|. 8385 Examples: > 8386 :echo pow(3, 3) 8387< 27.0 > 8388 :echo pow(2, 16) 8389< 65536.0 > 8390 :echo pow(32, 0.20) 8391< 2.0 8392 8393 Can also be used as a |method|: > 8394 Compute()->pow(3) 8395< 8396 {only available when compiled with the |+float| feature} 8397 8398prevnonblank({lnum}) *prevnonblank()* 8399 Return the line number of the first line at or above {lnum} 8400 that is not blank. Example: > 8401 let ind = indent(prevnonblank(v:lnum - 1)) 8402< When {lnum} is invalid or there is no non-blank line at or 8403 above it, zero is returned. 8404 {lnum} is used like with |getline()|. 8405 Also see |nextnonblank()|. 8406 8407 Can also be used as a |method|: > 8408 GetLnum()->prevnonblank() 8409 8410printf({fmt}, {expr1} ...) *printf()* 8411 Return a String with {fmt}, where "%" items are replaced by 8412 the formatted form of their respective arguments. Example: > 8413 printf("%4d: E%d %.30s", lnum, errno, msg) 8414< May result in: 8415 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ 8416 8417 When used as a |method| the base is passed as the second 8418 argument: > 8419 Compute()->printf("result: %d") 8420 8421< Often used items are: 8422 %s string 8423 %6S string right-aligned in 6 display cells 8424 %6s string right-aligned in 6 bytes 8425 %.9s string truncated to 9 bytes 8426 %c single byte 8427 %d decimal number 8428 %5d decimal number padded with spaces to 5 characters 8429 %x hex number 8430 %04x hex number padded with zeros to at least 4 characters 8431 %X hex number using upper case letters 8432 %o octal number 8433 %08b binary number padded with zeros to at least 8 chars 8434 %f floating point number as 12.23, inf, -inf or nan 8435 %F floating point number as 12.23, INF, -INF or NAN 8436 %e floating point number as 1.23e3, inf, -inf or nan 8437 %E floating point number as 1.23E3, INF, -INF or NAN 8438 %g floating point number, as %f or %e depending on value 8439 %G floating point number, as %F or %E depending on value 8440 %% the % character itself 8441 8442 Conversion specifications start with '%' and end with the 8443 conversion type. All other characters are copied unchanged to 8444 the result. 8445 8446 The "%" starts a conversion specification. The following 8447 arguments appear in sequence: 8448 8449 % [flags] [field-width] [.precision] type 8450 8451 flags 8452 Zero or more of the following flags: 8453 8454 # The value should be converted to an "alternate 8455 form". For c, d, and s conversions, this option 8456 has no effect. For o conversions, the precision 8457 of the number is increased to force the first 8458 character of the output string to a zero (except 8459 if a zero value is printed with an explicit 8460 precision of zero). 8461 For b and B conversions, a non-zero result has 8462 the string "0b" (or "0B" for B conversions) 8463 prepended to it. 8464 For x and X conversions, a non-zero result has 8465 the string "0x" (or "0X" for X conversions) 8466 prepended to it. 8467 8468 0 (zero) Zero padding. For all conversions the converted 8469 value is padded on the left with zeros rather 8470 than blanks. If a precision is given with a 8471 numeric conversion (d, b, B, o, x, and X), the 0 8472 flag is ignored. 8473 8474 - A negative field width flag; the converted value 8475 is to be left adjusted on the field boundary. 8476 The converted value is padded on the right with 8477 blanks, rather than on the left with blanks or 8478 zeros. A - overrides a 0 if both are given. 8479 8480 ' ' (space) A blank should be left before a positive 8481 number produced by a signed conversion (d). 8482 8483 + A sign must always be placed before a number 8484 produced by a signed conversion. A + overrides 8485 a space if both are used. 8486 8487 field-width 8488 An optional decimal digit string specifying a minimum 8489 field width. If the converted value has fewer bytes 8490 than the field width, it will be padded with spaces on 8491 the left (or right, if the left-adjustment flag has 8492 been given) to fill out the field width. 8493 8494 .precision 8495 An optional precision, in the form of a period '.' 8496 followed by an optional digit string. If the digit 8497 string is omitted, the precision is taken as zero. 8498 This gives the minimum number of digits to appear for 8499 d, o, x, and X conversions, or the maximum number of 8500 bytes to be printed from a string for s conversions. 8501 For floating point it is the number of digits after 8502 the decimal point. 8503 8504 type 8505 A character that specifies the type of conversion to 8506 be applied, see below. 8507 8508 A field width or precision, or both, may be indicated by an 8509 asterisk '*' instead of a digit string. In this case, a 8510 Number argument supplies the field width or precision. A 8511 negative field width is treated as a left adjustment flag 8512 followed by a positive field width; a negative precision is 8513 treated as though it were missing. Example: > 8514 :echo printf("%d: %.*s", nr, width, line) 8515< This limits the length of the text used from "line" to 8516 "width" bytes. 8517 8518 The conversion specifiers and their meanings are: 8519 8520 *printf-d* *printf-b* *printf-B* *printf-o* 8521 *printf-x* *printf-X* 8522 dbBoxX The Number argument is converted to signed decimal 8523 (d), unsigned binary (b and B), unsigned octal (o), or 8524 unsigned hexadecimal (x and X) notation. The letters 8525 "abcdef" are used for x conversions; the letters 8526 "ABCDEF" are used for X conversions. 8527 The precision, if any, gives the minimum number of 8528 digits that must appear; if the converted value 8529 requires fewer digits, it is padded on the left with 8530 zeros. 8531 In no case does a non-existent or small field width 8532 cause truncation of a numeric field; if the result of 8533 a conversion is wider than the field width, the field 8534 is expanded to contain the conversion result. 8535 The 'h' modifier indicates the argument is 16 bits. 8536 The 'l' modifier indicates the argument is 32 bits. 8537 The 'L' modifier indicates the argument is 64 bits. 8538 Generally, these modifiers are not useful. They are 8539 ignored when type is known from the argument. 8540 8541 i alias for d 8542 D alias for ld 8543 U alias for lu 8544 O alias for lo 8545 8546 *printf-c* 8547 c The Number argument is converted to a byte, and the 8548 resulting character is written. 8549 8550 *printf-s* 8551 s The text of the String argument is used. If a 8552 precision is specified, no more bytes than the number 8553 specified are used. 8554 If the argument is not a String type, it is 8555 automatically converted to text with the same format 8556 as ":echo". 8557 *printf-S* 8558 S The text of the String argument is used. If a 8559 precision is specified, no more display cells than the 8560 number specified are used. 8561 8562 *printf-f* *E807* 8563 f F The Float argument is converted into a string of the 8564 form 123.456. The precision specifies the number of 8565 digits after the decimal point. When the precision is 8566 zero the decimal point is omitted. When the precision 8567 is not specified 6 is used. A really big number 8568 (out of range or dividing by zero) results in "inf" 8569 or "-inf" with %f (INF or -INF with %F). 8570 "0.0 / 0.0" results in "nan" with %f (NAN with %F). 8571 Example: > 8572 echo printf("%.2f", 12.115) 8573< 12.12 8574 Note that roundoff depends on the system libraries. 8575 Use |round()| when in doubt. 8576 8577 *printf-e* *printf-E* 8578 e E The Float argument is converted into a string of the 8579 form 1.234e+03 or 1.234E+03 when using 'E'. The 8580 precision specifies the number of digits after the 8581 decimal point, like with 'f'. 8582 8583 *printf-g* *printf-G* 8584 g G The Float argument is converted like with 'f' if the 8585 value is between 0.001 (inclusive) and 10000000.0 8586 (exclusive). Otherwise 'e' is used for 'g' and 'E' 8587 for 'G'. When no precision is specified superfluous 8588 zeroes and '+' signs are removed, except for the zero 8589 immediately after the decimal point. Thus 10000000.0 8590 results in 1.0e7. 8591 8592 *printf-%* 8593 % A '%' is written. No argument is converted. The 8594 complete conversion specification is "%%". 8595 8596 When a Number argument is expected a String argument is also 8597 accepted and automatically converted. 8598 When a Float or String argument is expected a Number argument 8599 is also accepted and automatically converted. 8600 Any other argument type results in an error message. 8601 8602 *E766* *E767* 8603 The number of {exprN} arguments must exactly match the number 8604 of "%" items. If there are not sufficient or too many 8605 arguments an error is given. Up to 18 arguments can be used. 8606 8607 8608prompt_getprompt({buf}) *prompt_getprompt()* 8609 Returns the effective prompt text for buffer {buf}. {buf} can 8610 be a buffer name or number. See |prompt-buffer|. 8611 8612 If the buffer doesn't exist or isn't a prompt buffer, an empty 8613 string is returned. 8614 8615 Can also be used as a |method|: > 8616 GetBuffer()->prompt_getprompt() 8617 8618< {only available when compiled with the |+channel| feature} 8619 8620 8621prompt_setcallback({buf}, {expr}) *prompt_setcallback()* 8622 Set prompt callback for buffer {buf} to {expr}. When {expr} 8623 is an empty string the callback is removed. This has only 8624 effect if {buf} has 'buftype' set to "prompt". 8625 8626 The callback is invoked when pressing Enter. The current 8627 buffer will always be the prompt buffer. A new line for a 8628 prompt is added before invoking the callback, thus the prompt 8629 for which the callback was invoked will be in the last but one 8630 line. 8631 If the callback wants to add text to the buffer, it must 8632 insert it above the last line, since that is where the current 8633 prompt is. This can also be done asynchronously. 8634 The callback is invoked with one argument, which is the text 8635 that was entered at the prompt. This can be an empty string 8636 if the user only typed Enter. 8637 Example: > 8638 call prompt_setcallback(bufnr(), function('s:TextEntered')) 8639 func s:TextEntered(text) 8640 if a:text == 'exit' || a:text == 'quit' 8641 stopinsert 8642 close 8643 else 8644 call append(line('$') - 1, 'Entered: "' . a:text . '"') 8645 " Reset 'modified' to allow the buffer to be closed. 8646 set nomodified 8647 endif 8648 endfunc 8649 8650< Can also be used as a |method|: > 8651 GetBuffer()->prompt_setcallback(callback) 8652 8653< {only available when compiled with the |+channel| feature} 8654 8655prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()* 8656 Set a callback for buffer {buf} to {expr}. When {expr} is an 8657 empty string the callback is removed. This has only effect if 8658 {buf} has 'buftype' set to "prompt". 8659 8660 This callback will be invoked when pressing CTRL-C in Insert 8661 mode. Without setting a callback Vim will exit Insert mode, 8662 as in any buffer. 8663 8664 Can also be used as a |method|: > 8665 GetBuffer()->prompt_setinterrupt(callback) 8666 8667< {only available when compiled with the |+channel| feature} 8668 8669prompt_setprompt({buf}, {text}) *prompt_setprompt()* 8670 Set prompt for buffer {buf} to {text}. You most likely want 8671 {text} to end in a space. 8672 The result is only visible if {buf} has 'buftype' set to 8673 "prompt". Example: > 8674 call prompt_setprompt(bufnr(), 'command: ') 8675< 8676 Can also be used as a |method|: > 8677 GetBuffer()->prompt_setprompt('command: ') 8678 8679< {only available when compiled with the |+channel| feature} 8680 8681prop_ functions are documented here: |text-prop-functions| 8682 8683pum_getpos() *pum_getpos()* 8684 If the popup menu (see |ins-completion-menu|) is not visible, 8685 returns an empty |Dictionary|, otherwise, returns a 8686 |Dictionary| with the following keys: 8687 height nr of items visible 8688 width screen cells 8689 row top screen row (0 first row) 8690 col leftmost screen column (0 first col) 8691 size total nr of items 8692 scrollbar |TRUE| if scrollbar is visible 8693 8694 The values are the same as in |v:event| during 8695 |CompleteChanged|. 8696 8697pumvisible() *pumvisible()* 8698 Returns non-zero when the popup menu is visible, zero 8699 otherwise. See |ins-completion-menu|. 8700 This can be used to avoid some things that would remove the 8701 popup menu. 8702 8703py3eval({expr}) *py3eval()* 8704 Evaluate Python expression {expr} and return its result 8705 converted to Vim data structures. 8706 Numbers and strings are returned as they are (strings are 8707 copied though, Unicode strings are additionally converted to 8708 'encoding'). 8709 Lists are represented as Vim |List| type. 8710 Dictionaries are represented as Vim |Dictionary| type with 8711 keys converted to strings. 8712 Note that in a `:def` function local variables are not visible 8713 to {expr}. 8714 8715 Can also be used as a |method|: > 8716 GetExpr()->py3eval() 8717 8718< {only available when compiled with the |+python3| feature} 8719 8720 *E858* *E859* 8721pyeval({expr}) *pyeval()* 8722 Evaluate Python expression {expr} and return its result 8723 converted to Vim data structures. 8724 Numbers and strings are returned as they are (strings are 8725 copied though). 8726 Lists are represented as Vim |List| type. 8727 Dictionaries are represented as Vim |Dictionary| type, 8728 non-string keys result in error. 8729 Note that in a `:def` function local variables are not visible 8730 to {expr}. 8731 8732 Can also be used as a |method|: > 8733 GetExpr()->pyeval() 8734 8735< {only available when compiled with the |+python| feature} 8736 8737pyxeval({expr}) *pyxeval()* 8738 Evaluate Python expression {expr} and return its result 8739 converted to Vim data structures. 8740 Uses Python 2 or 3, see |python_x| and 'pyxversion'. 8741 See also: |pyeval()|, |py3eval()| 8742 8743 Can also be used as a |method|: > 8744 GetExpr()->pyxeval() 8745 8746< {only available when compiled with the |+python| or the 8747 |+python3| feature} 8748 8749rand([{expr}]) *rand()* *random* 8750 Return a pseudo-random Number generated with an xoshiro128** 8751 algorithm using seed {expr}. The returned number is 32 bits, 8752 also on 64 bits systems, for consistency. 8753 {expr} can be initialized by |srand()| and will be updated by 8754 rand(). If {expr} is omitted, an internal seed value is used 8755 and updated. 8756 8757 Examples: > 8758 :echo rand() 8759 :let seed = srand() 8760 :echo rand(seed) 8761 :echo rand(seed) % 16 " random number 0 - 15 8762< 8763 8764 *E726* *E727* 8765range({expr} [, {max} [, {stride}]]) *range()* 8766 Returns a |List| with Numbers: 8767 - If only {expr} is specified: [0, 1, ..., {expr} - 1] 8768 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}] 8769 - If {stride} is specified: [{expr}, {expr} + {stride}, ..., 8770 {max}] (increasing {expr} with {stride} each time, not 8771 producing a value past {max}). 8772 When the maximum is one before the start the result is an 8773 empty list. When the maximum is more than one before the 8774 start this is an error. 8775 Examples: > 8776 range(4) " [0, 1, 2, 3] 8777 range(2, 4) " [2, 3, 4] 8778 range(2, 9, 3) " [2, 5, 8] 8779 range(2, -2, -1) " [2, 1, 0, -1, -2] 8780 range(0) " [] 8781 range(2, 0) " error! 8782< 8783 Can also be used as a |method|: > 8784 GetExpr()->range() 8785< 8786 8787readblob({fname}) *readblob()* 8788 Read file {fname} in binary mode and return a |Blob|. 8789 When the file can't be opened an error message is given and 8790 the result is an empty |Blob|. 8791 Also see |readfile()| and |writefile()|. 8792 8793 8794readdir({directory} [, {expr} [, {dict}]]) *readdir()* 8795 Return a list with file and directory names in {directory}. 8796 You can also use |glob()| if you don't need to do complicated 8797 things, such as limiting the number of matches. 8798 The list will be sorted (case sensitive), see the {dict} 8799 argument below for changing the sort order. 8800 8801 When {expr} is omitted all entries are included. 8802 When {expr} is given, it is evaluated to check what to do: 8803 If {expr} results in -1 then no further entries will 8804 be handled. 8805 If {expr} results in 0 then this entry will not be 8806 added to the list. 8807 If {expr} results in 1 then this entry will be added 8808 to the list. 8809 The entries "." and ".." are always excluded. 8810 Each time {expr} is evaluated |v:val| is set to the entry name. 8811 When {expr} is a function the name is passed as the argument. 8812 For example, to get a list of files ending in ".txt": > 8813 readdir(dirname, {n -> n =~ '.txt$'}) 8814< To skip hidden and backup files: > 8815 readdir(dirname, {n -> n !~ '^\.\|\~$'}) 8816 8817< The optional {dict} argument allows for further custom 8818 values. Currently this is used to specify if and how sorting 8819 should be performed. The dict can have the following members: 8820 8821 sort How to sort the result returned from the system. 8822 Valid values are: 8823 "none" do not sort (fastest method) 8824 "case" sort case sensitive (byte value of 8825 each character, technically, using 8826 strcmp()) (default) 8827 "icase" sort case insensitive (technically 8828 using strcasecmp()) 8829 "collate" sort using the collation order 8830 of the "POSIX" or "C" |locale| 8831 (technically using strcoll()) 8832 Other values are silently ignored. 8833 8834 For example, to get a list of all files in the current 8835 directory without sorting the individual entries: > 8836 readdir('.', '1', #{sort: 'none'}) 8837< If you want to get a directory tree: > 8838 function! s:tree(dir) 8839 return {a:dir : map(readdir(a:dir), 8840 \ {_, x -> isdirectory(x) ? 8841 \ {x : s:tree(a:dir . '/' . x)} : x})} 8842 endfunction 8843 echo s:tree(".") 8844< 8845 Can also be used as a |method|: > 8846 GetDirName()->readdir() 8847< 8848readdirex({directory} [, {expr} [, {dict}]]) *readdirex()* 8849 Extended version of |readdir()|. 8850 Return a list of Dictionaries with file and directory 8851 information in {directory}. 8852 This is useful if you want to get the attributes of file and 8853 directory at the same time as getting a list of a directory. 8854 This is much faster than calling |readdir()| then calling 8855 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for 8856 each file and directory especially on MS-Windows. 8857 The list will by default be sorted by name (case sensitive), 8858 the sorting can be changed by using the optional {dict} 8859 argument, see |readdir()|. 8860 8861 The Dictionary for file and directory information has the 8862 following items: 8863 group Group name of the entry. (Only on Unix) 8864 name Name of the entry. 8865 perm Permissions of the entry. See |getfperm()|. 8866 size Size of the entry. See |getfsize()|. 8867 time Timestamp of the entry. See |getftime()|. 8868 type Type of the entry. 8869 On Unix, almost same as |getftype()| except: 8870 Symlink to a dir "linkd" 8871 Other symlink "link" 8872 On MS-Windows: 8873 Normal file "file" 8874 Directory "dir" 8875 Junction "junction" 8876 Symlink to a dir "linkd" 8877 Other symlink "link" 8878 Other reparse point "reparse" 8879 user User name of the entry's owner. (Only on Unix) 8880 On Unix, if the entry is a symlink, the Dictionary includes 8881 the information of the target (except the "type" item). 8882 On MS-Windows, it includes the information of the symlink 8883 itself because of performance reasons. 8884 8885 When {expr} is omitted all entries are included. 8886 When {expr} is given, it is evaluated to check what to do: 8887 If {expr} results in -1 then no further entries will 8888 be handled. 8889 If {expr} results in 0 then this entry will not be 8890 added to the list. 8891 If {expr} results in 1 then this entry will be added 8892 to the list. 8893 The entries "." and ".." are always excluded. 8894 Each time {expr} is evaluated |v:val| is set to a |Dictionary| 8895 of the entry. 8896 When {expr} is a function the entry is passed as the argument. 8897 For example, to get a list of files ending in ".txt": > 8898 readdirex(dirname, {e -> e.name =~ '.txt$'}) 8899< 8900 For example, to get a list of all files in the current 8901 directory without sorting the individual entries: > 8902 readdirex(dirname, '1', #{sort: 'none'}) 8903 8904< 8905 Can also be used as a |method|: > 8906 GetDirName()->readdirex() 8907< 8908 8909 *readfile()* 8910readfile({fname} [, {type} [, {max}]]) 8911 Read file {fname} and return a |List|, each line of the file 8912 as an item. Lines are broken at NL characters. Macintosh 8913 files separated with CR will result in a single long line 8914 (unless a NL appears somewhere). 8915 All NUL characters are replaced with a NL character. 8916 When {type} contains "b" binary mode is used: 8917 - When the last line ends in a NL an extra empty list item is 8918 added. 8919 - No CR characters are removed. 8920 Otherwise: 8921 - CR characters that appear before a NL are removed. 8922 - Whether the last line ends in a NL or not does not matter. 8923 - When 'encoding' is Unicode any UTF-8 byte order mark is 8924 removed from the text. 8925 When {max} is given this specifies the maximum number of lines 8926 to be read. Useful if you only want to check the first ten 8927 lines of a file: > 8928 :for line in readfile(fname, '', 10) 8929 : if line =~ 'Date' | echo line | endif 8930 :endfor 8931< When {max} is negative -{max} lines from the end of the file 8932 are returned, or as many as there are. 8933 When {max} is zero the result is an empty list. 8934 Note that without {max} the whole file is read into memory. 8935 Also note that there is no recognition of encoding. Read a 8936 file into a buffer if you need to. 8937 Deprecated (use |readblob()| instead): When {type} contains 8938 "B" a |Blob| is returned with the binary data of the file 8939 unmodified. 8940 When the file can't be opened an error message is given and 8941 the result is an empty list. 8942 Also see |writefile()|. 8943 8944 Can also be used as a |method|: > 8945 GetFileName()->readfile() 8946 8947reduce({object}, {func} [, {initial}]) *reduce()* *E998* 8948 {func} is called for every item in {object}, which can be a 8949 |List| or a |Blob|. {func} is called with two arguments: the 8950 result so far and current item. After processing all items 8951 the result is returned. 8952 8953 {initial} is the initial result. When omitted, the first item 8954 in {object} is used and {func} is first called for the second 8955 item. If {initial} is not given and {object} is empty no 8956 result can be computed, an E998 error is given. 8957 8958 Examples: > 8959 echo reduce([1, 3, 5], { acc, val -> acc + val }) 8960 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a') 8961 echo reduce(0z1122, { acc, val -> 2 * acc + val }) 8962< 8963 Can also be used as a |method|: > 8964 echo mylist->reduce({ acc, val -> acc + val }, 0) 8965 8966 8967reg_executing() *reg_executing()* 8968 Returns the single letter name of the register being executed. 8969 Returns an empty string when no register is being executed. 8970 See |@|. 8971 8972reg_recording() *reg_recording()* 8973 Returns the single letter name of the register being recorded. 8974 Returns an empty string when not recording. See |q|. 8975 8976reltime([{start} [, {end}]]) *reltime()* 8977 Return an item that represents a time value. The item is a 8978 list with items that depend on the system. In Vim 9 script 8979 list<any> can be used. 8980 The item can be passed to |reltimestr()| to convert it to a 8981 string or |reltimefloat()| to convert to a Float. 8982 8983 Without an argument reltime() returns the current time. 8984 With one argument is returns the time passed since the time 8985 specified in the argument. 8986 With two arguments it returns the time passed between {start} 8987 and {end}. 8988 8989 The {start} and {end} arguments must be values returned by 8990 reltime(). If there is an error zero is returned in legacy 8991 script, in Vim9 script an error is given. 8992 8993 Can also be used as a |method|: > 8994 GetStart()->reltime() 8995< 8996 {only available when compiled with the |+reltime| feature} 8997 8998reltimefloat({time}) *reltimefloat()* 8999 Return a Float that represents the time value of {time}. 9000 Example: > 9001 let start = reltime() 9002 call MyFunction() 9003 let seconds = reltimefloat(reltime(start)) 9004< See the note of reltimestr() about overhead. 9005 Also see |profiling|. 9006 If there is an error 0.0 is returned in legacy script, in Vim9 9007 script an error is given. 9008 9009 Can also be used as a |method|: > 9010 reltime(start)->reltimefloat() 9011 9012< {only available when compiled with the |+reltime| feature} 9013 9014reltimestr({time}) *reltimestr()* 9015 Return a String that represents the time value of {time}. 9016 This is the number of seconds, a dot and the number of 9017 microseconds. Example: > 9018 let start = reltime() 9019 call MyFunction() 9020 echo reltimestr(reltime(start)) 9021< Note that overhead for the commands will be added to the time. 9022 The accuracy depends on the system. 9023 Leading spaces are used to make the string align nicely. You 9024 can use split() to remove it. > 9025 echo split(reltimestr(reltime(start)))[0] 9026< Also see |profiling|. 9027 If there is an error an empty string is returned in legacy 9028 script, in Vim9 script an error is given. 9029 9030 Can also be used as a |method|: > 9031 reltime(start)->reltimestr() 9032 9033< {only available when compiled with the |+reltime| feature} 9034 9035 *remote_expr()* *E449* 9036remote_expr({server}, {string} [, {idvar} [, {timeout}]]) 9037 Send the {string} to {server}. The string is sent as an 9038 expression and the result is returned after evaluation. 9039 The result must be a String or a |List|. A |List| is turned 9040 into a String by joining the items with a line break in 9041 between (not at the end), like with join(expr, "\n"). 9042 If {idvar} is present and not empty, it is taken as the name 9043 of a variable and a {serverid} for later use with 9044 |remote_read()| is stored there. 9045 If {timeout} is given the read times out after this many 9046 seconds. Otherwise a timeout of 600 seconds is used. 9047 See also |clientserver| |RemoteReply|. 9048 This function is not available in the |sandbox|. 9049 {only available when compiled with the |+clientserver| feature} 9050 Note: Any errors will cause a local error message to be issued 9051 and the result will be the empty string. 9052 9053 Variables will be evaluated in the global namespace, 9054 independent of a function currently being active. Except 9055 when in debug mode, then local function variables and 9056 arguments can be evaluated. 9057 9058 Examples: > 9059 :echo remote_expr("gvim", "2+2") 9060 :echo remote_expr("gvim1", "b:current_syntax") 9061< 9062 Can also be used as a |method|: > 9063 ServerName()->remote_expr(expr) 9064 9065remote_foreground({server}) *remote_foreground()* 9066 Move the Vim server with the name {server} to the foreground. 9067 The {server} argument is a string. 9068 This works like: > 9069 remote_expr({server}, "foreground()") 9070< Except that on Win32 systems the client does the work, to work 9071 around the problem that the OS doesn't always allow the server 9072 to bring itself to the foreground. 9073 Note: This does not restore the window if it was minimized, 9074 like foreground() does. 9075 This function is not available in the |sandbox|. 9076 9077 Can also be used as a |method|: > 9078 ServerName()->remote_foreground() 9079 9080< {only in the Win32, Athena, Motif and GTK GUI versions and the 9081 Win32 console version} 9082 9083 9084remote_peek({serverid} [, {retvar}]) *remote_peek()* 9085 Returns a positive number if there are available strings 9086 from {serverid}. Copies any reply string into the variable 9087 {retvar} if specified. {retvar} must be a string with the 9088 name of a variable. 9089 Returns zero if none are available. 9090 Returns -1 if something is wrong. 9091 See also |clientserver|. 9092 This function is not available in the |sandbox|. 9093 {only available when compiled with the |+clientserver| feature} 9094 Examples: > 9095 :let repl = "" 9096 :echo "PEEK: ".remote_peek(id, "repl").": ".repl 9097 9098< Can also be used as a |method|: > 9099 ServerId()->remote_peek() 9100 9101remote_read({serverid}, [{timeout}]) *remote_read()* 9102 Return the oldest available reply from {serverid} and consume 9103 it. Unless a {timeout} in seconds is given, it blocks until a 9104 reply is available. 9105 See also |clientserver|. 9106 This function is not available in the |sandbox|. 9107 {only available when compiled with the |+clientserver| feature} 9108 Example: > 9109 :echo remote_read(id) 9110 9111< Can also be used as a |method|: > 9112 ServerId()->remote_read() 9113< 9114 *remote_send()* *E241* 9115remote_send({server}, {string} [, {idvar}]) 9116 Send the {string} to {server}. The string is sent as input 9117 keys and the function returns immediately. At the Vim server 9118 the keys are not mapped |:map|. 9119 If {idvar} is present, it is taken as the name of a variable 9120 and a {serverid} for later use with remote_read() is stored 9121 there. 9122 See also |clientserver| |RemoteReply|. 9123 This function is not available in the |sandbox|. 9124 {only available when compiled with the |+clientserver| feature} 9125 9126 Note: Any errors will be reported in the server and may mess 9127 up the display. 9128 Examples: > 9129 :echo remote_send("gvim", ":DropAndReply ".file, "serverid"). 9130 \ remote_read(serverid) 9131 9132 :autocmd NONE RemoteReply * 9133 \ echo remote_read(expand("<amatch>")) 9134 :echo remote_send("gvim", ":sleep 10 | echo ". 9135 \ 'server2client(expand("<client>"), "HELLO")<CR>') 9136< 9137 Can also be used as a |method|: > 9138 ServerName()->remote_send(keys) 9139< 9140 *remote_startserver()* *E941* *E942* 9141remote_startserver({name}) 9142 Become the server {name}. This fails if already running as a 9143 server, when |v:servername| is not empty. 9144 9145 Can also be used as a |method|: > 9146 ServerName()->remote_startserver() 9147 9148< {only available when compiled with the |+clientserver| feature} 9149 9150remove({list}, {idx} [, {end}]) *remove()* 9151 Without {end}: Remove the item at {idx} from |List| {list} and 9152 return the item. 9153 With {end}: Remove items from {idx} to {end} (inclusive) and 9154 return a |List| with these items. When {idx} points to the same 9155 item as {end} a list with one item is returned. When {end} 9156 points to an item before {idx} this is an error. 9157 See |list-index| for possible values of {idx} and {end}. 9158 Example: > 9159 :echo "last item: " . remove(mylist, -1) 9160 :call remove(mylist, 0, 9) 9161< 9162 Use |delete()| to remove a file. 9163 9164 Can also be used as a |method|: > 9165 mylist->remove(idx) 9166 9167remove({blob}, {idx} [, {end}]) 9168 Without {end}: Remove the byte at {idx} from |Blob| {blob} and 9169 return the byte. 9170 With {end}: Remove bytes from {idx} to {end} (inclusive) and 9171 return a |Blob| with these bytes. When {idx} points to the same 9172 byte as {end} a |Blob| with one byte is returned. When {end} 9173 points to a byte before {idx} this is an error. 9174 Example: > 9175 :echo "last byte: " . remove(myblob, -1) 9176 :call remove(mylist, 0, 9) 9177 9178remove({dict}, {key}) 9179 Remove the entry from {dict} with key {key} and return it. 9180 Example: > 9181 :echo "removed " . remove(dict, "one") 9182< If there is no {key} in {dict} this is an error. 9183 9184rename({from}, {to}) *rename()* 9185 Rename the file by the name {from} to the name {to}. This 9186 should also work to move files across file systems. The 9187 result is a Number, which is 0 if the file was renamed 9188 successfully, and non-zero when the renaming failed. 9189 NOTE: If {to} exists it is overwritten without warning. 9190 This function is not available in the |sandbox|. 9191 9192 Can also be used as a |method|: > 9193 GetOldName()->rename(newname) 9194 9195repeat({expr}, {count}) *repeat()* 9196 Repeat {expr} {count} times and return the concatenated 9197 result. Example: > 9198 :let separator = repeat('-', 80) 9199< When {count} is zero or negative the result is empty. 9200 When {expr} is a |List| the result is {expr} concatenated 9201 {count} times. Example: > 9202 :let longlist = repeat(['a', 'b'], 3) 9203< Results in ['a', 'b', 'a', 'b', 'a', 'b']. 9204 9205 Can also be used as a |method|: > 9206 mylist->repeat(count) 9207 9208resolve({filename}) *resolve()* *E655* 9209 On MS-Windows, when {filename} is a shortcut (a .lnk file), 9210 returns the path the shortcut points to in a simplified form. 9211 When {filename} is a symbolic link or junction point, return 9212 the full path to the target. If the target of junction is 9213 removed, return {filename}. 9214 On Unix, repeat resolving symbolic links in all path 9215 components of {filename} and return the simplified result. 9216 To cope with link cycles, resolving of symbolic links is 9217 stopped after 100 iterations. 9218 On other systems, return the simplified {filename}. 9219 The simplification step is done as by |simplify()|. 9220 resolve() keeps a leading path component specifying the 9221 current directory (provided the result is still a relative 9222 path name) and also keeps a trailing path separator. 9223 9224 Can also be used as a |method|: > 9225 GetName()->resolve() 9226 9227reverse({object}) *reverse()* 9228 Reverse the order of items in {object} in-place. 9229 {object} can be a |List| or a |Blob|. 9230 Returns {object}. 9231 If you want an object to remain unmodified make a copy first: > 9232 :let revlist = reverse(copy(mylist)) 9233< Can also be used as a |method|: > 9234 mylist->reverse() 9235 9236round({expr}) *round()* 9237 Round off {expr} to the nearest integral value and return it 9238 as a |Float|. If {expr} lies halfway between two integral 9239 values, then use the larger one (away from zero). 9240 {expr} must evaluate to a |Float| or a |Number|. 9241 Examples: > 9242 echo round(0.456) 9243< 0.0 > 9244 echo round(4.5) 9245< 5.0 > 9246 echo round(-4.5) 9247< -5.0 9248 9249 Can also be used as a |method|: > 9250 Compute()->round() 9251< 9252 {only available when compiled with the |+float| feature} 9253 9254rubyeval({expr}) *rubyeval()* 9255 Evaluate Ruby expression {expr} and return its result 9256 converted to Vim data structures. 9257 Numbers, floats and strings are returned as they are (strings 9258 are copied though). 9259 Arrays are represented as Vim |List| type. 9260 Hashes are represented as Vim |Dictionary| type. 9261 Other objects are represented as strings resulted from their 9262 "Object#to_s" method. 9263 Note that in a `:def` function local variables are not visible 9264 to {expr}. 9265 9266 Can also be used as a |method|: > 9267 GetRubyExpr()->rubyeval() 9268 9269< {only available when compiled with the |+ruby| feature} 9270 9271screenattr({row}, {col}) *screenattr()* 9272 Like |screenchar()|, but return the attribute. This is a rather 9273 arbitrary number that can only be used to compare to the 9274 attribute at other positions. 9275 9276 Can also be used as a |method|: > 9277 GetRow()->screenattr(col) 9278 9279screenchar({row}, {col}) *screenchar()* 9280 The result is a Number, which is the character at position 9281 [row, col] on the screen. This works for every possible 9282 screen position, also status lines, window separators and the 9283 command line. The top left position is row one, column one 9284 The character excludes composing characters. For double-byte 9285 encodings it may only be the first byte. 9286 This is mainly to be used for testing. 9287 Returns -1 when row or col is out of range. 9288 9289 Can also be used as a |method|: > 9290 GetRow()->screenchar(col) 9291 9292screenchars({row}, {col}) *screenchars()* 9293 The result is a |List| of Numbers. The first number is the same 9294 as what |screenchar()| returns. Further numbers are 9295 composing characters on top of the base character. 9296 This is mainly to be used for testing. 9297 Returns an empty List when row or col is out of range. 9298 9299 Can also be used as a |method|: > 9300 GetRow()->screenchars(col) 9301 9302screencol() *screencol()* 9303 The result is a Number, which is the current screen column of 9304 the cursor. The leftmost column has number 1. 9305 This function is mainly used for testing. 9306 9307 Note: Always returns the current screen column, thus if used 9308 in a command (e.g. ":echo screencol()") it will return the 9309 column inside the command line, which is 1 when the command is 9310 executed. To get the cursor position in the file use one of 9311 the following mappings: > 9312 nnoremap <expr> GG ":echom ".screencol()."\n" 9313 nnoremap <silent> GG :echom screencol()<CR> 9314 nnoremap GG <Cmd>echom screencol()<CR> 9315< 9316screenpos({winid}, {lnum}, {col}) *screenpos()* 9317 The result is a Dict with the screen position of the text 9318 character in window {winid} at buffer line {lnum} and column 9319 {col}. {col} is a one-based byte index. 9320 The Dict has these members: 9321 row screen row 9322 col first screen column 9323 endcol last screen column 9324 curscol cursor screen column 9325 If the specified position is not visible, all values are zero. 9326 The "endcol" value differs from "col" when the character 9327 occupies more than one screen cell. E.g. for a Tab "col" can 9328 be 1 and "endcol" can be 8. 9329 The "curscol" value is where the cursor would be placed. For 9330 a Tab it would be the same as "endcol", while for a double 9331 width character it would be the same as "col". 9332 The |conceal| feature is ignored here, the column numbers are 9333 as if 'conceallevel' is zero. You can set the cursor to the 9334 right position and use |screencol()| to get the value with 9335 |conceal| taken into account. 9336 9337 Can also be used as a |method|: > 9338 GetWinid()->screenpos(lnum, col) 9339 9340screenrow() *screenrow()* 9341 The result is a Number, which is the current screen row of the 9342 cursor. The top line has number one. 9343 This function is mainly used for testing. 9344 Alternatively you can use |winline()|. 9345 9346 Note: Same restrictions as with |screencol()|. 9347 9348screenstring({row}, {col}) *screenstring()* 9349 The result is a String that contains the base character and 9350 any composing characters at position [row, col] on the screen. 9351 This is like |screenchars()| but returning a String with the 9352 characters. 9353 This is mainly to be used for testing. 9354 Returns an empty String when row or col is out of range. 9355 9356 Can also be used as a |method|: > 9357 GetRow()->screenstring(col) 9358< 9359 *search()* 9360search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) 9361 Search for regexp pattern {pattern}. The search starts at the 9362 cursor position (you can use |cursor()| to set it). 9363 9364 When a match has been found its line number is returned. 9365 If there is no match a 0 is returned and the cursor doesn't 9366 move. No error message is given. 9367 9368 {flags} is a String, which can contain these character flags: 9369 'b' search Backward instead of forward 9370 'c' accept a match at the Cursor position 9371 'e' move to the End of the match 9372 'n' do Not move the cursor 9373 'p' return number of matching sub-Pattern (see below) 9374 's' Set the ' mark at the previous location of the cursor 9375 'w' Wrap around the end of the file 9376 'W' don't Wrap around the end of the file 9377 'z' start searching at the cursor column instead of zero 9378 If neither 'w' or 'W' is given, the 'wrapscan' option applies. 9379 9380 If the 's' flag is supplied, the ' mark is set, only if the 9381 cursor is moved. The 's' flag cannot be combined with the 'n' 9382 flag. 9383 9384 'ignorecase', 'smartcase' and 'magic' are used. 9385 9386 When the 'z' flag is not given, forward searching always 9387 starts in column zero and then matches before the cursor are 9388 skipped. When the 'c' flag is present in 'cpo' the next 9389 search starts after the match. Without the 'c' flag the next 9390 search starts one column further. This matters for 9391 overlapping matches. 9392 When searching backwards and the 'z' flag is given then the 9393 search starts in column zero, thus no match in the current 9394 line will be found (unless wrapping around the end of the 9395 file). 9396 9397 When the {stopline} argument is given then the search stops 9398 after searching this line. This is useful to restrict the 9399 search to a range of lines. Examples: > 9400 let match = search('(', 'b', line("w0")) 9401 let end = search('END', '', line("w$")) 9402< When {stopline} is used and it is not zero this also implies 9403 that the search does not wrap around the end of the file. 9404 A zero value is equal to not giving the argument. 9405 9406 When the {timeout} argument is given the search stops when 9407 more than this many milliseconds have passed. Thus when 9408 {timeout} is 500 the search stops after half a second. 9409 The value must not be negative. A zero value is like not 9410 giving the argument. 9411 {only available when compiled with the |+reltime| feature} 9412 9413 If the {skip} expression is given it is evaluated with the 9414 cursor positioned on the start of a match. If it evaluates to 9415 non-zero this match is skipped. This can be used, for 9416 example, to skip a match in a comment or a string. 9417 {skip} can be a string, which is evaluated as an expression, a 9418 function reference or a lambda. 9419 When {skip} is omitted or empty, every match is accepted. 9420 When evaluating {skip} causes an error the search is aborted 9421 and -1 returned. 9422 *search()-sub-match* 9423 With the 'p' flag the returned value is one more than the 9424 first sub-match in \(\). One if none of them matched but the 9425 whole pattern did match. 9426 To get the column number too use |searchpos()|. 9427 9428 The cursor will be positioned at the match, unless the 'n' 9429 flag is used. 9430 9431 Example (goes over all files in the argument list): > 9432 :let n = 1 9433 :while n <= argc() " loop over all files in arglist 9434 : exe "argument " . n 9435 : " start at the last char in the file and wrap for the 9436 : " first search to find match at start of file 9437 : normal G$ 9438 : let flags = "w" 9439 : while search("foo", flags) > 0 9440 : s/foo/bar/g 9441 : let flags = "W" 9442 : endwhile 9443 : update " write the file if modified 9444 : let n = n + 1 9445 :endwhile 9446< 9447 Example for using some flags: > 9448 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe') 9449< This will search for the keywords "if", "else", and "endif" 9450 under or after the cursor. Because of the 'p' flag, it 9451 returns 1, 2, or 3 depending on which keyword is found, or 0 9452 if the search fails. With the cursor on the first word of the 9453 line: 9454 if (foo == 0) | let foo = foo + 1 | endif ~ 9455 the function returns 1. Without the 'c' flag, the function 9456 finds the "endif" and returns 3. The same thing happens 9457 without the 'e' flag if the cursor is on the "f" of "if". 9458 The 'n' flag tells the function not to move the cursor. 9459 9460 Can also be used as a |method|: > 9461 GetPattern()->search() 9462 9463searchcount([{options}]) *searchcount()* 9464 Get or update the last search count, like what is displayed 9465 without the "S" flag in 'shortmess'. This works even if 9466 'shortmess' does contain the "S" flag. 9467 9468 This returns a |Dictionary|. The dictionary is empty if the 9469 previous pattern was not set and "pattern" was not specified. 9470 9471 key type meaning ~ 9472 current |Number| current position of match; 9473 0 if the cursor position is 9474 before the first match 9475 exact_match |Boolean| 1 if "current" is matched on 9476 "pos", otherwise 0 9477 total |Number| total count of matches found 9478 incomplete |Number| 0: search was fully completed 9479 1: recomputing was timed out 9480 2: max count exceeded 9481 9482 For {options} see further down. 9483 9484 To get the last search count when |n| or |N| was pressed, call 9485 this function with `recompute: 0` . This sometimes returns 9486 wrong information because |n| and |N|'s maximum count is 99. 9487 If it exceeded 99 the result must be max count + 1 (100). If 9488 you want to get correct information, specify `recompute: 1`: > 9489 9490 " result == maxcount + 1 (100) when many matches 9491 let result = searchcount(#{recompute: 0}) 9492 9493 " Below returns correct result (recompute defaults 9494 " to 1) 9495 let result = searchcount() 9496< 9497 The function is useful to add the count to |statusline|: > 9498 function! LastSearchCount() abort 9499 let result = searchcount(#{recompute: 0}) 9500 if empty(result) 9501 return '' 9502 endif 9503 if result.incomplete ==# 1 " timed out 9504 return printf(' /%s [?/??]', @/) 9505 elseif result.incomplete ==# 2 " max count exceeded 9506 if result.total > result.maxcount && 9507 \ result.current > result.maxcount 9508 return printf(' /%s [>%d/>%d]', @/, 9509 \ result.current, result.total) 9510 elseif result.total > result.maxcount 9511 return printf(' /%s [%d/>%d]', @/, 9512 \ result.current, result.total) 9513 endif 9514 endif 9515 return printf(' /%s [%d/%d]', @/, 9516 \ result.current, result.total) 9517 endfunction 9518 let &statusline .= '%{LastSearchCount()}' 9519 9520 " Or if you want to show the count only when 9521 " 'hlsearch' was on 9522 " let &statusline .= 9523 " \ '%{v:hlsearch ? LastSearchCount() : ""}' 9524< 9525 You can also update the search count, which can be useful in a 9526 |CursorMoved| or |CursorMovedI| autocommand: > 9527 9528 autocmd CursorMoved,CursorMovedI * 9529 \ let s:searchcount_timer = timer_start( 9530 \ 200, function('s:update_searchcount')) 9531 function! s:update_searchcount(timer) abort 9532 if a:timer ==# s:searchcount_timer 9533 call searchcount(#{ 9534 \ recompute: 1, maxcount: 0, timeout: 100}) 9535 redrawstatus 9536 endif 9537 endfunction 9538< 9539 This can also be used to count matched texts with specified 9540 pattern in the current buffer using "pattern": > 9541 9542 " Count '\<foo\>' in this buffer 9543 " (Note that it also updates search count) 9544 let result = searchcount(#{pattern: '\<foo\>'}) 9545 9546 " To restore old search count by old pattern, 9547 " search again 9548 call searchcount() 9549< 9550 {options} must be a |Dictionary|. It can contain: 9551 key type meaning ~ 9552 recompute |Boolean| if |TRUE|, recompute the count 9553 like |n| or |N| was executed. 9554 otherwise returns the last 9555 computed result (when |n| or 9556 |N| was used when "S" is not 9557 in 'shortmess', or this 9558 function was called). 9559 (default: |TRUE|) 9560 pattern |String| recompute if this was given 9561 and different with |@/|. 9562 this works as same as the 9563 below command is executed 9564 before calling this function > 9565 let @/ = pattern 9566< (default: |@/|) 9567 timeout |Number| 0 or negative number is no 9568 timeout. timeout milliseconds 9569 for recomputing the result 9570 (default: 0) 9571 maxcount |Number| 0 or negative number is no 9572 limit. max count of matched 9573 text while recomputing the 9574 result. if search exceeded 9575 total count, "total" value 9576 becomes `maxcount + 1` 9577 (default: 99) 9578 pos |List| `[lnum, col, off]` value 9579 when recomputing the result. 9580 this changes "current" result 9581 value. see |cursor()|, 9582 |getpos()| 9583 (default: cursor's position) 9584 9585 Can also be used as a |method|: > 9586 GetSearchOpts()->searchcount() 9587< 9588searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()* 9589 Search for the declaration of {name}. 9590 9591 With a non-zero {global} argument it works like |gD|, find 9592 first match in the file. Otherwise it works like |gd|, find 9593 first match in the function. 9594 9595 With a non-zero {thisblock} argument matches in a {} block 9596 that ends before the cursor position are ignored. Avoids 9597 finding variable declarations only valid in another scope. 9598 9599 Moves the cursor to the found match. 9600 Returns zero for success, non-zero for failure. 9601 Example: > 9602 if searchdecl('myvar') == 0 9603 echo getline('.') 9604 endif 9605< 9606 Can also be used as a |method|: > 9607 GetName()->searchdecl() 9608< 9609 *searchpair()* 9610searchpair({start}, {middle}, {end} [, {flags} [, {skip} 9611 [, {stopline} [, {timeout}]]]]) 9612 Search for the match of a nested start-end pair. This can be 9613 used to find the "endif" that matches an "if", while other 9614 if/endif pairs in between are ignored. 9615 The search starts at the cursor. The default is to search 9616 forward, include 'b' in {flags} to search backward. 9617 If a match is found, the cursor is positioned at it and the 9618 line number is returned. If no match is found 0 or -1 is 9619 returned and the cursor doesn't move. No error message is 9620 given. 9621 9622 {start}, {middle} and {end} are patterns, see |pattern|. They 9623 must not contain \( \) pairs. Use of \%( \) is allowed. When 9624 {middle} is not empty, it is found when searching from either 9625 direction, but only when not in a nested start-end pair. A 9626 typical use is: > 9627 searchpair('\<if\>', '\<else\>', '\<endif\>') 9628< By leaving {middle} empty the "else" is skipped. 9629 9630 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with 9631 |search()|. Additionally: 9632 'r' Repeat until no more matches found; will find the 9633 outer pair. Implies the 'W' flag. 9634 'm' Return number of matches instead of line number with 9635 the match; will be > 1 when 'r' is used. 9636 Note: it's nearly always a good idea to use the 'W' flag, to 9637 avoid wrapping around the end of the file. 9638 9639 When a match for {start}, {middle} or {end} is found, the 9640 {skip} expression is evaluated with the cursor positioned on 9641 the start of the match. It should return non-zero if this 9642 match is to be skipped. E.g., because it is inside a comment 9643 or a string. 9644 When {skip} is omitted or empty, every match is accepted. 9645 When evaluating {skip} causes an error the search is aborted 9646 and -1 returned. 9647 {skip} can be a string, a lambda, a funcref or a partial. 9648 Anything else makes the function fail. 9649 In a `:def` function when the {skip} argument is a string 9650 constant it is compiled into instructions. 9651 9652 For {stopline} and {timeout} see |search()|. 9653 9654 The value of 'ignorecase' is used. 'magic' is ignored, the 9655 patterns are used like it's on. 9656 9657 The search starts exactly at the cursor. A match with 9658 {start}, {middle} or {end} at the next character, in the 9659 direction of searching, is the first one found. Example: > 9660 if 1 9661 if 2 9662 endif 2 9663 endif 1 9664< When starting at the "if 2", with the cursor on the "i", and 9665 searching forwards, the "endif 2" is found. When starting on 9666 the character just before the "if 2", the "endif 1" will be 9667 found. That's because the "if 2" will be found first, and 9668 then this is considered to be a nested if/endif from "if 2" to 9669 "endif 2". 9670 When searching backwards and {end} is more than one character, 9671 it may be useful to put "\zs" at the end of the pattern, so 9672 that when the cursor is inside a match with the end it finds 9673 the matching start. 9674 9675 Example, to find the "endif" command in a Vim script: > 9676 9677 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W', 9678 \ 'getline(".") =~ "^\\s*\""') 9679 9680< The cursor must be at or after the "if" for which a match is 9681 to be found. Note that single-quote strings are used to avoid 9682 having to double the backslashes. The skip expression only 9683 catches comments at the start of a line, not after a command. 9684 Also, a word "en" or "if" halfway a line is considered a 9685 match. 9686 Another example, to search for the matching "{" of a "}": > 9687 9688 :echo searchpair('{', '', '}', 'bW') 9689 9690< This works when the cursor is at or before the "}" for which a 9691 match is to be found. To reject matches that syntax 9692 highlighting recognized as strings: > 9693 9694 :echo searchpair('{', '', '}', 'bW', 9695 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"') 9696< 9697 *searchpairpos()* 9698searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} 9699 [, {stopline} [, {timeout}]]]]) 9700 Same as |searchpair()|, but returns a |List| with the line and 9701 column position of the match. The first element of the |List| 9702 is the line number and the second element is the byte index of 9703 the column position of the match. If no match is found, 9704 returns [0, 0]. > 9705 9706 :let [lnum,col] = searchpairpos('{', '', '}', 'n') 9707< 9708 See |match-parens| for a bigger and more useful example. 9709 9710 *searchpos()* 9711searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]]) 9712 Same as |search()|, but returns a |List| with the line and 9713 column position of the match. The first element of the |List| 9714 is the line number and the second element is the byte index of 9715 the column position of the match. If no match is found, 9716 returns [0, 0]. 9717 Example: > 9718 :let [lnum, col] = searchpos('mypattern', 'n') 9719 9720< When the 'p' flag is given then there is an extra item with 9721 the sub-pattern match number |search()-sub-match|. Example: > 9722 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np') 9723< In this example "submatch" is 2 when a lowercase letter is 9724 found |/\l|, 3 when an uppercase letter is found |/\u|. 9725 9726 Can also be used as a |method|: > 9727 GetPattern()->searchpos() 9728 9729server2client({clientid}, {string}) *server2client()* 9730 Send a reply string to {clientid}. The most recent {clientid} 9731 that sent a string can be retrieved with expand("<client>"). 9732 {only available when compiled with the |+clientserver| feature} 9733 Returns zero for success, -1 for failure. 9734 Note: 9735 This id has to be stored before the next command can be 9736 received. I.e. before returning from the received command and 9737 before calling any commands that waits for input. 9738 See also |clientserver|. 9739 Example: > 9740 :echo server2client(expand("<client>"), "HELLO") 9741 9742< Can also be used as a |method|: > 9743 GetClientId()->server2client(string) 9744< 9745serverlist() *serverlist()* 9746 Return a list of available server names, one per line. 9747 When there are no servers or the information is not available 9748 an empty string is returned. See also |clientserver|. 9749 {only available when compiled with the |+clientserver| feature} 9750 Example: > 9751 :echo serverlist() 9752< 9753setbufline({buf}, {lnum}, {text}) *setbufline()* 9754 Set line {lnum} to {text} in buffer {buf}. This works like 9755 |setline()| for the specified buffer. 9756 9757 This function works only for loaded buffers. First call 9758 |bufload()| if needed. 9759 9760 To insert lines use |appendbufline()|. 9761 Any text properties in {lnum} are cleared. 9762 9763 {text} can be a string to set one line, or a list of strings 9764 to set multiple lines. If the list extends below the last 9765 line then those lines are added. 9766 9767 For the use of {buf}, see |bufname()| above. 9768 9769 {lnum} is used like with |setline()|. 9770 When {lnum} is just below the last line the {text} will be 9771 added below the last line. 9772 9773 When {buf} is not a valid buffer, the buffer is not loaded or 9774 {lnum} is not valid then 1 is returned. On success 0 is 9775 returned. 9776 9777 Can also be used as a |method|, the base is passed as the 9778 third argument: > 9779 GetText()->setbufline(buf, lnum) 9780 9781setbufvar({buf}, {varname}, {val}) *setbufvar()* 9782 Set option or local variable {varname} in buffer {buf} to 9783 {val}. 9784 This also works for a global or local window option, but it 9785 doesn't work for a global or local window variable. 9786 For a local window option the global value is unchanged. 9787 For the use of {buf}, see |bufname()| above. 9788 The {varname} argument is a string. 9789 Note that the variable name without "b:" must be used. 9790 Examples: > 9791 :call setbufvar(1, "&mod", 1) 9792 :call setbufvar("todo", "myvar", "foobar") 9793< This function is not available in the |sandbox|. 9794 9795 Can also be used as a |method|, the base is passed as the 9796 third argument: > 9797 GetValue()->setbufvar(buf, varname) 9798 9799 9800setcellwidths({list}) *setcellwidths()* 9801 Specify overrides for cell widths of character ranges. This 9802 tells Vim how wide characters are, counted in screen cells. 9803 This overrides 'ambiwidth'. Example: > 9804 setcellwidths([[0xad, 0xad, 1], 9805 \ [0x2194, 0x2199, 2]]) 9806 9807< *E1109* *E1110* *E1111* *E1112* *E1113* 9808 The {list} argument is a list of lists with each three 9809 numbers. These three numbers are [low, high, width]. "low" 9810 and "high" can be the same, in which case this refers to one 9811 character. Otherwise it is the range of characters from "low" 9812 to "high" (inclusive). "width" is either 1 or 2, indicating 9813 the character width in screen cells. 9814 An error is given if the argument is invalid, also when a 9815 range overlaps with another. 9816 Only characters with value 0x100 and higher can be used. 9817 9818 If the new value causes 'fillchars' or 'listchars' to become 9819 invalid it is rejected and an error is given. 9820 9821 To clear the overrides pass an empty list: > 9822 setcellwidths([]); 9823< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see 9824 the effect for known emoji characters. 9825 9826setcharpos({expr}, {list}) *setcharpos()* 9827 Same as |setpos()| but uses the specified column number as the 9828 character index instead of the byte index in the line. 9829 9830 Example: 9831 With the text "여보세요" in line 8: > 9832 call setcharpos('.', [0, 8, 4, 0]) 9833< positions the cursor on the fourth character '요'. > 9834 call setpos('.', [0, 8, 4, 0]) 9835< positions the cursor on the second character '보'. 9836 9837 Can also be used as a |method|: > 9838 GetPosition()->setcharpos('.') 9839 9840setcharsearch({dict}) *setcharsearch()* 9841 Set the current character search information to {dict}, 9842 which contains one or more of the following entries: 9843 9844 char character which will be used for a subsequent 9845 |,| or |;| command; an empty string clears the 9846 character search 9847 forward direction of character search; 1 for forward, 9848 0 for backward 9849 until type of character search; 1 for a |t| or |T| 9850 character search, 0 for an |f| or |F| 9851 character search 9852 9853 This can be useful to save/restore a user's character search 9854 from a script: > 9855 :let prevsearch = getcharsearch() 9856 :" Perform a command which clobbers user's search 9857 :call setcharsearch(prevsearch) 9858< Also see |getcharsearch()|. 9859 9860 Can also be used as a |method|: > 9861 SavedSearch()->setcharsearch() 9862 9863setcmdpos({pos}) *setcmdpos()* 9864 Set the cursor position in the command line to byte position 9865 {pos}. The first position is 1. 9866 Use |getcmdpos()| to obtain the current position. 9867 Only works while editing the command line, thus you must use 9868 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For 9869 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is 9870 set after the command line is set to the expression. For 9871 |c_CTRL-R_=| it is set after evaluating the expression but 9872 before inserting the resulting text. 9873 When the number is too big the cursor is put at the end of the 9874 line. A number smaller than one has undefined results. 9875 Returns FALSE when successful, TRUE when not editing the 9876 command line. 9877 9878 Can also be used as a |method|: > 9879 GetPos()->setcmdpos() 9880 9881setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()* 9882setcursorcharpos({list}) 9883 Same as |cursor()| but uses the specified column number as the 9884 character index instead of the byte index in the line. 9885 9886 Example: 9887 With the text "여보세요" in line 4: > 9888 call setcursorcharpos(4, 3) 9889< positions the cursor on the third character '세'. > 9890 call cursor(4, 3) 9891< positions the cursor on the first character '여'. 9892 9893 Can also be used as a |method|: > 9894 GetCursorPos()->setcursorcharpos() 9895 9896 9897setenv({name}, {val}) *setenv()* 9898 Set environment variable {name} to {val}. Example: > 9899 call setenv('HOME', '/home/myhome') 9900 9901< When {val} is |v:null| the environment variable is deleted. 9902 See also |expr-env|. 9903 9904 Can also be used as a |method|, the base is passed as the 9905 second argument: > 9906 GetPath()->setenv('PATH') 9907 9908setfperm({fname}, {mode}) *setfperm()* *chmod* 9909 Set the file permissions for {fname} to {mode}. 9910 {mode} must be a string with 9 characters. It is of the form 9911 "rwxrwxrwx", where each group of "rwx" flags represent, in 9912 turn, the permissions of the owner of the file, the group the 9913 file belongs to, and other users. A '-' character means the 9914 permission is off, any other character means on. Multi-byte 9915 characters are not supported. 9916 9917 For example "rw-r-----" means read-write for the user, 9918 readable by the group, not accessible by others. "xx-x-----" 9919 would do the same thing. 9920 9921 Returns non-zero for success, zero for failure. 9922 9923 Can also be used as a |method|: > 9924 GetFilename()->setfperm(mode) 9925< 9926 To read permissions see |getfperm()|. 9927 9928 9929setline({lnum}, {text}) *setline()* 9930 Set line {lnum} of the current buffer to {text}. To insert 9931 lines use |append()|. To set lines in another buffer use 9932 |setbufline()|. Any text properties in {lnum} are cleared. 9933 9934 {lnum} is used like with |getline()|. 9935 When {lnum} is just below the last line the {text} will be 9936 added below the last line. 9937 {text} can be any type or a List of any type, each item is 9938 converted to a String. 9939 9940 If this succeeds, FALSE is returned. If this fails (most likely 9941 because {lnum} is invalid) TRUE is returned. 9942 9943 Example: > 9944 :call setline(5, strftime("%c")) 9945 9946< When {text} is a |List| then line {lnum} and following lines 9947 will be set to the items in the list. Example: > 9948 :call setline(5, ['aaa', 'bbb', 'ccc']) 9949< This is equivalent to: > 9950 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']] 9951 : call setline(n, l) 9952 :endfor 9953 9954< Note: The '[ and '] marks are not set. 9955 9956 Can also be used as a |method|, the base is passed as the 9957 second argument: > 9958 GetText()->setline(lnum) 9959 9960setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()* 9961 Create or replace or add to the location list for window {nr}. 9962 {nr} can be the window number or the |window-ID|. 9963 When {nr} is zero the current window is used. 9964 9965 For a location list window, the displayed location list is 9966 modified. For an invalid window number {nr}, -1 is returned. 9967 Otherwise, same as |setqflist()|. 9968 Also see |location-list|. 9969 9970 For {action} see |setqflist-action|. 9971 9972 If the optional {what} dictionary argument is supplied, then 9973 only the items listed in {what} are set. Refer to |setqflist()| 9974 for the list of supported keys in {what}. 9975 9976 Can also be used as a |method|, the base is passed as the 9977 second argument: > 9978 GetLoclist()->setloclist(winnr) 9979 9980setmatches({list} [, {win}]) *setmatches()* 9981 Restores a list of matches saved by |getmatches()| for the 9982 current window. Returns 0 if successful, otherwise -1. All 9983 current matches are cleared before the list is restored. See 9984 example for |getmatches()|. 9985 If {win} is specified, use the window with this number or 9986 window ID instead of the current window. 9987 9988 Can also be used as a |method|: > 9989 GetMatches()->setmatches() 9990< 9991 *setpos()* 9992setpos({expr}, {list}) 9993 Set the position for String {expr}. Possible values: 9994 . the cursor 9995 'x mark x 9996 9997 {list} must be a |List| with four or five numbers: 9998 [bufnum, lnum, col, off] 9999 [bufnum, lnum, col, off, curswant] 10000 10001 "bufnum" is the buffer number. Zero can be used for the 10002 current buffer. When setting an uppercase mark "bufnum" is 10003 used for the mark position. For other marks it specifies the 10004 buffer to set the mark in. You can use the |bufnr()| function 10005 to turn a file name into a buffer number. 10006 For setting the cursor and the ' mark "bufnum" is ignored, 10007 since these are associated with a window, not a buffer. 10008 Does not change the jumplist. 10009 10010 "lnum" and "col" are the position in the buffer. The first 10011 column is 1. Use a zero "lnum" to delete a mark. If "col" is 10012 smaller than 1 then 1 is used. To use the character count 10013 instead of the byte count, use |setcharpos()|. 10014 10015 The "off" number is only used when 'virtualedit' is set. Then 10016 it is the offset in screen columns from the start of the 10017 character. E.g., a position within a <Tab> or after the last 10018 character. 10019 10020 The "curswant" number is only used when setting the cursor 10021 position. It sets the preferred column for when moving the 10022 cursor vertically. When the "curswant" number is missing the 10023 preferred column is not set. When it is present and setting a 10024 mark position it is not used. 10025 10026 Note that for '< and '> changing the line number may result in 10027 the marks to be effectively be swapped, so that '< is always 10028 before '>. 10029 10030 Returns 0 when the position could be set, -1 otherwise. 10031 An error message is given if {expr} is invalid. 10032 10033 Also see |setcharpos()|, |getpos()| and |getcurpos()|. 10034 10035 This does not restore the preferred column for moving 10036 vertically; if you set the cursor position with this, |j| and 10037 |k| motions will jump to previous columns! Use |cursor()| to 10038 also set the preferred column. Also see the "curswant" key in 10039 |winrestview()|. 10040 10041 Can also be used as a |method|: > 10042 GetPosition()->setpos('.') 10043 10044setqflist({list} [, {action} [, {what}]]) *setqflist()* 10045 Create or replace or add to the quickfix list. 10046 10047 If the optional {what} dictionary argument is supplied, then 10048 only the items listed in {what} are set. The first {list} 10049 argument is ignored. See below for the supported items in 10050 {what}. 10051 *setqflist-what* 10052 When {what} is not present, the items in {list} are used. Each 10053 item must be a dictionary. Non-dictionary items in {list} are 10054 ignored. Each dictionary item can contain the following 10055 entries: 10056 10057 bufnr buffer number; must be the number of a valid 10058 buffer 10059 filename name of a file; only used when "bufnr" is not 10060 present or it is invalid. 10061 module name of a module; if given it will be used in 10062 quickfix error window instead of the filename. 10063 lnum line number in the file 10064 pattern search pattern used to locate the error 10065 col column number 10066 vcol when non-zero: "col" is visual column 10067 when zero: "col" is byte index 10068 nr error number 10069 text description of the error 10070 type single-character error type, 'E', 'W', etc. 10071 valid recognized error message 10072 10073 The "col", "vcol", "nr", "type" and "text" entries are 10074 optional. Either "lnum" or "pattern" entry can be used to 10075 locate a matching error line. 10076 If the "filename" and "bufnr" entries are not present or 10077 neither the "lnum" or "pattern" entries are present, then the 10078 item will not be handled as an error line. 10079 If both "pattern" and "lnum" are present then "pattern" will 10080 be used. 10081 If the "valid" entry is not supplied, then the valid flag is 10082 set when "bufnr" is a valid buffer or "filename" exists. 10083 If you supply an empty {list}, the quickfix list will be 10084 cleared. 10085 Note that the list is not exactly the same as what 10086 |getqflist()| returns. 10087 10088 {action} values: *setqflist-action* *E927* 10089 'a' The items from {list} are added to the existing 10090 quickfix list. If there is no existing list, then a 10091 new list is created. 10092 10093 'r' The items from the current quickfix list are replaced 10094 with the items from {list}. This can also be used to 10095 clear the list: > 10096 :call setqflist([], 'r') 10097< 10098 'f' All the quickfix lists in the quickfix stack are 10099 freed. 10100 10101 If {action} is not present or is set to ' ', then a new list 10102 is created. The new quickfix list is added after the current 10103 quickfix list in the stack and all the following lists are 10104 freed. To add a new quickfix list at the end of the stack, 10105 set "nr" in {what} to "$". 10106 10107 The following items can be specified in dictionary {what}: 10108 context quickfix list context. See |quickfix-context| 10109 efm errorformat to use when parsing text from 10110 "lines". If this is not present, then the 10111 'errorformat' option value is used. 10112 See |quickfix-parse| 10113 id quickfix list identifier |quickfix-ID| 10114 idx index of the current entry in the quickfix 10115 list specified by 'id' or 'nr'. If set to '$', 10116 then the last entry in the list is set as the 10117 current entry. See |quickfix-index| 10118 items list of quickfix entries. Same as the {list} 10119 argument. 10120 lines use 'errorformat' to parse a list of lines and 10121 add the resulting entries to the quickfix list 10122 {nr} or {id}. Only a |List| value is supported. 10123 See |quickfix-parse| 10124 nr list number in the quickfix stack; zero 10125 means the current quickfix list and "$" means 10126 the last quickfix list. 10127 quickfixtextfunc 10128 function to get the text to display in the 10129 quickfix window. The value can be the name of 10130 a function or a funcref or a lambda. Refer to 10131 |quickfix-window-function| for an explanation 10132 of how to write the function and an example. 10133 title quickfix list title text. See |quickfix-title| 10134 Unsupported keys in {what} are ignored. 10135 If the "nr" item is not present, then the current quickfix list 10136 is modified. When creating a new quickfix list, "nr" can be 10137 set to a value one greater than the quickfix stack size. 10138 When modifying a quickfix list, to guarantee that the correct 10139 list is modified, "id" should be used instead of "nr" to 10140 specify the list. 10141 10142 Examples (See also |setqflist-examples|): > 10143 :call setqflist([], 'r', {'title': 'My search'}) 10144 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'}) 10145 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]}) 10146< 10147 Returns zero for success, -1 for failure. 10148 10149 This function can be used to create a quickfix list 10150 independent of the 'errorformat' setting. Use a command like 10151 `:cc 1` to jump to the first position. 10152 10153 Can also be used as a |method|, the base is passed as the 10154 second argument: > 10155 GetErrorlist()->setqflist() 10156< 10157 *setreg()* 10158setreg({regname}, {value} [, {options}]) 10159 Set the register {regname} to {value}. 10160 If {regname} is "" or "@", the unnamed register '"' is used. 10161 The {regname} argument is a string. In |Vim9-script| 10162 {regname} must be one character. 10163 10164 {value} may be any value returned by |getreg()| or 10165 |getreginfo()|, including a |List| or |Dict|. 10166 If {options} contains "a" or {regname} is upper case, 10167 then the value is appended. 10168 10169 {options} can also contain a register type specification: 10170 "c" or "v" |characterwise| mode 10171 "l" or "V" |linewise| mode 10172 "b" or "<CTRL-V>" |blockwise-visual| mode 10173 If a number immediately follows "b" or "<CTRL-V>" then this is 10174 used as the width of the selection - if it is not specified 10175 then the width of the block is set to the number of characters 10176 in the longest line (counting a <Tab> as 1 character). 10177 10178 If {options} contains no register settings, then the default 10179 is to use character mode unless {value} ends in a <NL> for 10180 string {value} and linewise mode for list {value}. Blockwise 10181 mode is never selected automatically. 10182 Returns zero for success, non-zero for failure. 10183 10184 *E883* 10185 Note: you may not use |List| containing more than one item to 10186 set search and expression registers. Lists containing no 10187 items act like empty strings. 10188 10189 Examples: > 10190 :call setreg(v:register, @*) 10191 :call setreg('*', @%, 'ac') 10192 :call setreg('a', "1\n2\n3", 'b5') 10193 :call setreg('"', { 'points_to': 'a'}) 10194 10195< This example shows using the functions to save and restore a 10196 register: > 10197 :let var_a = getreginfo() 10198 :call setreg('a', var_a) 10199< or: > 10200 :let var_a = getreg('a', 1, 1) 10201 :let var_amode = getregtype('a') 10202 .... 10203 :call setreg('a', var_a, var_amode) 10204< Note: you may not reliably restore register value 10205 without using the third argument to |getreg()| as without it 10206 newlines are represented as newlines AND Nul bytes are 10207 represented as newlines as well, see |NL-used-for-Nul|. 10208 10209 You can also change the type of a register by appending 10210 nothing: > 10211 :call setreg('a', '', 'al') 10212 10213< Can also be used as a |method|, the base is passed as the 10214 second argument: > 10215 GetText()->setreg('a') 10216 10217settabvar({tabnr}, {varname}, {val}) *settabvar()* 10218 Set tab-local variable {varname} to {val} in tab page {tabnr}. 10219 |t:var| 10220 The {varname} argument is a string. 10221 Note that autocommands are blocked, side effects may not be 10222 triggered, e.g. when setting 'filetype'. 10223 Note that the variable name without "t:" must be used. 10224 Tabs are numbered starting with one. 10225 This function is not available in the |sandbox|. 10226 10227 Can also be used as a |method|, the base is passed as the 10228 third argument: > 10229 GetValue()->settabvar(tab, name) 10230 10231settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* 10232 Set option or local variable {varname} in window {winnr} to 10233 {val}. 10234 Tabs are numbered starting with one. For the current tabpage 10235 use |setwinvar()|. 10236 {winnr} can be the window number or the |window-ID|. 10237 When {winnr} is zero the current window is used. 10238 Note that autocommands are blocked, side effects may not be 10239 triggered, e.g. when setting 'filetype' or 'syntax'. 10240 This also works for a global or local buffer option, but it 10241 doesn't work for a global or local buffer variable. 10242 For a local buffer option the global value is unchanged. 10243 Note that the variable name without "w:" must be used. 10244 Examples: > 10245 :call settabwinvar(1, 1, "&list", 0) 10246 :call settabwinvar(3, 2, "myvar", "foobar") 10247< This function is not available in the |sandbox|. 10248 10249 Can also be used as a |method|, the base is passed as the 10250 fourth argument: > 10251 GetValue()->settabwinvar(tab, winnr, name) 10252 10253settagstack({nr}, {dict} [, {action}]) *settagstack()* 10254 Modify the tag stack of the window {nr} using {dict}. 10255 {nr} can be the window number or the |window-ID|. 10256 10257 For a list of supported items in {dict}, refer to 10258 |gettagstack()|. "curidx" takes effect before changing the tag 10259 stack. 10260 *E962* 10261 How the tag stack is modified depends on the {action} 10262 argument: 10263 - If {action} is not present or is set to 'r', then the tag 10264 stack is replaced. 10265 - If {action} is set to 'a', then new entries from {dict} are 10266 pushed (added) onto the tag stack. 10267 - If {action} is set to 't', then all the entries from the 10268 current entry in the tag stack or "curidx" in {dict} are 10269 removed and then new entries are pushed to the stack. 10270 10271 The current index is set to one after the length of the tag 10272 stack after the modification. 10273 10274 Returns zero for success, -1 for failure. 10275 10276 Examples (for more examples see |tagstack-examples|): 10277 Empty the tag stack of window 3: > 10278 call settagstack(3, {'items' : []}) 10279 10280< Save and restore the tag stack: > 10281 let stack = gettagstack(1003) 10282 " do something else 10283 call settagstack(1003, stack) 10284 unlet stack 10285< 10286 Can also be used as a |method|, the base is passed as the 10287 second argument: > 10288 GetStack()->settagstack(winnr) 10289 10290setwinvar({winnr}, {varname}, {val}) *setwinvar()* 10291 Like |settabwinvar()| for the current tab page. 10292 Examples: > 10293 :call setwinvar(1, "&list", 0) 10294 :call setwinvar(2, "myvar", "foobar") 10295 10296< Can also be used as a |method|, the base is passed as the 10297 third argument: > 10298 GetValue()->setwinvar(winnr, name) 10299 10300sha256({string}) *sha256()* 10301 Returns a String with 64 hex characters, which is the SHA256 10302 checksum of {string}. 10303 10304 Can also be used as a |method|: > 10305 GetText()->sha256() 10306 10307< {only available when compiled with the |+cryptv| feature} 10308 10309shellescape({string} [, {special}]) *shellescape()* 10310 Escape {string} for use as a shell command argument. 10311 When the 'shell' contains powershell (MS-Windows) or pwsh 10312 (MS-Windows, Linux, and MacOS) then it will enclose {string} 10313 in single quotes and will double up all internal single 10314 quotes. 10315 On MS-Windows, when 'shellslash' is not set, it will enclose 10316 {string} in double quotes and double all double quotes within 10317 {string}. 10318 Otherwise it will enclose {string} in single quotes and 10319 replace all "'" with "'\''". 10320 10321 When the {special} argument is present and it's a non-zero 10322 Number or a non-empty String (|non-zero-arg|), then special 10323 items such as "!", "%", "#" and "<cword>" will be preceded by 10324 a backslash. This backslash will be removed again by the |:!| 10325 command. 10326 10327 The "!" character will be escaped (again with a |non-zero-arg| 10328 {special}) when 'shell' contains "csh" in the tail. That is 10329 because for csh and tcsh "!" is used for history replacement 10330 even when inside single quotes. 10331 10332 With a |non-zero-arg| {special} the <NL> character is also 10333 escaped. When 'shell' containing "csh" in the tail it's 10334 escaped a second time. 10335 10336 The "\" character will be escaped when 'shell' contains "fish" 10337 in the tail. That is because for fish "\" is used as an escape 10338 character inside single quotes. 10339 10340 Example of use with a |:!| command: > 10341 :exe '!dir ' . shellescape(expand('<cfile>'), 1) 10342< This results in a directory listing for the file under the 10343 cursor. Example of use with |system()|: > 10344 :call system("chmod +w -- " . shellescape(expand("%"))) 10345< See also |::S|. 10346 10347 Can also be used as a |method|: > 10348 GetCommand()->shellescape() 10349 10350shiftwidth([{col}]) *shiftwidth()* 10351 Returns the effective value of 'shiftwidth'. This is the 10352 'shiftwidth' value unless it is zero, in which case it is the 10353 'tabstop' value. This function was introduced with patch 10354 7.3.694 in 2012, everybody should have it by now (however it 10355 did not allow for the optional {col} argument until 8.1.542). 10356 10357 When there is one argument {col} this is used as column number 10358 for which to return the 'shiftwidth' value. This matters for the 10359 'vartabstop' feature. If the 'vartabstop' setting is enabled and 10360 no {col} argument is given, column 1 will be assumed. 10361 10362 Can also be used as a |method|: > 10363 GetColumn()->shiftwidth() 10364 10365sign_ functions are documented here: |sign-functions-details| 10366 10367 10368simplify({filename}) *simplify()* 10369 Simplify the file name as much as possible without changing 10370 the meaning. Shortcuts (on MS-Windows) or symbolic links (on 10371 Unix) are not resolved. If the first path component in 10372 {filename} designates the current directory, this will be 10373 valid for the result as well. A trailing path separator is 10374 not removed either. On Unix "//path" is unchanged, but 10375 "///path" is simplified to "/path" (this follows the Posix 10376 standard). 10377 Example: > 10378 simplify("./dir/.././/file/") == "./file/" 10379< Note: The combination "dir/.." is only removed if "dir" is 10380 a searchable directory or does not exist. On Unix, it is also 10381 removed when "dir" is a symbolic link within the same 10382 directory. In order to resolve all the involved symbolic 10383 links before simplifying the path name, use |resolve()|. 10384 10385 Can also be used as a |method|: > 10386 GetName()->simplify() 10387 10388sin({expr}) *sin()* 10389 Return the sine of {expr}, measured in radians, as a |Float|. 10390 {expr} must evaluate to a |Float| or a |Number|. 10391 Examples: > 10392 :echo sin(100) 10393< -0.506366 > 10394 :echo sin(-4.01) 10395< 0.763301 10396 10397 Can also be used as a |method|: > 10398 Compute()->sin() 10399< 10400 {only available when compiled with the |+float| feature} 10401 10402 10403sinh({expr}) *sinh()* 10404 Return the hyperbolic sine of {expr} as a |Float| in the range 10405 [-inf, inf]. 10406 {expr} must evaluate to a |Float| or a |Number|. 10407 Examples: > 10408 :echo sinh(0.5) 10409< 0.521095 > 10410 :echo sinh(-0.9) 10411< -1.026517 10412 10413 Can also be used as a |method|: > 10414 Compute()->sinh() 10415< 10416 {only available when compiled with the |+float| feature} 10417 10418 10419slice({expr}, {start} [, {end}]) *slice()* 10420 Similar to using a |slice| "expr[start : end]", but "end" is 10421 used exclusive. And for a string the indexes are used as 10422 character indexes instead of byte indexes, like in 10423 |vim9script|. Also, composing characters are not counted. 10424 When {end} is omitted the slice continues to the last item. 10425 When {end} is -1 the last item is omitted. 10426 10427 Can also be used as a |method|: > 10428 GetList()->slice(offset) 10429 10430 10431sort({list} [, {func} [, {dict}]]) *sort()* *E702* 10432 Sort the items in {list} in-place. Returns {list}. 10433 10434 If you want a list to remain unmodified make a copy first: > 10435 :let sortedlist = sort(copy(mylist)) 10436 10437< When {func} is omitted, is empty or zero, then sort() uses the 10438 string representation of each item to sort on. Numbers sort 10439 after Strings, |Lists| after Numbers. For sorting text in the 10440 current buffer use |:sort|. 10441 10442 When {func} is given and it is '1' or 'i' then case is 10443 ignored. 10444 10445 When {func} is given and it is 'l' then the current collation 10446 locale is used for ordering. Implementation details: strcoll() 10447 is used to compare strings. See |:language| check or set the 10448 collation locale. |v:collate| can also be used to check the 10449 current locale. Sorting using the locale typically ignores 10450 case. Example: > 10451 " ö is sorted similarly to o with English locale. 10452 :language collate en_US.UTF8 10453 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 10454< ['n', 'o', 'O', 'ö', 'p', 'z'] ~ 10455> 10456 " ö is sorted after z with Swedish locale. 10457 :language collate sv_SE.UTF8 10458 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') 10459< ['n', 'o', 'O', 'p', 'z', 'ö'] ~ 10460 This does not work properly on Mac. 10461 10462 When {func} is given and it is 'n' then all items will be 10463 sorted numerical (Implementation detail: this uses the 10464 strtod() function to parse numbers, Strings, Lists, Dicts and 10465 Funcrefs will be considered as being 0). 10466 10467 When {func} is given and it is 'N' then all items will be 10468 sorted numerical. This is like 'n' but a string containing 10469 digits will be used as the number they represent. 10470 10471 When {func} is given and it is 'f' then all items will be 10472 sorted numerical. All values must be a Number or a Float. 10473 10474 When {func} is a |Funcref| or a function name, this function 10475 is called to compare items. The function is invoked with two 10476 items as argument and must return zero if they are equal, 1 or 10477 bigger if the first one sorts after the second one, -1 or 10478 smaller if the first one sorts before the second one. 10479 10480 {dict} is for functions with the "dict" attribute. It will be 10481 used to set the local variable "self". |Dictionary-function| 10482 10483 The sort is stable, items which compare equal (as number or as 10484 string) will keep their relative position. E.g., when sorting 10485 on numbers, text strings will sort next to each other, in the 10486 same order as they were originally. 10487 10488 Can also be used as a |method|: > 10489 mylist->sort() 10490 10491< Also see |uniq()|. 10492 10493 Example: > 10494 func MyCompare(i1, i2) 10495 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 10496 endfunc 10497 eval mylist->sort("MyCompare") 10498< A shorter compare version for this specific simple case, which 10499 ignores overflow: > 10500 func MyCompare(i1, i2) 10501 return a:i1 - a:i2 10502 endfunc 10503< For a simple expression you can use a lambda: > 10504 eval mylist->sort({i1, i2 -> i1 - i2}) 10505< 10506sound_clear() *sound_clear()* 10507 Stop playing all sounds. 10508 10509 On some Linux systems you may need the libcanberra-pulse 10510 package, otherwise sound may not stop. 10511 10512 {only available when compiled with the |+sound| feature} 10513 10514 *sound_playevent()* 10515sound_playevent({name} [, {callback}]) 10516 Play a sound identified by {name}. Which event names are 10517 supported depends on the system. Often the XDG sound names 10518 are used. On Ubuntu they may be found in 10519 /usr/share/sounds/freedesktop/stereo. Example: > 10520 call sound_playevent('bell') 10521< On MS-Windows, {name} can be SystemAsterisk, SystemDefault, 10522 SystemExclamation, SystemExit, SystemHand, SystemQuestion, 10523 SystemStart, SystemWelcome, etc. 10524 10525 When {callback} is specified it is invoked when the sound is 10526 finished. The first argument is the sound ID, the second 10527 argument is the status: 10528 0 sound was played to the end 10529 1 sound was interrupted 10530 2 error occurred after sound started 10531 Example: > 10532 func Callback(id, status) 10533 echomsg "sound " .. a:id .. " finished with " .. a:status 10534 endfunc 10535 call sound_playevent('bell', 'Callback') 10536 10537< MS-Windows: {callback} doesn't work for this function. 10538 10539 Returns the sound ID, which can be passed to `sound_stop()`. 10540 Returns zero if the sound could not be played. 10541 10542 Can also be used as a |method|: > 10543 GetSoundName()->sound_playevent() 10544 10545< {only available when compiled with the |+sound| feature} 10546 10547 *sound_playfile()* 10548sound_playfile({path} [, {callback}]) 10549 Like `sound_playevent()` but play sound file {path}. {path} 10550 must be a full path. On Ubuntu you may find files to play 10551 with this command: > 10552 :!find /usr/share/sounds -type f | grep -v index.theme 10553 10554< Can also be used as a |method|: > 10555 GetSoundPath()->sound_playfile() 10556 10557< {only available when compiled with the |+sound| feature} 10558 10559 10560sound_stop({id}) *sound_stop()* 10561 Stop playing sound {id}. {id} must be previously returned by 10562 `sound_playevent()` or `sound_playfile()`. 10563 10564 On some Linux systems you may need the libcanberra-pulse 10565 package, otherwise sound may not stop. 10566 10567 On MS-Windows, this does not work for event sound started by 10568 `sound_playevent()`. To stop event sounds, use `sound_clear()`. 10569 10570 Can also be used as a |method|: > 10571 soundid->sound_stop() 10572 10573< {only available when compiled with the |+sound| feature} 10574 10575 *soundfold()* 10576soundfold({word}) 10577 Return the sound-folded equivalent of {word}. Uses the first 10578 language in 'spelllang' for the current window that supports 10579 soundfolding. 'spell' must be set. When no sound folding is 10580 possible the {word} is returned unmodified. 10581 This can be used for making spelling suggestions. Note that 10582 the method can be quite slow. 10583 10584 Can also be used as a |method|: > 10585 GetWord()->soundfold() 10586< 10587 *spellbadword()* 10588spellbadword([{sentence}]) 10589 Without argument: The result is the badly spelled word under 10590 or after the cursor. The cursor is moved to the start of the 10591 bad word. When no bad word is found in the cursor line the 10592 result is an empty string and the cursor doesn't move. 10593 10594 With argument: The result is the first word in {sentence} that 10595 is badly spelled. If there are no spelling mistakes the 10596 result is an empty string. 10597 10598 The return value is a list with two items: 10599 - The badly spelled word or an empty string. 10600 - The type of the spelling error: 10601 "bad" spelling mistake 10602 "rare" rare word 10603 "local" word only valid in another region 10604 "caps" word should start with Capital 10605 Example: > 10606 echo spellbadword("the quik brown fox") 10607< ['quik', 'bad'] ~ 10608 10609 The spelling information for the current window and the value 10610 of 'spelllang' are used. 10611 10612 Can also be used as a |method|: > 10613 GetText()->spellbadword() 10614< 10615 *spellsuggest()* 10616spellsuggest({word} [, {max} [, {capital}]]) 10617 Return a |List| with spelling suggestions to replace {word}. 10618 When {max} is given up to this number of suggestions are 10619 returned. Otherwise up to 25 suggestions are returned. 10620 10621 When the {capital} argument is given and it's non-zero only 10622 suggestions with a leading capital will be given. Use this 10623 after a match with 'spellcapcheck'. 10624 10625 {word} can be a badly spelled word followed by other text. 10626 This allows for joining two words that were split. The 10627 suggestions also include the following text, thus you can 10628 replace a line. 10629 10630 {word} may also be a good word. Similar words will then be 10631 returned. {word} itself is not included in the suggestions, 10632 although it may appear capitalized. 10633 10634 The spelling information for the current window is used. The 10635 values of 'spelllang' and 'spellsuggest' are used. 10636 10637 Can also be used as a |method|: > 10638 GetWord()->spellsuggest() 10639 10640split({string} [, {pattern} [, {keepempty}]]) *split()* 10641 Make a |List| out of {string}. When {pattern} is omitted or 10642 empty each white-separated sequence of characters becomes an 10643 item. 10644 Otherwise the string is split where {pattern} matches, 10645 removing the matched characters. 'ignorecase' is not used 10646 here, add \c to ignore case. |/\c| 10647 When the first or last item is empty it is omitted, unless the 10648 {keepempty} argument is given and it's non-zero. 10649 Other empty items are kept when {pattern} matches at least one 10650 character or when {keepempty} is non-zero. 10651 Example: > 10652 :let words = split(getline('.'), '\W\+') 10653< To split a string in individual characters: > 10654 :for c in split(mystring, '\zs') 10655< If you want to keep the separator you can also use '\zs' at 10656 the end of the pattern: > 10657 :echo split('abc:def:ghi', ':\zs') 10658< ['abc:', 'def:', 'ghi'] ~ 10659 Splitting a table where the first element can be empty: > 10660 :let items = split(line, ':', 1) 10661< The opposite function is |join()|. 10662 10663 Can also be used as a |method|: > 10664 GetString()->split() 10665 10666sqrt({expr}) *sqrt()* 10667 Return the non-negative square root of Float {expr} as a 10668 |Float|. 10669 {expr} must evaluate to a |Float| or a |Number|. When {expr} 10670 is negative the result is NaN (Not a Number). 10671 Examples: > 10672 :echo sqrt(100) 10673< 10.0 > 10674 :echo sqrt(-4.01) 10675< nan 10676 "nan" may be different, it depends on system libraries. 10677 10678 Can also be used as a |method|: > 10679 Compute()->sqrt() 10680< 10681 {only available when compiled with the |+float| feature} 10682 10683 10684srand([{expr}]) *srand()* 10685 Initialize seed used by |rand()|: 10686 - If {expr} is not given, seed values are initialized by 10687 reading from /dev/urandom, if possible, or using time(NULL) 10688 a.k.a. epoch time otherwise; this only has second accuracy. 10689 - If {expr} is given it must be a Number. It is used to 10690 initialize the seed values. This is useful for testing or 10691 when a predictable sequence is intended. 10692 10693 Examples: > 10694 :let seed = srand() 10695 :let seed = srand(userinput) 10696 :echo rand(seed) 10697 10698state([{what}]) *state()* 10699 Return a string which contains characters indicating the 10700 current state. Mostly useful in callbacks that want to do 10701 work that may not always be safe. Roughly this works like: 10702 - callback uses state() to check if work is safe to do. 10703 Yes: then do it right away. 10704 No: add to work queue and add a |SafeState| and/or 10705 |SafeStateAgain| autocommand (|SafeState| triggers at 10706 toplevel, |SafeStateAgain| triggers after handling 10707 messages and callbacks). 10708 - When SafeState or SafeStateAgain is triggered and executes 10709 your autocommand, check with `state()` if the work can be 10710 done now, and if yes remove it from the queue and execute. 10711 Remove the autocommand if the queue is now empty. 10712 Also see |mode()|. 10713 10714 When {what} is given only characters in this string will be 10715 added. E.g, this checks if the screen has scrolled: > 10716 if state('s') == '' 10717 " screen has not scrolled 10718< 10719 These characters indicate the state, generally indicating that 10720 something is busy: 10721 m halfway a mapping, :normal command, feedkeys() or 10722 stuffed command 10723 o operator pending, e.g. after |d| 10724 a Insert mode autocomplete active 10725 x executing an autocommand 10726 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and 10727 ch_readraw() when reading json 10728 S not triggering SafeState or SafeStateAgain, e.g. after 10729 |f| or a count 10730 c callback invoked, including timer (repeats for 10731 recursiveness up to "ccc") 10732 s screen has scrolled for messages 10733 10734str2float({string} [, {quoted}]) *str2float()* 10735 Convert String {string} to a Float. This mostly works the 10736 same as when using a floating point number in an expression, 10737 see |floating-point-format|. But it's a bit more permissive. 10738 E.g., "1e40" is accepted, while in an expression you need to 10739 write "1.0e40". The hexadecimal form "0x123" is also 10740 accepted, but not others, like binary or octal. 10741 When {quoted} is present and non-zero then embedded single 10742 quotes before the dot are ignored, thus "1'000.0" is a 10743 thousand. 10744 Text after the number is silently ignored. 10745 The decimal point is always '.', no matter what the locale is 10746 set to. A comma ends the number: "12,345.67" is converted to 10747 12.0. You can strip out thousands separators with 10748 |substitute()|: > 10749 let f = str2float(substitute(text, ',', '', 'g')) 10750< 10751 Can also be used as a |method|: > 10752 let f = text->substitute(',', '', 'g')->str2float() 10753< 10754 {only available when compiled with the |+float| feature} 10755 10756str2list({string} [, {utf8}]) *str2list()* 10757 Return a list containing the number values which represent 10758 each character in String {string}. Examples: > 10759 str2list(" ") returns [32] 10760 str2list("ABC") returns [65, 66, 67] 10761< |list2str()| does the opposite. 10762 10763 When {utf8} is omitted or zero, the current 'encoding' is used. 10764 When {utf8} is TRUE, always treat the String as UTF-8 10765 characters. With UTF-8 composing characters are handled 10766 properly: > 10767 str2list("á") returns [97, 769] 10768 10769< Can also be used as a |method|: > 10770 GetString()->str2list() 10771 10772 10773str2nr({string} [, {base} [, {quoted}]]) *str2nr()* 10774 Convert string {string} to a number. 10775 {base} is the conversion base, it can be 2, 8, 10 or 16. 10776 When {quoted} is present and non-zero then embedded single 10777 quotes are ignored, thus "1'000'000" is a million. 10778 10779 When {base} is omitted base 10 is used. This also means that 10780 a leading zero doesn't cause octal conversion to be used, as 10781 with the default String to Number conversion. Example: > 10782 let nr = str2nr('0123') 10783< 10784 When {base} is 16 a leading "0x" or "0X" is ignored. With a 10785 different base the result will be zero. Similarly, when 10786 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when 10787 {base} is 2 a leading "0b" or "0B" is ignored. 10788 Text after the number is silently ignored. 10789 10790 Can also be used as a |method|: > 10791 GetText()->str2nr() 10792 10793 10794strcharlen({string}) *strcharlen()* 10795 The result is a Number, which is the number of characters 10796 in String {string}. Composing characters are ignored. 10797 |strchars()| can count the number of characters, counting 10798 composing characters separately. 10799 10800 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 10801 10802 Can also be used as a |method|: > 10803 GetText()->strcharlen() 10804 10805 10806strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()* 10807 Like |strpart()| but using character index and length instead 10808 of byte index and length. 10809 When {skipcc} is omitted or zero, composing characters are 10810 counted separately. 10811 When {skipcc} set to 1, Composing characters are ignored, 10812 similar to |slice()|. 10813 When a character index is used where a character does not 10814 exist it is omitted and counted as one character. For 10815 example: > 10816 strcharpart('abc', -1, 2) 10817< results in 'a'. 10818 10819 Can also be used as a |method|: > 10820 GetText()->strcharpart(5) 10821 10822 10823strchars({string} [, {skipcc}]) *strchars()* 10824 The result is a Number, which is the number of characters 10825 in String {string}. 10826 When {skipcc} is omitted or zero, composing characters are 10827 counted separately. 10828 When {skipcc} set to 1, Composing characters are ignored. 10829 |strcharlen()| always does this. 10830 10831 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. 10832 10833 {skipcc} is only available after 7.4.755. For backward 10834 compatibility, you can define a wrapper function: > 10835 if has("patch-7.4.755") 10836 function s:strchars(str, skipcc) 10837 return strchars(a:str, a:skipcc) 10838 endfunction 10839 else 10840 function s:strchars(str, skipcc) 10841 if a:skipcc 10842 return strlen(substitute(a:str, ".", "x", "g")) 10843 else 10844 return strchars(a:str) 10845 endif 10846 endfunction 10847 endif 10848< 10849 Can also be used as a |method|: > 10850 GetText()->strchars() 10851 10852strdisplaywidth({string} [, {col}]) *strdisplaywidth()* 10853 The result is a Number, which is the number of display cells 10854 String {string} occupies on the screen when it starts at {col} 10855 (first column is zero). When {col} is omitted zero is used. 10856 Otherwise it is the screen column where to start. This 10857 matters for Tab characters. 10858 The option settings of the current window are used. This 10859 matters for anything that's displayed differently, such as 10860 'tabstop' and 'display'. 10861 When {string} contains characters with East Asian Width Class 10862 Ambiguous, this function's return value depends on 'ambiwidth'. 10863 Also see |strlen()|, |strwidth()| and |strchars()|. 10864 10865 Can also be used as a |method|: > 10866 GetText()->strdisplaywidth() 10867 10868strftime({format} [, {time}]) *strftime()* 10869 The result is a String, which is a formatted date and time, as 10870 specified by the {format} string. The given {time} is used, 10871 or the current time if no time is given. The accepted 10872 {format} depends on your system, thus this is not portable! 10873 See the manual page of the C function strftime() for the 10874 format. The maximum length of the result is 80 characters. 10875 See also |localtime()|, |getftime()| and |strptime()|. 10876 The language can be changed with the |:language| command. 10877 Examples: > 10878 :echo strftime("%c") Sun Apr 27 11:49:23 1997 10879 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25 10880 :echo strftime("%y%m%d %T") 970427 11:53:55 10881 :echo strftime("%H:%M") 11:55 10882 :echo strftime("%c", getftime("file.c")) 10883 Show mod time of file.c. 10884< Not available on all systems. To check use: > 10885 :if exists("*strftime") 10886 10887< Can also be used as a |method|: > 10888 GetFormat()->strftime() 10889 10890strgetchar({str}, {index}) *strgetchar()* 10891 Get character {index} from {str}. This uses a character 10892 index, not a byte index. Composing characters are considered 10893 separate characters here. 10894 Also see |strcharpart()| and |strchars()|. 10895 10896 Can also be used as a |method|: > 10897 GetText()->strgetchar(5) 10898 10899stridx({haystack}, {needle} [, {start}]) *stridx()* 10900 The result is a Number, which gives the byte index in 10901 {haystack} of the first occurrence of the String {needle}. 10902 If {start} is specified, the search starts at index {start}. 10903 This can be used to find a second match: > 10904 :let colon1 = stridx(line, ":") 10905 :let colon2 = stridx(line, ":", colon1 + 1) 10906< The search is done case-sensitive. 10907 For pattern searches use |match()|. 10908 -1 is returned if the {needle} does not occur in {haystack}. 10909 See also |strridx()|. 10910 Examples: > 10911 :echo stridx("An Example", "Example") 3 10912 :echo stridx("Starting point", "Start") 0 10913 :echo stridx("Starting point", "start") -1 10914< *strstr()* *strchr()* 10915 stridx() works similar to the C function strstr(). When used 10916 with a single character it works similar to strchr(). 10917 10918 Can also be used as a |method|: > 10919 GetHaystack()->stridx(needle) 10920< 10921 *string()* 10922string({expr}) Return {expr} converted to a String. If {expr} is a Number, 10923 Float, String, Blob or a composition of them, then the result 10924 can be parsed back with |eval()|. 10925 {expr} type result ~ 10926 String 'string' (single quotes are doubled) 10927 Number 123 10928 Float 123.123456 or 1.123456e8 10929 Funcref function('name') 10930 Blob 0z00112233.44556677.8899 10931 List [item, item] 10932 Dictionary {key: value, key: value} 10933 10934 When a |List| or |Dictionary| has a recursive reference it is 10935 replaced by "[...]" or "{...}". Using eval() on the result 10936 will then fail. 10937 10938 Can also be used as a |method|: > 10939 mylist->string() 10940 10941< Also see |strtrans()|. 10942 10943 10944strlen({string}) *strlen()* 10945 The result is a Number, which is the length of the String 10946 {string} in bytes. 10947 If the argument is a Number it is first converted to a String. 10948 For other types an error is given. 10949 If you want to count the number of multibyte characters use 10950 |strchars()|. 10951 Also see |len()|, |strdisplaywidth()| and |strwidth()|. 10952 10953 Can also be used as a |method|: > 10954 GetString()->strlen() 10955 10956strpart({src}, {start} [, {len} [, {chars}]]) *strpart()* 10957 The result is a String, which is part of {src}, starting from 10958 byte {start}, with the byte length {len}. 10959 When {chars} is present and TRUE then {len} is the number of 10960 characters positions (composing characters are not counted 10961 separately, thus "1" means one base character and any 10962 following composing characters). 10963 To count {start} as characters instead of bytes use 10964 |strcharpart()|. 10965 10966 When bytes are selected which do not exist, this doesn't 10967 result in an error, the bytes are simply omitted. 10968 If {len} is missing, the copy continues from {start} till the 10969 end of the {src}. > 10970 strpart("abcdefg", 3, 2) == "de" 10971 strpart("abcdefg", -2, 4) == "ab" 10972 strpart("abcdefg", 5, 4) == "fg" 10973 strpart("abcdefg", 3) == "defg" 10974 10975< Note: To get the first character, {start} must be 0. For 10976 example, to get the character under the cursor: > 10977 strpart(getline("."), col(".") - 1, 1, v:true) 10978< 10979 Can also be used as a |method|: > 10980 GetText()->strpart(5) 10981 10982strptime({format}, {timestring}) *strptime()* 10983 The result is a Number, which is a unix timestamp representing 10984 the date and time in {timestring}, which is expected to match 10985 the format specified in {format}. 10986 10987 The accepted {format} depends on your system, thus this is not 10988 portable! See the manual page of the C function strptime() 10989 for the format. Especially avoid "%c". The value of $TZ also 10990 matters. 10991 10992 If the {timestring} cannot be parsed with {format} zero is 10993 returned. If you do not know the format of {timestring} you 10994 can try different {format} values until you get a non-zero 10995 result. 10996 10997 See also |strftime()|. 10998 Examples: > 10999 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23") 11000< 862156163 > 11001 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55")) 11002< Sun Apr 27 11:53:55 1997 > 11003 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600) 11004< Sun Apr 27 12:53:55 1997 11005 11006 Can also be used as a |method|: > 11007 GetFormat()->strptime(timestring) 11008< 11009 Not available on all systems. To check use: > 11010 :if exists("*strptime") 11011 11012strridx({haystack}, {needle} [, {start}]) *strridx()* 11013 The result is a Number, which gives the byte index in 11014 {haystack} of the last occurrence of the String {needle}. 11015 When {start} is specified, matches beyond this index are 11016 ignored. This can be used to find a match before a previous 11017 match: > 11018 :let lastcomma = strridx(line, ",") 11019 :let comma2 = strridx(line, ",", lastcomma - 1) 11020< The search is done case-sensitive. 11021 For pattern searches use |match()|. 11022 -1 is returned if the {needle} does not occur in {haystack}. 11023 If the {needle} is empty the length of {haystack} is returned. 11024 See also |stridx()|. Examples: > 11025 :echo strridx("an angry armadillo", "an") 3 11026< *strrchr()* 11027 When used with a single character it works similar to the C 11028 function strrchr(). 11029 11030 Can also be used as a |method|: > 11031 GetHaystack()->strridx(needle) 11032 11033strtrans({string}) *strtrans()* 11034 The result is a String, which is {string} with all unprintable 11035 characters translated into printable characters |'isprint'|. 11036 Like they are shown in a window. Example: > 11037 echo strtrans(@a) 11038< This displays a newline in register a as "^@" instead of 11039 starting a new line. 11040 11041 Can also be used as a |method|: > 11042 GetString()->strtrans() 11043 11044strwidth({string}) *strwidth()* 11045 The result is a Number, which is the number of display cells 11046 String {string} occupies. A Tab character is counted as one 11047 cell, alternatively use |strdisplaywidth()|. 11048 When {string} contains characters with East Asian Width Class 11049 Ambiguous, this function's return value depends on 'ambiwidth'. 11050 Also see |strlen()|, |strdisplaywidth()| and |strchars()|. 11051 11052 Can also be used as a |method|: > 11053 GetString()->strwidth() 11054 11055submatch({nr} [, {list}]) *submatch()* *E935* 11056 Only for an expression in a |:substitute| command or 11057 substitute() function. 11058 Returns the {nr}'th submatch of the matched text. When {nr} 11059 is 0 the whole matched text is returned. 11060 Note that a NL in the string can stand for a line break of a 11061 multi-line match or a NUL character in the text. 11062 Also see |sub-replace-expression|. 11063 11064 If {list} is present and non-zero then submatch() returns 11065 a list of strings, similar to |getline()| with two arguments. 11066 NL characters in the text represent NUL characters in the 11067 text. 11068 Only returns more than one item for |:substitute|, inside 11069 |substitute()| this list will always contain one or zero 11070 items, since there are no real line breaks. 11071 11072 When substitute() is used recursively only the submatches in 11073 the current (deepest) call can be obtained. 11074 11075 Examples: > 11076 :s/\d\+/\=submatch(0) + 1/ 11077 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '') 11078< This finds the first number in the line and adds one to it. 11079 A line break is included as a newline character. 11080 11081 Can also be used as a |method|: > 11082 GetNr()->submatch() 11083 11084substitute({string}, {pat}, {sub}, {flags}) *substitute()* 11085 The result is a String, which is a copy of {string}, in which 11086 the first match of {pat} is replaced with {sub}. 11087 When {flags} is "g", all matches of {pat} in {string} are 11088 replaced. Otherwise {flags} should be "". 11089 11090 This works like the ":substitute" command (without any flags). 11091 But the matching with {pat} is always done like the 'magic' 11092 option is set and 'cpoptions' is empty (to make scripts 11093 portable). 'ignorecase' is still relevant, use |/\c| or |/\C| 11094 if you want to ignore or match case and ignore 'ignorecase'. 11095 'smartcase' is not used. See |string-match| for how {pat} is 11096 used. 11097 11098 A "~" in {sub} is not replaced with the previous {sub}. 11099 Note that some codes in {sub} have a special meaning 11100 |sub-replace-special|. For example, to replace something with 11101 "\n" (two characters), use "\\\\n" or '\\n'. 11102 11103 When {pat} does not match in {string}, {string} is returned 11104 unmodified. 11105 11106 Example: > 11107 :let &path = substitute(&path, ",\\=[^,]*$", "", "") 11108< This removes the last component of the 'path' option. > 11109 :echo substitute("testing", ".*", "\\U\\0", "") 11110< results in "TESTING". 11111 11112 When {sub} starts with "\=", the remainder is interpreted as 11113 an expression. See |sub-replace-expression|. Example: > 11114 :echo substitute(s, '%\(\x\x\)', 11115 \ '\=nr2char("0x" . submatch(1))', 'g') 11116 11117< When {sub} is a Funcref that function is called, with one 11118 optional argument. Example: > 11119 :echo substitute(s, '%\(\x\x\)', SubNr, 'g') 11120< The optional argument is a list which contains the whole 11121 matched string and up to nine submatches, like what 11122 |submatch()| returns. Example: > 11123 :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g') 11124 11125< Can also be used as a |method|: > 11126 GetString()->substitute(pat, sub, flags) 11127 11128swapinfo({fname}) *swapinfo()* 11129 The result is a dictionary, which holds information about the 11130 swapfile {fname}. The available fields are: 11131 version Vim version 11132 user user name 11133 host host name 11134 fname original file name 11135 pid PID of the Vim process that created the swap 11136 file 11137 mtime last modification time in seconds 11138 inode Optional: INODE number of the file 11139 dirty 1 if file was modified, 0 if not 11140 Note that "user" and "host" are truncated to at most 39 bytes. 11141 In case of failure an "error" item is added with the reason: 11142 Cannot open file: file not found or in accessible 11143 Cannot read file: cannot read first block 11144 Not a swap file: does not contain correct block ID 11145 Magic number mismatch: Info in first block is invalid 11146 11147 Can also be used as a |method|: > 11148 GetFilename()->swapinfo() 11149 11150swapname({buf}) *swapname()* 11151 The result is the swap file path of the buffer {expr}. 11152 For the use of {buf}, see |bufname()| above. 11153 If buffer {buf} is the current buffer, the result is equal to 11154 |:swapname| (unless there is no swap file). 11155 If buffer {buf} has no swap file, returns an empty string. 11156 11157 Can also be used as a |method|: > 11158 GetBufname()->swapname() 11159 11160synID({lnum}, {col}, {trans}) *synID()* 11161 The result is a Number, which is the syntax ID at the position 11162 {lnum} and {col} in the current window. 11163 The syntax ID can be used with |synIDattr()| and 11164 |synIDtrans()| to obtain syntax information about text. 11165 11166 {col} is 1 for the leftmost column, {lnum} is 1 for the first 11167 line. 'synmaxcol' applies, in a longer line zero is returned. 11168 Note that when the position is after the last character, 11169 that's where the cursor can be in Insert mode, synID() returns 11170 zero. {lnum} is used like with |getline()|. 11171 11172 When {trans} is |TRUE|, transparent items are reduced to the 11173 item that they reveal. This is useful when wanting to know 11174 the effective color. When {trans} is |FALSE|, the transparent 11175 item is returned. This is useful when wanting to know which 11176 syntax item is effective (e.g. inside parens). 11177 Warning: This function can be very slow. Best speed is 11178 obtained by going through the file in forward direction. 11179 11180 Example (echoes the name of the syntax item under the cursor): > 11181 :echo synIDattr(synID(line("."), col("."), 1), "name") 11182< 11183 11184synIDattr({synID}, {what} [, {mode}]) *synIDattr()* 11185 The result is a String, which is the {what} attribute of 11186 syntax ID {synID}. This can be used to obtain information 11187 about a syntax item. 11188 {mode} can be "gui", "cterm" or "term", to get the attributes 11189 for that mode. When {mode} is omitted, or an invalid value is 11190 used, the attributes for the currently active highlighting are 11191 used (GUI, cterm or term). 11192 Use synIDtrans() to follow linked highlight groups. 11193 {what} result 11194 "name" the name of the syntax item 11195 "fg" foreground color (GUI: color name used to set 11196 the color, cterm: color number as a string, 11197 term: empty string) 11198 "bg" background color (as with "fg") 11199 "font" font name (only available in the GUI) 11200 |highlight-font| 11201 "sp" special color for the GUI (as with "fg") 11202 |highlight-guisp| 11203 "ul" underline color for cterm: number as a string 11204 "fg#" like "fg", but for the GUI and the GUI is 11205 running the name in "#RRGGBB" form 11206 "bg#" like "fg#" for "bg" 11207 "sp#" like "fg#" for "sp" 11208 "bold" "1" if bold 11209 "italic" "1" if italic 11210 "reverse" "1" if reverse 11211 "inverse" "1" if inverse (= reverse) 11212 "standout" "1" if standout 11213 "underline" "1" if underlined 11214 "undercurl" "1" if undercurled 11215 "strike" "1" if strikethrough 11216 11217 Example (echoes the color of the syntax item under the 11218 cursor): > 11219 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") 11220< 11221 Can also be used as a |method|: > 11222 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") 11223 11224 11225synIDtrans({synID}) *synIDtrans()* 11226 The result is a Number, which is the translated syntax ID of 11227 {synID}. This is the syntax group ID of what is being used to 11228 highlight the character. Highlight links given with 11229 ":highlight link" are followed. 11230 11231 Can also be used as a |method|: > 11232 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") 11233 11234synconcealed({lnum}, {col}) *synconcealed()* 11235 The result is a |List| with currently three items: 11236 1. The first item in the list is 0 if the character at the 11237 position {lnum} and {col} is not part of a concealable 11238 region, 1 if it is. {lnum} is used like with |getline()|. 11239 2. The second item in the list is a string. If the first item 11240 is 1, the second item contains the text which will be 11241 displayed in place of the concealed text, depending on the 11242 current setting of 'conceallevel' and 'listchars'. 11243 3. The third and final item in the list is a number 11244 representing the specific syntax region matched in the 11245 line. When the character is not concealed the value is 11246 zero. This allows detection of the beginning of a new 11247 concealable region if there are two consecutive regions 11248 with the same replacement character. For an example, if 11249 the text is "123456" and both "23" and "45" are concealed 11250 and replaced by the character "X", then: 11251 call returns ~ 11252 synconcealed(lnum, 1) [0, '', 0] 11253 synconcealed(lnum, 2) [1, 'X', 1] 11254 synconcealed(lnum, 3) [1, 'X', 1] 11255 synconcealed(lnum, 4) [1, 'X', 2] 11256 synconcealed(lnum, 5) [1, 'X', 2] 11257 synconcealed(lnum, 6) [0, '', 0] 11258 11259 11260synstack({lnum}, {col}) *synstack()* 11261 Return a |List|, which is the stack of syntax items at the 11262 position {lnum} and {col} in the current window. {lnum} is 11263 used like with |getline()|. Each item in the List is an ID 11264 like what |synID()| returns. 11265 The first item in the List is the outer region, following are 11266 items contained in that one. The last one is what |synID()| 11267 returns, unless not the whole item is highlighted or it is a 11268 transparent item. 11269 This function is useful for debugging a syntax file. 11270 Example that shows the syntax stack under the cursor: > 11271 for id in synstack(line("."), col(".")) 11272 echo synIDattr(id, "name") 11273 endfor 11274< When the position specified with {lnum} and {col} is invalid 11275 nothing is returned. The position just after the last 11276 character in a line and the first column in an empty line are 11277 valid positions. 11278 11279system({expr} [, {input}]) *system()* *E677* 11280 Get the output of the shell command {expr} as a |String|. See 11281 |systemlist()| to get the output as a |List|. 11282 11283 When {input} is given and is a |String| this string is written 11284 to a file and passed as stdin to the command. The string is 11285 written as-is, you need to take care of using the correct line 11286 separators yourself. 11287 If {input} is given and is a |List| it is written to the file 11288 in a way |writefile()| does with {binary} set to "b" (i.e. 11289 with a newline between each list item with newlines inside 11290 list items converted to NULs). 11291 When {input} is given and is a number that is a valid id for 11292 an existing buffer then the content of the buffer is written 11293 to the file line by line, each line terminated by a NL and 11294 NULs characters where the text has a NL. 11295 11296 Pipes are not used, the 'shelltemp' option is not used. 11297 11298 When prepended by |:silent| the terminal will not be set to 11299 cooked mode. This is meant to be used for commands that do 11300 not need the user to type. It avoids stray characters showing 11301 up on the screen which require |CTRL-L| to remove. > 11302 :silent let f = system('ls *.vim') 11303< 11304 Note: Use |shellescape()| or |::S| with |expand()| or 11305 |fnamemodify()| to escape special characters in a command 11306 argument. Newlines in {expr} may cause the command to fail. 11307 The characters in 'shellquote' and 'shellxquote' may also 11308 cause trouble. 11309 This is not to be used for interactive commands. 11310 11311 The result is a String. Example: > 11312 :let files = system("ls " . shellescape(expand('%:h'))) 11313 :let files = system('ls ' . expand('%:h:S')) 11314 11315< To make the result more system-independent, the shell output 11316 is filtered to replace <CR> with <NL> for Macintosh, and 11317 <CR><NL> with <NL> for DOS-like systems. 11318 To avoid the string being truncated at a NUL, all NUL 11319 characters are replaced with SOH (0x01). 11320 11321 The command executed is constructed using several options: 11322 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote' 11323 ({tmp} is an automatically generated file name). 11324 For Unix, braces are put around {expr} to allow for 11325 concatenated commands. 11326 11327 The command will be executed in "cooked" mode, so that a 11328 CTRL-C will interrupt the command (on Unix at least). 11329 11330 The resulting error code can be found in |v:shell_error|. 11331 This function will fail in |restricted-mode|. 11332 11333 Note that any wrong value in the options mentioned above may 11334 make the function fail. It has also been reported to fail 11335 when using a security agent application. 11336 Unlike ":!cmd" there is no automatic check for changed files. 11337 Use |:checktime| to force a check. 11338 11339 Can also be used as a |method|: > 11340 :echo GetCmd()->system() 11341 11342 11343systemlist({expr} [, {input}]) *systemlist()* 11344 Same as |system()|, but returns a |List| with lines (parts of 11345 output separated by NL) with NULs transformed into NLs. Output 11346 is the same as |readfile()| will output with {binary} argument 11347 set to "b", except that there is no extra empty item when the 11348 result ends in a NL. 11349 Note that on MS-Windows you may get trailing CR characters. 11350 11351 To see the difference between "echo hello" and "echo -n hello" 11352 use |system()| and |split()|: > 11353 echo system('echo hello')->split('\n', 1) 11354< 11355 Returns an empty string on error. 11356 11357 Can also be used as a |method|: > 11358 :echo GetCmd()->systemlist() 11359 11360 11361tabpagebuflist([{arg}]) *tabpagebuflist()* 11362 The result is a |List|, where each item is the number of the 11363 buffer associated with each window in the current tab page. 11364 {arg} specifies the number of the tab page to be used. When 11365 omitted the current tab page is used. 11366 When {arg} is invalid the number zero is returned. 11367 To get a list of all buffers in all tabs use this: > 11368 let buflist = [] 11369 for i in range(tabpagenr('$')) 11370 call extend(buflist, tabpagebuflist(i + 1)) 11371 endfor 11372< Note that a buffer may appear in more than one window. 11373 11374 Can also be used as a |method|: > 11375 GetTabpage()->tabpagebuflist() 11376 11377tabpagenr([{arg}]) *tabpagenr()* 11378 The result is a Number, which is the number of the current 11379 tab page. The first tab page has number 1. 11380 11381 The optional argument {arg} supports the following values: 11382 $ the number of the last tab page (the tab page 11383 count). 11384 # the number of the last accessed tab page 11385 (where |g<Tab>| goes to). if there is no 11386 previous tab page 0 is returned. 11387 The number can be used with the |:tab| command. 11388 11389 11390tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()* 11391 Like |winnr()| but for tab page {tabarg}. 11392 {tabarg} specifies the number of tab page to be used. 11393 {arg} is used like with |winnr()|: 11394 - When omitted the current window number is returned. This is 11395 the window which will be used when going to this tab page. 11396 - When "$" the number of windows is returned. 11397 - When "#" the previous window nr is returned. 11398 Useful examples: > 11399 tabpagewinnr(1) " current window of tab page 1 11400 tabpagewinnr(4, '$') " number of windows in tab page 4 11401< When {tabarg} is invalid zero is returned. 11402 11403 Can also be used as a |method|: > 11404 GetTabpage()->tabpagewinnr() 11405< 11406 *tagfiles()* 11407tagfiles() Returns a |List| with the file names used to search for tags 11408 for the current buffer. This is the 'tags' option expanded. 11409 11410 11411taglist({expr} [, {filename}]) *taglist()* 11412 Returns a |List| of tags matching the regular expression {expr}. 11413 11414 If {filename} is passed it is used to prioritize the results 11415 in the same way that |:tselect| does. See |tag-priority|. 11416 {filename} should be the full path of the file. 11417 11418 Each list item is a dictionary with at least the following 11419 entries: 11420 name Name of the tag. 11421 filename Name of the file where the tag is 11422 defined. It is either relative to the 11423 current directory or a full path. 11424 cmd Ex command used to locate the tag in 11425 the file. 11426 kind Type of the tag. The value for this 11427 entry depends on the language specific 11428 kind values. Only available when 11429 using a tags file generated by 11430 Exuberant ctags or hdrtag. 11431 static A file specific tag. Refer to 11432 |static-tag| for more information. 11433 More entries may be present, depending on the content of the 11434 tags file: access, implementation, inherits and signature. 11435 Refer to the ctags documentation for information about these 11436 fields. For C code the fields "struct", "class" and "enum" 11437 may appear, they give the name of the entity the tag is 11438 contained in. 11439 11440 The ex-command "cmd" can be either an ex search pattern, a 11441 line number or a line number followed by a byte number. 11442 11443 If there are no matching tags, then an empty list is returned. 11444 11445 To get an exact tag match, the anchors '^' and '$' should be 11446 used in {expr}. This also make the function work faster. 11447 Refer to |tag-regexp| for more information about the tag 11448 search regular expression pattern. 11449 11450 Refer to |'tags'| for information about how the tags file is 11451 located by Vim. Refer to |tags-file-format| for the format of 11452 the tags file generated by the different ctags tools. 11453 11454 Can also be used as a |method|: > 11455 GetTagpattern()->taglist() 11456 11457tan({expr}) *tan()* 11458 Return the tangent of {expr}, measured in radians, as a |Float| 11459 in the range [-inf, inf]. 11460 {expr} must evaluate to a |Float| or a |Number|. 11461 Examples: > 11462 :echo tan(10) 11463< 0.648361 > 11464 :echo tan(-4.01) 11465< -1.181502 11466 11467 Can also be used as a |method|: > 11468 Compute()->tan() 11469< 11470 {only available when compiled with the |+float| feature} 11471 11472 11473tanh({expr}) *tanh()* 11474 Return the hyperbolic tangent of {expr} as a |Float| in the 11475 range [-1, 1]. 11476 {expr} must evaluate to a |Float| or a |Number|. 11477 Examples: > 11478 :echo tanh(0.5) 11479< 0.462117 > 11480 :echo tanh(-1) 11481< -0.761594 11482 11483 Can also be used as a |method|: > 11484 Compute()->tanh() 11485< 11486 {only available when compiled with the |+float| feature} 11487 11488 11489tempname() *tempname()* *temp-file-name* 11490 The result is a String, which is the name of a file that 11491 doesn't exist. It can be used for a temporary file. The name 11492 is different for at least 26 consecutive calls. Example: > 11493 :let tmpfile = tempname() 11494 :exe "redir > " . tmpfile 11495< For Unix, the file will be in a private directory |tempfile|. 11496 For MS-Windows forward slashes are used when the 'shellslash' 11497 option is set, or when 'shellcmdflag' starts with '-' and 11498 'shell' does not contain powershell or pwsh. 11499 11500 11501term_ functions are documented here: |terminal-function-details| 11502 11503 11504terminalprops() *terminalprops()* 11505 Returns a |Dictionary| with properties of the terminal that Vim 11506 detected from the response to |t_RV| request. See 11507 |v:termresponse| for the response itself. If |v:termresponse| 11508 is empty most values here will be 'u' for unknown. 11509 cursor_style whether sending |t_RS| works ** 11510 cursor_blink_mode whether sending |t_RC| works ** 11511 underline_rgb whether |t_8u| works ** 11512 mouse mouse type supported 11513 11514 ** value 'u' for unknown, 'y' for yes, 'n' for no 11515 11516 If the |+termresponse| feature is missing then the result is 11517 an empty dictionary. 11518 11519 If "cursor_style" is 'y' then |t_RS| will be sent to request the 11520 current cursor style. 11521 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to 11522 request the cursor blink status. 11523 "cursor_style" and "cursor_blink_mode" are also set if |t_u7| 11524 is not empty, Vim will detect the working of sending |t_RS| 11525 and |t_RC| on startup. 11526 11527 When "underline_rgb" is not 'y', then |t_8u| will be made empty. 11528 This avoids sending it to xterm, which would clear the colors. 11529 11530 For "mouse" the value 'u' is unknown 11531 11532 Also see: 11533 - 'ambiwidth' - detected by using |t_u7|. 11534 - |v:termstyleresp| and |v:termblinkresp| for the response to 11535 |t_RS| and |t_RC|. 11536 11537 11538test_ functions are documented here: |test-functions-details| 11539 11540 11541 *timer_info()* 11542timer_info([{id}]) 11543 Return a list with information about timers. 11544 When {id} is given only information about this timer is 11545 returned. When timer {id} does not exist an empty list is 11546 returned. 11547 When {id} is omitted information about all timers is returned. 11548 11549 For each timer the information is stored in a |Dictionary| with 11550 these items: 11551 "id" the timer ID 11552 "time" time the timer was started with 11553 "remaining" time until the timer fires 11554 "repeat" number of times the timer will still fire; 11555 -1 means forever 11556 "callback" the callback 11557 "paused" 1 if the timer is paused, 0 otherwise 11558 11559 Can also be used as a |method|: > 11560 GetTimer()->timer_info() 11561 11562< {only available when compiled with the |+timers| feature} 11563 11564timer_pause({timer}, {paused}) *timer_pause()* 11565 Pause or unpause a timer. A paused timer does not invoke its 11566 callback when its time expires. Unpausing a timer may cause 11567 the callback to be invoked almost immediately if enough time 11568 has passed. 11569 11570 Pausing a timer is useful to avoid the callback to be called 11571 for a short time. 11572 11573 If {paused} evaluates to a non-zero Number or a non-empty 11574 String, then the timer is paused, otherwise it is unpaused. 11575 See |non-zero-arg|. 11576 11577 Can also be used as a |method|: > 11578 GetTimer()->timer_pause(1) 11579 11580< {only available when compiled with the |+timers| feature} 11581 11582 *timer_start()* *timer* *timers* 11583timer_start({time}, {callback} [, {options}]) 11584 Create a timer and return the timer ID. 11585 11586 {time} is the waiting time in milliseconds. This is the 11587 minimum time before invoking the callback. When the system is 11588 busy or Vim is not waiting for input the time will be longer. 11589 11590 {callback} is the function to call. It can be the name of a 11591 function or a |Funcref|. It is called with one argument, which 11592 is the timer ID. The callback is only invoked when Vim is 11593 waiting for input. 11594 If you want to show a message look at |popup_notification()| 11595 to avoid interfering with what the user is doing. 11596 11597 {options} is a dictionary. Supported entries: 11598 "repeat" Number of times to repeat calling the 11599 callback. -1 means forever. When not present 11600 the callback will be called once. 11601 If the timer causes an error three times in a 11602 row the repeat is cancelled. This avoids that 11603 Vim becomes unusable because of all the error 11604 messages. 11605 11606 Example: > 11607 func MyHandler(timer) 11608 echo 'Handler called' 11609 endfunc 11610 let timer = timer_start(500, 'MyHandler', 11611 \ {'repeat': 3}) 11612< This will invoke MyHandler() three times at 500 msec 11613 intervals. 11614 11615 Can also be used as a |method|: > 11616 GetMsec()->timer_start(callback) 11617 11618< Not available in the |sandbox|. 11619 {only available when compiled with the |+timers| feature} 11620 11621timer_stop({timer}) *timer_stop()* 11622 Stop a timer. The timer callback will no longer be invoked. 11623 {timer} is an ID returned by timer_start(), thus it must be a 11624 Number. If {timer} does not exist there is no error. 11625 11626 Can also be used as a |method|: > 11627 GetTimer()->timer_stop() 11628 11629< {only available when compiled with the |+timers| feature} 11630 11631timer_stopall() *timer_stopall()* 11632 Stop all timers. The timer callbacks will no longer be 11633 invoked. Useful if a timer is misbehaving. If there are no 11634 timers there is no error. 11635 11636 {only available when compiled with the |+timers| feature} 11637 11638tolower({expr}) *tolower()* 11639 The result is a copy of the String given, with all uppercase 11640 characters turned into lowercase (just like applying |gu| to 11641 the string). 11642 11643 Can also be used as a |method|: > 11644 GetText()->tolower() 11645 11646toupper({expr}) *toupper()* 11647 The result is a copy of the String given, with all lowercase 11648 characters turned into uppercase (just like applying |gU| to 11649 the string). 11650 11651 Can also be used as a |method|: > 11652 GetText()->toupper() 11653 11654tr({src}, {fromstr}, {tostr}) *tr()* 11655 The result is a copy of the {src} string with all characters 11656 which appear in {fromstr} replaced by the character in that 11657 position in the {tostr} string. Thus the first character in 11658 {fromstr} is translated into the first character in {tostr} 11659 and so on. Exactly like the unix "tr" command. 11660 This code also deals with multibyte characters properly. 11661 11662 Examples: > 11663 echo tr("hello there", "ht", "HT") 11664< returns "Hello THere" > 11665 echo tr("<blob>", "<>", "{}") 11666< returns "{blob}" 11667 11668 Can also be used as a |method|: > 11669 GetText()->tr(from, to) 11670 11671trim({text} [, {mask} [, {dir}]]) *trim()* 11672 Return {text} as a String where any character in {mask} is 11673 removed from the beginning and/or end of {text}. 11674 11675 If {mask} is not given, {mask} is all characters up to 0x20, 11676 which includes Tab, space, NL and CR, plus the non-breaking 11677 space character 0xa0. 11678 11679 The optional {dir} argument specifies where to remove the 11680 characters: 11681 0 remove from the beginning and end of {text} 11682 1 remove only at the beginning of {text} 11683 2 remove only at the end of {text} 11684 When omitted both ends are trimmed. 11685 11686 This function deals with multibyte characters properly. 11687 11688 Examples: > 11689 echo trim(" some text ") 11690< returns "some text" > 11691 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") . "_TAIL" 11692< returns "RESERVE_TAIL" > 11693 echo trim("rm<Xrm<>X>rrm", "rm<>") 11694< returns "Xrm<>X" (characters in the middle are not removed) > 11695 echo trim(" vim ", " ", 2) 11696< returns " vim" 11697 11698 Can also be used as a |method|: > 11699 GetText()->trim() 11700 11701trunc({expr}) *trunc()* 11702 Return the largest integral value with magnitude less than or 11703 equal to {expr} as a |Float| (truncate towards zero). 11704 {expr} must evaluate to a |Float| or a |Number|. 11705 Examples: > 11706 echo trunc(1.456) 11707< 1.0 > 11708 echo trunc(-5.456) 11709< -5.0 > 11710 echo trunc(4.0) 11711< 4.0 11712 11713 Can also be used as a |method|: > 11714 Compute()->trunc() 11715< 11716 {only available when compiled with the |+float| feature} 11717 11718 *type()* 11719type({expr}) The result is a Number representing the type of {expr}. 11720 Instead of using the number directly, it is better to use the 11721 v:t_ variable that has the value: 11722 Number: 0 |v:t_number| 11723 String: 1 |v:t_string| 11724 Funcref: 2 |v:t_func| 11725 List: 3 |v:t_list| 11726 Dictionary: 4 |v:t_dict| 11727 Float: 5 |v:t_float| 11728 Boolean: 6 |v:t_bool| (v:false and v:true) 11729 None: 7 |v:t_none| (v:null and v:none) 11730 Job: 8 |v:t_job| 11731 Channel: 9 |v:t_channel| 11732 Blob: 10 |v:t_blob| 11733 For backward compatibility, this method can be used: > 11734 :if type(myvar) == type(0) 11735 :if type(myvar) == type("") 11736 :if type(myvar) == type(function("tr")) 11737 :if type(myvar) == type([]) 11738 :if type(myvar) == type({}) 11739 :if type(myvar) == type(0.0) 11740 :if type(myvar) == type(v:false) 11741 :if type(myvar) == type(v:none) 11742< To check if the v:t_ variables exist use this: > 11743 :if exists('v:t_number') 11744 11745< Can also be used as a |method|: > 11746 mylist->type() 11747 11748 11749typename({expr}) *typename()* 11750 Return a string representation of the type of {expr}. 11751 Example: > 11752 echo typename([1, 2, 3]) 11753 list<number> 11754 11755 11756undofile({name}) *undofile()* 11757 Return the name of the undo file that would be used for a file 11758 with name {name} when writing. This uses the 'undodir' 11759 option, finding directories that exist. It does not check if 11760 the undo file exists. 11761 {name} is always expanded to the full path, since that is what 11762 is used internally. 11763 If {name} is empty undofile() returns an empty string, since a 11764 buffer without a file name will not write an undo file. 11765 Useful in combination with |:wundo| and |:rundo|. 11766 When compiled without the |+persistent_undo| option this always 11767 returns an empty string. 11768 11769 Can also be used as a |method|: > 11770 GetFilename()->undofile() 11771 11772undotree() *undotree()* 11773 Return the current state of the undo tree in a dictionary with 11774 the following items: 11775 "seq_last" The highest undo sequence number used. 11776 "seq_cur" The sequence number of the current position in 11777 the undo tree. This differs from "seq_last" 11778 when some changes were undone. 11779 "time_cur" Time last used for |:earlier| and related 11780 commands. Use |strftime()| to convert to 11781 something readable. 11782 "save_last" Number of the last file write. Zero when no 11783 write yet. 11784 "save_cur" Number of the current position in the undo 11785 tree. 11786 "synced" Non-zero when the last undo block was synced. 11787 This happens when waiting from input from the 11788 user. See |undo-blocks|. 11789 "entries" A list of dictionaries with information about 11790 undo blocks. 11791 11792 The first item in the "entries" list is the oldest undo item. 11793 Each List item is a |Dictionary| with these items: 11794 "seq" Undo sequence number. Same as what appears in 11795 |:undolist|. 11796 "time" Timestamp when the change happened. Use 11797 |strftime()| to convert to something readable. 11798 "newhead" Only appears in the item that is the last one 11799 that was added. This marks the last change 11800 and where further changes will be added. 11801 "curhead" Only appears in the item that is the last one 11802 that was undone. This marks the current 11803 position in the undo tree, the block that will 11804 be used by a redo command. When nothing was 11805 undone after the last change this item will 11806 not appear anywhere. 11807 "save" Only appears on the last block before a file 11808 write. The number is the write count. The 11809 first write has number 1, the last one the 11810 "save_last" mentioned above. 11811 "alt" Alternate entry. This is again a List of undo 11812 blocks. Each item may again have an "alt" 11813 item. 11814 11815uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* 11816 Remove second and succeeding copies of repeated adjacent 11817 {list} items in-place. Returns {list}. If you want a list 11818 to remain unmodified make a copy first: > 11819 :let newlist = uniq(copy(mylist)) 11820< The default compare function uses the string representation of 11821 each item. For the use of {func} and {dict} see |sort()|. 11822 11823 Can also be used as a |method|: > 11824 mylist->uniq() 11825 11826values({dict}) *values()* 11827 Return a |List| with all the values of {dict}. The |List| is 11828 in arbitrary order. Also see |items()| and |keys()|. 11829 11830 Can also be used as a |method|: > 11831 mydict->values() 11832 11833virtcol({expr}) *virtcol()* 11834 The result is a Number, which is the screen column of the file 11835 position given with {expr}. That is, the last screen position 11836 occupied by the character at that position, when the screen 11837 would be of unlimited width. When there is a <Tab> at the 11838 position, the returned Number will be the column at the end of 11839 the <Tab>. For example, for a <Tab> in column 1, with 'ts' 11840 set to 8, it returns 8. |conceal| is ignored. 11841 For the byte position use |col()|. 11842 For the use of {expr} see |col()|. 11843 When 'virtualedit' is used {expr} can be [lnum, col, off], where 11844 "off" is the offset in screen columns from the start of the 11845 character. E.g., a position within a <Tab> or after the last 11846 character. When "off" is omitted zero is used. 11847 When Virtual editing is active in the current mode, a position 11848 beyond the end of the line can be returned. |'virtualedit'| 11849 The accepted positions are: 11850 . the cursor position 11851 $ the end of the cursor line (the result is the 11852 number of displayed characters in the cursor line 11853 plus one) 11854 'x position of mark x (if the mark is not set, 0 is 11855 returned) 11856 v In Visual mode: the start of the Visual area (the 11857 cursor is the end). When not in Visual mode 11858 returns the cursor position. Differs from |'<| in 11859 that it's updated right away. 11860 Note that only marks in the current file can be used. 11861 Examples: > 11862 virtcol(".") with text "foo^Lbar", with cursor on the "^L", returns 5 11863 virtcol("$") with text "foo^Lbar", returns 9 11864 virtcol("'t") with text " there", with 't at 'h', returns 6 11865< The first column is 1. 0 is returned for an error. 11866 A more advanced example that echoes the maximum length of 11867 all lines: > 11868 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) 11869 11870< Can also be used as a |method|: > 11871 GetPos()->virtcol() 11872 11873 11874visualmode([{expr}]) *visualmode()* 11875 The result is a String, which describes the last Visual mode 11876 used in the current buffer. Initially it returns an empty 11877 string, but once Visual mode has been used, it returns "v", 11878 "V", or "<CTRL-V>" (a single CTRL-V character) for 11879 character-wise, line-wise, or block-wise Visual mode 11880 respectively. 11881 Example: > 11882 :exe "normal " . visualmode() 11883< This enters the same Visual mode as before. It is also useful 11884 in scripts if you wish to act differently depending on the 11885 Visual mode that was used. 11886 If Visual mode is active, use |mode()| to get the Visual mode 11887 (e.g., in a |:vmap|). 11888 If {expr} is supplied and it evaluates to a non-zero Number or 11889 a non-empty String, then the Visual mode will be cleared and 11890 the old value is returned. See |non-zero-arg|. 11891 11892wildmenumode() *wildmenumode()* 11893 Returns |TRUE| when the wildmenu is active and |FALSE| 11894 otherwise. See 'wildmenu' and 'wildmode'. 11895 This can be used in mappings to handle the 'wildcharm' option 11896 gracefully. (Makes only sense with |mapmode-c| mappings). 11897 11898 For example to make <c-j> work like <down> in wildmode, use: > 11899 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>" 11900< 11901 (Note, this needs the 'wildcharm' option set appropriately). 11902 11903win_execute({id}, {command} [, {silent}]) *win_execute()* 11904 Like `execute()` but in the context of window {id}. 11905 The window will temporarily be made the current window, 11906 without triggering autocommands or changing directory. When 11907 executing {command} autocommands will be triggered, this may 11908 have unexpected side effects. Use |:noautocmd| if needed. 11909 Example: > 11910 call win_execute(winid, 'set syntax=python') 11911< Doing the same with `setwinvar()` would not trigger 11912 autocommands and not actually show syntax highlighting. 11913 11914 *E994* 11915 Not all commands are allowed in popup windows. 11916 When window {id} does not exist then no error is given and 11917 an empty string is returned. 11918 11919 Can also be used as a |method|, the base is passed as the 11920 second argument: > 11921 GetCommand()->win_execute(winid) 11922 11923win_findbuf({bufnr}) *win_findbuf()* 11924 Returns a |List| with |window-ID|s for windows that contain 11925 buffer {bufnr}. When there is none the list is empty. 11926 11927 Can also be used as a |method|: > 11928 GetBufnr()->win_findbuf() 11929 11930win_getid([{win} [, {tab}]]) *win_getid()* 11931 Get the |window-ID| for the specified window. 11932 When {win} is missing use the current window. 11933 With {win} this is the window number. The top window has 11934 number 1. 11935 Without {tab} use the current tab, otherwise the tab with 11936 number {tab}. The first tab has number one. 11937 Return zero if the window cannot be found. 11938 11939 Can also be used as a |method|: > 11940 GetWinnr()->win_getid() 11941 11942 11943win_gettype([{nr}]) *win_gettype()* 11944 Return the type of the window: 11945 "autocmd" autocommand window. Temporary window 11946 used to execute autocommands. 11947 "command" command-line window |cmdwin| 11948 (empty) normal window 11949 "loclist" |location-list-window| 11950 "popup" popup window |popup| 11951 "preview" preview window |preview-window| 11952 "quickfix" |quickfix-window| 11953 "unknown" window {nr} not found 11954 11955 When {nr} is omitted return the type of the current window. 11956 When {nr} is given return the type of this window by number or 11957 |window-ID|. 11958 11959 Also see the 'buftype' option. When running a terminal in a 11960 popup window then 'buftype' is "terminal" and win_gettype() 11961 returns "popup". 11962 11963 Can also be used as a |method|: > 11964 GetWinid()->win_gettype() 11965< 11966win_gotoid({expr}) *win_gotoid()* 11967 Go to window with ID {expr}. This may also change the current 11968 tabpage. 11969 Return TRUE if successful, FALSE if the window cannot be found. 11970 11971 Can also be used as a |method|: > 11972 GetWinid()->win_gotoid() 11973 11974win_id2tabwin({expr}) *win_id2tabwin()* 11975 Return a list with the tab number and window number of window 11976 with ID {expr}: [tabnr, winnr]. 11977 Return [0, 0] if the window cannot be found. 11978 11979 Can also be used as a |method|: > 11980 GetWinid()->win_id2tabwin() 11981 11982win_id2win({expr}) *win_id2win()* 11983 Return the window number of window with ID {expr}. 11984 Return 0 if the window cannot be found in the current tabpage. 11985 11986 Can also be used as a |method|: > 11987 GetWinid()->win_id2win() 11988 11989win_screenpos({nr}) *win_screenpos()* 11990 Return the screen position of window {nr} as a list with two 11991 numbers: [row, col]. The first window always has position 11992 [1, 1], unless there is a tabline, then it is [2, 1]. 11993 {nr} can be the window number or the |window-ID|. Use zero 11994 for the current window. 11995 Returns [0, 0] if the window cannot be found in the current 11996 tabpage. 11997 11998 Can also be used as a |method|: > 11999 GetWinid()->win_screenpos() 12000< 12001win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* 12002 Move the window {nr} to a new split of the window {target}. 12003 This is similar to moving to {target}, creating a new window 12004 using |:split| but having the same contents as window {nr}, and 12005 then closing {nr}. 12006 12007 Both {nr} and {target} can be window numbers or |window-ID|s. 12008 Both must be in the current tab page. 12009 12010 Returns zero for success, non-zero for failure. 12011 12012 {options} is a |Dictionary| with the following optional entries: 12013 "vertical" When TRUE, the split is created vertically, 12014 like with |:vsplit|. 12015 "rightbelow" When TRUE, the split is made below or to the 12016 right (if vertical). When FALSE, it is done 12017 above or to the left (if vertical). When not 12018 present, the values of 'splitbelow' and 12019 'splitright' are used. 12020 12021 Can also be used as a |method|: > 12022 GetWinid()->win_splitmove(target) 12023< 12024 12025 *winbufnr()* 12026winbufnr({nr}) The result is a Number, which is the number of the buffer 12027 associated with window {nr}. {nr} can be the window number or 12028 the |window-ID|. 12029 When {nr} is zero, the number of the buffer in the current 12030 window is returned. 12031 When window {nr} doesn't exist, -1 is returned. 12032 Example: > 12033 :echo "The file in the current window is " . bufname(winbufnr(0)) 12034< 12035 Can also be used as a |method|: > 12036 FindWindow()->winbufnr()->bufname() 12037< 12038 *wincol()* 12039wincol() The result is a Number, which is the virtual column of the 12040 cursor in the window. This is counting screen cells from the 12041 left side of the window. The leftmost column is one. 12042 12043 *windowsversion()* 12044windowsversion() 12045 The result is a String. For MS-Windows it indicates the OS 12046 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2", 12047 Windows XP is "5.1". For non-MS-Windows systems the result is 12048 an empty string. 12049 12050winheight({nr}) *winheight()* 12051 The result is a Number, which is the height of window {nr}. 12052 {nr} can be the window number or the |window-ID|. 12053 When {nr} is zero, the height of the current window is 12054 returned. When window {nr} doesn't exist, -1 is returned. 12055 An existing window always has a height of zero or more. 12056 This excludes any window toolbar line. 12057 Examples: > 12058 :echo "The current window has " . winheight(0) . " lines." 12059 12060< Can also be used as a |method|: > 12061 GetWinid()->winheight() 12062< 12063winlayout([{tabnr}]) *winlayout()* 12064 The result is a nested List containing the layout of windows 12065 in a tabpage. 12066 12067 Without {tabnr} use the current tabpage, otherwise the tabpage 12068 with number {tabnr}. If the tabpage {tabnr} is not found, 12069 returns an empty list. 12070 12071 For a leaf window, it returns: 12072 ['leaf', {winid}] 12073 For horizontally split windows, which form a column, it 12074 returns: 12075 ['col', [{nested list of windows}]] 12076 For vertically split windows, which form a row, it returns: 12077 ['row', [{nested list of windows}]] 12078 12079 Example: > 12080 " Only one window in the tab page 12081 :echo winlayout() 12082 ['leaf', 1000] 12083 " Two horizontally split windows 12084 :echo winlayout() 12085 ['col', [['leaf', 1000], ['leaf', 1001]]] 12086 " The second tab page, with three horizontally split 12087 " windows, with two vertically split windows in the 12088 " middle window 12089 :echo winlayout(2) 12090 ['col', [['leaf', 1002], ['row', [['leaf', 1003], 12091 ['leaf', 1001]]], ['leaf', 1000]]] 12092< 12093 Can also be used as a |method|: > 12094 GetTabnr()->winlayout() 12095< 12096 *winline()* 12097winline() The result is a Number, which is the screen line of the cursor 12098 in the window. This is counting screen lines from the top of 12099 the window. The first line is one. 12100 If the cursor was moved the view on the file will be updated 12101 first, this may cause a scroll. 12102 12103 *winnr()* 12104winnr([{arg}]) The result is a Number, which is the number of the current 12105 window. The top window has number 1. 12106 Returns zero for a popup window. 12107 12108 The optional argument {arg} supports the following values: 12109 $ the number of the last window (the window 12110 count). 12111 # the number of the last accessed window (where 12112 |CTRL-W_p| goes to). If there is no previous 12113 window or it is in another tab page 0 is 12114 returned. 12115 {N}j the number of the Nth window below the 12116 current window (where |CTRL-W_j| goes to). 12117 {N}k the number of the Nth window above the current 12118 window (where |CTRL-W_k| goes to). 12119 {N}h the number of the Nth window left of the 12120 current window (where |CTRL-W_h| goes to). 12121 {N}l the number of the Nth window right of the 12122 current window (where |CTRL-W_l| goes to). 12123 The number can be used with |CTRL-W_w| and ":wincmd w" 12124 |:wincmd|. 12125 Also see |tabpagewinnr()| and |win_getid()|. 12126 Examples: > 12127 let window_count = winnr('$') 12128 let prev_window = winnr('#') 12129 let wnum = winnr('3k') 12130 12131< Can also be used as a |method|: > 12132 GetWinval()->winnr() 12133< 12134 *winrestcmd()* 12135winrestcmd() Returns a sequence of |:resize| commands that should restore 12136 the current window sizes. Only works properly when no windows 12137 are opened or closed and the current window and tab page is 12138 unchanged. 12139 Example: > 12140 :let cmd = winrestcmd() 12141 :call MessWithWindowSizes() 12142 :exe cmd 12143< 12144 *winrestview()* 12145winrestview({dict}) 12146 Uses the |Dictionary| returned by |winsaveview()| to restore 12147 the view of the current window. 12148 Note: The {dict} does not have to contain all values, that are 12149 returned by |winsaveview()|. If values are missing, those 12150 settings won't be restored. So you can use: > 12151 :call winrestview({'curswant': 4}) 12152< 12153 This will only set the curswant value (the column the cursor 12154 wants to move on vertical movements) of the cursor to column 5 12155 (yes, that is 5), while all other settings will remain the 12156 same. This is useful, if you set the cursor position manually. 12157 12158 If you have changed the values the result is unpredictable. 12159 If the window size changed the result won't be the same. 12160 12161 Can also be used as a |method|: > 12162 GetView()->winrestview() 12163< 12164 *winsaveview()* 12165winsaveview() Returns a |Dictionary| that contains information to restore 12166 the view of the current window. Use |winrestview()| to 12167 restore the view. 12168 This is useful if you have a mapping that jumps around in the 12169 buffer and you want to go back to the original view. 12170 This does not save fold information. Use the 'foldenable' 12171 option to temporarily switch off folding, so that folds are 12172 not opened when moving around. This may have side effects. 12173 The return value includes: 12174 lnum cursor line number 12175 col cursor column (Note: the first column 12176 zero, as opposed to what getpos() 12177 returns) 12178 coladd cursor column offset for 'virtualedit' 12179 curswant column for vertical movement 12180 topline first line in the window 12181 topfill filler lines, only in diff mode 12182 leftcol first column displayed; only used when 12183 'wrap' is off 12184 skipcol columns skipped 12185 Note that no option values are saved. 12186 12187 12188winwidth({nr}) *winwidth()* 12189 The result is a Number, which is the width of window {nr}. 12190 {nr} can be the window number or the |window-ID|. 12191 When {nr} is zero, the width of the current window is 12192 returned. When window {nr} doesn't exist, -1 is returned. 12193 An existing window always has a width of zero or more. 12194 Examples: > 12195 :echo "The current window has " . winwidth(0) . " columns." 12196 :if winwidth(0) <= 50 12197 : 50 wincmd | 12198 :endif 12199< For getting the terminal or screen size, see the 'columns' 12200 option. 12201 12202 Can also be used as a |method|: > 12203 GetWinid()->winwidth() 12204 12205 12206wordcount() *wordcount()* 12207 The result is a dictionary of byte/chars/word statistics for 12208 the current buffer. This is the same info as provided by 12209 |g_CTRL-G| 12210 The return value includes: 12211 bytes Number of bytes in the buffer 12212 chars Number of chars in the buffer 12213 words Number of words in the buffer 12214 cursor_bytes Number of bytes before cursor position 12215 (not in Visual mode) 12216 cursor_chars Number of chars before cursor position 12217 (not in Visual mode) 12218 cursor_words Number of words before cursor position 12219 (not in Visual mode) 12220 visual_bytes Number of bytes visually selected 12221 (only in Visual mode) 12222 visual_chars Number of chars visually selected 12223 (only in Visual mode) 12224 visual_words Number of words visually selected 12225 (only in Visual mode) 12226 12227 12228 *writefile()* 12229writefile({object}, {fname} [, {flags}]) 12230 When {object} is a |List| write it to file {fname}. Each list 12231 item is separated with a NL. Each list item must be a String 12232 or Number. 12233 When {flags} contains "b" then binary mode is used: There will 12234 not be a NL after the last list item. An empty item at the 12235 end does cause the last line in the file to end in a NL. 12236 12237 When {object} is a |Blob| write the bytes to file {fname} 12238 unmodified. 12239 12240 When {flags} contains "a" then append mode is used, lines are 12241 appended to the file: > 12242 :call writefile(["foo"], "event.log", "a") 12243 :call writefile(["bar"], "event.log", "a") 12244< 12245 When {flags} contains "s" then fsync() is called after writing 12246 the file. This flushes the file to disk, if possible. This 12247 takes more time but avoids losing the file if the system 12248 crashes. 12249 When {flags} does not contain "S" or "s" then fsync() is 12250 called if the 'fsync' option is set. 12251 When {flags} contains "S" then fsync() is not called, even 12252 when 'fsync' is set. 12253 12254 All NL characters are replaced with a NUL character. 12255 Inserting CR characters needs to be done before passing {list} 12256 to writefile(). 12257 An existing file is overwritten, if possible. 12258 When the write fails -1 is returned, otherwise 0. There is an 12259 error message if the file can't be created or when writing 12260 fails. 12261 Also see |readfile()|. 12262 To copy a file byte for byte: > 12263 :let fl = readfile("foo", "b") 12264 :call writefile(fl, "foocopy", "b") 12265 12266< Can also be used as a |method|: > 12267 GetText()->writefile("thefile") 12268 12269 12270xor({expr}, {expr}) *xor()* 12271 Bitwise XOR on the two arguments. The arguments are converted 12272 to a number. A List, Dict or Float argument causes an error. 12273 Example: > 12274 :let bits = xor(bits, 0x80) 12275< 12276 Can also be used as a |method|: > 12277 :let bits = bits->xor(0x80) 12278< 12279 12280 *feature-list* 12281There are three types of features: 122821. Features that are only supported when they have been enabled when Vim 12283 was compiled |+feature-list|. Example: > 12284 :if has("cindent") 12285< *gui_running* 122862. Features that are only supported when certain conditions have been met. 12287 Example: > 12288 :if has("gui_running") 12289< *has-patch* 122903. Beyond a certain version or at a certain version and including a specific 12291 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or 12292 later, or it is version 7.4 and patch 248 was included. Example: > 12293 :if has("patch-7.4.248") 12294< Note that it's possible for patch 248 to be omitted even though 249 is 12295 included. Only happens when cherry-picking patches. 12296 Note that this form only works for patch 7.4.237 and later, before that 12297 you need to check for the patch and the v:version. Example (checking 12298 version 6.2.148 or later): > 12299 :if v:version > 602 || (v:version == 602 && has("patch148")) 12300 12301Hint: To find out if Vim supports backslashes in a file name (MS-Windows), 12302use: `if exists('+shellslash')` 12303 12304 12305acl Compiled with |ACL| support. 12306all_builtin_terms Compiled with all builtin terminals enabled. 12307amiga Amiga version of Vim. 12308arabic Compiled with Arabic support |Arabic|. 12309arp Compiled with ARP support (Amiga). 12310autocmd Compiled with autocommand support. (always true) 12311autochdir Compiled with support for 'autochdir' 12312autoservername Automatically enable |clientserver| 12313balloon_eval Compiled with |balloon-eval| support. 12314balloon_multiline GUI supports multiline balloons. 12315beos BeOS version of Vim. 12316browse Compiled with |:browse| support, and browse() will 12317 work. 12318browsefilter Compiled with support for |browsefilter|. 12319bsd Compiled on an OS in the BSD family (excluding macOS). 12320builtin_terms Compiled with some builtin terminals. 12321byte_offset Compiled with support for 'o' in 'statusline' 12322channel Compiled with support for |channel| and |job| 12323cindent Compiled with 'cindent' support. 12324clientserver Compiled with remote invocation support |clientserver|. 12325clipboard Compiled with 'clipboard' support. 12326clipboard_working Compiled with 'clipboard' support and it can be used. 12327cmdline_compl Compiled with |cmdline-completion| support. 12328cmdline_hist Compiled with |cmdline-history| support. 12329cmdline_info Compiled with 'showcmd' and 'ruler' support. 12330comments Compiled with |'comments'| support. 12331compatible Compiled to be very Vi compatible. 12332conpty Platform where |ConPTY| can be used. 12333cryptv Compiled with encryption support |encryption|. 12334cscope Compiled with |cscope| support. 12335cursorbind Compiled with |'cursorbind'| (always true) 12336debug Compiled with "DEBUG" defined. 12337dialog_con Compiled with console dialog support. 12338dialog_gui Compiled with GUI dialog support. 12339diff Compiled with |vimdiff| and 'diff' support. 12340digraphs Compiled with support for digraphs. 12341directx Compiled with support for DirectX and 'renderoptions'. 12342dnd Compiled with support for the "~ register |quote_~|. 12343drop_file Compiled with |drop_file| support. 12344ebcdic Compiled on a machine with ebcdic character set. 12345emacs_tags Compiled with support for Emacs tags. 12346eval Compiled with expression evaluation support. Always 12347 true, of course! 12348ex_extra |+ex_extra| (always true) 12349extra_search Compiled with support for |'incsearch'| and 12350 |'hlsearch'| 12351farsi Support for Farsi was removed |farsi|. 12352file_in_path Compiled with support for |gf| and |<cfile>| 12353filterpipe When 'shelltemp' is off pipes are used for shell 12354 read/write/filter commands 12355find_in_path Compiled with support for include file searches 12356 |+find_in_path|. 12357float Compiled with support for |Float|. 12358fname_case Case in file names matters (for Amiga and MS-Windows 12359 this is not present). 12360folding Compiled with |folding| support. 12361footer Compiled with GUI footer support. |gui-footer| 12362fork Compiled to use fork()/exec() instead of system(). 12363gettext Compiled with message translation |multi-lang| 12364gui Compiled with GUI enabled. 12365gui_athena Compiled with Athena GUI. 12366gui_gnome Compiled with Gnome support (gui_gtk is also defined). 12367gui_gtk Compiled with GTK+ GUI (any version). 12368gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined). 12369gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined). 12370gui_haiku Compiled with Haiku GUI. 12371gui_mac Compiled with Macintosh GUI. 12372gui_motif Compiled with Motif GUI. 12373gui_photon Compiled with Photon GUI. 12374gui_running Vim is running in the GUI, or it will start soon. 12375gui_win32 Compiled with MS-Windows Win32 GUI. 12376gui_win32s idem, and Win32s system being used (Windows 3.1) 12377haiku Haiku version of Vim. 12378hangul_input Compiled with Hangul input support. |hangul| 12379hpux HP-UX version of Vim. 12380iconv Can use iconv() for conversion. 12381insert_expand Compiled with support for CTRL-X expansion commands in 12382 Insert mode. (always true) 12383job Compiled with support for |channel| and |job| 12384ipv6 Compiled with support for IPv6 networking in |channel|. 12385jumplist Compiled with |jumplist| support. 12386keymap Compiled with 'keymap' support. 12387lambda Compiled with |lambda| support. 12388langmap Compiled with 'langmap' support. 12389libcall Compiled with |libcall()| support. 12390linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and 12391 'breakindent' support. 12392linux Linux version of Vim. 12393lispindent Compiled with support for lisp indenting. 12394listcmds Compiled with commands for the buffer list |:files| 12395 and the argument list |arglist|. 12396localmap Compiled with local mappings and abbr. |:map-local| 12397lua Compiled with Lua interface |Lua|. 12398mac Any Macintosh version of Vim cf. osx 12399macunix Synonym for osxdarwin 12400menu Compiled with support for |:menu|. 12401mksession Compiled with support for |:mksession|. 12402modify_fname Compiled with file name modifiers. |filename-modifiers| 12403 (always true) 12404mouse Compiled with support for mouse. 12405mouse_dec Compiled with support for Dec terminal mouse. 12406mouse_gpm Compiled with support for gpm (Linux console mouse) 12407mouse_gpm_enabled GPM mouse is working 12408mouse_netterm Compiled with support for netterm mouse. 12409mouse_pterm Compiled with support for qnx pterm mouse. 12410mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse) 12411mouse_sgr Compiled with support for sgr mouse. 12412mouse_urxvt Compiled with support for urxvt mouse. 12413mouse_xterm Compiled with support for xterm mouse. 12414mouseshape Compiled with support for 'mouseshape'. 12415multi_byte Compiled with support for 'encoding' (always true) 12416multi_byte_encoding 'encoding' is set to a multibyte encoding. 12417multi_byte_ime Compiled with support for IME input method. 12418multi_lang Compiled with support for multiple languages. 12419mzscheme Compiled with MzScheme interface |mzscheme|. 12420nanotime Compiled with sub-second time stamp checks. 12421netbeans_enabled Compiled with support for |netbeans| and connected. 12422netbeans_intg Compiled with support for |netbeans|. 12423num64 Compiled with 64-bit |Number| support. 12424ole Compiled with OLE automation support for Win32. 12425osx Compiled for macOS cf. mac 12426osxdarwin Compiled for macOS, with |mac-darwin-feature| 12427packages Compiled with |packages| support. 12428path_extra Compiled with up/downwards search in 'path' and 'tags' 12429perl Compiled with Perl interface. 12430persistent_undo Compiled with support for persistent undo history. 12431postscript Compiled with PostScript file printing. 12432printer Compiled with |:hardcopy| support. 12433profile Compiled with |:profile| support. 12434python Python 2.x interface available. |has-python| 12435python_compiled Compiled with Python 2.x interface. |has-python| 12436python_dynamic Python 2.x interface is dynamically loaded. |has-python| 12437python3 Python 3.x interface available. |has-python| 12438python3_compiled Compiled with Python 3.x interface. |has-python| 12439python3_dynamic Python 3.x interface is dynamically loaded. |has-python| 12440pythonx Python 2.x and/or 3.x interface available. |python_x| 12441qnx QNX version of Vim. 12442quickfix Compiled with |quickfix| support. 12443reltime Compiled with |reltime()| support. 12444rightleft Compiled with 'rightleft' support. 12445ruby Compiled with Ruby interface |ruby|. 12446scrollbind Compiled with 'scrollbind' support. (always true) 12447showcmd Compiled with 'showcmd' support. 12448signs Compiled with |:sign| support. 12449smartindent Compiled with 'smartindent' support. 12450sodium Compiled with libsodium for better crypt support 12451sound Compiled with sound support, e.g. `sound_playevent()` 12452spell Compiled with spell checking support |spell|. 12453startuptime Compiled with |--startuptime| support. 12454statusline Compiled with support for 'statusline', 'rulerformat' 12455 and special formats of 'titlestring' and 'iconstring'. 12456sun SunOS version of Vim. 12457sun_workshop Support for Sun |workshop| has been removed. 12458syntax Compiled with syntax highlighting support |syntax|. 12459syntax_items There are active syntax highlighting items for the 12460 current buffer. 12461system Compiled to use system() instead of fork()/exec(). 12462tag_binary Compiled with binary searching in tags files 12463 |tag-binary-search|. 12464tag_old_static Support for old static tags was removed, see 12465 |tag-old-static|. 12466tcl Compiled with Tcl interface. 12467termguicolors Compiled with true color in terminal support. 12468terminal Compiled with |terminal| support. 12469terminfo Compiled with terminfo instead of termcap. 12470termresponse Compiled with support for |t_RV| and |v:termresponse|. 12471textobjects Compiled with support for |text-objects|. 12472textprop Compiled with support for |text-properties|. 12473tgetent Compiled with tgetent support, able to use a termcap 12474 or terminfo file. 12475timers Compiled with |timer_start()| support. 12476title Compiled with window title support |'title'|. 12477toolbar Compiled with support for |gui-toolbar|. 12478ttyin input is a terminal (tty) 12479ttyout output is a terminal (tty) 12480unix Unix version of Vim. *+unix* 12481unnamedplus Compiled with support for "unnamedplus" in 'clipboard' 12482user_commands User-defined commands. (always true) 12483vartabs Compiled with variable tabstop support |'vartabstop'|. 12484vcon Win32: Virtual console support is working, can use 12485 'termguicolors'. Also see |+vtp|. 12486vertsplit Compiled with vertically split windows |:vsplit|. 12487 (always true) 12488vim_starting True while initial source'ing takes place. |startup| 12489 *vim_starting* 12490viminfo Compiled with viminfo support. 12491vimscript-1 Compiled Vim script version 1 support 12492vimscript-2 Compiled Vim script version 2 support 12493vimscript-3 Compiled Vim script version 3 support 12494virtualedit Compiled with 'virtualedit' option. (always true) 12495visual Compiled with Visual mode. (always true) 12496visualextra Compiled with extra Visual mode commands. (always 12497 true) |blockwise-operators|. 12498vms VMS version of Vim. 12499vreplace Compiled with |gR| and |gr| commands. (always true) 12500vtp Compiled for vcon support |+vtp| (check vcon to find 12501 out if it works in the current console). 12502wildignore Compiled with 'wildignore' option. 12503wildmenu Compiled with 'wildmenu' option. 12504win16 old version for MS-Windows 3.1 (always false) 12505win32 Win32 version of Vim (MS-Windows 95 and later, 32 or 12506 64 bits) 12507win32unix Win32 version of Vim, using Unix files (Cygwin) 12508win64 Win64 version of Vim (MS-Windows 64 bit). 12509win95 Win32 version for MS-Windows 95/98/ME (always false) 12510winaltkeys Compiled with 'winaltkeys' option. 12511windows Compiled with support for more than one window. 12512 (always true) 12513writebackup Compiled with 'writebackup' default on. 12514xfontset Compiled with X fontset support |xfontset|. 12515xim Compiled with X input method support |xim|. 12516xpm Compiled with pixmap support. 12517xpm_w32 Compiled with pixmap support for Win32. (Only for 12518 backward compatibility. Use "xpm" instead.) 12519xsmp Compiled with X session management support. 12520xsmp_interact Compiled with interactive X session management support. 12521xterm_clipboard Compiled with support for xterm clipboard. 12522xterm_save Compiled with support for saving and restoring the 12523 xterm screen. 12524x11 Compiled with X11 support. 12525 12526 *string-match* 12527Matching a pattern in a String 12528 12529A regexp pattern as explained at |pattern| is normally used to find a match in 12530the buffer lines. When a pattern is used to find a match in a String, almost 12531everything works in the same way. The difference is that a String is handled 12532like it is one line. When it contains a "\n" character, this is not seen as a 12533line break for the pattern. It can be matched with a "\n" in the pattern, or 12534with ".". Example: > 12535 :let a = "aaaa\nxxxx" 12536 :echo matchstr(a, "..\n..") 12537 aa 12538 xx 12539 :echo matchstr(a, "a.x") 12540 a 12541 x 12542 12543Don't forget that "^" will only match at the first character of the String and 12544"$" at the last character of the string. They don't match after or before a 12545"\n". 12546 12547============================================================================== 125485. Defining functions *user-functions* 12549 12550New functions can be defined. These can be called just like builtin 12551functions. The function executes a sequence of Ex commands. Normal mode 12552commands can be executed with the |:normal| command. 12553 12554This section is about the legacy functions. For the Vim9 functions, which 12555execute much faster, support type checking and more, see |vim9.txt|. 12556 12557The function name must start with an uppercase letter, to avoid confusion with 12558builtin functions. To prevent from using the same name in different scripts 12559avoid obvious, short names. A good habit is to start the function name with 12560the name of the script, e.g., "HTMLcolor()". 12561 12562It's also possible to use curly braces, see |curly-braces-names|. And the 12563|autoload| facility is useful to define a function only when it's called. 12564 12565 *local-function* 12566A function local to a script must start with "s:". A local script function 12567can only be called from within the script and from functions, user commands 12568and autocommands defined in the script. It is also possible to call the 12569function from a mapping defined in the script, but then |<SID>| must be used 12570instead of "s:" when the mapping is expanded outside of the script. 12571There are only script-local functions, no buffer-local or window-local 12572functions. 12573 12574 *:fu* *:function* *E128* *E129* *E123* 12575:fu[nction] List all functions and their arguments. 12576 12577:fu[nction] {name} List function {name}. 12578 {name} can also be a |Dictionary| entry that is a 12579 |Funcref|: > 12580 :function dict.init 12581 12582:fu[nction] /{pattern} List functions with a name matching {pattern}. 12583 Example that lists all functions ending with "File": > 12584 :function /File$ 12585< 12586 *:function-verbose* 12587When 'verbose' is non-zero, listing a function will also display where it was 12588last defined. Example: > 12589 12590 :verbose function SetFileTypeSH 12591 function SetFileTypeSH(name) 12592 Last set from /usr/share/vim/vim-7.0/filetype.vim 12593< 12594See |:verbose-cmd| for more information. 12595 12596 *E124* *E125* *E853* *E884* 12597:fu[nction][!] {name}([arguments]) [range] [abort] [dict] [closure] 12598 Define a new function by the name {name}. The body of 12599 the function follows in the next lines, until the 12600 matching |:endfunction|. 12601 12602 The name must be made of alphanumeric characters and 12603 '_', and must start with a capital or "s:" (see 12604 above). Note that using "b:" or "g:" is not allowed. 12605 (since patch 7.4.260 E884 is given if the function 12606 name has a colon in the name, e.g. for "foo:bar()". 12607 Before that patch no error was given). 12608 12609 {name} can also be a |Dictionary| entry that is a 12610 |Funcref|: > 12611 :function dict.init(arg) 12612< "dict" must be an existing dictionary. The entry 12613 "init" is added if it didn't exist yet. Otherwise [!] 12614 is required to overwrite an existing function. The 12615 result is a |Funcref| to a numbered function. The 12616 function can only be used with a |Funcref| and will be 12617 deleted if there are no more references to it. 12618 *E127* *E122* 12619 When a function by this name already exists and [!] is 12620 not used an error message is given. There is one 12621 exception: When sourcing a script again, a function 12622 that was previously defined in that script will be 12623 silently replaced. 12624 When [!] is used, an existing function is silently 12625 replaced. Unless it is currently being executed, that 12626 is an error. 12627 NOTE: Use ! wisely. If used without care it can cause 12628 an existing function to be replaced unexpectedly, 12629 which is hard to debug. 12630 NOTE: In Vim9 script script-local functions cannot be 12631 deleted or redefined. 12632 12633 For the {arguments} see |function-argument|. 12634 12635 *:func-range* *a:firstline* *a:lastline* 12636 When the [range] argument is added, the function is 12637 expected to take care of a range itself. The range is 12638 passed as "a:firstline" and "a:lastline". If [range] 12639 is excluded, ":{range}call" will call the function for 12640 each line in the range, with the cursor on the start 12641 of each line. See |function-range-example|. 12642 The cursor is still moved to the first line of the 12643 range, as is the case with all Ex commands. 12644 *:func-abort* 12645 When the [abort] argument is added, the function will 12646 abort as soon as an error is detected. 12647 *:func-dict* 12648 When the [dict] argument is added, the function must 12649 be invoked through an entry in a |Dictionary|. The 12650 local variable "self" will then be set to the 12651 dictionary. See |Dictionary-function|. 12652 *:func-closure* *E932* 12653 When the [closure] argument is added, the function 12654 can access variables and arguments from the outer 12655 scope. This is usually called a closure. In this 12656 example Bar() uses "x" from the scope of Foo(). It 12657 remains referenced even after Foo() returns: > 12658 :function! Foo() 12659 : let x = 0 12660 : function! Bar() closure 12661 : let x += 1 12662 : return x 12663 : endfunction 12664 : return funcref('Bar') 12665 :endfunction 12666 12667 :let F = Foo() 12668 :echo F() 12669< 1 > 12670 :echo F() 12671< 2 > 12672 :echo F() 12673< 3 12674 12675 *function-search-undo* 12676 The last used search pattern and the redo command "." 12677 will not be changed by the function. This also 12678 implies that the effect of |:nohlsearch| is undone 12679 when the function returns. 12680 12681 *:endf* *:endfunction* *E126* *E193* *W22* 12682:endf[unction] [argument] 12683 The end of a function definition. Best is to put it 12684 on a line by its own, without [argument]. 12685 12686 [argument] can be: 12687 | command command to execute next 12688 \n command command to execute next 12689 " comment always ignored 12690 anything else ignored, warning given when 12691 'verbose' is non-zero 12692 The support for a following command was added in Vim 12693 8.0.0654, before that any argument was silently 12694 ignored. 12695 12696 To be able to define a function inside an `:execute` 12697 command, use line breaks instead of |:bar|: > 12698 :exe "func Foo()\necho 'foo'\nendfunc" 12699< 12700 *:delf* *:delfunction* *E130* *E131* *E933* 12701:delf[unction][!] {name} 12702 Delete function {name}. 12703 {name} can also be a |Dictionary| entry that is a 12704 |Funcref|: > 12705 :delfunc dict.init 12706< This will remove the "init" entry from "dict". The 12707 function is deleted if there are no more references to 12708 it. 12709 With the ! there is no error if the function does not 12710 exist. 12711 *:retu* *:return* *E133* 12712:retu[rn] [expr] Return from a function. When "[expr]" is given, it is 12713 evaluated and returned as the result of the function. 12714 If "[expr]" is not given, the number 0 is returned. 12715 When a function ends without an explicit ":return", 12716 the number 0 is returned. 12717 Note that there is no check for unreachable lines, 12718 thus there is no warning if commands follow ":return". 12719 12720 If the ":return" is used after a |:try| but before the 12721 matching |:finally| (if present), the commands 12722 following the ":finally" up to the matching |:endtry| 12723 are executed first. This process applies to all 12724 nested ":try"s inside the function. The function 12725 returns at the outermost ":endtry". 12726 12727 *function-argument* *a:var* 12728An argument can be defined by giving its name. In the function this can then 12729be used as "a:name" ("a:" for argument). 12730 *a:0* *a:1* *a:000* *E740* *...* 12731Up to 20 arguments can be given, separated by commas. After the named 12732arguments an argument "..." can be specified, which means that more arguments 12733may optionally be following. In the function the extra arguments can be used 12734as "a:1", "a:2", etc. "a:0" is set to the number of extra arguments (which 12735can be 0). "a:000" is set to a |List| that contains these arguments. Note 12736that "a:1" is the same as "a:000[0]". 12737 *E742* 12738The a: scope and the variables in it cannot be changed, they are fixed. 12739However, if a composite type is used, such as |List| or |Dictionary| , you can 12740change their contents. Thus you can pass a |List| to a function and have the 12741function add an item to it. If you want to make sure the function cannot 12742change a |List| or |Dictionary| use |:lockvar|. 12743 12744It is also possible to define a function without any arguments. You must 12745still supply the () then. 12746 12747It is allowed to define another function inside a function body. 12748 12749 *optional-function-argument* 12750You can provide default values for positional named arguments. This makes 12751them optional for function calls. When a positional argument is not 12752specified at a call, the default expression is used to initialize it. 12753This only works for functions declared with `:function` or `:def`, not for 12754lambda expressions |expr-lambda|. 12755 12756Example: > 12757 function Something(key, value = 10) 12758 echo a:key .. ": " .. a:value 12759 endfunction 12760 call Something('empty') "empty: 10" 12761 call Something('key', 20) "key: 20" 12762 12763The argument default expressions are evaluated at the time of the function 12764call, not definition. Thus it is possible to use an expression which is 12765invalid the moment the function is defined. The expressions are also only 12766evaluated when arguments are not specified during a call. 12767 *none-function_argument* 12768You can pass |v:none| to use the default expression. Note that this means you 12769cannot pass v:none as an ordinary value when an argument has a default 12770expression. 12771 12772Example: > 12773 function Something(a = 10, b = 20, c = 30) 12774 endfunction 12775 call Something(1, v:none, 3) " b = 20 12776< 12777 *E989* 12778Optional arguments with default expressions must occur after any mandatory 12779arguments. You can use "..." after all optional named arguments. 12780 12781It is possible for later argument defaults to refer to prior arguments, 12782but not the other way around. They must be prefixed with "a:", as with all 12783arguments. 12784 12785Example that works: > 12786 :function Okay(mandatory, optional = a:mandatory) 12787 :endfunction 12788Example that does NOT work: > 12789 :function NoGood(first = a:second, second = 10) 12790 :endfunction 12791< 12792When not using "...", the number of arguments in a function call must be at 12793least equal to the number of mandatory named arguments. When using "...", the 12794number of arguments may be larger than the total of mandatory and optional 12795arguments. 12796 12797 *local-variables* 12798Inside a function local variables can be used. These will disappear when the 12799function returns. Global variables need to be accessed with "g:". 12800 12801Example: > 12802 :function Table(title, ...) 12803 : echohl Title 12804 : echo a:title 12805 : echohl None 12806 : echo a:0 . " items:" 12807 : for s in a:000 12808 : echon ' ' . s 12809 : endfor 12810 :endfunction 12811 12812This function can then be called with: > 12813 call Table("Table", "line1", "line2") 12814 call Table("Empty Table") 12815 12816To return more than one value, return a |List|: > 12817 :function Compute(n1, n2) 12818 : if a:n2 == 0 12819 : return ["fail", 0] 12820 : endif 12821 : return ["ok", a:n1 / a:n2] 12822 :endfunction 12823 12824This function can then be called with: > 12825 :let [success, div] = Compute(102, 6) 12826 :if success == "ok" 12827 : echo div 12828 :endif 12829< 12830 *:cal* *:call* *E107* *E117* 12831:[range]cal[l] {name}([arguments]) 12832 Call a function. The name of the function and its arguments 12833 are as specified with `:function`. Up to 20 arguments can be 12834 used. The returned value is discarded. 12835 Without a range and for functions that accept a range, the 12836 function is called once. When a range is given the cursor is 12837 positioned at the start of the first line before executing the 12838 function. 12839 When a range is given and the function doesn't handle it 12840 itself, the function is executed for each line in the range, 12841 with the cursor in the first column of that line. The cursor 12842 is left at the last line (possibly moved by the last function 12843 call). The arguments are re-evaluated for each line. Thus 12844 this works: 12845 *function-range-example* > 12846 :function Mynumber(arg) 12847 : echo line(".") . " " . a:arg 12848 :endfunction 12849 :1,5call Mynumber(getline(".")) 12850< 12851 The "a:firstline" and "a:lastline" are defined anyway, they 12852 can be used to do something different at the start or end of 12853 the range. 12854 12855 Example of a function that handles the range itself: > 12856 12857 :function Cont() range 12858 : execute (a:firstline + 1) . "," . a:lastline . 's/^/\t\\ ' 12859 :endfunction 12860 :4,8call Cont() 12861< 12862 This function inserts the continuation character "\" in front 12863 of all the lines in the range, except the first one. 12864 12865 When the function returns a composite value it can be further 12866 dereferenced, but the range will not be used then. Example: > 12867 :4,8call GetDict().method() 12868< Here GetDict() gets the range but method() does not. 12869 12870 *E132* 12871The recursiveness of user functions is restricted with the |'maxfuncdepth'| 12872option. 12873 12874It is also possible to use `:eval`. It does not support a range, but does 12875allow for method chaining, e.g.: > 12876 eval GetList()->Filter()->append('$') 12877 12878A function can also be called as part of evaluating an expression or when it 12879is used as a method: > 12880 let x = GetList() 12881 let y = GetList()->Filter() 12882 12883 12884AUTOMATICALLY LOADING FUNCTIONS ~ 12885 *autoload-functions* 12886When using many or large functions, it's possible to automatically define them 12887only when they are used. There are two methods: with an autocommand and with 12888the "autoload" directory in 'runtimepath'. 12889 12890 12891Using an autocommand ~ 12892 12893This is introduced in the user manual, section |41.14|. 12894 12895The autocommand is useful if you have a plugin that is a long Vim script file. 12896You can define the autocommand and quickly quit the script with `:finish`. 12897That makes Vim startup faster. The autocommand should then load the same file 12898again, setting a variable to skip the `:finish` command. 12899 12900Use the FuncUndefined autocommand event with a pattern that matches the 12901function(s) to be defined. Example: > 12902 12903 :au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim 12904 12905The file "~/vim/bufnetfuncs.vim" should then define functions that start with 12906"BufNet". Also see |FuncUndefined|. 12907 12908 12909Using an autoload script ~ 12910 *autoload* *E746* 12911This is introduced in the user manual, section |41.15|. 12912 12913Using a script in the "autoload" directory is simpler, but requires using 12914exactly the right file name. A function that can be autoloaded has a name 12915like this: > 12916 12917 :call filename#funcname() 12918 12919These functions are always global, in Vim9 script "g:" needs to be used: > 12920 :call g:filename#funcname() 12921 12922When such a function is called, and it is not defined yet, Vim will search the 12923"autoload" directories in 'runtimepath' for a script file called 12924"filename.vim". For example "~/.vim/autoload/filename.vim". That file should 12925then define the function like this: > 12926 12927 function filename#funcname() 12928 echo "Done!" 12929 endfunction 12930 12931The file name and the name used before the # in the function must match 12932exactly, and the defined function must have the name exactly as it will be 12933called. In Vim9 script the "g:" prefix must be used: > 12934 function g:filename#funcname() 12935 12936or for a compiled function: > 12937 def g:filename#funcname() 12938 12939It is possible to use subdirectories. Every # in the function name works like 12940a path separator. Thus when calling a function: > 12941 12942 :call foo#bar#func() 12943 12944Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'. 12945 12946This also works when reading a variable that has not been set yet: > 12947 12948 :let l = foo#bar#lvar 12949 12950However, when the autoload script was already loaded it won't be loaded again 12951for an unknown variable. 12952 12953When assigning a value to such a variable nothing special happens. This can 12954be used to pass settings to the autoload script before it's loaded: > 12955 12956 :let foo#bar#toggle = 1 12957 :call foo#bar#func() 12958 12959Note that when you make a mistake and call a function that is supposed to be 12960defined in an autoload script, but the script doesn't actually define the 12961function, you will get an error message for the missing function. If you fix 12962the autoload script it won't be automatically loaded again. Either restart 12963Vim or manually source the script. 12964 12965Also note that if you have two script files, and one calls a function in the 12966other and vice versa, before the used function is defined, it won't work. 12967Avoid using the autoload functionality at the toplevel. 12968 12969Hint: If you distribute a bunch of scripts you can pack them together with the 12970|vimball| utility. Also read the user manual |distribute-script|. 12971 12972============================================================================== 129736. Curly braces names *curly-braces-names* 12974 12975In most places where you can use a variable, you can use a "curly braces name" 12976variable. This is a regular variable name with one or more expressions 12977wrapped in braces {} like this: > 12978 my_{adjective}_variable 12979 12980When Vim encounters this, it evaluates the expression inside the braces, puts 12981that in place of the expression, and re-interprets the whole as a variable 12982name. So in the above example, if the variable "adjective" was set to 12983"noisy", then the reference would be to "my_noisy_variable", whereas if 12984"adjective" was set to "quiet", then it would be to "my_quiet_variable". 12985 12986One application for this is to create a set of variables governed by an option 12987value. For example, the statement > 12988 echo my_{&background}_message 12989 12990would output the contents of "my_dark_message" or "my_light_message" depending 12991on the current value of 'background'. 12992 12993You can use multiple brace pairs: > 12994 echo my_{adverb}_{adjective}_message 12995..or even nest them: > 12996 echo my_{ad{end_of_word}}_message 12997where "end_of_word" is either "verb" or "jective". 12998 12999However, the expression inside the braces must evaluate to a valid single 13000variable name, e.g. this is invalid: > 13001 :let foo='a + b' 13002 :echo c{foo}d 13003.. since the result of expansion is "ca + bd", which is not a variable name. 13004 13005 *curly-braces-function-names* 13006You can call and define functions by an evaluated name in a similar way. 13007Example: > 13008 :let func_end='whizz' 13009 :call my_func_{func_end}(parameter) 13010 13011This would call the function "my_func_whizz(parameter)". 13012 13013This does NOT work: > 13014 :let i = 3 13015 :let @{i} = '' " error 13016 :echo @{i} " error 13017 13018============================================================================== 130197. Commands *expression-commands* 13020 13021Note: in Vim9 script `:let` is used for variable declaration, not assignment. 13022An assignment leaves out the `:let` command. |vim9-declaration| 13023 13024:let {var-name} = {expr1} *:let* *E18* 13025 Set internal variable {var-name} to the result of the 13026 expression {expr1}. The variable will get the type 13027 from the {expr}. If {var-name} didn't exist yet, it 13028 is created. 13029 13030:let {var-name}[{idx}] = {expr1} *E689* 13031 Set a list item to the result of the expression 13032 {expr1}. {var-name} must refer to a list and {idx} 13033 must be a valid index in that list. For nested list 13034 the index can be repeated. 13035 This cannot be used to add an item to a |List|. 13036 This cannot be used to set a byte in a String. You 13037 can do that like this: > 13038 :let var = var[0:2] . 'X' . var[4:] 13039< When {var-name} is a |Blob| then {idx} can be the 13040 length of the blob, in which case one byte is 13041 appended. 13042 13043 *E711* *E719* 13044:let {var-name}[{idx1}:{idx2}] = {expr1} *E708* *E709* *E710* 13045 Set a sequence of items in a |List| to the result of 13046 the expression {expr1}, which must be a list with the 13047 correct number of items. 13048 {idx1} can be omitted, zero is used instead. 13049 {idx2} can be omitted, meaning the end of the list. 13050 When the selected range of items is partly past the 13051 end of the list, items will be added. 13052 13053 *:let+=* *:let-=* *:letstar=* 13054 *:let/=* *:let%=* *:let.=* *:let..=* *E734* *E985* 13055:let {var} += {expr1} Like ":let {var} = {var} + {expr1}". 13056:let {var} -= {expr1} Like ":let {var} = {var} - {expr1}". 13057:let {var} *= {expr1} Like ":let {var} = {var} * {expr1}". 13058:let {var} /= {expr1} Like ":let {var} = {var} / {expr1}". 13059:let {var} %= {expr1} Like ":let {var} = {var} % {expr1}". 13060:let {var} .= {expr1} Like ":let {var} = {var} . {expr1}". 13061:let {var} ..= {expr1} Like ":let {var} = {var} .. {expr1}". 13062 These fail if {var} was not set yet and when the type 13063 of {var} and {expr1} don't fit the operator. 13064 `.=` is not supported with Vim script version 2 and 13065 later, see |vimscript-version|. 13066 13067 13068:let ${env-name} = {expr1} *:let-environment* *:let-$* 13069 Set environment variable {env-name} to the result of 13070 the expression {expr1}. The type is always String. 13071 13072 On some systems making an environment variable empty 13073 causes it to be deleted. Many systems do not make a 13074 difference between an environment variable that is not 13075 set and an environment variable that is empty. 13076 13077:let ${env-name} .= {expr1} 13078 Append {expr1} to the environment variable {env-name}. 13079 If the environment variable didn't exist yet this 13080 works like "=". 13081 13082:let @{reg-name} = {expr1} *:let-register* *:let-@* 13083 Write the result of the expression {expr1} in register 13084 {reg-name}. {reg-name} must be a single letter, and 13085 must be the name of a writable register (see 13086 |registers|). "@@" can be used for the unnamed 13087 register, "@/" for the search pattern. 13088 If the result of {expr1} ends in a <CR> or <NL>, the 13089 register will be linewise, otherwise it will be set to 13090 characterwise. 13091 This can be used to clear the last search pattern: > 13092 :let @/ = "" 13093< This is different from searching for an empty string, 13094 that would match everywhere. 13095 13096:let @{reg-name} .= {expr1} 13097 Append {expr1} to register {reg-name}. If the 13098 register was empty it's like setting it to {expr1}. 13099 13100:let &{option-name} = {expr1} *:let-option* *:let-&* 13101 Set option {option-name} to the result of the 13102 expression {expr1}. A String or Number value is 13103 always converted to the type of the option. 13104 For an option local to a window or buffer the effect 13105 is just like using the |:set| command: both the local 13106 value and the global value are changed. 13107 Example: > 13108 :let &path = &path . ',/usr/local/include' 13109< This also works for terminal codes in the form t_xx. 13110 But only for alphanumerical names. Example: > 13111 :let &t_k1 = "\<Esc>[234;" 13112< When the code does not exist yet it will be created as 13113 a terminal key code, there is no error. 13114 13115:let &{option-name} .= {expr1} 13116 For a string option: Append {expr1} to the value. 13117 Does not insert a comma like |:set+=|. 13118 13119:let &{option-name} += {expr1} 13120:let &{option-name} -= {expr1} 13121 For a number or boolean option: Add or subtract 13122 {expr1}. 13123 13124:let &l:{option-name} = {expr1} 13125:let &l:{option-name} .= {expr1} 13126:let &l:{option-name} += {expr1} 13127:let &l:{option-name} -= {expr1} 13128 Like above, but only set the local value of an option 13129 (if there is one). Works like |:setlocal|. 13130 13131:let &g:{option-name} = {expr1} 13132:let &g:{option-name} .= {expr1} 13133:let &g:{option-name} += {expr1} 13134:let &g:{option-name} -= {expr1} 13135 Like above, but only set the global value of an option 13136 (if there is one). Works like |:setglobal|. 13137 13138:let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688* 13139 {expr1} must evaluate to a |List|. The first item in 13140 the list is assigned to {name1}, the second item to 13141 {name2}, etc. 13142 The number of names must match the number of items in 13143 the |List|. 13144 Each name can be one of the items of the ":let" 13145 command as mentioned above. 13146 Example: > 13147 :let [s, item] = GetItem(s) 13148< Detail: {expr1} is evaluated first, then the 13149 assignments are done in sequence. This matters if 13150 {name2} depends on {name1}. Example: > 13151 :let x = [0, 1] 13152 :let i = 0 13153 :let [i, x[i]] = [1, 2] 13154 :echo x 13155< The result is [0, 2]. 13156 13157:let [{name1}, {name2}, ...] .= {expr1} 13158:let [{name1}, {name2}, ...] += {expr1} 13159:let [{name1}, {name2}, ...] -= {expr1} 13160 Like above, but append/add/subtract the value for each 13161 |List| item. 13162 13163:let [{name}, ..., ; {lastname}] = {expr1} *E452* 13164 Like |:let-unpack| above, but the |List| may have more 13165 items than there are names. A list of the remaining 13166 items is assigned to {lastname}. If there are no 13167 remaining items {lastname} is set to an empty list. 13168 Example: > 13169 :let [a, b; rest] = ["aval", "bval", 3, 4] 13170< 13171:let [{name}, ..., ; {lastname}] .= {expr1} 13172:let [{name}, ..., ; {lastname}] += {expr1} 13173:let [{name}, ..., ; {lastname}] -= {expr1} 13174 Like above, but append/add/subtract the value for each 13175 |List| item. 13176 13177 *:let=<<* *:let-heredoc* 13178 *E990* *E991* *E172* *E221* 13179:let {var-name} =<< [trim] {endmarker} 13180text... 13181text... 13182{endmarker} 13183 Set internal variable {var-name} to a |List| 13184 containing the lines of text bounded by the string 13185 {endmarker}. The lines of text is used as a 13186 |literal-string|. 13187 {endmarker} must not contain white space. 13188 {endmarker} cannot start with a lower case character. 13189 The last line should end only with the {endmarker} 13190 string without any other character. Watch out for 13191 white space after {endmarker}! 13192 13193 Without "trim" any white space characters in the lines 13194 of text are preserved. If "trim" is specified before 13195 {endmarker}, then indentation is stripped so you can 13196 do: > 13197 let text =<< trim END 13198 if ok 13199 echo 'done' 13200 endif 13201 END 13202< Results in: ["if ok", " echo 'done'", "endif"] 13203 The marker must line up with "let" and the indentation 13204 of the first line is removed from all the text lines. 13205 Specifically: all the leading indentation exactly 13206 matching the leading indentation of the first 13207 non-empty text line is stripped from the input lines. 13208 All leading indentation exactly matching the leading 13209 indentation before `let` is stripped from the line 13210 containing {endmarker}. Note that the difference 13211 between space and tab matters here. 13212 13213 If {var-name} didn't exist yet, it is created. 13214 Cannot be followed by another command, but can be 13215 followed by a comment. 13216 13217 To avoid line continuation to be applied, consider 13218 adding 'C' to 'cpoptions': > 13219 set cpo+=C 13220 let var =<< END 13221 \ leading backslash 13222 END 13223 set cpo-=C 13224< 13225 Examples: > 13226 let var1 =<< END 13227 Sample text 1 13228 Sample text 2 13229 Sample text 3 13230 END 13231 13232 let data =<< trim DATA 13233 1 2 3 4 13234 5 6 7 8 13235 DATA 13236< 13237 *E121* 13238:let {var-name} .. List the value of variable {var-name}. Multiple 13239 variable names may be given. Special names recognized 13240 here: *E738* 13241 g: global variables 13242 b: local buffer variables 13243 w: local window variables 13244 t: local tab page variables 13245 s: script-local variables 13246 l: local function variables 13247 v: Vim variables. 13248 This does not work in Vim9 script. |vim9-declaration| 13249 13250:let List the values of all variables. The type of the 13251 variable is indicated before the value: 13252 <nothing> String 13253 # Number 13254 * Funcref 13255 This does not work in Vim9 script. |vim9-declaration| 13256 13257:unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795* 13258 Remove the internal variable {name}. Several variable 13259 names can be given, they are all removed. The name 13260 may also be a |List| or |Dictionary| item. 13261 With [!] no error message is given for non-existing 13262 variables. 13263 One or more items from a |List| can be removed: > 13264 :unlet list[3] " remove fourth item 13265 :unlet list[3:] " remove fourth item to last 13266< One item from a |Dictionary| can be removed at a time: > 13267 :unlet dict['two'] 13268 :unlet dict.two 13269< This is especially useful to clean up used global 13270 variables and script-local variables (these are not 13271 deleted when the script ends). Function-local 13272 variables are automatically deleted when the function 13273 ends. 13274 13275:unl[et] ${env-name} ... *:unlet-environment* *:unlet-$* 13276 Remove environment variable {env-name}. 13277 Can mix {name} and ${env-name} in one :unlet command. 13278 No error message is given for a non-existing 13279 variable, also without !. 13280 If the system does not support deleting an environment 13281 variable, it is made empty. 13282 13283 *:cons* *:const* 13284:cons[t] {var-name} = {expr1} 13285:cons[t] [{name1}, {name2}, ...] = {expr1} 13286:cons[t] [{name}, ..., ; {lastname}] = {expr1} 13287:cons[t] {var-name} =<< [trim] {marker} 13288text... 13289text... 13290{marker} 13291 Similar to |:let|, but additionally lock the variable 13292 after setting the value. This is the same as locking 13293 the variable with |:lockvar| just after |:let|, thus: > 13294 :const x = 1 13295< is equivalent to: > 13296 :let x = 1 13297 :lockvar! x 13298< NOTE: in Vim9 script `:const` works differently, see 13299 |vim9-const| 13300 This is useful if you want to make sure the variable 13301 is not modified. If the value is a List or Dictionary 13302 literal then the items also cannot be changed: > 13303 const ll = [1, 2, 3] 13304 let ll[1] = 5 " Error! 13305< Nested references are not locked: > 13306 let lvar = ['a'] 13307 const lconst = [0, lvar] 13308 let lconst[0] = 2 " Error! 13309 let lconst[1][0] = 'b' " OK 13310< *E995* 13311 |:const| does not allow to for changing a variable: > 13312 :let x = 1 13313 :const x = 2 " Error! 13314< *E996* 13315 Note that environment variables, option values and 13316 register values cannot be used here, since they cannot 13317 be locked. 13318 13319:cons[t] 13320:cons[t] {var-name} 13321 If no argument is given or only {var-name} is given, 13322 the behavior is the same as |:let|. 13323 13324:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv* 13325 Lock the internal variable {name}. Locking means that 13326 it can no longer be changed (until it is unlocked). 13327 A locked variable can be deleted: > 13328 :lockvar v 13329 :let v = 'asdf' " fails! 13330 :unlet v " works 13331< *E741* *E940* 13332 If you try to change a locked variable you get an 13333 error message: "E741: Value is locked: {name}". 13334 If you try to lock or unlock a built-in variable you 13335 get an error message: "E940: Cannot lock or unlock 13336 variable {name}". 13337 13338 [depth] is relevant when locking a |List| or 13339 |Dictionary|. It specifies how deep the locking goes: 13340 0 Lock the variable {name} but not its 13341 value. 13342 1 Lock the |List| or |Dictionary| itself, 13343 cannot add or remove items, but can 13344 still change their values. 13345 2 Also lock the values, cannot change 13346 the items. If an item is a |List| or 13347 |Dictionary|, cannot add or remove 13348 items, but can still change the 13349 values. 13350 3 Like 2 but for the |List| / 13351 |Dictionary| in the |List| / 13352 |Dictionary|, one level deeper. 13353 The default [depth] is 2, thus when {name} is a |List| 13354 or |Dictionary| the values cannot be changed. 13355 13356 Example with [depth] 0: > 13357 let mylist = [1, 2, 3] 13358 lockvar 0 mylist 13359 let mylist[0] = 77 " OK 13360 call add(mylist, 4] " OK 13361 let mylist = [7, 8, 9] " Error! 13362< *E743* 13363 For unlimited depth use [!] and omit [depth]. 13364 However, there is a maximum depth of 100 to catch 13365 loops. 13366 13367 Note that when two variables refer to the same |List| 13368 and you lock one of them, the |List| will also be 13369 locked when used through the other variable. 13370 Example: > 13371 :let l = [0, 1, 2, 3] 13372 :let cl = l 13373 :lockvar l 13374 :let cl[1] = 99 " won't work! 13375< You may want to make a copy of a list to avoid this. 13376 See |deepcopy()|. 13377 13378 13379:unlo[ckvar][!] [depth] {name} ... *:unlockvar* *:unlo* 13380 Unlock the internal variable {name}. Does the 13381 opposite of |:lockvar|. 13382 13383:if {expr1} *:if* *:end* *:endif* *:en* *E171* *E579* *E580* 13384:en[dif] Execute the commands until the next matching ":else" 13385 or ":endif" if {expr1} evaluates to non-zero. 13386 13387 From Vim version 4.5 until 5.0, every Ex command in 13388 between the ":if" and ":endif" is ignored. These two 13389 commands were just to allow for future expansions in a 13390 backward compatible way. Nesting was allowed. Note 13391 that any ":else" or ":elseif" was ignored, the "else" 13392 part was not executed either. 13393 13394 You can use this to remain compatible with older 13395 versions: > 13396 :if version >= 500 13397 : version-5-specific-commands 13398 :endif 13399< The commands still need to be parsed to find the 13400 "endif". Sometimes an older Vim has a problem with a 13401 new command. For example, ":silent" is recognized as 13402 a ":substitute" command. In that case ":execute" can 13403 avoid problems: > 13404 :if version >= 600 13405 : execute "silent 1,$delete" 13406 :endif 13407< 13408 NOTE: The ":append" and ":insert" commands don't work 13409 properly in between ":if" and ":endif". 13410 13411 *:else* *:el* *E581* *E583* 13412:el[se] Execute the commands until the next matching ":else" 13413 or ":endif" if they previously were not being 13414 executed. 13415 13416 *:elseif* *:elsei* *E582* *E584* 13417:elsei[f] {expr1} Short for ":else" ":if", with the addition that there 13418 is no extra ":endif". 13419 13420:wh[ile] {expr1} *:while* *:endwhile* *:wh* *:endw* 13421 *E170* *E585* *E588* *E733* 13422:endw[hile] Repeat the commands between ":while" and ":endwhile", 13423 as long as {expr1} evaluates to non-zero. 13424 When an error is detected from a command inside the 13425 loop, execution continues after the "endwhile". 13426 Example: > 13427 :let lnum = 1 13428 :while lnum <= line("$") 13429 :call FixLine(lnum) 13430 :let lnum = lnum + 1 13431 :endwhile 13432< 13433 NOTE: The ":append" and ":insert" commands don't work 13434 properly inside a ":while" and ":for" loop. 13435 13436:for {var} in {object} *:for* *E690* *E732* 13437:endfo[r] *:endfo* *:endfor* 13438 Repeat the commands between ":for" and ":endfor" for 13439 each item in {object}. {object} can be a |List| or 13440 a |Blob|. Variable {var} is set to the value of each 13441 item. When an error is detected for a command inside 13442 the loop, execution continues after the "endfor". 13443 Changing {object} inside the loop affects what items 13444 are used. Make a copy if this is unwanted: > 13445 :for item in copy(mylist) 13446< 13447 When {object} is a |List| and not making a copy, Vim 13448 stores a reference to the next item in the |List| 13449 before executing the commands with the current item. 13450 Thus the current item can be removed without effect. 13451 Removing any later item means it will not be found. 13452 Thus the following example works (an inefficient way 13453 to make a |List| empty): > 13454 for item in mylist 13455 call remove(mylist, 0) 13456 endfor 13457< Note that reordering the |List| (e.g., with sort() or 13458 reverse()) may have unexpected effects. 13459 13460 When {object} is a |Blob|, Vim always makes a copy to 13461 iterate over. Unlike with |List|, modifying the 13462 |Blob| does not affect the iteration. 13463 13464:for [{var1}, {var2}, ...] in {listlist} 13465:endfo[r] 13466 Like ":for" above, but each item in {listlist} must be 13467 a list, of which each item is assigned to {var1}, 13468 {var2}, etc. Example: > 13469 :for [lnum, col] in [[1, 3], [2, 5], [3, 8]] 13470 :echo getline(lnum)[col] 13471 :endfor 13472< 13473 *:continue* *:con* *E586* 13474:con[tinue] When used inside a ":while" or ":for" loop, jumps back 13475 to the start of the loop. 13476 If it is used after a |:try| inside the loop but 13477 before the matching |:finally| (if present), the 13478 commands following the ":finally" up to the matching 13479 |:endtry| are executed first. This process applies to 13480 all nested ":try"s inside the loop. The outermost 13481 ":endtry" then jumps back to the start of the loop. 13482 13483 *:break* *:brea* *E587* 13484:brea[k] When used inside a ":while" or ":for" loop, skips to 13485 the command after the matching ":endwhile" or 13486 ":endfor". 13487 If it is used after a |:try| inside the loop but 13488 before the matching |:finally| (if present), the 13489 commands following the ":finally" up to the matching 13490 |:endtry| are executed first. This process applies to 13491 all nested ":try"s inside the loop. The outermost 13492 ":endtry" then jumps to the command after the loop. 13493 13494:try *:try* *:endt* *:endtry* *E600* *E601* *E602* 13495:endt[ry] Change the error handling for the commands between 13496 ":try" and ":endtry" including everything being 13497 executed across ":source" commands, function calls, 13498 or autocommand invocations. 13499 13500 When an error or interrupt is detected and there is 13501 a |:finally| command following, execution continues 13502 after the ":finally". Otherwise, or when the 13503 ":endtry" is reached thereafter, the next 13504 (dynamically) surrounding ":try" is checked for 13505 a corresponding ":finally" etc. Then the script 13506 processing is terminated. Whether a function 13507 definition has an "abort" argument does not matter. 13508 Example: > 13509 try | call Unknown() | finally | echomsg "cleanup" | endtry 13510 echomsg "not reached" 13511< 13512 Moreover, an error or interrupt (dynamically) inside 13513 ":try" and ":endtry" is converted to an exception. It 13514 can be caught as if it were thrown by a |:throw| 13515 command (see |:catch|). In this case, the script 13516 processing is not terminated. 13517 13518 The value "Vim:Interrupt" is used for an interrupt 13519 exception. An error in a Vim command is converted 13520 to a value of the form "Vim({command}):{errmsg}", 13521 other errors are converted to a value of the form 13522 "Vim:{errmsg}". {command} is the full command name, 13523 and {errmsg} is the message that is displayed if the 13524 error exception is not caught, always beginning with 13525 the error number. 13526 Examples: > 13527 try | sleep 100 | catch /^Vim:Interrupt$/ | endtry 13528 try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry 13529< 13530 *:cat* *:catch* *E603* *E604* *E605* 13531:cat[ch] /{pattern}/ The following commands until the next |:catch|, 13532 |:finally|, or |:endtry| that belongs to the same 13533 |:try| as the ":catch" are executed when an exception 13534 matching {pattern} is being thrown and has not yet 13535 been caught by a previous ":catch". Otherwise, these 13536 commands are skipped. 13537 When {pattern} is omitted all errors are caught. 13538 Examples: > 13539 :catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C) 13540 :catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors 13541 :catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts 13542 :catch /^Vim(write):/ " catch all errors in :write 13543 :catch /^Vim\%((\a\+)\)\=:E123:/ " catch error E123 13544 :catch /my-exception/ " catch user exception 13545 :catch /.*/ " catch everything 13546 :catch " same as /.*/ 13547< 13548 Another character can be used instead of / around the 13549 {pattern}, so long as it does not have a special 13550 meaning (e.g., '|' or '"') and doesn't occur inside 13551 {pattern}. 13552 Information about the exception is available in 13553 |v:exception|. Also see |throw-variables|. 13554 NOTE: It is not reliable to ":catch" the TEXT of 13555 an error message because it may vary in different 13556 locales. 13557 13558 *:fina* *:finally* *E606* *E607* 13559:fina[lly] The following commands until the matching |:endtry| 13560 are executed whenever the part between the matching 13561 |:try| and the ":finally" is left: either by falling 13562 through to the ":finally" or by a |:continue|, 13563 |:break|, |:finish|, or |:return|, or by an error or 13564 interrupt or exception (see |:throw|). 13565 13566 *:th* *:throw* *E608* 13567:th[row] {expr1} The {expr1} is evaluated and thrown as an exception. 13568 If the ":throw" is used after a |:try| but before the 13569 first corresponding |:catch|, commands are skipped 13570 until the first ":catch" matching {expr1} is reached. 13571 If there is no such ":catch" or if the ":throw" is 13572 used after a ":catch" but before the |:finally|, the 13573 commands following the ":finally" (if present) up to 13574 the matching |:endtry| are executed. If the ":throw" 13575 is after the ":finally", commands up to the ":endtry" 13576 are skipped. At the ":endtry", this process applies 13577 again for the next dynamically surrounding ":try" 13578 (which may be found in a calling function or sourcing 13579 script), until a matching ":catch" has been found. 13580 If the exception is not caught, the command processing 13581 is terminated. 13582 Example: > 13583 :try | throw "oops" | catch /^oo/ | echo "caught" | endtry 13584< Note that "catch" may need to be on a separate line 13585 for when an error causes the parsing to skip the whole 13586 line and not see the "|" that separates the commands. 13587 13588 *:ec* *:echo* 13589:ec[ho] {expr1} .. Echoes each {expr1}, with a space in between. The 13590 first {expr1} starts on a new line. 13591 Also see |:comment|. 13592 Use "\n" to start a new line. Use "\r" to move the 13593 cursor to the first column. 13594 Uses the highlighting set by the |:echohl| command. 13595 Cannot be followed by a comment. 13596 Example: > 13597 :echo "the value of 'shell' is" &shell 13598< *:echo-redraw* 13599 A later redraw may make the message disappear again. 13600 And since Vim mostly postpones redrawing until it's 13601 finished with a sequence of commands this happens 13602 quite often. To avoid that a command from before the 13603 ":echo" causes a redraw afterwards (redraws are often 13604 postponed until you type something), force a redraw 13605 with the |:redraw| command. Example: > 13606 :new | redraw | echo "there is a new window" 13607< 13608 *:echon* 13609:echon {expr1} .. Echoes each {expr1}, without anything added. Also see 13610 |:comment|. 13611 Uses the highlighting set by the |:echohl| command. 13612 Cannot be followed by a comment. 13613 Example: > 13614 :echon "the value of 'shell' is " &shell 13615< 13616 Note the difference between using ":echo", which is a 13617 Vim command, and ":!echo", which is an external shell 13618 command: > 13619 :!echo % --> filename 13620< The arguments of ":!" are expanded, see |:_%|. > 13621 :!echo "%" --> filename or "filename" 13622< Like the previous example. Whether you see the double 13623 quotes or not depends on your 'shell'. > 13624 :echo % --> nothing 13625< The '%' is an illegal character in an expression. > 13626 :echo "%" --> % 13627< This just echoes the '%' character. > 13628 :echo expand("%") --> filename 13629< This calls the expand() function to expand the '%'. 13630 13631 *:echoh* *:echohl* 13632:echoh[l] {name} Use the highlight group {name} for the following 13633 |:echo|, |:echon| and |:echomsg| commands. Also used 13634 for the |input()| prompt. Example: > 13635 :echohl WarningMsg | echo "Don't panic!" | echohl None 13636< Don't forget to set the group back to "None", 13637 otherwise all following echo's will be highlighted. 13638 13639 *:echom* *:echomsg* 13640:echom[sg] {expr1} .. Echo the expression(s) as a true message, saving the 13641 message in the |message-history|. 13642 Spaces are placed between the arguments as with the 13643 |:echo| command. But unprintable characters are 13644 displayed, not interpreted. 13645 The parsing works slightly different from |:echo|, 13646 more like |:execute|. All the expressions are first 13647 evaluated and concatenated before echoing anything. 13648 If expressions does not evaluate to a Number or 13649 String, string() is used to turn it into a string. 13650 Uses the highlighting set by the |:echohl| command. 13651 Example: > 13652 :echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see." 13653< See |:echo-redraw| to avoid the message disappearing 13654 when the screen is redrawn. 13655 *:echoe* *:echoerr* 13656:echoe[rr] {expr1} .. Echo the expression(s) as an error message, saving the 13657 message in the |message-history|. When used in a 13658 script or function the line number will be added. 13659 Spaces are placed between the arguments as with the 13660 |:echomsg| command. When used inside a try conditional, 13661 the message is raised as an error exception instead 13662 (see |try-echoerr|). 13663 Example: > 13664 :echoerr "This script just failed!" 13665< If you just want a highlighted message use |:echohl|. 13666 And to get a beep: > 13667 :exe "normal \<Esc>" 13668 13669:echoc[onsole] {expr1} .. *:echoc* *:echoconsole* 13670 Intended for testing: works like `:echomsg` but when 13671 running in the GUI and started from a terminal write 13672 the text to stdout. 13673 13674 *:eval* 13675:eval {expr} Evaluate {expr} and discard the result. Example: > 13676 :eval Getlist()->Filter()->append('$') 13677 13678< The expression is supposed to have a side effect, 13679 since the resulting value is not used. In the example 13680 the `append()` call appends the List with text to the 13681 buffer. This is similar to `:call` but works with any 13682 expression. 13683 13684 The command can be shortened to `:ev` or `:eva`, but 13685 these are hard to recognize and therefore not to be 13686 used. 13687 13688 The command cannot be followed by "|" and another 13689 command, since "|" is seen as part of the expression. 13690 13691 13692 *:exe* *:execute* 13693:exe[cute] {expr1} .. Executes the string that results from the evaluation 13694 of {expr1} as an Ex command. 13695 Multiple arguments are concatenated, with a space in 13696 between. To avoid the extra space use the ".." 13697 operator to concatenate strings into one argument. 13698 {expr1} is used as the processed command, command line 13699 editing keys are not recognized. 13700 Cannot be followed by a comment. 13701 Examples: > 13702 :execute "buffer" nextbuf 13703 :execute "normal" count .. "w" 13704< 13705 ":execute" can be used to append a command to commands 13706 that don't accept a '|'. Example: > 13707 :execute '!ls' | echo "theend" 13708 13709< ":execute" is also a nice way to avoid having to type 13710 control characters in a Vim script for a ":normal" 13711 command: > 13712 :execute "normal ixxx\<Esc>" 13713< This has an <Esc> character, see |expr-string|. 13714 13715 Be careful to correctly escape special characters in 13716 file names. The |fnameescape()| function can be used 13717 for Vim commands, |shellescape()| for |:!| commands. 13718 Examples: > 13719 :execute "e " .. fnameescape(filename) 13720 :execute "!ls " .. shellescape(filename, 1) 13721< 13722 Note: The executed string may be any command-line, but 13723 starting or ending "if", "while" and "for" does not 13724 always work, because when commands are skipped the 13725 ":execute" is not evaluated and Vim loses track of 13726 where blocks start and end. Also "break" and 13727 "continue" should not be inside ":execute". 13728 This example does not work, because the ":execute" is 13729 not evaluated and Vim does not see the "while", and 13730 gives an error for finding an ":endwhile": > 13731 :if 0 13732 : execute 'while i > 5' 13733 : echo "test" 13734 : endwhile 13735 :endif 13736< 13737 It is allowed to have a "while" or "if" command 13738 completely in the executed string: > 13739 :execute 'while i < 5 | echo i | let i = i + 1 | endwhile' 13740< 13741 13742 *:exe-comment* 13743 ":execute", ":echo" and ":echon" cannot be followed by 13744 a comment directly, because they see the '"' as the 13745 start of a string. But, you can use '|' followed by a 13746 comment. Example: > 13747 :echo "foo" | "this is a comment 13748 13749============================================================================== 137508. Exception handling *exception-handling* 13751 13752The Vim script language comprises an exception handling feature. This section 13753explains how it can be used in a Vim script. 13754 13755Exceptions may be raised by Vim on an error or on interrupt, see 13756|catch-errors| and |catch-interrupt|. You can also explicitly throw an 13757exception by using the ":throw" command, see |throw-catch|. 13758 13759 13760TRY CONDITIONALS *try-conditionals* 13761 13762Exceptions can be caught or can cause cleanup code to be executed. You can 13763use a try conditional to specify catch clauses (that catch exceptions) and/or 13764a finally clause (to be executed for cleanup). 13765 A try conditional begins with a |:try| command and ends at the matching 13766|:endtry| command. In between, you can use a |:catch| command to start 13767a catch clause, or a |:finally| command to start a finally clause. There may 13768be none or multiple catch clauses, but there is at most one finally clause, 13769which must not be followed by any catch clauses. The lines before the catch 13770clauses and the finally clause is called a try block. > 13771 13772 :try 13773 : ... 13774 : ... TRY BLOCK 13775 : ... 13776 :catch /{pattern}/ 13777 : ... 13778 : ... CATCH CLAUSE 13779 : ... 13780 :catch /{pattern}/ 13781 : ... 13782 : ... CATCH CLAUSE 13783 : ... 13784 :finally 13785 : ... 13786 : ... FINALLY CLAUSE 13787 : ... 13788 :endtry 13789 13790The try conditional allows to watch code for exceptions and to take the 13791appropriate actions. Exceptions from the try block may be caught. Exceptions 13792from the try block and also the catch clauses may cause cleanup actions. 13793 When no exception is thrown during execution of the try block, the control 13794is transferred to the finally clause, if present. After its execution, the 13795script continues with the line following the ":endtry". 13796 When an exception occurs during execution of the try block, the remaining 13797lines in the try block are skipped. The exception is matched against the 13798patterns specified as arguments to the ":catch" commands. The catch clause 13799after the first matching ":catch" is taken, other catch clauses are not 13800executed. The catch clause ends when the next ":catch", ":finally", or 13801":endtry" command is reached - whatever is first. Then, the finally clause 13802(if present) is executed. When the ":endtry" is reached, the script execution 13803continues in the following line as usual. 13804 When an exception that does not match any of the patterns specified by the 13805":catch" commands is thrown in the try block, the exception is not caught by 13806that try conditional and none of the catch clauses is executed. Only the 13807finally clause, if present, is taken. The exception pends during execution of 13808the finally clause. It is resumed at the ":endtry", so that commands after 13809the ":endtry" are not executed and the exception might be caught elsewhere, 13810see |try-nesting|. 13811 When during execution of a catch clause another exception is thrown, the 13812remaining lines in that catch clause are not executed. The new exception is 13813not matched against the patterns in any of the ":catch" commands of the same 13814try conditional and none of its catch clauses is taken. If there is, however, 13815a finally clause, it is executed, and the exception pends during its 13816execution. The commands following the ":endtry" are not executed. The new 13817exception might, however, be caught elsewhere, see |try-nesting|. 13818 When during execution of the finally clause (if present) an exception is 13819thrown, the remaining lines in the finally clause are skipped. If the finally 13820clause has been taken because of an exception from the try block or one of the 13821catch clauses, the original (pending) exception is discarded. The commands 13822following the ":endtry" are not executed, and the exception from the finally 13823clause is propagated and can be caught elsewhere, see |try-nesting|. 13824 13825The finally clause is also executed, when a ":break" or ":continue" for 13826a ":while" loop enclosing the complete try conditional is executed from the 13827try block or a catch clause. Or when a ":return" or ":finish" is executed 13828from the try block or a catch clause of a try conditional in a function or 13829sourced script, respectively. The ":break", ":continue", ":return", or 13830":finish" pends during execution of the finally clause and is resumed when the 13831":endtry" is reached. It is, however, discarded when an exception is thrown 13832from the finally clause. 13833 When a ":break" or ":continue" for a ":while" loop enclosing the complete 13834try conditional or when a ":return" or ":finish" is encountered in the finally 13835clause, the rest of the finally clause is skipped, and the ":break", 13836":continue", ":return" or ":finish" is executed as usual. If the finally 13837clause has been taken because of an exception or an earlier ":break", 13838":continue", ":return", or ":finish" from the try block or a catch clause, 13839this pending exception or command is discarded. 13840 13841For examples see |throw-catch| and |try-finally|. 13842 13843 13844NESTING OF TRY CONDITIONALS *try-nesting* 13845 13846Try conditionals can be nested arbitrarily. That is, a complete try 13847conditional can be put into the try block, a catch clause, or the finally 13848clause of another try conditional. If the inner try conditional does not 13849catch an exception thrown in its try block or throws a new exception from one 13850of its catch clauses or its finally clause, the outer try conditional is 13851checked according to the rules above. If the inner try conditional is in the 13852try block of the outer try conditional, its catch clauses are checked, but 13853otherwise only the finally clause is executed. It does not matter for 13854nesting, whether the inner try conditional is directly contained in the outer 13855one, or whether the outer one sources a script or calls a function containing 13856the inner try conditional. 13857 13858When none of the active try conditionals catches an exception, just their 13859finally clauses are executed. Thereafter, the script processing terminates. 13860An error message is displayed in case of an uncaught exception explicitly 13861thrown by a ":throw" command. For uncaught error and interrupt exceptions 13862implicitly raised by Vim, the error message(s) or interrupt message are shown 13863as usual. 13864 13865For examples see |throw-catch|. 13866 13867 13868EXAMINING EXCEPTION HANDLING CODE *except-examine* 13869 13870Exception handling code can get tricky. If you are in doubt what happens, set 13871'verbose' to 13 or use the ":13verbose" command modifier when sourcing your 13872script file. Then you see when an exception is thrown, discarded, caught, or 13873finished. When using a verbosity level of at least 14, things pending in 13874a finally clause are also shown. This information is also given in debug mode 13875(see |debug-scripts|). 13876 13877 13878THROWING AND CATCHING EXCEPTIONS *throw-catch* 13879 13880You can throw any number or string as an exception. Use the |:throw| command 13881and pass the value to be thrown as argument: > 13882 :throw 4711 13883 :throw "string" 13884< *throw-expression* 13885You can also specify an expression argument. The expression is then evaluated 13886first, and the result is thrown: > 13887 :throw 4705 + strlen("string") 13888 :throw strpart("strings", 0, 6) 13889 13890An exception might be thrown during evaluation of the argument of the ":throw" 13891command. Unless it is caught there, the expression evaluation is abandoned. 13892The ":throw" command then does not throw a new exception. 13893 Example: > 13894 13895 :function! Foo(arg) 13896 : try 13897 : throw a:arg 13898 : catch /foo/ 13899 : endtry 13900 : return 1 13901 :endfunction 13902 : 13903 :function! Bar() 13904 : echo "in Bar" 13905 : return 4710 13906 :endfunction 13907 : 13908 :throw Foo("arrgh") + Bar() 13909 13910This throws "arrgh", and "in Bar" is not displayed since Bar() is not 13911executed. > 13912 :throw Foo("foo") + Bar() 13913however displays "in Bar" and throws 4711. 13914 13915Any other command that takes an expression as argument might also be 13916abandoned by an (uncaught) exception during the expression evaluation. The 13917exception is then propagated to the caller of the command. 13918 Example: > 13919 13920 :if Foo("arrgh") 13921 : echo "then" 13922 :else 13923 : echo "else" 13924 :endif 13925 13926Here neither of "then" or "else" is displayed. 13927 13928 *catch-order* 13929Exceptions can be caught by a try conditional with one or more |:catch| 13930commands, see |try-conditionals|. The values to be caught by each ":catch" 13931command can be specified as a pattern argument. The subsequent catch clause 13932gets executed when a matching exception is caught. 13933 Example: > 13934 13935 :function! Foo(value) 13936 : try 13937 : throw a:value 13938 : catch /^\d\+$/ 13939 : echo "Number thrown" 13940 : catch /.*/ 13941 : echo "String thrown" 13942 : endtry 13943 :endfunction 13944 : 13945 :call Foo(0x1267) 13946 :call Foo('string') 13947 13948The first call to Foo() displays "Number thrown", the second "String thrown". 13949An exception is matched against the ":catch" commands in the order they are 13950specified. Only the first match counts. So you should place the more 13951specific ":catch" first. The following order does not make sense: > 13952 13953 : catch /.*/ 13954 : echo "String thrown" 13955 : catch /^\d\+$/ 13956 : echo "Number thrown" 13957 13958The first ":catch" here matches always, so that the second catch clause is 13959never taken. 13960 13961 *throw-variables* 13962If you catch an exception by a general pattern, you may access the exact value 13963in the variable |v:exception|: > 13964 13965 : catch /^\d\+$/ 13966 : echo "Number thrown. Value is" v:exception 13967 13968You may also be interested where an exception was thrown. This is stored in 13969|v:throwpoint|. Note that "v:exception" and "v:throwpoint" are valid for the 13970exception most recently caught as long it is not finished. 13971 Example: > 13972 13973 :function! Caught() 13974 : if v:exception != "" 13975 : echo 'Caught "' . v:exception . '" in ' . v:throwpoint 13976 : else 13977 : echo 'Nothing caught' 13978 : endif 13979 :endfunction 13980 : 13981 :function! Foo() 13982 : try 13983 : try 13984 : try 13985 : throw 4711 13986 : finally 13987 : call Caught() 13988 : endtry 13989 : catch /.*/ 13990 : call Caught() 13991 : throw "oops" 13992 : endtry 13993 : catch /.*/ 13994 : call Caught() 13995 : finally 13996 : call Caught() 13997 : endtry 13998 :endfunction 13999 : 14000 :call Foo() 14001 14002This displays > 14003 14004 Nothing caught 14005 Caught "4711" in function Foo, line 4 14006 Caught "oops" in function Foo, line 10 14007 Nothing caught 14008 14009A practical example: The following command ":LineNumber" displays the line 14010number in the script or function where it has been used: > 14011 14012 :function! LineNumber() 14013 : return substitute(v:throwpoint, '.*\D\(\d\+\).*', '\1', "") 14014 :endfunction 14015 :command! LineNumber try | throw "" | catch | echo LineNumber() | endtry 14016< 14017 *try-nested* 14018An exception that is not caught by a try conditional can be caught by 14019a surrounding try conditional: > 14020 14021 :try 14022 : try 14023 : throw "foo" 14024 : catch /foobar/ 14025 : echo "foobar" 14026 : finally 14027 : echo "inner finally" 14028 : endtry 14029 :catch /foo/ 14030 : echo "foo" 14031 :endtry 14032 14033The inner try conditional does not catch the exception, just its finally 14034clause is executed. The exception is then caught by the outer try 14035conditional. The example displays "inner finally" and then "foo". 14036 14037 *throw-from-catch* 14038You can catch an exception and throw a new one to be caught elsewhere from the 14039catch clause: > 14040 14041 :function! Foo() 14042 : throw "foo" 14043 :endfunction 14044 : 14045 :function! Bar() 14046 : try 14047 : call Foo() 14048 : catch /foo/ 14049 : echo "Caught foo, throw bar" 14050 : throw "bar" 14051 : endtry 14052 :endfunction 14053 : 14054 :try 14055 : call Bar() 14056 :catch /.*/ 14057 : echo "Caught" v:exception 14058 :endtry 14059 14060This displays "Caught foo, throw bar" and then "Caught bar". 14061 14062 *rethrow* 14063There is no real rethrow in the Vim script language, but you may throw 14064"v:exception" instead: > 14065 14066 :function! Bar() 14067 : try 14068 : call Foo() 14069 : catch /.*/ 14070 : echo "Rethrow" v:exception 14071 : throw v:exception 14072 : endtry 14073 :endfunction 14074< *try-echoerr* 14075Note that this method cannot be used to "rethrow" Vim error or interrupt 14076exceptions, because it is not possible to fake Vim internal exceptions. 14077Trying so causes an error exception. You should throw your own exception 14078denoting the situation. If you want to cause a Vim error exception containing 14079the original error exception value, you can use the |:echoerr| command: > 14080 14081 :try 14082 : try 14083 : asdf 14084 : catch /.*/ 14085 : echoerr v:exception 14086 : endtry 14087 :catch /.*/ 14088 : echo v:exception 14089 :endtry 14090 14091This code displays 14092 14093 Vim(echoerr):Vim:E492: Not an editor command: asdf ~ 14094 14095 14096CLEANUP CODE *try-finally* 14097 14098Scripts often change global settings and restore them at their end. If the 14099user however interrupts the script by pressing CTRL-C, the settings remain in 14100an inconsistent state. The same may happen to you in the development phase of 14101a script when an error occurs or you explicitly throw an exception without 14102catching it. You can solve these problems by using a try conditional with 14103a finally clause for restoring the settings. Its execution is guaranteed on 14104normal control flow, on error, on an explicit ":throw", and on interrupt. 14105(Note that errors and interrupts from inside the try conditional are converted 14106to exceptions. When not caught, they terminate the script after the finally 14107clause has been executed.) 14108Example: > 14109 14110 :try 14111 : let s:saved_ts = &ts 14112 : set ts=17 14113 : 14114 : " Do the hard work here. 14115 : 14116 :finally 14117 : let &ts = s:saved_ts 14118 : unlet s:saved_ts 14119 :endtry 14120 14121This method should be used locally whenever a function or part of a script 14122changes global settings which need to be restored on failure or normal exit of 14123that function or script part. 14124 14125 *break-finally* 14126Cleanup code works also when the try block or a catch clause is left by 14127a ":continue", ":break", ":return", or ":finish". 14128 Example: > 14129 14130 :let first = 1 14131 :while 1 14132 : try 14133 : if first 14134 : echo "first" 14135 : let first = 0 14136 : continue 14137 : else 14138 : throw "second" 14139 : endif 14140 : catch /.*/ 14141 : echo v:exception 14142 : break 14143 : finally 14144 : echo "cleanup" 14145 : endtry 14146 : echo "still in while" 14147 :endwhile 14148 :echo "end" 14149 14150This displays "first", "cleanup", "second", "cleanup", and "end". > 14151 14152 :function! Foo() 14153 : try 14154 : return 4711 14155 : finally 14156 : echo "cleanup\n" 14157 : endtry 14158 : echo "Foo still active" 14159 :endfunction 14160 : 14161 :echo Foo() "returned by Foo" 14162 14163This displays "cleanup" and "4711 returned by Foo". You don't need to add an 14164extra ":return" in the finally clause. (Above all, this would override the 14165return value.) 14166 14167 *except-from-finally* 14168Using either of ":continue", ":break", ":return", ":finish", or ":throw" in 14169a finally clause is possible, but not recommended since it abandons the 14170cleanup actions for the try conditional. But, of course, interrupt and error 14171exceptions might get raised from a finally clause. 14172 Example where an error in the finally clause stops an interrupt from 14173working correctly: > 14174 14175 :try 14176 : try 14177 : echo "Press CTRL-C for interrupt" 14178 : while 1 14179 : endwhile 14180 : finally 14181 : unlet novar 14182 : endtry 14183 :catch /novar/ 14184 :endtry 14185 :echo "Script still running" 14186 :sleep 1 14187 14188If you need to put commands that could fail into a finally clause, you should 14189think about catching or ignoring the errors in these commands, see 14190|catch-errors| and |ignore-errors|. 14191 14192 14193CATCHING ERRORS *catch-errors* 14194 14195If you want to catch specific errors, you just have to put the code to be 14196watched in a try block and add a catch clause for the error message. The 14197presence of the try conditional causes all errors to be converted to an 14198exception. No message is displayed and |v:errmsg| is not set then. To find 14199the right pattern for the ":catch" command, you have to know how the format of 14200the error exception is. 14201 Error exceptions have the following format: > 14202 14203 Vim({cmdname}):{errmsg} 14204or > 14205 Vim:{errmsg} 14206 14207{cmdname} is the name of the command that failed; the second form is used when 14208the command name is not known. {errmsg} is the error message usually produced 14209when the error occurs outside try conditionals. It always begins with 14210a capital "E", followed by a two or three-digit error number, a colon, and 14211a space. 14212 14213Examples: 14214 14215The command > 14216 :unlet novar 14217normally produces the error message > 14218 E108: No such variable: "novar" 14219which is converted inside try conditionals to an exception > 14220 Vim(unlet):E108: No such variable: "novar" 14221 14222The command > 14223 :dwim 14224normally produces the error message > 14225 E492: Not an editor command: dwim 14226which is converted inside try conditionals to an exception > 14227 Vim:E492: Not an editor command: dwim 14228 14229You can catch all ":unlet" errors by a > 14230 :catch /^Vim(unlet):/ 14231or all errors for misspelled command names by a > 14232 :catch /^Vim:E492:/ 14233 14234Some error messages may be produced by different commands: > 14235 :function nofunc 14236and > 14237 :delfunction nofunc 14238both produce the error message > 14239 E128: Function name must start with a capital: nofunc 14240which is converted inside try conditionals to an exception > 14241 Vim(function):E128: Function name must start with a capital: nofunc 14242or > 14243 Vim(delfunction):E128: Function name must start with a capital: nofunc 14244respectively. You can catch the error by its number independently on the 14245command that caused it if you use the following pattern: > 14246 :catch /^Vim(\a\+):E128:/ 14247 14248Some commands like > 14249 :let x = novar 14250produce multiple error messages, here: > 14251 E121: Undefined variable: novar 14252 E15: Invalid expression: novar 14253Only the first is used for the exception value, since it is the most specific 14254one (see |except-several-errors|). So you can catch it by > 14255 :catch /^Vim(\a\+):E121:/ 14256 14257You can catch all errors related to the name "nofunc" by > 14258 :catch /\<nofunc\>/ 14259 14260You can catch all Vim errors in the ":write" and ":read" commands by > 14261 :catch /^Vim(\(write\|read\)):E\d\+:/ 14262 14263You can catch all Vim errors by the pattern > 14264 :catch /^Vim\((\a\+)\)\=:E\d\+:/ 14265< 14266 *catch-text* 14267NOTE: You should never catch the error message text itself: > 14268 :catch /No such variable/ 14269only works in the English locale, but not when the user has selected 14270a different language by the |:language| command. It is however helpful to 14271cite the message text in a comment: > 14272 :catch /^Vim(\a\+):E108:/ " No such variable 14273 14274 14275IGNORING ERRORS *ignore-errors* 14276 14277You can ignore errors in a specific Vim command by catching them locally: > 14278 14279 :try 14280 : write 14281 :catch 14282 :endtry 14283 14284But you are strongly recommended NOT to use this simple form, since it could 14285catch more than you want. With the ":write" command, some autocommands could 14286be executed and cause errors not related to writing, for instance: > 14287 14288 :au BufWritePre * unlet novar 14289 14290There could even be such errors you are not responsible for as a script 14291writer: a user of your script might have defined such autocommands. You would 14292then hide the error from the user. 14293 It is much better to use > 14294 14295 :try 14296 : write 14297 :catch /^Vim(write):/ 14298 :endtry 14299 14300which only catches real write errors. So catch only what you'd like to ignore 14301intentionally. 14302 14303For a single command that does not cause execution of autocommands, you could 14304even suppress the conversion of errors to exceptions by the ":silent!" 14305command: > 14306 :silent! nunmap k 14307This works also when a try conditional is active. 14308 14309 14310CATCHING INTERRUPTS *catch-interrupt* 14311 14312When there are active try conditionals, an interrupt (CTRL-C) is converted to 14313the exception "Vim:Interrupt". You can catch it like every exception. The 14314script is not terminated, then. 14315 Example: > 14316 14317 :function! TASK1() 14318 : sleep 10 14319 :endfunction 14320 14321 :function! TASK2() 14322 : sleep 20 14323 :endfunction 14324 14325 :while 1 14326 : let command = input("Type a command: ") 14327 : try 14328 : if command == "" 14329 : continue 14330 : elseif command == "END" 14331 : break 14332 : elseif command == "TASK1" 14333 : call TASK1() 14334 : elseif command == "TASK2" 14335 : call TASK2() 14336 : else 14337 : echo "\nIllegal command:" command 14338 : continue 14339 : endif 14340 : catch /^Vim:Interrupt$/ 14341 : echo "\nCommand interrupted" 14342 : " Caught the interrupt. Continue with next prompt. 14343 : endtry 14344 :endwhile 14345 14346You can interrupt a task here by pressing CTRL-C; the script then asks for 14347a new command. If you press CTRL-C at the prompt, the script is terminated. 14348 14349For testing what happens when CTRL-C would be pressed on a specific line in 14350your script, use the debug mode and execute the |>quit| or |>interrupt| 14351command on that line. See |debug-scripts|. 14352 14353 14354CATCHING ALL *catch-all* 14355 14356The commands > 14357 14358 :catch /.*/ 14359 :catch // 14360 :catch 14361 14362catch everything, error exceptions, interrupt exceptions and exceptions 14363explicitly thrown by the |:throw| command. This is useful at the top level of 14364a script in order to catch unexpected things. 14365 Example: > 14366 14367 :try 14368 : 14369 : " do the hard work here 14370 : 14371 :catch /MyException/ 14372 : 14373 : " handle known problem 14374 : 14375 :catch /^Vim:Interrupt$/ 14376 : echo "Script interrupted" 14377 :catch /.*/ 14378 : echo "Internal error (" . v:exception . ")" 14379 : echo " - occurred at " . v:throwpoint 14380 :endtry 14381 :" end of script 14382 14383Note: Catching all might catch more things than you want. Thus, you are 14384strongly encouraged to catch only for problems that you can really handle by 14385specifying a pattern argument to the ":catch". 14386 Example: Catching all could make it nearly impossible to interrupt a script 14387by pressing CTRL-C: > 14388 14389 :while 1 14390 : try 14391 : sleep 1 14392 : catch 14393 : endtry 14394 :endwhile 14395 14396 14397EXCEPTIONS AND AUTOCOMMANDS *except-autocmd* 14398 14399Exceptions may be used during execution of autocommands. Example: > 14400 14401 :autocmd User x try 14402 :autocmd User x throw "Oops!" 14403 :autocmd User x catch 14404 :autocmd User x echo v:exception 14405 :autocmd User x endtry 14406 :autocmd User x throw "Arrgh!" 14407 :autocmd User x echo "Should not be displayed" 14408 : 14409 :try 14410 : doautocmd User x 14411 :catch 14412 : echo v:exception 14413 :endtry 14414 14415This displays "Oops!" and "Arrgh!". 14416 14417 *except-autocmd-Pre* 14418For some commands, autocommands get executed before the main action of the 14419command takes place. If an exception is thrown and not caught in the sequence 14420of autocommands, the sequence and the command that caused its execution are 14421abandoned and the exception is propagated to the caller of the command. 14422 Example: > 14423 14424 :autocmd BufWritePre * throw "FAIL" 14425 :autocmd BufWritePre * echo "Should not be displayed" 14426 : 14427 :try 14428 : write 14429 :catch 14430 : echo "Caught:" v:exception "from" v:throwpoint 14431 :endtry 14432 14433Here, the ":write" command does not write the file currently being edited (as 14434you can see by checking 'modified'), since the exception from the BufWritePre 14435autocommand abandons the ":write". The exception is then caught and the 14436script displays: > 14437 14438 Caught: FAIL from BufWrite Auto commands for "*" 14439< 14440 *except-autocmd-Post* 14441For some commands, autocommands get executed after the main action of the 14442command has taken place. If this main action fails and the command is inside 14443an active try conditional, the autocommands are skipped and an error exception 14444is thrown that can be caught by the caller of the command. 14445 Example: > 14446 14447 :autocmd BufWritePost * echo "File successfully written!" 14448 : 14449 :try 14450 : write /i/m/p/o/s/s/i/b/l/e 14451 :catch 14452 : echo v:exception 14453 :endtry 14454 14455This just displays: > 14456 14457 Vim(write):E212: Can't open file for writing (/i/m/p/o/s/s/i/b/l/e) 14458 14459If you really need to execute the autocommands even when the main action 14460fails, trigger the event from the catch clause. 14461 Example: > 14462 14463 :autocmd BufWritePre * set noreadonly 14464 :autocmd BufWritePost * set readonly 14465 : 14466 :try 14467 : write /i/m/p/o/s/s/i/b/l/e 14468 :catch 14469 : doautocmd BufWritePost /i/m/p/o/s/s/i/b/l/e 14470 :endtry 14471< 14472You can also use ":silent!": > 14473 14474 :let x = "ok" 14475 :let v:errmsg = "" 14476 :autocmd BufWritePost * if v:errmsg != "" 14477 :autocmd BufWritePost * let x = "after fail" 14478 :autocmd BufWritePost * endif 14479 :try 14480 : silent! write /i/m/p/o/s/s/i/b/l/e 14481 :catch 14482 :endtry 14483 :echo x 14484 14485This displays "after fail". 14486 14487If the main action of the command does not fail, exceptions from the 14488autocommands will be catchable by the caller of the command: > 14489 14490 :autocmd BufWritePost * throw ":-(" 14491 :autocmd BufWritePost * echo "Should not be displayed" 14492 : 14493 :try 14494 : write 14495 :catch 14496 : echo v:exception 14497 :endtry 14498< 14499 *except-autocmd-Cmd* 14500For some commands, the normal action can be replaced by a sequence of 14501autocommands. Exceptions from that sequence will be catchable by the caller 14502of the command. 14503 Example: For the ":write" command, the caller cannot know whether the file 14504had actually been written when the exception occurred. You need to tell it in 14505some way. > 14506 14507 :if !exists("cnt") 14508 : let cnt = 0 14509 : 14510 : autocmd BufWriteCmd * if &modified 14511 : autocmd BufWriteCmd * let cnt = cnt + 1 14512 : autocmd BufWriteCmd * if cnt % 3 == 2 14513 : autocmd BufWriteCmd * throw "BufWriteCmdError" 14514 : autocmd BufWriteCmd * endif 14515 : autocmd BufWriteCmd * write | set nomodified 14516 : autocmd BufWriteCmd * if cnt % 3 == 0 14517 : autocmd BufWriteCmd * throw "BufWriteCmdError" 14518 : autocmd BufWriteCmd * endif 14519 : autocmd BufWriteCmd * echo "File successfully written!" 14520 : autocmd BufWriteCmd * endif 14521 :endif 14522 : 14523 :try 14524 : write 14525 :catch /^BufWriteCmdError$/ 14526 : if &modified 14527 : echo "Error on writing (file contents not changed)" 14528 : else 14529 : echo "Error after writing" 14530 : endif 14531 :catch /^Vim(write):/ 14532 : echo "Error on writing" 14533 :endtry 14534 14535When this script is sourced several times after making changes, it displays 14536first > 14537 File successfully written! 14538then > 14539 Error on writing (file contents not changed) 14540then > 14541 Error after writing 14542etc. 14543 14544 *except-autocmd-ill* 14545You cannot spread a try conditional over autocommands for different events. 14546The following code is ill-formed: > 14547 14548 :autocmd BufWritePre * try 14549 : 14550 :autocmd BufWritePost * catch 14551 :autocmd BufWritePost * echo v:exception 14552 :autocmd BufWritePost * endtry 14553 : 14554 :write 14555 14556 14557EXCEPTION HIERARCHIES AND PARAMETERIZED EXCEPTIONS *except-hier-param* 14558 14559Some programming languages allow to use hierarchies of exception classes or to 14560pass additional information with the object of an exception class. You can do 14561similar things in Vim. 14562 In order to throw an exception from a hierarchy, just throw the complete 14563class name with the components separated by a colon, for instance throw the 14564string "EXCEPT:MATHERR:OVERFLOW" for an overflow in a mathematical library. 14565 When you want to pass additional information with your exception class, add 14566it in parentheses, for instance throw the string "EXCEPT:IO:WRITEERR(myfile)" 14567for an error when writing "myfile". 14568 With the appropriate patterns in the ":catch" command, you can catch for 14569base classes or derived classes of your hierarchy. Additional information in 14570parentheses can be cut out from |v:exception| with the ":substitute" command. 14571 Example: > 14572 14573 :function! CheckRange(a, func) 14574 : if a:a < 0 14575 : throw "EXCEPT:MATHERR:RANGE(" . a:func . ")" 14576 : endif 14577 :endfunction 14578 : 14579 :function! Add(a, b) 14580 : call CheckRange(a:a, "Add") 14581 : call CheckRange(a:b, "Add") 14582 : let c = a:a + a:b 14583 : if c < 0 14584 : throw "EXCEPT:MATHERR:OVERFLOW" 14585 : endif 14586 : return c 14587 :endfunction 14588 : 14589 :function! Div(a, b) 14590 : call CheckRange(a:a, "Div") 14591 : call CheckRange(a:b, "Div") 14592 : if (a:b == 0) 14593 : throw "EXCEPT:MATHERR:ZERODIV" 14594 : endif 14595 : return a:a / a:b 14596 :endfunction 14597 : 14598 :function! Write(file) 14599 : try 14600 : execute "write" fnameescape(a:file) 14601 : catch /^Vim(write):/ 14602 : throw "EXCEPT:IO(" . getcwd() . ", " . a:file . "):WRITEERR" 14603 : endtry 14604 :endfunction 14605 : 14606 :try 14607 : 14608 : " something with arithmetics and I/O 14609 : 14610 :catch /^EXCEPT:MATHERR:RANGE/ 14611 : let function = substitute(v:exception, '.*(\(\a\+\)).*', '\1', "") 14612 : echo "Range error in" function 14613 : 14614 :catch /^EXCEPT:MATHERR/ " catches OVERFLOW and ZERODIV 14615 : echo "Math error" 14616 : 14617 :catch /^EXCEPT:IO/ 14618 : let dir = substitute(v:exception, '.*(\(.\+\),\s*.\+).*', '\1', "") 14619 : let file = substitute(v:exception, '.*(.\+,\s*\(.\+\)).*', '\1', "") 14620 : if file !~ '^/' 14621 : let file = dir . "/" . file 14622 : endif 14623 : echo 'I/O error for "' . file . '"' 14624 : 14625 :catch /^EXCEPT/ 14626 : echo "Unspecified error" 14627 : 14628 :endtry 14629 14630The exceptions raised by Vim itself (on error or when pressing CTRL-C) use 14631a flat hierarchy: they are all in the "Vim" class. You cannot throw yourself 14632exceptions with the "Vim" prefix; they are reserved for Vim. 14633 Vim error exceptions are parameterized with the name of the command that 14634failed, if known. See |catch-errors|. 14635 14636 14637PECULIARITIES 14638 *except-compat* 14639The exception handling concept requires that the command sequence causing the 14640exception is aborted immediately and control is transferred to finally clauses 14641and/or a catch clause. 14642 14643In the Vim script language there are cases where scripts and functions 14644continue after an error: in functions without the "abort" flag or in a command 14645after ":silent!", control flow goes to the following line, and outside 14646functions, control flow goes to the line following the outermost ":endwhile" 14647or ":endif". On the other hand, errors should be catchable as exceptions 14648(thus, requiring the immediate abortion). 14649 14650This problem has been solved by converting errors to exceptions and using 14651immediate abortion (if not suppressed by ":silent!") only when a try 14652conditional is active. This is no restriction since an (error) exception can 14653be caught only from an active try conditional. If you want an immediate 14654termination without catching the error, just use a try conditional without 14655catch clause. (You can cause cleanup code being executed before termination 14656by specifying a finally clause.) 14657 14658When no try conditional is active, the usual abortion and continuation 14659behavior is used instead of immediate abortion. This ensures compatibility of 14660scripts written for Vim 6.1 and earlier. 14661 14662However, when sourcing an existing script that does not use exception handling 14663commands (or when calling one of its functions) from inside an active try 14664conditional of a new script, you might change the control flow of the existing 14665script on error. You get the immediate abortion on error and can catch the 14666error in the new script. If however the sourced script suppresses error 14667messages by using the ":silent!" command (checking for errors by testing 14668|v:errmsg| if appropriate), its execution path is not changed. The error is 14669not converted to an exception. (See |:silent|.) So the only remaining cause 14670where this happens is for scripts that don't care about errors and produce 14671error messages. You probably won't want to use such code from your new 14672scripts. 14673 14674 *except-syntax-err* 14675Syntax errors in the exception handling commands are never caught by any of 14676the ":catch" commands of the try conditional they belong to. Its finally 14677clauses, however, is executed. 14678 Example: > 14679 14680 :try 14681 : try 14682 : throw 4711 14683 : catch /\(/ 14684 : echo "in catch with syntax error" 14685 : catch 14686 : echo "inner catch-all" 14687 : finally 14688 : echo "inner finally" 14689 : endtry 14690 :catch 14691 : echo 'outer catch-all caught "' . v:exception . '"' 14692 : finally 14693 : echo "outer finally" 14694 :endtry 14695 14696This displays: > 14697 inner finally 14698 outer catch-all caught "Vim(catch):E54: Unmatched \(" 14699 outer finally 14700The original exception is discarded and an error exception is raised, instead. 14701 14702 *except-single-line* 14703The ":try", ":catch", ":finally", and ":endtry" commands can be put on 14704a single line, but then syntax errors may make it difficult to recognize the 14705"catch" line, thus you better avoid this. 14706 Example: > 14707 :try | unlet! foo # | catch | endtry 14708raises an error exception for the trailing characters after the ":unlet!" 14709argument, but does not see the ":catch" and ":endtry" commands, so that the 14710error exception is discarded and the "E488: Trailing characters" message gets 14711displayed. 14712 14713 *except-several-errors* 14714When several errors appear in a single command, the first error message is 14715usually the most specific one and therefore converted to the error exception. 14716 Example: > 14717 echo novar 14718causes > 14719 E121: Undefined variable: novar 14720 E15: Invalid expression: novar 14721The value of the error exception inside try conditionals is: > 14722 Vim(echo):E121: Undefined variable: novar 14723< *except-syntax-error* 14724But when a syntax error is detected after a normal error in the same command, 14725the syntax error is used for the exception being thrown. 14726 Example: > 14727 unlet novar # 14728causes > 14729 E108: No such variable: "novar" 14730 E488: Trailing characters 14731The value of the error exception inside try conditionals is: > 14732 Vim(unlet):E488: Trailing characters 14733This is done because the syntax error might change the execution path in a way 14734not intended by the user. Example: > 14735 try 14736 try | unlet novar # | catch | echo v:exception | endtry 14737 catch /.*/ 14738 echo "outer catch:" v:exception 14739 endtry 14740This displays "outer catch: Vim(unlet):E488: Trailing characters", and then 14741a "E600: Missing :endtry" error message is given, see |except-single-line|. 14742 14743============================================================================== 147449. Examples *eval-examples* 14745 14746Printing in Binary ~ 14747> 14748 :" The function Nr2Bin() returns the binary string representation of a number. 14749 :func Nr2Bin(nr) 14750 : let n = a:nr 14751 : let r = "" 14752 : while n 14753 : let r = '01'[n % 2] . r 14754 : let n = n / 2 14755 : endwhile 14756 : return r 14757 :endfunc 14758 14759 :" The function String2Bin() converts each character in a string to a 14760 :" binary string, separated with dashes. 14761 :func String2Bin(str) 14762 : let out = '' 14763 : for ix in range(strlen(a:str)) 14764 : let out = out . '-' . Nr2Bin(char2nr(a:str[ix])) 14765 : endfor 14766 : return out[1:] 14767 :endfunc 14768 14769Example of its use: > 14770 :echo Nr2Bin(32) 14771result: "100000" > 14772 :echo String2Bin("32") 14773result: "110011-110010" 14774 14775 14776Sorting lines ~ 14777 14778This example sorts lines with a specific compare function. > 14779 14780 :func SortBuffer() 14781 : let lines = getline(1, '$') 14782 : call sort(lines, function("Strcmp")) 14783 : call setline(1, lines) 14784 :endfunction 14785 14786As a one-liner: > 14787 :call setline(1, sort(getline(1, '$'), function("Strcmp"))) 14788 14789 14790scanf() replacement ~ 14791 *sscanf* 14792There is no sscanf() function in Vim. If you need to extract parts from a 14793line, you can use matchstr() and substitute() to do it. This example shows 14794how to get the file name, line number and column number out of a line like 14795"foobar.txt, 123, 45". > 14796 :" Set up the match bit 14797 :let mx='\(\f\+\),\s*\(\d\+\),\s*\(\d\+\)' 14798 :"get the part matching the whole expression 14799 :let l = matchstr(line, mx) 14800 :"get each item out of the match 14801 :let file = substitute(l, mx, '\1', '') 14802 :let lnum = substitute(l, mx, '\2', '') 14803 :let col = substitute(l, mx, '\3', '') 14804 14805The input is in the variable "line", the results in the variables "file", 14806"lnum" and "col". (idea from Michael Geddes) 14807 14808 14809getting the scriptnames in a Dictionary ~ 14810 *scriptnames-dictionary* 14811The |:scriptnames| command can be used to get a list of all script files that 14812have been sourced. There is no equivalent function or variable for this 14813(because it's rarely needed). In case you need to manipulate the list this 14814code can be used: > 14815 " Get the output of ":scriptnames" in the scriptnames_output variable. 14816 let scriptnames_output = '' 14817 redir => scriptnames_output 14818 silent scriptnames 14819 redir END 14820 14821 " Split the output into lines and parse each line. Add an entry to the 14822 " "scripts" dictionary. 14823 let scripts = {} 14824 for line in split(scriptnames_output, "\n") 14825 " Only do non-blank lines. 14826 if line =~ '\S' 14827 " Get the first number in the line. 14828 let nr = matchstr(line, '\d\+') 14829 " Get the file name, remove the script number " 123: ". 14830 let name = substitute(line, '.\+:\s*', '', '') 14831 " Add an item to the Dictionary 14832 let scripts[nr] = name 14833 endif 14834 endfor 14835 unlet scriptnames_output 14836 14837============================================================================== 1483810. Vim script versions *vimscript-version* *vimscript-versions* 14839 *scriptversion* 14840Over time many features have been added to Vim script. This includes Ex 14841commands, functions, variable types, etc. Each individual feature can be 14842checked with the |has()| and |exists()| functions. 14843 14844Sometimes old syntax of functionality gets in the way of making Vim better. 14845When support is taken away this will break older Vim scripts. To make this 14846explicit the |:scriptversion| command can be used. When a Vim script is not 14847compatible with older versions of Vim this will give an explicit error, 14848instead of failing in mysterious ways. 14849 14850 *scriptversion-1* > 14851 :scriptversion 1 14852< This is the original Vim script, same as not using a |:scriptversion| 14853 command. Can be used to go back to old syntax for a range of lines. 14854 Test for support with: > 14855 has('vimscript-1') 14856 14857< *scriptversion-2* > 14858 :scriptversion 2 14859< String concatenation with "." is not supported, use ".." instead. 14860 This avoids the ambiguity using "." for Dict member access and 14861 floating point numbers. Now ".5" means the number 0.5. 14862 14863 *scriptversion-3* > 14864 :scriptversion 3 14865< All |vim-variable|s must be prefixed by "v:". E.g. "version" doesn't 14866 work as |v:version| anymore, it can be used as a normal variable. 14867 Same for some obvious names as "count" and others. 14868 14869 Test for support with: > 14870 has('vimscript-3') 14871< 14872 *scriptversion-4* > 14873 :scriptversion 4 14874< Numbers with a leading zero are not recognized as octal. "0o" or "0O" 14875 is still recognized as octal. With the 14876 previous version you get: > 14877 echo 017 " displays 15 (octal) 14878 echo 0o17 " displays 15 (octal) 14879 echo 018 " displays 18 (decimal) 14880< with script version 4: > 14881 echo 017 " displays 17 (decimal) 14882 echo 0o17 " displays 15 (octal) 14883 echo 018 " displays 18 (decimal) 14884< Also, it is possible to use single quotes inside numbers to make them 14885 easier to read: > 14886 echo 1'000'000 14887< The quotes must be surrounded by digits. 14888 14889 Test for support with: > 14890 has('vimscript-4') 14891 14892============================================================================== 1489311. No +eval feature *no-eval-feature* 14894 14895When the |+eval| feature was disabled at compile time, none of the expression 14896evaluation commands are available. To prevent this from causing Vim scripts 14897to generate all kinds of errors, the ":if" and ":endif" commands are still 14898recognized, though the argument of the ":if" and everything between the ":if" 14899and the matching ":endif" is ignored. Nesting of ":if" blocks is allowed, but 14900only if the commands are at the start of the line. The ":else" command is not 14901recognized. 14902 14903Example of how to avoid executing commands when the |+eval| feature is 14904missing: > 14905 14906 :if 1 14907 : echo "Expression evaluation is compiled in" 14908 :else 14909 : echo "You will _never_ see this message" 14910 :endif 14911 14912To execute a command only when the |+eval| feature is disabled can be done in 14913two ways. The simplest is to exit the script (or Vim) prematurely: > 14914 if 1 14915 echo "commands executed with +eval" 14916 finish 14917 endif 14918 args " command executed without +eval 14919 14920If you do not want to abort loading the script you can use a trick, as this 14921example shows: > 14922 14923 silent! while 0 14924 set history=111 14925 silent! endwhile 14926 14927When the |+eval| feature is available the command is skipped because of the 14928"while 0". Without the |+eval| feature the "while 0" is an error, which is 14929silently ignored, and the command is executed. 14930 14931============================================================================== 1493212. The sandbox *eval-sandbox* *sandbox* *E48* 14933 14934The 'foldexpr', 'formatexpr', 'includeexpr', 'indentexpr', 'statusline' and 14935'foldtext' options may be evaluated in a sandbox. This means that you are 14936protected from these expressions having nasty side effects. This gives some 14937safety for when these options are set from a modeline. It is also used when 14938the command from a tags file is executed and for CTRL-R = in the command line. 14939The sandbox is also used for the |:sandbox| command. 14940 14941These items are not allowed in the sandbox: 14942 - changing the buffer text 14943 - defining or changing mapping, autocommands, user commands 14944 - setting certain options (see |option-summary|) 14945 - setting certain v: variables (see |v:var|) *E794* 14946 - executing a shell command 14947 - reading or writing a file 14948 - jumping to another buffer or editing a file 14949 - executing Python, Perl, etc. commands 14950This is not guaranteed 100% secure, but it should block most attacks. 14951 14952 *:san* *:sandbox* 14953:san[dbox] {cmd} Execute {cmd} in the sandbox. Useful to evaluate an 14954 option that may have been set from a modeline, e.g. 14955 'foldexpr'. 14956 14957 *sandbox-option* 14958A few options contain an expression. When this expression is evaluated it may 14959have to be done in the sandbox to avoid a security risk. But the sandbox is 14960restrictive, thus this only happens when the option was set from an insecure 14961location. Insecure in this context are: 14962- sourcing a .vimrc or .exrc in the current directory 14963- while executing in the sandbox 14964- value coming from a modeline 14965- executing a function that was defined in the sandbox 14966 14967Note that when in the sandbox and saving an option value and restoring it, the 14968option will still be marked as it was set in the sandbox. 14969 14970============================================================================== 1497113. Textlock *textlock* 14972 14973In a few situations it is not allowed to change the text in the buffer, jump 14974to another window and some other things that might confuse or break what Vim 14975is currently doing. This mostly applies to things that happen when Vim is 14976actually doing something else. For example, evaluating the 'balloonexpr' may 14977happen any moment the mouse cursor is resting at some position. 14978 14979This is not allowed when the textlock is active: 14980 - changing the buffer text 14981 - jumping to another buffer or window 14982 - editing another file 14983 - closing a window or quitting Vim 14984 - etc. 14985 14986 14987 vim:tw=78:ts=8:noet:ft=help:norl: 14988