blob: 572ca413846ba183691e5689c19c120e5cd868d9 [file] [log] [blame]
Christ van Willegen92e109f2025-03-24 20:12:37 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Mar 24
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000132col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000133complete({startcol}, {matches}) none set Insert mode completion
134complete_add({expr}) Number add completion match
135complete_check() Number check for key typed during completion
136complete_info([{what}]) Dict get current completion information
137confirm({msg} [, {choices} [, {default} [, {type}]]])
138 Number number of choice picked by user
139copy({expr}) any make a shallow copy of {expr}
140cos({expr}) Float cosine of {expr}
141cosh({expr}) Float hyperbolic cosine of {expr}
142count({comp}, {expr} [, {ic} [, {start}]])
143 Number count how many {expr} are in {comp}
144cscope_connection([{num}, {dbpath} [, {prepend}]])
145 Number checks existence of cscope connection
146cursor({lnum}, {col} [, {off}])
147 Number move cursor to {lnum}, {col}, {off}
148cursor({list}) Number move cursor to position in {list}
149debugbreak({pid}) Number interrupt process being debugged
150deepcopy({expr} [, {noref}]) any make a full copy of {expr}
151delete({fname} [, {flags}]) Number delete the file or directory {fname}
152deletebufline({buf}, {first} [, {last}])
153 Number delete lines from buffer {buf}
154did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100155diff({fromlist}, {tolist} [, {options}])
156 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000157diff_filler({lnum}) Number diff filler lines about {lnum}
158diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
159digraph_get({chars}) String get the |digraph| of {chars}
160digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200161digraph_set({chars}, {digraph}) Bool register |digraph|
162digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000163echoraw({expr}) none output {expr} as-is
164empty({expr}) Number |TRUE| if {expr} is empty
165environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100166err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000167escape({string}, {chars}) String escape {chars} in {string} with '\'
168eval({string}) any evaluate {string} into its value
169eventhandler() Number |TRUE| if inside an event handler
170executable({expr}) Number 1 if executable {expr} exists
171execute({command}) String execute {command} and get the output
172exepath({expr}) String full path of the command {expr}
173exists({expr}) Number |TRUE| if {expr} exists
174exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
175exp({expr}) Float exponential of {expr}
176expand({expr} [, {nosuf} [, {list}]])
177 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100178expandcmd({string} [, {options}])
179 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000180extend({expr1}, {expr2} [, {expr3}])
181 List/Dict insert items of {expr2} into {expr1}
182extendnew({expr1}, {expr2} [, {expr3}])
183 List/Dict like |extend()| but creates a new
184 List or Dictionary
185feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200186filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
187 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000188filereadable({file}) Number |TRUE| if {file} is a readable file
189filewritable({file}) Number |TRUE| if {file} is a writable file
190filter({expr1}, {expr2}) List/Dict/Blob/String
191 remove items from {expr1} where
192 {expr2} is 0
193finddir({name} [, {path} [, {count}]])
194 String find directory {name} in {path}
195findfile({name} [, {path} [, {count}]])
196 String find file {name} in {path}
197flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
198flattennew({list} [, {maxdepth}])
199 List flatten a copy of {list}
200float2nr({expr}) Number convert Float {expr} to a Number
201floor({expr}) Float round {expr} down
202fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
203fnameescape({fname}) String escape special characters in {fname}
204fnamemodify({fname}, {mods}) String modify file name
205foldclosed({lnum}) Number first line of fold at {lnum} if closed
206foldclosedend({lnum}) Number last line of fold at {lnum} if closed
207foldlevel({lnum}) Number fold level at {lnum}
208foldtext() String line displayed for closed fold
209foldtextresult({lnum}) String text for closed fold at {lnum}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100210foreach({expr1}, {expr2}) List/Tuple/Dict/Blob/String
Ernie Raele79e2072024-01-13 11:47:33 +0100211 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100213fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214funcref({name} [, {arglist}] [, {dict}])
215 Funcref reference to function {name}
216function({name} [, {arglist}] [, {dict}])
217 Funcref named reference to function {name}
218garbagecollect([{atexit}]) none free memory, breaking cyclic references
219get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
220get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
221get({func}, {what}) any get property of funcref/partial {func}
222getbufinfo([{buf}]) List information about buffers
223getbufline({buf}, {lnum} [, {end}])
224 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000225getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getbufvar({buf}, {varname} [, {def}])
227 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100228getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000229getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100231getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232 get one character from the user
233getcharmod() Number modifiers for the last typed character
234getcharpos({expr}) List position of cursor, mark, etc.
235getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100236getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200237getcmdcomplpat() String return the completion pattern of the
238 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100239getcmdcompltype() String return the type of the current
240 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200241getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100244getcmdscreenpos() Number return cursor screen position in
245 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000246getcmdtype() String return current command-line type
247getcmdwintype() String return current command-line window type
248getcompletion({pat}, {type} [, {filtered}])
249 List list of cmdline completion matches
250getcurpos([{winnr}]) List position of the cursor
251getcursorcharpos([{winnr}]) List character position of the cursor
252getcwd([{winnr} [, {tabnr}]]) String get the current working directory
253getenv({name}) String return environment variable
254getfontname([{name}]) String name of font being used
255getfperm({fname}) String file permissions of file {fname}
256getfsize({fname}) Number size in bytes of file {fname}
257getftime({fname}) Number last modification time of file
258getftype({fname}) String description of type of file {fname}
259getimstatus() Number |TRUE| if the IME status is active
260getjumplist([{winnr} [, {tabnr}]])
261 List list of jump list items
262getline({lnum}) String line {lnum} of current buffer
263getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
264getloclist({nr}) List list of location list items
265getloclist({nr}, {what}) Dict get specific location list properties
266getmarklist([{buf}]) List list of global/local marks
267getmatches([{win}]) List list of current matches
268getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000269getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000270getpid() Number process ID of Vim
271getpos({expr}) List position of cursor, mark, etc.
272getqflist() List list of quickfix items
273getqflist({what}) Dict get specific quickfix list properties
274getreg([{regname} [, 1 [, {list}]]])
275 String or List contents of a register
276getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100277getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100278 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200279getregionpos({pos1}, {pos2} [, {opts}])
280 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000281getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100282getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100283getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284gettabinfo([{expr}]) List list of tab pages
285gettabvar({nr}, {varname} [, {def}])
286 any variable {varname} in tab {nr} or {def}
287gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
288 any {name} in {winnr} in tab page {tabnr}
289gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200290gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000292getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwinposx() Number X coord in pixels of the Vim window
294getwinposy() Number Y coord in pixels of the Vim window
295getwinvar({nr}, {varname} [, {def}])
296 any variable {varname} in window {nr}
297glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
298 any expand file wildcards in {expr}
299glob2regpat({expr}) String convert a glob pat into a search pat
300globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
301 String do glob({expr}) for all dirs in {path}
302has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
303has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
304haslocaldir([{winnr} [, {tabnr}]])
305 Number |TRUE| if the window executed |:lcd|
306 or |:tcd|
307hasmapto({what} [, {mode} [, {abbr}]])
308 Number |TRUE| if mapping to {what} exists
309histadd({history}, {item}) Number add an item to a history
310histdel({history} [, {item}]) Number remove an item from a history
311histget({history} [, {index}]) String get the item {index} from a history
312histnr({history}) Number highest index of a history
313hlID({name}) Number syntax ID of highlight group {name}
314hlexists({name}) Number |TRUE| if highlight group {name} exists
315hlget([{name} [, {resolve}]]) List get highlight group attributes
316hlset({list}) Number set highlight group attributes
317hostname() String name of the machine Vim is running on
318iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200319id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320indent({lnum}) Number indent of line {lnum}
321index({object}, {expr} [, {start} [, {ic}]])
322 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100323indexof({object}, {expr} [, {opts}]])
324 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000325input({prompt} [, {text} [, {completion}]])
326 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100327inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000328 String like input() but in a GUI dialog
329inputlist({textlist}) Number let the user pick from a choice list
330inputrestore() Number restore typeahead
331inputsave() Number save and clear typeahead
332inputsecret({prompt} [, {text}]) String like input() but hiding the text
333insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200334instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000335interrupt() none interrupt script execution
336invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100337isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000338isdirectory({directory}) Number |TRUE| if {directory} is a directory
339isinf({expr}) Number determine if {expr} is infinity value
340 (positive or negative)
341islocked({expr}) Number |TRUE| if {expr} is locked
342isnan({expr}) Number |TRUE| if {expr} is NaN
343items({dict}) List key-value pairs in {dict}
344job_getchannel({job}) Channel get the channel handle for {job}
345job_info([{job}]) Dict get information about {job}
346job_setoptions({job}, {options}) none set options for {job}
347job_start({command} [, {options}])
348 Job start a job
349job_status({job}) String get the status of {job}
350job_stop({job} [, {how}]) Number stop {job}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100351join({expr} [, {sep}]) String join items in {expr} into one String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000352js_decode({string}) any decode JS style JSON
353js_encode({expr}) String encode JS style JSON
354json_decode({string}) any decode JSON
355json_encode({expr}) String encode JSON
356keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100357keytrans({string}) String translate internal keycodes to a form
358 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000359len({expr}) Number the length of {expr}
360libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
361libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
362line({expr} [, {winid}]) Number line nr of cursor, last line or mark
363line2byte({lnum}) Number byte count of line {lnum}
364lispindent({lnum}) Number Lisp indent for line {lnum}
365list2blob({list}) Blob turn {list} of numbers into a Blob
366list2str({list} [, {utf8}]) String turn {list} of numbers into a String
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100367list2tuple({list}) Tuple turn {list} of items into a tuple
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000368listener_add({callback} [, {buf}])
369 Number add a callback to listen to changes
370listener_flush([{buf}]) none invoke listener callbacks
371listener_remove({id}) none remove a listener callback
372localtime() Number current time
373log({expr}) Float natural logarithm (base e) of {expr}
374log10({expr}) Float logarithm of Float {expr} to base 10
375luaeval({expr} [, {expr}]) any evaluate |Lua| expression
376map({expr1}, {expr2}) List/Dict/Blob/String
377 change each item in {expr1} to {expr2}
378maparg({name} [, {mode} [, {abbr} [, {dict}]]])
379 String or Dict
380 rhs of mapping {name} in mode {mode}
381mapcheck({name} [, {mode} [, {abbr}]])
382 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100383maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000384mapnew({expr1}, {expr2}) List/Dict/Blob/String
385 like |map()| but creates a new List or
386 Dictionary
387mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
388match({expr}, {pat} [, {start} [, {count}]])
389 Number position where {pat} matches in {expr}
390matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
391 Number highlight {pattern} with {group}
392matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
393 Number highlight positions with {group}
394matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100395matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
396 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000397matchdelete({id} [, {win}]) Number delete match identified by {id}
398matchend({expr}, {pat} [, {start} [, {count}]])
399 Number position where {pat} ends in {expr}
400matchfuzzy({list}, {str} [, {dict}])
401 List fuzzy match {str} in {list}
402matchfuzzypos({list}, {str} [, {dict}])
403 List fuzzy match {str} in {list}
404matchlist({expr}, {pat} [, {start} [, {count}]])
405 List match and submatches of {pat} in {expr}
406matchstr({expr}, {pat} [, {start} [, {count}]])
407 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100408matchstrlist({list}, {pat} [, {dict})
409 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000410matchstrpos({expr}, {pat} [, {start} [, {count}]])
411 List {count}'th match of {pat} in {expr}
412max({expr}) Number maximum value of items in {expr}
413menu_info({name} [, {mode}]) Dict get menu item information
414min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000415mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000416 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200417mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000418mzeval({expr}) any evaluate |MzScheme| expression
419nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100420ngettext({single}, {plural}, {number}[, {domain}])
421 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000422nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
423or({expr}, {expr}) Number bitwise OR
424pathshorten({expr} [, {len}]) String shorten directory names in a path
425perleval({expr}) any evaluate |Perl| expression
426popup_atcursor({what}, {options}) Number create popup window near the cursor
427popup_beval({what}, {options}) Number create popup window for 'ballooneval'
428popup_clear() none close all popup windows
429popup_close({id} [, {result}]) none close popup window {id}
430popup_create({what}, {options}) Number create a popup window
431popup_dialog({what}, {options}) Number create a popup window used as a dialog
432popup_filter_menu({id}, {key}) Number filter for a menu popup window
433popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100434popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000435popup_findinfo() Number get window ID of info popup window
436popup_findpreview() Number get window ID of preview popup window
437popup_getoptions({id}) Dict get options of popup window {id}
438popup_getpos({id}) Dict get position of popup window {id}
439popup_hide({id}) none hide popup menu {id}
440popup_list() List get a list of window IDs of all popups
441popup_locate({row}, {col}) Number get window ID of popup at position
442popup_menu({what}, {options}) Number create a popup window used as a menu
443popup_move({id}, {options}) none set position of popup window {id}
444popup_notification({what}, {options})
445 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200446popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000447popup_setoptions({id}, {options})
448 none set options for popup window {id}
449popup_settext({id}, {text}) none set the text of popup window {id}
450popup_show({id}) none unhide popup window {id}
451pow({x}, {y}) Float {x} to the power of {y}
452prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
453printf({fmt}, {expr1}...) String format text
454prompt_getprompt({buf}) String get prompt text
455prompt_setcallback({buf}, {expr}) none set prompt callback function
456prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
457prompt_setprompt({buf}, {text}) none set prompt text
458prop_add({lnum}, {col}, {props}) none add one text property
459prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
460 none add multiple text properties
461prop_clear({lnum} [, {lnum-end} [, {props}]])
462 none remove all text properties
463prop_find({props} [, {direction}])
464 Dict search for a text property
465prop_list({lnum} [, {props}]) List text properties in {lnum}
466prop_remove({props} [, {lnum} [, {lnum-end}]])
467 Number remove a text property
468prop_type_add({name}, {props}) none define a new property type
469prop_type_change({name}, {props})
470 none change an existing property type
471prop_type_delete({name} [, {props}])
472 none delete a property type
473prop_type_get({name} [, {props}])
474 Dict get property type values
475prop_type_list([{props}]) List get list of property types
476pum_getpos() Dict position and size of pum if visible
477pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100478py3eval({expr} [, {locals}]) any evaluate |python3| expression
479pyeval({expr} [, {locals}]) any evaluate |Python| expression
480pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000481rand([{expr}]) Number get pseudo-random number
482range({expr} [, {max} [, {stride}]])
483 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100484readblob({fname} [, {offset} [, {size}]])
485 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000486readdir({dir} [, {expr} [, {dict}]])
487 List file names in {dir} selected by {expr}
488readdirex({dir} [, {expr} [, {dict}]])
489 List file info in {dir} selected by {expr}
490readfile({fname} [, {type} [, {max}]])
491 List get list of lines from file {fname}
492reduce({object}, {func} [, {initial}])
493 any reduce {object} using {func}
494reg_executing() String get the executing register name
495reg_recording() String get the recording register name
496reltime([{start} [, {end}]]) List get time value
497reltimefloat({time}) Float turn the time value into a Float
498reltimestr({time}) String turn time value into a String
499remote_expr({server}, {string} [, {idvar} [, {timeout}]])
500 String send expression
501remote_foreground({server}) Number bring Vim server to the foreground
502remote_peek({serverid} [, {retvar}])
503 Number check for reply string
504remote_read({serverid} [, {timeout}])
505 String read reply string
506remote_send({server}, {string} [, {idvar}])
507 String send key sequence
508remote_startserver({name}) none become server {name}
509remove({list}, {idx} [, {end}]) any/List
510 remove items {idx}-{end} from {list}
511remove({blob}, {idx} [, {end}]) Number/Blob
512 remove bytes {idx}-{end} from {blob}
513remove({dict}, {key}) any remove entry {key} from {dict}
514rename({from}, {to}) Number rename (move) file from {from} to {to}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100515repeat({expr}, {count}) List/Tuple/Blob/String
Bakudankun375141e2022-09-09 18:46:47 +0100516 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000517resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100518reverse({obj}) List/Tuple/Blob/String
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100519 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000520round({expr}) Float round off {expr}
521rubyeval({expr}) any evaluate |Ruby| expression
522screenattr({row}, {col}) Number attribute at screen position
523screenchar({row}, {col}) Number character at screen position
524screenchars({row}, {col}) List List of characters at screen position
525screencol() Number current cursor column
526screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
527screenrow() Number current cursor row
528screenstring({row}, {col}) String characters at screen position
529search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
530 Number search for {pattern}
531searchcount([{options}]) Dict get or update search stats
532searchdecl({name} [, {global} [, {thisblock}]])
533 Number search for variable declaration
534searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
535 Number search for other end of start/end pair
536searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
537 List search for other end of start/end pair
538searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
539 List search for {pattern}
540server2client({clientid}, {string})
541 Number send reply string
542serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700543setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000544 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700545 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000546setbufvar({buf}, {varname}, {val})
547 none set {varname} in buffer {buf} to {val}
548setcellwidths({list}) none set character cell width overrides
549setcharpos({expr}, {list}) Number set the {expr} position to {list}
550setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100551setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000552setcmdpos({pos}) Number set cursor position in command-line
553setcursorcharpos({list}) Number move cursor to position in {list}
554setenv({name}, {val}) none set environment variable
555setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
556setline({lnum}, {line}) Number set line {lnum} to {line}
557setloclist({nr}, {list} [, {action}])
558 Number modify location list using {list}
559setloclist({nr}, {list}, {action}, {what})
560 Number modify specific location list props
561setmatches({list} [, {win}]) Number restore a list of matches
562setpos({expr}, {list}) Number set the {expr} position to {list}
563setqflist({list} [, {action}]) Number modify quickfix list using {list}
564setqflist({list}, {action}, {what})
565 Number modify specific quickfix list props
566setreg({n}, {v} [, {opt}]) Number set register to value and type
567settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
568settabwinvar({tabnr}, {winnr}, {varname}, {val})
569 none set {varname} in window {winnr} in tab
570 page {tabnr} to {val}
571settagstack({nr}, {dict} [, {action}])
572 Number modify tag stack using {dict}
573setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
574sha256({string}) String SHA256 checksum of {string}
575shellescape({string} [, {special}])
576 String escape {string} for use as shell
577 command argument
578shiftwidth([{col}]) Number effective value of 'shiftwidth'
579sign_define({name} [, {dict}]) Number define or update a sign
580sign_define({list}) List define or update a list of signs
581sign_getdefined([{name}]) List get a list of defined signs
582sign_getplaced([{buf} [, {dict}]])
583 List get a list of placed signs
584sign_jump({id}, {group}, {buf})
585 Number jump to a sign
586sign_place({id}, {group}, {name}, {buf} [, {dict}])
587 Number place a sign
588sign_placelist({list}) List place a list of signs
589sign_undefine([{name}]) Number undefine a sign
590sign_undefine({list}) List undefine a list of signs
591sign_unplace({group} [, {dict}])
592 Number unplace a sign
593sign_unplacelist({list}) List unplace a list of signs
594simplify({filename}) String simplify filename as much as possible
595sin({expr}) Float sine of {expr}
596sinh({expr}) Float hyperbolic sine of {expr}
597slice({expr}, {start} [, {end}]) String, List or Blob
598 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000599sort({list} [, {how} [, {dict}]])
600 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000601sound_clear() none stop playing all sounds
602sound_playevent({name} [, {callback}])
603 Number play an event sound
604sound_playfile({path} [, {callback}])
605 Number play sound file {path}
606sound_stop({id}) none stop playing sound {id}
607soundfold({word}) String sound-fold {word}
608spellbadword() String badly spelled word at cursor
609spellsuggest({word} [, {max} [, {capital}]])
610 List spelling suggestions
611split({expr} [, {pat} [, {keepempty}]])
612 List make |List| from {pat} separated {expr}
613sqrt({expr}) Float square root of {expr}
614srand([{expr}]) List get seed for |rand()|
615state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100616str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000617str2float({expr} [, {quoted}]) Float convert String to Float
618str2list({expr} [, {utf8}]) List convert each character of {expr} to
619 ASCII/UTF-8 value
620str2nr({expr} [, {base} [, {quoted}]])
621 Number convert String to Number
622strcharlen({expr}) Number character length of the String {expr}
623strcharpart({str}, {start} [, {len} [, {skipcc}]])
624 String {len} characters of {str} at
625 character {start}
626strchars({expr} [, {skipcc}]) Number character count of the String {expr}
627strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
628strftime({format} [, {time}]) String format time with a specified format
629strgetchar({str}, {index}) Number get char {index} from {str}
630stridx({haystack}, {needle} [, {start}])
631 Number index of {needle} in {haystack}
632string({expr}) String String representation of {expr} value
633strlen({expr}) Number length of the String {expr}
634strpart({str}, {start} [, {len} [, {chars}]])
635 String {len} bytes/chars of {str} at
636 byte {start}
637strptime({format}, {timestring})
638 Number Convert {timestring} to unix timestamp
639strridx({haystack}, {needle} [, {start}])
640 Number last index of {needle} in {haystack}
641strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100642strutf16len({string} [, {countcc}])
643 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000644strwidth({expr}) Number display cell length of the String {expr}
645submatch({nr} [, {list}]) String or List
646 specific match in ":s" or substitute()
647substitute({expr}, {pat}, {sub}, {flags})
648 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000649swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000650swapinfo({fname}) Dict information about swap file {fname}
651swapname({buf}) String swap file of buffer {buf}
652synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
653synIDattr({synID}, {what} [, {mode}])
654 String attribute {what} of syntax ID {synID}
655synIDtrans({synID}) Number translated syntax ID of {synID}
656synconcealed({lnum}, {col}) List info about concealing
657synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
658system({expr} [, {input}]) String output of shell command/filter {expr}
659systemlist({expr} [, {input}]) List output of shell command/filter {expr}
660tabpagebuflist([{arg}]) List list of buffer numbers in tab page
661tabpagenr([{arg}]) Number number of current or last tab page
662tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
663tagfiles() List tags files used
664taglist({expr} [, {filename}]) List list of tags matching {expr}
665tan({expr}) Float tangent of {expr}
666tanh({expr}) Float hyperbolic tangent of {expr}
667tempname() String name for a temporary file
668term_dumpdiff({filename}, {filename} [, {options}])
669 Number display difference between two dumps
670term_dumpload({filename} [, {options}])
671 Number displaying a screen dump
672term_dumpwrite({buf}, {filename} [, {options}])
673 none dump terminal window contents
674term_getaltscreen({buf}) Number get the alternate screen flag
675term_getansicolors({buf}) List get ANSI palette in GUI color mode
676term_getattr({attr}, {what}) Number get the value of attribute {what}
677term_getcursor({buf}) List get the cursor position of a terminal
678term_getjob({buf}) Job get the job associated with a terminal
679term_getline({buf}, {row}) String get a line of text from a terminal
680term_getscrolled({buf}) Number get the scroll count of a terminal
681term_getsize({buf}) List get the size of a terminal
682term_getstatus({buf}) String get the status of a terminal
683term_gettitle({buf}) String get the title of a terminal
684term_gettty({buf}, [{input}]) String get the tty name of a terminal
685term_list() List get the list of terminal buffers
686term_scrape({buf}, {row}) List get row of a terminal screen
687term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
688term_setansicolors({buf}, {colors})
689 none set ANSI palette in GUI color mode
690term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
691term_setkill({buf}, {how}) none set signal to stop job in terminal
692term_setrestore({buf}, {command}) none set command to restore terminal
693term_setsize({buf}, {rows}, {cols})
694 none set the size of a terminal
695term_start({cmd} [, {options}]) Number open a terminal window and run a job
696term_wait({buf} [, {time}]) Number wait for screen to be updated
697terminalprops() Dict properties of the terminal
698test_alloc_fail({id}, {countdown}, {repeat})
699 none make memory allocation fail
700test_autochdir() none enable 'autochdir' during startup
701test_feedinput({string}) none add key sequence to input buffer
702test_garbagecollect_now() none free memory right now for testing
703test_garbagecollect_soon() none free memory soon for testing
704test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000705test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000706test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000707test_mswin_event({event}, {args})
708 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000709test_null_blob() Blob null value for testing
710test_null_channel() Channel null value for testing
711test_null_dict() Dict null value for testing
712test_null_function() Funcref null value for testing
713test_null_job() Job null value for testing
714test_null_list() List null value for testing
715test_null_partial() Funcref null value for testing
716test_null_string() String null value for testing
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100717test_null_tuple() Tuple null value for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000718test_option_not_set({name}) none reset flag indicating option was set
719test_override({expr}, {val}) none test with Vim internal overrides
720test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000721test_setmouse({row}, {col}) none set the mouse position for testing
722test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200723test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000724test_unknown() any unknown value for testing
725test_void() any void value for testing
726timer_info([{id}]) List information about timers
727timer_pause({id}, {pause}) none pause or unpause a timer
728timer_start({time}, {callback} [, {options}])
729 Number create a timer
730timer_stop({timer}) none stop a timer
731timer_stopall() none stop all timers
732tolower({expr}) String the String {expr} switched to lowercase
733toupper({expr}) String the String {expr} switched to uppercase
734tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
735 to chars in {tostr}
736trim({text} [, {mask} [, {dir}]])
737 String trim characters in {mask} from {text}
738trunc({expr}) Float truncate Float {expr}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100739tuple2list({tuple}) List turn {tuple} of items into a list
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000740type({expr}) Number type of value {expr}
741typename({expr}) String representation of the type of {expr}
742undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500743undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000744uniq({list} [, {func} [, {dict}]])
745 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100746utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
747 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000748values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200749virtcol({expr} [, {list} [, {winid}])
750 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100751 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100752virtcol2col({winid}, {lnum}, {col})
753 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200754visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000755wildmenumode() Number whether 'wildmenu' mode is active
756win_execute({id}, {command} [, {silent}])
757 String execute {command} in window {id}
758win_findbuf({bufnr}) List find windows containing {bufnr}
759win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
760win_gettype([{nr}]) String type of window {nr}
761win_gotoid({expr}) Number go to window with ID {expr}
762win_id2tabwin({expr}) List get tab and window nr from window ID
763win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000764win_move_separator({nr}) Number move window vertical separator
765win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000766win_screenpos({nr}) List get screen position of window {nr}
767win_splitmove({nr}, {target} [, {options}])
768 Number move window {nr} to split of {target}
769winbufnr({nr}) Number buffer number of window {nr}
770wincol() Number window column of the cursor
771windowsversion() String MS-Windows OS version
772winheight({nr}) Number height of window {nr}
773winlayout([{tabnr}]) List layout of windows in tab {tabnr}
774winline() Number window line of the cursor
775winnr([{expr}]) Number number of current window
776winrestcmd() String returns command to restore window sizes
777winrestview({dict}) none restore view of current window
778winsaveview() Dict save view of current window
779winwidth({nr}) Number width of window {nr}
780wordcount() Dict get byte/char/word statistics
781writefile({object}, {fname} [, {flags}])
782 Number write |Blob| or |List| of lines to file
783xor({expr}, {expr}) Number bitwise XOR
784
785==============================================================================
7862. Details *builtin-function-details*
787
788Not all functions are here, some have been moved to a help file covering the
789specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200790Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000791
792abs({expr}) *abs()*
793 Return the absolute value of {expr}. When {expr} evaluates to
794 a |Float| abs() returns a |Float|. When {expr} can be
795 converted to a |Number| abs() returns a |Number|. Otherwise
796 abs() gives an error message and returns -1.
797 Examples: >
798 echo abs(1.456)
799< 1.456 >
800 echo abs(-5.456)
801< 5.456 >
802 echo abs(-4)
803< 4
804
805 Can also be used as a |method|: >
806 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200807<
808 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000810
811acos({expr}) *acos()*
812 Return the arc cosine of {expr} measured in radians, as a
813 |Float| in the range of [0, pi].
814 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100815 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000816 Examples: >
817 :echo acos(0)
818< 1.570796 >
819 :echo acos(-0.5)
820< 2.094395
821
822 Can also be used as a |method|: >
823 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200824<
825 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827
828add({object}, {expr}) *add()*
829 Append the item {expr} to |List| or |Blob| {object}. Returns
830 the resulting |List| or |Blob|. Examples: >
831 :let alist = add([1, 2, 3], item)
832 :call add(mylist, "woodstock")
833< Note that when {expr} is a |List| it is appended as a single
834 item. Use |extend()| to concatenate |Lists|.
835 When {object} is a |Blob| then {expr} must be a number.
836 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100837 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000838
839 Can also be used as a |method|: >
840 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200841<
842 Return type: list<{type}> (depending on the given |List|) or
843 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000844
845
846and({expr}, {expr}) *and()*
847 Bitwise AND on the two arguments. The arguments are converted
848 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100849 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000850 Example: >
851 :let flag = and(bits, 0x80)
852< Can also be used as a |method|: >
853 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200854<
855 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000856
857
858append({lnum}, {text}) *append()*
859 When {text} is a |List|: Append each item of the |List| as a
860 text line below line {lnum} in the current buffer.
861 Otherwise append {text} as one text line below line {lnum} in
862 the current buffer.
863 Any type of item is accepted and converted to a String.
864 {lnum} can be zero to insert a line before the first one.
865 {lnum} is used like with |getline()|.
866 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000867 0 for success. When {text} is an empty list zero is returned,
868 no matter the value of {lnum}.
869 In |Vim9| script an invalid argument or negative number
870 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000871 :let failed = append(line('$'), "# THE END")
872 :let failed = append(0, ["Chapter 1", "the beginning"])
873
874< Can also be used as a |method| after a List, the base is
875 passed as the second argument: >
876 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200877<
878 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000879
880
881appendbufline({buf}, {lnum}, {text}) *appendbufline()*
882 Like |append()| but append the text in buffer {buf}.
883
884 This function works only for loaded buffers. First call
885 |bufload()| if needed.
886
887 For the use of {buf}, see |bufname()|.
888
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000889 {lnum} is the line number to append below. Note that using
890 |line()| would use the current buffer, not the one appending
891 to. Use "$" to append at the end of the buffer. Other string
892 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000893
894 On success 0 is returned, on failure 1 is returned.
895 In |Vim9| script an error is given for an invalid {lnum}.
896
897 If {buf} is not a valid buffer or {lnum} is not valid, an
898 error message is given. Example: >
899 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000900< However, when {text} is an empty list then no error is given
901 for an invalid {lnum}, since {lnum} isn't actually used.
902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000903 Can also be used as a |method| after a List, the base is
904 passed as the second argument: >
905 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200906<
907 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000908
909
910argc([{winid}]) *argc()*
911 The result is the number of files in the argument list. See
912 |arglist|.
913 If {winid} is not supplied, the argument list of the current
914 window is used.
915 If {winid} is -1, the global argument list is used.
916 Otherwise {winid} specifies the window of which the argument
917 list is used: either the window number or the window ID.
918 Returns -1 if the {winid} argument is invalid.
919
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200920 Return type: |Number|
921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000922 *argidx()*
923argidx() The result is the current index in the argument list. 0 is
924 the first file. argc() - 1 is the last one. See |arglist|.
925
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200926 Return type: |Number|
927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000928 *arglistid()*
929arglistid([{winnr} [, {tabnr}]])
930 Return the argument list ID. This is a number which
931 identifies the argument list being used. Zero is used for the
932 global argument list. See |arglist|.
933 Returns -1 if the arguments are invalid.
934
935 Without arguments use the current window.
936 With {winnr} only use this window in the current tab page.
937 With {winnr} and {tabnr} use the window in the specified tab
938 page.
939 {winnr} can be the window number or the |window-ID|.
940
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200941 Return type: |Number|
942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000943 *argv()*
944argv([{nr} [, {winid}]])
945 The result is the {nr}th file in the argument list. See
946 |arglist|. "argv(0)" is the first one. Example: >
947 :let i = 0
948 :while i < argc()
949 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000950 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000951 : let i = i + 1
952 :endwhile
953< Without the {nr} argument, or when {nr} is -1, a |List| with
954 the whole |arglist| is returned.
955
956 The {winid} argument specifies the window ID, see |argc()|.
957 For the Vim command line arguments see |v:argv|.
958
Bram Moolenaar016188f2022-06-06 20:52:59 +0100959 Returns an empty string if {nr}th argument is not present in
960 the argument list. Returns an empty List if the {winid}
961 argument is invalid.
962
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200963 Return type: |String|
964
965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000966asin({expr}) *asin()*
967 Return the arc sine of {expr} measured in radians, as a |Float|
968 in the range of [-pi/2, pi/2].
969 {expr} must evaluate to a |Float| or a |Number| in the range
970 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100971 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
972 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000973 Examples: >
974 :echo asin(0.8)
975< 0.927295 >
976 :echo asin(-0.5)
977< -0.523599
978
979 Can also be used as a |method|: >
980 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200981<
982 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000983
984assert_ functions are documented here: |assert-functions-details|
985
986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000987atan({expr}) *atan()*
988 Return the principal value of the arc tangent of {expr}, in
989 the range [-pi/2, +pi/2] radians, as a |Float|.
990 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100991 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000992 Examples: >
993 :echo atan(100)
994< 1.560797 >
995 :echo atan(-4.01)
996< -1.326405
997
998 Can also be used as a |method|: >
999 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001000<
1001 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002
1003
1004atan2({expr1}, {expr2}) *atan2()*
1005 Return the arc tangent of {expr1} / {expr2}, measured in
1006 radians, as a |Float| in the range [-pi, pi].
1007 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001008 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1009 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001010 Examples: >
1011 :echo atan2(-1, 1)
1012< -0.785398 >
1013 :echo atan2(1, -1)
1014< 2.356194
1015
1016 Can also be used as a |method|: >
1017 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001018<
1019 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001020
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001021
1022autocmd_add({acmds}) *autocmd_add()*
1023 Adds a List of autocmds and autocmd groups.
1024
1025 The {acmds} argument is a List where each item is a Dict with
1026 the following optional items:
1027 bufnr buffer number to add a buffer-local autocmd.
1028 If this item is specified, then the "pattern"
1029 item is ignored.
1030 cmd Ex command to execute for this autocmd event
1031 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001032 This can be either a String with a single
1033 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001034 group autocmd group name. Refer to |autocmd-groups|.
1035 If this group doesn't exist then it is
1036 created. If not specified or empty, then the
1037 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001038 nested boolean flag, set to v:true to add a nested
1039 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001040 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001041 which executes only once. Refer to
1042 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001043 pattern autocmd pattern string. Refer to
1044 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001045 present, then this item is ignored. This can
1046 be a String with a single pattern or a List of
1047 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001048 replace boolean flag, set to v:true to remove all the
1049 commands associated with the specified autocmd
1050 event and group and add the {cmd}. This is
1051 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001052 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001053
1054 Returns v:true on success and v:false on failure.
1055 Examples: >
1056 " Create a buffer-local autocmd for buffer 5
1057 let acmd = {}
1058 let acmd.group = 'MyGroup'
1059 let acmd.event = 'BufEnter'
1060 let acmd.bufnr = 5
1061 let acmd.cmd = 'call BufEnterFunc()'
1062 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001063<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001064 Can also be used as a |method|: >
1065 GetAutocmdList()->autocmd_add()
1066<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001067 Return type: |vim9-boolean|
1068
1069
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001070autocmd_delete({acmds}) *autocmd_delete()*
1071 Deletes a List of autocmds and autocmd groups.
1072
1073 The {acmds} argument is a List where each item is a Dict with
1074 the following optional items:
1075 bufnr buffer number to delete a buffer-local autocmd.
1076 If this item is specified, then the "pattern"
1077 item is ignored.
1078 cmd Ex command for this autocmd event
1079 event autocmd event name. Refer to |autocmd-events|.
1080 If '*' then all the autocmd events in this
1081 group are deleted.
1082 group autocmd group name. Refer to |autocmd-groups|.
1083 If not specified or empty, then the default
1084 group is used.
1085 nested set to v:true for a nested autocmd.
1086 Refer to |autocmd-nested|.
1087 once set to v:true for an autocmd which executes
1088 only once. Refer to |autocmd-once|.
1089 pattern autocmd pattern string. Refer to
1090 |autocmd-patterns|. If "bufnr" item is
1091 present, then this item is ignored.
1092
1093 If only {group} is specified in a {acmds} entry and {event},
1094 {pattern} and {cmd} are not specified, then that autocmd group
1095 is deleted.
1096
Bram Moolenaar016188f2022-06-06 20:52:59 +01001097 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001098 Examples: >
1099 " :autocmd! BufLeave *.vim
1100 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1101 call autocmd_delete([acmd]})
1102 " :autocmd! MyGroup1 BufLeave
1103 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1104 call autocmd_delete([acmd])
1105 " :autocmd! MyGroup2 BufEnter *.c
1106 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1107 \ pattern: '*.c'}
1108 " :autocmd! MyGroup2 * *.c
1109 let acmd = #{group: 'MyGroup2', event: '*',
1110 \ pattern: '*.c'}
1111 call autocmd_delete([acmd])
1112 " :autocmd! MyGroup3
1113 let acmd = #{group: 'MyGroup3'}
1114 call autocmd_delete([acmd])
1115<
1116 Can also be used as a |method|: >
1117 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001118<
1119 Return type: |vim9-boolean|
1120
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001121
1122autocmd_get([{opts}]) *autocmd_get()*
1123 Returns a |List| of autocmds. If {opts} is not supplied, then
1124 returns the autocmds for all the events in all the groups.
1125
1126 The optional {opts} Dict argument supports the following
1127 items:
1128 group Autocmd group name. If specified, returns only
1129 the autocmds defined in this group. If the
1130 specified group doesn't exist, results in an
1131 error message. If set to an empty string,
1132 then the default autocmd group is used.
1133 event Autocmd event name. If specified, returns only
1134 the autocmds defined for this event. If set
1135 to "*", then returns autocmds for all the
1136 events. If the specified event doesn't exist,
1137 results in an error message.
1138 pattern Autocmd pattern. If specified, returns only
1139 the autocmds defined for this pattern.
1140 A combination of the above three times can be supplied in
1141 {opts}.
1142
1143 Each Dict in the returned List contains the following items:
1144 bufnr For buffer-local autocmds, buffer number where
1145 the autocmd is defined.
1146 cmd Command executed for this autocmd.
1147 event Autocmd event name.
1148 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001149 nested Boolean flag, set to v:true for a nested
1150 autocmd. See |autocmd-nested|.
1151 once Boolean flag, set to v:true, if the autocmd
1152 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001153 pattern Autocmd pattern. For a buffer-local
1154 autocmd, this will be of the form "<buffer=n>".
1155 If there are multiple commands for an autocmd event in a
1156 group, then separate items are returned for each command.
1157
Bram Moolenaar016188f2022-06-06 20:52:59 +01001158 Returns an empty List if an autocmd with the specified group
1159 or event or pattern is not found.
1160
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001161 Examples: >
1162 " :autocmd MyGroup
1163 echo autocmd_get(#{group: 'Mygroup'})
1164 " :autocmd G BufUnload
1165 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1166 " :autocmd G * *.ts
1167 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1168 echo autocmd_get(acmd)
1169 " :autocmd Syntax
1170 echo autocmd_get(#{event: 'Syntax'})
1171 " :autocmd G BufEnter *.ts
1172 let acmd = #{group: 'G', event: 'BufEnter',
1173 \ pattern: '*.ts'}
1174 echo autocmd_get(acmd)
1175<
1176 Can also be used as a |method|: >
1177 Getopts()->autocmd_get()
1178<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001179 Return type: list<dict<any>>
1180
1181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001182balloon_gettext() *balloon_gettext()*
1183 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001184 not used for the List. Returns an empty string if balloon
1185 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001186
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001187 Return type: |String|
1188
1189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001190balloon_show({expr}) *balloon_show()*
1191 Show {expr} inside the balloon. For the GUI {expr} is used as
1192 a string. For a terminal {expr} can be a list, which contains
1193 the lines of the balloon. If {expr} is not a list it will be
1194 split with |balloon_split()|.
1195 If {expr} is an empty string any existing balloon is removed.
1196
1197 Example: >
1198 func GetBalloonContent()
1199 " ... initiate getting the content
1200 return ''
1201 endfunc
1202 set balloonexpr=GetBalloonContent()
1203
1204 func BalloonCallback(result)
1205 call balloon_show(a:result)
1206 endfunc
1207< Can also be used as a |method|: >
1208 GetText()->balloon_show()
1209<
1210 The intended use is that fetching the content of the balloon
1211 is initiated from 'balloonexpr'. It will invoke an
1212 asynchronous method, in which a callback invokes
1213 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001214 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001215
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001216 When showing a balloon is not possible then nothing happens,
1217 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001218 {only available when compiled with the |+balloon_eval| or
1219 |+balloon_eval_term| feature}
1220
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001221 Return type: |Number|
1222
1223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001224balloon_split({msg}) *balloon_split()*
1225 Split String {msg} into lines to be displayed in a balloon.
1226 The splits are made for the current window size and optimize
1227 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001228 Returns a |List| with the split lines. Returns an empty List
1229 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001230 Can also be used as a |method|: >
1231 GetText()->balloon_split()->balloon_show()
1232
1233< {only available when compiled with the |+balloon_eval_term|
1234 feature}
1235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001236 Return type: list<any> or list<string>
1237
h-easte80f3452025-01-02 10:40:29 +01001238base64_decode({string}) *base64_decode()*
1239 Return a Blob containing the bytes decoded from the base64
1240 encoded characters in {string}.
1241
1242 The {string} argument should contain only base64-encoded
1243 characters and should have a length that is a multiple of 4.
1244
1245 Returns an empty blob on error.
1246
1247 Examples: >
1248 " Write the decoded contents to a binary file
1249 call writefile(base64_decode(s), 'tools.bmp')
1250 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001251 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001252<
1253 Can also be used as a |method|: >
1254 GetEncodedString()->base64_decode()
1255<
1256 Return type: |Blob|
1257
1258
1259base64_encode({blob}) *base64_encode()*
1260 Return a base64-encoded String representing the bytes in
1261 {blob}. The base64 alphabet defined in RFC 4648 is used.
1262
1263 Examples: >
1264 " Encode the contents of a binary file
1265 echo base64_encode(readblob('somefile.bin'))
1266 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001267 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001268<
1269 Can also be used as a |method|: >
1270 GetBinaryData()->base64_encode()
1271<
1272 Return type: |String|
1273
1274
Christ van Willegence0ef912024-06-20 23:41:59 +02001275bindtextdomain({package}, {path}) *bindtextdomain()*
1276 Bind a specific {package} to a {path} so that the
1277 |gettext()| function can be used to get language-specific
1278 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001279 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001280
Christ van Willegen8252ef12024-07-11 21:36:21 +02001281 Returns v:true on success and v:false on failure (out of
1282 memory).
1283
1284 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001286blob2list({blob}) *blob2list()*
1287 Return a List containing the number value of each byte in Blob
1288 {blob}. Examples: >
1289 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1290 blob2list(0z) returns []
1291< Returns an empty List on error. |list2blob()| does the
1292 opposite.
1293
1294 Can also be used as a |method|: >
1295 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001296<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001297 Return type: list<any> or list<number>
1298
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001299
1300blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001301 Return a List of Strings in the current 'encoding' by
1302 converting the bytes in {blob} into characters.
1303
1304 Each <NL> byte in the blob is interpreted as the end of a
1305 string and a new list item is added. Each <NUL> byte in the
1306 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001307
1308 If {options} is not supplied, the current 'encoding' value is
1309 used to decode the bytes in {blob}.
1310
1311 The argument {options} is a |Dict| and supports the following
1312 items:
1313 encoding Decode the bytes in {blob} using this
1314 encoding. The value is a |String|. See
Bakudankunb3854bf2025-02-23 20:29:21 +01001315 |encoding-names| for the supported values
1316 (plus the special value "none").
Christian Brabandtd5afc742025-03-18 20:55:42 +01001317 *E1515* *E1516*
Bakudankunb3854bf2025-02-23 20:29:21 +01001318 When current 'encoding' is "utf-8", an error is given and an
1319 empty List is returned if an invalid byte sequence is
1320 encountered in {blob}. To suppress this validation and get
1321 potentially invalid string, set "encoding" in {options} to
1322 "none".
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001323
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001324 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001325
1326 See also |str2blob()|
1327
1328 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +01001329 blob2str(0z6162) returns ['ab']
1330 blob2str(0zC2ABC2BB) returns ['«»']
1331 blob2str(0z610A62) returns ['a', 'b']
1332 blob2str(0z610062) returns ['a\nb']
1333 blob2str(0zABBB, {'encoding': 'latin1'}) returns ['«»']
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001334<
1335 Can also be used as a |method|: >
1336 GetBlob()->blob2str()
1337<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001338 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001339
1340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001341 *browse()*
1342browse({save}, {title}, {initdir}, {default})
1343 Put up a file requester. This only works when "has("browse")"
1344 returns |TRUE| (only in some GUI versions).
1345 The input fields are:
1346 {save} when |TRUE|, select file to write
1347 {title} title for the requester
1348 {initdir} directory to start browsing in
1349 {default} default file name
1350 An empty string is returned when the "Cancel" button is hit,
1351 something went wrong, or browsing is not possible.
1352
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001353 Return type: |String|
1354
1355
1356browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001357 Put up a directory requester. This only works when
1358 "has("browse")" returns |TRUE| (only in some GUI versions).
1359 On systems where a directory browser is not supported a file
1360 browser is used. In that case: select a file in the directory
1361 to be used.
1362 The input fields are:
1363 {title} title for the requester
1364 {initdir} directory to start browsing in
1365 When the "Cancel" button is hit, something went wrong, or
1366 browsing is not possible, an empty string is returned.
1367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001368 Return type: |String|
1369
1370
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001371bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001372 Add a buffer to the buffer list with name {name} (must be a
1373 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001374 If a buffer for file {name} already exists, return that buffer
1375 number. Otherwise return the buffer number of the newly
1376 created buffer. When {name} is an empty string then a new
1377 buffer is always created.
1378 The buffer will not have 'buflisted' set and not be loaded
1379 yet. To add some text to the buffer use this: >
1380 let bufnr = bufadd('someName')
1381 call bufload(bufnr)
1382 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001383< Returns 0 on error.
1384 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001385 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001386<
1387 Return type: |Number|
1388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001389
1390bufexists({buf}) *bufexists()*
1391 The result is a Number, which is |TRUE| if a buffer called
1392 {buf} exists.
1393 If the {buf} argument is a number, buffer numbers are used.
1394 Number zero is the alternate buffer for the current window.
1395
1396 If the {buf} argument is a string it must match a buffer name
1397 exactly. The name can be:
1398 - Relative to the current directory.
1399 - A full path.
1400 - The name of a buffer with 'buftype' set to "nofile".
1401 - A URL name.
1402 Unlisted buffers will be found.
1403 Note that help files are listed by their short name in the
1404 output of |:buffers|, but bufexists() requires using their
1405 long name to be able to find them.
1406 bufexists() may report a buffer exists, but to use the name
1407 with a |:buffer| command you may need to use |expand()|. Esp
1408 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1409 Use "bufexists(0)" to test for the existence of an alternate
1410 file name.
1411
1412 Can also be used as a |method|: >
1413 let exists = 'somename'->bufexists()
1414<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001415 Return type: |Number|
1416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001417 Obsolete name: buffer_exists(). *buffer_exists()*
1418
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001420buflisted({buf}) *buflisted()*
1421 The result is a Number, which is |TRUE| if a buffer called
1422 {buf} exists and is listed (has the 'buflisted' option set).
1423 The {buf} argument is used like with |bufexists()|.
1424
1425 Can also be used as a |method|: >
1426 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001427<
1428 Return type: |Number|
1429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001430
1431bufload({buf}) *bufload()*
1432 Ensure the buffer {buf} is loaded. When the buffer name
1433 refers to an existing file then the file is read. Otherwise
1434 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001435 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001436 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001437 If there is an existing swap file for the file of the buffer,
1438 there will be no dialog, the buffer will be loaded anyway.
1439 The {buf} argument is used like with |bufexists()|.
1440
1441 Can also be used as a |method|: >
1442 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001443<
1444 Return type: |Number|
1445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001446
1447bufloaded({buf}) *bufloaded()*
1448 The result is a Number, which is |TRUE| if a buffer called
1449 {buf} exists and is loaded (shown in a window or hidden).
1450 The {buf} argument is used like with |bufexists()|.
1451
1452 Can also be used as a |method|: >
1453 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001454<
1455 Return type: |Number|
1456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001457
1458bufname([{buf}]) *bufname()*
1459 The result is the name of a buffer. Mostly as it is displayed
1460 by the `:ls` command, but not using special names such as
1461 "[No Name]".
1462 If {buf} is omitted the current buffer is used.
1463 If {buf} is a Number, that buffer number's name is given.
1464 Number zero is the alternate buffer for the current window.
1465 If {buf} is a String, it is used as a |file-pattern| to match
1466 with the buffer names. This is always done like 'magic' is
1467 set and 'cpoptions' is empty. When there is more than one
1468 match an empty string is returned.
1469 "" or "%" can be used for the current buffer, "#" for the
1470 alternate buffer.
1471 A full match is preferred, otherwise a match at the start, end
1472 or middle of the buffer name is accepted. If you only want a
1473 full match then put "^" at the start and "$" at the end of the
1474 pattern.
1475 Listed buffers are found first. If there is a single match
1476 with a listed buffer, that one is returned. Next unlisted
1477 buffers are searched for.
1478 If the {buf} is a String, but you want to use it as a buffer
1479 number, force it to be a Number by adding zero to it: >
1480 :echo bufname("3" + 0)
1481< Can also be used as a |method|: >
1482 echo bufnr->bufname()
1483
1484< If the buffer doesn't exist, or doesn't have a name, an empty
1485 string is returned. >
1486 bufname("#") alternate buffer name
1487 bufname(3) name of buffer 3
1488 bufname("%") name of current buffer
1489 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001490<
1491 Return type: |String|
1492 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001493 Obsolete name: buffer_name().
1494
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001495
1496bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001497 The result is the number of a buffer, as it is displayed by
1498 the `:ls` command. For the use of {buf}, see |bufname()|
1499 above.
1500
1501 If the buffer doesn't exist, -1 is returned. Or, if the
1502 {create} argument is present and TRUE, a new, unlisted,
1503 buffer is created and its number is returned. Example: >
1504 let newbuf = bufnr('Scratch001', 1)
1505< Using an empty name uses the current buffer. To create a new
1506 buffer with an empty name use |bufadd()|.
1507
1508 bufnr("$") is the last buffer: >
1509 :let last_buffer = bufnr("$")
1510< The result is a Number, which is the highest buffer number
1511 of existing buffers. Note that not all buffers with a smaller
1512 number necessarily exist, because ":bwipeout" may have removed
1513 them. Use bufexists() to test for the existence of a buffer.
1514
1515 Can also be used as a |method|: >
1516 echo bufref->bufnr()
1517<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001518 Return type: |Number|
1519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001520 Obsolete name: buffer_number(). *buffer_number()*
1521 *last_buffer_nr()*
1522 Obsolete name for bufnr("$"): last_buffer_nr().
1523
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525bufwinid({buf}) *bufwinid()*
1526 The result is a Number, which is the |window-ID| of the first
1527 window associated with buffer {buf}. For the use of {buf},
1528 see |bufname()| above. If buffer {buf} doesn't exist or
1529 there is no such window, -1 is returned. Example: >
1530
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001531 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001532<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001533 Only deals with the current tab page. See |win_findbuf()| for
1534 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001535
1536 Can also be used as a |method|: >
1537 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001538<
1539 Return type: |Number|
1540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001541
1542bufwinnr({buf}) *bufwinnr()*
1543 Like |bufwinid()| but return the window number instead of the
1544 |window-ID|.
1545 If buffer {buf} doesn't exist or there is no such window, -1
1546 is returned. Example: >
1547
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001548 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001549
1550< The number can be used with |CTRL-W_w| and ":wincmd w"
1551 |:wincmd|.
1552
1553 Can also be used as a |method|: >
1554 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001555<
1556 Return type: |Number|
1557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001558
1559byte2line({byte}) *byte2line()*
1560 Return the line number that contains the character at byte
1561 count {byte} in the current buffer. This includes the
1562 end-of-line character, depending on the 'fileformat' option
1563 for the current buffer. The first character has byte count
1564 one.
1565 Also see |line2byte()|, |go| and |:goto|.
1566
Bram Moolenaar016188f2022-06-06 20:52:59 +01001567 Returns -1 if the {byte} value is invalid.
1568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001569 Can also be used as a |method|: >
1570 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001571<
1572 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001574 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575 feature}
1576
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001577
Christian Brabandt67672ef2023-04-24 21:09:54 +01001578byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001579 Return byte index of the {nr}'th character in the String
1580 {expr}. Use zero for the first character, it then returns
1581 zero.
1582 If there are no multibyte characters the returned value is
1583 equal to {nr}.
1584 Composing characters are not counted separately, their byte
1585 length is added to the preceding base character. See
1586 |byteidxcomp()| below for counting composing characters
1587 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001588 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1589 index in the String {expr} instead of as the character index.
1590 The UTF-16 index is the index in the string when it is encoded
1591 with 16-bit words. If the specified UTF-16 index is in the
1592 middle of a character (e.g. in a 4-byte character), then the
1593 byte index of the first byte in the character is returned.
1594 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001595 Example : >
1596 echo matchstr(str, ".", byteidx(str, 3))
1597< will display the fourth character. Another way to do the
1598 same: >
1599 let s = strpart(str, byteidx(str, 3))
1600 echo strpart(s, 0, byteidx(s, 1))
1601< Also see |strgetchar()| and |strcharpart()|.
1602
1603 If there are less than {nr} characters -1 is returned.
1604 If there are exactly {nr} characters the length of the string
1605 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001606 See |charidx()| and |utf16idx()| for getting the character and
1607 UTF-16 index respectively from the byte index.
1608 Examples: >
1609 echo byteidx('a😊😊', 2) returns 5
1610 echo byteidx('a😊😊', 2, 1) returns 1
1611 echo byteidx('a😊😊', 3, 1) returns 5
1612<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001613 Can also be used as a |method|: >
1614 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001615<
1616 Return type: |Number|
1617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001618
Christian Brabandt67672ef2023-04-24 21:09:54 +01001619byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620 Like byteidx(), except that a composing character is counted
1621 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001622 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001623 echo byteidx(s, 1)
1624 echo byteidxcomp(s, 1)
1625 echo byteidxcomp(s, 2)
1626< The first and third echo result in 3 ('e' plus composing
1627 character is 3 bytes), the second echo results in 1 ('e' is
1628 one byte).
1629 Only works differently from byteidx() when 'encoding' is set
1630 to a Unicode encoding.
1631
1632 Can also be used as a |method|: >
1633 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001634<
1635 Return type: |Number|
1636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001637
1638call({func}, {arglist} [, {dict}]) *call()* *E699*
1639 Call function {func} with the items in |List| {arglist} as
1640 arguments.
1641 {func} can either be a |Funcref| or the name of a function.
1642 a:firstline and a:lastline are set to the cursor line.
1643 Returns the return value of the called function.
1644 {dict} is for functions with the "dict" attribute. It will be
1645 used to set the local variable "self". |Dictionary-function|
1646
1647 Can also be used as a |method|: >
1648 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001649<
1650 Return type: any, depending on {func}
1651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001652
1653ceil({expr}) *ceil()*
1654 Return the smallest integral value greater than or equal to
1655 {expr} as a |Float| (round up).
1656 {expr} must evaluate to a |Float| or a |Number|.
1657 Examples: >
1658 echo ceil(1.456)
1659< 2.0 >
1660 echo ceil(-5.456)
1661< -5.0 >
1662 echo ceil(4.0)
1663< 4.0
1664
Bram Moolenaar016188f2022-06-06 20:52:59 +01001665 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001667 Can also be used as a |method|: >
1668 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001669<
1670 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001671
1672
1673ch_ functions are documented here: |channel-functions-details|
1674
1675
1676changenr() *changenr()*
1677 Return the number of the most recent change. This is the same
1678 number as what is displayed with |:undolist| and can be used
1679 with the |:undo| command.
1680 When a change was made it is the number of that change. After
1681 redo it is the number of the redone change. After undo it is
1682 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001683 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001685 Return type: |Number|
1686
1687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001688char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001689 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690 Examples: >
1691 char2nr(" ") returns 32
1692 char2nr("ABC") returns 65
1693< When {utf8} is omitted or zero, the current 'encoding' is used.
1694 Example for "utf-8": >
1695 char2nr("á") returns 225
1696 char2nr("á"[0]) returns 195
1697< When {utf8} is TRUE, always treat as UTF-8 characters.
1698 A combining character is a separate character.
1699 |nr2char()| does the opposite.
1700 To turn a string into a list of character numbers: >
1701 let str = "ABC"
1702 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1703< Result: [65, 66, 67]
1704
Bram Moolenaar016188f2022-06-06 20:52:59 +01001705 Returns 0 if {string} is not a |String|.
1706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001707 Can also be used as a |method|: >
1708 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001709<
1710 Return type: |Number|
1711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001713charclass({string}) *charclass()*
1714 Return the character class of the first character in {string}.
1715 The character class is one of:
1716 0 blank
1717 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001718 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 3 emoji
1720 other specific Unicode class
1721 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001722 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001724 Return type: |Number|
1725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001726
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001727charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001728 Same as |col()| but returns the character index of the column
1729 position given with {expr} instead of the byte position.
1730
1731 Example:
1732 With the cursor on '세' in line 5 with text "여보세요": >
1733 charcol('.') returns 3
1734 col('.') returns 7
1735
1736< Can also be used as a |method|: >
1737 GetPos()->col()
1738<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001739 Return type: |Number|
1740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001741 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001742charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001743 Return the character index of the byte at {idx} in {string}.
1744 The index of the first character is zero.
1745 If there are no multibyte characters the returned value is
1746 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001748 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001749 are not counted separately, their byte length is added to the
1750 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 When {countcc} is |TRUE|, then composing characters are
1752 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001753
1754 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1755 index in the String {expr} instead of as the byte index.
1756
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001757 Returns -1 if the arguments are invalid or if there are less
1758 than {idx} bytes. If there are exactly {idx} bytes the length
1759 of the string in characters is returned.
1760
1761 An error is given and -1 is returned if the first argument is
1762 not a string, the second argument is not a number or when the
1763 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001764
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001766 from the character index and |utf16idx()| for getting the
1767 UTF-16 index from the character index.
1768 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001769 Examples: >
1770 echo charidx('áb́ć', 3) returns 1
1771 echo charidx('áb́ć', 6, 1) returns 4
1772 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001773 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001774<
1775 Can also be used as a |method|: >
1776 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001777<
1778 Return type: |Number|
1779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001780
1781chdir({dir}) *chdir()*
1782 Change the current working directory to {dir}. The scope of
1783 the directory change depends on the directory of the current
1784 window:
1785 - If the current window has a window-local directory
1786 (|:lcd|), then changes the window local directory.
1787 - Otherwise, if the current tabpage has a local
1788 directory (|:tcd|) then changes the tabpage local
1789 directory.
1790 - Otherwise, changes the global directory.
1791 {dir} must be a String.
1792 If successful, returns the previous working directory. Pass
1793 this to another chdir() to restore the directory.
1794 On failure, returns an empty string.
1795
1796 Example: >
1797 let save_dir = chdir(newdir)
1798 if save_dir != ""
1799 " ... do some work
1800 call chdir(save_dir)
1801 endif
1802
1803< Can also be used as a |method|: >
1804 GetDir()->chdir()
1805<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001806 Return type: |String|
1807
1808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001809cindent({lnum}) *cindent()*
1810 Get the amount of indent for line {lnum} according the C
1811 indenting rules, as with 'cindent'.
1812 The indent is counted in spaces, the value of 'tabstop' is
1813 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001814 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001815 See |C-indenting|.
1816
1817 Can also be used as a |method|: >
1818 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001819<
1820 Return type: |Number|
1821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001822
1823clearmatches([{win}]) *clearmatches()*
1824 Clears all matches previously defined for the current window
1825 by |matchadd()| and the |:match| commands.
1826 If {win} is specified, use the window with this number or
1827 window ID instead of the current window.
1828
1829 Can also be used as a |method|: >
1830 GetWin()->clearmatches()
1831<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001832 Return type: |Number|
1833
1834
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001835col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001836 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001837 position given with {expr}.
1838 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001839 When {expr} is "$", it means the end of the cursor line, so
1840 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001841 Additionally {expr} can be [lnum, col]: a |List| with the line
1842 and column number. Most useful when the column is "$", to get
1843 the last column of a specific line. When "lnum" or "col" is
1844 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001845
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001846 With the optional {winid} argument the values are obtained for
1847 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001849 To get the line number use |line()|. To get both use
1850 |getpos()|.
1851 For the screen column position use |virtcol()|. For the
1852 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001854 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001856 Examples: >
1857 col(".") column of cursor
1858 col("$") length of cursor line plus one
1859 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001860 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001861<
1862 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001863 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001864 For an uppercase mark the column may actually be in another
1865 buffer.
1866 For the cursor position, when 'virtualedit' is active, the
1867 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001868 line. Also, when using a <Cmd> mapping the cursor isn't
1869 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001870 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001871
1872< Can also be used as a |method|: >
1873 GetPos()->col()
1874<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001875 Return type: |Number|
1876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001877
1878complete({startcol}, {matches}) *complete()* *E785*
1879 Set the matches for Insert mode completion.
1880 Can only be used in Insert mode. You need to use a mapping
1881 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1882 or with an expression mapping.
1883 {startcol} is the byte offset in the line where the completed
1884 text start. The text up to the cursor is the original text
1885 that will be replaced by the matches. Use col('.') for an
1886 empty string. "col('.') - 1" will replace one character by a
1887 match.
1888 {matches} must be a |List|. Each |List| item is one match.
1889 See |complete-items| for the kind of items that are possible.
1890 "longest" in 'completeopt' is ignored.
1891 Note that the after calling this function you need to avoid
1892 inserting anything that would cause completion to stop.
1893 The match can be selected with CTRL-N and CTRL-P as usual with
1894 Insert mode completion. The popup menu will appear if
1895 specified, see |ins-completion-menu|.
1896 Example: >
1897 inoremap <F5> <C-R>=ListMonths()<CR>
1898
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001899 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001900 call complete(col('.'), ['January', 'February', 'March',
1901 \ 'April', 'May', 'June', 'July', 'August', 'September',
1902 \ 'October', 'November', 'December'])
1903 return ''
1904 endfunc
1905< This isn't very useful, but it shows how it works. Note that
1906 an empty string is returned to avoid a zero being inserted.
1907
1908 Can also be used as a |method|, the base is passed as the
1909 second argument: >
1910 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001911<
1912 Return type: |Number|
1913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001914
1915complete_add({expr}) *complete_add()*
1916 Add {expr} to the list of matches. Only to be used by the
1917 function specified with the 'completefunc' option.
1918 Returns 0 for failure (empty string or out of memory),
1919 1 when the match was added, 2 when the match was already in
1920 the list.
1921 See |complete-functions| for an explanation of {expr}. It is
1922 the same as one item in the list that 'omnifunc' would return.
1923
1924 Can also be used as a |method|: >
1925 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001926<
1927 Return type: |Number|
1928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001929
1930complete_check() *complete_check()*
1931 Check for a key typed while looking for completion matches.
1932 This is to be used when looking for matches takes some time.
1933 Returns |TRUE| when searching for matches is to be aborted,
1934 zero otherwise.
1935 Only to be used by the function specified with the
1936 'completefunc' option.
1937
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001938 Return type: |Number|
1939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001940
1941complete_info([{what}]) *complete_info()*
1942 Returns a |Dictionary| with information about Insert mode
1943 completion. See |ins-completion|.
1944 The items are:
1945 mode Current completion mode name string.
1946 See |complete_info_mode| for the values.
1947 pum_visible |TRUE| if popup menu is visible.
1948 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001949 items List of all completion candidates. Each item
1950 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001951 "abbr", "menu", "kind", "info" and "user_data".
1952 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001953 matches Same as "items", but only returns items that
1954 are matching current query. If both "matches"
1955 and "items" are in "what", the returned list
1956 will still be named "items", but each item
1957 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001958 selected Selected item index. First index is zero.
1959 Index is -1 if no item is selected (showing
1960 typed text only, or the last completion after
1961 no item is selected when using the <Up> or
1962 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001963 completed Return a dictionary containing the entries of
1964 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001965
1966 *complete_info_mode*
1967 mode values are:
1968 "" Not in completion mode
1969 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1970 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1971 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1972 |i_CTRL-X_CTRL-Y|
1973 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1974 "files" File names |i_CTRL-X_CTRL-F|
1975 "tags" Tags |i_CTRL-X_CTRL-]|
1976 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1977 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1978 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1979 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1980 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1981 "function" User defined completion |i_CTRL-X_CTRL-U|
1982 "omni" Omni completion |i_CTRL-X_CTRL-O|
1983 "spell" Spelling suggestions |i_CTRL-X_s|
1984 "eval" |complete()| completion
1985 "unknown" Other internal modes
1986
1987 If the optional {what} list argument is supplied, then only
1988 the items listed in {what} are returned. Unsupported items in
1989 {what} are silently ignored.
1990
1991 To get the position and size of the popup menu, see
1992 |pum_getpos()|. It's also available in |v:event| during the
1993 |CompleteChanged| event.
1994
Bram Moolenaar016188f2022-06-06 20:52:59 +01001995 Returns an empty |Dictionary| on error.
1996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001997 Examples: >
1998 " Get all items
1999 call complete_info()
2000 " Get only 'mode'
2001 call complete_info(['mode'])
2002 " Get only 'mode' and 'pum_visible'
2003 call complete_info(['mode', 'pum_visible'])
2004
2005< Can also be used as a |method|: >
2006 GetItems()->complete_info()
2007<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002008 Return type: dict<any>
2009
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002010 *confirm()*
2011confirm({msg} [, {choices} [, {default} [, {type}]]])
2012 confirm() offers the user a dialog, from which a choice can be
2013 made. It returns the number of the choice. For the first
2014 choice this is 1.
2015 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002016 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002017
2018 {msg} is displayed in a |dialog| with {choices} as the
2019 alternatives. When {choices} is missing or empty, "&OK" is
2020 used (and translated).
2021 {msg} is a String, use '\n' to include a newline. Only on
2022 some systems the string is wrapped when it doesn't fit.
2023
2024 {choices} is a String, with the individual choices separated
2025 by '\n', e.g. >
2026 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2027< The letter after the '&' is the shortcut key for that choice.
2028 Thus you can type 'c' to select "Cancel". The shortcut does
2029 not need to be the first letter: >
2030 confirm("file has been modified", "&Save\nSave &All")
2031< For the console, the first letter of each choice is used as
2032 the default shortcut key. Case is ignored.
2033
2034 The optional {default} argument is the number of the choice
2035 that is made if the user hits <CR>. Use 1 to make the first
2036 choice the default one. Use 0 to not set a default. If
2037 {default} is omitted, 1 is used.
2038
2039 The optional {type} String argument gives the type of dialog.
2040 This is only used for the icon of the GTK, Mac, Motif and
2041 Win32 GUI. It can be one of these values: "Error",
2042 "Question", "Info", "Warning" or "Generic". Only the first
2043 character is relevant. When {type} is omitted, "Generic" is
2044 used.
2045
2046 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2047 or another valid interrupt key, confirm() returns 0.
2048
2049 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002050 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002051 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002052 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002053 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002054 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002055 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002056 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002057 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002058 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002059< In a GUI dialog, buttons are used. The layout of the buttons
2060 depends on the 'v' flag in 'guioptions'. If it is included,
2061 the buttons are always put vertically. Otherwise, confirm()
2062 tries to put the buttons in one horizontal line. If they
2063 don't fit, a vertical layout is used anyway. For some systems
2064 the horizontal layout is always used.
2065
2066 Can also be used as a |method|in: >
2067 BuildMessage()->confirm("&Yes\n&No")
2068<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002069 Return type: |Number|
2070
2071
2072copy({expr}) *copy()*
2073 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002074 different from using {expr} directly.
2075 When {expr} is a |List| a shallow copy is created. This means
2076 that the original |List| can be changed without changing the
2077 copy, and vice versa. But the items are identical, thus
2078 changing an item changes the contents of both |Lists|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002079 A |Tuple| or |Dictionary| is copied in a similar way as a
2080 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002081 Also see |deepcopy()|.
2082 Can also be used as a |method|: >
2083 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002084<
2085 Return type: any, depending on {expr}
2086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002087
2088cos({expr}) *cos()*
2089 Return the cosine of {expr}, measured in radians, as a |Float|.
2090 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002091 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002092 Examples: >
2093 :echo cos(100)
2094< 0.862319 >
2095 :echo cos(-4.01)
2096< -0.646043
2097
2098 Can also be used as a |method|: >
2099 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002100<
2101 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002102
2103
2104cosh({expr}) *cosh()*
2105 Return the hyperbolic cosine of {expr} as a |Float| in the range
2106 [1, inf].
2107 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002108 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002109 Examples: >
2110 :echo cosh(0.5)
2111< 1.127626 >
2112 :echo cosh(-0.5)
2113< -1.127626
2114
2115 Can also be used as a |method|: >
2116 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002117<
2118 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002119
2120
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002121count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002122 Return the number of times an item with value {expr} appears
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002123 in |String|, |List|, |Tuple| or |Dictionary| {comp}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002124
2125 If {start} is given then start with the item with this index.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002126 {start} can only be used with a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002127
2128 When {ic} is given and it's |TRUE| then case is ignored.
2129
2130 When {comp} is a string then the number of not overlapping
2131 occurrences of {expr} is returned. Zero is returned when
2132 {expr} is an empty string.
2133
2134 Can also be used as a |method|: >
2135 mylist->count(val)
2136<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002137 Return type: |Number|
2138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002139 *cscope_connection()*
2140cscope_connection([{num} , {dbpath} [, {prepend}]])
2141 Checks for the existence of a |cscope| connection. If no
2142 parameters are specified, then the function returns:
2143 0, if cscope was not available (not compiled in), or
2144 if there are no cscope connections;
2145 1, if there is at least one cscope connection.
2146
2147 If parameters are specified, then the value of {num}
2148 determines how existence of a cscope connection is checked:
2149
2150 {num} Description of existence check
2151 ----- ------------------------------
2152 0 Same as no parameters (e.g., "cscope_connection()").
2153 1 Ignore {prepend}, and use partial string matches for
2154 {dbpath}.
2155 2 Ignore {prepend}, and use exact string matches for
2156 {dbpath}.
2157 3 Use {prepend}, use partial string matches for both
2158 {dbpath} and {prepend}.
2159 4 Use {prepend}, use exact string matches for both
2160 {dbpath} and {prepend}.
2161
2162 Note: All string comparisons are case sensitive!
2163
2164 Examples. Suppose we had the following (from ":cs show"): >
2165
2166 # pid database name prepend path
2167 0 27664 cscope.out /usr/local
2168<
2169 Invocation Return Val ~
2170 ---------- ---------- >
2171 cscope_connection() 1
2172 cscope_connection(1, "out") 1
2173 cscope_connection(2, "out") 0
2174 cscope_connection(3, "out") 0
2175 cscope_connection(3, "out", "local") 1
2176 cscope_connection(4, "out") 0
2177 cscope_connection(4, "out", "local") 0
2178 cscope_connection(4, "cscope.out", "/usr/local") 1
2179<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002180 Return type: |Number|
2181
2182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002183cursor({lnum}, {col} [, {off}]) *cursor()*
2184cursor({list})
2185 Positions the cursor at the column (byte count) {col} in the
2186 line {lnum}. The first column is one.
2187
2188 When there is one argument {list} this is used as a |List|
2189 with two, three or four item:
2190 [{lnum}, {col}]
2191 [{lnum}, {col}, {off}]
2192 [{lnum}, {col}, {off}, {curswant}]
2193 This is like the return value of |getpos()| or |getcurpos()|,
2194 but without the first item.
2195
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002196 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002197 |setcursorcharpos()|.
2198
2199 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002200 {lnum} is used like with |getline()|, except that if {lnum} is
2201 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002202 If {lnum} is greater than the number of lines in the buffer,
2203 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002204 If {col} is greater than the number of bytes in the line,
2205 the cursor will be positioned at the last character in the
2206 line.
2207 If {col} is zero, the cursor will stay in the current column.
2208 If {curswant} is given it is used to set the preferred column
2209 for vertical movement. Otherwise {col} is used.
2210
2211 When 'virtualedit' is used {off} specifies the offset in
2212 screen columns from the start of the character. E.g., a
2213 position within a <Tab> or after the last character.
2214 Returns 0 when the position could be set, -1 otherwise.
2215
2216 Can also be used as a |method|: >
2217 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002218<
2219 Return type: |Number|
2220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002221
2222debugbreak({pid}) *debugbreak()*
2223 Specifically used to interrupt a program being debugged. It
2224 will cause process {pid} to get a SIGTRAP. Behavior for other
2225 processes is undefined. See |terminal-debugger|.
2226 {only available on MS-Windows}
2227
Bram Moolenaar016188f2022-06-06 20:52:59 +01002228 Returns |TRUE| if successfully interrupted the program.
2229 Otherwise returns |FALSE|.
2230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002231 Can also be used as a |method|: >
2232 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002233<
2234 Return type: |Number|
2235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002236
2237deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2238 Make a copy of {expr}. For Numbers and Strings this isn't
2239 different from using {expr} directly.
2240 When {expr} is a |List| a full copy is created. This means
2241 that the original |List| can be changed without changing the
2242 copy, and vice versa. When an item is a |List| or
2243 |Dictionary|, a copy for it is made, recursively. Thus
2244 changing an item in the copy does not change the contents of
2245 the original |List|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002246 A |Tuple| or |Dictionary| is copied in a similar way as a
2247 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002248
2249 When {noref} is omitted or zero a contained |List| or
2250 |Dictionary| is only copied once. All references point to
2251 this single copy. With {noref} set to 1 every occurrence of a
2252 |List| or |Dictionary| results in a new copy. This also means
2253 that a cyclic reference causes deepcopy() to fail.
2254 *E724*
2255 Nesting is possible up to 100 levels. When there is an item
2256 that refers back to a higher level making a deep copy with
2257 {noref} set to 1 will fail.
2258 Also see |copy()|.
2259
2260 Can also be used as a |method|: >
2261 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002262<
2263 Return type: any, depending on {expr}
2264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002265
2266delete({fname} [, {flags}]) *delete()*
2267 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002268 name {fname}.
2269
2270 This also works when {fname} is a symbolic link. The symbolic
2271 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002272
2273 When {flags} is "d": Deletes the directory by the name
2274 {fname}. This fails when directory {fname} is not empty.
2275
2276 When {flags} is "rf": Deletes the directory by the name
2277 {fname} and everything in it, recursively. BE CAREFUL!
2278 Note: on MS-Windows it is not possible to delete a directory
2279 that is being used.
2280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002281 The result is a Number, which is 0/false if the delete
2282 operation was successful and -1/true when the deletion failed
2283 or partly failed.
2284
2285 Use |remove()| to delete an item from a |List|.
2286 To delete a line from the buffer use |:delete| or
2287 |deletebufline()|.
2288
2289 Can also be used as a |method|: >
2290 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002291<
2292 Return type: |Number|
2293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002294
2295deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2296 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2297 If {last} is omitted then delete line {first} only.
2298 On success 0 is returned, on failure 1 is returned.
2299
2300 This function works only for loaded buffers. First call
2301 |bufload()| if needed.
2302
2303 For the use of {buf}, see |bufname()| above.
2304
2305 {first} and {last} are used like with |getline()|. Note that
2306 when using |line()| this refers to the current buffer. Use "$"
2307 to refer to the last line in buffer {buf}.
2308
2309 Can also be used as a |method|: >
2310 GetBuffer()->deletebufline(1)
2311<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002312 Return type: |Number|
2313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002314 *did_filetype()*
2315did_filetype() Returns |TRUE| when autocommands are being executed and the
2316 FileType event has been triggered at least once. Can be used
2317 to avoid triggering the FileType event again in the scripts
2318 that detect the file type. |FileType|
2319 Returns |FALSE| when `:setf FALLBACK` was used.
2320 When editing another file, the counter is reset, thus this
2321 really checks if the FileType event has been triggered for the
2322 current buffer. This allows an autocommand that starts
2323 editing another buffer to set 'filetype' and load a syntax
2324 file.
2325
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002326 Return type: |Number|
2327
2328
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002329diff({fromlist}, {tolist} [, {options}]) *diff()*
2330 Returns a String or a List containing the diff between the
2331 strings in {fromlist} and {tolist}. Uses the Vim internal
2332 diff library to compute the diff.
2333
2334 *E106*
2335 The optional "output" item in {options} specifies the returned
2336 diff format. The following values are supported:
2337 indices Return a List of the starting and ending
2338 indices and a count of the strings in each
2339 diff hunk.
2340 unified Return the unified diff output as a String.
2341 This is the default.
2342
2343 If the "output" item in {options} is "indices", then a List is
2344 returned. Each List item contains a Dict with the following
2345 items for each diff hunk:
2346 from_idx start index in {fromlist} for this diff hunk.
2347 from_count number of strings in {fromlist} that are
2348 added/removed/modified in this diff hunk.
2349 to_idx start index in {tolist} for this diff hunk.
2350 to_count number of strings in {tolist} that are
2351 added/removed/modified in this diff hunk.
2352
2353 The {options} Dict argument also specifies diff options
2354 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002355 algorithm Dict specifying the diff algorithm to
2356 use. Supported boolean items are
2357 "myers", "minimal", "patience" and
2358 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002359 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002360 iblank ignore changes where lines are all
2361 blank.
2362 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002363 indent-heuristic use the indent heuristic for the
2364 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002365 iwhite ignore changes in amount of white
2366 space.
2367 iwhiteall ignore all white space changes.
2368 iwhiteeol ignore white space changes at end of
2369 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002370 For more information about these options, refer to 'diffopt'.
2371
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002372 To compute the unified diff, all the items in {fromlist} are
2373 concatenated into a string using a newline separator and the
2374 same for {tolist}. The unified diff output uses line numbers.
2375
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002376 Returns an empty List or String if {fromlist} and {tolist} are
2377 identical.
2378
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002379 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002380 :echo diff(['abc'], ['xxx'])
2381 @@ -1 +1 @@
2382 -abc
2383 +xxx
2384
2385 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2386 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2387 :echo diff(readfile('oldfile'), readfile('newfile'))
2388 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002389<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002390 For more examples, refer to |diff-func-examples|
2391
2392 Can also be used as a |method|: >
2393 GetFromList->diff(to_list)
2394<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002395 Return type: |String| or list<dict<number>> or list<any>
2396 depending on {options}
2397
2398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002399diff_filler({lnum}) *diff_filler()*
2400 Returns the number of filler lines above line {lnum}.
2401 These are the lines that were inserted at this point in
2402 another diff'ed window. These filler lines are shown in the
2403 display but don't exist in the buffer.
2404 {lnum} is used like with |getline()|. Thus "." is the current
2405 line, "'m" mark m, etc.
2406 Returns 0 if the current window is not in diff mode.
2407
2408 Can also be used as a |method|: >
2409 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002410<
2411 Return type: |Number|
2412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002413
2414diff_hlID({lnum}, {col}) *diff_hlID()*
2415 Returns the highlight ID for diff mode at line {lnum} column
2416 {col} (byte index). When the current line does not have a
2417 diff change zero is returned.
2418 {lnum} is used like with |getline()|. Thus "." is the current
2419 line, "'m" mark m, etc.
2420 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2421 line.
2422 The highlight ID can be used with |synIDattr()| to obtain
2423 syntax information about the highlighting.
2424
2425 Can also be used as a |method|: >
2426 GetLnum()->diff_hlID(col)
2427<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002428 Return type: |Number|
2429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002430
2431digraph_get({chars}) *digraph_get()* *E1214*
2432 Return the digraph of {chars}. This should be a string with
2433 exactly two characters. If {chars} are not just two
2434 characters, or the digraph of {chars} does not exist, an error
2435 is given and an empty string is returned.
2436
2437 The character will be converted from Unicode to 'encoding'
2438 when needed. This does require the conversion to be
2439 available, it might fail.
2440
2441 Also see |digraph_getlist()|.
2442
2443 Examples: >
2444 " Get a built-in digraph
2445 :echo digraph_get('00') " Returns '∞'
2446
2447 " Get a user-defined digraph
2448 :call digraph_set('aa', 'あ')
2449 :echo digraph_get('aa') " Returns 'あ'
2450<
2451 Can also be used as a |method|: >
2452 GetChars()->digraph_get()
2453<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002454 Return type: |String|
2455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002456 This function works only when compiled with the |+digraphs|
2457 feature. If this feature is disabled, this function will
2458 display an error message.
2459
2460
2461digraph_getlist([{listall}]) *digraph_getlist()*
2462 Return a list of digraphs. If the {listall} argument is given
2463 and it is TRUE, return all digraphs, including the default
2464 digraphs. Otherwise, return only user-defined digraphs.
2465
2466 The characters will be converted from Unicode to 'encoding'
2467 when needed. This does require the conservation to be
2468 available, it might fail.
2469
2470 Also see |digraph_get()|.
2471
2472 Examples: >
2473 " Get user-defined digraphs
2474 :echo digraph_getlist()
2475
2476 " Get all the digraphs, including default digraphs
2477 :echo digraph_getlist(1)
2478<
2479 Can also be used as a |method|: >
2480 GetNumber()->digraph_getlist()
2481<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002482 Return type: list<list<string>>
2483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002484 This function works only when compiled with the |+digraphs|
2485 feature. If this feature is disabled, this function will
2486 display an error message.
2487
2488
Bram Moolenaara2baa732022-02-04 16:09:54 +00002489digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002490 Add digraph {chars} to the list. {chars} must be a string
2491 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002492 encoded character. *E1215*
2493 Be careful, composing characters are NOT ignored. This
2494 function is similar to |:digraphs| command, but useful to add
2495 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002497 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002498 this fails an error message is given and v:false is returned.
2499
2500 If you want to define multiple digraphs at once, you can use
2501 |digraph_setlist()|.
2502
2503 Example: >
2504 call digraph_set(' ', 'あ')
2505<
2506 Can be used as a |method|: >
2507 GetString()->digraph_set('あ')
2508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002509 Return type: |vim9-boolean|
2510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002511 This function works only when compiled with the |+digraphs|
2512 feature. If this feature is disabled, this function will
2513 display an error message.
2514
2515
2516digraph_setlist({digraphlist}) *digraph_setlist()*
2517 Similar to |digraph_set()| but this function can add multiple
2518 digraphs at once. {digraphlist} is a list composed of lists,
2519 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002520 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521 Example: >
2522 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2523<
2524 It is similar to the following: >
2525 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2526 call digraph_set(chars, digraph)
2527 endfor
2528< Except that the function returns after the first error,
2529 following digraphs will not be added.
2530
2531 Can be used as a |method|: >
2532 GetList()->digraph_setlist()
2533<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002534 Return type: |vim9-boolean|
2535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002536 This function works only when compiled with the |+digraphs|
2537 feature. If this feature is disabled, this function will
2538 display an error message.
2539
2540
2541echoraw({string}) *echoraw()*
2542 Output {string} as-is, including unprintable characters.
2543 This can be used to output a terminal code. For example, to
2544 disable modifyOtherKeys: >
2545 call echoraw(&t_TE)
2546< and to enable it again: >
2547 call echoraw(&t_TI)
2548< Use with care, you can mess up the terminal this way.
2549
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002550 Return type: |Number|
2551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002552
2553empty({expr}) *empty()*
2554 Return the Number 1 if {expr} is empty, zero otherwise.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002555 - A |List|, |Tuple| or |Dictionary| is empty when it does
2556 not have any items.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002557 - A |String| is empty when its length is zero.
2558 - A |Number| and |Float| are empty when their value is zero.
2559 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2560 - A |Job| is empty when it failed to start.
2561 - A |Channel| is empty when it is closed.
2562 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002563 - An |Object| is empty, when the empty() method in the object
2564 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002565
2566 For a long |List| this is much faster than comparing the
2567 length with zero.
2568
2569 Can also be used as a |method|: >
2570 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002571<
2572 Return type: |Number|
2573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002574
2575environ() *environ()*
2576 Return all of environment variables as dictionary. You can
2577 check if an environment variable exists like this: >
2578 :echo has_key(environ(), 'HOME')
2579< Note that the variable name may be CamelCase; to ignore case
2580 use this: >
2581 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002582<
2583 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002584
Bram Moolenaar416bd912023-07-07 23:19:18 +01002585
2586err_teapot([{expr}]) *err_teapot()*
2587 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002588 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002589 If {expr} is present and it is TRUE error 503 is given,
2590 indicating that coffee is temporarily not available.
2591 If {expr} is present it must be a String.
2592
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002593 Return type: |Number|
2594
Bram Moolenaar416bd912023-07-07 23:19:18 +01002595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002596escape({string}, {chars}) *escape()*
2597 Escape the characters in {chars} that occur in {string} with a
2598 backslash. Example: >
2599 :echo escape('c:\program files\vim', ' \')
2600< results in: >
2601 c:\\program\ files\\vim
2602< Also see |shellescape()| and |fnameescape()|.
2603
2604 Can also be used as a |method|: >
2605 GetText()->escape(' \')
2606<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002607 Return type: |String|
2608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002609 *eval()*
2610eval({string}) Evaluate {string} and return the result. Especially useful to
2611 turn the result of |string()| back into the original value.
2612 This works for Numbers, Floats, Strings, Blobs and composites
2613 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002614 functions. In |Vim9| script, it can be used to obtain |enum|
2615 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002616
2617 Can also be used as a |method|: >
2618 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002619<
2620 Return type: any, depending on {string}
2621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002622
2623eventhandler() *eventhandler()*
2624 Returns 1 when inside an event handler. That is that Vim got
2625 interrupted while waiting for the user to type a character,
2626 e.g., when dropping a file on Vim. This means interactive
2627 commands cannot be used. Otherwise zero is returned.
2628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002629 Return type: |Number|
2630
2631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002632executable({expr}) *executable()*
2633 This function checks if an executable with the name {expr}
2634 exists. {expr} must be the name of the program without any
2635 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002637 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002638 searchpath for programs.
2639 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002640 On MS-Windows the ".exe", ".bat", etc. can optionally be
2641 included. Then the extensions in $PATHEXT are tried. Thus if
2642 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2643 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2644 by itself can be used in $PATHEXT to try using the name
2645 without an extension. When 'shell' looks like a Unix shell,
2646 then the name is also tried without adding an extension.
2647 On MS-Windows it only checks if the file exists and is not a
2648 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002649 On MS-Windows an executable in the same directory as the Vim
2650 executable is always found. Since this directory is added to
2651 $PATH it should also work to execute it |win32-PATH|.
2652 *NoDefaultCurrentDirectoryInExePath*
2653 On MS-Windows an executable in Vim's current working directory
2654 is also normally found, but this can be disabled by setting
2655 the $NoDefaultCurrentDirectoryInExePath environment variable.
2656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657 The result is a Number:
2658 1 exists
2659 0 does not exist
2660 -1 not implemented on this system
2661 |exepath()| can be used to get the full path of an executable.
2662
2663 Can also be used as a |method|: >
2664 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002665<
2666 Return type: |Number|
2667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002668
2669execute({command} [, {silent}]) *execute()*
2670 Execute an Ex command or commands and return the output as a
2671 string.
2672 {command} can be a string or a List. In case of a List the
2673 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002674 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002675 redir => var
2676 {command}
2677 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002678< Except that line continuation in {command} is not recognized.
2679
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002680 The optional {silent} argument can have these values:
2681 "" no `:silent` used
2682 "silent" `:silent` used
2683 "silent!" `:silent!` used
2684 The default is "silent". Note that with "silent!", unlike
2685 `:redir`, error messages are dropped. When using an external
2686 command the screen may be messed up, use `system()` instead.
2687 *E930*
2688 It is not possible to use `:redir` anywhere in {command}.
2689
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002690 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002691 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002692
2693< To execute a command in another window than the current one
2694 use `win_execute()`.
2695
2696 When used recursively the output of the recursive call is not
2697 included in the output of the higher level call.
2698
2699 Can also be used as a |method|: >
2700 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002701<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002702 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002704
2705exepath({expr}) *exepath()*
2706 If {expr} is an executable and is either an absolute path, a
2707 relative path or found in $PATH, return the full path.
2708 Note that the current directory is used when {expr} starts
2709 with "./", which may be a problem for Vim: >
2710 echo exepath(v:progpath)
2711< If {expr} cannot be found in $PATH or is not executable then
2712 an empty string is returned.
2713
2714 Can also be used as a |method|: >
2715 GetCommand()->exepath()
2716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002717 Return type: |String|
2718
2719
2720exists({expr}) *exists()*
2721 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002722 zero otherwise.
2723
2724 Note: In a compiled |:def| function the evaluation is done at
2725 runtime. Use `exists_compiled()` to evaluate the expression
2726 at compile time.
2727
2728 For checking for a supported feature use |has()|.
2729 For checking if a file exists use |filereadable()|.
2730
2731 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002732 varname internal variable (see
2733 dict.key |internal-variables|). Also works
2734 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002735 import.Func entries, |List| items, class and
2736 class.Func object methods, imported items, etc.
2737 object.Func Does not work for local variables in a
2738 class.varname compiled `:def` function.
2739 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002740 script, since it can be used as a
2741 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002742 Beware that evaluating an index may
2743 cause an error message for an invalid
2744 expression. E.g.: >
2745 :let l = [1, 2, 3]
2746 :echo exists("l[5]")
2747< 0 >
2748 :echo exists("l[xx]")
2749< E121: Undefined variable: xx
2750 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002751 &option-name Vim option (only checks if it exists,
2752 not if it really works)
2753 +option-name Vim option that works.
2754 $ENVNAME environment variable (could also be
2755 done by comparing with an empty
2756 string)
2757 *funcname built-in function (see |functions|)
2758 or user defined function (see
2759 |user-functions|) that is implemented.
2760 Also works for a variable that is a
2761 Funcref.
2762 ?funcname built-in function that could be
2763 implemented; to be used to check if
2764 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002765 :cmdname Ex command: built-in command, user
2766 command or command modifier |:command|.
2767 Returns:
2768 1 for match with start of a command
2769 2 full match with a command
2770 3 matches several user commands
2771 To check for a supported command
2772 always check the return value to be 2.
2773 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002774 :3match The |:3match| command (but you
2775 probably should not use it, it is
2776 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002777 #event autocommand defined for this event
2778 #event#pattern autocommand defined for this event and
2779 pattern (the pattern is taken
2780 literally and compared to the
2781 autocommand patterns character by
2782 character)
2783 #group autocommand group exists
2784 #group#event autocommand defined for this group and
2785 event.
2786 #group#event#pattern
2787 autocommand defined for this group,
2788 event and pattern.
2789 ##event autocommand for this event is
2790 supported.
2791
2792 Examples: >
2793 exists("&shortname")
2794 exists("$HOSTNAME")
2795 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002796 exists("*s:MyFunc") " only for legacy script
2797 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002798 exists("bufcount")
2799 exists(":Make")
2800 exists("#CursorHold")
2801 exists("#BufReadPre#*.gz")
2802 exists("#filetypeindent")
2803 exists("#filetypeindent#FileType")
2804 exists("#filetypeindent#FileType#*")
2805 exists("##ColorScheme")
2806< There must be no space between the symbol (&/$/*/#) and the
2807 name.
2808 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002809 a few cases this is ignored. That may become stricter in the
2810 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002811 Working example: >
2812 exists(":make")
2813< NOT working example: >
2814 exists(":make install")
2815
2816< Note that the argument must be a string, not the name of the
2817 variable itself. For example: >
2818 exists(bufcount)
2819< This doesn't check for existence of the "bufcount" variable,
2820 but gets the value of "bufcount", and checks if that exists.
2821
2822 Can also be used as a |method|: >
2823 Varname()->exists()
2824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002825 Return type: |String|
2826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002827
2828exists_compiled({expr}) *exists_compiled()*
2829 Like `exists()` but evaluated at compile time. This is useful
2830 to skip a block where a function is used that would otherwise
2831 give an error: >
2832 if exists_compiled('*ThatFunction')
2833 ThatFunction('works')
2834 endif
2835< If `exists()` were used then a compilation error would be
2836 given if ThatFunction() is not defined.
2837
2838 {expr} must be a literal string. *E1232*
2839 Can only be used in a |:def| function. *E1233*
2840 This does not work to check for arguments or local variables.
2841
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002842 Return type: |String|
2843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002844
2845exp({expr}) *exp()*
2846 Return the exponential of {expr} as a |Float| in the range
2847 [0, inf].
2848 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002849 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002850 Examples: >
2851 :echo exp(2)
2852< 7.389056 >
2853 :echo exp(-1)
2854< 0.367879
2855
2856 Can also be used as a |method|: >
2857 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002858<
2859 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002860
2861
2862expand({string} [, {nosuf} [, {list}]]) *expand()*
2863 Expand wildcards and the following special keywords in
2864 {string}. 'wildignorecase' applies.
2865
2866 If {list} is given and it is |TRUE|, a List will be returned.
2867 Otherwise the result is a String and when there are several
2868 matches, they are separated by <NL> characters. [Note: in
2869 version 5.0 a space was used, which caused problems when a
2870 file name contains a space]
2871
2872 If the expansion fails, the result is an empty string. A name
2873 for a non-existing file is not included, unless {string} does
2874 not start with '%', '#' or '<', see below.
2875
Christian Brabandtec9c3262024-02-21 20:40:05 +01002876 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002877 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002879 When {string} starts with '%', '#' or '<', the expansion is
2880 done like for the |cmdline-special| variables with their
2881 associated modifiers. Here is a short overview:
2882
2883 % current file name
2884 # alternate file name
2885 #n alternate file name n
2886 <cfile> file name under the cursor
2887 <afile> autocmd file name
2888 <abuf> autocmd buffer number (as a String!)
2889 <amatch> autocmd matched name
2890 <cexpr> C expression under the cursor
2891 <sfile> sourced script file or function name
2892 <slnum> sourced script line number or function
2893 line number
2894 <sflnum> script file line number, also when in
2895 a function
2896 <SID> "<SNR>123_" where "123" is the
2897 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002898 <script> sourced script file, or script file
2899 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002900 <stack> call stack
2901 <cword> word under the cursor
2902 <cWORD> WORD under the cursor
2903 <client> the {clientid} of the last received
2904 message |server2client()|
2905 Modifiers:
2906 :p expand to full path
2907 :h head (last path component removed)
2908 :t tail (last path component only)
2909 :r root (one extension removed)
2910 :e extension only
2911
2912 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002913 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002914< Note that when expanding a string that starts with '%', '#' or
2915 '<', any following text is ignored. This does NOT work: >
2916 :let doesntwork = expand("%:h.bak")
2917< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002918 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002919< Also note that expanding "<cfile>" and others only returns the
2920 referenced file name without further expansion. If "<cfile>"
2921 is "~/.cshrc", you need to do another expand() to have the
2922 "~/" expanded into the path of the home directory: >
2923 :echo expand(expand("<cfile>"))
2924<
2925 There cannot be white space between the variables and the
2926 following modifier. The |fnamemodify()| function can be used
2927 to modify normal file names.
2928
2929 When using '%' or '#', and the current or alternate file name
2930 is not defined, an empty string is used. Using "%:p" in a
2931 buffer with no name, results in the current directory, with a
2932 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002933 When 'verbose' is set then expanding '%', '#' and <> items
2934 will result in an error message if the argument cannot be
2935 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002936
2937 When {string} does not start with '%', '#' or '<', it is
2938 expanded like a file name is expanded on the command line.
2939 'suffixes' and 'wildignore' are used, unless the optional
2940 {nosuf} argument is given and it is |TRUE|.
2941 Names for non-existing files are included. The "**" item can
2942 be used to search in a directory tree. For example, to find
2943 all "README" files in the current directory and below: >
2944 :echo expand("**/README")
2945<
2946 expand() can also be used to expand variables and environment
2947 variables that are only known in a shell. But this can be
2948 slow, because a shell may be used to do the expansion. See
2949 |expr-env-expand|.
2950 The expanded variable is still handled like a list of file
2951 names. When an environment variable cannot be expanded, it is
2952 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2953 "$FOOBAR".
2954
2955 See |glob()| for finding existing files. See |system()| for
2956 getting the raw output of an external command.
2957
2958 Can also be used as a |method|: >
2959 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002960<
2961 Return type: |String| or list<string> depending on {list}
2962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002963
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002964expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002965 Expand special items in String {string} like what is done for
2966 an Ex command such as `:edit`. This expands special keywords,
2967 like with |expand()|, and environment variables, anywhere in
2968 {string}. "~user" and "~/path" are only expanded at the
2969 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002970
2971 The following items are supported in the {options} Dict
2972 argument:
2973 errmsg If set to TRUE, error messages are displayed
2974 if an error is encountered during expansion.
2975 By default, error messages are not displayed.
2976
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002977 Returns the expanded string. If an error is encountered
2978 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002979
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002980 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002981 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002982 make /path/runtime/doc/builtin.o
2983 :echo expandcmd('make %<.o', {'errmsg': v:true})
2984<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002985 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002986 GetCommand()->expandcmd()
2987<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002988 Return type: |String| or list<string> depending on {list}
2989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002990extend({expr1}, {expr2} [, {expr3}]) *extend()*
2991 {expr1} and {expr2} must be both |Lists| or both
2992 |Dictionaries|.
2993
2994 If they are |Lists|: Append {expr2} to {expr1}.
2995 If {expr3} is given insert the items of {expr2} before the
2996 item with index {expr3} in {expr1}. When {expr3} is zero
2997 insert before the first item. When {expr3} is equal to
2998 len({expr1}) then {expr2} is appended.
2999 Examples: >
3000 :echo sort(extend(mylist, [7, 5]))
3001 :call extend(mylist, [2, 3], 1)
3002< When {expr1} is the same List as {expr2} then the number of
3003 items copied is equal to the original length of the List.
3004 E.g., when {expr3} is 1 you get N new copies of the first item
3005 (where N is the original length of the List).
3006 Use |add()| to concatenate one item to a list. To concatenate
3007 two lists into a new list use the + operator: >
3008 :let newlist = [1, 2, 3] + [4, 5]
3009<
3010 If they are |Dictionaries|:
3011 Add all entries from {expr2} to {expr1}.
3012 If a key exists in both {expr1} and {expr2} then {expr3} is
3013 used to decide what to do:
3014 {expr3} = "keep": keep the value of {expr1}
3015 {expr3} = "force": use the value of {expr2}
3016 {expr3} = "error": give an error message *E737*
3017 When {expr3} is omitted then "force" is assumed.
3018
3019 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003020 make a copy of {expr1} first or use |extendnew()| to return a
3021 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003022 {expr2} remains unchanged.
3023 When {expr1} is locked and {expr2} is not empty the operation
3024 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003025 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003026
3027 Can also be used as a |method|: >
3028 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003029<
3030 Return type: list<{type}> or dict<{type}> depending on {expr1}
3031 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003032
3033
3034extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3035 Like |extend()| but instead of adding items to {expr1} a new
3036 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003037 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003039 Return type: list<{type}> or dict<{type}> depending on {expr1}
3040 and {expr2}, in case of error: |Number|
3041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003042
3043feedkeys({string} [, {mode}]) *feedkeys()*
3044 Characters in {string} are queued for processing as if they
3045 come from a mapping or were typed by the user.
3046
3047 By default the string is added to the end of the typeahead
3048 buffer, thus if a mapping is still being executed the
3049 characters come after them. Use the 'i' flag to insert before
3050 other characters, they will be executed next, before any
3051 characters from a mapping.
3052
3053 The function does not wait for processing of keys contained in
3054 {string}.
3055
3056 To include special keys into {string}, use double-quotes
3057 and "\..." notation |expr-quote|. For example,
3058 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3059 feedkeys('\<CR>') pushes 5 characters.
3060 A special code that might be useful is <Ignore>, it exits the
3061 wait for a character without doing anything. *<Ignore>*
3062
3063 {mode} is a String, which can contain these character flags:
3064 'm' Remap keys. This is default. If {mode} is absent,
3065 keys are remapped.
3066 'n' Do not remap keys.
3067 't' Handle keys as if typed; otherwise they are handled as
3068 if coming from a mapping. This matters for undo,
3069 opening folds, etc.
3070 'L' Lowlevel input. Only works for Unix or when using the
3071 GUI. Keys are used as if they were coming from the
3072 terminal. Other flags are not used. *E980*
3073 When a CTRL-C interrupts and 't' is included it sets
3074 the internal "got_int" flag.
3075 'i' Insert the string instead of appending (see above).
3076 'x' Execute commands until typeahead is empty. This is
3077 similar to using ":normal!". You can call feedkeys()
3078 several times without 'x' and then one time with 'x'
3079 (possibly with an empty {string}) to execute all the
3080 typeahead. Note that when Vim ends in Insert mode it
3081 will behave as if <Esc> is typed, to avoid getting
3082 stuck, waiting for a character to be typed before the
3083 script continues.
3084 Note that if you manage to call feedkeys() while
3085 executing commands, thus calling it recursively, then
3086 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003087 'c' Remove any script context when executing, so that
3088 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003089 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003090 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003091 '!' When used with 'x' will not end Insert mode. Can be
3092 used in a test when a timer is set to exit Insert mode
3093 a little later. Useful for testing CursorHoldI.
3094
3095 Return value is always 0.
3096
3097 Can also be used as a |method|: >
3098 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003099<
3100 Return type: |String| or list<string> depending on {list}
3101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003102
Shougo Matsushita60c87432024-06-03 22:59:27 +02003103filecopy({from}, {to}) *filecopy()*
3104 Copy the file pointed to by the name {from} to {to}. The
3105 result is a Number, which is |TRUE| if the file was copied
3106 successfully, and |FALSE| when it failed.
3107 If a file with name {to} already exists, it will fail.
3108 Note that it does not handle directories (yet).
3109
3110 This function is not available in the |sandbox|.
3111
3112 Can also be used as a |method|: >
3113 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003114<
3115 Return type: |Number|
3116
Shougo Matsushita60c87432024-06-03 22:59:27 +02003117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003118filereadable({file}) *filereadable()*
3119 The result is a Number, which is |TRUE| when a file with the
3120 name {file} exists, and can be read. If {file} doesn't exist,
3121 or is a directory, the result is |FALSE|. {file} is any
3122 expression, which is used as a String.
3123 If you don't care about the file being readable you can use
3124 |glob()|.
3125 {file} is used as-is, you may want to expand wildcards first: >
3126 echo filereadable('~/.vimrc')
3127 0
3128 echo filereadable(expand('~/.vimrc'))
3129 1
3130
3131< Can also be used as a |method|: >
3132 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003133<
3134 Return type: |Number|
3135
3136 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003137 Obsolete name: file_readable().
3138
3139
3140filewritable({file}) *filewritable()*
3141 The result is a Number, which is 1 when a file with the
3142 name {file} exists, and can be written. If {file} doesn't
3143 exist, or is not writable, the result is 0. If {file} is a
3144 directory, and we can write to it, the result is 2.
3145
3146 Can also be used as a |method|: >
3147 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003148<
3149 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003150
3151
3152filter({expr1}, {expr2}) *filter()*
3153 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3154 For each item in {expr1} evaluate {expr2} and when the result
3155 is zero or false remove the item from the |List| or
3156 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003157 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003158
3159 {expr2} must be a |string| or |Funcref|.
3160
3161 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3162 of the current item. For a |Dictionary| |v:key| has the key
3163 of the current item and for a |List| |v:key| has the index of
3164 the current item. For a |Blob| |v:key| has the index of the
3165 current byte. For a |String| |v:key| has the index of the
3166 current character.
3167 Examples: >
3168 call filter(mylist, 'v:val !~ "OLD"')
3169< Removes the items where "OLD" appears. >
3170 call filter(mydict, 'v:key >= 8')
3171< Removes the items with a key below 8. >
3172 call filter(var, 0)
3173< Removes all the items, thus clears the |List| or |Dictionary|.
3174
3175 Note that {expr2} is the result of expression and is then
3176 used as an expression again. Often it is good to use a
3177 |literal-string| to avoid having to double backslashes.
3178
3179 If {expr2} is a |Funcref| it must take two arguments:
3180 1. the key or the index of the current item.
3181 2. the value of the current item.
3182 The function must return |TRUE| if the item should be kept.
3183 Example that keeps the odd items of a list: >
3184 func Odd(idx, val)
3185 return a:idx % 2 == 1
3186 endfunc
3187 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003188< It is shorter when using a |lambda|. In |Vim9| syntax: >
3189 call filter(myList, (idx, val) => idx * val <= 42)
3190< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003191 call filter(myList, {idx, val -> idx * val <= 42})
3192< If you do not use "val" you can leave it out: >
3193 call filter(myList, {idx -> idx % 2 == 1})
3194<
3195 In |Vim9| script the result must be true, false, zero or one.
3196 Other values will result in a type error.
3197
3198 For a |List| and a |Dictionary| the operation is done
3199 in-place. If you want it to remain unmodified make a copy
3200 first: >
3201 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3202
3203< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003204 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003205 When an error is encountered while evaluating {expr2} no
3206 further items in {expr1} are processed.
3207 When {expr2} is a Funcref errors inside a function are ignored,
3208 unless it was defined with the "abort" flag.
3209
3210 Can also be used as a |method|: >
3211 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003212<
3213 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3214 depending on {expr1}
3215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216
3217finddir({name} [, {path} [, {count}]]) *finddir()*
3218 Find directory {name} in {path}. Supports both downwards and
3219 upwards recursive directory searches. See |file-searching|
3220 for the syntax of {path}.
3221
3222 Returns the path of the first found match. When the found
3223 directory is below the current directory a relative path is
3224 returned. Otherwise a full path is returned.
3225 If {path} is omitted or empty then 'path' is used.
3226
3227 If the optional {count} is given, find {count}'s occurrence of
3228 {name} in {path} instead of the first one.
3229 When {count} is negative return all the matches in a |List|.
3230
Bram Moolenaar016188f2022-06-06 20:52:59 +01003231 Returns an empty string if the directory is not found.
3232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003233 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235 Can also be used as a |method|: >
3236 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003237<
3238 Return type: |String|
3239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003240
3241findfile({name} [, {path} [, {count}]]) *findfile()*
3242 Just like |finddir()|, but find a file instead of a directory.
3243 Uses 'suffixesadd'.
3244 Example: >
3245 :echo findfile("tags.vim", ".;")
3246< Searches from the directory of the current file upwards until
3247 it finds the file "tags.vim".
3248
3249 Can also be used as a |method|: >
3250 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003251<
3252 Return type: |String|
3253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003254
3255flatten({list} [, {maxdepth}]) *flatten()*
3256 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3257 the result is a |List| without nesting, as if {maxdepth} is
3258 a very large number.
3259 The {list} is changed in place, use |flattennew()| if you do
3260 not want that.
3261 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003262 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003263 *E900*
3264 {maxdepth} means how deep in nested lists changes are made.
3265 {list} is not modified when {maxdepth} is 0.
3266 {maxdepth} must be positive number.
3267
3268 If there is an error the number zero is returned.
3269
3270 Example: >
3271 :echo flatten([1, [2, [3, 4]], 5])
3272< [1, 2, 3, 4, 5] >
3273 :echo flatten([1, [2, [3, 4]], 5], 1)
3274< [1, 2, [3, 4], 5]
3275
3276 Can also be used as a |method|: >
3277 mylist->flatten()
3278<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003279 Return type: list<{type}>
3280
3281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003282flattennew({list} [, {maxdepth}]) *flattennew()*
3283 Like |flatten()| but first make a copy of {list}.
3284
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003285 Return type: list<{type}>
3286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003287
3288float2nr({expr}) *float2nr()*
3289 Convert {expr} to a Number by omitting the part after the
3290 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003291 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003292 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003293 When the value of {expr} is out of range for a |Number| the
3294 result is truncated to 0x7fffffff or -0x7fffffff (or when
3295 64-bit Number support is enabled, 0x7fffffffffffffff or
3296 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3297 64-bit Number support is enabled, -0x8000000000000000).
3298 Examples: >
3299 echo float2nr(3.95)
3300< 3 >
3301 echo float2nr(-23.45)
3302< -23 >
3303 echo float2nr(1.0e100)
3304< 2147483647 (or 9223372036854775807) >
3305 echo float2nr(-1.0e150)
3306< -2147483647 (or -9223372036854775807) >
3307 echo float2nr(1.0e-100)
3308< 0
3309
3310 Can also be used as a |method|: >
3311 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003312<
3313 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003314
3315
3316floor({expr}) *floor()*
3317 Return the largest integral value less than or equal to
3318 {expr} as a |Float| (round down).
3319 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003320 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003321 Examples: >
3322 echo floor(1.856)
3323< 1.0 >
3324 echo floor(-5.456)
3325< -6.0 >
3326 echo floor(4.0)
3327< 4.0
3328
3329 Can also be used as a |method|: >
3330 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003331<
3332 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003333
3334
3335fmod({expr1}, {expr2}) *fmod()*
3336 Return the remainder of {expr1} / {expr2}, even if the
3337 division is not representable. Returns {expr1} - i * {expr2}
3338 for some integer i such that if {expr2} is non-zero, the
3339 result has the same sign as {expr1} and magnitude less than
3340 the magnitude of {expr2}. If {expr2} is zero, the value
3341 returned is zero. The value returned is a |Float|.
3342 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003343 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3344 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003345 Examples: >
3346 :echo fmod(12.33, 1.22)
3347< 0.13 >
3348 :echo fmod(-12.33, 1.22)
3349< -0.13
3350
3351 Can also be used as a |method|: >
3352 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003353<
3354 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003355
3356
3357fnameescape({string}) *fnameescape()*
3358 Escape {string} for use as file name command argument. All
3359 characters that have a special meaning, such as '%' and '|'
3360 are escaped with a backslash.
3361 For most systems the characters escaped are
3362 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3363 appears in a filename, it depends on the value of 'isfname'.
3364 A leading '+' and '>' is also escaped (special after |:edit|
3365 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003366 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003367 Example: >
3368 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003369 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003370< results in executing: >
3371 edit \+some\ str\%nge\|name
3372<
3373 Can also be used as a |method|: >
3374 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003375<
3376 Return type: |String|
3377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003378
3379fnamemodify({fname}, {mods}) *fnamemodify()*
3380 Modify file name {fname} according to {mods}. {mods} is a
3381 string of characters like it is used for file names on the
3382 command line. See |filename-modifiers|.
3383 Example: >
3384 :echo fnamemodify("main.c", ":p:h")
3385< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003386 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003387< If {mods} is empty or an unsupported modifier is used then
3388 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003389 When {fname} is empty then with {mods} ":h" returns ".", so
3390 that `:cd` can be used with it. This is different from
3391 expand('%:h') without a buffer name, which returns an empty
3392 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003393 Note: Environment variables don't work in {fname}, use
3394 |expand()| first then.
3395
3396 Can also be used as a |method|: >
3397 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003398<
3399 Return type: |String|
3400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003401
3402foldclosed({lnum}) *foldclosed()*
3403 The result is a Number. If the line {lnum} is in a closed
3404 fold, the result is the number of the first line in that fold.
3405 If the line {lnum} is not in a closed fold, -1 is returned.
3406 {lnum} is used like with |getline()|. Thus "." is the current
3407 line, "'m" mark m, etc.
3408
3409 Can also be used as a |method|: >
3410 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003411<
3412 Return type: |Number|
3413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003414
3415foldclosedend({lnum}) *foldclosedend()*
3416 The result is a Number. If the line {lnum} is in a closed
3417 fold, the result is the number of the last line in that fold.
3418 If the line {lnum} is not in a closed fold, -1 is returned.
3419 {lnum} is used like with |getline()|. Thus "." is the current
3420 line, "'m" mark m, etc.
3421
3422 Can also be used as a |method|: >
3423 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003424<
3425 Return type: |Number|
3426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427
3428foldlevel({lnum}) *foldlevel()*
3429 The result is a Number, which is the foldlevel of line {lnum}
3430 in the current buffer. For nested folds the deepest level is
3431 returned. If there is no fold at line {lnum}, zero is
3432 returned. It doesn't matter if the folds are open or closed.
3433 When used while updating folds (from 'foldexpr') -1 is
3434 returned for lines where folds are still to be updated and the
3435 foldlevel is unknown. As a special case the level of the
3436 previous line is usually available.
3437 {lnum} is used like with |getline()|. Thus "." is the current
3438 line, "'m" mark m, etc.
3439
3440 Can also be used as a |method|: >
3441 GetLnum()->foldlevel()
3442<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003443 Return type: |Number|
3444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003445 *foldtext()*
3446foldtext() Returns a String, to be displayed for a closed fold. This is
3447 the default function used for the 'foldtext' option and should
3448 only be called from evaluating 'foldtext'. It uses the
3449 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3450 The returned string looks like this: >
3451 +-- 45 lines: abcdef
3452< The number of leading dashes depends on the foldlevel. The
3453 "45" is the number of lines in the fold. "abcdef" is the text
3454 in the first non-blank line of the fold. Leading white space,
3455 "//" or "/*" and the text from the 'foldmarker' and
3456 'commentstring' options is removed.
3457 When used to draw the actual foldtext, the rest of the line
3458 will be filled with the fold char from the 'fillchars'
3459 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003460 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003461
3462 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003463 {not available when compiled without the |+folding| feature}
3464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003466foldtextresult({lnum}) *foldtextresult()*
3467 Returns the text that is displayed for the closed fold at line
3468 {lnum}. Evaluates 'foldtext' in the appropriate context.
3469 When there is no closed fold at {lnum} an empty string is
3470 returned.
3471 {lnum} is used like with |getline()|. Thus "." is the current
3472 line, "'m" mark m, etc.
3473 Useful when exporting folded text, e.g., to HTML.
3474 {not available when compiled without the |+folding| feature}
3475
3476
3477 Can also be used as a |method|: >
3478 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003479<
3480 Return type: |String|
3481
Ernie Raele79e2072024-01-13 11:47:33 +01003482
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003483foreach({expr1}, {expr2}) *foreach()* *E1525*
3484 {expr1} must be a |List|, |Tuple|, |String|, |Blob| or
3485 |Dictionary|.
Ernie Raele79e2072024-01-13 11:47:33 +01003486 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003487 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003488 See |map()| and |filter()| to modify {expr1}.
3489
3490 {expr2} must be a |string| or |Funcref|.
3491
3492 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3493 of the current item. For a |Dictionary| |v:key| has the key
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003494 of the current item and for a |List| or a |Tuple| |v:key| has
3495 the index of the current item. For a |Blob| |v:key| has the
3496 index of the current byte. For a |String| |v:key| has the
3497 index of the current character.
Ernie Raele79e2072024-01-13 11:47:33 +01003498 Examples: >
3499 call foreach(mylist, 'used[v:val] = true')
3500< This records the items that are in the {expr1} list.
3501
3502 Note that {expr2} is the result of expression and is then used
3503 as a command. Often it is good to use a |literal-string| to
3504 avoid having to double backslashes.
3505
3506 If {expr2} is a |Funcref| it must take two arguments:
3507 1. the key or the index of the current item.
3508 2. the value of the current item.
3509 With a legacy script lambda you don't get an error if it only
3510 accepts one argument, but with a Vim9 lambda you get "E1106:
3511 One argument too many", the number of arguments must match.
3512 If the function returns a value, it is ignored.
3513
3514 Returns {expr1} in all cases.
3515 When an error is encountered while executing {expr2} no
3516 further items in {expr1} are processed.
3517 When {expr2} is a Funcref errors inside a function are ignored,
3518 unless it was defined with the "abort" flag.
3519
3520 Can also be used as a |method|: >
3521 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003523 Return type: |String|, |Blob|, list<{type}>, tuple<{type}> or
3524 dict<{type}> depending on {expr1}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003526 *foreground()*
3527foreground() Move the Vim window to the foreground. Useful when sent from
3528 a client to a Vim server. |remote_send()|
3529 On Win32 systems this might not work, the OS does not always
3530 allow a window to bring itself to the foreground. Use
3531 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003532
3533 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003534 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 Win32 console version}
3536
Bram Moolenaaraa534142022-09-15 21:46:02 +01003537fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 Get the full command name from a short abbreviated command
3539 name; see |20.2| for details on command abbreviations.
3540
3541 The string argument {name} may start with a `:` and can
3542 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003543 Returns an empty string if a command doesn't exist, if it's
3544 ambiguous (for user-defined commands) or cannot be shortened
3545 this way. |vim9-no-shorten|
3546
3547 Without the {vim9} argument uses the current script version.
3548 If {vim9} is present and FALSE then legacy script rules are
3549 used. When {vim9} is present and TRUE then Vim9 rules are
3550 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003551
3552 For example `fullcommand('s')`, `fullcommand('sub')`,
3553 `fullcommand(':%substitute')` all return "substitute".
3554
3555 Can also be used as a |method|: >
3556 GetName()->fullcommand()
3557<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003558 Return type: |String|
3559
3560
3561funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003562 Just like |function()|, but the returned Funcref will lookup
3563 the function by reference, not by name. This matters when the
3564 function {name} is redefined later.
3565
3566 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003567 It only works for an autoloaded function if it has already
3568 been loaded (to avoid mistakenly loading the autoload script
3569 when only intending to use the function name, use |function()|
3570 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003571 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003572
3573 Can also be used as a |method|: >
3574 GetFuncname()->funcref([arg])
3575<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003576 Return type: func(...): any or |Number| on error
3577
Dominique Pellee764d1b2023-03-12 21:20:59 +00003578 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003579function({name} [, {arglist}] [, {dict}])
3580 Return a |Funcref| variable that refers to function {name}.
3581 {name} can be the name of a user defined function or an
3582 internal function.
3583
3584 {name} can also be a Funcref or a partial. When it is a
3585 partial the dict stored in it will be used and the {dict}
3586 argument is not allowed. E.g.: >
3587 let FuncWithArg = function(dict.Func, [arg])
3588 let Broken = function(dict.Func, [arg], dict)
3589<
3590 When using the Funcref the function will be found by {name},
3591 also when it was redefined later. Use |funcref()| to keep the
3592 same function.
3593
3594 When {arglist} or {dict} is present this creates a partial.
3595 That means the argument list and/or the dictionary is stored in
3596 the Funcref and will be used when the Funcref is called.
3597
3598 The arguments are passed to the function in front of other
3599 arguments, but after any argument from |method|. Example: >
3600 func Callback(arg1, arg2, name)
3601 ...
3602 let Partial = function('Callback', ['one', 'two'])
3603 ...
3604 call Partial('name')
3605< Invokes the function as with: >
3606 call Callback('one', 'two', 'name')
3607
3608< With a |method|: >
3609 func Callback(one, two, three)
3610 ...
3611 let Partial = function('Callback', ['two'])
3612 ...
3613 eval 'one'->Partial('three')
3614< Invokes the function as with: >
3615 call Callback('one', 'two', 'three')
3616
3617< The function() call can be nested to add more arguments to the
3618 Funcref. The extra arguments are appended to the list of
3619 arguments. Example: >
3620 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003621 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003622 let Func = function('Callback', ['one'])
3623 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003624 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003625 call Func2('name')
3626< Invokes the function as with: >
3627 call Callback('one', 'two', 'name')
3628
3629< The Dictionary is only useful when calling a "dict" function.
3630 In that case the {dict} is passed in as "self". Example: >
3631 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003632 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003633 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003634 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003635 let context = {"name": "example"}
3636 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003637 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003638 call Func() " will echo: called for example
3639< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003640 arguments, these two are equivalent, if Callback() is defined
3641 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003642 let Func = function('Callback', context)
3643 let Func = context.Callback
3644
3645< The argument list and the Dictionary can be combined: >
3646 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003647 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003648 let context = {"name": "example"}
3649 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003650 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003651 call Func(500)
3652< Invokes the function as with: >
3653 call context.Callback('one', 500)
3654<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003655 Returns 0 on error.
3656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003657 Can also be used as a |method|: >
3658 GetFuncname()->function([arg])
3659
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003660<
3661 Return type: func(...): any or |Number| on error
3662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003663
3664garbagecollect([{atexit}]) *garbagecollect()*
3665 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3666 that have circular references.
3667
3668 There is hardly ever a need to invoke this function, as it is
3669 automatically done when Vim runs out of memory or is waiting
3670 for the user to press a key after 'updatetime'. Items without
3671 circular references are always freed when they become unused.
3672 This is useful if you have deleted a very big |List| and/or
3673 |Dictionary| with circular references in a script that runs
3674 for a long time.
3675
3676 When the optional {atexit} argument is one, garbage
3677 collection will also be done when exiting Vim, if it wasn't
3678 done before. This is useful when checking for memory leaks.
3679
3680 The garbage collection is not done immediately but only when
3681 it's safe to perform. This is when waiting for the user to
3682 type a character. To force garbage collection immediately use
3683 |test_garbagecollect_now()|.
3684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003685 Return type: |String|
3686
3687
LemonBoy48b7d052024-07-09 18:24:59 +02003688get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003689 Get item {idx} from |List| {list}. When this item is not
3690 available return {default}. Return zero when {default} is
3691 omitted.
3692 Preferably used as a |method|: >
3693 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003694<
3695 Return type: any, depending on {list}
3696
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003697get({tuple}, {idx} [, {default}]) *get()-tuple*
3698 Get item {idx} from |Tuple| {tuple}. When this item is not
3699 available return {default}. Return zero when {default} is
3700 omitted.
3701 Preferably used as a |method|: >
3702 mytuple->get(idx)
3703<
3704 Return type: any, depending on {tuple}
3705
LemonBoy48b7d052024-07-09 18:24:59 +02003706get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003707 Get byte {idx} from |Blob| {blob}. When this byte is not
3708 available return {default}. Return -1 when {default} is
3709 omitted.
3710 Preferably used as a |method|: >
3711 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003712<
3713 Return type: |Number|
3714
LemonBoy48b7d052024-07-09 18:24:59 +02003715get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003716 Get item with key {key} from |Dictionary| {dict}. When this
3717 item is not available return {default}. Return zero when
3718 {default} is omitted. Useful example: >
3719 let val = get(g:, 'var_name', 'default')
3720< This gets the value of g:var_name if it exists, and uses
3721 'default' when it does not exist.
3722 Preferably used as a |method|: >
3723 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003724<
h-east84ac2122024-06-17 18:12:30 +02003725 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003726
LemonBoy48b7d052024-07-09 18:24:59 +02003727get({func}, {what}) *get()-func*
3728 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003729 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003730 "name" The function name
3731 "func" The function
3732 "dict" The dictionary
3733 "args" The list with arguments
3734 "arity" A dictionary with information about the number of
3735 arguments accepted by the function (minus the
3736 {arglist}) with the following fields:
3737 required the number of positional arguments
3738 optional the number of optional arguments,
3739 in addition to the required ones
3740 varargs |TRUE| if the function accepts a
3741 variable number of arguments |...|
3742
3743 Note: There is no error, if the {arglist} of
3744 the Funcref contains more arguments than the
3745 Funcref expects, it's not validated.
3746
Bram Moolenaar016188f2022-06-06 20:52:59 +01003747 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003749 Preferably used as a |method|: >
3750 myfunc->get(what)
3751<
LemonBoy48b7d052024-07-09 18:24:59 +02003752 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003754 *getbufinfo()*
3755getbufinfo([{buf}])
3756getbufinfo([{dict}])
3757 Get information about buffers as a List of Dictionaries.
3758
3759 Without an argument information about all the buffers is
3760 returned.
3761
3762 When the argument is a |Dictionary| only the buffers matching
3763 the specified criteria are returned. The following keys can
3764 be specified in {dict}:
3765 buflisted include only listed buffers.
3766 bufloaded include only loaded buffers.
3767 bufmodified include only modified buffers.
3768
3769 Otherwise, {buf} specifies a particular buffer to return
3770 information for. For the use of {buf}, see |bufname()|
3771 above. If the buffer is found the returned List has one item.
3772 Otherwise the result is an empty list.
3773
3774 Each returned List item is a dictionary with the following
3775 entries:
3776 bufnr Buffer number.
3777 changed TRUE if the buffer is modified.
3778 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003779 command TRUE if the buffer belongs to the
3780 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003781 hidden TRUE if the buffer is hidden.
3782 lastused Timestamp in seconds, like
3783 |localtime()|, when the buffer was
3784 last used.
3785 {only with the |+viminfo| feature}
3786 listed TRUE if the buffer is listed.
3787 lnum Line number used for the buffer when
3788 opened in the current window.
3789 Only valid if the buffer has been
3790 displayed in the window in the past.
3791 If you want the line number of the
3792 last known cursor position in a given
3793 window, use |line()|: >
3794 :echo line('.', {winid})
3795<
3796 linecount Number of lines in the buffer (only
3797 valid when loaded)
3798 loaded TRUE if the buffer is loaded.
3799 name Full path to the file in the buffer.
3800 signs List of signs placed in the buffer.
3801 Each list item is a dictionary with
3802 the following fields:
3803 id sign identifier
3804 lnum line number
3805 name sign name
3806 variables A reference to the dictionary with
3807 buffer-local variables.
3808 windows List of |window-ID|s that display this
3809 buffer
3810 popups List of popup |window-ID|s that
3811 display this buffer
3812
3813 Examples: >
3814 for buf in getbufinfo()
3815 echo buf.name
3816 endfor
3817 for buf in getbufinfo({'buflisted':1})
3818 if buf.changed
3819 ....
3820 endif
3821 endfor
3822<
3823 To get buffer-local options use: >
3824 getbufvar({bufnr}, '&option_name')
3825<
3826 Can also be used as a |method|: >
3827 GetBufnr()->getbufinfo()
3828<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003829 Return type: list<dict<any>>
3830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003831
3832 *getbufline()*
3833getbufline({buf}, {lnum} [, {end}])
3834 Return a |List| with the lines starting from {lnum} to {end}
3835 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003836 |List| with only the line {lnum} is returned. See
3837 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003838
3839 For the use of {buf}, see |bufname()| above.
3840
3841 For {lnum} and {end} "$" can be used for the last line of the
3842 buffer. Otherwise a number must be used.
3843
3844 When {lnum} is smaller than 1 or bigger than the number of
3845 lines in the buffer, an empty |List| is returned.
3846
3847 When {end} is greater than the number of lines in the buffer,
3848 it is treated as {end} is set to the number of lines in the
3849 buffer. When {end} is before {lnum} an empty |List| is
3850 returned.
3851
3852 This function works only for loaded buffers. For unloaded and
3853 non-existing buffers, an empty |List| is returned.
3854
3855 Example: >
3856 :let lines = getbufline(bufnr("myfile"), 1, "$")
3857
3858< Can also be used as a |method|: >
3859 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003861 Return type: list<string>
3862
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003863 *getbufoneline()*
3864getbufoneline({buf}, {lnum})
3865 Just like `getbufline()` but only get one line and return it
3866 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003867
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003868 Return type: |String|
3869
3870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003871getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3872 The result is the value of option or local buffer variable
3873 {varname} in buffer {buf}. Note that the name without "b:"
3874 must be used.
3875 The {varname} argument is a string.
3876 When {varname} is empty returns a |Dictionary| with all the
3877 buffer-local variables.
3878 When {varname} is equal to "&" returns a |Dictionary| with all
3879 the buffer-local options.
3880 Otherwise, when {varname} starts with "&" returns the value of
3881 a buffer-local option.
3882 This also works for a global or buffer-local option, but it
3883 doesn't work for a global variable, window-local variable or
3884 window-local option.
3885 For the use of {buf}, see |bufname()| above.
3886 When the buffer or variable doesn't exist {def} or an empty
3887 string is returned, there is no error message.
3888 Examples: >
3889 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003890 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003891
3892< Can also be used as a |method|: >
3893 GetBufnr()->getbufvar(varname)
3894<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003895 Return type: any, depending on {varname}
3896
3897
mikoto20001083cae2024-11-11 21:24:14 +01003898getcellpixels() *getcellpixels()*
3899 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003900 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003901
3902 Only works on Unix (terminal and gVim) and Windows (gVim only).
3903 Returns [] on other systems or on failure.
3904 Note that there could be variations across different terminals.
3905 On macOS, system Terminal.app returns sizes in points (before
3906 Retina scaling), whereas third-party terminals return raw pixel
3907 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003908
mikoto2000de094dc2024-11-14 22:13:48 +01003909 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003910
3911
Kota Kato66bb9ae2023-01-17 18:31:56 +00003912getcellwidths() *getcellwidths()*
3913 Returns a |List| of cell widths of character ranges overridden
3914 by |setcellwidths()|. The format is equal to the argument of
3915 |setcellwidths()|. If no character ranges have their cell
3916 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003917
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003918 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003919
3920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003921getchangelist([{buf}]) *getchangelist()*
3922 Returns the |changelist| for the buffer {buf}. For the use
3923 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3924 exist, an empty list is returned.
3925
3926 The returned list contains two entries: a list with the change
3927 locations and the current position in the list. Each
3928 entry in the change list is a dictionary with the following
3929 entries:
3930 col column number
3931 coladd column offset for 'virtualedit'
3932 lnum line number
3933 If buffer {buf} is the current buffer, then the current
3934 position refers to the position in the list. For other
3935 buffers, it is set to the length of the list.
3936
3937 Can also be used as a |method|: >
3938 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003939<
3940 Return type: list<any>
3941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003942
zeertzjqe0a2ab32025-02-02 09:14:35 +01003943getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003944 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003945 If {expr} is omitted or is -1, wait until a character is
3946 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003947 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003948 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003949 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003950 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003951 If you prefer always getting a string use |getcharstr()|, or
3952 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003953
Doug Kearns9cd9e752024-04-07 17:42:17 +02003954 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003956 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003957 Otherwise a String is returned with the encoded character.
3958 For a special key it's a String with a sequence of bytes
3959 starting with 0x80 (decimal: 128). This is the same value as
3960 the String "\<Key>", e.g., "\<Left>". The returned value is
3961 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01003962 that is not included in the character. |keytrans()| can also
3963 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003964
Doug Kearns9cd9e752024-04-07 17:42:17 +02003965 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003966 while Vim waits to see if this is the start of an escape
3967 sequence.
3968
Doug Kearns9cd9e752024-04-07 17:42:17 +02003969 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003970 one-byte character it is the character itself as a number.
3971 Use nr2char() to convert it to a String.
3972
3973 Use getcharmod() to obtain any additional modifiers.
3974
zeertzjqe0a2ab32025-02-02 09:14:35 +01003975 The optional argument {opts} is a Dict and supports the
3976 following items:
3977
zeertzjqedf0f7d2025-02-02 19:01:01 +01003978 cursor A String specifying cursor behavior
3979 when waiting for a character.
3980 "hide": hide the cursor.
3981 "keep": keep current cursor unchanged.
3982 "msg": move cursor to message area.
3983 (default: "msg")
3984
zeertzjqe0a2ab32025-02-02 09:14:35 +01003985 number If |TRUE|, return a Number when getting
3986 a single character.
3987 If |FALSE|, the return value is always
3988 converted to a String, and an empty
3989 String (instead of 0) is returned when
3990 no character is available.
3991 (default: |TRUE|)
3992
3993 simplify If |TRUE|, include modifiers in the
3994 character if possible. E.g., return
3995 the same value for CTRL-I and <Tab>.
3996 If |FALSE|, don't include modifiers in
3997 the character.
3998 (default: |TRUE|)
3999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004000 When the user clicks a mouse button, the mouse event will be
4001 returned. The position can then be found in |v:mouse_col|,
4002 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
4003 |getmousepos()| can also be used. Mouse move events will be
4004 ignored.
4005 This example positions the mouse as it would normally happen: >
4006 let c = getchar()
4007 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004008 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004009 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004010 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004011 endif
4012<
4013 When using bracketed paste only the first character is
4014 returned, the rest of the pasted text is dropped.
4015 |xterm-bracketed-paste|.
4016
4017 There is no prompt, you will somehow have to make clear to the
4018 user that a character has to be typed. The screen is not
4019 redrawn, e.g. when resizing the window. When using a popup
4020 window it should work better with a |popup-filter|.
4021
4022 There is no mapping for the character.
4023 Key codes are replaced, thus when the user presses the <Del>
4024 key you get the code for the <Del> key, not the raw character
4025 sequence. Examples: >
4026 getchar() == "\<Del>"
4027 getchar() == "\<S-Left>"
4028< This example redefines "f" to ignore case: >
4029 :nmap f :call FindChar()<CR>
4030 :function FindChar()
4031 : let c = nr2char(getchar())
4032 : while col('.') < col('$') - 1
4033 : normal l
4034 : if getline('.')[col('.') - 1] ==? c
4035 : break
4036 : endif
4037 : endwhile
4038 :endfunction
4039<
4040 You may also receive synthetic characters, such as
4041 |<CursorHold>|. Often you will want to ignore this and get
4042 another character: >
4043 :function GetKey()
4044 : let c = getchar()
4045 : while c == "\<CursorHold>"
4046 : let c = getchar()
4047 : endwhile
4048 : return c
4049 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004050<
4051 Return type: |Number| or |String|
4052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004053
4054getcharmod() *getcharmod()*
4055 The result is a Number which is the state of the modifiers for
4056 the last obtained character with getchar() or in another way.
4057 These values are added together:
4058 2 shift
4059 4 control
4060 8 alt (meta)
4061 16 meta (when it's different from ALT)
4062 32 mouse double click
4063 64 mouse triple click
4064 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004065 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004066 Only the modifiers that have not been included in the
4067 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004068 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004070 Return type: |Number|
4071
4072
4073getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004074 Get the position for String {expr}. Same as |getpos()| but the
4075 column number in the returned List is a character index
4076 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004077 If |getpos()| returns a very large column number, equal to
4078 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004079 of the last character.
4080
4081 Example:
4082 With the cursor on '세' in line 5 with text "여보세요": >
4083 getcharpos('.') returns [0, 5, 3, 0]
4084 getpos('.') returns [0, 5, 7, 0]
4085<
4086 Can also be used as a |method|: >
4087 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004088<
4089 Return type: list<number>
4090
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004091
4092getcharsearch() *getcharsearch()*
4093 Return the current character search information as a {dict}
4094 with the following entries:
4095
4096 char character previously used for a character
4097 search (|t|, |f|, |T|, or |F|); empty string
4098 if no character search has been performed
4099 forward direction of character search; 1 for forward,
4100 0 for backward
4101 until type of character search; 1 for a |t| or |T|
4102 character search, 0 for an |f| or |F|
4103 character search
4104
4105 This can be useful to always have |;| and |,| search
4106 forward/backward regardless of the direction of the previous
4107 character search: >
4108 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4109 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4110< Also see |setcharsearch()|.
4111
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004112 Return type: dict<any>
4113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004114
zeertzjqe0a2ab32025-02-02 09:14:35 +01004115getcharstr([{expr} [, {opts}]]) *getcharstr()*
4116 The same as |getchar()|, except that this always returns a
4117 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004118
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004119 Return type: |String|
4120
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004121getcmdcomplpat() *getcmdcomplpat()*
4122 Return completion pattern of the current command-line.
4123 Only works when the command line is being edited, thus
4124 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4125 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4126 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4127 Returns an empty string when completion is not defined.
4128
4129 Return type: |String|
4130
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004131
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004132getcmdcompltype() *getcmdcompltype()*
4133 Return the type of the current command-line completion.
4134 Only works when the command line is being edited, thus
4135 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004136 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004137 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004138 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004139 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004140
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004141 Return type: |String|
4142
4143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004144getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004145 Return the current command-line input. Only works when the
4146 command line is being edited, thus requires use of
4147 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004148 Example: >
4149 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004150< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4151 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004152 Returns an empty string when entering a password or using
4153 |inputsecret()|.
4154
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004155 Return type: |String|
4156
4157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004158getcmdpos() *getcmdpos()*
4159 Return the position of the cursor in the command line as a
4160 byte count. The first column is 1.
4161 Only works when editing the command line, thus requires use of
4162 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4163 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004164 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4165 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004166
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004167 Return type: |Number|
4168
4169
Shougo Matsushita69084282024-09-23 20:34:47 +02004170getcmdprompt() *getcmdprompt()*
4171 Return the current command-line prompt when using functions
4172 like |input()| or |confirm()|.
4173 Only works when the command line is being edited, thus
4174 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4175 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4176 |setcmdpos()| and |setcmdline()|.
4177
4178 Return type: |String|
4179
4180
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004181getcmdscreenpos() *getcmdscreenpos()*
4182 Return the screen position of the cursor in the command line
4183 as a byte count. The first column is 1.
4184 Instead of |getcmdpos()|, it adds the prompt position.
4185 Only works when editing the command line, thus requires use of
4186 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4187 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004188 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4189 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004190
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004191 Return type: |Number|
4192
4193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004194getcmdtype() *getcmdtype()*
4195 Return the current command-line type. Possible return values
4196 are:
4197 : normal Ex command
4198 > debug mode command |debug-mode|
4199 / forward search command
4200 ? backward search command
4201 @ |input()| command
4202 - |:insert| or |:append| command
4203 = |i_CTRL-R_=|
4204 Only works when editing the command line, thus requires use of
4205 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4206 Returns an empty string otherwise.
4207 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004209 Return type: |String|
4210
4211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004212getcmdwintype() *getcmdwintype()*
4213 Return the current |command-line-window| type. Possible return
4214 values are the same as |getcmdtype()|. Returns an empty string
4215 when not in the command-line window.
4216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004217 Return type: |String|
4218
4219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004220getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4221 Return a list of command-line completion matches. The String
4222 {type} argument specifies what for. The following completion
4223 types are supported:
4224
4225 arglist file names in argument list
4226 augroup autocmd groups
4227 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004228 behave |:behave| suboptions
4229 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004230 color color schemes
4231 command Ex command
4232 cmdline |cmdline-completion| result
4233 compiler compilers
4234 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004235 custom,{func} custom completion, defined via {func}
4236 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004237 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004238 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004239 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004240 environment environment variable names
4241 event autocommand events
4242 expression Vim expression
4243 file file and directory names
4244 file_in_path file and directory names in |'path'|
4245 filetype filetype names |'filetype'|
4246 function function name
4247 help help subjects
4248 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004249 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004250 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004251 locale locale names (as output of locale -a)
4252 mapclear buffer argument
4253 mapping mapping name
4254 menu menus
4255 messages |:messages| suboptions
4256 option options
4257 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004258 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004259 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004260 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004261 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004262 sign |:sign| suboptions
4263 syntax syntax file names |'syntax'|
4264 syntime |:syntime| suboptions
4265 tag tags
4266 tag_listfiles tags, file names
4267 user user names
4268 var user variables
4269
4270 If {pat} is an empty string, then all the matches are
4271 returned. Otherwise only items matching {pat} are returned.
4272 See |wildcards| for the use of special characters in {pat}.
4273
4274 If the optional {filtered} flag is set to 1, then 'wildignore'
4275 is applied to filter the results. Otherwise all the matches
4276 are returned. The 'wildignorecase' option always applies.
4277
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004278 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4279 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004280 regular expression matching is used. Thus this function
4281 follows the user preference, what happens on the command line.
4282 If you do not want this you can make 'wildoptions' empty
4283 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004285 If {type} is "cmdline", then the |cmdline-completion| result is
4286 returned. For example, to complete the possible values after
4287 a ":call" command: >
4288 echo getcompletion('call ', 'cmdline')
4289<
4290 If there are no matches, an empty list is returned. An
4291 invalid value for {type} produces an error.
4292
4293 Can also be used as a |method|: >
4294 GetPattern()->getcompletion('color')
4295<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004296 Return type: list<string>
4297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004298 *getcurpos()*
4299getcurpos([{winid}])
4300 Get the position of the cursor. This is like getpos('.'), but
4301 includes an extra "curswant" item in the list:
4302 [0, lnum, col, off, curswant] ~
4303 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004304 cursor vertically. After |$| command it will be a very large
4305 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004306 |getpos()|.
4307 The first "bufnum" item is always zero. The byte position of
4308 the cursor is returned in 'col'. To get the character
4309 position, use |getcursorcharpos()|.
4310
4311 The optional {winid} argument can specify the window. It can
4312 be the window number or the |window-ID|. The last known
4313 cursor position is returned, this may be invalid for the
4314 current value of the buffer if it is not the current window.
4315 If {winid} is invalid a list with zeroes is returned.
4316
4317 This can be used to save and restore the cursor position: >
4318 let save_cursor = getcurpos()
4319 MoveTheCursorAround
4320 call setpos('.', save_cursor)
4321< Note that this only works within the window. See
4322 |winrestview()| for restoring more state.
4323
4324 Can also be used as a |method|: >
4325 GetWinid()->getcurpos()
4326<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004327 Return type: list<number>
4328
4329
4330getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004331 Same as |getcurpos()| but the column number in the returned
4332 List is a character index instead of a byte index.
4333
4334 Example:
4335 With the cursor on '보' in line 3 with text "여보세요": >
4336 getcursorcharpos() returns [0, 3, 2, 0, 3]
4337 getcurpos() returns [0, 3, 4, 0, 3]
4338<
4339 Can also be used as a |method|: >
4340 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004341<
4342 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004343
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004344
4345getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004346 The result is a String, which is the name of the current
4347 working directory. 'autochdir' is ignored.
4348
4349 With {winnr} return the local current directory of this window
4350 in the current tab page. {winnr} can be the window number or
4351 the |window-ID|.
4352 If {winnr} is -1 return the name of the global working
4353 directory. See also |haslocaldir()|.
4354
4355 With {winnr} and {tabnr} return the local current directory of
4356 the window in the specified tab page. If {winnr} is -1 return
4357 the working directory of the tabpage.
4358 If {winnr} is zero use the current window, if {tabnr} is zero
4359 use the current tabpage.
4360 Without any arguments, return the actual working directory of
4361 the current window.
4362 Return an empty string if the arguments are invalid.
4363
4364 Examples: >
4365 " Get the working directory of the current window
4366 :echo getcwd()
4367 :echo getcwd(0)
4368 :echo getcwd(0, 0)
4369 " Get the working directory of window 3 in tabpage 2
4370 :echo getcwd(3, 2)
4371 " Get the global working directory
4372 :echo getcwd(-1)
4373 " Get the working directory of tabpage 3
4374 :echo getcwd(-1, 3)
4375 " Get the working directory of current tabpage
4376 :echo getcwd(-1, 0)
4377
4378< Can also be used as a |method|: >
4379 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004380<
4381 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004382
4383getenv({name}) *getenv()*
4384 Return the value of environment variable {name}. The {name}
4385 argument is a string, without a leading '$'. Example: >
4386 myHome = getenv('HOME')
4387
4388< When the variable does not exist |v:null| is returned. That
4389 is different from a variable set to an empty string, although
4390 some systems interpret the empty value as the variable being
4391 deleted. See also |expr-env|.
4392
4393 Can also be used as a |method|: >
4394 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004395<
4396 Return type: |String| or |Number|
4397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004398
4399getfontname([{name}]) *getfontname()*
4400 Without an argument returns the name of the normal font being
4401 used. Like what is used for the Normal highlight group
4402 |hl-Normal|.
4403 With an argument a check is done whether String {name} is a
4404 valid font name. If not then an empty string is returned.
4405 Otherwise the actual font name is returned, or {name} if the
4406 GUI does not support obtaining the real name.
4407 Only works when the GUI is running, thus not in your vimrc or
4408 gvimrc file. Use the |GUIEnter| autocommand to use this
4409 function just after the GUI has started.
4410 Note that the GTK GUI accepts any font name, thus checking for
4411 a valid name does not work.
4412
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004413 Return type: |String|
4414
4415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004416getfperm({fname}) *getfperm()*
4417 The result is a String, which is the read, write, and execute
4418 permissions of the given file {fname}.
4419 If {fname} does not exist or its directory cannot be read, an
4420 empty string is returned.
4421 The result is of the form "rwxrwxrwx", where each group of
4422 "rwx" flags represent, in turn, the permissions of the owner
4423 of the file, the group the file belongs to, and other users.
4424 If a user does not have a given permission the flag for this
4425 is replaced with the string "-". Examples: >
4426 :echo getfperm("/etc/passwd")
4427 :echo getfperm(expand("~/.vimrc"))
4428< This will hopefully (from a security point of view) display
4429 the string "rw-r--r--" or even "rw-------".
4430
4431 Can also be used as a |method|: >
4432 GetFilename()->getfperm()
4433<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004434 Return type: |String|
4435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004436 For setting permissions use |setfperm()|.
4437
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004439getfsize({fname}) *getfsize()*
4440 The result is a Number, which is the size in bytes of the
4441 given file {fname}.
4442 If {fname} is a directory, 0 is returned.
4443 If the file {fname} can't be found, -1 is returned.
4444 If the size of {fname} is too big to fit in a Number then -2
4445 is returned.
4446
4447 Can also be used as a |method|: >
4448 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004449<
4450 Return type: |Number|
4451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004452
4453getftime({fname}) *getftime()*
4454 The result is a Number, which is the last modification time of
4455 the given file {fname}. The value is measured as seconds
4456 since 1st Jan 1970, and may be passed to strftime(). See also
4457 |localtime()| and |strftime()|.
4458 If the file {fname} can't be found -1 is returned.
4459
4460 Can also be used as a |method|: >
4461 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004462<
4463 Return type: |Number|
4464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004465
4466getftype({fname}) *getftype()*
4467 The result is a String, which is a description of the kind of
4468 file of the given file {fname}.
4469 If {fname} does not exist an empty string is returned.
4470 Here is a table over different kinds of files and their
4471 results:
4472 Normal file "file"
4473 Directory "dir"
4474 Symbolic link "link"
4475 Block device "bdev"
4476 Character device "cdev"
4477 Socket "socket"
4478 FIFO "fifo"
4479 All other "other"
4480 Example: >
4481 getftype("/home")
4482< Note that a type such as "link" will only be returned on
4483 systems that support it. On some systems only "dir" and
4484 "file" are returned. On MS-Windows a symbolic link to a
4485 directory returns "dir" instead of "link".
4486
4487 Can also be used as a |method|: >
4488 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004489<
4490 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004491
4492getimstatus() *getimstatus()*
4493 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004494 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004495 See 'imstatusfunc'.
4496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004497 Return type: |Number|
4498
4499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004500getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4501 Returns the |jumplist| for the specified window.
4502
4503 Without arguments use the current window.
4504 With {winnr} only use this window in the current tab page.
4505 {winnr} can also be a |window-ID|.
4506 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004507 page. If {winnr} or {tabnr} is invalid, an empty list is
4508 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004509
4510 The returned list contains two entries: a list with the jump
4511 locations and the last used jump position number in the list.
4512 Each entry in the jump location list is a dictionary with
4513 the following entries:
4514 bufnr buffer number
4515 col column number
4516 coladd column offset for 'virtualedit'
4517 filename filename if available
4518 lnum line number
4519
4520 Can also be used as a |method|: >
4521 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004522<
4523 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004525 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004526getline({lnum} [, {end}])
4527 Without {end} the result is a String, which is line {lnum}
4528 from the current buffer. Example: >
4529 getline(1)
4530< When {lnum} is a String that doesn't start with a
4531 digit, |line()| is called to translate the String into a Number.
4532 To get the line under the cursor: >
4533 getline(".")
4534< When {lnum} is a number smaller than 1 or bigger than the
4535 number of lines in the buffer, an empty string is returned.
4536
4537 When {end} is given the result is a |List| where each item is
4538 a line from the current buffer in the range {lnum} to {end},
4539 including line {end}.
4540 {end} is used in the same way as {lnum}.
4541 Non-existing lines are silently omitted.
4542 When {end} is before {lnum} an empty |List| is returned.
4543 Example: >
4544 :let start = line('.')
4545 :let end = search("^$") - 1
4546 :let lines = getline(start, end)
4547
4548< Can also be used as a |method|: >
4549 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004550<
4551 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004552
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004553 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004554 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004555
4556getloclist({nr} [, {what}]) *getloclist()*
4557 Returns a |List| with all the entries in the location list for
4558 window {nr}. {nr} can be the window number or the |window-ID|.
4559 When {nr} is zero the current window is used.
4560
4561 For a location list window, the displayed location list is
4562 returned. For an invalid window number {nr}, an empty list is
4563 returned. Otherwise, same as |getqflist()|.
4564
4565 If the optional {what} dictionary argument is supplied, then
4566 returns the items listed in {what} as a dictionary. Refer to
4567 |getqflist()| for the supported items in {what}.
4568
4569 In addition to the items supported by |getqflist()| in {what},
4570 the following item is supported by |getloclist()|:
4571
4572 filewinid id of the window used to display files
4573 from the location list. This field is
4574 applicable only when called from a
4575 location list window. See
4576 |location-list-file-window| for more
4577 details.
4578
4579 Returns a |Dictionary| with default values if there is no
4580 location list for the window {nr}.
4581 Returns an empty Dictionary if window {nr} does not exist.
4582
4583 Examples (See also |getqflist-examples|): >
4584 :echo getloclist(3, {'all': 0})
4585 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004586<
4587 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004588
4589
4590getmarklist([{buf}]) *getmarklist()*
4591 Without the {buf} argument returns a |List| with information
4592 about all the global marks. |mark|
4593
4594 If the optional {buf} argument is specified, returns the
4595 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004596 see |bufname()|. If {buf} is invalid, an empty list is
4597 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004598
4599 Each item in the returned List is a |Dict| with the following:
4600 mark name of the mark prefixed by "'"
4601 pos a |List| with the position of the mark:
4602 [bufnum, lnum, col, off]
4603 Refer to |getpos()| for more information.
4604 file file name
4605
4606 Refer to |getpos()| for getting information about a specific
4607 mark.
4608
4609 Can also be used as a |method|: >
4610 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004611<
4612 Return type: list<dict<any>> or list<any>
4613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004614
4615getmatches([{win}]) *getmatches()*
4616 Returns a |List| with all matches previously defined for the
4617 current window by |matchadd()| and the |:match| commands.
4618 |getmatches()| is useful in combination with |setmatches()|,
4619 as |setmatches()| can restore a list of matches saved by
4620 |getmatches()|.
4621 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004622 window ID instead of the current window. If {win} is invalid,
4623 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004624 Example: >
4625 :echo getmatches()
4626< [{'group': 'MyGroup1', 'pattern': 'TODO',
4627 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4628 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4629 :let m = getmatches()
4630 :call clearmatches()
4631 :echo getmatches()
4632< [] >
4633 :call setmatches(m)
4634 :echo getmatches()
4635< [{'group': 'MyGroup1', 'pattern': 'TODO',
4636 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4637 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4638 :unlet m
4639<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004640 Return type: list<dict<any>> or list<any>
4641
4642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004643getmousepos() *getmousepos()*
4644 Returns a |Dictionary| with the last known position of the
4645 mouse. This can be used in a mapping for a mouse click or in
4646 a filter of a popup window. The items are:
4647 screenrow screen row
4648 screencol screen column
4649 winid Window ID of the click
4650 winrow row inside "winid"
4651 wincol column inside "winid"
4652 line text line inside "winid"
4653 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004654 coladd offset (in screen columns) from the
4655 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004656 All numbers are 1-based.
4657
4658 If not over a window, e.g. when in the command line, then only
4659 "screenrow" and "screencol" are valid, the others are zero.
4660
4661 When on the status line below a window or the vertical
4662 separator right of a window, the "line" and "column" values
4663 are zero.
4664
4665 When the position is after the text then "column" is the
4666 length of the text in bytes plus one.
4667
4668 If the mouse is over a popup window then that window is used.
4669
4670 When using |getchar()| the Vim variables |v:mouse_lnum|,
4671 |v:mouse_col| and |v:mouse_winid| also provide these values.
4672
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004673 Return type: dict<number>
4674
4675
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004676getmouseshape() *getmouseshape()*
4677 Returns the name of the currently showing mouse pointer.
4678 When the |+mouseshape| feature is not supported or the shape
4679 is unknown an empty string is returned.
4680 This function is mainly intended for testing.
4681
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004682 Return type: |String|
4683
4684
4685getpid() *getpid()*
4686 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004687 On Unix and MS-Windows this is a unique number, until Vim
4688 exits.
4689
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004690 Return type: |Number|
4691
4692
4693getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004694 Get the position for String {expr}.
4695 The accepted values for {expr} are: *E1209*
4696 . The cursor position.
4697 $ The last line in the current buffer.
4698 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004699 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004700 w0 First line visible in current window (one if the
4701 display isn't updated, e.g. in silent Ex mode).
4702 w$ Last line visible in current window (this is one
4703 less than "w0" if no lines are visible).
4704 v When not in Visual mode, returns the cursor
4705 position. In Visual mode, returns the other end
4706 of the Visual area. A good way to think about
4707 this is that in Visual mode "v" and "." complement
4708 each other. While "." refers to the cursor
4709 position, "v" refers to where |v_o| would move the
4710 cursor. As a result, you can use "v" and "."
4711 together to work on all of a selection in
4712 characterwise Visual mode. If the cursor is at
4713 the end of a characterwise Visual area, "v" refers
4714 to the start of the same Visual area. And if the
4715 cursor is at the start of a characterwise Visual
4716 area, "v" refers to the end of the same Visual
4717 area. "v" differs from |'<| and |'>| in that it's
4718 updated right away.
4719 Note that a mark in another file can be used. The line number
4720 then applies to another buffer.
4721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004722 The result is a |List| with four numbers:
4723 [bufnum, lnum, col, off]
4724 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4725 is the buffer number of the mark.
4726 "lnum" and "col" are the position in the buffer. The first
4727 column is 1.
4728 The "off" number is zero, unless 'virtualedit' is used. Then
4729 it is the offset in screen columns from the start of the
4730 character. E.g., a position within a <Tab> or after the last
4731 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004732
4733 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004734 The column number in the returned List is the byte position
4735 within the line. To get the character position in the line,
4736 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004737
4738 Note that for '< and '> Visual mode matters: when it is "V"
4739 (visual line mode) the column of '< is zero and the column of
4740 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004741 A very large column number equal to |v:maxcol| can be returned,
4742 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004743 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004745 This can be used to save and restore the position of a mark: >
4746 let save_a_mark = getpos("'a")
4747 ...
4748 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004749<
4750 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004751
4752 Can also be used as a |method|: >
4753 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004754<
4755 Return type: list<number>
4756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004757
4758getqflist([{what}]) *getqflist()*
4759 Returns a |List| with all the current quickfix errors. Each
4760 list item is a dictionary with these entries:
4761 bufnr number of buffer that has the file name, use
4762 bufname() to get the name
4763 module module name
4764 lnum line number in the buffer (first line is 1)
4765 end_lnum
4766 end of line number if the item is multiline
4767 col column number (first column is 1)
4768 end_col end of column number if the item has range
4769 vcol |TRUE|: "col" is visual column
4770 |FALSE|: "col" is byte index
4771 nr error number
h-east84ac2122024-06-17 18:12:30 +02004772 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004773 text description of the error
4774 type type of the error, 'E', '1', etc.
4775 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004776 user_data
4777 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004778 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004779
4780 When there is no error list or it's empty, an empty list is
4781 returned. Quickfix list entries with a non-existing buffer
4782 number are returned with "bufnr" set to zero (Note: some
4783 functions accept buffer number zero for the alternate buffer,
4784 you may need to explicitly check for zero).
4785
4786 Useful application: Find pattern matches in multiple files and
4787 do something with them: >
4788 :vimgrep /theword/jg *.c
4789 :for d in getqflist()
4790 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4791 :endfor
4792<
4793 If the optional {what} dictionary argument is supplied, then
4794 returns only the items listed in {what} as a dictionary. The
4795 following string items are supported in {what}:
4796 changedtick get the total number of changes made
4797 to the list |quickfix-changedtick|
4798 context get the |quickfix-context|
4799 efm errorformat to use when parsing "lines". If
4800 not present, then the 'errorformat' option
4801 value is used.
4802 id get information for the quickfix list with
4803 |quickfix-ID|; zero means the id for the
4804 current list or the list specified by "nr"
4805 idx get information for the quickfix entry at this
4806 index in the list specified by 'id' or 'nr'.
4807 If set to zero, then uses the current entry.
4808 See |quickfix-index|
4809 items quickfix list entries
4810 lines parse a list of lines using 'efm' and return
4811 the resulting entries. Only a |List| type is
4812 accepted. The current quickfix list is not
4813 modified. See |quickfix-parse|.
4814 nr get information for this quickfix list; zero
4815 means the current quickfix list and "$" means
4816 the last quickfix list
4817 qfbufnr number of the buffer displayed in the quickfix
4818 window. Returns 0 if the quickfix buffer is
4819 not present. See |quickfix-buffer|.
4820 size number of entries in the quickfix list
4821 title get the list title |quickfix-title|
4822 winid get the quickfix |window-ID|
4823 all all of the above quickfix properties
4824 Non-string items in {what} are ignored. To get the value of a
4825 particular item, set it to zero.
4826 If "nr" is not present then the current quickfix list is used.
4827 If both "nr" and a non-zero "id" are specified, then the list
4828 specified by "id" is used.
4829 To get the number of lists in the quickfix stack, set "nr" to
4830 "$" in {what}. The "nr" value in the returned dictionary
4831 contains the quickfix stack size.
4832 When "lines" is specified, all the other items except "efm"
4833 are ignored. The returned dictionary contains the entry
4834 "items" with the list of entries.
4835
4836 The returned dictionary contains the following entries:
4837 changedtick total number of changes made to the
4838 list |quickfix-changedtick|
4839 context quickfix list context. See |quickfix-context|
4840 If not present, set to "".
4841 id quickfix list ID |quickfix-ID|. If not
4842 present, set to 0.
4843 idx index of the quickfix entry in the list. If not
4844 present, set to 0.
4845 items quickfix list entries. If not present, set to
4846 an empty list.
4847 nr quickfix list number. If not present, set to 0
4848 qfbufnr number of the buffer displayed in the quickfix
4849 window. If not present, set to 0.
4850 size number of entries in the quickfix list. If not
4851 present, set to 0.
4852 title quickfix list title text. If not present, set
4853 to "".
4854 winid quickfix |window-ID|. If not present, set to 0
4855
4856 Examples (See also |getqflist-examples|): >
4857 :echo getqflist({'all': 1})
4858 :echo getqflist({'nr': 2, 'title': 1})
4859 :echo getqflist({'lines' : ["F1:10:L10"]})
4860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004861 Return type: list<dict<any>> or list<any>
4862
4863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004864getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4865 The result is a String, which is the contents of register
4866 {regname}. Example: >
4867 :let cliptext = getreg('*')
4868< When register {regname} was not set the result is an empty
4869 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004870 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004871
4872 getreg('=') returns the last evaluated value of the expression
4873 register. (For use in maps.)
4874 getreg('=', 1) returns the expression itself, so that it can
4875 be restored with |setreg()|. For other registers the extra
4876 argument is ignored, thus you can always give it.
4877
4878 If {list} is present and |TRUE|, the result type is changed
4879 to |List|. Each list item is one text line. Use it if you care
4880 about zero bytes possibly present inside register: without
4881 third argument both NLs and zero bytes are represented as NLs
4882 (see |NL-used-for-Nul|).
4883 When the register was not set an empty list is returned.
4884
4885 If {regname} is "", the unnamed register '"' is used.
4886 If {regname} is not specified, |v:register| is used.
4887 In |Vim9-script| {regname} must be one character.
4888
4889 Can also be used as a |method|: >
4890 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004891<
4892 Return type: |String|
4893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004894
4895getreginfo([{regname}]) *getreginfo()*
4896 Returns detailed information about register {regname} as a
4897 Dictionary with the following entries:
4898 regcontents List of lines contained in register
4899 {regname}, like
4900 |getreg|({regname}, 1, 1).
4901 regtype the type of register {regname}, as in
4902 |getregtype()|.
4903 isunnamed Boolean flag, v:true if this register
4904 is currently pointed to by the unnamed
4905 register.
4906 points_to for the unnamed register, gives the
4907 single letter name of the register
4908 currently pointed to (see |quotequote|).
4909 For example, after deleting a line
4910 with `dd`, this field will be "1",
4911 which is the register that got the
4912 deleted text.
4913
4914 The {regname} argument is a string. If {regname} is invalid
4915 or not set, an empty Dictionary will be returned.
4916 If {regname} is "" or "@", the unnamed register '"' is used.
4917 If {regname} is not specified, |v:register| is used.
4918 The returned Dictionary can be passed to |setreg()|.
4919 In |Vim9-script| {regname} must be one character.
4920
4921 Can also be used as a |method|: >
4922 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004923<
4924 Return type: dict<any>
4925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004926
Shougo Matsushita19b71882024-02-28 22:48:12 +01004927getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004928 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004929 buffer.
4930
4931 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004932 See |getpos()| for the format of the list. It's possible
4933 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004934 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004935
4936 The optional argument {opts} is a Dict and supports the
4937 following items:
4938
zeertzjqafc22952024-05-24 19:07:12 +02004939 type Specify the region's selection type.
4940 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004941 except that the width can be omitted
4942 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004943 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004944
zeertzjq87410ab2024-03-02 06:00:23 +08004945 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004946 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004947 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004948
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004949 You can get the last selection type by |visualmode()|.
4950 If Visual mode is active, use |mode()| to get the Visual mode
4951 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004952 This function is useful to get text starting and ending in
4953 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004954
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004955 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004956 Note that:
4957 - Order of {pos1} and {pos2} doesn't matter, it will always
4958 return content from the upper left position to the lower
4959 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004960 - If 'virtualedit' is enabled and the region is past the end
4961 of the lines, resulting lines are padded with spaces.
4962 - If the region is blockwise and it starts or ends in the
4963 middle of a multi-cell character, it is not included but
4964 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004965 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004966 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004967 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004968 - It is evaluated in current window context, which makes a
4969 difference if the buffer is displayed in a window with
4970 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004971
4972 Examples: >
4973 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004974 \ <Cmd>echow getregion(
4975 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004976<
4977 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004978 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004979<
4980 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004981
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004982
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004983getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4984 Same as |getregion()|, but returns a list of positions
4985 describing the buffer text segments bound by {pos1} and
4986 {pos2}.
4987 The segments are a pair of positions for every line: >
4988 [[{start_pos}, {end_pos}], ...]
4989<
4990 The position is a |List| with four numbers:
4991 [bufnum, lnum, col, off]
4992 "bufnum" is the buffer number.
4993 "lnum" and "col" are the position in the buffer. The first
4994 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004995 If the "off" number of a starting position is non-zero, it is
4996 the offset in screen columns from the start of the character.
4997 E.g., a position within a <Tab> or after the last character.
4998 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004999 the offset of the character's first cell not included in the
5000 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005001
zeertzjq2b09de92024-05-24 07:48:51 +02005002 Apart from the options supported by |getregion()|, {opts} also
5003 supports the following:
5004
5005 eol If |TRUE|, indicate positions beyond
5006 the end of a line with "col" values
5007 one more than the length of the line.
5008 If |FALSE|, positions are limited
5009 within their lines, and if a line is
5010 empty or the selection is entirely
5011 beyond the end of a line, a "col"
5012 value of 0 is used for both positions.
5013 (default: |FALSE|)
5014
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005015 Can also be used as a |method|: >
5016 getpos('.')->getregionpos(getpos("'a"))
5017<
Christian Brabandt83d74402025-03-19 21:55:59 +01005018 For an example, see the highlight-yank plugin |52.6|
5019
zeertzjqd4d12072024-07-16 20:34:16 +02005020 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005021
5022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005023getregtype([{regname}]) *getregtype()*
5024 The result is a String, which is type of register {regname}.
5025 The value will be one of:
5026 "v" for |characterwise| text
5027 "V" for |linewise| text
5028 "<CTRL-V>{width}" for |blockwise-visual| text
5029 "" for an empty or unknown register
5030 <CTRL-V> is one character with value 0x16.
5031 The {regname} argument is a string. If {regname} is "", the
5032 unnamed register '"' is used. If {regname} is not specified,
5033 |v:register| is used.
5034 In |Vim9-script| {regname} must be one character.
5035
5036 Can also be used as a |method|: >
5037 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005038<
5039 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005040
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005041
Bram Moolenaar71badf92023-04-22 22:40:14 +01005042getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005043 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005044 scripts in the order they were sourced, like what
5045 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005046
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005047 The optional Dict argument {opts} supports the following
5048 optional items:
5049 name Script name match pattern. If specified,
5050 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005051 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005052 "name" are returned.
5053 sid Script ID |<SID>|. If specified, only
5054 information about the script with ID "sid" is
5055 returned and "name" is ignored.
5056
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005057 Each item in the returned List is a |Dict| with the following
5058 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005059 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005060 `import autoload` but was not actually sourced
5061 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005062 functions List of script-local function names defined in
5063 the script. Present only when a particular
5064 script is specified using the "sid" item in
5065 {opts}.
5066 name Vim script file name.
5067 sid Script ID |<SID>|.
5068 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005069 this script name links to, if any, otherwise
5070 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005071 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005072 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005073 specified using the "sid" item in {opts}.
5074 Note that this is a copy, the value of
5075 script-local variables cannot be changed using
5076 this dictionary.
h_east59858792023-10-25 22:47:05 +09005077 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005078
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005079 Examples: >
5080 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005081 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005082<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005083 Return type: list<dict<any>>
5084
5085
ichizok663d18d2025-01-02 18:06:00 +01005086getstacktrace() *getstacktrace()*
5087 Returns the current stack trace of Vim scripts.
5088 Stack trace is a |List|, of which each item is a |Dictionary|
5089 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005090 funcref The funcref if the stack is at a function,
5091 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005092 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005093 stack is at an autocmd event, otherwise this
5094 item is omitted.
5095 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005096 filepath The file path of the script on the stack.
5097
5098 Return type: list<dict<any>>
5099
5100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005101gettabinfo([{tabnr}]) *gettabinfo()*
5102 If {tabnr} is not specified, then information about all the
5103 tab pages is returned as a |List|. Each List item is a
5104 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5105 number and information about that one is returned. If the tab
5106 page does not exist an empty List is returned.
5107
5108 Each List item is a |Dictionary| with the following entries:
5109 tabnr tab page number.
5110 variables a reference to the dictionary with
5111 tabpage-local variables
5112 windows List of |window-ID|s in the tab page.
5113
5114 Can also be used as a |method|: >
5115 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005116<
5117 Return type: list<dict<any>>
5118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005119
5120gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5121 Get the value of a tab-local variable {varname} in tab page
5122 {tabnr}. |t:var|
5123 Tabs are numbered starting with one.
5124 The {varname} argument is a string. When {varname} is empty a
5125 dictionary with all tab-local variables is returned.
5126 Note that the name without "t:" must be used.
5127 When the tab or variable doesn't exist {def} or an empty
5128 string is returned, there is no error message.
5129
5130 Can also be used as a |method|: >
5131 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005132<
5133 Return type: any, depending on {varname}
5134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005135
5136gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5137 Get the value of window-local variable {varname} in window
5138 {winnr} in tab page {tabnr}.
5139 The {varname} argument is a string. When {varname} is empty a
5140 dictionary with all window-local variables is returned.
5141 When {varname} is equal to "&" get the values of all
5142 window-local options in a |Dictionary|.
5143 Otherwise, when {varname} starts with "&" get the value of a
5144 window-local option.
5145 Note that {varname} must be the name without "w:".
5146 Tabs are numbered starting with one. For the current tabpage
5147 use |getwinvar()|.
5148 {winnr} can be the window number or the |window-ID|.
5149 When {winnr} is zero the current window is used.
5150 This also works for a global option, buffer-local option and
5151 window-local option, but it doesn't work for a global variable
5152 or buffer-local variable.
5153 When the tab, window or variable doesn't exist {def} or an
5154 empty string is returned, there is no error message.
5155 Examples: >
5156 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005157 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005158<
5159 To obtain all window-local variables use: >
5160 gettabwinvar({tabnr}, {winnr}, '&')
5161
5162< Can also be used as a |method|: >
5163 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005164<
5165 Return type: any, depending on {varname}
5166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005167
5168gettagstack([{winnr}]) *gettagstack()*
5169 The result is a Dict, which is the tag stack of window {winnr}.
5170 {winnr} can be the window number or the |window-ID|.
5171 When {winnr} is not specified, the current window is used.
5172 When window {winnr} doesn't exist, an empty Dict is returned.
5173
5174 The returned dictionary contains the following entries:
5175 curidx Current index in the stack. When at
5176 top of the stack, set to (length + 1).
5177 Index of bottom of the stack is 1.
5178 items List of items in the stack. Each item
5179 is a dictionary containing the
5180 entries described below.
5181 length Number of entries in the stack.
5182
5183 Each item in the stack is a dictionary with the following
5184 entries:
5185 bufnr buffer number of the current jump
5186 from cursor position before the tag jump.
5187 See |getpos()| for the format of the
5188 returned list.
5189 matchnr current matching tag number. Used when
5190 multiple matching tags are found for a
5191 name.
5192 tagname name of the tag
5193
5194 See |tagstack| for more information about the tag stack.
5195
5196 Can also be used as a |method|: >
5197 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005198<
5199 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005200
5201
Christ van Willegence0ef912024-06-20 23:41:59 +02005202gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005203 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005204 This is intended for use in Vim scripts. When generating
5205 message translations the {text} is extracted by `xgettext`,
5206 the translator can add translated messages into the .po file
5207 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005208 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005209 `xgettext` does not support single quoted escaped text.
5210
Christ van Willegence0ef912024-06-20 23:41:59 +02005211 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005212 for that specific package. This is mainly required for
5213 third-party Vim scripts. You need to specify a path to the
5214 translations with the |bindtextdomain()| function before
5215 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005217 Return type: |String|
5218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005219
5220getwininfo([{winid}]) *getwininfo()*
5221 Returns information about windows as a |List| with Dictionaries.
5222
5223 If {winid} is given Information about the window with that ID
5224 is returned, as a |List| with one item. If the window does not
5225 exist the result is an empty list.
5226
5227 Without {winid} information about all the windows in all the
5228 tab pages is returned.
5229
5230 Each List item is a |Dictionary| with the following entries:
5231 botline last complete displayed buffer line
5232 bufnr number of buffer in the window
5233 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005234 leftcol first column displayed; only used when
5235 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005236 loclist 1 if showing a location list
5237 {only with the +quickfix feature}
5238 quickfix 1 if quickfix or location list window
5239 {only with the +quickfix feature}
5240 terminal 1 if a terminal window
5241 {only with the +terminal feature}
5242 tabnr tab page number
5243 topline first displayed buffer line
5244 variables a reference to the dictionary with
5245 window-local variables
5246 width window width
5247 winbar 1 if the window has a toolbar, 0
5248 otherwise
5249 wincol leftmost screen column of the window;
5250 "col" from |win_screenpos()|
5251 textoff number of columns occupied by any
5252 'foldcolumn', 'signcolumn' and line
5253 number in front of the text
5254 winid |window-ID|
5255 winnr window number
5256 winrow topmost screen line of the window;
5257 "row" from |win_screenpos()|
5258
5259 Can also be used as a |method|: >
5260 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005261<
5262 Return type: list<dict<any>>
5263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005264
5265getwinpos([{timeout}]) *getwinpos()*
5266 The result is a |List| with two numbers, the result of
5267 |getwinposx()| and |getwinposy()| combined:
5268 [x-pos, y-pos]
5269 {timeout} can be used to specify how long to wait in msec for
5270 a response from the terminal. When omitted 100 msec is used.
5271 Use a longer time for a remote terminal.
5272 When using a value less than 10 and no response is received
5273 within that time, a previously reported position is returned,
5274 if available. This can be used to poll for the position and
5275 do some work in the meantime: >
5276 while 1
5277 let res = getwinpos(1)
5278 if res[0] >= 0
5279 break
5280 endif
5281 " Do some work here
5282 endwhile
5283<
5284
5285 Can also be used as a |method|: >
5286 GetTimeout()->getwinpos()
5287<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005288 Return type: list<number>
5289
5290
5291getwinposx() *getwinposx()*
5292 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005293 the left hand side of the GUI Vim window. Also works for an
5294 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005295 The result will be -1 if the information is not available
5296 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005297 The value can be used with `:winpos`.
5298
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005299 Return type: |Number|
5300
5301
5302getwinposy() *getwinposy()*
5303 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005304 the top of the GUI Vim window. Also works for an xterm (uses
5305 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005306 The result will be -1 if the information is not available
5307 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005308 The value can be used with `:winpos`.
5309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005310 Return type: |Number|
5311
5312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005313getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5314 Like |gettabwinvar()| for the current tabpage.
5315 Examples: >
5316 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005317 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005318
5319< Can also be used as a |method|: >
5320 GetWinnr()->getwinvar(varname)
5321<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005322 Return type: any, depending on {varname}
5323
5324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005325glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5326 Expand the file wildcards in {expr}. See |wildcards| for the
5327 use of special characters.
5328
5329 Unless the optional {nosuf} argument is given and is |TRUE|,
5330 the 'suffixes' and 'wildignore' options apply: Names matching
5331 one of the patterns in 'wildignore' will be skipped and
5332 'suffixes' affect the ordering of matches.
5333 'wildignorecase' always applies.
5334
5335 When {list} is present and it is |TRUE| the result is a |List|
5336 with all matching files. The advantage of using a List is,
5337 you also get filenames containing newlines correctly.
5338 Otherwise the result is a String and when there are several
5339 matches, they are separated by <NL> characters.
5340
5341 If the expansion fails, the result is an empty String or List.
5342
5343 You can also use |readdir()| if you need to do complicated
5344 things, such as limiting the number of matches.
5345
5346 A name for a non-existing file is not included. A symbolic
5347 link is only included if it points to an existing file.
5348 However, when the {alllinks} argument is present and it is
5349 |TRUE| then all symbolic links are included.
5350
5351 For most systems backticks can be used to get files names from
5352 any external command. Example: >
5353 :let tagfiles = glob("`find . -name tags -print`")
5354 :let &tags = substitute(tagfiles, "\n", ",", "g")
5355< The result of the program inside the backticks should be one
5356 item per line. Spaces inside an item are allowed.
5357
5358 See |expand()| for expanding special Vim variables. See
5359 |system()| for getting the raw output of an external command.
5360
5361 Can also be used as a |method|: >
5362 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005363<
5364 Return type: |String| or list<string> or list<any> depending
5365 on {list}
5366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005367
h-east624bb832024-11-09 18:37:32 +01005368glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005369 Convert a file pattern, as used by glob(), into a search
5370 pattern. The result can be used to match with a string that
5371 is a file name. E.g. >
5372 if filename =~ glob2regpat('Make*.mak')
5373< This is equivalent to: >
5374 if filename =~ '^Make.*\.mak$'
5375< When {string} is an empty string the result is "^$", match an
5376 empty string.
5377 Note that the result depends on the system. On MS-Windows
5378 a backslash usually means a path separator.
5379
5380 Can also be used as a |method|: >
5381 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005382<
5383 Return type: |String|
5384
5385 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005386globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5387 Perform glob() for String {expr} on all directories in {path}
5388 and concatenate the results. Example: >
5389 :echo globpath(&rtp, "syntax/c.vim")
5390<
5391 {path} is a comma-separated list of directory names. Each
5392 directory name is prepended to {expr} and expanded like with
5393 |glob()|. A path separator is inserted when needed.
5394 To add a comma inside a directory name escape it with a
5395 backslash. Note that on MS-Windows a directory may have a
5396 trailing backslash, remove it if you put a comma after it.
5397 If the expansion fails for one of the directories, there is no
5398 error message.
5399
5400 Unless the optional {nosuf} argument is given and is |TRUE|,
5401 the 'suffixes' and 'wildignore' options apply: Names matching
5402 one of the patterns in 'wildignore' will be skipped and
5403 'suffixes' affect the ordering of matches.
5404
5405 When {list} is present and it is |TRUE| the result is a |List|
5406 with all matching files. The advantage of using a List is, you
5407 also get filenames containing newlines correctly. Otherwise
5408 the result is a String and when there are several matches,
5409 they are separated by <NL> characters. Example: >
5410 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5411<
5412 {alllinks} is used as with |glob()|.
5413
5414 The "**" item can be used to search in a directory tree.
5415 For example, to find all "README.txt" files in the directories
5416 in 'runtimepath' and below: >
5417 :echo globpath(&rtp, "**/README.txt")
5418< Upwards search and limiting the depth of "**" is not
5419 supported, thus using 'path' will not always work properly.
5420
5421 Can also be used as a |method|, the base is passed as the
5422 second argument: >
5423 GetExpr()->globpath(&rtp)
5424<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005425 Return type: |String| or list<string> or list<any> depending
5426 on {list}
5427
5428
5429has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005430 When {check} is omitted or is zero: The result is a Number,
5431 which is 1 if the feature {feature} is supported, zero
5432 otherwise. The {feature} argument is a string, case is
5433 ignored. See |feature-list| below.
5434
5435 When {check} is present and not zero: The result is a Number,
5436 which is 1 if the feature {feature} could ever be supported,
5437 zero otherwise. This is useful to check for a typo in
5438 {feature} and to detect dead code. Keep in mind that an older
5439 Vim version will not know about a feature added later and
5440 features that have been abandoned will not be known by the
5441 current Vim version.
5442
5443 Also see |exists()| and |exists_compiled()|.
5444
5445 Note that to skip code that has a syntax error when the
5446 feature is not available, Vim may skip the rest of the line
5447 and miss a following `endif`. Therefore put the `endif` on a
5448 separate line: >
5449 if has('feature')
5450 let x = this->breaks->without->the->feature
5451 endif
5452< If the `endif` would be moved to the second line as "| endif" it
5453 would not be found.
5454
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005455 Return type: |Number|
5456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005457
5458has_key({dict}, {key}) *has_key()*
5459 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005460 has an entry with key {key}. FALSE otherwise.
5461 The {key} argument is a string. In |Vim9| script a number is
5462 also accepted (and converted to a string) but no other types.
5463 In legacy script the usual automatic conversion to string is
5464 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005465
5466 Can also be used as a |method|: >
5467 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005468<
5469 Return type: |Number|
5470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005471
5472haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5473 The result is a Number:
5474 1 when the window has set a local directory via |:lcd|
5475 2 when the tab-page has set a local directory via |:tcd|
5476 0 otherwise.
5477
5478 Without arguments use the current window.
5479 With {winnr} use this window in the current tab page.
5480 With {winnr} and {tabnr} use the window in the specified tab
5481 page.
5482 {winnr} can be the window number or the |window-ID|.
5483 If {winnr} is -1 it is ignored and only the tabpage is used.
5484 Return 0 if the arguments are invalid.
5485 Examples: >
5486 if haslocaldir() == 1
5487 " window local directory case
5488 elseif haslocaldir() == 2
5489 " tab-local directory case
5490 else
5491 " global directory case
5492 endif
5493
5494 " current window
5495 :echo haslocaldir()
5496 :echo haslocaldir(0)
5497 :echo haslocaldir(0, 0)
5498 " window n in current tab page
5499 :echo haslocaldir(n)
5500 :echo haslocaldir(n, 0)
5501 " window n in tab page m
5502 :echo haslocaldir(n, m)
5503 " tab page m
5504 :echo haslocaldir(-1, m)
5505<
5506 Can also be used as a |method|: >
5507 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005508<
5509 Return type: |Number|
5510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005511
5512hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5513 The result is a Number, which is TRUE if there is a mapping
5514 that contains {what} in somewhere in the rhs (what it is
5515 mapped to) and this mapping exists in one of the modes
5516 indicated by {mode}.
5517 The arguments {what} and {mode} are strings.
5518 When {abbr} is there and it is |TRUE| use abbreviations
5519 instead of mappings. Don't forget to specify Insert and/or
5520 Command-line mode.
5521 Both the global mappings and the mappings local to the current
5522 buffer are checked for a match.
5523 If no matching mapping is found FALSE is returned.
5524 The following characters are recognized in {mode}:
5525 n Normal mode
5526 v Visual and Select mode
5527 x Visual mode
5528 s Select mode
5529 o Operator-pending mode
5530 i Insert mode
5531 l Language-Argument ("r", "f", "t", etc.)
5532 c Command-line mode
5533 When {mode} is omitted, "nvo" is used.
5534
5535 This function is useful to check if a mapping already exists
5536 to a function in a Vim script. Example: >
5537 :if !hasmapto('\ABCdoit')
5538 : map <Leader>d \ABCdoit
5539 :endif
5540< This installs the mapping to "\ABCdoit" only if there isn't
5541 already a mapping to "\ABCdoit".
5542
5543 Can also be used as a |method|: >
5544 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005545<
5546 Return type: |Number|
5547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005548
5549histadd({history}, {item}) *histadd()*
5550 Add the String {item} to the history {history} which can be
5551 one of: *hist-names*
5552 "cmd" or ":" command line history
5553 "search" or "/" search pattern history
5554 "expr" or "=" typed expression history
5555 "input" or "@" input line history
5556 "debug" or ">" debug command history
5557 empty the current or last used history
5558 The {history} string does not need to be the whole name, one
5559 character is sufficient.
5560 If {item} does already exist in the history, it will be
5561 shifted to become the newest entry.
5562 The result is a Number: TRUE if the operation was successful,
5563 otherwise FALSE is returned.
5564
5565 Example: >
5566 :call histadd("input", strftime("%Y %b %d"))
5567 :let date=input("Enter date: ")
5568< This function is not available in the |sandbox|.
5569
5570 Can also be used as a |method|, the base is passed as the
5571 second argument: >
5572 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005573<
5574 Return type: |Number|
5575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005576
5577histdel({history} [, {item}]) *histdel()*
5578 Clear {history}, i.e. delete all its entries. See |hist-names|
5579 for the possible values of {history}.
5580
5581 If the parameter {item} evaluates to a String, it is used as a
5582 regular expression. All entries matching that expression will
5583 be removed from the history (if there are any).
5584 Upper/lowercase must match, unless "\c" is used |/\c|.
5585 If {item} evaluates to a Number, it will be interpreted as
5586 an index, see |:history-indexing|. The respective entry will
5587 be removed if it exists.
5588
5589 The result is TRUE for a successful operation, otherwise FALSE
5590 is returned.
5591
5592 Examples:
5593 Clear expression register history: >
5594 :call histdel("expr")
5595<
5596 Remove all entries starting with "*" from the search history: >
5597 :call histdel("/", '^\*')
5598<
5599 The following three are equivalent: >
5600 :call histdel("search", histnr("search"))
5601 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005602 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005603<
5604 To delete the last search pattern and use the last-but-one for
5605 the "n" command and 'hlsearch': >
5606 :call histdel("search", -1)
5607 :let @/ = histget("search", -1)
5608<
5609 Can also be used as a |method|: >
5610 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005611<
5612 Return type: |Number|
5613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005614
5615histget({history} [, {index}]) *histget()*
5616 The result is a String, the entry with Number {index} from
5617 {history}. See |hist-names| for the possible values of
5618 {history}, and |:history-indexing| for {index}. If there is
5619 no such entry, an empty String is returned. When {index} is
5620 omitted, the most recent item from the history is used.
5621
5622 Examples:
5623 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005624 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005625
5626< Define an Ex command ":H {num}" that supports re-execution of
5627 the {num}th entry from the output of |:history|. >
5628 :command -nargs=1 H execute histget("cmd", 0+<args>)
5629<
5630 Can also be used as a |method|: >
5631 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005632<
5633 Return type: |String|
5634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005635
5636histnr({history}) *histnr()*
5637 The result is the Number of the current entry in {history}.
5638 See |hist-names| for the possible values of {history}.
5639 If an error occurred, -1 is returned.
5640
5641 Example: >
5642 :let inp_index = histnr("expr")
5643
5644< Can also be used as a |method|: >
5645 GetHistory()->histnr()
5646<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005647 Return type: |Number|
5648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005649hlexists({name}) *hlexists()*
5650 The result is a Number, which is TRUE if a highlight group
5651 called {name} exists. This is when the group has been
5652 defined in some way. Not necessarily when highlighting has
5653 been defined for it, it may also have been used for a syntax
5654 item.
5655 *highlight_exists()*
5656 Obsolete name: highlight_exists().
5657
5658 Can also be used as a |method|: >
5659 GetName()->hlexists()
5660<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005661 Return type: |Number|
5662
5663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005664hlget([{name} [, {resolve}]]) *hlget()*
5665 Returns a List of all the highlight group attributes. If the
5666 optional {name} is specified, then returns a List with only
5667 the attributes of the specified highlight group. Returns an
5668 empty List if the highlight group {name} is not present.
5669
5670 If the optional {resolve} argument is set to v:true and the
5671 highlight group {name} is linked to another group, then the
5672 link is resolved recursively and the attributes of the
5673 resolved highlight group are returned.
5674
5675 Each entry in the returned List is a Dictionary with the
5676 following items:
5677 cleared boolean flag, set to v:true if the highlight
5678 group attributes are cleared or not yet
5679 specified. See |highlight-clear|.
5680 cterm cterm attributes. See |highlight-cterm|.
5681 ctermbg cterm background color.
5682 See |highlight-ctermbg|.
5683 ctermfg cterm foreground color.
5684 See |highlight-ctermfg|.
5685 ctermul cterm underline color. See |highlight-ctermul|.
5686 default boolean flag, set to v:true if the highlight
5687 group link is a default link. See
5688 |highlight-default|.
5689 font highlight group font. See |highlight-font|.
5690 gui gui attributes. See |highlight-gui|.
5691 guibg gui background color. See |highlight-guibg|.
5692 guifg gui foreground color. See |highlight-guifg|.
5693 guisp gui special color. See |highlight-guisp|.
5694 id highlight group ID.
5695 linksto linked highlight group name.
5696 See |:highlight-link|.
5697 name highlight group name. See |group-name|.
5698 start start terminal keycode. See |highlight-start|.
5699 stop stop terminal keycode. See |highlight-stop|.
5700 term term attributes. See |highlight-term|.
5701
5702 The 'term', 'cterm' and 'gui' items in the above Dictionary
5703 have a dictionary value with the following optional boolean
5704 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5705 'reverse', 'inverse' and 'strikethrough'.
5706
5707 Example(s): >
5708 :echo hlget()
5709 :echo hlget('ModeMsg')
5710 :echo hlget('Number', v:true)
5711<
5712 Can also be used as a |method|: >
5713 GetName()->hlget()
5714<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005715 Return type: list<dict<any>>
5716
5717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005718hlset({list}) *hlset()*
5719 Creates or modifies the attributes of a List of highlight
5720 groups. Each item in {list} is a dictionary containing the
5721 attributes of a highlight group. See |hlget()| for the list of
5722 supported items in this dictionary.
5723
5724 In addition to the items described in |hlget()|, the following
5725 additional items are supported in the dictionary:
5726
5727 force boolean flag to force the creation of
5728 a link for an existing highlight group
5729 with attributes.
5730
5731 The highlight group is identified using the 'name' item and
5732 the 'id' item (if supplied) is ignored. If a highlight group
5733 with a specified name doesn't exist, then it is created.
5734 Otherwise the attributes of an existing highlight group are
5735 modified.
5736
5737 If an empty dictionary value is used for the 'term' or 'cterm'
5738 or 'gui' entries, then the corresponding attributes are
5739 cleared. If the 'cleared' item is set to v:true, then all the
5740 attributes of the highlight group are cleared.
5741
5742 The 'linksto' item can be used to link a highlight group to
5743 another highlight group. See |:highlight-link|.
5744
5745 Returns zero for success, -1 for failure.
5746
5747 Example(s): >
5748 " add bold attribute to the Visual highlight group
5749 :call hlset([#{name: 'Visual',
5750 \ term: #{reverse: 1 , bold: 1}}])
5751 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5752 :let l = hlget()
5753 :call hlset(l)
5754 " clear the Search highlight group
5755 :call hlset([#{name: 'Search', cleared: v:true}])
5756 " clear the 'term' attributes for a highlight group
5757 :call hlset([#{name: 'Title', term: {}}])
5758 " create the MyHlg group linking it to DiffAdd
5759 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5760 " remove the MyHlg group link
5761 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5762 " clear the attributes and a link
5763 :call hlset([#{name: 'MyHlg', cleared: v:true,
5764 \ linksto: 'NONE'}])
5765<
5766 Can also be used as a |method|: >
5767 GetAttrList()->hlset()
5768<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005769 Return type: |Number|
5770
5771hlID({name}) *hlID()*
5772 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005773 with name {name}. When the highlight group doesn't exist,
5774 zero is returned.
5775 This can be used to retrieve information about the highlight
5776 group. For example, to get the background color of the
5777 "Comment" group: >
5778 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5779< *highlightID()*
5780 Obsolete name: highlightID().
5781
5782 Can also be used as a |method|: >
5783 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005784<
5785 Return type: |Number|
5786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005787
5788hostname() *hostname()*
5789 The result is a String, which is the name of the machine on
5790 which Vim is currently running. Machine names greater than
5791 256 characters long are truncated.
5792
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005793 Return type: |String|
5794
5795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005796iconv({string}, {from}, {to}) *iconv()*
5797 The result is a String, which is the text {string} converted
5798 from encoding {from} to encoding {to}.
5799 When the conversion completely fails an empty string is
5800 returned. When some characters could not be converted they
5801 are replaced with "?".
5802 The encoding names are whatever the iconv() library function
5803 can accept, see ":!man 3 iconv".
5804 Most conversions require Vim to be compiled with the |+iconv|
5805 feature. Otherwise only UTF-8 to latin1 conversion and back
5806 can be done.
5807 This can be used to display messages with special characters,
5808 no matter what 'encoding' is set to. Write the message in
5809 UTF-8 and use: >
5810 echo iconv(utf8_str, "utf-8", &enc)
5811< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5812 from/to UCS-2 is automatically changed to use UTF-8. You
5813 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5814
5815 Can also be used as a |method|: >
5816 GetText()->iconv('latin1', 'utf-8')
5817<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005818 Return type: |String|
5819
5820
h-east624bb832024-11-09 18:37:32 +01005821id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005822 The result is a unique String associated with the {item} and
5823 not with the {item}'s contents. It is only valid while the
5824 {item} exists and is referenced. It is valid only in the
5825 instance of vim that produces the result. The whole idea is
5826 that `id({item})` does not change if the contents of {item}
5827 changes. This is useful as a `key` for creating an identity
5828 dictionary, rather than one based on equals.
5829
5830 This operation does not reference {item} and there is no
5831 function to convert the `id` to the {item}. It may be useful to
5832 have a map of `id` to {item}. The following >
5833 var referenceMap: dict<any>
5834 var id = item->id()
5835 referenceMap[id] = item
5836< prevents {item} from being garbage collected and provides a
5837 way to get the {item} from the `id`.
5838
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005839 {item} may be a List, Tuple, Dictionary, Object, Job, Channel
5840 or Blob. If the item is not a permitted type, or it is a null
Ernie Raelc8e158b2024-07-09 18:39:52 +02005841 value, then an empty String is returned.
5842
5843 Can also be used as a |method|: >
5844 GetItem()->id()
5845<
5846 Return type: |String|
5847
5848
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005849indent({lnum}) *indent()*
5850 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005851 current buffer. The indent is counted in spaces, the value
5852 of 'tabstop' is relevant. {lnum} is used just like in
5853 |getline()|.
5854 When {lnum} is invalid -1 is returned. In |Vim9| script an
5855 error is given.
5856
5857 Can also be used as a |method|: >
5858 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005859<
5860 Return type: |Number|
5861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005862
5863index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005864 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005865 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005866
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005867 If {object} is a |List| or a |Tuple| return the lowest index
5868 where the item has a value equal to {expr}. There is no
5869 automatic conversion, so the String "4" is different from the
5870 Number 4. And the number 4 is different from the Float 4.0.
5871 The value of 'ignorecase' is not used here, case matters as
5872 indicated by the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005873
5874 If {object} is |Blob| return the lowest index where the byte
5875 value is equal to {expr}.
5876
5877 If {start} is given then start looking at the item with index
5878 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005880 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5881 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005883 -1 is returned when {expr} is not found in {object}.
5884 Example: >
5885 :let idx = index(words, "the")
5886 :if index(numbers, 123) >= 0
5887
5888< Can also be used as a |method|: >
5889 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005890<
5891 Return type: |Number|
5892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005893
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005894indexof({object}, {expr} [, {opts}]) *indexof()*
5895 Returns the index of an item in {object} where {expr} is
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005896 v:true. {object} must be a |List|, a |Tuple| or a |Blob|.
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005897
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005898 If {object} is a |List| or a |Tuple|, evaluate {expr} for each
Christ van Willegen92e109f2025-03-24 20:12:37 +01005899 item in the List or Tuple until the expression is v:true
5900 and return the index of this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005901
5902 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005903 Blob until the expression is v:true and return the index of
5904 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005905
5906 {expr} must be a |string| or |Funcref|.
5907
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005908 If {expr} is a |string|: If {object} is a |List| or a |Tuple|,
5909 inside {expr} |v:key| has the index of the current List or
5910 Tuple item and |v:val| has the value of the item. If {object}
5911 is a |Blob|, inside {expr} |v:key| has the index of the
5912 current byte and |v:val| has the byte value.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005913
5914 If {expr} is a |Funcref| it must take two arguments:
5915 1. the key or the index of the current item.
5916 2. the value of the current item.
5917 The function must return |TRUE| if the item is found and the
5918 search should stop.
5919
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005920 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005921 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005922 startidx start evaluating {expr} at the item with this
5923 index; may be negative for an item relative to
5924 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005925 Returns -1 when {expr} evaluates to v:false for all the items.
5926 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005927 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5928 :echo indexof(l, "v:val.n == 20")
5929 :echo indexof(l, {i, v -> v.n == 30})
5930 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005931
5932< Can also be used as a |method|: >
5933 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005934<
5935 Return type: |Number|
5936
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005938input({prompt} [, {text} [, {completion}]]) *input()*
5939 The result is a String, which is whatever the user typed on
5940 the command-line. The {prompt} argument is either a prompt
5941 string, or a blank string (for no prompt). A '\n' can be used
5942 in the prompt to start a new line.
5943 The highlighting set with |:echohl| is used for the prompt.
5944 The input is entered just like a command-line, with the same
5945 editing commands and mappings. There is a separate history
5946 for lines typed for input().
5947 Example: >
5948 :if input("Coffee or beer? ") == "beer"
5949 : echo "Cheers!"
5950 :endif
5951<
5952 If the optional {text} argument is present and not empty, this
5953 is used for the default reply, as if the user typed this.
5954 Example: >
5955 :let color = input("Color? ", "white")
5956
5957< The optional {completion} argument specifies the type of
5958 completion supported for the input. Without it completion is
5959 not performed. The supported completion types are the same as
5960 that can be supplied to a user-defined command using the
5961 "-complete=" argument. Refer to |:command-completion| for
5962 more information. Example: >
5963 let fname = input("File: ", "", "file")
5964<
5965 NOTE: This function must not be used in a startup file, for
5966 the versions that only run in GUI mode (e.g., the Win32 GUI).
5967 Note: When input() is called from within a mapping it will
5968 consume remaining characters from that mapping, because a
5969 mapping is handled like the characters were typed.
5970 Use |inputsave()| before input() and |inputrestore()|
5971 after input() to avoid that. Another solution is to avoid
5972 that further characters follow in the mapping, e.g., by using
5973 |:execute| or |:normal|.
5974
5975 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005976 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005977 :function GetFoo()
5978 : call inputsave()
5979 : let g:Foo = input("enter search pattern: ")
5980 : call inputrestore()
5981 :endfunction
5982
5983< Can also be used as a |method|: >
5984 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005985<
5986 Return type: |String|
5987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005988
5989inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5990 Like |input()|, but when the GUI is running and text dialogs
5991 are supported, a dialog window pops up to input the text.
5992 Example: >
5993 :let n = inputdialog("value for shiftwidth", shiftwidth())
5994 :if n != ""
5995 : let &sw = n
5996 :endif
5997< When the dialog is cancelled {cancelreturn} is returned. When
5998 omitted an empty string is returned.
5999 Hitting <Enter> works like pressing the OK button. Hitting
6000 <Esc> works like pressing the Cancel button.
6001 NOTE: Command-line completion is not supported.
6002
6003 Can also be used as a |method|: >
6004 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006005<
6006 Return type: |String|
6007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006008
6009inputlist({textlist}) *inputlist()*
6010 {textlist} must be a |List| of strings. This |List| is
6011 displayed, one string per line. The user will be prompted to
6012 enter a number, which is returned.
6013 The user can also select an item by clicking on it with the
6014 mouse, if the mouse is enabled in the command line ('mouse' is
6015 "a" or includes "c"). For the first string 0 is returned.
6016 When clicking above the first item a negative number is
6017 returned. When clicking on the prompt one more than the
6018 length of {textlist} is returned.
6019 Make sure {textlist} has less than 'lines' entries, otherwise
6020 it won't work. It's a good idea to put the entry number at
6021 the start of the string. And put a prompt in the first item.
6022 Example: >
6023 let color = inputlist(['Select color:', '1. red',
6024 \ '2. green', '3. blue'])
6025
6026< Can also be used as a |method|: >
6027 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006028<
6029 Return type: |Number|
6030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006031
6032inputrestore() *inputrestore()*
6033 Restore typeahead that was saved with a previous |inputsave()|.
6034 Should be called the same number of times inputsave() is
6035 called. Calling it more often is harmless though.
6036 Returns TRUE when there is nothing to restore, FALSE otherwise.
6037
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006038 Return type: |Number|
6039
6040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006041inputsave() *inputsave()*
6042 Preserve typeahead (also from mappings) and clear it, so that
6043 a following prompt gets input from the user. Should be
6044 followed by a matching inputrestore() after the prompt. Can
6045 be used several times, in which case there must be just as
6046 many inputrestore() calls.
6047 Returns TRUE when out of memory, FALSE otherwise.
6048
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006049 Return type: |Number|
6050
6051
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006052inputsecret({prompt} [, {text}]) *inputsecret()*
6053 This function acts much like the |input()| function with but
6054 two exceptions:
6055 a) the user's response will be displayed as a sequence of
6056 asterisks ("*") thereby keeping the entry secret, and
6057 b) the user's response will not be recorded on the input
6058 |history| stack.
6059 The result is a String, which is whatever the user actually
6060 typed on the command-line in response to the issued prompt.
6061 NOTE: Command-line completion is not supported.
6062
6063 Can also be used as a |method|: >
6064 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006065<
6066 Return type: |String|
6067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068
6069insert({object}, {item} [, {idx}]) *insert()*
6070 When {object} is a |List| or a |Blob| insert {item} at the start
6071 of it.
6072
6073 If {idx} is specified insert {item} before the item with index
6074 {idx}. If {idx} is zero it goes before the first item, just
6075 like omitting {idx}. A negative {idx} is also possible, see
6076 |list-index|. -1 inserts just before the last item.
6077
6078 Returns the resulting |List| or |Blob|. Examples: >
6079 :let mylist = insert([2, 3, 5], 1)
6080 :call insert(mylist, 4, -1)
6081 :call insert(mylist, 6, len(mylist))
6082< The last example can be done simpler with |add()|.
6083 Note that when {item} is a |List| it is inserted as a single
6084 item. Use |extend()| to concatenate |Lists|.
6085
6086 Can also be used as a |method|: >
6087 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006088<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006089 Return type: |Number|
6090
6091
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006092 *instanceof()* *E614* *E616* *E693*
6093instanceof({object}, {class})
6094 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006095 argument is a direct or indirect instance of a |Class|,
6096 |Interface|, or class |:type| alias specified by {class}.
6097 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006098 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006099 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006100 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006101
6102< Can also be used as a |method|: >
6103 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006104<
6105 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006107interrupt() *interrupt()*
6108 Interrupt script execution. It works more or less like the
6109 user typing CTRL-C, most commands won't execute and control
6110 returns to the user. This is useful to abort execution
6111 from lower down, e.g. in an autocommand. Example: >
6112 :function s:check_typoname(file)
6113 : if fnamemodify(a:file, ':t') == '['
6114 : echomsg 'Maybe typo'
6115 : call interrupt()
6116 : endif
6117 :endfunction
6118 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006119<
6120 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006121
6122invert({expr}) *invert()*
6123 Bitwise invert. The argument is converted to a number. A
6124 List, Dict or Float argument causes an error. Example: >
6125 :let bits = invert(bits)
6126< Can also be used as a |method|: >
6127 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006128<
6129 Return type: |Number|
6130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006131
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006132isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006133 The result is a Number, which is |TRUE| when {path} is an
6134 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006135 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006136 On MS-Windows, it is considered absolute when it starts with an
6137 optional drive prefix and is followed by a '\' or '/'. UNC paths
6138 are always absolute.
6139 Example: >
6140 echo isabsolutepath('/usr/share/') " 1
6141 echo isabsolutepath('./foobar') " 0
6142 echo isabsolutepath('C:\Windows') " 1
6143 echo isabsolutepath('foobar') " 0
6144 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006145<
LemonBoydca1d402022-04-28 15:26:33 +01006146 Can also be used as a |method|: >
6147 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006148<
6149 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006150
6151
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006152isdirectory({directory}) *isdirectory()*
6153 The result is a Number, which is |TRUE| when a directory
6154 with the name {directory} exists. If {directory} doesn't
6155 exist, or isn't a directory, the result is |FALSE|. {directory}
6156 is any expression, which is used as a String.
6157
6158 Can also be used as a |method|: >
6159 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006160<
6161 Return type: |Number|
6162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006163
6164isinf({expr}) *isinf()*
6165 Return 1 if {expr} is a positive infinity, or -1 a negative
6166 infinity, otherwise 0. >
6167 :echo isinf(1.0 / 0.0)
6168< 1 >
6169 :echo isinf(-1.0 / 0.0)
6170< -1
6171
6172 Can also be used as a |method|: >
6173 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006174<
6175 Return type: |Number|
6176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006177
6178islocked({expr}) *islocked()* *E786*
6179 The result is a Number, which is |TRUE| when {expr} is the
6180 name of a locked variable.
6181 The string argument {expr} must be the name of a variable,
6182 |List| item or |Dictionary| entry, not the variable itself!
6183 Example: >
6184 :let alist = [0, ['a', 'b'], 2, 3]
6185 :lockvar 1 alist
6186 :echo islocked('alist') " 1
6187 :echo islocked('alist[1]') " 0
6188
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006189< When {expr} is a variable that does not exist -1 is returned.
6190 If {expr} uses a range, list or dict index that is out of
6191 range or does not exist you get an error message. Use
6192 |exists()| to check for existence.
6193 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006194
6195 Can also be used as a |method|: >
6196 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006197<
6198 Return type: |Number|
6199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006200
6201isnan({expr}) *isnan()*
6202 Return |TRUE| if {expr} is a float with value NaN. >
6203 echo isnan(0.0 / 0.0)
6204< 1
6205
6206 Can also be used as a |method|: >
6207 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006208<
6209 Return type: |Number|
6210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006211
6212items({dict}) *items()*
6213 Return a |List| with all the key-value pairs of {dict}. Each
6214 |List| item is a list with two items: the key of a {dict}
6215 entry and the value of this entry. The |List| is in arbitrary
6216 order. Also see |keys()| and |values()|.
6217 Example: >
6218 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006219 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006220 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006221<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006222 A |List|, a |Tuple| or a |String| argument is also supported.
6223 In these cases, items() returns a List with the index and the
6224 value at the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006225
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006226 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006227 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006228<
6229 Return type: list<list<any>> or list<any>
6230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006231
6232job_ functions are documented here: |job-functions-details|
6233
6234
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006235join({expr} [, {sep}]) *join()*
6236 Join the items in {expr} together into one String. {expr} can
6237 be a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238 When {sep} is specified it is put in between the items. If
6239 {sep} is omitted a single space is used.
6240 Note that {sep} is not added at the end. You might want to
6241 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006242 let lines = join(mylist, "\n") .. "\n"
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006243< String items are used as-is. |Lists|, |Tuples| and
6244 |Dictionaries| are converted into a string like with
6245 |string()|. The opposite function is |split()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006246
6247 Can also be used as a |method|: >
6248 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006249<
6250 Return type: |String|
6251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252
6253js_decode({string}) *js_decode()*
6254 This is similar to |json_decode()| with these differences:
6255 - Object key names do not have to be in quotes.
6256 - Strings can be in single quotes.
6257 - Empty items in an array (between two commas) are allowed and
6258 result in v:none items.
6259
6260 Can also be used as a |method|: >
6261 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006262<
6263 Return type: any, depending on {varname}
6264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265
6266js_encode({expr}) *js_encode()*
6267 This is similar to |json_encode()| with these differences:
6268 - Object key names are not in quotes.
6269 - v:none items in an array result in an empty item between
6270 commas.
6271 For example, the Vim object:
6272 [1,v:none,{"one":1},v:none] ~
6273 Will be encoded as:
6274 [1,,{one:1},,] ~
6275 While json_encode() would produce:
6276 [1,null,{"one":1},null] ~
6277 This encoding is valid for JavaScript. It is more efficient
6278 than JSON, especially when using an array with optional items.
6279
6280 Can also be used as a |method|: >
6281 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006282<
6283 Return type: |String|
6284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006285
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006286json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006287 This parses a JSON formatted string and returns the equivalent
6288 in Vim values. See |json_encode()| for the relation between
6289 JSON and Vim values.
6290 The decoding is permissive:
6291 - A trailing comma in an array and object is ignored, e.g.
6292 "[1, 2, ]" is the same as "[1, 2]".
6293 - Integer keys are accepted in objects, e.g. {1:2} is the
6294 same as {"1":2}.
6295 - More floating point numbers are recognized, e.g. "1." for
6296 "1.0", or "001.2" for "1.2". Special floating point values
6297 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6298 are accepted.
6299 - Leading zeroes in integer numbers are ignored, e.g. "012"
6300 for "12" or "-012" for "-12".
6301 - Capitalization is ignored in literal names null, true or
6302 false, e.g. "NULL" for "null", "True" for "true".
6303 - Control characters U+0000 through U+001F which are not
6304 escaped in strings are accepted, e.g. " " (tab
6305 character in string) for "\t".
6306 - An empty JSON expression or made of only spaces is accepted
6307 and results in v:none.
6308 - Backslash in an invalid 2-character sequence escape is
6309 ignored, e.g. "\a" is decoded as "a".
6310 - A correct surrogate pair in JSON strings should normally be
6311 a 12 character sequence such as "\uD834\uDD1E", but
6312 json_decode() silently accepts truncated surrogate pairs
6313 such as "\uD834" or "\uD834\u"
6314 *E938*
6315 A duplicate key in an object, valid in rfc7159, is not
6316 accepted by json_decode() as the result must be a valid Vim
6317 type, e.g. this fails: {"a":"b", "a":"c"}
6318
6319 Can also be used as a |method|: >
6320 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006321<
6322 Return type: any, depending on {varname}
6323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006324
6325json_encode({expr}) *json_encode()*
6326 Encode {expr} as JSON and return this as a string.
6327 The encoding is specified in:
6328 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006329 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330 |Number| decimal number
6331 |Float| floating point number
6332 Float nan "NaN"
6333 Float inf "Infinity"
6334 Float -inf "-Infinity"
6335 |String| in double quotes (possibly null)
6336 |Funcref| not possible, error
6337 |List| as an array (possibly null); when
6338 used recursively: []
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006339 |Tuple| as an array (possibly null); when
6340 used recursively: []
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006341 |Dict| as an object (possibly null); when
6342 used recursively: {}
6343 |Blob| as an array of the individual bytes
6344 v:false "false"
6345 v:true "true"
6346 v:none "null"
6347 v:null "null"
6348 Note that NaN and Infinity are passed on as values. This is
6349 missing in the JSON standard, but several implementations do
6350 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006351 If a string contains an illegal character then the replacement
6352 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006353
6354 Can also be used as a |method|: >
6355 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006356<
6357 Return type: |String|
6358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006359
6360keys({dict}) *keys()*
6361 Return a |List| with all the keys of {dict}. The |List| is in
6362 arbitrary order. Also see |items()| and |values()|.
6363
6364 Can also be used as a |method|: >
6365 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006366<
6367 Return type: list<string>
6368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006369
zeertzjqcdc83932022-09-12 13:38:41 +01006370keytrans({string}) *keytrans()*
6371 Turn the internal byte representation of keys into a form that
6372 can be used for |:map|. E.g. >
6373 :let xx = "\<C-Home>"
6374 :echo keytrans(xx)
6375< <C-Home>
6376
6377 Can also be used as a |method|: >
6378 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006379<
6380 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006381
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006382
6383len({expr}) *len()* *E701*
6384 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006385 When {expr} is a String or a Number the length in bytes is
6386 used, as with |strlen()|.
6387 When {expr} is a |List| the number of items in the |List| is
6388 returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006389 When {expr} is a |Tuple| the number of items in the |Tuple| is
6390 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006391 When {expr} is a |Blob| the number of bytes is returned.
6392 When {expr} is a |Dictionary| the number of entries in the
6393 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006394 When {expr} is an |Object|, invokes the len() method in the
6395 object (if present) to get the length (|object-len()|).
6396 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006397
6398 Can also be used as a |method|: >
6399 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006400<
6401 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006402
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006403
6404 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006405libcall({libname}, {funcname}, {argument})
6406 Call function {funcname} in the run-time library {libname}
6407 with single argument {argument}.
6408 This is useful to call functions in a library that you
6409 especially made to be used with Vim. Since only one argument
6410 is possible, calling standard library functions is rather
6411 limited.
6412 The result is the String returned by the function. If the
6413 function returns NULL, this will appear as an empty string ""
6414 to Vim.
6415 If the function returns a number, use libcallnr()!
6416 If {argument} is a number, it is passed to the function as an
6417 int; if {argument} is a string, it is passed as a
6418 null-terminated string.
6419 This function will fail in |restricted-mode|.
6420
6421 libcall() allows you to write your own 'plug-in' extensions to
6422 Vim without having to recompile the program. It is NOT a
6423 means to call system functions! If you try to do so Vim will
6424 very probably crash.
6425
6426 For Win32, the functions you write must be placed in a DLL
6427 and use the normal C calling convention (NOT Pascal which is
6428 used in Windows System DLLs). The function must take exactly
6429 one parameter, either a character pointer or a long integer,
6430 and must return a character pointer or NULL. The character
6431 pointer returned must point to memory that will remain valid
6432 after the function has returned (e.g. in static data in the
6433 DLL). If it points to allocated memory, that memory will
6434 leak away. Using a static buffer in the function should work,
6435 it's then freed when the DLL is unloaded.
6436
6437 WARNING: If the function returns a non-valid pointer, Vim may
6438 crash! This also happens if the function returns a number,
6439 because Vim thinks it's a pointer.
6440 For Win32 systems, {libname} should be the filename of the DLL
6441 without the ".DLL" suffix. A full path is only required if
6442 the DLL is not in the usual places.
6443 For Unix: When compiling your own plugins, remember that the
6444 object code must be compiled as position-independent ('PIC').
6445 {only in Win32 and some Unix versions, when the |+libcall|
6446 feature is present}
6447 Examples: >
6448 :echo libcall("libc.so", "getenv", "HOME")
6449
6450< Can also be used as a |method|, the base is passed as the
6451 third argument: >
6452 GetValue()->libcall("libc.so", "getenv")
6453<
6454 *libcallnr()*
6455libcallnr({libname}, {funcname}, {argument})
6456 Just like |libcall()|, but used for a function that returns an
6457 int instead of a string.
6458 {only in Win32 on some Unix versions, when the |+libcall|
6459 feature is present}
6460 Examples: >
6461 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6462 :call libcallnr("libc.so", "printf", "Hello World!\n")
6463 :call libcallnr("libc.so", "sleep", 10)
6464<
6465 Can also be used as a |method|, the base is passed as the
6466 third argument: >
6467 GetValue()->libcallnr("libc.so", "printf")
6468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006469 Return type: |String|
6470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471
6472line({expr} [, {winid}]) *line()*
6473 The result is a Number, which is the line number of the file
6474 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006475 See |getpos()| for accepted positions.
6476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006477 To get the column number use |col()|. To get both use
6478 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006480 With the optional {winid} argument the values are obtained for
6481 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006482
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006483 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006485 Examples: >
6486 line(".") line number of the cursor
6487 line(".", winid) idem, in window "winid"
6488 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006489 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006490<
6491 To jump to the last known position when opening a file see
6492 |last-position-jump|.
6493
6494 Can also be used as a |method|: >
6495 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006496<
6497 Return type: |Number|
6498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006499
6500line2byte({lnum}) *line2byte()*
6501 Return the byte count from the start of the buffer for line
6502 {lnum}. This includes the end-of-line character, depending on
6503 the 'fileformat' option for the current buffer. The first
6504 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6505 This can also be used to get the byte count for the line just
6506 below the last line: >
6507 line2byte(line("$") + 1)
6508< This is the buffer size plus one. If 'fileencoding' is empty
6509 it is the file size plus one. {lnum} is used like with
6510 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6511 feature has been disabled at compile time, -1 is returned.
6512 Also see |byte2line()|, |go| and |:goto|.
6513
6514 Can also be used as a |method|: >
6515 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006516<
6517 Return type: |Number|
6518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006519
6520lispindent({lnum}) *lispindent()*
6521 Get the amount of indent for line {lnum} according the lisp
6522 indenting rules, as with 'lisp'.
6523 The indent is counted in spaces, the value of 'tabstop' is
6524 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006525 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526 error is given.
6527
6528 Can also be used as a |method|: >
6529 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006530<
6531 Return type: |Number|
6532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006533
6534list2blob({list}) *list2blob()*
6535 Return a Blob concatenating all the number values in {list}.
6536 Examples: >
6537 list2blob([1, 2, 3, 4]) returns 0z01020304
6538 list2blob([]) returns 0z
6539< Returns an empty Blob on error. If one of the numbers is
6540 negative or more than 255 error *E1239* is given.
6541
6542 |blob2list()| does the opposite.
6543
6544 Can also be used as a |method|: >
6545 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006546<
6547 Return type: |Blob|
6548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006549
6550list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006551 Convert each number in {list} to a character string and
6552 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006553 list2str([32]) returns " "
6554 list2str([65, 66, 67]) returns "ABC"
6555< The same can be done (slowly) with: >
6556 join(map(list, {nr, val -> nr2char(val)}), '')
6557< |str2list()| does the opposite.
6558
6559 When {utf8} is omitted or zero, the current 'encoding' is used.
6560 When {utf8} is TRUE, always return UTF-8 characters.
6561 With UTF-8 composing characters work as expected: >
6562 list2str([97, 769]) returns "á"
6563<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006564 Returns an empty string on error.
6565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006566 Can also be used as a |method|: >
6567 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006568<
6569 Return type: |String|
6570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006571
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006572list2tuple({list}) *list2tuple()*
6573 Create a Tuple from a shallow copy of the list items.
6574 Examples: >
6575 list2tuple([1, 2, 3]) returns (1, 2, 3)
6576< |tuple2list()| does the opposite.
6577
6578 This function doesn't recursively convert all the List items
6579 in {list} to a Tuple. Note that the items are identical
6580 between the list and the tuple, changing an item changes the
6581 contents of both the tuple and the list.
6582
6583 Returns an empty tuple on error.
6584
6585 Can also be used as a |method|: >
6586 GetList()->list2tuple()
6587<
6588 Return type: tuple<{type}> (depending on the given |List|)
6589
6590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006591listener_add({callback} [, {buf}]) *listener_add()*
6592 Add a callback function that will be invoked when changes have
6593 been made to buffer {buf}.
6594 {buf} refers to a buffer name or number. For the accepted
6595 values, see |bufname()|. When {buf} is omitted the current
6596 buffer is used.
6597 Returns a unique ID that can be passed to |listener_remove()|.
6598
6599 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006600 bufnr the buffer that was changed
6601 start first changed line number
6602 end first line number below the change
6603 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006604 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006605 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006606
6607 Example: >
6608 func Listener(bufnr, start, end, added, changes)
6609 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6610 endfunc
6611 call listener_add('Listener', bufnr)
6612
Bram Moolenaar944697a2022-02-20 19:48:20 +00006613< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614 dictionary with these entries:
6615 lnum the first line number of the change
6616 end the first line below the change
6617 added number of lines added; negative if lines were
6618 deleted
6619 col first column in "lnum" that was affected by
6620 the change; one if unknown or the whole line
6621 was affected; this is a byte index, first
6622 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006623 When lines are inserted (not when a line is split, e.g. by
6624 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006625 lnum line above which the new line is added
6626 end equal to "lnum"
6627 added number of lines inserted
6628 col 1
6629 When lines are deleted the values are:
6630 lnum the first deleted line
6631 end the line below the first deleted line, before
6632 the deletion was done
6633 added negative, number of lines deleted
6634 col 1
6635 When lines are changed:
6636 lnum the first changed line
6637 end the line below the last changed line
6638 added 0
6639 col first column with a change or 1
6640
6641 The entries are in the order the changes were made, thus the
6642 most recent change is at the end. The line numbers are valid
6643 when the callback is invoked, but later changes may make them
6644 invalid, thus keeping a copy for later might not work.
6645
6646 The {callback} is invoked just before the screen is updated,
6647 when |listener_flush()| is called or when a change is being
6648 made that changes the line count in a way it causes a line
6649 number in the list of changes to become invalid.
6650
6651 The {callback} is invoked with the text locked, see
6652 |textlock|. If you do need to make changes to the buffer, use
6653 a timer to do this later |timer_start()|.
6654
6655 The {callback} is not invoked when the buffer is first loaded.
6656 Use the |BufReadPost| autocmd event to handle the initial text
6657 of a buffer.
6658 The {callback} is also not invoked when the buffer is
6659 unloaded, use the |BufUnload| autocmd event for that.
6660
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006661 Returns zero if {callback} or {buf} is invalid.
6662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006663 Can also be used as a |method|, the base is passed as the
6664 second argument: >
6665 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006666<
6667 Return type: |Number|
6668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006669
6670listener_flush([{buf}]) *listener_flush()*
6671 Invoke listener callbacks for buffer {buf}. If there are no
6672 pending changes then no callbacks are invoked.
6673
6674 {buf} refers to a buffer name or number. For the accepted
6675 values, see |bufname()|. When {buf} is omitted the current
6676 buffer is used.
6677
6678 Can also be used as a |method|: >
6679 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006680<
6681 Return type: |Number|
6682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683
6684listener_remove({id}) *listener_remove()*
6685 Remove a listener previously added with listener_add().
6686 Returns FALSE when {id} could not be found, TRUE when {id} was
6687 removed.
6688
6689 Can also be used as a |method|: >
6690 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006691<
6692 Return type: |Number|
6693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006694
6695localtime() *localtime()*
6696 Return the current time, measured as seconds since 1st Jan
6697 1970. See also |strftime()|, |strptime()| and |getftime()|.
6698
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006699 Return type: |Number|
6700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006701
6702log({expr}) *log()*
6703 Return the natural logarithm (base e) of {expr} as a |Float|.
6704 {expr} must evaluate to a |Float| or a |Number| in the range
6705 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006706 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006707 Examples: >
6708 :echo log(10)
6709< 2.302585 >
6710 :echo log(exp(5))
6711< 5.0
6712
6713 Can also be used as a |method|: >
6714 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006715<
6716 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006717
6718
6719log10({expr}) *log10()*
6720 Return the logarithm of Float {expr} to base 10 as a |Float|.
6721 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006722 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006723 Examples: >
6724 :echo log10(1000)
6725< 3.0 >
6726 :echo log10(0.01)
6727< -2.0
6728
6729 Can also be used as a |method|: >
6730 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006731<
6732 Return type: |Float|
6733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006734
6735luaeval({expr} [, {expr}]) *luaeval()*
6736 Evaluate Lua expression {expr} and return its result converted
6737 to Vim data structures. Second {expr} may hold additional
6738 argument accessible as _A inside first {expr}.
6739 Strings are returned as they are.
6740 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006741 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006742 Dictionaries and lists obtained by vim.eval() are returned
6743 as-is.
6744 Other objects are returned as zero without any errors.
6745 See |lua-luaeval| for more details.
6746 Note that in a `:def` function local variables are not visible
6747 to {expr}.
6748
6749 Can also be used as a |method|: >
6750 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006751<
6752 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006753
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006754 {only available when compiled with the |+lua| feature}
6755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006756
6757map({expr1}, {expr2}) *map()*
6758 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006759 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006760 item in {expr1} with the result of evaluating {expr2}.
6761 For a |Blob| each byte is replaced.
6762 For a |String|, each character, including composing
6763 characters, is replaced.
6764 If the item type changes you may want to use |mapnew()| to
6765 create a new List or Dictionary. This is required when using
6766 Vim9 script.
6767
6768 {expr2} must be a |String| or |Funcref|.
6769
6770 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6771 of the current item. For a |Dictionary| |v:key| has the key
6772 of the current item and for a |List| |v:key| has the index of
6773 the current item. For a |Blob| |v:key| has the index of the
6774 current byte. For a |String| |v:key| has the index of the
6775 current character.
6776 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006777 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006778< This puts "> " before and " <" after each item in "mylist".
6779
6780 Note that {expr2} is the result of an expression and is then
6781 used as an expression again. Often it is good to use a
6782 |literal-string| to avoid having to double backslashes. You
6783 still have to double ' quotes
6784
6785 If {expr2} is a |Funcref| it is called with two arguments:
6786 1. The key or the index of the current item.
6787 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006788 With a legacy script lambda you don't get an error if it only
6789 accepts one argument, but with a Vim9 lambda you get "E1106:
6790 One argument too many", the number of arguments must match.
6791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006792 The function must return the new value of the item. Example
6793 that changes each value by "key-value": >
6794 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006795 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006796 endfunc
6797 call map(myDict, function('KeyValue'))
6798< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006799 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006800< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006801 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006802< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006803 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006804<
6805 The operation is done in-place for a |List| and |Dictionary|.
6806 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006807 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006808
6809< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6810 or a new |Blob| or |String|.
6811 When an error is encountered while evaluating {expr2} no
6812 further items in {expr1} are processed.
6813 When {expr2} is a Funcref errors inside a function are ignored,
6814 unless it was defined with the "abort" flag.
6815
6816 Can also be used as a |method|: >
6817 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006818<
6819 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6820 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006821
6822
6823maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6824 When {dict} is omitted or zero: Return the rhs of mapping
6825 {name} in mode {mode}. The returned String has special
6826 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006827 listing. When {dict} is TRUE a dictionary is returned, see
6828 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006829
6830 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006831 returned if {dict} is FALSE, otherwise returns an empty Dict.
6832 When the mapping for {name} is empty, then "<Nop>" is
6833 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006834
6835 The {name} can have special key names, like in the ":map"
6836 command.
6837
6838 {mode} can be one of these strings:
6839 "n" Normal
6840 "v" Visual (including Select)
6841 "o" Operator-pending
6842 "i" Insert
6843 "c" Cmd-line
6844 "s" Select
6845 "x" Visual
6846 "l" langmap |language-mapping|
6847 "t" Terminal-Job
6848 "" Normal, Visual and Operator-pending
6849 When {mode} is omitted, the modes for "" are used.
6850
6851 When {abbr} is there and it is |TRUE| use abbreviations
6852 instead of mappings.
6853
6854 When {dict} is there and it is |TRUE| return a dictionary
6855 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006856 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006857 "lhs" The {lhs} of the mapping as it would be typed
6858 "lhsraw" The {lhs} of the mapping as raw bytes
6859 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6860 form, only present when it differs from "lhsraw"
6861 "rhs" The {rhs} of the mapping as typed.
6862 "silent" 1 for a |:map-silent| mapping, else 0.
6863 "noremap" 1 if the {rhs} of the mapping is not remappable.
6864 "script" 1 if mapping was defined with <script>.
6865 "expr" 1 for an expression mapping (|:map-<expr>|).
6866 "buffer" 1 for a buffer local mapping (|:map-local|).
6867 "mode" Modes for which the mapping is defined. In
6868 addition to the modes mentioned above, these
6869 characters will be used:
6870 " " Normal, Visual and Operator-pending
6871 "!" Insert and Commandline mode
6872 (|mapmode-ic|)
6873 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006874 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006875 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006876 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006877 "lnum" The line number in "sid", zero if unknown.
6878 "nowait" Do not wait for other, longer mappings.
6879 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006880 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006881 "mode_bits" Vim's internal binary representation of "mode".
6882 |mapset()| ignores this; only "mode" is used.
6883 See |maplist()| for usage examples. The values
6884 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006885
6886 The dictionary can be used to restore a mapping with
6887 |mapset()|.
6888
6889 The mappings local to the current buffer are checked first,
6890 then the global mappings.
6891 This function can be used to map a key even when it's already
6892 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006893 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006894
6895< Can also be used as a |method|: >
6896 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006897<
6898 Return type: |String| or dict<any> depending on {dict}
6899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006900
6901mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6902 Check if there is a mapping that matches with {name} in mode
6903 {mode}. See |maparg()| for {mode} and special names in
6904 {name}.
6905 When {abbr} is there and it is |TRUE| use abbreviations
6906 instead of mappings.
6907 A match happens with a mapping that starts with {name} and
6908 with a mapping which is equal to the start of {name}.
6909
6910 matches mapping "a" "ab" "abc" ~
6911 mapcheck("a") yes yes yes
6912 mapcheck("abc") yes yes yes
6913 mapcheck("ax") yes no no
6914 mapcheck("b") no no no
6915
6916 The difference with maparg() is that mapcheck() finds a
6917 mapping that matches with {name}, while maparg() only finds a
6918 mapping for {name} exactly.
6919 When there is no mapping that starts with {name}, an empty
6920 String is returned. If there is one, the RHS of that mapping
6921 is returned. If there are several mappings that start with
6922 {name}, the RHS of one of them is returned. This will be
6923 "<Nop>" if the RHS is empty.
6924 The mappings local to the current buffer are checked first,
6925 then the global mappings.
6926 This function can be used to check if a mapping can be added
6927 without being ambiguous. Example: >
6928 :if mapcheck("_vv") == ""
6929 : map _vv :set guifont=7x13<CR>
6930 :endif
6931< This avoids adding the "_vv" mapping when there already is a
6932 mapping for "_v" or for "_vvv".
6933
6934 Can also be used as a |method|: >
6935 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006936<
6937 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006938
6939
Ernie Rael09661202022-04-25 14:40:44 +01006940maplist([{abbr}]) *maplist()*
6941 Returns a |List| of all mappings. Each List item is a |Dict|,
6942 the same as what is returned by |maparg()|, see
6943 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6944 abbreviations instead of mappings.
6945
6946 Example to show all mappings with 'MultiMatch' in rhs: >
6947 vim9script
6948 echo maplist()->filter(
6949 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006950< It can be tricky to find mappings for particular |:map-modes|.
6951 |mapping-dict|'s "mode_bits" can simplify this. For example,
6952 the mode_bits for Normal, Insert or Command-line modes are
6953 0x19. To find all the mappings available in those modes you
6954 can do: >
6955 vim9script
6956 var saved_maps = []
6957 for m in maplist()
6958 if and(m.mode_bits, 0x19) != 0
6959 saved_maps->add(m)
6960 endif
6961 endfor
6962 echo saved_maps->mapnew((_, m) => m.lhs)
6963< The values of the mode_bits are defined in Vim's src/vim.h
6964 file and they can be discovered at runtime using
6965 |:map-commands| and "maplist()". Example: >
6966 vim9script
6967 omap xyzzy <Nop>
6968 var op_bit = maplist()->filter(
6969 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6970 ounmap xyzzy
6971 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006972<
6973 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006974
6975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006976mapnew({expr1}, {expr2}) *mapnew()*
6977 Like |map()| but instead of replacing items in {expr1} a new
6978 List or Dictionary is created and returned. {expr1} remains
6979 unchanged. Items can still be changed by {expr2}, if you
6980 don't want that use |deepcopy()| first.
6981
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006982 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6983 depending on {expr1}
6984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006985
6986mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006987mapset({dict})
6988 Restore a mapping from a dictionary, possibly returned by
6989 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6990 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006991 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006992 feature allows copying mappings from one buffer to another.
6993 The dict.mode value may restore a single mapping that covers
6994 more than one mode, like with mode values of '!', ' ', 'nox',
6995 or 'v'. *E1276*
6996
6997 In the first form, {mode} and {abbr} should be the same as
6998 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006999 {mode} is used to define the mode in which the mapping is set,
7000 not the "mode" entry in {dict}.
7001 Example for saving and restoring a mapping: >
7002 let save_map = maparg('K', 'n', 0, 1)
7003 nnoremap K somethingelse
7004 ...
7005 call mapset('n', 0, save_map)
7006< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01007007 e.g. with `:map!`, you need to save/restore the mapping for
7008 all of them, when they might differ.
7009
7010 In the second form, with {dict} as the only argument, mode
7011 and abbr are taken from the dict.
7012 Example: >
7013 vim9script
7014 var save_maps = maplist()->filter(
7015 (_, m) => m.lhs == 'K')
7016 nnoremap K somethingelse
7017 cnoremap K somethingelse2
7018 # ...
7019 unmap K
7020 for d in save_maps
7021 mapset(d)
7022 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007023<
7024 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007025
7026
7027match({expr}, {pat} [, {start} [, {count}]]) *match()*
7028 When {expr} is a |List| then this returns the index of the
7029 first item where {pat} matches. Each item is used as a
7030 String, |Lists| and |Dictionaries| are used as echoed.
7031
7032 Otherwise, {expr} is used as a String. The result is a
7033 Number, which gives the index (byte offset) in {expr} where
7034 {pat} matches.
7035
7036 A match at the first character or |List| item returns zero.
7037 If there is no match -1 is returned.
7038
7039 For getting submatches see |matchlist()|.
7040 Example: >
7041 :echo match("testing", "ing") " results in 4
7042 :echo match([1, 'x'], '\a') " results in 1
7043< See |string-match| for how {pat} is used.
7044 *strpbrk()*
7045 Vim doesn't have a strpbrk() function. But you can do: >
7046 :let sepidx = match(line, '[.,;: \t]')
7047< *strcasestr()*
7048 Vim doesn't have a strcasestr() function. But you can add
7049 "\c" to the pattern to ignore case: >
7050 :let idx = match(haystack, '\cneedle')
7051<
7052 If {start} is given, the search starts from byte index
7053 {start} in a String or item {start} in a |List|.
7054 The result, however, is still the index counted from the
7055 first character/item. Example: >
7056 :echo match("testing", "ing", 2)
7057< result is again "4". >
7058 :echo match("testing", "ing", 4)
7059< result is again "4". >
7060 :echo match("testing", "t", 2)
7061< result is "3".
7062 For a String, if {start} > 0 then it is like the string starts
7063 {start} bytes later, thus "^" will match at {start}. Except
7064 when {count} is given, then it's like matches before the
7065 {start} byte are ignored (this is a bit complicated to keep it
7066 backwards compatible).
7067 For a String, if {start} < 0, it will be set to 0. For a list
7068 the index is counted from the end.
7069 If {start} is out of range ({start} > strlen({expr}) for a
7070 String or {start} > len({expr}) for a |List|) -1 is returned.
7071
7072 When {count} is given use the {count}'th match. When a match
7073 is found in a String the search for the next one starts one
7074 character further. Thus this example results in 1: >
7075 echo match("testing", "..", 0, 2)
7076< In a |List| the search continues in the next item.
7077 Note that when {count} is added the way {start} works changes,
7078 see above.
7079
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007080 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007081 See |pattern| for the patterns that are accepted.
7082 The 'ignorecase' option is used to set the ignore-caseness of
7083 the pattern. 'smartcase' is NOT used. The matching is always
7084 done like 'magic' is set and 'cpoptions' is empty.
7085 Note that a match at the start is preferred, thus when the
7086 pattern is using "*" (any number of matches) it tends to find
7087 zero matches at the start instead of a number of matches
7088 further down in the text.
7089
7090 Can also be used as a |method|: >
7091 GetText()->match('word')
7092 GetList()->match('word')
7093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007094 Return type: |Number|
7095
7096
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007097 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007098matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7099 Defines a pattern to be highlighted in the current window (a
7100 "match"). It will be highlighted with {group}. Returns an
7101 identification number (ID), which can be used to delete the
7102 match using |matchdelete()|. The ID is bound to the window.
7103 Matching is case sensitive and magic, unless case sensitivity
7104 or magicness are explicitly overridden in {pattern}. The
7105 'magic', 'smartcase' and 'ignorecase' options are not used.
7106 The "Conceal" value is special, it causes the match to be
7107 concealed.
7108
7109 The optional {priority} argument assigns a priority to the
7110 match. A match with a high priority will have its
7111 highlighting overrule that of a match with a lower priority.
7112 A priority is specified as an integer (negative numbers are no
7113 exception). If the {priority} argument is not specified, the
7114 default priority is 10. The priority of 'hlsearch' is zero,
7115 hence all matches with a priority greater than zero will
7116 overrule it. Syntax highlighting (see 'syntax') is a separate
7117 mechanism, and regardless of the chosen priority a match will
7118 always overrule syntax highlighting.
7119
7120 The optional {id} argument allows the request for a specific
7121 match ID. If a specified ID is already taken, an error
7122 message will appear and the match will not be added. An ID
7123 is specified as a positive integer (zero excluded). IDs 1, 2
7124 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007125 respectively. 3 is reserved for use by the |matchparen|
7126 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007127 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007128 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007129
7130 The optional {dict} argument allows for further custom
7131 values. Currently this is used to specify a match specific
7132 conceal character that will be shown for |hl-Conceal|
7133 highlighted matches. The dict can have the following members:
7134
7135 conceal Special character to show instead of the
7136 match (only for |hl-Conceal| highlighted
7137 matches, see |:syn-cchar|)
7138 window Instead of the current window use the
7139 window with this number or window ID.
7140
7141 The number of matches is not limited, as it is the case with
7142 the |:match| commands.
7143
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007144 Returns -1 on error.
7145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007146 Example: >
7147 :highlight MyGroup ctermbg=green guibg=green
7148 :let m = matchadd("MyGroup", "TODO")
7149< Deletion of the pattern: >
7150 :call matchdelete(m)
7151
7152< A list of matches defined by |matchadd()| and |:match| are
7153 available from |getmatches()|. All matches can be deleted in
7154 one operation by |clearmatches()|.
7155
7156 Can also be used as a |method|: >
7157 GetGroup()->matchadd('TODO')
7158<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007159 Return type: |Number|
7160
7161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007162 *matchaddpos()*
7163matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7164 Same as |matchadd()|, but requires a list of positions {pos}
7165 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007166 because it does not handle regular expressions and it sets
7167 buffer line boundaries to redraw screen. It is supposed to be
7168 used when fast match additions and deletions are required, for
7169 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007170
7171 {pos} is a list of positions. Each position can be one of
7172 these:
7173 - A number. This whole line will be highlighted. The first
7174 line has number 1.
7175 - A list with one number, e.g., [23]. The whole line with this
7176 number will be highlighted.
7177 - A list with two numbers, e.g., [23, 11]. The first number is
7178 the line number, the second one is the column number (first
7179 column is 1, the value must correspond to the byte index as
7180 |col()| would return). The character at this position will
7181 be highlighted.
7182 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7183 the third number gives the length of the highlight in bytes.
7184
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007185 Returns -1 on error.
7186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007187 Example: >
7188 :highlight MyGroup ctermbg=green guibg=green
7189 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7190< Deletion of the pattern: >
7191 :call matchdelete(m)
7192
7193< Matches added by |matchaddpos()| are returned by
7194 |getmatches()|.
7195
7196 Can also be used as a |method|: >
7197 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007198<
7199 Return type: |Number|
7200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007201
7202matcharg({nr}) *matcharg()*
7203 Selects the {nr} match item, as set with a |:match|,
7204 |:2match| or |:3match| command.
7205 Return a |List| with two elements:
7206 The name of the highlight group used
7207 The pattern used.
7208 When {nr} is not 1, 2 or 3 returns an empty |List|.
7209 When there is no match item set returns ['', ''].
7210 This is useful to save and restore a |:match|.
7211 Highlighting matches using the |:match| commands are limited
7212 to three matches. |matchadd()| does not have this limitation.
7213
7214 Can also be used as a |method|: >
7215 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007216<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007217 Return type: list<string>
7218
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007219 *matchbufline()*
7220matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7221 Returns the |List| of matches in lines from {lnum} to {end} in
7222 buffer {buf} where {pat} matches.
7223
7224 {lnum} and {end} can either be a line number or the string "$"
7225 to refer to the last line in {buf}.
7226
7227 The {dict} argument supports following items:
7228 submatches include submatch information (|/\(|)
7229
7230 For each match, a |Dict| with the following items is returned:
7231 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007232 lnum line number where there is a match
7233 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007234 Note that there can be multiple matches in a single line.
7235
7236 This function works only for loaded buffers. First call
7237 |bufload()| if needed.
7238
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007239 See |match-pattern| for information about the effect of some
7240 option settings on the pattern.
7241
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007242 When {buf} is not a valid buffer, the buffer is not loaded or
7243 {lnum} or {end} is not valid then an error is given and an
7244 empty |List| is returned.
7245
7246 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007247 " Assuming line 3 in buffer 5 contains "a"
7248 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7249 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7250 " Assuming line 4 in buffer 10 contains "tik tok"
7251 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7252 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007253<
7254 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007255 "\1", "\2", etc. are also returned. Example: >
7256 " Assuming line 2 in buffer 2 contains "acd"
7257 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007258 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007259 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007260< The "submatches" List always contains 9 items. If a submatch
7261 is not found, then an empty string is returned for that
7262 submatch.
7263
7264 Can also be used as a |method|: >
7265 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007266<
7267 Return type: list<dict<any>> or list<any>
7268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007269
h-east624bb832024-11-09 18:37:32 +01007270matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007271 Deletes a match with ID {id} previously defined by |matchadd()|
7272 or one of the |:match| commands. Returns 0 if successful,
7273 otherwise -1. See example for |matchadd()|. All matches can
7274 be deleted in one operation by |clearmatches()|.
7275 If {win} is specified, use the window with this number or
7276 window ID instead of the current window.
7277
7278 Can also be used as a |method|: >
7279 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007280<
7281 Return type: |Number|
7282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007283
7284matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7285 Same as |match()|, but return the index of first character
7286 after the match. Example: >
7287 :echo matchend("testing", "ing")
7288< results in "7".
7289 *strspn()* *strcspn()*
7290 Vim doesn't have a strspn() or strcspn() function, but you can
7291 do it with matchend(): >
7292 :let span = matchend(line, '[a-zA-Z]')
7293 :let span = matchend(line, '[^a-zA-Z]')
7294< Except that -1 is returned when there are no matches.
7295
7296 The {start}, if given, has the same meaning as for |match()|. >
7297 :echo matchend("testing", "ing", 2)
7298< results in "7". >
7299 :echo matchend("testing", "ing", 5)
7300< result is "-1".
7301 When {expr} is a |List| the result is equal to |match()|.
7302
7303 Can also be used as a |method|: >
7304 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007305<
7306 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007307
7308
7309matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7310 If {list} is a list of strings, then returns a |List| with all
7311 the strings in {list} that fuzzy match {str}. The strings in
7312 the returned list are sorted based on the matching score.
7313
7314 The optional {dict} argument always supports the following
7315 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007316 matchseq When this item is present return only matches
7317 that contain the characters in {str} in the
7318 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007319 limit Maximum number of matches in {list} to be
7320 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007321 camelcase Use enhanced camel case scoring making results
7322 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007323 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007324
7325 If {list} is a list of dictionaries, then the optional {dict}
7326 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007327 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007328 {str}. The value of this item should be a
7329 string.
7330 text_cb |Funcref| that will be called for every item
7331 in {list} to get the text for fuzzy matching.
7332 This should accept a dictionary item as the
7333 argument and return the text for that item to
7334 use for fuzzy matching.
7335
7336 {str} is treated as a literal string and regular expression
7337 matching is NOT supported. The maximum supported {str} length
7338 is 256.
7339
7340 When {str} has multiple words each separated by white space,
7341 then the list of strings that have all the words is returned.
7342
7343 If there are no matching strings or there is an error, then an
7344 empty list is returned. If length of {str} is greater than
7345 256, then returns an empty list.
7346
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007347 When {limit} is given, matchfuzzy() will find up to this
7348 number of matches in {list} and return them in sorted order.
7349
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007350 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007351 matching strings.
7352
7353 Example: >
7354 :echo matchfuzzy(["clay", "crow"], "cay")
7355< results in ["clay"]. >
7356 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7357< results in a list of buffer names fuzzy matching "ndl". >
7358 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7359< results in a list of buffer information dicts with buffer
7360 names fuzzy matching "ndl". >
7361 :echo getbufinfo()->matchfuzzy("spl",
7362 \ {'text_cb' : {v -> v.name}})
7363< results in a list of buffer information dicts with buffer
7364 names fuzzy matching "spl". >
7365 :echo v:oldfiles->matchfuzzy("test")
7366< results in a list of file names fuzzy matching "test". >
7367 :let l = readfile("buffer.c")->matchfuzzy("str")
7368< results in a list of lines in "buffer.c" fuzzy matching "str". >
7369 :echo ['one two', 'two one']->matchfuzzy('two one')
7370< results in ['two one', 'one two']. >
7371 :echo ['one two', 'two one']->matchfuzzy('two one',
7372 \ {'matchseq': 1})
7373< results in ['two one'].
7374
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007375 Return type: list<string> or list<any>
7376
7377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007378matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7379 Same as |matchfuzzy()|, but returns the list of matched
7380 strings, the list of character positions where characters
7381 in {str} matches and a list of matching scores. You can
7382 use |byteidx()| to convert a character position to a byte
7383 position.
7384
7385 If {str} matches multiple times in a string, then only the
7386 positions for the best match is returned.
7387
7388 If there are no matching strings or there is an error, then a
7389 list with three empty list items is returned.
7390
7391 Example: >
7392 :echo matchfuzzypos(['testing'], 'tsg')
7393< results in [['testing'], [[0, 2, 6]], [99]] >
7394 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7395< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7396 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7397< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007399 Return type: list<list<any>>
7400
7401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007402matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7403 Same as |match()|, but return a |List|. The first item in the
7404 list is the matched string, same as what matchstr() would
7405 return. Following items are submatches, like "\1", "\2", etc.
7406 in |:substitute|. When an optional submatch didn't match an
7407 empty string is used. Example: >
7408 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7409< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7410 When there is no match an empty list is returned.
7411
7412 You can pass in a List, but that is not very useful.
7413
7414 Can also be used as a |method|: >
7415 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007417 Return type: list<string> or list<any>
7418
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007419 *matchstrlist()*
7420matchstrlist({list}, {pat} [, {dict}])
7421 Returns the |List| of matches in {list} where {pat} matches.
7422 {list} is a |List| of strings. {pat} is matched against each
7423 string in {list}.
7424
7425 The {dict} argument supports following items:
7426 submatches include submatch information (|/\(|)
7427
7428 For each match, a |Dict| with the following items is returned:
7429 byteidx starting byte index of the match.
7430 idx index in {list} of the match.
7431 text matched string
7432 submatches a List of submatches. Present only if
7433 "submatches" is set to v:true in {dict}.
7434
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007435 See |match-pattern| for information about the effect of some
7436 option settings on the pattern.
7437
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007438 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007439 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7440 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7441 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7442 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007443<
7444 If "submatches" is present and is v:true, then submatches like
7445 "\1", "\2", etc. are also returned. Example: >
7446 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7447 \ #{submatches: v:true})
7448 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7449< The "submatches" List always contains 9 items. If a submatch
7450 is not found, then an empty string is returned for that
7451 submatch.
7452
7453 Can also be used as a |method|: >
7454 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007455<
7456 Return type: list<dict<any>> or list<any>
7457
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007458
7459matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7460 Same as |match()|, but return the matched string. Example: >
7461 :echo matchstr("testing", "ing")
7462< results in "ing".
7463 When there is no match "" is returned.
7464 The {start}, if given, has the same meaning as for |match()|. >
7465 :echo matchstr("testing", "ing", 2)
7466< results in "ing". >
7467 :echo matchstr("testing", "ing", 5)
7468< result is "".
7469 When {expr} is a |List| then the matching item is returned.
7470 The type isn't changed, it's not necessarily a String.
7471
7472 Can also be used as a |method|: >
7473 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007474<
7475 Return type: |String|
7476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007477
7478matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7479 Same as |matchstr()|, but return the matched string, the start
7480 position and the end position of the match. Example: >
7481 :echo matchstrpos("testing", "ing")
7482< results in ["ing", 4, 7].
7483 When there is no match ["", -1, -1] is returned.
7484 The {start}, if given, has the same meaning as for |match()|. >
7485 :echo matchstrpos("testing", "ing", 2)
7486< results in ["ing", 4, 7]. >
7487 :echo matchstrpos("testing", "ing", 5)
7488< result is ["", -1, -1].
7489 When {expr} is a |List| then the matching item, the index
7490 of first item where {pat} matches, the start position and the
7491 end position of the match are returned. >
7492 :echo matchstrpos([1, '__x'], '\a')
7493< result is ["x", 1, 2, 3].
7494 The type isn't changed, it's not necessarily a String.
7495
7496 Can also be used as a |method|: >
7497 GetText()->matchstrpos('word')
7498<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007499 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007500
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007501
7502max({expr}) *max()*
7503 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007504 echo max([apples, pears, oranges])
7505
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007506< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7507 Dictionary, it returns the maximum of all values in the
7508 Dictionary. If {expr} is neither a List nor a Tuple nor a
7509 Dictionary, or one of the items in {expr} cannot be used as a
7510 Number this results in an error. An empty |List|, |Tuple|
7511 or |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007512
7513 Can also be used as a |method|: >
7514 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007515<
7516 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007517
7518
7519menu_info({name} [, {mode}]) *menu_info()*
7520 Return information about the specified menu {name} in
7521 mode {mode}. The menu name should be specified without the
7522 shortcut character ('&'). If {name} is "", then the top-level
7523 menu names are returned.
7524
7525 {mode} can be one of these strings:
7526 "n" Normal
7527 "v" Visual (including Select)
7528 "o" Operator-pending
7529 "i" Insert
7530 "c" Cmd-line
7531 "s" Select
7532 "x" Visual
7533 "t" Terminal-Job
7534 "" Normal, Visual and Operator-pending
7535 "!" Insert and Cmd-line
7536 When {mode} is omitted, the modes for "" are used.
7537
7538 Returns a |Dictionary| containing the following items:
7539 accel menu item accelerator text |menu-text|
7540 display display name (name without '&')
7541 enabled v:true if this menu item is enabled
7542 Refer to |:menu-enable|
7543 icon name of the icon file (for toolbar)
7544 |toolbar-icon|
7545 iconidx index of a built-in icon
7546 modes modes for which the menu is defined. In
7547 addition to the modes mentioned above, these
7548 characters will be used:
7549 " " Normal, Visual and Operator-pending
7550 name menu item name.
7551 noremenu v:true if the {rhs} of the menu item is not
7552 remappable else v:false.
7553 priority menu order priority |menu-priority|
7554 rhs right-hand-side of the menu item. The returned
7555 string has special characters translated like
7556 in the output of the ":menu" command listing.
7557 When the {rhs} of a menu item is empty, then
7558 "<Nop>" is returned.
7559 script v:true if script-local remapping of {rhs} is
7560 allowed else v:false. See |:menu-script|.
7561 shortcut shortcut key (character after '&' in
7562 the menu name) |menu-shortcut|
7563 silent v:true if the menu item is created
7564 with <silent> argument |:menu-silent|
7565 submenus |List| containing the names of
7566 all the submenus. Present only if the menu
7567 item has submenus.
7568
7569 Returns an empty dictionary if the menu item is not found.
7570
7571 Examples: >
7572 :echo menu_info('Edit.Cut')
7573 :echo menu_info('File.Save', 'n')
7574
7575 " Display the entire menu hierarchy in a buffer
7576 func ShowMenu(name, pfx)
7577 let m = menu_info(a:name)
7578 call append(line('$'), a:pfx .. m.display)
7579 for child in m->get('submenus', [])
7580 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7581 \ a:pfx .. ' ')
7582 endfor
7583 endfunc
7584 new
7585 for topmenu in menu_info('').submenus
7586 call ShowMenu(topmenu, '')
7587 endfor
7588<
7589 Can also be used as a |method|: >
7590 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007591<
7592 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007593
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007594min({expr}) *min()*
7595 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007596 echo min([apples, pears, oranges])
7597
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007598< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7599 Dictionary, it returns the minimum of all values in the
7600 Dictionary. If {expr} is neither a List nor a Tuple nor a
7601 Dictionary, or one of the items in {expr} cannot be used as a
7602 Number this results in an error. An empty |List|, |Tuple| or
7603 |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007604
7605 Can also be used as a |method|: >
7606 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007607<
7608 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007609
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007610
7611mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007612 Create directory {name}.
7613
Bram Moolenaar938ae282023-02-20 20:44:55 +00007614 When {flags} is present it must be a string. An empty string
7615 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007616
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007617 {flags} can contain these character flags:
7618 "p" intermediate directories will be created as necessary
7619 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007620 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007621 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007622 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007623
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007624 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007625 some directories may already exist. Only the first one that
7626 is created and what it contains is scheduled to be deleted.
7627 E.g. when using: >
7628 call mkdir('subdir/tmp/autoload', 'pR')
7629< and "subdir" already exists then "subdir/tmp" will be
7630 scheduled for deletion, like with: >
7631 defer delete('subdir/tmp', 'rf')
7632< Note that if scheduling the defer fails the directory is not
7633 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007634
7635 If {prot} is given it is used to set the protection bits of
7636 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7637 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007638 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007639 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007640 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007641 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007642
7643< This function is not available in the |sandbox|.
7644
7645 There is no error if the directory already exists and the "p"
7646 flag is passed (since patch 8.0.1708). However, without the
7647 "p" option the call will fail.
7648
7649 The function result is a Number, which is TRUE if the call was
7650 successful or FALSE if the directory creation failed or partly
7651 failed.
7652
7653 Not available on all systems. To check use: >
7654 :if exists("*mkdir")
7655
7656< Can also be used as a |method|: >
7657 GetName()->mkdir()
7658<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007659 Return type: |Number|
7660
7661
7662mode([{expr}]) *mode()*
7663 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007664 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007665 a non-empty String (|non-zero-arg|), then the full mode is
7666 returned, otherwise only the first letter is returned.
7667 Also see |state()|.
7668
7669 n Normal
7670 no Operator-pending
7671 nov Operator-pending (forced characterwise |o_v|)
7672 noV Operator-pending (forced linewise |o_V|)
7673 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7674 CTRL-V is one character
7675 niI Normal using |i_CTRL-O| in |Insert-mode|
7676 niR Normal using |i_CTRL-O| in |Replace-mode|
7677 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7678 nt Terminal-Normal (insert goes to Terminal-Job mode)
7679 v Visual by character
7680 vs Visual by character using |v_CTRL-O| in Select mode
7681 V Visual by line
7682 Vs Visual by line using |v_CTRL-O| in Select mode
7683 CTRL-V Visual blockwise
7684 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7685 s Select by character
7686 S Select by line
7687 CTRL-S Select blockwise
7688 i Insert
7689 ic Insert mode completion |compl-generic|
7690 ix Insert mode |i_CTRL-X| completion
7691 R Replace |R|
7692 Rc Replace mode completion |compl-generic|
7693 Rx Replace mode |i_CTRL-X| completion
7694 Rv Virtual Replace |gR|
7695 Rvc Virtual Replace mode completion |compl-generic|
7696 Rvx Virtual Replace mode |i_CTRL-X| completion
7697 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007698 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007699 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007700 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007701 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007702 ce Normal Ex mode |Q|
7703 r Hit-enter prompt
7704 rm The -- more -- prompt
7705 r? A |:confirm| query of some sort
7706 ! Shell or external command is executing
7707 t Terminal-Job mode: keys go to the job
7708
7709 This is useful in the 'statusline' option or when used
7710 with |remote_expr()| In most other places it always returns
7711 "c" or "n".
7712 Note that in the future more modes and more specific modes may
7713 be added. It's better not to compare the whole string but only
7714 the leading character(s).
7715 Also see |visualmode()|.
7716
7717 Can also be used as a |method|: >
7718 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007719<
7720 Return type: |String|
7721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007722
7723mzeval({expr}) *mzeval()*
7724 Evaluate MzScheme expression {expr} and return its result
7725 converted to Vim data structures.
7726 Numbers and strings are returned as they are.
7727 Pairs (including lists and improper lists) and vectors are
7728 returned as Vim |Lists|.
7729 Hash tables are represented as Vim |Dictionary| type with keys
7730 converted to strings.
7731 All other types are converted to string with display function.
7732 Examples: >
7733 :mz (define l (list 1 2 3))
7734 :mz (define h (make-hash)) (hash-set! h "list" l)
7735 :echo mzeval("l")
7736 :echo mzeval("h")
7737<
7738 Note that in a `:def` function local variables are not visible
7739 to {expr}.
7740
7741 Can also be used as a |method|: >
7742 GetExpr()->mzeval()
7743<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007744 Return type: any, depending on {expr}
7745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007746 {only available when compiled with the |+mzscheme| feature}
7747
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007749nextnonblank({lnum}) *nextnonblank()*
7750 Return the line number of the first line at or below {lnum}
7751 that is not blank. Example: >
7752 if getline(nextnonblank(1)) =~ "Java"
7753< When {lnum} is invalid or there is no non-blank line at or
7754 below it, zero is returned.
7755 {lnum} is used like with |getline()|.
7756 See also |prevnonblank()|.
7757
7758 Can also be used as a |method|: >
7759 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007760<
7761 Return type: |Number|
7762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007763
Christ van Willegenc0786752025-02-01 15:42:16 +01007764ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7765 Return a string that contains the correct value for a
7766 message based on the rules for plural form(s) in
7767 a language. Examples: >
7768 ngettext("File", "Files", 2) # returns "Files"
7769<
7770 Can be used as a |method|: >
7771 1->ngettext("File", "Files") # returns "File"
7772<
7773 See |gettext()| for information on the domain parameter.
7774
7775 Return type: |String|
7776
7777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007778nr2char({expr} [, {utf8}]) *nr2char()*
7779 Return a string with a single character, which has the number
7780 value {expr}. Examples: >
7781 nr2char(64) returns "@"
7782 nr2char(32) returns " "
7783< When {utf8} is omitted or zero, the current 'encoding' is used.
7784 Example for "utf-8": >
7785 nr2char(300) returns I with bow character
7786< When {utf8} is TRUE, always return UTF-8 characters.
7787 Note that a NUL character in the file is specified with
7788 nr2char(10), because NULs are represented with newline
7789 characters. nr2char(0) is a real NUL and terminates the
7790 string, thus results in an empty string.
7791 To turn a list of character numbers into a string: >
7792 let list = [65, 66, 67]
7793 let str = join(map(list, {_, val -> nr2char(val)}), '')
7794< Result: "ABC"
7795
7796 Can also be used as a |method|: >
7797 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007798<
7799 Return type: |String|
7800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007801
7802or({expr}, {expr}) *or()*
7803 Bitwise OR on the two arguments. The arguments are converted
7804 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007805 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007806 Example: >
7807 :let bits = or(bits, 0x80)
7808< Can also be used as a |method|: >
7809 :let bits = bits->or(0x80)
7810
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007811< Rationale: The reason this is a function and not using the "|"
7812 character like many languages, is that Vi has always used "|"
7813 to separate commands. In many places it would not be clear if
7814 "|" is an operator or a command separator.
7815
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007816 Return type: |Number|
7817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007818
7819pathshorten({path} [, {len}]) *pathshorten()*
7820 Shorten directory names in the path {path} and return the
7821 result. The tail, the file name, is kept as-is. The other
7822 components in the path are reduced to {len} letters in length.
7823 If {len} is omitted or smaller than 1 then 1 is used (single
7824 letters). Leading '~' and '.' characters are kept. Examples: >
7825 :echo pathshorten('~/.vim/autoload/myfile.vim')
7826< ~/.v/a/myfile.vim ~
7827>
7828 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7829< ~/.vi/au/myfile.vim ~
7830 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007831 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007832
7833 Can also be used as a |method|: >
7834 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007835<
7836 Return type: |String|
7837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007838
7839perleval({expr}) *perleval()*
7840 Evaluate Perl expression {expr} in scalar context and return
7841 its result converted to Vim data structures. If value can't be
7842 converted, it is returned as a string Perl representation.
7843 Note: If you want an array or hash, {expr} must return a
7844 reference to it.
7845 Example: >
7846 :echo perleval('[1 .. 4]')
7847< [1, 2, 3, 4]
7848
7849 Note that in a `:def` function local variables are not visible
7850 to {expr}.
7851
7852 Can also be used as a |method|: >
7853 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007854<
7855 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007856
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007857 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007858
7859
7860popup_ functions are documented here: |popup-functions|
7861
7862
7863pow({x}, {y}) *pow()*
7864 Return the power of {x} to the exponent {y} as a |Float|.
7865 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007866 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007867 Examples: >
7868 :echo pow(3, 3)
7869< 27.0 >
7870 :echo pow(2, 16)
7871< 65536.0 >
7872 :echo pow(32, 0.20)
7873< 2.0
7874
7875 Can also be used as a |method|: >
7876 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007877<
7878 Return type: |Number|
7879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007880
7881prevnonblank({lnum}) *prevnonblank()*
7882 Return the line number of the first line at or above {lnum}
7883 that is not blank. Example: >
7884 let ind = indent(prevnonblank(v:lnum - 1))
7885< When {lnum} is invalid or there is no non-blank line at or
7886 above it, zero is returned.
7887 {lnum} is used like with |getline()|.
7888 Also see |nextnonblank()|.
7889
7890 Can also be used as a |method|: >
7891 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007892<
7893 Return type: |Number|
7894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007895
7896printf({fmt}, {expr1} ...) *printf()*
7897 Return a String with {fmt}, where "%" items are replaced by
7898 the formatted form of their respective arguments. Example: >
7899 printf("%4d: E%d %.30s", lnum, errno, msg)
7900< May result in:
7901 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7902
7903 When used as a |method| the base is passed as the second
7904 argument: >
7905 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007906<
7907 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007908
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007909 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007910 %s string
7911 %6S string right-aligned in 6 display cells
7912 %6s string right-aligned in 6 bytes
7913 %.9s string truncated to 9 bytes
7914 %c single byte
7915 %d decimal number
7916 %5d decimal number padded with spaces to 5 characters
7917 %x hex number
7918 %04x hex number padded with zeros to at least 4 characters
7919 %X hex number using upper case letters
7920 %o octal number
7921 %08b binary number padded with zeros to at least 8 chars
7922 %f floating point number as 12.23, inf, -inf or nan
7923 %F floating point number as 12.23, INF, -INF or NAN
7924 %e floating point number as 1.23e3, inf, -inf or nan
7925 %E floating point number as 1.23E3, INF, -INF or NAN
7926 %g floating point number, as %f or %e depending on value
7927 %G floating point number, as %F or %E depending on value
7928 %% the % character itself
7929
7930 Conversion specifications start with '%' and end with the
7931 conversion type. All other characters are copied unchanged to
7932 the result.
7933
7934 The "%" starts a conversion specification. The following
7935 arguments appear in sequence:
7936
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007937 % [pos-argument] [flags] [field-width] [.precision] type
7938
7939 pos-argument
7940 At most one positional argument specifier. These
7941 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007942
7943 flags
7944 Zero or more of the following flags:
7945
7946 # The value should be converted to an "alternate
7947 form". For c, d, and s conversions, this option
7948 has no effect. For o conversions, the precision
7949 of the number is increased to force the first
7950 character of the output string to a zero (except
7951 if a zero value is printed with an explicit
7952 precision of zero).
7953 For b and B conversions, a non-zero result has
7954 the string "0b" (or "0B" for B conversions)
7955 prepended to it.
7956 For x and X conversions, a non-zero result has
7957 the string "0x" (or "0X" for X conversions)
7958 prepended to it.
7959
7960 0 (zero) Zero padding. For all conversions the converted
7961 value is padded on the left with zeros rather
7962 than blanks. If a precision is given with a
7963 numeric conversion (d, b, B, o, x, and X), the 0
7964 flag is ignored.
7965
7966 - A negative field width flag; the converted value
7967 is to be left adjusted on the field boundary.
7968 The converted value is padded on the right with
7969 blanks, rather than on the left with blanks or
7970 zeros. A - overrides a 0 if both are given.
7971
7972 ' ' (space) A blank should be left before a positive
7973 number produced by a signed conversion (d).
7974
7975 + A sign must always be placed before a number
7976 produced by a signed conversion. A + overrides
7977 a space if both are used.
7978
7979 field-width
7980 An optional decimal digit string specifying a minimum
7981 field width. If the converted value has fewer bytes
7982 than the field width, it will be padded with spaces on
7983 the left (or right, if the left-adjustment flag has
7984 been given) to fill out the field width. For the S
7985 conversion the count is in cells.
7986
7987 .precision
7988 An optional precision, in the form of a period '.'
7989 followed by an optional digit string. If the digit
7990 string is omitted, the precision is taken as zero.
7991 This gives the minimum number of digits to appear for
7992 d, o, x, and X conversions, the maximum number of
7993 bytes to be printed from a string for s conversions,
7994 or the maximum number of cells to be printed from a
7995 string for S conversions.
7996 For floating point it is the number of digits after
7997 the decimal point.
7998
7999 type
8000 A character that specifies the type of conversion to
8001 be applied, see below.
8002
8003 A field width or precision, or both, may be indicated by an
8004 asterisk '*' instead of a digit string. In this case, a
8005 Number argument supplies the field width or precision. A
8006 negative field width is treated as a left adjustment flag
8007 followed by a positive field width; a negative precision is
8008 treated as though it were missing. Example: >
8009 :echo printf("%d: %.*s", nr, width, line)
8010< This limits the length of the text used from "line" to
8011 "width" bytes.
8012
Dominique Pellé17dca3c2023-12-14 20:36:32 +01008013 If the argument to be formatted is specified using a
8014 positional argument specifier, and a '*' is used to indicate
8015 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008016 precision, the argument(s) to be used must also be specified
8017 using a {n$} positional argument specifier. See |printf-$|.
8018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019 The conversion specifiers and their meanings are:
8020
8021 *printf-d* *printf-b* *printf-B* *printf-o*
8022 *printf-x* *printf-X*
8023 dbBoxX The Number argument is converted to signed decimal
8024 (d), unsigned binary (b and B), unsigned octal (o), or
8025 unsigned hexadecimal (x and X) notation. The letters
8026 "abcdef" are used for x conversions; the letters
8027 "ABCDEF" are used for X conversions.
8028 The precision, if any, gives the minimum number of
8029 digits that must appear; if the converted value
8030 requires fewer digits, it is padded on the left with
8031 zeros.
8032 In no case does a non-existent or small field width
8033 cause truncation of a numeric field; if the result of
8034 a conversion is wider than the field width, the field
8035 is expanded to contain the conversion result.
8036 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02008037 The 'l' modifier indicates the argument is a long
8038 integer. The size will be 32 bits or 64 bits
8039 depending on your platform.
8040 The "ll" modifier indicates the argument is 64 bits.
8041 The b and B conversion specifiers never take a width
8042 modifier and always assume their argument is a 64 bit
8043 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008044 Generally, these modifiers are not useful. They are
8045 ignored when type is known from the argument.
8046
8047 i alias for d
8048 D alias for ld
8049 U alias for lu
8050 O alias for lo
8051
8052 *printf-c*
8053 c The Number argument is converted to a byte, and the
8054 resulting character is written.
8055
8056 *printf-s*
8057 s The text of the String argument is used. If a
8058 precision is specified, no more bytes than the number
8059 specified are used.
8060 If the argument is not a String type, it is
8061 automatically converted to text with the same format
8062 as ":echo".
8063 *printf-S*
8064 S The text of the String argument is used. If a
8065 precision is specified, no more display cells than the
8066 number specified are used.
8067
8068 *printf-f* *E807*
8069 f F The Float argument is converted into a string of the
8070 form 123.456. The precision specifies the number of
8071 digits after the decimal point. When the precision is
8072 zero the decimal point is omitted. When the precision
8073 is not specified 6 is used. A really big number
8074 (out of range or dividing by zero) results in "inf"
8075 or "-inf" with %f (INF or -INF with %F).
8076 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8077 Example: >
8078 echo printf("%.2f", 12.115)
8079< 12.12
8080 Note that roundoff depends on the system libraries.
8081 Use |round()| when in doubt.
8082
8083 *printf-e* *printf-E*
8084 e E The Float argument is converted into a string of the
8085 form 1.234e+03 or 1.234E+03 when using 'E'. The
8086 precision specifies the number of digits after the
8087 decimal point, like with 'f'.
8088
8089 *printf-g* *printf-G*
8090 g G The Float argument is converted like with 'f' if the
8091 value is between 0.001 (inclusive) and 10000000.0
8092 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8093 for 'G'. When no precision is specified superfluous
8094 zeroes and '+' signs are removed, except for the zero
8095 immediately after the decimal point. Thus 10000000.0
8096 results in 1.0e7.
8097
8098 *printf-%*
8099 % A '%' is written. No argument is converted. The
8100 complete conversion specification is "%%".
8101
8102 When a Number argument is expected a String argument is also
8103 accepted and automatically converted.
8104 When a Float or String argument is expected a Number argument
8105 is also accepted and automatically converted.
8106 Any other argument type results in an error message.
8107
8108 *E766* *E767*
8109 The number of {exprN} arguments must exactly match the number
8110 of "%" items. If there are not sufficient or too many
8111 arguments an error is given. Up to 18 arguments can be used.
8112
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008113 *printf-$*
8114 In certain languages, error and informative messages are
8115 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008116 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008117 having a different word order, positional arguments may be
8118 used to indicate this. For instance: >
8119
h_east596a9f22023-11-21 21:24:23 +09008120 #, c-format
8121 msgid "%s returning %s"
8122 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008123<
h_east596a9f22023-11-21 21:24:23 +09008124 In this example, the sentence has its 2 string arguments
8125 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008126
h_east596a9f22023-11-21 21:24:23 +09008127 echo printf(
8128 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8129 "Bram", "Moolenaar")
8130< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008131
h_east596a9f22023-11-21 21:24:23 +09008132 echo printf(
8133 "In Belgium, vim's creator's name is: %2$s %1$s",
8134 "Bram", "Moolenaar")
8135< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008136
8137 Width (and precision) can be specified using the '*' specifier.
8138 In this case, you must specify the field width position in the
8139 argument list. >
8140
h_east596a9f22023-11-21 21:24:23 +09008141 echo printf("%1$*2$.*3$d", 1, 2, 3)
8142< 001 >
8143 echo printf("%2$*3$.*1$d", 1, 2, 3)
8144< 2 >
8145 echo printf("%3$*1$.*2$d", 1, 2, 3)
8146< 03 >
8147 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8148< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008149
8150 You can mix specifying the width and/or precision directly
8151 and via positional arguments: >
8152
h_east596a9f22023-11-21 21:24:23 +09008153 echo printf("%1$4.*2$f", 1.4142135, 6)
8154< 1.414214 >
8155 echo printf("%1$*2$.4f", 1.4142135, 6)
8156< 1.4142 >
8157 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8158< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008159
Christ van Willegenc35fc032024-03-14 18:30:41 +01008160 You will get an overflow error |E1510|, when the field-width
8161 or precision will result in a string longer than 6400 chars.
8162
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008163 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008164 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008165 echo printf("%s%1$s", "One", "Two")
8166< E1500: Cannot mix positional and non-positional arguments:
8167 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008168
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008169 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008170 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008171 echo printf("%3$s%1$s", "One", "Two", "Three")
8172< E1501: format argument 2 unused in $-style format:
8173 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008174
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008175 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008176 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008177 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8178< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008179
8180 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008181 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8182< E1502: Positional argument 2 used as field width reused as
8183 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008184
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008185 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008186 When a positional argument is used, but not the correct number
8187 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008188 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8189< E1503: Positional argument 3 out of bounds: %1$d at width
8190 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008191
8192 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008193 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8194< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8195 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008196
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008197 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008198 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008199 echo printf("%1$s %2$s %1$s", "One", "Two")
8200< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008201
8202 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008203 echo printf("%1$s %2$s %1$d", "One", "Two")
8204< E1504: Positional argument 1 type used inconsistently:
8205 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008206
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008207 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008208 Various other errors that lead to a format string being
8209 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008210 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8211< E1505: Invalid format specifier: %1$d at width %2$d is:
8212 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008213
Christ van Willegenea746f92023-10-05 20:48:36 +02008214 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008215 This internal error indicates that the logic to parse a
8216 positional format argument ran into a problem that couldn't be
8217 otherwise reported. Please file a bug against Vim if you run
8218 into this, copying the exact format string and parameters that
8219 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008220
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008221 Return type: |String|
8222
Christ van Willegenea746f92023-10-05 20:48:36 +02008223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008224prompt_getprompt({buf}) *prompt_getprompt()*
8225 Returns the effective prompt text for buffer {buf}. {buf} can
8226 be a buffer name or number. See |prompt-buffer|.
8227
8228 If the buffer doesn't exist or isn't a prompt buffer, an empty
8229 string is returned.
8230
8231 Can also be used as a |method|: >
8232 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008233<
8234 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008236 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008237
8238
8239prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8240 Set prompt callback for buffer {buf} to {expr}. When {expr}
8241 is an empty string the callback is removed. This has only
8242 effect if {buf} has 'buftype' set to "prompt".
8243
8244 The callback is invoked when pressing Enter. The current
8245 buffer will always be the prompt buffer. A new line for a
8246 prompt is added before invoking the callback, thus the prompt
8247 for which the callback was invoked will be in the last but one
8248 line.
8249 If the callback wants to add text to the buffer, it must
8250 insert it above the last line, since that is where the current
8251 prompt is. This can also be done asynchronously.
8252 The callback is invoked with one argument, which is the text
8253 that was entered at the prompt. This can be an empty string
8254 if the user only typed Enter.
8255 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008256 func s:TextEntered(text)
8257 if a:text == 'exit' || a:text == 'quit'
8258 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008259 " Reset 'modified' to allow the buffer to be closed.
8260 " We assume there is nothing useful to be saved.
8261 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008262 close
8263 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008264 " Do something useful with "a:text". In this example
8265 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008266 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008267 endif
8268 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008269 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008270
8271< Can also be used as a |method|: >
8272 GetBuffer()->prompt_setcallback(callback)
8273
8274< {only available when compiled with the |+channel| feature}
8275
8276prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8277 Set a callback for buffer {buf} to {expr}. When {expr} is an
8278 empty string the callback is removed. This has only effect if
8279 {buf} has 'buftype' set to "prompt".
8280
8281 This callback will be invoked when pressing CTRL-C in Insert
8282 mode. Without setting a callback Vim will exit Insert mode,
8283 as in any buffer.
8284
8285 Can also be used as a |method|: >
8286 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008287<
8288 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008289
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008290 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008291
8292prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8293 Set prompt for buffer {buf} to {text}. You most likely want
8294 {text} to end in a space.
8295 The result is only visible if {buf} has 'buftype' set to
8296 "prompt". Example: >
8297 call prompt_setprompt(bufnr(), 'command: ')
8298<
8299 Can also be used as a |method|: >
8300 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008301<
8302 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008303
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008304 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008305
8306prop_ functions are documented here: |text-prop-functions|
8307
8308pum_getpos() *pum_getpos()*
8309 If the popup menu (see |ins-completion-menu|) is not visible,
8310 returns an empty |Dictionary|, otherwise, returns a
8311 |Dictionary| with the following keys:
8312 height nr of items visible
8313 width screen cells
8314 row top screen row (0 first row)
8315 col leftmost screen column (0 first col)
8316 size total nr of items
8317 scrollbar |TRUE| if scrollbar is visible
8318
8319 The values are the same as in |v:event| during
8320 |CompleteChanged|.
8321
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008322 Return type: dict<any>
8323
8324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008325pumvisible() *pumvisible()*
8326 Returns non-zero when the popup menu is visible, zero
8327 otherwise. See |ins-completion-menu|.
8328 This can be used to avoid some things that would remove the
8329 popup menu.
8330
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008331 Return type: |Number|
8332
8333
zeertzjq7c515282024-11-10 20:26:12 +01008334py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335 Evaluate Python expression {expr} and return its result
8336 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008337 If a {locals} |Dictionary| is given, it defines set of local
8338 variables available in the expression. The keys are variable
8339 names and the values are the variable values. |Dictionary| and
8340 |List| values are referenced, and may be updated by the
8341 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008342 Numbers and strings are returned as they are (strings are
8343 copied though, Unicode strings are additionally converted to
8344 'encoding').
8345 Lists are represented as Vim |List| type.
8346 Dictionaries are represented as Vim |Dictionary| type with
8347 keys converted to strings.
8348 Note that in a `:def` function local variables are not visible
8349 to {expr}.
8350
8351 Can also be used as a |method|: >
8352 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008353 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008354<
8355 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008356
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008357 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008358
8359 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008360pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008361 Evaluate Python expression {expr} and return its result
8362 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008363 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008364 Numbers and strings are returned as they are (strings are
8365 copied though).
8366 Lists are represented as Vim |List| type.
8367 Dictionaries are represented as Vim |Dictionary| type,
8368 non-string keys result in error.
8369 Note that in a `:def` function local variables are not visible
8370 to {expr}.
8371
8372 Can also be used as a |method|: >
8373 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008374<
8375 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008376
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008377 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008378
zeertzjq7c515282024-11-10 20:26:12 +01008379pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008380 Evaluate Python expression {expr} and return its result
8381 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008382 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008383 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8384 See also: |pyeval()|, |py3eval()|
8385
8386 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008387 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008388<
8389 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008390
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008391 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008392 |+python3| feature}
8393
8394rand([{expr}]) *rand()* *random*
8395 Return a pseudo-random Number generated with an xoshiro128**
8396 algorithm using seed {expr}. The returned number is 32 bits,
8397 also on 64 bits systems, for consistency.
8398 {expr} can be initialized by |srand()| and will be updated by
8399 rand(). If {expr} is omitted, an internal seed value is used
8400 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008401 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008402
8403 Examples: >
8404 :echo rand()
8405 :let seed = srand()
8406 :echo rand(seed)
8407 :echo rand(seed) % 16 " random number 0 - 15
8408<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008409 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008410
8411 *E726* *E727*
8412range({expr} [, {max} [, {stride}]]) *range()*
8413 Returns a |List| with Numbers:
8414 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8415 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8416 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8417 {max}] (increasing {expr} with {stride} each time, not
8418 producing a value past {max}).
8419 When the maximum is one before the start the result is an
8420 empty list. When the maximum is more than one before the
8421 start this is an error.
8422 Examples: >
8423 range(4) " [0, 1, 2, 3]
8424 range(2, 4) " [2, 3, 4]
8425 range(2, 9, 3) " [2, 5, 8]
8426 range(2, -2, -1) " [2, 1, 0, -1, -2]
8427 range(0) " []
8428 range(2, 0) " error!
8429<
8430 Can also be used as a |method|: >
8431 GetExpr()->range()
8432<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008433 Return type: list<number>
8434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008435
K.Takata11df3ae2022-10-19 14:02:40 +01008436readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008437 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008438 If {offset} is specified, read the file from the specified
8439 offset. If it is a negative value, it is used as an offset
8440 from the end of the file. E.g., to read the last 12 bytes: >
8441 readblob('file.bin', -12)
8442< If {size} is specified, only the specified size will be read.
8443 E.g. to read the first 100 bytes of a file: >
8444 readblob('file.bin', 0, 100)
8445< If {size} is -1 or omitted, the whole data starting from
8446 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008447 This can be also used to read the data from a character device
8448 on Unix when {size} is explicitly set. Only if the device
8449 supports seeking {offset} can be used. Otherwise it should be
8450 zero. E.g. to read 10 bytes from a serial console: >
8451 readblob('/dev/ttyS0', 0, 10)
8452< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008453 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008454 When the offset is beyond the end of the file the result is an
8455 empty blob.
8456 When trying to read more bytes than are available the result
8457 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008458 Also see |readfile()| and |writefile()|.
8459
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008460 Return type: |Blob|
8461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008462
8463readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8464 Return a list with file and directory names in {directory}.
8465 You can also use |glob()| if you don't need to do complicated
8466 things, such as limiting the number of matches.
8467 The list will be sorted (case sensitive), see the {dict}
8468 argument below for changing the sort order.
8469
8470 When {expr} is omitted all entries are included.
8471 When {expr} is given, it is evaluated to check what to do:
8472 If {expr} results in -1 then no further entries will
8473 be handled.
8474 If {expr} results in 0 then this entry will not be
8475 added to the list.
8476 If {expr} results in 1 then this entry will be added
8477 to the list.
8478 The entries "." and ".." are always excluded.
8479 Each time {expr} is evaluated |v:val| is set to the entry name.
8480 When {expr} is a function the name is passed as the argument.
8481 For example, to get a list of files ending in ".txt": >
8482 readdir(dirname, {n -> n =~ '.txt$'})
8483< To skip hidden and backup files: >
8484 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008485< *E857*
8486 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008487 values. Currently this is used to specify if and how sorting
8488 should be performed. The dict can have the following members:
8489
8490 sort How to sort the result returned from the system.
8491 Valid values are:
8492 "none" do not sort (fastest method)
8493 "case" sort case sensitive (byte value of
8494 each character, technically, using
8495 strcmp()) (default)
8496 "icase" sort case insensitive (technically
8497 using strcasecmp())
8498 "collate" sort using the collation order
8499 of the "POSIX" or "C" |locale|
8500 (technically using strcoll())
8501 Other values are silently ignored.
8502
8503 For example, to get a list of all files in the current
8504 directory without sorting the individual entries: >
8505 readdir('.', '1', #{sort: 'none'})
8506< If you want to get a directory tree: >
8507 function! s:tree(dir)
8508 return {a:dir : map(readdir(a:dir),
8509 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008510 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008511 endfunction
8512 echo s:tree(".")
8513<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008514 Returns an empty List on error.
8515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008516 Can also be used as a |method|: >
8517 GetDirName()->readdir()
8518<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008519 Return type: list<string> or list<any>
8520
8521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008522readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8523 Extended version of |readdir()|.
8524 Return a list of Dictionaries with file and directory
8525 information in {directory}.
8526 This is useful if you want to get the attributes of file and
8527 directory at the same time as getting a list of a directory.
8528 This is much faster than calling |readdir()| then calling
8529 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8530 each file and directory especially on MS-Windows.
8531 The list will by default be sorted by name (case sensitive),
8532 the sorting can be changed by using the optional {dict}
8533 argument, see |readdir()|.
8534
8535 The Dictionary for file and directory information has the
8536 following items:
8537 group Group name of the entry. (Only on Unix)
8538 name Name of the entry.
8539 perm Permissions of the entry. See |getfperm()|.
8540 size Size of the entry. See |getfsize()|.
8541 time Timestamp of the entry. See |getftime()|.
8542 type Type of the entry.
8543 On Unix, almost same as |getftype()| except:
8544 Symlink to a dir "linkd"
8545 Other symlink "link"
8546 On MS-Windows:
8547 Normal file "file"
8548 Directory "dir"
8549 Junction "junction"
8550 Symlink to a dir "linkd"
8551 Other symlink "link"
8552 Other reparse point "reparse"
8553 user User name of the entry's owner. (Only on Unix)
8554 On Unix, if the entry is a symlink, the Dictionary includes
8555 the information of the target (except the "type" item).
8556 On MS-Windows, it includes the information of the symlink
8557 itself because of performance reasons.
8558
8559 When {expr} is omitted all entries are included.
8560 When {expr} is given, it is evaluated to check what to do:
8561 If {expr} results in -1 then no further entries will
8562 be handled.
8563 If {expr} results in 0 then this entry will not be
8564 added to the list.
8565 If {expr} results in 1 then this entry will be added
8566 to the list.
8567 The entries "." and ".." are always excluded.
8568 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8569 of the entry.
8570 When {expr} is a function the entry is passed as the argument.
8571 For example, to get a list of files ending in ".txt": >
8572 readdirex(dirname, {e -> e.name =~ '.txt$'})
8573<
8574 For example, to get a list of all files in the current
8575 directory without sorting the individual entries: >
8576 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008577<
8578 Can also be used as a |method|: >
8579 GetDirName()->readdirex()
8580<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008581 Return type: list<dict<any>> or list<any>
8582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008583
8584 *readfile()*
8585readfile({fname} [, {type} [, {max}]])
8586 Read file {fname} and return a |List|, each line of the file
8587 as an item. Lines are broken at NL characters. Macintosh
8588 files separated with CR will result in a single long line
8589 (unless a NL appears somewhere).
8590 All NUL characters are replaced with a NL character.
8591 When {type} contains "b" binary mode is used:
8592 - When the last line ends in a NL an extra empty list item is
8593 added.
8594 - No CR characters are removed.
8595 Otherwise:
8596 - CR characters that appear before a NL are removed.
8597 - Whether the last line ends in a NL or not does not matter.
8598 - When 'encoding' is Unicode any UTF-8 byte order mark is
8599 removed from the text.
8600 When {max} is given this specifies the maximum number of lines
8601 to be read. Useful if you only want to check the first ten
8602 lines of a file: >
8603 :for line in readfile(fname, '', 10)
8604 : if line =~ 'Date' | echo line | endif
8605 :endfor
8606< When {max} is negative -{max} lines from the end of the file
8607 are returned, or as many as there are.
8608 When {max} is zero the result is an empty list.
8609 Note that without {max} the whole file is read into memory.
8610 Also note that there is no recognition of encoding. Read a
8611 file into a buffer if you need to.
8612 Deprecated (use |readblob()| instead): When {type} contains
8613 "B" a |Blob| is returned with the binary data of the file
8614 unmodified.
8615 When the file can't be opened an error message is given and
8616 the result is an empty list.
8617 Also see |writefile()|.
8618
8619 Can also be used as a |method|: >
8620 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621<
8622 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008623
8624reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8625 {func} is called for every item in {object}, which can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008626 |String|, |List|, |Tuple| or a |Blob|. {func} is called with
8627 two arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008628 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008629
8630 {initial} is the initial result. When omitted, the first item
8631 in {object} is used and {func} is first called for the second
8632 item. If {initial} is not given and {object} is empty no
8633 result can be computed, an E998 error is given.
8634
8635 Examples: >
8636 echo reduce([1, 3, 5], { acc, val -> acc + val })
8637 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8638 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8639 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8640<
8641 Can also be used as a |method|: >
8642 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008643<
8644 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8645 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008646
8647
8648reg_executing() *reg_executing()*
8649 Returns the single letter name of the register being executed.
8650 Returns an empty string when no register is being executed.
8651 See |@|.
8652
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008653 Return type: |String|
8654
8655
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008656reg_recording() *reg_recording()*
8657 Returns the single letter name of the register being recorded.
8658 Returns an empty string when not recording. See |q|.
8659
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008660 Return type: |String|
8661
8662
8663reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008664reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008665reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008666 Return an item that represents a time value. The item is a
8667 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008668 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008669 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008670 string or |reltimefloat()| to convert to a Float. For
8671 example, to see the time spent in function Work(): >
8672 var startTime = reltime()
8673 Work()
8674 echo startTime->reltime()->reltimestr()
8675<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008676 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008677 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008678 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008679 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008680 specified in the argument.
8681 With two arguments it returns the time passed between {start}
8682 and {end}.
8683
8684 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008685 reltime(). If there is an error an empty List is returned in
8686 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008687
8688 Can also be used as a |method|: >
8689 GetStart()->reltime()
8690<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008691 Return type: list<number>
8692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008693 {only available when compiled with the |+reltime| feature}
8694
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008696reltimefloat({time}) *reltimefloat()*
8697 Return a Float that represents the time value of {time}.
8698 Example: >
8699 let start = reltime()
8700 call MyFunction()
8701 let seconds = reltimefloat(reltime(start))
8702< See the note of reltimestr() about overhead.
8703 Also see |profiling|.
8704 If there is an error 0.0 is returned in legacy script, in Vim9
8705 script an error is given.
8706
8707 Can also be used as a |method|: >
8708 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008709<
8710 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008711
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008712 {only available when compiled with the |+reltime| feature}
8713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008714
8715reltimestr({time}) *reltimestr()*
8716 Return a String that represents the time value of {time}.
8717 This is the number of seconds, a dot and the number of
8718 microseconds. Example: >
8719 let start = reltime()
8720 call MyFunction()
8721 echo reltimestr(reltime(start))
8722< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008723 The accuracy depends on the system. Use reltimefloat() for the
8724 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008725 Leading spaces are used to make the string align nicely. You
8726 can use split() to remove it. >
8727 echo split(reltimestr(reltime(start)))[0]
8728< Also see |profiling|.
8729 If there is an error an empty string is returned in legacy
8730 script, in Vim9 script an error is given.
8731
8732 Can also be used as a |method|: >
8733 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008734<
8735 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008737 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008738
8739 *remote_expr()* *E449*
8740remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008741 Send the {string} to {server}. The {server} argument is a
8742 string, also see |{server}|.
8743
8744 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008745 after evaluation. The result must be a String or a |List|
8746 other types will be converted to String. A |List| is turned
8747 into a String by joining the items with a line break in
8748 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008750 If {idvar} is present and not empty, it is taken as the name
8751 of a variable and a {serverid} for later use with
8752 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008754 If {timeout} is given the read times out after this many
8755 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008757 See also |clientserver| |RemoteReply|.
8758 This function is not available in the |sandbox|.
8759 {only available when compiled with the |+clientserver| feature}
8760 Note: Any errors will cause a local error message to be issued
8761 and the result will be the empty string.
8762
8763 Variables will be evaluated in the global namespace,
8764 independent of a function currently being active. Except
8765 when in debug mode, then local function variables and
8766 arguments can be evaluated.
8767
8768 Examples: >
8769 :echo remote_expr("gvim", "2+2")
8770 :echo remote_expr("gvim1", "b:current_syntax")
8771<
8772 Can also be used as a |method|: >
8773 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008774<
8775 Return type: |String| or list<{type}>
8776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008777
8778remote_foreground({server}) *remote_foreground()*
8779 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008780 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008781 This works like: >
8782 remote_expr({server}, "foreground()")
8783< Except that on Win32 systems the client does the work, to work
8784 around the problem that the OS doesn't always allow the server
8785 to bring itself to the foreground.
8786 Note: This does not restore the window if it was minimized,
8787 like foreground() does.
8788 This function is not available in the |sandbox|.
8789
8790 Can also be used as a |method|: >
8791 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008792<
8793 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008794
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008795 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008796 Win32 console version}
8797
8798
8799remote_peek({serverid} [, {retvar}]) *remote_peek()*
8800 Returns a positive number if there are available strings
8801 from {serverid}. Copies any reply string into the variable
8802 {retvar} if specified. {retvar} must be a string with the
8803 name of a variable.
8804 Returns zero if none are available.
8805 Returns -1 if something is wrong.
8806 See also |clientserver|.
8807 This function is not available in the |sandbox|.
8808 {only available when compiled with the |+clientserver| feature}
8809 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008810 :let repl = ""
8811 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008812
8813< Can also be used as a |method|: >
8814 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008815<
8816 Return type: |Number|
8817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008818
8819remote_read({serverid}, [{timeout}]) *remote_read()*
8820 Return the oldest available reply from {serverid} and consume
8821 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008822 reply is available. Returns an empty string, if a reply is
8823 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008824 See also |clientserver|.
8825 This function is not available in the |sandbox|.
8826 {only available when compiled with the |+clientserver| feature}
8827 Example: >
8828 :echo remote_read(id)
8829
8830< Can also be used as a |method|: >
8831 ServerId()->remote_read()
8832<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008833 Return type: |String|
8834
8835
8836remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008837 Send the {string} to {server}. The {server} argument is a
8838 string, also see |{server}|.
8839
8840 The string is sent as input keys and the function returns
8841 immediately. At the Vim server the keys are not mapped
8842 |:map|.
8843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008844 If {idvar} is present, it is taken as the name of a variable
8845 and a {serverid} for later use with remote_read() is stored
8846 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008848 See also |clientserver| |RemoteReply|.
8849 This function is not available in the |sandbox|.
8850 {only available when compiled with the |+clientserver| feature}
8851
8852 Note: Any errors will be reported in the server and may mess
8853 up the display.
8854 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008855 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008856 \ remote_read(serverid)
8857
8858 :autocmd NONE RemoteReply *
8859 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008860 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008861 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8862<
8863 Can also be used as a |method|: >
8864 ServerName()->remote_send(keys)
8865<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008866 Return type: |String|
8867
8868
8869remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008870 Become the server {name}. {name} must be a non-empty string.
8871 This fails if already running as a server, when |v:servername|
8872 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008873
8874 Can also be used as a |method|: >
8875 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008876<
8877 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008878
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008879 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008880
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008881
8882remove({list}, {idx}) *remove()*
8883remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008884 Without {end}: Remove the item at {idx} from |List| {list} and
8885 return the item.
8886 With {end}: Remove items from {idx} to {end} (inclusive) and
8887 return a |List| with these items. When {idx} points to the same
8888 item as {end} a list with one item is returned. When {end}
8889 points to an item before {idx} this is an error.
8890 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008891 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008892 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008893 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008894 :call remove(mylist, 0, 9)
8895<
8896 Use |delete()| to remove a file.
8897
8898 Can also be used as a |method|: >
8899 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008900<
8901 Return type: any, depending on {list}
8902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008903
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008904remove({blob}, {idx})
8905remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008906 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8907 return the byte.
8908 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8909 return a |Blob| with these bytes. When {idx} points to the same
8910 byte as {end} a |Blob| with one byte is returned. When {end}
8911 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008912 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008913 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008914 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008915 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008916<
8917 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008918
8919remove({dict}, {key})
8920 Remove the entry from {dict} with key {key} and return it.
8921 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008922 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008923< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008924 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008925
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008926 Return type: any, depending on {dict}
8927
8928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008929rename({from}, {to}) *rename()*
8930 Rename the file by the name {from} to the name {to}. This
8931 should also work to move files across file systems. The
8932 result is a Number, which is 0 if the file was renamed
8933 successfully, and non-zero when the renaming failed.
8934 NOTE: If {to} exists it is overwritten without warning.
8935 This function is not available in the |sandbox|.
8936
8937 Can also be used as a |method|: >
8938 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008939<
8940 Return type: |Number|
8941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008942
8943repeat({expr}, {count}) *repeat()*
8944 Repeat {expr} {count} times and return the concatenated
8945 result. Example: >
8946 :let separator = repeat('-', 80)
8947< When {count} is zero or negative the result is empty.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008948 When {expr} is a |List|, a |Tuple| or a |Blob| the result is
8949 {expr} concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008950 :let longlist = repeat(['a', 'b'], 3)
8951< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8952
8953 Can also be used as a |method|: >
8954 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008955<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008956 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
8957 depending on {expr}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008959
8960resolve({filename}) *resolve()* *E655*
8961 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8962 returns the path the shortcut points to in a simplified form.
8963 When {filename} is a symbolic link or junction point, return
8964 the full path to the target. If the target of junction is
8965 removed, return {filename}.
8966 On Unix, repeat resolving symbolic links in all path
8967 components of {filename} and return the simplified result.
8968 To cope with link cycles, resolving of symbolic links is
8969 stopped after 100 iterations.
8970 On other systems, return the simplified {filename}.
8971 The simplification step is done as by |simplify()|.
8972 resolve() keeps a leading path component specifying the
8973 current directory (provided the result is still a relative
8974 path name) and also keeps a trailing path separator.
8975
8976 Can also be used as a |method|: >
8977 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008978<
8979 Return type: |String|
8980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008981
8982reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008983 Reverse the order of items in {object}. {object} can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008984 |List|, a |Tuple|, a |Blob| or a |String|. For a List and a
8985 Blob the items are reversed in-place and {object} is returned.
8986 For a Tuple, a new Tuple is returned.
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008987 For a String a new String is returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008988 Returns zero if {object} is not a List, Tuple, Blob or a
8989 String. If you want a List or Blob to remain unmodified make
8990 a copy first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008991 :let revlist = reverse(copy(mylist))
8992< Can also be used as a |method|: >
8993 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008994<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008995 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
8996 depending on {object}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008998
8999round({expr}) *round()*
9000 Round off {expr} to the nearest integral value and return it
9001 as a |Float|. If {expr} lies halfway between two integral
9002 values, then use the larger one (away from zero).
9003 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009004 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009005 Examples: >
9006 echo round(0.456)
9007< 0.0 >
9008 echo round(4.5)
9009< 5.0 >
9010 echo round(-4.5)
9011< -5.0
9012
9013 Can also be used as a |method|: >
9014 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009015<
9016 Return type: |Float|
9017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009018
9019rubyeval({expr}) *rubyeval()*
9020 Evaluate Ruby expression {expr} and return its result
9021 converted to Vim data structures.
9022 Numbers, floats and strings are returned as they are (strings
9023 are copied though).
9024 Arrays are represented as Vim |List| type.
9025 Hashes are represented as Vim |Dictionary| type.
9026 Other objects are represented as strings resulted from their
9027 "Object#to_s" method.
9028 Note that in a `:def` function local variables are not visible
9029 to {expr}.
9030
9031 Can also be used as a |method|: >
9032 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009033<
9034 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009035
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009036 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009037
9038screenattr({row}, {col}) *screenattr()*
9039 Like |screenchar()|, but return the attribute. This is a rather
9040 arbitrary number that can only be used to compare to the
9041 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009042 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009043
9044 Can also be used as a |method|: >
9045 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009046<
9047 Return type: |Number|
9048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009049
9050screenchar({row}, {col}) *screenchar()*
9051 The result is a Number, which is the character at position
9052 [row, col] on the screen. This works for every possible
9053 screen position, also status lines, window separators and the
9054 command line. The top left position is row one, column one
9055 The character excludes composing characters. For double-byte
9056 encodings it may only be the first byte.
9057 This is mainly to be used for testing.
9058 Returns -1 when row or col is out of range.
9059
9060 Can also be used as a |method|: >
9061 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009062<
9063 Return type: |Number|
9064
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009065
9066screenchars({row}, {col}) *screenchars()*
9067 The result is a |List| of Numbers. The first number is the same
9068 as what |screenchar()| returns. Further numbers are
9069 composing characters on top of the base character.
9070 This is mainly to be used for testing.
9071 Returns an empty List when row or col is out of range.
9072
9073 Can also be used as a |method|: >
9074 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009075<
9076 Return type: list<number> or list<any>
9077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009078
9079screencol() *screencol()*
9080 The result is a Number, which is the current screen column of
9081 the cursor. The leftmost column has number 1.
9082 This function is mainly used for testing.
9083
9084 Note: Always returns the current screen column, thus if used
9085 in a command (e.g. ":echo screencol()") it will return the
9086 column inside the command line, which is 1 when the command is
9087 executed. To get the cursor position in the file use one of
9088 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009089 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009090 nnoremap <silent> GG :echom screencol()<CR>
9091 nnoremap GG <Cmd>echom screencol()<CR>
9092<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009093 Return type: |Number|
9094
9095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009096screenpos({winid}, {lnum}, {col}) *screenpos()*
9097 The result is a Dict with the screen position of the text
9098 character in window {winid} at buffer line {lnum} and column
9099 {col}. {col} is a one-based byte index.
9100 The Dict has these members:
9101 row screen row
9102 col first screen column
9103 endcol last screen column
9104 curscol cursor screen column
9105 If the specified position is not visible, all values are zero.
9106 The "endcol" value differs from "col" when the character
9107 occupies more than one screen cell. E.g. for a Tab "col" can
9108 be 1 and "endcol" can be 8.
9109 The "curscol" value is where the cursor would be placed. For
9110 a Tab it would be the same as "endcol", while for a double
9111 width character it would be the same as "col".
9112 The |conceal| feature is ignored here, the column numbers are
9113 as if 'conceallevel' is zero. You can set the cursor to the
9114 right position and use |screencol()| to get the value with
9115 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009116 If the position is in a closed fold the screen position of the
9117 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009118 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009119
9120 Can also be used as a |method|: >
9121 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009122<
9123 Return type: dict<number> or dict<any>
9124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009125
9126screenrow() *screenrow()*
9127 The result is a Number, which is the current screen row of the
9128 cursor. The top line has number one.
9129 This function is mainly used for testing.
9130 Alternatively you can use |winline()|.
9131
9132 Note: Same restrictions as with |screencol()|.
9133
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009134 Return type: |Number|
9135
9136
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009137screenstring({row}, {col}) *screenstring()*
9138 The result is a String that contains the base character and
9139 any composing characters at position [row, col] on the screen.
9140 This is like |screenchars()| but returning a String with the
9141 characters.
9142 This is mainly to be used for testing.
9143 Returns an empty String when row or col is out of range.
9144
9145 Can also be used as a |method|: >
9146 GetRow()->screenstring(col)
9147<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009148 Return type: |String|
9149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009150 *search()*
9151search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9152 Search for regexp pattern {pattern}. The search starts at the
9153 cursor position (you can use |cursor()| to set it).
9154
9155 When a match has been found its line number is returned.
9156 If there is no match a 0 is returned and the cursor doesn't
9157 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009158 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009159
9160 {flags} is a String, which can contain these character flags:
9161 'b' search Backward instead of forward
9162 'c' accept a match at the Cursor position
9163 'e' move to the End of the match
9164 'n' do Not move the cursor
9165 'p' return number of matching sub-Pattern (see below)
9166 's' Set the ' mark at the previous location of the cursor
9167 'w' Wrap around the end of the file
9168 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009169 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009170 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9171
9172 If the 's' flag is supplied, the ' mark is set, only if the
9173 cursor is moved. The 's' flag cannot be combined with the 'n'
9174 flag.
9175
9176 'ignorecase', 'smartcase' and 'magic' are used.
9177
9178 When the 'z' flag is not given, forward searching always
9179 starts in column zero and then matches before the cursor are
9180 skipped. When the 'c' flag is present in 'cpo' the next
9181 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009182 search starts one column after the start of the match. This
9183 matters for overlapping matches. See |cpo-c|. You can also
9184 insert "\ze" to change where the match ends, see |/\ze|.
9185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009186 When searching backwards and the 'z' flag is given then the
9187 search starts in column zero, thus no match in the current
9188 line will be found (unless wrapping around the end of the
9189 file).
9190
9191 When the {stopline} argument is given then the search stops
9192 after searching this line. This is useful to restrict the
9193 search to a range of lines. Examples: >
9194 let match = search('(', 'b', line("w0"))
9195 let end = search('END', '', line("w$"))
9196< When {stopline} is used and it is not zero this also implies
9197 that the search does not wrap around the end of the file.
9198 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009199 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009200 When the {timeout} argument is given the search stops when
9201 more than this many milliseconds have passed. Thus when
9202 {timeout} is 500 the search stops after half a second.
9203 The value must not be negative. A zero value is like not
9204 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009205
9206 Note: the timeout is only considered when searching, not
9207 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009208 {only available when compiled with the |+reltime| feature}
9209
9210 If the {skip} expression is given it is evaluated with the
9211 cursor positioned on the start of a match. If it evaluates to
9212 non-zero this match is skipped. This can be used, for
9213 example, to skip a match in a comment or a string.
9214 {skip} can be a string, which is evaluated as an expression, a
9215 function reference or a lambda.
9216 When {skip} is omitted or empty, every match is accepted.
9217 When evaluating {skip} causes an error the search is aborted
9218 and -1 returned.
9219 *search()-sub-match*
9220 With the 'p' flag the returned value is one more than the
9221 first sub-match in \(\). One if none of them matched but the
9222 whole pattern did match.
9223 To get the column number too use |searchpos()|.
9224
9225 The cursor will be positioned at the match, unless the 'n'
9226 flag is used.
9227
9228 Example (goes over all files in the argument list): >
9229 :let n = 1
9230 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009231 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009232 : " start at the last char in the file and wrap for the
9233 : " first search to find match at start of file
9234 : normal G$
9235 : let flags = "w"
9236 : while search("foo", flags) > 0
9237 : s/foo/bar/g
9238 : let flags = "W"
9239 : endwhile
9240 : update " write the file if modified
9241 : let n = n + 1
9242 :endwhile
9243<
9244 Example for using some flags: >
9245 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9246< This will search for the keywords "if", "else", and "endif"
9247 under or after the cursor. Because of the 'p' flag, it
9248 returns 1, 2, or 3 depending on which keyword is found, or 0
9249 if the search fails. With the cursor on the first word of the
9250 line:
9251 if (foo == 0) | let foo = foo + 1 | endif ~
9252 the function returns 1. Without the 'c' flag, the function
9253 finds the "endif" and returns 3. The same thing happens
9254 without the 'e' flag if the cursor is on the "f" of "if".
9255 The 'n' flag tells the function not to move the cursor.
9256
9257 Can also be used as a |method|: >
9258 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009259<
9260 Return type: |Number|
9261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009262
9263searchcount([{options}]) *searchcount()*
9264 Get or update the last search count, like what is displayed
9265 without the "S" flag in 'shortmess'. This works even if
9266 'shortmess' does contain the "S" flag.
9267
9268 This returns a |Dictionary|. The dictionary is empty if the
9269 previous pattern was not set and "pattern" was not specified.
9270
9271 key type meaning ~
9272 current |Number| current position of match;
9273 0 if the cursor position is
9274 before the first match
9275 exact_match |Boolean| 1 if "current" is matched on
9276 "pos", otherwise 0
9277 total |Number| total count of matches found
9278 incomplete |Number| 0: search was fully completed
9279 1: recomputing was timed out
9280 2: max count exceeded
9281
9282 For {options} see further down.
9283
9284 To get the last search count when |n| or |N| was pressed, call
9285 this function with `recompute: 0` . This sometimes returns
9286 wrong information because |n| and |N|'s maximum count is 99.
9287 If it exceeded 99 the result must be max count + 1 (100). If
9288 you want to get correct information, specify `recompute: 1`: >
9289
9290 " result == maxcount + 1 (100) when many matches
9291 let result = searchcount(#{recompute: 0})
9292
9293 " Below returns correct result (recompute defaults
9294 " to 1)
9295 let result = searchcount()
9296<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009297 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009298 function! LastSearchCount() abort
9299 let result = searchcount(#{recompute: 0})
9300 if empty(result)
9301 return ''
9302 endif
9303 if result.incomplete ==# 1 " timed out
9304 return printf(' /%s [?/??]', @/)
9305 elseif result.incomplete ==# 2 " max count exceeded
9306 if result.total > result.maxcount &&
9307 \ result.current > result.maxcount
9308 return printf(' /%s [>%d/>%d]', @/,
9309 \ result.current, result.total)
9310 elseif result.total > result.maxcount
9311 return printf(' /%s [%d/>%d]', @/,
9312 \ result.current, result.total)
9313 endif
9314 endif
9315 return printf(' /%s [%d/%d]', @/,
9316 \ result.current, result.total)
9317 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009318 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009319
9320 " Or if you want to show the count only when
9321 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009322 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009323 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9324<
9325 You can also update the search count, which can be useful in a
9326 |CursorMoved| or |CursorMovedI| autocommand: >
9327
9328 autocmd CursorMoved,CursorMovedI *
9329 \ let s:searchcount_timer = timer_start(
9330 \ 200, function('s:update_searchcount'))
9331 function! s:update_searchcount(timer) abort
9332 if a:timer ==# s:searchcount_timer
9333 call searchcount(#{
9334 \ recompute: 1, maxcount: 0, timeout: 100})
9335 redrawstatus
9336 endif
9337 endfunction
9338<
9339 This can also be used to count matched texts with specified
9340 pattern in the current buffer using "pattern": >
9341
9342 " Count '\<foo\>' in this buffer
9343 " (Note that it also updates search count)
9344 let result = searchcount(#{pattern: '\<foo\>'})
9345
9346 " To restore old search count by old pattern,
9347 " search again
9348 call searchcount()
9349<
9350 {options} must be a |Dictionary|. It can contain:
9351 key type meaning ~
9352 recompute |Boolean| if |TRUE|, recompute the count
9353 like |n| or |N| was executed.
9354 otherwise returns the last
9355 computed result (when |n| or
9356 |N| was used when "S" is not
9357 in 'shortmess', or this
9358 function was called).
9359 (default: |TRUE|)
9360 pattern |String| recompute if this was given
9361 and different with |@/|.
9362 this works as same as the
9363 below command is executed
9364 before calling this function >
9365 let @/ = pattern
9366< (default: |@/|)
9367 timeout |Number| 0 or negative number is no
9368 timeout. timeout milliseconds
9369 for recomputing the result
9370 (default: 0)
9371 maxcount |Number| 0 or negative number is no
9372 limit. max count of matched
9373 text while recomputing the
9374 result. if search exceeded
9375 total count, "total" value
9376 becomes `maxcount + 1`
9377 (default: 99)
9378 pos |List| `[lnum, col, off]` value
9379 when recomputing the result.
9380 this changes "current" result
9381 value. see |cursor()|,
9382 |getpos()|
9383 (default: cursor's position)
9384
9385 Can also be used as a |method|: >
9386 GetSearchOpts()->searchcount()
9387<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009388 Return type: dict<number>
9389
9390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009391searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9392 Search for the declaration of {name}.
9393
9394 With a non-zero {global} argument it works like |gD|, find
9395 first match in the file. Otherwise it works like |gd|, find
9396 first match in the function.
9397
9398 With a non-zero {thisblock} argument matches in a {} block
9399 that ends before the cursor position are ignored. Avoids
9400 finding variable declarations only valid in another scope.
9401
9402 Moves the cursor to the found match.
9403 Returns zero for success, non-zero for failure.
9404 Example: >
9405 if searchdecl('myvar') == 0
9406 echo getline('.')
9407 endif
9408<
9409 Can also be used as a |method|: >
9410 GetName()->searchdecl()
9411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009412 Return type: |Number|
9413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009414 *searchpair()*
9415searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9416 [, {stopline} [, {timeout}]]]])
9417 Search for the match of a nested start-end pair. This can be
9418 used to find the "endif" that matches an "if", while other
9419 if/endif pairs in between are ignored.
9420 The search starts at the cursor. The default is to search
9421 forward, include 'b' in {flags} to search backward.
9422 If a match is found, the cursor is positioned at it and the
9423 line number is returned. If no match is found 0 or -1 is
9424 returned and the cursor doesn't move. No error message is
9425 given.
9426
9427 {start}, {middle} and {end} are patterns, see |pattern|. They
9428 must not contain \( \) pairs. Use of \%( \) is allowed. When
9429 {middle} is not empty, it is found when searching from either
9430 direction, but only when not in a nested start-end pair. A
9431 typical use is: >
9432 searchpair('\<if\>', '\<else\>', '\<endif\>')
9433< By leaving {middle} empty the "else" is skipped.
9434
9435 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9436 |search()|. Additionally:
9437 'r' Repeat until no more matches found; will find the
9438 outer pair. Implies the 'W' flag.
9439 'm' Return number of matches instead of line number with
9440 the match; will be > 1 when 'r' is used.
9441 Note: it's nearly always a good idea to use the 'W' flag, to
9442 avoid wrapping around the end of the file.
9443
9444 When a match for {start}, {middle} or {end} is found, the
9445 {skip} expression is evaluated with the cursor positioned on
9446 the start of the match. It should return non-zero if this
9447 match is to be skipped. E.g., because it is inside a comment
9448 or a string.
9449 When {skip} is omitted or empty, every match is accepted.
9450 When evaluating {skip} causes an error the search is aborted
9451 and -1 returned.
9452 {skip} can be a string, a lambda, a funcref or a partial.
9453 Anything else makes the function fail.
9454 In a `:def` function when the {skip} argument is a string
9455 constant it is compiled into instructions.
9456
9457 For {stopline} and {timeout} see |search()|.
9458
9459 The value of 'ignorecase' is used. 'magic' is ignored, the
9460 patterns are used like it's on.
9461
9462 The search starts exactly at the cursor. A match with
9463 {start}, {middle} or {end} at the next character, in the
9464 direction of searching, is the first one found. Example: >
9465 if 1
9466 if 2
9467 endif 2
9468 endif 1
9469< When starting at the "if 2", with the cursor on the "i", and
9470 searching forwards, the "endif 2" is found. When starting on
9471 the character just before the "if 2", the "endif 1" will be
9472 found. That's because the "if 2" will be found first, and
9473 then this is considered to be a nested if/endif from "if 2" to
9474 "endif 2".
9475 When searching backwards and {end} is more than one character,
9476 it may be useful to put "\zs" at the end of the pattern, so
9477 that when the cursor is inside a match with the end it finds
9478 the matching start.
9479
9480 Example, to find the "endif" command in a Vim script: >
9481
9482 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9483 \ 'getline(".") =~ "^\\s*\""')
9484
9485< The cursor must be at or after the "if" for which a match is
9486 to be found. Note that single-quote strings are used to avoid
9487 having to double the backslashes. The skip expression only
9488 catches comments at the start of a line, not after a command.
9489 Also, a word "en" or "if" halfway a line is considered a
9490 match.
9491 Another example, to search for the matching "{" of a "}": >
9492
9493 :echo searchpair('{', '', '}', 'bW')
9494
9495< This works when the cursor is at or before the "}" for which a
9496 match is to be found. To reject matches that syntax
9497 highlighting recognized as strings: >
9498
9499 :echo searchpair('{', '', '}', 'bW',
9500 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9501<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009502 Return type: |Number|
9503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009504 *searchpairpos()*
9505searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9506 [, {stopline} [, {timeout}]]]])
9507 Same as |searchpair()|, but returns a |List| with the line and
9508 column position of the match. The first element of the |List|
9509 is the line number and the second element is the byte index of
9510 the column position of the match. If no match is found,
9511 returns [0, 0]. >
9512
9513 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9514<
9515 See |match-parens| for a bigger and more useful example.
9516
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009517 Return type: list<number>
9518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009519 *searchpos()*
9520searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9521 Same as |search()|, but returns a |List| with the line and
9522 column position of the match. The first element of the |List|
9523 is the line number and the second element is the byte index of
9524 the column position of the match. If no match is found,
9525 returns [0, 0].
9526 Example: >
9527 :let [lnum, col] = searchpos('mypattern', 'n')
9528
9529< When the 'p' flag is given then there is an extra item with
9530 the sub-pattern match number |search()-sub-match|. Example: >
9531 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9532< In this example "submatch" is 2 when a lowercase letter is
9533 found |/\l|, 3 when an uppercase letter is found |/\u|.
9534
9535 Can also be used as a |method|: >
9536 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009537<
9538 Return type: list<number>
9539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009540
9541server2client({clientid}, {string}) *server2client()*
9542 Send a reply string to {clientid}. The most recent {clientid}
9543 that sent a string can be retrieved with expand("<client>").
9544 {only available when compiled with the |+clientserver| feature}
9545 Returns zero for success, -1 for failure.
9546 Note:
9547 This id has to be stored before the next command can be
9548 received. I.e. before returning from the received command and
9549 before calling any commands that waits for input.
9550 See also |clientserver|.
9551 Example: >
9552 :echo server2client(expand("<client>"), "HELLO")
9553
9554< Can also be used as a |method|: >
9555 GetClientId()->server2client(string)
9556<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009557 Return type: |Number|
9558
9559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009560serverlist() *serverlist()*
9561 Return a list of available server names, one per line.
9562 When there are no servers or the information is not available
9563 an empty string is returned. See also |clientserver|.
9564 {only available when compiled with the |+clientserver| feature}
9565 Example: >
9566 :echo serverlist()
9567<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009568 Return type: |String|
9569
9570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009571setbufline({buf}, {lnum}, {text}) *setbufline()*
9572 Set line {lnum} to {text} in buffer {buf}. This works like
9573 |setline()| for the specified buffer.
9574
9575 This function works only for loaded buffers. First call
9576 |bufload()| if needed.
9577
9578 To insert lines use |appendbufline()|.
9579 Any text properties in {lnum} are cleared.
9580
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009581 {text} can be a string to set one line, or a List of strings
9582 to set multiple lines. If the List extends below the last
9583 line then those lines are added. If the List is empty then
9584 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009585
9586 For the use of {buf}, see |bufname()| above.
9587
9588 {lnum} is used like with |setline()|.
9589 Use "$" to refer to the last line in buffer {buf}.
9590 When {lnum} is just below the last line the {text} will be
9591 added below the last line.
9592
9593 When {buf} is not a valid buffer, the buffer is not loaded or
9594 {lnum} is not valid then 1 is returned. In |Vim9| script an
9595 error is given.
9596 On success 0 is returned.
9597
9598 Can also be used as a |method|, the base is passed as the
9599 third argument: >
9600 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009601<
9602 Return type: |Number|
9603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009604
9605setbufvar({buf}, {varname}, {val}) *setbufvar()*
9606 Set option or local variable {varname} in buffer {buf} to
9607 {val}.
9608 This also works for a global or local window option, but it
9609 doesn't work for a global or local window variable.
9610 For a local window option the global value is unchanged.
9611 For the use of {buf}, see |bufname()| above.
9612 The {varname} argument is a string.
9613 Note that the variable name without "b:" must be used.
9614 Examples: >
9615 :call setbufvar(1, "&mod", 1)
9616 :call setbufvar("todo", "myvar", "foobar")
9617< This function is not available in the |sandbox|.
9618
9619 Can also be used as a |method|, the base is passed as the
9620 third argument: >
9621 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009622<
9623 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009624
9625
9626setcellwidths({list}) *setcellwidths()*
9627 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009628 tells Vim how wide characters are when displayed in the
9629 terminal, counted in screen cells. The values override
9630 'ambiwidth'. Example: >
9631 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009632 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009633 \ [0x2194, 0x2199, 2],
9634 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009635
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009636< The {list} argument is a List of Lists with each three
9637 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9638 {low} and {high} can be the same, in which case this refers to
9639 one character. Otherwise it is the range of characters from
9640 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009641 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009642
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009643 {width} must be either 1 or 2, indicating the character width
9644 in screen cells. *E1112*
9645 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009646 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009648 If the new value causes 'fillchars' or 'listchars' to become
9649 invalid it is rejected and an error is given.
9650
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009651 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009652 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009654< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009655 the effect for known emoji characters. Move the cursor
9656 through the text to check if the cell widths of your terminal
9657 match with what Vim knows about each emoji. If it doesn't
9658 look right you need to adjust the {list} argument.
9659
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009660 Return type: |Number|
9661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009662
9663setcharpos({expr}, {list}) *setcharpos()*
9664 Same as |setpos()| but uses the specified column number as the
9665 character index instead of the byte index in the line.
9666
9667 Example:
9668 With the text "여보세요" in line 8: >
9669 call setcharpos('.', [0, 8, 4, 0])
9670< positions the cursor on the fourth character '요'. >
9671 call setpos('.', [0, 8, 4, 0])
9672< positions the cursor on the second character '보'.
9673
9674 Can also be used as a |method|: >
9675 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009676<
9677 Return type: |Number|
9678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009679
9680setcharsearch({dict}) *setcharsearch()*
9681 Set the current character search information to {dict},
9682 which contains one or more of the following entries:
9683
9684 char character which will be used for a subsequent
9685 |,| or |;| command; an empty string clears the
9686 character search
9687 forward direction of character search; 1 for forward,
9688 0 for backward
9689 until type of character search; 1 for a |t| or |T|
9690 character search, 0 for an |f| or |F|
9691 character search
9692
9693 This can be useful to save/restore a user's character search
9694 from a script: >
9695 :let prevsearch = getcharsearch()
9696 :" Perform a command which clobbers user's search
9697 :call setcharsearch(prevsearch)
9698< Also see |getcharsearch()|.
9699
9700 Can also be used as a |method|: >
9701 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009702<
9703 Return type: dict<any>
9704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009705
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009706setcmdline({str} [, {pos}]) *setcmdline()*
9707 Set the command line to {str} and set the cursor position to
9708 {pos}.
9709 If {pos} is omitted, the cursor is positioned after the text.
9710 Returns 0 when successful, 1 when not editing the command
9711 line.
9712
9713 Can also be used as a |method|: >
9714 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009715<
9716 Return type: |Number|
9717
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009719setcmdpos({pos}) *setcmdpos()*
9720 Set the cursor position in the command line to byte position
9721 {pos}. The first position is 1.
9722 Use |getcmdpos()| to obtain the current position.
9723 Only works while editing the command line, thus you must use
9724 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9725 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9726 set after the command line is set to the expression. For
9727 |c_CTRL-R_=| it is set after evaluating the expression but
9728 before inserting the resulting text.
9729 When the number is too big the cursor is put at the end of the
9730 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009731 Returns 0 when successful, 1 when not editing the command
9732 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009733
9734 Can also be used as a |method|: >
9735 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009736<
9737 Return type: |Number|
9738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009739
9740setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9741setcursorcharpos({list})
9742 Same as |cursor()| but uses the specified column number as the
9743 character index instead of the byte index in the line.
9744
9745 Example:
9746 With the text "여보세요" in line 4: >
9747 call setcursorcharpos(4, 3)
9748< positions the cursor on the third character '세'. >
9749 call cursor(4, 3)
9750< positions the cursor on the first character '여'.
9751
9752 Can also be used as a |method|: >
9753 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009754<
9755 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009756
9757
9758setenv({name}, {val}) *setenv()*
9759 Set environment variable {name} to {val}. Example: >
9760 call setenv('HOME', '/home/myhome')
9761
9762< When {val} is |v:null| the environment variable is deleted.
9763 See also |expr-env|.
9764
9765 Can also be used as a |method|, the base is passed as the
9766 second argument: >
9767 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009768<
9769 Return type: |Number|
9770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009771
9772setfperm({fname}, {mode}) *setfperm()* *chmod*
9773 Set the file permissions for {fname} to {mode}.
9774 {mode} must be a string with 9 characters. It is of the form
9775 "rwxrwxrwx", where each group of "rwx" flags represent, in
9776 turn, the permissions of the owner of the file, the group the
9777 file belongs to, and other users. A '-' character means the
9778 permission is off, any other character means on. Multi-byte
9779 characters are not supported.
9780
9781 For example "rw-r-----" means read-write for the user,
9782 readable by the group, not accessible by others. "xx-x-----"
9783 would do the same thing.
9784
9785 Returns non-zero for success, zero for failure.
9786
9787 Can also be used as a |method|: >
9788 GetFilename()->setfperm(mode)
9789<
9790 To read permissions see |getfperm()|.
9791
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009792 Return type: |Number|
9793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009794
9795setline({lnum}, {text}) *setline()*
9796 Set line {lnum} of the current buffer to {text}. To insert
9797 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009798 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009799 Any text properties in {lnum} are cleared. See
9800 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009801
9802 {lnum} is used like with |getline()|.
9803 When {lnum} is just below the last line the {text} will be
9804 added below the last line.
9805 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009806 converted to a String. When {text} is an empty List then
9807 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009808
9809 If this succeeds, FALSE is returned. If this fails (most likely
9810 because {lnum} is invalid) TRUE is returned.
9811 In |Vim9| script an error is given if {lnum} is invalid.
9812
9813 Example: >
9814 :call setline(5, strftime("%c"))
9815
9816< When {text} is a |List| then line {lnum} and following lines
9817 will be set to the items in the list. Example: >
9818 :call setline(5, ['aaa', 'bbb', 'ccc'])
9819< This is equivalent to: >
9820 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9821 : call setline(n, l)
9822 :endfor
9823
9824< Note: The '[ and '] marks are not set.
9825
9826 Can also be used as a |method|, the base is passed as the
9827 second argument: >
9828 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009829<
9830 Return type: |Number|
9831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009832
9833setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9834 Create or replace or add to the location list for window {nr}.
9835 {nr} can be the window number or the |window-ID|.
9836 When {nr} is zero the current window is used.
9837
9838 For a location list window, the displayed location list is
9839 modified. For an invalid window number {nr}, -1 is returned.
9840 Otherwise, same as |setqflist()|.
9841 Also see |location-list|.
9842
9843 For {action} see |setqflist-action|.
9844
9845 If the optional {what} dictionary argument is supplied, then
9846 only the items listed in {what} are set. Refer to |setqflist()|
9847 for the list of supported keys in {what}.
9848
9849 Can also be used as a |method|, the base is passed as the
9850 second argument: >
9851 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009852<
9853 Return type: |Number|
9854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009855
9856setmatches({list} [, {win}]) *setmatches()*
9857 Restores a list of matches saved by |getmatches()| for the
9858 current window. Returns 0 if successful, otherwise -1. All
9859 current matches are cleared before the list is restored. See
9860 example for |getmatches()|.
9861 If {win} is specified, use the window with this number or
9862 window ID instead of the current window.
9863
9864 Can also be used as a |method|: >
9865 GetMatches()->setmatches()
9866<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009867 Return type: |Number|
9868
9869
9870setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009871 Set the position for String {expr}. Possible values:
9872 . the cursor
9873 'x mark x
9874
9875 {list} must be a |List| with four or five numbers:
9876 [bufnum, lnum, col, off]
9877 [bufnum, lnum, col, off, curswant]
9878
9879 "bufnum" is the buffer number. Zero can be used for the
9880 current buffer. When setting an uppercase mark "bufnum" is
9881 used for the mark position. For other marks it specifies the
9882 buffer to set the mark in. You can use the |bufnr()| function
9883 to turn a file name into a buffer number.
9884 For setting the cursor and the ' mark "bufnum" is ignored,
9885 since these are associated with a window, not a buffer.
9886 Does not change the jumplist.
9887
9888 "lnum" and "col" are the position in the buffer. The first
9889 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9890 smaller than 1 then 1 is used. To use the character count
9891 instead of the byte count, use |setcharpos()|.
9892
9893 The "off" number is only used when 'virtualedit' is set. Then
9894 it is the offset in screen columns from the start of the
9895 character. E.g., a position within a <Tab> or after the last
9896 character.
9897
9898 The "curswant" number is only used when setting the cursor
9899 position. It sets the preferred column for when moving the
9900 cursor vertically. When the "curswant" number is missing the
9901 preferred column is not set. When it is present and setting a
9902 mark position it is not used.
9903
9904 Note that for '< and '> changing the line number may result in
9905 the marks to be effectively be swapped, so that '< is always
9906 before '>.
9907
9908 Returns 0 when the position could be set, -1 otherwise.
9909 An error message is given if {expr} is invalid.
9910
9911 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9912
9913 This does not restore the preferred column for moving
9914 vertically; if you set the cursor position with this, |j| and
9915 |k| motions will jump to previous columns! Use |cursor()| to
9916 also set the preferred column. Also see the "curswant" key in
9917 |winrestview()|.
9918
9919 Can also be used as a |method|: >
9920 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009921<
9922 Return type: |Number|
9923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009924
9925setqflist({list} [, {action} [, {what}]]) *setqflist()*
9926 Create or replace or add to the quickfix list.
9927
9928 If the optional {what} dictionary argument is supplied, then
9929 only the items listed in {what} are set. The first {list}
9930 argument is ignored. See below for the supported items in
9931 {what}.
9932 *setqflist-what*
9933 When {what} is not present, the items in {list} are used. Each
9934 item must be a dictionary. Non-dictionary items in {list} are
9935 ignored. Each dictionary item can contain the following
9936 entries:
9937
9938 bufnr buffer number; must be the number of a valid
9939 buffer
9940 filename name of a file; only used when "bufnr" is not
9941 present or it is invalid.
9942 module name of a module; if given it will be used in
9943 quickfix error window instead of the filename.
9944 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009945 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009946 pattern search pattern used to locate the error
9947 col column number
9948 vcol when non-zero: "col" is visual column
9949 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009950 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009951 nr error number
9952 text description of the error
9953 type single-character error type, 'E', 'W', etc.
9954 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009955 user_data custom data associated with the item, can be
9956 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009957
9958 The "col", "vcol", "nr", "type" and "text" entries are
9959 optional. Either "lnum" or "pattern" entry can be used to
9960 locate a matching error line.
9961 If the "filename" and "bufnr" entries are not present or
9962 neither the "lnum" or "pattern" entries are present, then the
9963 item will not be handled as an error line.
9964 If both "pattern" and "lnum" are present then "pattern" will
9965 be used.
9966 If the "valid" entry is not supplied, then the valid flag is
9967 set when "bufnr" is a valid buffer or "filename" exists.
9968 If you supply an empty {list}, the quickfix list will be
9969 cleared.
9970 Note that the list is not exactly the same as what
9971 |getqflist()| returns.
9972
9973 {action} values: *setqflist-action* *E927*
9974 'a' The items from {list} are added to the existing
9975 quickfix list. If there is no existing list, then a
9976 new list is created.
9977
9978 'r' The items from the current quickfix list are replaced
9979 with the items from {list}. This can also be used to
9980 clear the list: >
9981 :call setqflist([], 'r')
9982<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009983 'u' Like 'r', but tries to preserve the current selection
9984 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009985 'f' All the quickfix lists in the quickfix stack are
9986 freed.
9987
9988 If {action} is not present or is set to ' ', then a new list
9989 is created. The new quickfix list is added after the current
9990 quickfix list in the stack and all the following lists are
9991 freed. To add a new quickfix list at the end of the stack,
9992 set "nr" in {what} to "$".
9993
9994 The following items can be specified in dictionary {what}:
9995 context quickfix list context. See |quickfix-context|
9996 efm errorformat to use when parsing text from
9997 "lines". If this is not present, then the
9998 'errorformat' option value is used.
9999 See |quickfix-parse|
10000 id quickfix list identifier |quickfix-ID|
10001 idx index of the current entry in the quickfix
10002 list specified by 'id' or 'nr'. If set to '$',
10003 then the last entry in the list is set as the
10004 current entry. See |quickfix-index|
10005 items list of quickfix entries. Same as the {list}
10006 argument.
10007 lines use 'errorformat' to parse a list of lines and
10008 add the resulting entries to the quickfix list
10009 {nr} or {id}. Only a |List| value is supported.
10010 See |quickfix-parse|
10011 nr list number in the quickfix stack; zero
10012 means the current quickfix list and "$" means
10013 the last quickfix list.
10014 quickfixtextfunc
10015 function to get the text to display in the
10016 quickfix window. The value can be the name of
10017 a function or a funcref or a lambda. Refer to
10018 |quickfix-window-function| for an explanation
10019 of how to write the function and an example.
10020 title quickfix list title text. See |quickfix-title|
10021 Unsupported keys in {what} are ignored.
10022 If the "nr" item is not present, then the current quickfix list
10023 is modified. When creating a new quickfix list, "nr" can be
10024 set to a value one greater than the quickfix stack size.
10025 When modifying a quickfix list, to guarantee that the correct
10026 list is modified, "id" should be used instead of "nr" to
10027 specify the list.
10028
10029 Examples (See also |setqflist-examples|): >
10030 :call setqflist([], 'r', {'title': 'My search'})
10031 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
10032 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
10033<
10034 Returns zero for success, -1 for failure.
10035
10036 This function can be used to create a quickfix list
10037 independent of the 'errorformat' setting. Use a command like
10038 `:cc 1` to jump to the first position.
10039
10040 Can also be used as a |method|, the base is passed as the
10041 second argument: >
10042 GetErrorlist()->setqflist()
10043<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010044 Return type: |Number|
10045
10046
10047setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010048 Set the register {regname} to {value}.
10049 If {regname} is "" or "@", the unnamed register '"' is used.
10050 The {regname} argument is a string. In |Vim9-script|
10051 {regname} must be one character.
10052
10053 {value} may be any value returned by |getreg()| or
10054 |getreginfo()|, including a |List| or |Dict|.
10055 If {options} contains "a" or {regname} is upper case,
10056 then the value is appended.
10057
10058 {options} can also contain a register type specification:
10059 "c" or "v" |characterwise| mode
10060 "l" or "V" |linewise| mode
10061 "b" or "<CTRL-V>" |blockwise-visual| mode
10062 If a number immediately follows "b" or "<CTRL-V>" then this is
10063 used as the width of the selection - if it is not specified
10064 then the width of the block is set to the number of characters
10065 in the longest line (counting a <Tab> as 1 character).
10066
10067 If {options} contains no register settings, then the default
10068 is to use character mode unless {value} ends in a <NL> for
10069 string {value} and linewise mode for list {value}. Blockwise
10070 mode is never selected automatically.
10071 Returns zero for success, non-zero for failure.
10072
10073 *E883*
10074 Note: you may not use |List| containing more than one item to
10075 set search and expression registers. Lists containing no
10076 items act like empty strings.
10077
10078 Examples: >
10079 :call setreg(v:register, @*)
10080 :call setreg('*', @%, 'ac')
10081 :call setreg('a', "1\n2\n3", 'b5')
10082 :call setreg('"', { 'points_to': 'a'})
10083
10084< This example shows using the functions to save and restore a
10085 register: >
10086 :let var_a = getreginfo()
10087 :call setreg('a', var_a)
10088< or: >
10089 :let var_a = getreg('a', 1, 1)
10090 :let var_amode = getregtype('a')
10091 ....
10092 :call setreg('a', var_a, var_amode)
10093< Note: you may not reliably restore register value
10094 without using the third argument to |getreg()| as without it
10095 newlines are represented as newlines AND Nul bytes are
10096 represented as newlines as well, see |NL-used-for-Nul|.
10097
10098 You can also change the type of a register by appending
10099 nothing: >
10100 :call setreg('a', '', 'al')
10101
10102< Can also be used as a |method|, the base is passed as the
10103 second argument: >
10104 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010105<
10106 Return type: |Number|
10107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010108
10109settabvar({tabnr}, {varname}, {val}) *settabvar()*
10110 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10111 |t:var|
10112 The {varname} argument is a string.
10113 Note that autocommands are blocked, side effects may not be
10114 triggered, e.g. when setting 'filetype'.
10115 Note that the variable name without "t:" must be used.
10116 Tabs are numbered starting with one.
10117 This function is not available in the |sandbox|.
10118
10119 Can also be used as a |method|, the base is passed as the
10120 third argument: >
10121 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010122<
10123 Return type: |Number|
10124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010125
10126settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10127 Set option or local variable {varname} in window {winnr} to
10128 {val}.
10129 Tabs are numbered starting with one. For the current tabpage
10130 use |setwinvar()|.
10131 {winnr} can be the window number or the |window-ID|.
10132 When {winnr} is zero the current window is used.
10133 Note that autocommands are blocked, side effects may not be
10134 triggered, e.g. when setting 'filetype' or 'syntax'.
10135 This also works for a global or local buffer option, but it
10136 doesn't work for a global or local buffer variable.
10137 For a local buffer option the global value is unchanged.
10138 Note that the variable name without "w:" must be used.
10139 Examples: >
10140 :call settabwinvar(1, 1, "&list", 0)
10141 :call settabwinvar(3, 2, "myvar", "foobar")
10142< This function is not available in the |sandbox|.
10143
10144 Can also be used as a |method|, the base is passed as the
10145 fourth argument: >
10146 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010147<
10148 Return type: |Number|
10149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010150
10151settagstack({nr}, {dict} [, {action}]) *settagstack()*
10152 Modify the tag stack of the window {nr} using {dict}.
10153 {nr} can be the window number or the |window-ID|.
10154
10155 For a list of supported items in {dict}, refer to
10156 |gettagstack()|. "curidx" takes effect before changing the tag
10157 stack.
10158 *E962*
10159 How the tag stack is modified depends on the {action}
10160 argument:
10161 - If {action} is not present or is set to 'r', then the tag
10162 stack is replaced.
10163 - If {action} is set to 'a', then new entries from {dict} are
10164 pushed (added) onto the tag stack.
10165 - If {action} is set to 't', then all the entries from the
10166 current entry in the tag stack or "curidx" in {dict} are
10167 removed and then new entries are pushed to the stack.
10168
10169 The current index is set to one after the length of the tag
10170 stack after the modification.
10171
10172 Returns zero for success, -1 for failure.
10173
10174 Examples (for more examples see |tagstack-examples|):
10175 Empty the tag stack of window 3: >
10176 call settagstack(3, {'items' : []})
10177
10178< Save and restore the tag stack: >
10179 let stack = gettagstack(1003)
10180 " do something else
10181 call settagstack(1003, stack)
10182 unlet stack
10183<
10184 Can also be used as a |method|, the base is passed as the
10185 second argument: >
10186 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010187<
10188 Return type: |Number|
10189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010190
10191setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10192 Like |settabwinvar()| for the current tab page.
10193 Examples: >
10194 :call setwinvar(1, "&list", 0)
10195 :call setwinvar(2, "myvar", "foobar")
10196
10197< Can also be used as a |method|, the base is passed as the
10198 third argument: >
10199 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010200<
10201 Return type: |Number|
10202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010203
10204sha256({string}) *sha256()*
10205 Returns a String with 64 hex characters, which is the SHA256
10206 checksum of {string}.
10207
10208 Can also be used as a |method|: >
10209 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010210<
10211 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010212
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010213 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010214
10215shellescape({string} [, {special}]) *shellescape()*
10216 Escape {string} for use as a shell command argument.
10217 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010218 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010219 in single quotes and will double up all internal single
10220 quotes.
10221 On MS-Windows, when 'shellslash' is not set, it will enclose
10222 {string} in double quotes and double all double quotes within
10223 {string}.
10224 Otherwise it will enclose {string} in single quotes and
10225 replace all "'" with "'\''".
10226
Enno5faeb602024-05-15 21:54:19 +020010227 The {special} argument adds additional escaping of keywords
10228 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010229 number or a non-empty String (|non-zero-arg|), then special
10230 items such as "!", "%", "#" and "<cword>" (as listed in
10231 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010232 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010233
10234 The "!" character will be escaped (again with a |non-zero-arg|
10235 {special}) when 'shell' contains "csh" in the tail. That is
10236 because for csh and tcsh "!" is used for history replacement
10237 even when inside single quotes.
10238
10239 With a |non-zero-arg| {special} the <NL> character is also
10240 escaped. When 'shell' containing "csh" in the tail it's
10241 escaped a second time.
10242
10243 The "\" character will be escaped when 'shell' contains "fish"
10244 in the tail. That is because for fish "\" is used as an escape
10245 character inside single quotes.
10246
10247 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010248 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010249< This results in a directory listing for the file under the
10250 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010251 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010252< See also |::S|.
10253
10254 Can also be used as a |method|: >
10255 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010256<
10257 Return type: |String|
10258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010259
10260shiftwidth([{col}]) *shiftwidth()*
10261 Returns the effective value of 'shiftwidth'. This is the
10262 'shiftwidth' value unless it is zero, in which case it is the
10263 'tabstop' value. This function was introduced with patch
10264 7.3.694 in 2012, everybody should have it by now (however it
10265 did not allow for the optional {col} argument until 8.1.542).
10266
10267 When there is one argument {col} this is used as column number
10268 for which to return the 'shiftwidth' value. This matters for the
10269 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10270 no {col} argument is given, column 1 will be assumed.
10271
10272 Can also be used as a |method|: >
10273 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010274<
10275 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010276
10277sign_ functions are documented here: |sign-functions-details|
10278
10279
10280simplify({filename}) *simplify()*
10281 Simplify the file name as much as possible without changing
10282 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10283 Unix) are not resolved. If the first path component in
10284 {filename} designates the current directory, this will be
10285 valid for the result as well. A trailing path separator is
10286 not removed either. On Unix "//path" is unchanged, but
10287 "///path" is simplified to "/path" (this follows the Posix
10288 standard).
10289 Example: >
10290 simplify("./dir/.././/file/") == "./file/"
10291< Note: The combination "dir/.." is only removed if "dir" is
10292 a searchable directory or does not exist. On Unix, it is also
10293 removed when "dir" is a symbolic link within the same
10294 directory. In order to resolve all the involved symbolic
10295 links before simplifying the path name, use |resolve()|.
10296
10297 Can also be used as a |method|: >
10298 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010299<
10300 Return type: |String|
10301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010302
10303sin({expr}) *sin()*
10304 Return the sine of {expr}, measured in radians, as a |Float|.
10305 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010306 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010307 Examples: >
10308 :echo sin(100)
10309< -0.506366 >
10310 :echo sin(-4.01)
10311< 0.763301
10312
10313 Can also be used as a |method|: >
10314 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010315<
10316 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010317
10318
10319sinh({expr}) *sinh()*
10320 Return the hyperbolic sine of {expr} as a |Float| in the range
10321 [-inf, inf].
10322 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010323 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010324 Examples: >
10325 :echo sinh(0.5)
10326< 0.521095 >
10327 :echo sinh(-0.9)
10328< -1.026517
10329
10330 Can also be used as a |method|: >
10331 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010332<
10333 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010334
10335
10336slice({expr}, {start} [, {end}]) *slice()*
10337 Similar to using a |slice| "expr[start : end]", but "end" is
10338 used exclusive. And for a string the indexes are used as
10339 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010340 |vim9script|. Also, composing characters are treated as a
10341 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010342 When {end} is omitted the slice continues to the last item.
10343 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010344 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010345
10346 Can also be used as a |method|: >
10347 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010348<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010349 Return type: list<{type}> or tuple<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010350
10351
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010352sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010353 Sort the items in {list} in-place. Returns {list}.
10354
10355 If you want a list to remain unmodified make a copy first: >
10356 :let sortedlist = sort(copy(mylist))
10357
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010358< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010359 string representation of each item to sort on. Numbers sort
10360 after Strings, |Lists| after Numbers. For sorting text in the
10361 current buffer use |:sort|.
10362
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010363 When {how} is given and it is 'i' then case is ignored.
10364 In legacy script, for backwards compatibility, the value one
10365 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010366
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010367 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010368 locale is used for ordering. Implementation details: strcoll()
10369 is used to compare strings. See |:language| check or set the
10370 collation locale. |v:collate| can also be used to check the
10371 current locale. Sorting using the locale typically ignores
10372 case. Example: >
10373 " ö is sorted similarly to o with English locale.
10374 :language collate en_US.UTF8
10375 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10376< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10377>
10378 " ö is sorted after z with Swedish locale.
10379 :language collate sv_SE.UTF8
10380 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10381< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10382 This does not work properly on Mac.
10383
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010384 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010385 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010386 strtod() function to parse numbers. Strings, Lists, Dicts and
10387 Funcrefs will be considered as being 0). Note that this won't
10388 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010389
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010390 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010391 sorted numerical. This is like 'n' but a string containing
10392 digits will be used as the number they represent.
10393
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010394 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010395 sorted numerical. All values must be a Number or a Float.
10396
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010397 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398 is called to compare items. The function is invoked with two
10399 items as argument and must return zero if they are equal, 1 or
10400 bigger if the first one sorts after the second one, -1 or
10401 smaller if the first one sorts before the second one.
10402
10403 {dict} is for functions with the "dict" attribute. It will be
10404 used to set the local variable "self". |Dictionary-function|
10405
10406 The sort is stable, items which compare equal (as number or as
10407 string) will keep their relative position. E.g., when sorting
10408 on numbers, text strings will sort next to each other, in the
10409 same order as they were originally.
10410
10411 Can also be used as a |method|: >
10412 mylist->sort()
10413
10414< Also see |uniq()|.
10415
10416 Example: >
10417 func MyCompare(i1, i2)
10418 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10419 endfunc
10420 eval mylist->sort("MyCompare")
10421< A shorter compare version for this specific simple case, which
10422 ignores overflow: >
10423 func MyCompare(i1, i2)
10424 return a:i1 - a:i2
10425 endfunc
10426< For a simple expression you can use a lambda: >
10427 eval mylist->sort({i1, i2 -> i1 - i2})
10428<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010429 Return type: list<{type}>
10430
10431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010432sound_clear() *sound_clear()*
10433 Stop playing all sounds.
10434
10435 On some Linux systems you may need the libcanberra-pulse
10436 package, otherwise sound may not stop.
10437
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010438 Return type: |Number|
10439
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010440 {only available when compiled with the |+sound| feature}
10441
10442 *sound_playevent()*
10443sound_playevent({name} [, {callback}])
10444 Play a sound identified by {name}. Which event names are
10445 supported depends on the system. Often the XDG sound names
10446 are used. On Ubuntu they may be found in
10447 /usr/share/sounds/freedesktop/stereo. Example: >
10448 call sound_playevent('bell')
10449< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10450 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10451 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010452 On macOS, {name} refers to files located in
10453 /System/Library/Sounds (e.g. "Tink"). It will also work for
10454 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010455
10456 When {callback} is specified it is invoked when the sound is
10457 finished. The first argument is the sound ID, the second
10458 argument is the status:
10459 0 sound was played to the end
10460 1 sound was interrupted
10461 2 error occurred after sound started
10462 Example: >
10463 func Callback(id, status)
10464 echomsg "sound " .. a:id .. " finished with " .. a:status
10465 endfunc
10466 call sound_playevent('bell', 'Callback')
10467
10468< MS-Windows: {callback} doesn't work for this function.
10469
10470 Returns the sound ID, which can be passed to `sound_stop()`.
10471 Returns zero if the sound could not be played.
10472
10473 Can also be used as a |method|: >
10474 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010475<
10476 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010477
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010478 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010479
10480 *sound_playfile()*
10481sound_playfile({path} [, {callback}])
10482 Like `sound_playevent()` but play sound file {path}. {path}
10483 must be a full path. On Ubuntu you may find files to play
10484 with this command: >
10485 :!find /usr/share/sounds -type f | grep -v index.theme
10486
10487< Can also be used as a |method|: >
10488 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010489<
10490 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010491
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010492 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010493
10494
10495sound_stop({id}) *sound_stop()*
10496 Stop playing sound {id}. {id} must be previously returned by
10497 `sound_playevent()` or `sound_playfile()`.
10498
10499 On some Linux systems you may need the libcanberra-pulse
10500 package, otherwise sound may not stop.
10501
10502 On MS-Windows, this does not work for event sound started by
10503 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10504
10505 Can also be used as a |method|: >
10506 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010507<
10508 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010509
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010510 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010511
10512 *soundfold()*
10513soundfold({word})
10514 Return the sound-folded equivalent of {word}. Uses the first
10515 language in 'spelllang' for the current window that supports
10516 soundfolding. 'spell' must be set. When no sound folding is
10517 possible the {word} is returned unmodified.
10518 This can be used for making spelling suggestions. Note that
10519 the method can be quite slow.
10520
10521 Can also be used as a |method|: >
10522 GetWord()->soundfold()
10523<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010524 Return type: |String|
10525
10526
10527spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010528 Without argument: The result is the badly spelled word under
10529 or after the cursor. The cursor is moved to the start of the
10530 bad word. When no bad word is found in the cursor line the
10531 result is an empty string and the cursor doesn't move.
10532
10533 With argument: The result is the first word in {sentence} that
10534 is badly spelled. If there are no spelling mistakes the
10535 result is an empty string.
10536
10537 The return value is a list with two items:
10538 - The badly spelled word or an empty string.
10539 - The type of the spelling error:
10540 "bad" spelling mistake
10541 "rare" rare word
10542 "local" word only valid in another region
10543 "caps" word should start with Capital
10544 Example: >
10545 echo spellbadword("the quik brown fox")
10546< ['quik', 'bad'] ~
10547
10548 The spelling information for the current window and the value
10549 of 'spelllang' are used.
10550
10551 Can also be used as a |method|: >
10552 GetText()->spellbadword()
10553<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010554 Return type: list<string>
10555
10556
10557spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010558 Return a |List| with spelling suggestions to replace {word}.
10559 When {max} is given up to this number of suggestions are
10560 returned. Otherwise up to 25 suggestions are returned.
10561
10562 When the {capital} argument is given and it's non-zero only
10563 suggestions with a leading capital will be given. Use this
10564 after a match with 'spellcapcheck'.
10565
10566 {word} can be a badly spelled word followed by other text.
10567 This allows for joining two words that were split. The
10568 suggestions also include the following text, thus you can
10569 replace a line.
10570
10571 {word} may also be a good word. Similar words will then be
10572 returned. {word} itself is not included in the suggestions,
10573 although it may appear capitalized.
10574
10575 The spelling information for the current window is used. The
10576 values of 'spelllang' and 'spellsuggest' are used.
10577
10578 Can also be used as a |method|: >
10579 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010580<
10581 Return type: list<string> or list<any>
10582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010583
10584split({string} [, {pattern} [, {keepempty}]]) *split()*
10585 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010586 empty each white space separated sequence of characters
10587 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010588 Otherwise the string is split where {pattern} matches,
10589 removing the matched characters. 'ignorecase' is not used
10590 here, add \c to ignore case. |/\c|
10591 When the first or last item is empty it is omitted, unless the
10592 {keepempty} argument is given and it's non-zero.
10593 Other empty items are kept when {pattern} matches at least one
10594 character or when {keepempty} is non-zero.
10595 Example: >
10596 :let words = split(getline('.'), '\W\+')
10597< To split a string in individual characters: >
10598 :for c in split(mystring, '\zs')
10599< If you want to keep the separator you can also use '\zs' at
10600 the end of the pattern: >
10601 :echo split('abc:def:ghi', ':\zs')
10602< ['abc:', 'def:', 'ghi'] ~
10603 Splitting a table where the first element can be empty: >
10604 :let items = split(line, ':', 1)
10605< The opposite function is |join()|.
10606
10607 Can also be used as a |method|: >
10608 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010609<
10610 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010611
10612sqrt({expr}) *sqrt()*
10613 Return the non-negative square root of Float {expr} as a
10614 |Float|.
10615 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010616 is negative the result is NaN (Not a Number). Returns 0.0 if
10617 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010618 Examples: >
10619 :echo sqrt(100)
10620< 10.0 >
10621 :echo sqrt(-4.01)
10622< nan
10623 "nan" may be different, it depends on system libraries.
10624
10625 Can also be used as a |method|: >
10626 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010627<
10628 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010629
10630
10631srand([{expr}]) *srand()*
10632 Initialize seed used by |rand()|:
10633 - If {expr} is not given, seed values are initialized by
10634 reading from /dev/urandom, if possible, or using time(NULL)
10635 a.k.a. epoch time otherwise; this only has second accuracy.
10636 - If {expr} is given it must be a Number. It is used to
10637 initialize the seed values. This is useful for testing or
10638 when a predictable sequence is intended.
10639
10640 Examples: >
10641 :let seed = srand()
10642 :let seed = srand(userinput)
10643 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010644<
10645 Return type: list<number>
10646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010647
10648state([{what}]) *state()*
10649 Return a string which contains characters indicating the
10650 current state. Mostly useful in callbacks that want to do
10651 work that may not always be safe. Roughly this works like:
10652 - callback uses state() to check if work is safe to do.
10653 Yes: then do it right away.
10654 No: add to work queue and add a |SafeState| and/or
10655 |SafeStateAgain| autocommand (|SafeState| triggers at
10656 toplevel, |SafeStateAgain| triggers after handling
10657 messages and callbacks).
10658 - When SafeState or SafeStateAgain is triggered and executes
10659 your autocommand, check with `state()` if the work can be
10660 done now, and if yes remove it from the queue and execute.
10661 Remove the autocommand if the queue is now empty.
10662 Also see |mode()|.
10663
10664 When {what} is given only characters in this string will be
10665 added. E.g, this checks if the screen has scrolled: >
10666 if state('s') == ''
10667 " screen has not scrolled
10668<
10669 These characters indicate the state, generally indicating that
10670 something is busy:
10671 m halfway a mapping, :normal command, feedkeys() or
10672 stuffed command
10673 o operator pending, e.g. after |d|
10674 a Insert mode autocomplete active
10675 x executing an autocommand
10676 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10677 ch_readraw() when reading json
10678 S not triggering SafeState or SafeStateAgain, e.g. after
10679 |f| or a count
10680 c callback invoked, including timer (repeats for
10681 recursiveness up to "ccc")
10682 s screen has scrolled for messages
10683
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010684 Return type: |String|
10685
10686
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010687str2blob({list} [, {options}]) *str2blob()*
10688 Return a Blob by converting the characters in the List of
10689 strings in {list} into bytes.
10690
10691 A <NL> byte is added to the blob after each list item. A
10692 newline character in the string is translated into a <NUL>
10693 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010694
10695 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010696 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010697
10698 The argument {options} is a |Dict| and supports the following
10699 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010700 encoding Convert the characters using this encoding
10701 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010702 The value is a |String|. See |encoding-names|
10703 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010704
10705 An error is given and an empty blob is returned if the
10706 character encoding fails.
10707
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010708 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010709
10710 See also |blob2str()|
10711
10712 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010713 str2blob(["ab"]) returns 0z6162
10714 str2blob(["«»"]) returns 0zC2ABC2BB
10715 str2blob(["a\nb"]) returns 0z610062
10716 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010717 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010718 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010719<
10720 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010721 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010722<
10723 Return type: |Blob|
10724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010725str2float({string} [, {quoted}]) *str2float()*
10726 Convert String {string} to a Float. This mostly works the
10727 same as when using a floating point number in an expression,
10728 see |floating-point-format|. But it's a bit more permissive.
10729 E.g., "1e40" is accepted, while in an expression you need to
10730 write "1.0e40". The hexadecimal form "0x123" is also
10731 accepted, but not others, like binary or octal.
10732 When {quoted} is present and non-zero then embedded single
10733 quotes before the dot are ignored, thus "1'000.0" is a
10734 thousand.
10735 Text after the number is silently ignored.
10736 The decimal point is always '.', no matter what the locale is
10737 set to. A comma ends the number: "12,345.67" is converted to
10738 12.0. You can strip out thousands separators with
10739 |substitute()|: >
10740 let f = str2float(substitute(text, ',', '', 'g'))
10741<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010742 Returns 0.0 if the conversion fails.
10743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010744 Can also be used as a |method|: >
10745 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010746<
10747 Return type: |Float|
10748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010749
10750str2list({string} [, {utf8}]) *str2list()*
10751 Return a list containing the number values which represent
10752 each character in String {string}. Examples: >
10753 str2list(" ") returns [32]
10754 str2list("ABC") returns [65, 66, 67]
10755< |list2str()| does the opposite.
10756
10757 When {utf8} is omitted or zero, the current 'encoding' is used.
10758 When {utf8} is TRUE, always treat the String as UTF-8
10759 characters. With UTF-8 composing characters are handled
10760 properly: >
10761 str2list("á") returns [97, 769]
10762
10763< Can also be used as a |method|: >
10764 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010765<
10766 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010767
10768
10769str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10770 Convert string {string} to a number.
10771 {base} is the conversion base, it can be 2, 8, 10 or 16.
10772 When {quoted} is present and non-zero then embedded single
10773 quotes are ignored, thus "1'000'000" is a million.
10774
10775 When {base} is omitted base 10 is used. This also means that
10776 a leading zero doesn't cause octal conversion to be used, as
10777 with the default String to Number conversion. Example: >
10778 let nr = str2nr('0123')
10779<
10780 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10781 different base the result will be zero. Similarly, when
10782 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10783 {base} is 2 a leading "0b" or "0B" is ignored.
10784 Text after the number is silently ignored.
10785
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010786 Returns 0 if {string} is empty or on error.
10787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010788 Can also be used as a |method|: >
10789 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010790<
10791 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010792
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
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010800 Returns 0 if {string} is empty or on error.
10801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010802 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10803
10804 Can also be used as a |method|: >
10805 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010806<
10807 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010808
10809
10810strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10811 Like |strpart()| but using character index and length instead
10812 of byte index and length.
10813 When {skipcc} is omitted or zero, composing characters are
10814 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010815 When {skipcc} set to 1, composing characters are treated as a
10816 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010817 When a character index is used where a character does not
10818 exist it is omitted and counted as one character. For
10819 example: >
10820 strcharpart('abc', -1, 2)
10821< results in 'a'.
10822
Bram Moolenaard592deb2022-06-17 15:42:40 +010010823 Returns an empty string on error.
10824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010825 Can also be used as a |method|: >
10826 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010827<
10828 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010829
10830
10831strchars({string} [, {skipcc}]) *strchars()*
10832 The result is a Number, which is the number of characters
10833 in String {string}.
10834 When {skipcc} is omitted or zero, composing characters are
10835 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010836 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010837 |strcharlen()| always does this.
10838
Bram Moolenaard592deb2022-06-17 15:42:40 +010010839 Returns zero on error.
10840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10842
10843 {skipcc} is only available after 7.4.755. For backward
10844 compatibility, you can define a wrapper function: >
10845 if has("patch-7.4.755")
10846 function s:strchars(str, skipcc)
10847 return strchars(a:str, a:skipcc)
10848 endfunction
10849 else
10850 function s:strchars(str, skipcc)
10851 if a:skipcc
10852 return strlen(substitute(a:str, ".", "x", "g"))
10853 else
10854 return strchars(a:str)
10855 endif
10856 endfunction
10857 endif
10858<
10859 Can also be used as a |method|: >
10860 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010861<
10862 Return type: |Number|
10863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010864
10865strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10866 The result is a Number, which is the number of display cells
10867 String {string} occupies on the screen when it starts at {col}
10868 (first column is zero). When {col} is omitted zero is used.
10869 Otherwise it is the screen column where to start. This
10870 matters for Tab characters.
10871 The option settings of the current window are used. This
10872 matters for anything that's displayed differently, such as
10873 'tabstop' and 'display'.
10874 When {string} contains characters with East Asian Width Class
10875 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010876 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010877 Also see |strlen()|, |strwidth()| and |strchars()|.
10878
10879 Can also be used as a |method|: >
10880 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010881<
10882 Return type: |Number|
10883
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010884
10885strftime({format} [, {time}]) *strftime()*
10886 The result is a String, which is a formatted date and time, as
10887 specified by the {format} string. The given {time} is used,
10888 or the current time if no time is given. The accepted
10889 {format} depends on your system, thus this is not portable!
10890 See the manual page of the C function strftime() for the
10891 format. The maximum length of the result is 80 characters.
10892 See also |localtime()|, |getftime()| and |strptime()|.
10893 The language can be changed with the |:language| command.
10894 Examples: >
10895 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10896 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10897 :echo strftime("%y%m%d %T") 970427 11:53:55
10898 :echo strftime("%H:%M") 11:55
10899 :echo strftime("%c", getftime("file.c"))
10900 Show mod time of file.c.
10901< Not available on all systems. To check use: >
10902 :if exists("*strftime")
10903
10904< Can also be used as a |method|: >
10905 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010906<
10907 Return type: |String|
10908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010909
10910strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010911 Get a Number corresponding to the character at {index} in
10912 {str}. This uses a zero-based character index, not a byte
10913 index. Composing characters are considered separate
10914 characters here. Use |nr2char()| to convert the Number to a
10915 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010916 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010917 Also see |strcharpart()| and |strchars()|.
10918
10919 Can also be used as a |method|: >
10920 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010921<
10922 Return type: |Number|
10923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010924
10925stridx({haystack}, {needle} [, {start}]) *stridx()*
10926 The result is a Number, which gives the byte index in
10927 {haystack} of the first occurrence of the String {needle}.
10928 If {start} is specified, the search starts at index {start}.
10929 This can be used to find a second match: >
10930 :let colon1 = stridx(line, ":")
10931 :let colon2 = stridx(line, ":", colon1 + 1)
10932< The search is done case-sensitive.
10933 For pattern searches use |match()|.
10934 -1 is returned if the {needle} does not occur in {haystack}.
10935 See also |strridx()|.
10936 Examples: >
10937 :echo stridx("An Example", "Example") 3
10938 :echo stridx("Starting point", "Start") 0
10939 :echo stridx("Starting point", "start") -1
10940< *strstr()* *strchr()*
10941 stridx() works similar to the C function strstr(). When used
10942 with a single character it works similar to strchr().
10943
10944 Can also be used as a |method|: >
10945 GetHaystack()->stridx(needle)
10946<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010947 Return type: |Number|
10948
10949
10950string({expr}) *string()*
10951 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010952 Float, String, Blob or a composition of them, then the result
10953 can be parsed back with |eval()|.
10954 {expr} type result ~
10955 String 'string' (single quotes are doubled)
10956 Number 123
10957 Float 123.123456 or 1.123456e8
10958 Funcref function('name')
10959 Blob 0z00112233.44556677.8899
10960 List [item, item]
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010961 Tuple (item, item)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010962 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010963 Class class SomeName
10964 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010965 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010966 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010967
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010968 When a |List|, |Tuple| or |Dictionary| has a recursive
10969 reference it is replaced by "[...]" or "(...)" or "{...}".
10970 Using eval() on the result will then fail.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010971
mityu7f0bba22024-03-29 10:14:41 +010010972 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010973 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010974 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010976 Can also be used as a |method|: >
10977 mylist->string()
10978
10979< Also see |strtrans()|.
10980
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010981 Return type: |String|
10982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010983
10984strlen({string}) *strlen()*
10985 The result is a Number, which is the length of the String
10986 {string} in bytes.
10987 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010988 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010989 If you want to count the number of multibyte characters use
10990 |strchars()|.
10991 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10992
10993 Can also be used as a |method|: >
10994 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010995<
10996 Return type: |Number|
10997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010998
10999strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
11000 The result is a String, which is part of {src}, starting from
11001 byte {start}, with the byte length {len}.
11002 When {chars} is present and TRUE then {len} is the number of
11003 characters positions (composing characters are not counted
11004 separately, thus "1" means one base character and any
11005 following composing characters).
11006 To count {start} as characters instead of bytes use
11007 |strcharpart()|.
11008
11009 When bytes are selected which do not exist, this doesn't
11010 result in an error, the bytes are simply omitted.
11011 If {len} is missing, the copy continues from {start} till the
11012 end of the {src}. >
11013 strpart("abcdefg", 3, 2) == "de"
11014 strpart("abcdefg", -2, 4) == "ab"
11015 strpart("abcdefg", 5, 4) == "fg"
11016 strpart("abcdefg", 3) == "defg"
11017
11018< Note: To get the first character, {start} must be 0. For
11019 example, to get the character under the cursor: >
11020 strpart(getline("."), col(".") - 1, 1, v:true)
11021<
Bram Moolenaard592deb2022-06-17 15:42:40 +010011022 Returns an empty string on error.
11023
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011024 Can also be used as a |method|: >
11025 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011026<
11027 Return type: |String|
11028
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011029
11030strptime({format}, {timestring}) *strptime()*
11031 The result is a Number, which is a unix timestamp representing
11032 the date and time in {timestring}, which is expected to match
11033 the format specified in {format}.
11034
11035 The accepted {format} depends on your system, thus this is not
11036 portable! See the manual page of the C function strptime()
11037 for the format. Especially avoid "%c". The value of $TZ also
11038 matters.
11039
11040 If the {timestring} cannot be parsed with {format} zero is
11041 returned. If you do not know the format of {timestring} you
11042 can try different {format} values until you get a non-zero
11043 result.
11044
11045 See also |strftime()|.
11046 Examples: >
11047 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11048< 862156163 >
11049 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11050< Sun Apr 27 11:53:55 1997 >
11051 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11052< Sun Apr 27 12:53:55 1997
11053
11054 Can also be used as a |method|: >
11055 GetFormat()->strptime(timestring)
11056<
11057 Not available on all systems. To check use: >
11058 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011059<
11060 Return type: |Number|
11061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011062
11063strridx({haystack}, {needle} [, {start}]) *strridx()*
11064 The result is a Number, which gives the byte index in
11065 {haystack} of the last occurrence of the String {needle}.
11066 When {start} is specified, matches beyond this index are
11067 ignored. This can be used to find a match before a previous
11068 match: >
11069 :let lastcomma = strridx(line, ",")
11070 :let comma2 = strridx(line, ",", lastcomma - 1)
11071< The search is done case-sensitive.
11072 For pattern searches use |match()|.
11073 -1 is returned if the {needle} does not occur in {haystack}.
11074 If the {needle} is empty the length of {haystack} is returned.
11075 See also |stridx()|. Examples: >
11076 :echo strridx("an angry armadillo", "an") 3
11077< *strrchr()*
11078 When used with a single character it works similar to the C
11079 function strrchr().
11080
11081 Can also be used as a |method|: >
11082 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011083<
11084 Return type: |Number|
11085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011086
11087strtrans({string}) *strtrans()*
11088 The result is a String, which is {string} with all unprintable
11089 characters translated into printable characters |'isprint'|.
11090 Like they are shown in a window. Example: >
11091 echo strtrans(@a)
11092< This displays a newline in register a as "^@" instead of
11093 starting a new line.
11094
Bram Moolenaard592deb2022-06-17 15:42:40 +010011095 Returns an empty string on error.
11096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011097 Can also be used as a |method|: >
11098 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011099<
11100 Return type: |String|
11101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011102
Christian Brabandt67672ef2023-04-24 21:09:54 +010011103strutf16len({string} [, {countcc}]) *strutf16len()*
11104 The result is a Number, which is the number of UTF-16 code
11105 units in String {string} (after converting it to UTF-16).
11106
11107 When {countcc} is TRUE, composing characters are counted
11108 separately.
11109 When {countcc} is omitted or FALSE, composing characters are
11110 ignored.
11111
11112 Returns zero on error.
11113
11114 Also see |strlen()| and |strcharlen()|.
11115 Examples: >
11116 echo strutf16len('a') returns 1
11117 echo strutf16len('©') returns 1
11118 echo strutf16len('😊') returns 2
11119 echo strutf16len('ą́') returns 1
11120 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011121<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011122 Can also be used as a |method|: >
11123 GetText()->strutf16len()
11124<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011125 Return type: |Number|
11126
11127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011128strwidth({string}) *strwidth()*
11129 The result is a Number, which is the number of display cells
11130 String {string} occupies. A Tab character is counted as one
11131 cell, alternatively use |strdisplaywidth()|.
11132 When {string} contains characters with East Asian Width Class
11133 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011134 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011135 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11136
11137 Can also be used as a |method|: >
11138 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011139<
11140 Return type: |Number|
11141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011142
11143submatch({nr} [, {list}]) *submatch()* *E935*
11144 Only for an expression in a |:substitute| command or
11145 substitute() function.
11146 Returns the {nr}'th submatch of the matched text. When {nr}
11147 is 0 the whole matched text is returned.
11148 Note that a NL in the string can stand for a line break of a
11149 multi-line match or a NUL character in the text.
11150 Also see |sub-replace-expression|.
11151
11152 If {list} is present and non-zero then submatch() returns
11153 a list of strings, similar to |getline()| with two arguments.
11154 NL characters in the text represent NUL characters in the
11155 text.
11156 Only returns more than one item for |:substitute|, inside
11157 |substitute()| this list will always contain one or zero
11158 items, since there are no real line breaks.
11159
11160 When substitute() is used recursively only the submatches in
11161 the current (deepest) call can be obtained.
11162
Bram Moolenaard592deb2022-06-17 15:42:40 +010011163 Returns an empty string or list on error.
11164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011165 Examples: >
11166 :s/\d\+/\=submatch(0) + 1/
11167 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11168< This finds the first number in the line and adds one to it.
11169 A line break is included as a newline character.
11170
11171 Can also be used as a |method|: >
11172 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011173<
11174 Return type: |String| or list<string> depending on {list}
11175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011176
11177substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11178 The result is a String, which is a copy of {string}, in which
11179 the first match of {pat} is replaced with {sub}.
11180 When {flags} is "g", all matches of {pat} in {string} are
11181 replaced. Otherwise {flags} should be "".
11182
11183 This works like the ":substitute" command (without any flags).
11184 But the matching with {pat} is always done like the 'magic'
11185 option is set and 'cpoptions' is empty (to make scripts
11186 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11187 if you want to ignore or match case and ignore 'ignorecase'.
11188 'smartcase' is not used. See |string-match| for how {pat} is
11189 used.
11190
11191 A "~" in {sub} is not replaced with the previous {sub}.
11192 Note that some codes in {sub} have a special meaning
11193 |sub-replace-special|. For example, to replace something with
11194 "\n" (two characters), use "\\\\n" or '\\n'.
11195
11196 When {pat} does not match in {string}, {string} is returned
11197 unmodified.
11198
11199 Example: >
11200 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11201< This removes the last component of the 'path' option. >
11202 :echo substitute("testing", ".*", "\\U\\0", "")
11203< results in "TESTING".
11204
11205 When {sub} starts with "\=", the remainder is interpreted as
11206 an expression. See |sub-replace-expression|. Example: >
11207 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011208 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011209
11210< When {sub} is a Funcref that function is called, with one
11211 optional argument. Example: >
11212 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11213< The optional argument is a list which contains the whole
11214 matched string and up to nine submatches, like what
11215 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011216 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011217
Bram Moolenaard592deb2022-06-17 15:42:40 +010011218< Returns an empty string on error.
11219
11220 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011221 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011222<
11223 Return type: |String|
11224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011225
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011226swapfilelist() *swapfilelist()*
11227 Returns a list of swap file names, like what "vim -r" shows.
11228 See the |-r| command argument. The 'directory' option is used
11229 for the directories to inspect. If you only want to get a
11230 list of swap files in the current directory then temporarily
11231 set 'directory' to a dot: >
11232 let save_dir = &directory
11233 let &directory = '.'
11234 let swapfiles = swapfilelist()
11235 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011236<
11237 Return type: list<string>
11238
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011240swapinfo({fname}) *swapinfo()*
11241 The result is a dictionary, which holds information about the
11242 swapfile {fname}. The available fields are:
11243 version Vim version
11244 user user name
11245 host host name
11246 fname original file name
11247 pid PID of the Vim process that created the swap
11248 file
11249 mtime last modification time in seconds
11250 inode Optional: INODE number of the file
11251 dirty 1 if file was modified, 0 if not
11252 Note that "user" and "host" are truncated to at most 39 bytes.
11253 In case of failure an "error" item is added with the reason:
11254 Cannot open file: file not found or in accessible
11255 Cannot read file: cannot read first block
11256 Not a swap file: does not contain correct block ID
11257 Magic number mismatch: Info in first block is invalid
11258
11259 Can also be used as a |method|: >
11260 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011261<
11262 Return type: dict<any> or dict<string>
11263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011264
11265swapname({buf}) *swapname()*
11266 The result is the swap file path of the buffer {expr}.
11267 For the use of {buf}, see |bufname()| above.
11268 If buffer {buf} is the current buffer, the result is equal to
11269 |:swapname| (unless there is no swap file).
11270 If buffer {buf} has no swap file, returns an empty string.
11271
11272 Can also be used as a |method|: >
11273 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011274<
11275 Return type: |String|
11276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011277
11278synID({lnum}, {col}, {trans}) *synID()*
11279 The result is a Number, which is the syntax ID at the position
11280 {lnum} and {col} in the current window.
11281 The syntax ID can be used with |synIDattr()| and
11282 |synIDtrans()| to obtain syntax information about text.
11283
11284 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11285 line. 'synmaxcol' applies, in a longer line zero is returned.
11286 Note that when the position is after the last character,
11287 that's where the cursor can be in Insert mode, synID() returns
11288 zero. {lnum} is used like with |getline()|.
11289
11290 When {trans} is |TRUE|, transparent items are reduced to the
11291 item that they reveal. This is useful when wanting to know
11292 the effective color. When {trans} is |FALSE|, the transparent
11293 item is returned. This is useful when wanting to know which
11294 syntax item is effective (e.g. inside parens).
11295 Warning: This function can be very slow. Best speed is
11296 obtained by going through the file in forward direction.
11297
Bram Moolenaard592deb2022-06-17 15:42:40 +010011298 Returns zero on error.
11299
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011300 Example (echoes the name of the syntax item under the cursor): >
11301 :echo synIDattr(synID(line("."), col("."), 1), "name")
11302<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011303 Return type: |Number|
11304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011305
11306synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11307 The result is a String, which is the {what} attribute of
11308 syntax ID {synID}. This can be used to obtain information
11309 about a syntax item.
11310 {mode} can be "gui", "cterm" or "term", to get the attributes
11311 for that mode. When {mode} is omitted, or an invalid value is
11312 used, the attributes for the currently active highlighting are
11313 used (GUI, cterm or term).
11314 Use synIDtrans() to follow linked highlight groups.
11315 {what} result
11316 "name" the name of the syntax item
11317 "fg" foreground color (GUI: color name used to set
11318 the color, cterm: color number as a string,
11319 term: empty string)
11320 "bg" background color (as with "fg")
11321 "font" font name (only available in the GUI)
11322 |highlight-font|
11323 "sp" special color for the GUI (as with "fg")
11324 |highlight-guisp|
11325 "ul" underline color for cterm: number as a string
11326 "fg#" like "fg", but for the GUI and the GUI is
11327 running the name in "#RRGGBB" form
11328 "bg#" like "fg#" for "bg"
11329 "sp#" like "fg#" for "sp"
11330 "bold" "1" if bold
11331 "italic" "1" if italic
11332 "reverse" "1" if reverse
11333 "inverse" "1" if inverse (= reverse)
11334 "standout" "1" if standout
11335 "underline" "1" if underlined
11336 "undercurl" "1" if undercurled
11337 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011338 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011339
Bram Moolenaard592deb2022-06-17 15:42:40 +010011340 Returns an empty string on error.
11341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011342 Example (echoes the color of the syntax item under the
11343 cursor): >
11344 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11345<
11346 Can also be used as a |method|: >
11347 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011348<
11349 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011350
11351
11352synIDtrans({synID}) *synIDtrans()*
11353 The result is a Number, which is the translated syntax ID of
11354 {synID}. This is the syntax group ID of what is being used to
11355 highlight the character. Highlight links given with
11356 ":highlight link" are followed.
11357
Bram Moolenaard592deb2022-06-17 15:42:40 +010011358 Returns zero on error.
11359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011360 Can also be used as a |method|: >
11361 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011362<
11363 Return type: |Number|
11364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011365
11366synconcealed({lnum}, {col}) *synconcealed()*
11367 The result is a |List| with currently three items:
11368 1. The first item in the list is 0 if the character at the
11369 position {lnum} and {col} is not part of a concealable
11370 region, 1 if it is. {lnum} is used like with |getline()|.
11371 2. The second item in the list is a string. If the first item
11372 is 1, the second item contains the text which will be
11373 displayed in place of the concealed text, depending on the
11374 current setting of 'conceallevel' and 'listchars'.
11375 3. The third and final item in the list is a number
11376 representing the specific syntax region matched in the
11377 line. When the character is not concealed the value is
11378 zero. This allows detection of the beginning of a new
11379 concealable region if there are two consecutive regions
11380 with the same replacement character. For an example, if
11381 the text is "123456" and both "23" and "45" are concealed
11382 and replaced by the character "X", then:
11383 call returns ~
11384 synconcealed(lnum, 1) [0, '', 0]
11385 synconcealed(lnum, 2) [1, 'X', 1]
11386 synconcealed(lnum, 3) [1, 'X', 1]
11387 synconcealed(lnum, 4) [1, 'X', 2]
11388 synconcealed(lnum, 5) [1, 'X', 2]
11389 synconcealed(lnum, 6) [0, '', 0]
11390
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011391 Note: Doesn't consider |matchadd()| highlighting items,
11392 since syntax and matching highlighting are two different
11393 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011394
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011395 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011397
11398synstack({lnum}, {col}) *synstack()*
11399 Return a |List|, which is the stack of syntax items at the
11400 position {lnum} and {col} in the current window. {lnum} is
11401 used like with |getline()|. Each item in the List is an ID
11402 like what |synID()| returns.
11403 The first item in the List is the outer region, following are
11404 items contained in that one. The last one is what |synID()|
11405 returns, unless not the whole item is highlighted or it is a
11406 transparent item.
11407 This function is useful for debugging a syntax file.
11408 Example that shows the syntax stack under the cursor: >
11409 for id in synstack(line("."), col("."))
11410 echo synIDattr(id, "name")
11411 endfor
11412< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011413 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011414 character in a line and the first column in an empty line are
11415 valid positions.
11416
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011417 Return type: list<number> or list<any>
11418
11419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011420system({expr} [, {input}]) *system()* *E677*
11421 Get the output of the shell command {expr} as a |String|. See
11422 |systemlist()| to get the output as a |List|.
11423
11424 When {input} is given and is a |String| this string is written
11425 to a file and passed as stdin to the command. The string is
11426 written as-is, you need to take care of using the correct line
11427 separators yourself.
11428 If {input} is given and is a |List| it is written to the file
11429 in a way |writefile()| does with {binary} set to "b" (i.e.
11430 with a newline between each list item with newlines inside
11431 list items converted to NULs).
11432 When {input} is given and is a number that is a valid id for
11433 an existing buffer then the content of the buffer is written
11434 to the file line by line, each line terminated by a NL and
11435 NULs characters where the text has a NL.
11436
11437 Pipes are not used, the 'shelltemp' option is not used.
11438
11439 When prepended by |:silent| the terminal will not be set to
11440 cooked mode. This is meant to be used for commands that do
11441 not need the user to type. It avoids stray characters showing
11442 up on the screen which require |CTRL-L| to remove. >
11443 :silent let f = system('ls *.vim')
11444<
11445 Note: Use |shellescape()| or |::S| with |expand()| or
11446 |fnamemodify()| to escape special characters in a command
11447 argument. Newlines in {expr} may cause the command to fail.
11448 The characters in 'shellquote' and 'shellxquote' may also
11449 cause trouble.
11450 This is not to be used for interactive commands.
11451
11452 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011453 :let files = system('ls ' .. shellescape(expand('%:h')))
11454 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011455
11456< To make the result more system-independent, the shell output
11457 is filtered to replace <CR> with <NL> for Macintosh, and
11458 <CR><NL> with <NL> for DOS-like systems.
11459 To avoid the string being truncated at a NUL, all NUL
11460 characters are replaced with SOH (0x01).
11461
11462 The command executed is constructed using several options:
11463 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11464 ({tmp} is an automatically generated file name).
11465 For Unix, braces are put around {expr} to allow for
11466 concatenated commands.
11467
11468 The command will be executed in "cooked" mode, so that a
11469 CTRL-C will interrupt the command (on Unix at least).
11470
11471 The resulting error code can be found in |v:shell_error|.
11472 This function will fail in |restricted-mode|.
11473
11474 Note that any wrong value in the options mentioned above may
11475 make the function fail. It has also been reported to fail
11476 when using a security agent application.
11477 Unlike ":!cmd" there is no automatic check for changed files.
11478 Use |:checktime| to force a check.
11479
11480 Can also be used as a |method|: >
11481 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011482<
11483 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011484
11485
11486systemlist({expr} [, {input}]) *systemlist()*
11487 Same as |system()|, but returns a |List| with lines (parts of
11488 output separated by NL) with NULs transformed into NLs. Output
11489 is the same as |readfile()| will output with {binary} argument
11490 set to "b", except that there is no extra empty item when the
11491 result ends in a NL.
11492 Note that on MS-Windows you may get trailing CR characters.
11493
11494 To see the difference between "echo hello" and "echo -n hello"
11495 use |system()| and |split()|: >
11496 echo system('echo hello')->split('\n', 1)
11497<
11498 Returns an empty string on error.
11499
11500 Can also be used as a |method|: >
11501 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011502<
11503 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011504
11505
11506tabpagebuflist([{arg}]) *tabpagebuflist()*
11507 The result is a |List|, where each item is the number of the
11508 buffer associated with each window in the current tab page.
11509 {arg} specifies the number of the tab page to be used. When
11510 omitted the current tab page is used.
11511 When {arg} is invalid the number zero is returned.
11512 To get a list of all buffers in all tabs use this: >
11513 let buflist = []
11514 for i in range(tabpagenr('$'))
11515 call extend(buflist, tabpagebuflist(i + 1))
11516 endfor
11517< Note that a buffer may appear in more than one window.
11518
11519 Can also be used as a |method|: >
11520 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011521<
11522 Return type: list<number>
11523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011524
11525tabpagenr([{arg}]) *tabpagenr()*
11526 The result is a Number, which is the number of the current
11527 tab page. The first tab page has number 1.
11528
11529 The optional argument {arg} supports the following values:
11530 $ the number of the last tab page (the tab page
11531 count).
11532 # the number of the last accessed tab page
11533 (where |g<Tab>| goes to). if there is no
11534 previous tab page 0 is returned.
11535 The number can be used with the |:tab| command.
11536
Bram Moolenaard592deb2022-06-17 15:42:40 +010011537 Returns zero on error.
11538
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011539 Return type: |Number|
11540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011541
11542tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11543 Like |winnr()| but for tab page {tabarg}.
11544 {tabarg} specifies the number of tab page to be used.
11545 {arg} is used like with |winnr()|:
11546 - When omitted the current window number is returned. This is
11547 the window which will be used when going to this tab page.
11548 - When "$" the number of windows is returned.
11549 - When "#" the previous window nr is returned.
11550 Useful examples: >
11551 tabpagewinnr(1) " current window of tab page 1
11552 tabpagewinnr(4, '$') " number of windows in tab page 4
11553< When {tabarg} is invalid zero is returned.
11554
11555 Can also be used as a |method|: >
11556 GetTabpage()->tabpagewinnr()
11557<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011558 Return type: |Number|
11559
11560
11561tagfiles() *tagfiles()*
11562 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011563 for the current buffer. This is the 'tags' option expanded.
11564
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011565 Return type: list<string> or list<any>
11566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011567
11568taglist({expr} [, {filename}]) *taglist()*
11569 Returns a |List| of tags matching the regular expression {expr}.
11570
11571 If {filename} is passed it is used to prioritize the results
11572 in the same way that |:tselect| does. See |tag-priority|.
11573 {filename} should be the full path of the file.
11574
11575 Each list item is a dictionary with at least the following
11576 entries:
11577 name Name of the tag.
11578 filename Name of the file where the tag is
11579 defined. It is either relative to the
11580 current directory or a full path.
11581 cmd Ex command used to locate the tag in
11582 the file.
11583 kind Type of the tag. The value for this
11584 entry depends on the language specific
11585 kind values. Only available when
11586 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011587 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011588 static A file specific tag. Refer to
11589 |static-tag| for more information.
11590 More entries may be present, depending on the content of the
11591 tags file: access, implementation, inherits and signature.
11592 Refer to the ctags documentation for information about these
11593 fields. For C code the fields "struct", "class" and "enum"
11594 may appear, they give the name of the entity the tag is
11595 contained in.
11596
11597 The ex-command "cmd" can be either an ex search pattern, a
11598 line number or a line number followed by a byte number.
11599
11600 If there are no matching tags, then an empty list is returned.
11601
11602 To get an exact tag match, the anchors '^' and '$' should be
11603 used in {expr}. This also make the function work faster.
11604 Refer to |tag-regexp| for more information about the tag
11605 search regular expression pattern.
11606
11607 Refer to |'tags'| for information about how the tags file is
11608 located by Vim. Refer to |tags-file-format| for the format of
11609 the tags file generated by the different ctags tools.
11610
11611 Can also be used as a |method|: >
11612 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011613<
11614 Return type: list<dict<any>> or list<any>
11615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011616
11617tan({expr}) *tan()*
11618 Return the tangent of {expr}, measured in radians, as a |Float|
11619 in the range [-inf, inf].
11620 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011621 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011622 Examples: >
11623 :echo tan(10)
11624< 0.648361 >
11625 :echo tan(-4.01)
11626< -1.181502
11627
11628 Can also be used as a |method|: >
11629 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011630<
11631 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011632
11633
11634tanh({expr}) *tanh()*
11635 Return the hyperbolic tangent of {expr} as a |Float| in the
11636 range [-1, 1].
11637 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011638 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011639 Examples: >
11640 :echo tanh(0.5)
11641< 0.462117 >
11642 :echo tanh(-1)
11643< -0.761594
11644
11645 Can also be used as a |method|: >
11646 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011647<
11648 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011649
11650
11651tempname() *tempname()* *temp-file-name*
11652 The result is a String, which is the name of a file that
11653 doesn't exist. It can be used for a temporary file. The name
11654 is different for at least 26 consecutive calls. Example: >
11655 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011656 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011657< For Unix, the file will be in a private directory |tempfile|
11658 that is recursively deleted when Vim exits, on other systems
11659 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011660 For MS-Windows forward slashes are used when the 'shellslash'
11661 option is set, or when 'shellcmdflag' starts with '-' and
11662 'shell' does not contain powershell or pwsh.
11663
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011664 Return type: |String|
11665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011666
11667term_ functions are documented here: |terminal-function-details|
11668
11669
11670terminalprops() *terminalprops()*
11671 Returns a |Dictionary| with properties of the terminal that Vim
11672 detected from the response to |t_RV| request. See
11673 |v:termresponse| for the response itself. If |v:termresponse|
11674 is empty most values here will be 'u' for unknown.
11675 cursor_style whether sending |t_RS| works **
11676 cursor_blink_mode whether sending |t_RC| works **
11677 underline_rgb whether |t_8u| works **
11678 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011679 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011680
11681 ** value 'u' for unknown, 'y' for yes, 'n' for no
11682
11683 If the |+termresponse| feature is missing then the result is
11684 an empty dictionary.
11685
11686 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11687 current cursor style.
11688 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11689 request the cursor blink status.
11690 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11691 is not empty, Vim will detect the working of sending |t_RS|
11692 and |t_RC| on startup.
11693
11694 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11695 This avoids sending it to xterm, which would clear the colors.
11696
11697 For "mouse" the value 'u' is unknown
11698
11699 Also see:
11700 - 'ambiwidth' - detected by using |t_u7|.
11701 - |v:termstyleresp| and |v:termblinkresp| for the response to
11702 |t_RS| and |t_RC|.
11703
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011704 Return type: dict<string>
11705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011706
11707test_ functions are documented here: |test-functions-details|
11708
11709
11710 *timer_info()*
11711timer_info([{id}])
11712 Return a list with information about timers.
11713 When {id} is given only information about this timer is
11714 returned. When timer {id} does not exist an empty list is
11715 returned.
11716 When {id} is omitted information about all timers is returned.
11717
11718 For each timer the information is stored in a |Dictionary| with
11719 these items:
11720 "id" the timer ID
11721 "time" time the timer was started with
11722 "remaining" time until the timer fires
11723 "repeat" number of times the timer will still fire;
11724 -1 means forever
11725 "callback" the callback
11726 "paused" 1 if the timer is paused, 0 otherwise
11727
11728 Can also be used as a |method|: >
11729 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011730<
11731 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011732
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011733 {only available when compiled with the |+timers| feature}
11734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011735
11736timer_pause({timer}, {paused}) *timer_pause()*
11737 Pause or unpause a timer. A paused timer does not invoke its
11738 callback when its time expires. Unpausing a timer may cause
11739 the callback to be invoked almost immediately if enough time
11740 has passed.
11741
11742 Pausing a timer is useful to avoid the callback to be called
11743 for a short time.
11744
11745 If {paused} evaluates to a non-zero Number or a non-empty
11746 String, then the timer is paused, otherwise it is unpaused.
11747 See |non-zero-arg|.
11748
11749 Can also be used as a |method|: >
11750 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011751<
11752 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011753
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011754 {only available when compiled with the |+timers| feature}
11755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011756
11757 *timer_start()* *timer* *timers*
11758timer_start({time}, {callback} [, {options}])
11759 Create a timer and return the timer ID.
11760
11761 {time} is the waiting time in milliseconds. This is the
11762 minimum time before invoking the callback. When the system is
11763 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011764 Zero can be used to execute the callback when Vim is back in
11765 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011766
11767 {callback} is the function to call. It can be the name of a
11768 function or a |Funcref|. It is called with one argument, which
11769 is the timer ID. The callback is only invoked when Vim is
11770 waiting for input.
11771 If you want to show a message look at |popup_notification()|
11772 to avoid interfering with what the user is doing.
11773
11774 {options} is a dictionary. Supported entries:
11775 "repeat" Number of times to repeat calling the
11776 callback. -1 means forever. When not present
11777 the callback will be called once.
11778 If the timer causes an error three times in a
11779 row the repeat is cancelled. This avoids that
11780 Vim becomes unusable because of all the error
11781 messages.
11782
Bram Moolenaard592deb2022-06-17 15:42:40 +010011783 Returns -1 on error.
11784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011785 Example: >
11786 func MyHandler(timer)
11787 echo 'Handler called'
11788 endfunc
11789 let timer = timer_start(500, 'MyHandler',
11790 \ {'repeat': 3})
11791< This will invoke MyHandler() three times at 500 msec
11792 intervals.
11793
11794 Can also be used as a |method|: >
11795 GetMsec()->timer_start(callback)
11796
11797< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011798
11799 Return type: |Number|
11800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011801 {only available when compiled with the |+timers| feature}
11802
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011804timer_stop({timer}) *timer_stop()*
11805 Stop a timer. The timer callback will no longer be invoked.
11806 {timer} is an ID returned by timer_start(), thus it must be a
11807 Number. If {timer} does not exist there is no error.
11808
11809 Can also be used as a |method|: >
11810 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011811<
11812 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011813
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011814 {only available when compiled with the |+timers| feature}
11815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011816
11817timer_stopall() *timer_stopall()*
11818 Stop all timers. The timer callbacks will no longer be
11819 invoked. Useful if a timer is misbehaving. If there are no
11820 timers there is no error.
11821
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011822 Return type: |Number|
11823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011824 {only available when compiled with the |+timers| feature}
11825
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011827tolower({expr}) *tolower()*
11828 The result is a copy of the String given, with all uppercase
11829 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011830 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011831
11832 Can also be used as a |method|: >
11833 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011834<
11835 Return type: |String|
11836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011837
11838toupper({expr}) *toupper()*
11839 The result is a copy of the String given, with all lowercase
11840 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011841 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011842
11843 Can also be used as a |method|: >
11844 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011845<
11846 Return type: |String|
11847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011848
11849tr({src}, {fromstr}, {tostr}) *tr()*
11850 The result is a copy of the {src} string with all characters
11851 which appear in {fromstr} replaced by the character in that
11852 position in the {tostr} string. Thus the first character in
11853 {fromstr} is translated into the first character in {tostr}
11854 and so on. Exactly like the unix "tr" command.
11855 This code also deals with multibyte characters properly.
11856
Bram Moolenaard592deb2022-06-17 15:42:40 +010011857 Returns an empty string on error.
11858
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011859 Examples: >
11860 echo tr("hello there", "ht", "HT")
11861< returns "Hello THere" >
11862 echo tr("<blob>", "<>", "{}")
11863< returns "{blob}"
11864
11865 Can also be used as a |method|: >
11866 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011867<
11868 Return type: |String|
11869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011870
11871trim({text} [, {mask} [, {dir}]]) *trim()*
11872 Return {text} as a String where any character in {mask} is
11873 removed from the beginning and/or end of {text}.
11874
Illia Bobyr80799172023-10-17 18:00:50 +020011875 If {mask} is not given, or is an empty string, {mask} is all
11876 characters up to 0x20, which includes Tab, space, NL and CR,
11877 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011878
11879 The optional {dir} argument specifies where to remove the
11880 characters:
11881 0 remove from the beginning and end of {text}
11882 1 remove only at the beginning of {text}
11883 2 remove only at the end of {text}
11884 When omitted both ends are trimmed.
11885
11886 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011887 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011888
11889 Examples: >
11890 echo trim(" some text ")
11891< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011892 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011893< returns "RESERVE_TAIL" >
11894 echo trim("rm<Xrm<>X>rrm", "rm<>")
11895< returns "Xrm<>X" (characters in the middle are not removed) >
11896 echo trim(" vim ", " ", 2)
11897< returns " vim"
11898
11899 Can also be used as a |method|: >
11900 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011901<
11902 Return type: |String|
11903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011904
11905trunc({expr}) *trunc()*
11906 Return the largest integral value with magnitude less than or
11907 equal to {expr} as a |Float| (truncate towards zero).
11908 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011909 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011910 Examples: >
11911 echo trunc(1.456)
11912< 1.0 >
11913 echo trunc(-5.456)
11914< -5.0 >
11915 echo trunc(4.0)
11916< 4.0
11917
11918 Can also be used as a |method|: >
11919 Compute()->trunc()
11920<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011921 Return type: |Float|
11922
11923
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011924tuple2list({list}) *tuple2list()*
11925 Create a List from a shallow copy of the tuple items.
11926 Examples: >
11927 tuple2list((1, 2, 3)) returns [1, 2, 3]
11928< |list2tuple()| does the opposite.
11929
11930 This function doesn't recursively convert all the Tuple items
11931 in {tuple} to a List. Note that the items are identical
11932 between the list and the tuple, changing an item changes the
11933 contents of both the tuple and the list.
11934
11935 Returns an empty list on error.
11936
11937 Can also be used as a |method|: >
11938 GetTuple()->tuple2list()
11939<
11940 Return type: list<{type}> (depending on the given |Tuple|)
11941
11942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011943 *type()*
11944type({expr}) The result is a Number representing the type of {expr}.
11945 Instead of using the number directly, it is better to use the
11946 v:t_ variable that has the value:
11947 Number: 0 |v:t_number|
11948 String: 1 |v:t_string|
11949 Funcref: 2 |v:t_func|
11950 List: 3 |v:t_list|
11951 Dictionary: 4 |v:t_dict|
11952 Float: 5 |v:t_float|
11953 Boolean: 6 |v:t_bool| (v:false and v:true)
11954 None: 7 |v:t_none| (v:null and v:none)
11955 Job: 8 |v:t_job|
11956 Channel: 9 |v:t_channel|
11957 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011958 Class: 12 |v:t_class|
11959 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011960 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011961 Enum: 15 |v:t_enum|
11962 EnumValue: 16 |v:t_enumvalue|
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011963 Tuple: 17 |v:t_tuple|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011964 For backward compatibility, this method can be used: >
11965 :if type(myvar) == type(0)
11966 :if type(myvar) == type("")
11967 :if type(myvar) == type(function("tr"))
11968 :if type(myvar) == type([])
11969 :if type(myvar) == type({})
11970 :if type(myvar) == type(0.0)
11971 :if type(myvar) == type(v:false)
11972 :if type(myvar) == type(v:none)
11973< To check if the v:t_ variables exist use this: >
11974 :if exists('v:t_number')
11975
11976< Can also be used as a |method|: >
11977 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011978<
11979 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011980
11981
11982typename({expr}) *typename()*
11983 Return a string representation of the type of {expr}.
11984 Example: >
11985 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011986< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011987
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011988 Return type: |String|
11989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011990
11991undofile({name}) *undofile()*
11992 Return the name of the undo file that would be used for a file
11993 with name {name} when writing. This uses the 'undodir'
11994 option, finding directories that exist. It does not check if
11995 the undo file exists.
11996 {name} is always expanded to the full path, since that is what
11997 is used internally.
11998 If {name} is empty undofile() returns an empty string, since a
11999 buffer without a file name will not write an undo file.
12000 Useful in combination with |:wundo| and |:rundo|.
12001 When compiled without the |+persistent_undo| option this always
12002 returns an empty string.
12003
12004 Can also be used as a |method|: >
12005 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012006<
12007 Return type: |String|
12008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012009
Devin J. Pohly5fee1112023-04-23 20:26:59 -050012010undotree([{buf}]) *undotree()*
12011 Return the current state of the undo tree for the current
12012 buffer, or for a specific buffer if {buf} is given. The
12013 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012014 "seq_last" The highest undo sequence number used.
12015 "seq_cur" The sequence number of the current position in
12016 the undo tree. This differs from "seq_last"
12017 when some changes were undone.
12018 "time_cur" Time last used for |:earlier| and related
12019 commands. Use |strftime()| to convert to
12020 something readable.
12021 "save_last" Number of the last file write. Zero when no
12022 write yet.
12023 "save_cur" Number of the current position in the undo
12024 tree.
12025 "synced" Non-zero when the last undo block was synced.
12026 This happens when waiting from input from the
12027 user. See |undo-blocks|.
12028 "entries" A list of dictionaries with information about
12029 undo blocks.
12030
12031 The first item in the "entries" list is the oldest undo item.
12032 Each List item is a |Dictionary| with these items:
12033 "seq" Undo sequence number. Same as what appears in
12034 |:undolist|.
12035 "time" Timestamp when the change happened. Use
12036 |strftime()| to convert to something readable.
12037 "newhead" Only appears in the item that is the last one
12038 that was added. This marks the last change
12039 and where further changes will be added.
12040 "curhead" Only appears in the item that is the last one
12041 that was undone. This marks the current
12042 position in the undo tree, the block that will
12043 be used by a redo command. When nothing was
12044 undone after the last change this item will
12045 not appear anywhere.
12046 "save" Only appears on the last block before a file
12047 write. The number is the write count. The
12048 first write has number 1, the last one the
12049 "save_last" mentioned above.
12050 "alt" Alternate entry. This is again a List of undo
12051 blocks. Each item may again have an "alt"
12052 item.
12053
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012054 Return type: dict<any>
12055
12056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012057uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
12058 Remove second and succeeding copies of repeated adjacent
12059 {list} items in-place. Returns {list}. If you want a list
12060 to remain unmodified make a copy first: >
12061 :let newlist = uniq(copy(mylist))
12062< The default compare function uses the string representation of
12063 each item. For the use of {func} and {dict} see |sort()|.
12064
Bram Moolenaard592deb2022-06-17 15:42:40 +010012065 Returns zero if {list} is not a |List|.
12066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012067 Can also be used as a |method|: >
12068 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012069<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012070 Return type: list<{type}>
12071
12072
Christian Brabandt67672ef2023-04-24 21:09:54 +010012073 *utf16idx()*
12074utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012075 Same as |charidx()| but returns the UTF-16 code unit index of
12076 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012077
12078 When {charidx} is present and TRUE, {idx} is used as the
12079 character index in the String {string} instead of as the byte
12080 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012081 An {idx} in the middle of a UTF-8 sequence is rounded
12082 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012083
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012084 Returns -1 if the arguments are invalid or if there are less
12085 than {idx} bytes in {string}. If there are exactly {idx} bytes
12086 the length of the string in UTF-16 code units is returned.
12087
Christian Brabandt67672ef2023-04-24 21:09:54 +010012088 See |byteidx()| and |byteidxcomp()| for getting the byte index
12089 from the UTF-16 index and |charidx()| for getting the
12090 character index from the UTF-16 index.
12091 Refer to |string-offset-encoding| for more information.
12092 Examples: >
12093 echo utf16idx('a😊😊', 3) returns 2
12094 echo utf16idx('a😊😊', 7) returns 4
12095 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12096 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12097 echo utf16idx('aą́c', 6) returns 2
12098 echo utf16idx('aą́c', 6, 1) returns 4
12099 echo utf16idx('a😊😊', 9) returns -1
12100<
12101 Can also be used as a |method|: >
12102 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012103<
12104 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012106
12107values({dict}) *values()*
12108 Return a |List| with all the values of {dict}. The |List| is
12109 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012110 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012111
12112 Can also be used as a |method|: >
12113 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012114<
12115 Return type: list<any>
12116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012117
zeertzjq825cf812023-08-17 22:55:25 +020012118virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012119 The result is a Number, which is the screen column of the file
12120 position given with {expr}. That is, the last screen position
12121 occupied by the character at that position, when the screen
12122 would be of unlimited width. When there is a <Tab> at the
12123 position, the returned Number will be the column at the end of
12124 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12125 set to 8, it returns 8. |conceal| is ignored.
12126 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012127
zeertzjq02f3eba2024-06-12 20:45:24 +020012128 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012129 When {expr} is "$", it means the end of the cursor line, so
12130 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012131
12132 When 'virtualedit' is used {expr} can be [lnum, col, off],
12133 where "off" is the offset in screen columns from the start of
12134 the character. E.g., a position within a <Tab> or after the
12135 last character. When "off" is omitted zero is used. When
12136 Virtual editing is active in the current mode, a position
12137 beyond the end of the line can be returned. Also see
12138 |'virtualedit'|
12139
zeertzjq825cf812023-08-17 22:55:25 +020012140 If {list} is present and non-zero then virtcol() returns a
12141 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012142 character.
12143
zeertzjq825cf812023-08-17 22:55:25 +020012144 With the optional {winid} argument the values are obtained for
12145 that window instead of the current window.
12146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012147 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012148
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012149 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012150 " With text "foo^Lbar" and cursor on the "^L":
12151
12152 virtcol(".") " returns 5
12153 virtcol(".", 1) " returns [4, 5]
12154 virtcol("$") " returns 9
12155
12156 " With text " there", with 't at 'h':
12157
12158 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012159<
12160 The first column is 1. 0 or [0, 0] is returned for an error.
12161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012162 A more advanced example that echoes the maximum length of
12163 all lines: >
12164 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12165
12166< Can also be used as a |method|: >
12167 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012168<
12169 Return type: |Number|
12170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012171
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012172virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12173 The result is a Number, which is the byte index of the
12174 character in window {winid} at buffer line {lnum} and virtual
12175 column {col}.
12176
zeertzjqb583eda2023-10-14 11:32:28 +020012177 If buffer line {lnum} is an empty line, 0 is returned.
12178
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012179 If {col} is greater than the last virtual column in line
12180 {lnum}, then the byte index of the character at the last
12181 virtual column is returned.
12182
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012183 For a multi-byte character, the column number of the first
12184 byte in the character is returned.
12185
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012186 The {winid} argument can be the window number or the
12187 |window-ID|. If this is zero, then the current window is used.
12188
12189 Returns -1 if the window {winid} doesn't exist or the buffer
12190 line {lnum} or virtual column {col} is invalid.
12191
12192 See also |screenpos()|, |virtcol()| and |col()|.
12193
12194 Can also be used as a |method|: >
12195 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012196<
12197 Return type: |Number|
12198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012199
12200visualmode([{expr}]) *visualmode()*
12201 The result is a String, which describes the last Visual mode
12202 used in the current buffer. Initially it returns an empty
12203 string, but once Visual mode has been used, it returns "v",
12204 "V", or "<CTRL-V>" (a single CTRL-V character) for
12205 character-wise, line-wise, or block-wise Visual mode
12206 respectively.
12207 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012208 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012209< This enters the same Visual mode as before. It is also useful
12210 in scripts if you wish to act differently depending on the
12211 Visual mode that was used.
12212 If Visual mode is active, use |mode()| to get the Visual mode
12213 (e.g., in a |:vmap|).
12214 If {expr} is supplied and it evaluates to a non-zero Number or
12215 a non-empty String, then the Visual mode will be cleared and
12216 the old value is returned. See |non-zero-arg|.
12217
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012218 Return type: |String|
12219
12220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012221wildmenumode() *wildmenumode()*
12222 Returns |TRUE| when the wildmenu is active and |FALSE|
12223 otherwise. See 'wildmenu' and 'wildmode'.
12224 This can be used in mappings to handle the 'wildcharm' option
12225 gracefully. (Makes only sense with |mapmode-c| mappings).
12226
12227 For example to make <c-j> work like <down> in wildmode, use: >
12228 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12229<
Milly6c2fc372024-10-16 22:11:17 +020012230 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012231
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012232 Return type: |Number|
12233
12234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012235win_execute({id}, {command} [, {silent}]) *win_execute()*
12236 Like `execute()` but in the context of window {id}.
12237 The window will temporarily be made the current window,
12238 without triggering autocommands or changing directory. When
12239 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012240 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012241 Example: >
12242 call win_execute(winid, 'set syntax=python')
12243< Doing the same with `setwinvar()` would not trigger
12244 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012245 *E994*
12246 Not all commands are allowed in popup windows.
12247 When window {id} does not exist then no error is given and
12248 an empty string is returned.
12249
12250 Can also be used as a |method|, the base is passed as the
12251 second argument: >
12252 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012253<
12254 Return type: |String|
12255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012256
12257win_findbuf({bufnr}) *win_findbuf()*
12258 Returns a |List| with |window-ID|s for windows that contain
12259 buffer {bufnr}. When there is none the list is empty.
12260
12261 Can also be used as a |method|: >
12262 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012263<
12264 Return type: list<number> or list<any>
12265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012266
12267win_getid([{win} [, {tab}]]) *win_getid()*
12268 Get the |window-ID| for the specified window.
12269 When {win} is missing use the current window.
12270 With {win} this is the window number. The top window has
12271 number 1.
12272 Without {tab} use the current tab, otherwise the tab with
12273 number {tab}. The first tab has number one.
12274 Return zero if the window cannot be found.
12275
12276 Can also be used as a |method|: >
12277 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012278<
12279 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012280
12281
12282win_gettype([{nr}]) *win_gettype()*
12283 Return the type of the window:
12284 "autocmd" autocommand window. Temporary window
12285 used to execute autocommands.
12286 "command" command-line window |cmdwin|
12287 (empty) normal window
12288 "loclist" |location-list-window|
12289 "popup" popup window |popup|
12290 "preview" preview window |preview-window|
12291 "quickfix" |quickfix-window|
12292 "unknown" window {nr} not found
12293
12294 When {nr} is omitted return the type of the current window.
12295 When {nr} is given return the type of this window by number or
12296 |window-ID|.
12297
12298 Also see the 'buftype' option. When running a terminal in a
12299 popup window then 'buftype' is "terminal" and win_gettype()
12300 returns "popup".
12301
12302 Can also be used as a |method|: >
12303 GetWinid()->win_gettype()
12304<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012305 Return type: |String|
12306
12307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012308win_gotoid({expr}) *win_gotoid()*
12309 Go to window with ID {expr}. This may also change the current
12310 tabpage.
12311 Return TRUE if successful, FALSE if the window cannot be found.
12312
12313 Can also be used as a |method|: >
12314 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012315<
12316 Return type: |Number|
12317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012318
12319win_id2tabwin({expr}) *win_id2tabwin()*
12320 Return a list with the tab number and window number of window
12321 with ID {expr}: [tabnr, winnr].
12322 Return [0, 0] if the window cannot be found.
12323
12324 Can also be used as a |method|: >
12325 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012326<
12327 Return type: list<number>
12328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012329
12330win_id2win({expr}) *win_id2win()*
12331 Return the window number of window with ID {expr}.
12332 Return 0 if the window cannot be found in the current tabpage.
12333
12334 Can also be used as a |method|: >
12335 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012336<
12337 Return type: |Number|
12338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012339
Daniel Steinbergee630312022-01-10 13:36:34 +000012340win_move_separator({nr}, {offset}) *win_move_separator()*
12341 Move window {nr}'s vertical separator (i.e., the right border)
12342 by {offset} columns, as if being dragged by the mouse. {nr}
12343 can be a window number or |window-ID|. A positive {offset}
12344 moves right and a negative {offset} moves left. Moving a
12345 window's vertical separator will change the width of the
12346 window and the width of other windows adjacent to the vertical
12347 separator. The magnitude of movement may be smaller than
12348 specified (e.g., as a consequence of maintaining
12349 'winminwidth'). Returns TRUE if the window can be found and
12350 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012351 This will fail for the rightmost window and a full-width
12352 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012353 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012354
12355 Can also be used as a |method|: >
12356 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012357<
12358 Return type: |Number|
12359
Daniel Steinbergee630312022-01-10 13:36:34 +000012360
12361win_move_statusline({nr}, {offset}) *win_move_statusline()*
12362 Move window {nr}'s status line (i.e., the bottom border) by
12363 {offset} rows, as if being dragged by the mouse. {nr} can be a
12364 window number or |window-ID|. A positive {offset} moves down
12365 and a negative {offset} moves up. Moving a window's status
12366 line will change the height of the window and the height of
12367 other windows adjacent to the status line. The magnitude of
12368 movement may be smaller than specified (e.g., as a consequence
12369 of maintaining 'winminheight'). Returns TRUE if the window can
12370 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012371 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012372
12373 Can also be used as a |method|: >
12374 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012375<
12376 Return type: |Number|
12377
Daniel Steinbergee630312022-01-10 13:36:34 +000012378
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012379win_screenpos({nr}) *win_screenpos()*
12380 Return the screen position of window {nr} as a list with two
12381 numbers: [row, col]. The first window always has position
12382 [1, 1], unless there is a tabline, then it is [2, 1].
12383 {nr} can be the window number or the |window-ID|. Use zero
12384 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012385 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012386
12387 Can also be used as a |method|: >
12388 GetWinid()->win_screenpos()
12389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012390 Return type: list<number>
12391
12392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012393win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012394 Temporarily switch to window {target}, then move window {nr}
12395 to a new split adjacent to {target}.
12396 Unlike commands such as |:split|, no new windows are created
12397 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012398
12399 Both {nr} and {target} can be window numbers or |window-ID|s.
12400 Both must be in the current tab page.
12401
12402 Returns zero for success, non-zero for failure.
12403
12404 {options} is a |Dictionary| with the following optional entries:
12405 "vertical" When TRUE, the split is created vertically,
12406 like with |:vsplit|.
12407 "rightbelow" When TRUE, the split is made below or to the
12408 right (if vertical). When FALSE, it is done
12409 above or to the left (if vertical). When not
12410 present, the values of 'splitbelow' and
12411 'splitright' are used.
12412
12413 Can also be used as a |method|: >
12414 GetWinid()->win_splitmove(target)
12415<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012416 Return type: |Number|
12417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012418
12419 *winbufnr()*
12420winbufnr({nr}) The result is a Number, which is the number of the buffer
12421 associated with window {nr}. {nr} can be the window number or
12422 the |window-ID|.
12423 When {nr} is zero, the number of the buffer in the current
12424 window is returned.
12425 When window {nr} doesn't exist, -1 is returned.
12426 Example: >
12427 :echo "The file in the current window is " . bufname(winbufnr(0))
12428<
12429 Can also be used as a |method|: >
12430 FindWindow()->winbufnr()->bufname()
12431<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012432 Return type: |Number|
12433
12434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012435 *wincol()*
12436wincol() The result is a Number, which is the virtual column of the
12437 cursor in the window. This is counting screen cells from the
12438 left side of the window. The leftmost column is one.
12439
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012440 Return type: |Number|
12441
12442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012443 *windowsversion()*
12444windowsversion()
12445 The result is a String. For MS-Windows it indicates the OS
12446 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12447 Windows XP is "5.1". For non-MS-Windows systems the result is
12448 an empty string.
12449
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012450 Return type: |String|
12451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012452winheight({nr}) *winheight()*
12453 The result is a Number, which is the height of window {nr}.
12454 {nr} can be the window number or the |window-ID|.
12455 When {nr} is zero, the height of the current window is
12456 returned. When window {nr} doesn't exist, -1 is returned.
12457 An existing window always has a height of zero or more.
12458 This excludes any window toolbar line.
12459 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012460 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012461
12462< Can also be used as a |method|: >
12463 GetWinid()->winheight()
12464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012465 Return type: |Number|
12466
12467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012468winlayout([{tabnr}]) *winlayout()*
12469 The result is a nested List containing the layout of windows
12470 in a tabpage.
12471
12472 Without {tabnr} use the current tabpage, otherwise the tabpage
12473 with number {tabnr}. If the tabpage {tabnr} is not found,
12474 returns an empty list.
12475
12476 For a leaf window, it returns:
12477 ['leaf', {winid}]
12478 For horizontally split windows, which form a column, it
12479 returns:
12480 ['col', [{nested list of windows}]]
12481 For vertically split windows, which form a row, it returns:
12482 ['row', [{nested list of windows}]]
12483
12484 Example: >
12485 " Only one window in the tab page
12486 :echo winlayout()
12487 ['leaf', 1000]
12488 " Two horizontally split windows
12489 :echo winlayout()
12490 ['col', [['leaf', 1000], ['leaf', 1001]]]
12491 " The second tab page, with three horizontally split
12492 " windows, with two vertically split windows in the
12493 " middle window
12494 :echo winlayout(2)
12495 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12496 ['leaf', 1001]]], ['leaf', 1000]]]
12497<
12498 Can also be used as a |method|: >
12499 GetTabnr()->winlayout()
12500<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012501 Return type: list<any>
12502
12503
12504winline() *winline()*
12505 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012506 in the window. This is counting screen lines from the top of
12507 the window. The first line is one.
12508 If the cursor was moved the view on the file will be updated
12509 first, this may cause a scroll.
12510
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012511 Return type: |Number|
12512
12513
12514winnr([{arg}]) *winnr()*
12515 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012516 window. The top window has number 1.
12517 Returns zero for a popup window.
12518
12519 The optional argument {arg} supports the following values:
12520 $ the number of the last window (the window
12521 count).
12522 # the number of the last accessed window (where
12523 |CTRL-W_p| goes to). If there is no previous
12524 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012525 returned. May refer to the current window in
12526 some cases (e.g. when evaluating 'statusline'
12527 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012528 {N}j the number of the Nth window below the
12529 current window (where |CTRL-W_j| goes to).
12530 {N}k the number of the Nth window above the current
12531 window (where |CTRL-W_k| goes to).
12532 {N}h the number of the Nth window left of the
12533 current window (where |CTRL-W_h| goes to).
12534 {N}l the number of the Nth window right of the
12535 current window (where |CTRL-W_l| goes to).
12536 The number can be used with |CTRL-W_w| and ":wincmd w"
12537 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012538 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012539 Also see |tabpagewinnr()| and |win_getid()|.
12540 Examples: >
12541 let window_count = winnr('$')
12542 let prev_window = winnr('#')
12543 let wnum = winnr('3k')
12544
12545< Can also be used as a |method|: >
12546 GetWinval()->winnr()
12547<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012548 Return type: |Number|
12549
12550
12551winrestcmd() *winrestcmd()*
12552 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012553 the current window sizes. Only works properly when no windows
12554 are opened or closed and the current window and tab page is
12555 unchanged.
12556 Example: >
12557 :let cmd = winrestcmd()
12558 :call MessWithWindowSizes()
12559 :exe cmd
12560<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012561 Return type: |String|
12562
12563
12564winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012565 Uses the |Dictionary| returned by |winsaveview()| to restore
12566 the view of the current window.
12567 Note: The {dict} does not have to contain all values, that are
12568 returned by |winsaveview()|. If values are missing, those
12569 settings won't be restored. So you can use: >
12570 :call winrestview({'curswant': 4})
12571<
12572 This will only set the curswant value (the column the cursor
12573 wants to move on vertical movements) of the cursor to column 5
12574 (yes, that is 5), while all other settings will remain the
12575 same. This is useful, if you set the cursor position manually.
12576
12577 If you have changed the values the result is unpredictable.
12578 If the window size changed the result won't be the same.
12579
12580 Can also be used as a |method|: >
12581 GetView()->winrestview()
12582<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012583 Return type: |Number|
12584
12585
12586winsaveview() *winsaveview()*
12587 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012588 the view of the current window. Use |winrestview()| to
12589 restore the view.
12590 This is useful if you have a mapping that jumps around in the
12591 buffer and you want to go back to the original view.
12592 This does not save fold information. Use the 'foldenable'
12593 option to temporarily switch off folding, so that folds are
12594 not opened when moving around. This may have side effects.
12595 The return value includes:
12596 lnum cursor line number
12597 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012598 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012599 returns)
12600 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012601 curswant column for vertical movement (Note:
12602 the first column is zero, as opposed
12603 to what |getcurpos()| returns). After
12604 |$| command it will be a very large
12605 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012606 topline first line in the window
12607 topfill filler lines, only in diff mode
12608 leftcol first column displayed; only used when
12609 'wrap' is off
12610 skipcol columns skipped
12611 Note that no option values are saved.
12612
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012613 Return type: dict<number>
12614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012615
12616winwidth({nr}) *winwidth()*
12617 The result is a Number, which is the width of window {nr}.
12618 {nr} can be the window number or the |window-ID|.
12619 When {nr} is zero, the width of the current window is
12620 returned. When window {nr} doesn't exist, -1 is returned.
12621 An existing window always has a width of zero or more.
12622 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012623 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012624 :if winwidth(0) <= 50
12625 : 50 wincmd |
12626 :endif
12627< For getting the terminal or screen size, see the 'columns'
12628 option.
12629
12630 Can also be used as a |method|: >
12631 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012632<
12633 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012634
12635
12636wordcount() *wordcount()*
12637 The result is a dictionary of byte/chars/word statistics for
12638 the current buffer. This is the same info as provided by
12639 |g_CTRL-G|
12640 The return value includes:
12641 bytes Number of bytes in the buffer
12642 chars Number of chars in the buffer
12643 words Number of words in the buffer
12644 cursor_bytes Number of bytes before cursor position
12645 (not in Visual mode)
12646 cursor_chars Number of chars before cursor position
12647 (not in Visual mode)
12648 cursor_words Number of words before cursor position
12649 (not in Visual mode)
12650 visual_bytes Number of bytes visually selected
12651 (only in Visual mode)
12652 visual_chars Number of chars visually selected
12653 (only in Visual mode)
12654 visual_words Number of words visually selected
12655 (only in Visual mode)
12656
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012657 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012658
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012659
12660writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012661 When {object} is a |List| write it to file {fname}. Each list
12662 item is separated with a NL. Each list item must be a String
12663 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012664 All NL characters are replaced with a NUL character.
12665 Inserting CR characters needs to be done before passing {list}
12666 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012667
12668 When {object} is a |Blob| write the bytes to file {fname}
12669 unmodified, also when binary mode is not specified.
12670
12671 {flags} must be a String. These characters are recognized:
12672
12673 'b' Binary mode is used: There will not be a NL after the
12674 last list item. An empty item at the end does cause the
12675 last line in the file to end in a NL.
12676
12677 'a' Append mode is used, lines are appended to the file: >
12678 :call writefile(["foo"], "event.log", "a")
12679 :call writefile(["bar"], "event.log", "a")
12680<
12681 'D' Delete the file when the current function ends. This
12682 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012683 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012684< Fails when not in a function. Also see |:defer|.
12685
12686 's' fsync() is called after writing the file. This flushes
12687 the file to disk, if possible. This takes more time but
12688 avoids losing the file if the system crashes.
12689
12690 'S' fsync() is not called, even when 'fsync' is set.
12691
12692 When {flags} does not contain "S" or "s" then fsync() is
12693 called if the 'fsync' option is set.
12694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012695 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012697 When the write fails -1 is returned, otherwise 0. There is an
12698 error message if the file can't be created or when writing
12699 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012701 Also see |readfile()|.
12702 To copy a file byte for byte: >
12703 :let fl = readfile("foo", "b")
12704 :call writefile(fl, "foocopy", "b")
12705
12706< Can also be used as a |method|: >
12707 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012708<
12709 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012710
12711
12712xor({expr}, {expr}) *xor()*
12713 Bitwise XOR on the two arguments. The arguments are converted
12714 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012715 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012716 Example: >
12717 :let bits = xor(bits, 0x80)
12718<
12719 Can also be used as a |method|: >
12720 :let bits = bits->xor(0x80)
12721<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012722 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012723
12724==============================================================================
127253. Feature list *feature-list*
12726
12727There are three types of features:
127281. Features that are only supported when they have been enabled when Vim
12729 was compiled |+feature-list|. Example: >
12730 :if has("cindent")
12731< *gui_running*
127322. Features that are only supported when certain conditions have been met.
12733 Example: >
12734 :if has("gui_running")
12735< *has-patch*
127363. Beyond a certain version or at a certain version and including a specific
12737 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12738 later, or it is version 7.4 and patch 248 was included. Example: >
12739 :if has("patch-7.4.248")
12740< Note that it's possible for patch 248 to be omitted even though 249 is
12741 included. Only happens when cherry-picking patches.
12742 Note that this form only works for patch 7.4.237 and later, before that
12743 you need to check for the patch and the v:version. Example (checking
12744 version 6.2.148 or later): >
12745 :if v:version > 602 || (v:version == 602 && has("patch148"))
12746
12747Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12748use: `if exists('+shellslash')`
12749
12750
12751acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012752all_builtin_terms Compiled with all builtin terminals enabled. (always
12753 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012754amiga Amiga version of Vim.
12755arabic Compiled with Arabic support |Arabic|.
12756arp Compiled with ARP support (Amiga).
12757autocmd Compiled with autocommand support. (always true)
12758autochdir Compiled with support for 'autochdir'
12759autoservername Automatically enable |clientserver|
12760balloon_eval Compiled with |balloon-eval| support.
12761balloon_multiline GUI supports multiline balloons.
12762beos BeOS version of Vim.
12763browse Compiled with |:browse| support, and browse() will
12764 work.
12765browsefilter Compiled with support for |browsefilter|.
12766bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012767builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012768byte_offset Compiled with support for 'o' in 'statusline'
12769channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012770cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012771clientserver Compiled with remote invocation support |clientserver|.
12772clipboard Compiled with 'clipboard' support.
12773clipboard_working Compiled with 'clipboard' support and it can be used.
12774cmdline_compl Compiled with |cmdline-completion| support.
12775cmdline_hist Compiled with |cmdline-history| support.
12776cmdline_info Compiled with 'showcmd' and 'ruler' support.
12777comments Compiled with |'comments'| support.
12778compatible Compiled to be very Vi compatible.
12779conpty Platform where |ConPTY| can be used.
12780cryptv Compiled with encryption support |encryption|.
12781cscope Compiled with |cscope| support.
12782cursorbind Compiled with |'cursorbind'| (always true)
12783debug Compiled with "DEBUG" defined.
12784dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012785dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012786dialog_gui Compiled with GUI dialog support.
12787diff Compiled with |vimdiff| and 'diff' support.
12788digraphs Compiled with support for digraphs.
12789directx Compiled with support for DirectX and 'renderoptions'.
12790dnd Compiled with support for the "~ register |quote_~|.
12791drop_file Compiled with |drop_file| support.
12792ebcdic Compiled on a machine with ebcdic character set.
12793emacs_tags Compiled with support for Emacs tags.
12794eval Compiled with expression evaluation support. Always
12795 true, of course!
12796ex_extra |+ex_extra| (always true)
12797extra_search Compiled with support for |'incsearch'| and
12798 |'hlsearch'|
12799farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012800file_in_path Compiled with support for |gf| and |<cfile>| (always
12801 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012802filterpipe When 'shelltemp' is off pipes are used for shell
12803 read/write/filter commands
12804find_in_path Compiled with support for include file searches
12805 |+find_in_path|.
12806float Compiled with support for |Float|.
12807fname_case Case in file names matters (for Amiga and MS-Windows
12808 this is not present).
12809folding Compiled with |folding| support.
12810footer Compiled with GUI footer support. |gui-footer|
12811fork Compiled to use fork()/exec() instead of system().
12812gettext Compiled with message translation |multi-lang|
12813gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012814gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012815gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12816gui_gtk Compiled with GTK+ GUI (any version).
12817gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12818gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12819gui_haiku Compiled with Haiku GUI.
12820gui_mac Compiled with Macintosh GUI.
12821gui_motif Compiled with Motif GUI.
12822gui_photon Compiled with Photon GUI.
12823gui_running Vim is running in the GUI, or it will start soon.
12824gui_win32 Compiled with MS-Windows Win32 GUI.
12825gui_win32s idem, and Win32s system being used (Windows 3.1)
12826haiku Haiku version of Vim.
12827hangul_input Compiled with Hangul input support. |hangul|
12828hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012829hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012830iconv Can use iconv() for conversion.
12831insert_expand Compiled with support for CTRL-X expansion commands in
12832 Insert mode. (always true)
12833job Compiled with support for |channel| and |job|
12834ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012835jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012836keymap Compiled with 'keymap' support.
12837lambda Compiled with |lambda| support.
12838langmap Compiled with 'langmap' support.
12839libcall Compiled with |libcall()| support.
12840linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12841 'breakindent' support.
12842linux Linux version of Vim.
12843lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012844 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012845listcmds Compiled with commands for the buffer list |:files|
12846 and the argument list |arglist|.
12847localmap Compiled with local mappings and abbr. |:map-local|
12848lua Compiled with Lua interface |Lua|.
12849mac Any Macintosh version of Vim cf. osx
12850macunix Synonym for osxdarwin
12851menu Compiled with support for |:menu|.
12852mksession Compiled with support for |:mksession|.
12853modify_fname Compiled with file name modifiers. |filename-modifiers|
12854 (always true)
12855mouse Compiled with support for mouse.
12856mouse_dec Compiled with support for Dec terminal mouse.
12857mouse_gpm Compiled with support for gpm (Linux console mouse)
12858mouse_gpm_enabled GPM mouse is working
12859mouse_netterm Compiled with support for netterm mouse.
12860mouse_pterm Compiled with support for qnx pterm mouse.
12861mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12862mouse_sgr Compiled with support for sgr mouse.
12863mouse_urxvt Compiled with support for urxvt mouse.
12864mouse_xterm Compiled with support for xterm mouse.
12865mouseshape Compiled with support for 'mouseshape'.
12866multi_byte Compiled with support for 'encoding' (always true)
12867multi_byte_encoding 'encoding' is set to a multibyte encoding.
12868multi_byte_ime Compiled with support for IME input method.
12869multi_lang Compiled with support for multiple languages.
12870mzscheme Compiled with MzScheme interface |mzscheme|.
12871nanotime Compiled with sub-second time stamp checks.
12872netbeans_enabled Compiled with support for |netbeans| and connected.
12873netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012874num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012875ole Compiled with OLE automation support for Win32.
12876osx Compiled for macOS cf. mac
12877osxdarwin Compiled for macOS, with |mac-darwin-feature|
12878packages Compiled with |packages| support.
12879path_extra Compiled with up/downwards search in 'path' and 'tags'
12880perl Compiled with Perl interface.
12881persistent_undo Compiled with support for persistent undo history.
12882postscript Compiled with PostScript file printing.
12883printer Compiled with |:hardcopy| support.
12884profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012885prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012886python Python 2.x interface available. |has-python|
12887python_compiled Compiled with Python 2.x interface. |has-python|
12888python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12889python3 Python 3.x interface available. |has-python|
12890python3_compiled Compiled with Python 3.x interface. |has-python|
12891python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012892python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012893pythonx Python 2.x and/or 3.x interface available. |python_x|
12894qnx QNX version of Vim.
12895quickfix Compiled with |quickfix| support.
12896reltime Compiled with |reltime()| support.
12897rightleft Compiled with 'rightleft' support.
12898ruby Compiled with Ruby interface |ruby|.
12899scrollbind Compiled with 'scrollbind' support. (always true)
12900showcmd Compiled with 'showcmd' support.
12901signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012902smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012903sodium Compiled with libsodium for better crypt support
12904sound Compiled with sound support, e.g. `sound_playevent()`
12905spell Compiled with spell checking support |spell|.
12906startuptime Compiled with |--startuptime| support.
12907statusline Compiled with support for 'statusline', 'rulerformat'
12908 and special formats of 'titlestring' and 'iconstring'.
12909sun SunOS version of Vim.
12910sun_workshop Support for Sun |workshop| has been removed.
12911syntax Compiled with syntax highlighting support |syntax|.
12912syntax_items There are active syntax highlighting items for the
12913 current buffer.
12914system Compiled to use system() instead of fork()/exec().
12915tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012916 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012917tag_old_static Support for old static tags was removed, see
12918 |tag-old-static|.
12919tcl Compiled with Tcl interface.
12920termguicolors Compiled with true color in terminal support.
12921terminal Compiled with |terminal| support.
12922terminfo Compiled with terminfo instead of termcap.
12923termresponse Compiled with support for |t_RV| and |v:termresponse|.
12924textobjects Compiled with support for |text-objects|.
12925textprop Compiled with support for |text-properties|.
12926tgetent Compiled with tgetent support, able to use a termcap
12927 or terminfo file.
12928timers Compiled with |timer_start()| support.
12929title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012930 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012931toolbar Compiled with support for |gui-toolbar|.
12932ttyin input is a terminal (tty)
12933ttyout output is a terminal (tty)
12934unix Unix version of Vim. *+unix*
12935unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12936user_commands User-defined commands. (always true)
12937vartabs Compiled with variable tabstop support |'vartabstop'|.
12938vcon Win32: Virtual console support is working, can use
12939 'termguicolors'. Also see |+vtp|.
12940vertsplit Compiled with vertically split windows |:vsplit|.
12941 (always true)
12942vim_starting True while initial source'ing takes place. |startup|
12943 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012944vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012945viminfo Compiled with viminfo support.
12946vimscript-1 Compiled Vim script version 1 support
12947vimscript-2 Compiled Vim script version 2 support
12948vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012949vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012950virtualedit Compiled with 'virtualedit' option. (always true)
12951visual Compiled with Visual mode. (always true)
12952visualextra Compiled with extra Visual mode commands. (always
12953 true) |blockwise-operators|.
12954vms VMS version of Vim.
12955vreplace Compiled with |gR| and |gr| commands. (always true)
12956vtp Compiled for vcon support |+vtp| (check vcon to find
12957 out if it works in the current console).
12958wildignore Compiled with 'wildignore' option.
12959wildmenu Compiled with 'wildmenu' option.
12960win16 old version for MS-Windows 3.1 (always false)
12961win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12962 64 bits)
12963win32unix Win32 version of Vim, using Unix files (Cygwin)
12964win64 Win64 version of Vim (MS-Windows 64 bit).
12965win95 Win32 version for MS-Windows 95/98/ME (always false)
12966winaltkeys Compiled with 'winaltkeys' option.
12967windows Compiled with support for more than one window.
12968 (always true)
12969writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012970xattr Compiled with extended attributes support |xattr|
12971 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012972xfontset Compiled with X fontset support |xfontset|.
12973xim Compiled with X input method support |xim|.
12974xpm Compiled with pixmap support.
12975xpm_w32 Compiled with pixmap support for Win32. (Only for
12976 backward compatibility. Use "xpm" instead.)
12977xsmp Compiled with X session management support.
12978xsmp_interact Compiled with interactive X session management support.
12979xterm_clipboard Compiled with support for xterm clipboard.
12980xterm_save Compiled with support for saving and restoring the
12981 xterm screen.
12982x11 Compiled with X11 support.
12983
12984
12985==============================================================================
129864. Matching a pattern in a String *string-match*
12987
12988This is common between several functions. A regexp pattern as explained at
12989|pattern| is normally used to find a match in the buffer lines. When a
12990pattern is used to find a match in a String, almost everything works in the
12991same way. The difference is that a String is handled like it is one line.
12992When it contains a "\n" character, this is not seen as a line break for the
12993pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12994>
12995 :let a = "aaaa\nxxxx"
12996 :echo matchstr(a, "..\n..")
12997 aa
12998 xx
12999 :echo matchstr(a, "a.x")
13000 a
13001 x
13002
13003Don't forget that "^" will only match at the first character of the String and
13004"$" at the last character of the string. They don't match after or before a
13005"\n".
13006
13007 vim:tw=78:ts=8:noet:ft=help:norl: