1- *eval.txt* For Vim version 8.2. Last change: 2020 Dec 29
1+ *eval.txt* For Vim version 8.2. Last change: 2021 Jan 10
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -49,7 +49,7 @@ There are ten types of variables:
4949 *Number* *Integer*
5050Number A 32 or 64 bit signed number. |expr-number|
5151 The number of bits is available in |v:numbersize|.
52- Examples: -123 0x10 0177 0b1011
52+ Examples: -123 0x10 0177 0o177 0b1011
5353
5454Float A floating point number. |floating-point-format| *Float*
5555 {only when compiled with the |+float| feature}
@@ -97,9 +97,10 @@ the Number. Examples:
9797Conversion from a String to a Number only happens in legacy Vim script, not in
9898Vim9 script. It is done by converting the first digits to a number.
9999Hexadecimal "0xf9", Octal "017" or "0o17", and Binary "0b10"
100- numbers are recognized (NOTE: when using |scriptversion-4| octal with a
101- leading "0" is not recognized). If the String doesn't start with digits, the
102- result is zero.
100+ numbers are recognized
101+ NOTE: when using |scriptversion-4| octal with a leading "0" is not recognized.
102+ The 0o notation requires patch 8.2.0886.
103+ If the String doesn't start with digits, the result is zero.
103104Examples:
104105 String "456" --> Number 456 ~
105106 String "6bar" --> Number 6 ~
@@ -1150,7 +1151,7 @@ expr7 *expr7*
11501151
11511152For '!' |TRUE| becomes |FALSE|, |FALSE| becomes |TRUE| (one).
11521153For '-' the sign of the number is changed.
1153- For '+' the number is unchanged.
1154+ For '+' the number is unchanged. Note: "++" has no effect.
11541155
11551156A String will be converted to a Number first.
11561157
@@ -1191,6 +1192,7 @@ start with one!
11911192If the length of the String is less than the index, the result is an empty
11921193String. A negative index always results in an empty string (reason: backward
11931194compatibility). Use [-1:] to get the last byte or character.
1195+ In Vim9 script a negative index is used like with a list: count from the end.
11941196
11951197If expr8 is a |List| then it results the item at index expr1. See |list-index|
11961198for possible index values. If the index is out of range this results in an
@@ -1318,8 +1320,8 @@ When using the lambda form there must be no white space between the } and the
13181320number
13191321------
13201322number number constant *expr-number*
1321- *hex-number* *octal-number* *binary-number*
13221323
1324+ *0x* *hex-number* *0o* *octal-number* *binary-number*
13231325Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
13241326and Octal (starting with 0, 0o or 0O).
13251327
@@ -1572,7 +1574,7 @@ Note how execute() is used to execute an Ex command. That's ugly though.
15721574
15731575Lambda expressions have internal names like '<lambda>42'. If you get an error
15741576for a lambda expression, you can find what it is with the following command: >
1575- :function {' <lambda>42'}
1577+ :function <lambda>42
15761578See also: |numbered-function|
15771579
15781580==============================================================================
@@ -2487,12 +2489,13 @@ ch_status({handle} [, {options}])
24872489changenr() Number current change number
24882490char2nr({expr} [, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
24892491charclass({string}) Number character class of {string}
2492+ charcol({expr}) Number column number of cursor or mark
24902493charidx({string}, {idx} [, {countcc}])
24912494 Number char index of byte {idx} in {string}
24922495chdir({dir}) String change current working directory
24932496cindent({lnum}) Number C indent for line {lnum}
24942497clearmatches([{win}]) none clear all matches
2495- col({expr}) Number column nr of cursor or mark
2498+ col({expr}) Number column byte index of cursor or mark
24962499complete({startcol}, {matches}) none set Insert mode completion
24972500complete_add({expr}) Number add completion match
24982501complete_check() Number check for key typed during completion
@@ -2570,6 +2573,7 @@ getbufvar({expr}, {varname} [, {def}])
25702573getchangelist([{expr}]) List list of change list items
25712574getchar([expr]) Number get one character from the user
25722575getcharmod() Number modifiers for the last typed character
2576+ getcharpos({expr}) List position of cursor, mark, etc.
25732577getcharsearch() Dict last character search
25742578getcmdline() String return the current command-line
25752579getcmdpos() Number return cursor position in command-line
@@ -2578,6 +2582,7 @@ getcmdwintype() String return current command-line window type
25782582getcompletion({pat}, {type} [, {filtered}])
25792583 List list of cmdline completion matches
25802584getcurpos([{winnr}]) List position of the cursor
2585+ getcursorcharpos([{winnr}]) List character position of the cursor
25812586getcwd([{winnr} [, {tabnr}]]) String get the current working directory
25822587getenv({name}) String return environment variable
25832588getfontname([{name}]) String name of font being used
@@ -2840,8 +2845,10 @@ setbufline({expr}, {lnum}, {text})
28402845setbufvar({expr}, {varname}, {val})
28412846 none set {varname} in buffer {expr} to {val}
28422847setcellwidths({list}) none set character cell width overrides
2848+ setcharpos({expr}, {list}) Number set the {expr} position to {list}
28432849setcharsearch({dict}) Dict set character search from {dict}
28442850setcmdpos({pos}) Number set cursor position in command-line
2851+ setcursorcharpos({list}) Number move cursor to position in {list}
28452852setenv({name}, {val}) none set environment variable
28462853setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
28472854setline({lnum}, {line}) Number set line {lnum} to {line}
@@ -3525,8 +3532,8 @@ byteidxcomp({expr}, {nr}) *byteidxcomp()*
35253532< The first and third echo result in 3 ('e' plus composing
35263533 character is 3 bytes), the second echo results in 1 ('e' is
35273534 one byte).
3528- Only works differently from byteidx() when 'encoding' is set to
3529- a Unicode encoding.
3535+ Only works differently from byteidx() when 'encoding' is set
3536+ to a Unicode encoding.
35303537
35313538 Can also be used as a |method|: >
35323539 GetName()->byteidxcomp(idx)
@@ -3602,6 +3609,18 @@ charclass({string}) *charclass()*
36023609 other specific Unicode class
36033610 The class is used in patterns and word motions.
36043611
3612+ *charcol()*
3613+ charcol({expr}) Same as |col()| but returns the character index of the column
3614+ position given with {expr} instead of the byte position.
3615+
3616+ Example:
3617+ With the cursor on '세' in line 5 with text "여보세요": >
3618+ charcol('.') returns 3
3619+ col('.') returns 7
3620+
3621+ < Can also be used as a |method|: >
3622+ GetPos()->col()
3623+ <
36053624 *charidx()*
36063625charidx({string}, {idx} [, {countcc}])
36073626 Return the character index of the byte at {idx} in {string}.
@@ -3692,7 +3711,8 @@ col({expr}) The result is a Number, which is the byte index of the column
36923711 out of range then col() returns zero.
36933712 To get the line number use |line()|. To get both use
36943713 |getpos()|.
3695- For the screen column position use |virtcol()|.
3714+ For the screen column position use |virtcol()|. For the
3715+ character position use |charcol()|.
36963716 Note that only marks in the current file can be used.
36973717 Examples: >
36983718 col(".") column of cursor
@@ -3993,6 +4013,9 @@ cursor({list})
39934013 This is like the return value of |getpos()| or |getcurpos()|,
39944014 but without the first item.
39954015
4016+ To position the cursor using the character count, use
4017+ |setcursorcharpos()|.
4018+
39964019 Does not change the jumplist.
39974020 If {lnum} is greater than the number of lines in the buffer,
39984021 the cursor will be positioned at the last line in the buffer.
@@ -5232,6 +5255,20 @@ getcharmod() *getcharmod()*
52325255 character itself are obtained. Thus Shift-a results in "A"
52335256 without a modifier.
52345257
5258+ *getcharpos()*
5259+ getcharpos({expr})
5260+ Get the position for {expr}. Same as |getpos()| but the column
5261+ number in the returned List is a character index instead of
5262+ a byte index.
5263+
5264+ Example:
5265+ With the cursor on '세' in line 5 with text "여보세요": >
5266+ getcharpos('.') returns [0, 5, 3, 0]
5267+ getpos('.') returns [0, 5, 7, 0]
5268+ <
5269+ Can also be used as a |method|: >
5270+ GetMark()->getcharpos()
5271+
52355272getcharsearch() *getcharsearch()*
52365273 Return the current character search information as a {dict}
52375274 with the following entries:
@@ -5357,8 +5394,11 @@ getcurpos([{winid}])
53575394 includes an extra "curswant" item in the list:
53585395 [0, lnum, col, off, curswant] ~
53595396 The "curswant" number is the preferred column when moving the
5360- cursor vertically. Also see |getpos()|.
5361- The first "bufnum" item is always zero.
5397+ cursor vertically. Also see |getcursorcharpos()| and
5398+ |getpos()|.
5399+ The first "bufnum" item is always zero. The byte position of
5400+ the cursor is returned in 'col'. To get the character
5401+ position, use |getcursorcharpos()|.
53625402
53635403 The optional {winid} argument can specify the window. It can
53645404 be the window number or the |window-ID|. The last known
@@ -5372,7 +5412,24 @@ getcurpos([{winid}])
53725412 call setpos('.', save_cursor)
53735413< Note that this only works within the window. See
53745414 |winrestview()| for restoring more state.
5375- *getcwd()*
5415+
5416+ Can also be used as a |method|: >
5417+ GetWinid()->getcurpos()
5418+
5419+ < *getcursorcharpos()*
5420+ getcursorcharpos([{winid}])
5421+ Same as |getcurpos()| but the column number in the returned
5422+ List is a character index instead of a byte index.
5423+
5424+ Example:
5425+ With the cursor on '보' in line 3 with text "여보세요": >
5426+ getcursorcharpos() returns [0, 3, 2, 0, 3]
5427+ getcurpos() returns [0, 3, 4, 0, 3]
5428+
5429+ < Can also be used as a |method|: >
5430+ GetWinid()->getcursorcharpos()
5431+
5432+ < *getcwd()*
53765433getcwd([{winnr} [, {tabnr}]])
53775434 The result is a String, which is the name of the current
53785435 working directory.
@@ -5679,16 +5736,18 @@ getpos({expr}) Get the position for {expr}. For possible values of {expr}
56795736 Note that for '< and '> Visual mode matters: when it is "V"
56805737 (visual line mode) the column of '< is zero and the column of
56815738 '> is a large number.
5739+ The column number in the returned List is the byte position
5740+ within the line. To get the character position in the line,
5741+ use |getcharpos()|
56825742 This can be used to save and restore the position of a mark: >
56835743 let save_a_mark = getpos("'a")
56845744 ...
56855745 call setpos("'a", save_a_mark)
5686- < Also see |getcurpos()| and |setpos()|.
5746+ < Also see |getcharpos()|, | getcurpos()| and |setpos()|.
56875747
56885748 Can also be used as a |method|: >
56895749 GetMark()->getpos()
56905750
5691-
56925751getqflist([{what}]) *getqflist()*
56935752 Returns a |List| with all the current quickfix errors. Each
56945753 list item is a dictionary with these entries:
@@ -7554,8 +7613,10 @@ matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
75547613<
75557614
75567615 *max()*
7557- max({expr}) Return the maximum value of all items in {expr}.
7558- {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7616+ max({expr}) Return the maximum value of all items in {expr}. Example: >
7617+ echo max([apples, pears, oranges])
7618+
7619+ < {expr} can be a |List| or a |Dictionary|. For a Dictionary,
75597620 it returns the maximum of all values in the Dictionary.
75607621 If {expr} is neither a List nor a Dictionary, or one of the
75617622 items in {expr} cannot be used as a Number this results in
@@ -7625,8 +7686,10 @@ menu_info({name} [, {mode}]) *menu_info()*
76257686
76267687
76277688< *min()*
7628- min({expr}) Return the minimum value of all items in {expr}.
7629- {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7689+ min({expr}) Return the minimum value of all items in {expr}. Example: >
7690+ echo min([apples, pears, oranges])
7691+
7692+ < {expr} can be a |List| or a |Dictionary|. For a Dictionary,
76307693 it returns the minimum of all values in the Dictionary.
76317694 If {expr} is neither a List nor a Dictionary, or one of the
76327695 items in {expr} cannot be used as a Number this results in
@@ -7643,13 +7706,13 @@ mkdir({name} [, {path} [, {prot}]])
76437706 necessary. Otherwise it must be "".
76447707
76457708 If {prot} is given it is used to set the protection bits of
7646- the new directory. The default is 0755 (rwxr-xr-x: r/w for
7647- the user readable for others). Use 0700 to make it unreadable
7648- for others. This is only used for the last part of {name}.
7649- Thus if you create /tmp/foo/bar then /tmp/foo will be created
7650- with 0755 .
7709+ the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7710+ the user, readable for others). Use 0o700 to make it
7711+ unreadable for others. This is only used for the last part of
7712+ {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7713+ created with 0o755 .
76517714 Example: >
7652- :call mkdir($HOME . "/tmp/foo/bar", "p", 0700 )
7715+ :call mkdir($HOME . "/tmp/foo/bar", "p", 0o700 )
76537716
76547717< This function is not available in the |sandbox|.
76557718
@@ -9212,6 +9275,19 @@ setcellwidths({list}) *setcellwidths()*
92129275< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
92139276 the effect for known emoji characters.
92149277
9278+ setcharpos({expr}, {list}) *setcharpos()*
9279+ Same as |setpos()| but uses the specified column number as the
9280+ character index instead of the byte index in the line.
9281+
9282+ Example:
9283+ With the text "여보세요" in line 8: >
9284+ call setcharpos('.', [0, 8, 4, 0])
9285+ < positions the cursor on the fourth character '요'. >
9286+ call setpos('.', [0, 8, 4, 0])
9287+ < positions the cursor on the second character '보'.
9288+
9289+ Can also be used as a |method|: >
9290+ GetPosition()->setcharpos('.')
92159291
92169292setcharsearch({dict}) *setcharsearch()*
92179293 Set the current character search information to {dict},
@@ -9254,6 +9330,21 @@ setcmdpos({pos}) *setcmdpos()*
92549330 Can also be used as a |method|: >
92559331 GetPos()->setcmdpos()
92569332
9333+ setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9334+ setcursorcharpos({list})
9335+ Same as |cursor()| but uses the specified column number as the
9336+ character index instead of the byte index in the line.
9337+
9338+ Example:
9339+ With the text "여보세요" in line 4: >
9340+ call setcursorcharpos(4, 3)
9341+ < positions the cursor on the third character '세'. >
9342+ call cursor(4, 3)
9343+ < positions the cursor on the first character '여'.
9344+
9345+ Can also be used as a |method|: >
9346+ GetCursorPos()->setcursorcharpos()
9347+
92579348setenv({name}, {val}) *setenv()*
92589349 Set environment variable {name} to {val}.
92599350 When {val} is |v:null| the environment variable is deleted.
@@ -9365,7 +9456,8 @@ setpos({expr}, {list})
93659456
93669457 "lnum" and "col" are the position in the buffer. The first
93679458 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9368- smaller than 1 then 1 is used.
9459+ smaller than 1 then 1 is used. To use the character count
9460+ instead of the byte count, use |setcharpos()|.
93699461
93709462 The "off" number is only used when 'virtualedit' is set. Then
93719463 it is the offset in screen columns from the start of the
@@ -9385,7 +9477,7 @@ setpos({expr}, {list})
93859477 Returns 0 when the position could be set, -1 otherwise.
93869478 An error message is given if {expr} is invalid.
93879479
9388- Also see |getpos()| and |getcurpos()|.
9480+ Also see |setcharpos()|, | getpos()| and |getcurpos()|.
93899481
93909482 This does not restore the preferred column for moving
93919483 vertically; if you set the cursor position with this, |j| and
0 commit comments