blob: f3baf2470aa88099296c32494563eaab3c8499f3 [file] [log] [blame]
RestorerZ96509102024-07-11 21:14:15 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jul 11
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
Christ van Willegence0ef912024-06-20 23:41:59 +020070bindtextdomain({package}, {path})
71 none bind text domain to specied path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000072blob2list({blob}) List convert {blob} into a list of numbers
73browse({save}, {title}, {initdir}, {default})
74 String put up a file requester
75browsedir({title}, {initdir}) String put up a directory requester
76bufadd({name}) Number add a buffer to the buffer list
77bufexists({buf}) Number |TRUE| if buffer {buf} exists
78buflisted({buf}) Number |TRUE| if buffer {buf} is listed
79bufload({buf}) Number load buffer {buf} if not loaded yet
80bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
81bufname([{buf}]) String Name of the buffer {buf}
82bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
83bufwinid({buf}) Number window ID of buffer {buf}
84bufwinnr({buf}) Number window number of buffer {buf}
85byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010086byteidx({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
88byteidxcomp({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000090call({func}, {arglist} [, {dict}])
91 any call {func} with arguments {arglist}
92ceil({expr}) Float round {expr} up
93ch_canread({handle}) Number check if there is something to read
94ch_close({handle}) none close {handle}
95ch_close_in({handle}) none close in part of {handle}
96ch_evalexpr({handle}, {expr} [, {options}])
97 any evaluate {expr} on JSON {handle}
98ch_evalraw({handle}, {string} [, {options}])
99 any evaluate {string} on raw {handle}
100ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
101ch_getjob({channel}) Job get the Job of {channel}
102ch_info({handle}) String info about channel {handle}
103ch_log({msg} [, {handle}]) none write {msg} in the channel log file
104ch_logfile({fname} [, {mode}]) none start logging channel activity
105ch_open({address} [, {options}])
106 Channel open a channel to {address}
107ch_read({handle} [, {options}]) String read from {handle}
108ch_readblob({handle} [, {options}])
109 Blob read Blob from {handle}
110ch_readraw({handle} [, {options}])
111 String read raw from {handle}
112ch_sendexpr({handle}, {expr} [, {options}])
113 any send {expr} over JSON {handle}
114ch_sendraw({handle}, {expr} [, {options}])
115 any send {expr} over raw {handle}
116ch_setoptions({handle}, {options})
117 none set options for {handle}
118ch_status({handle} [, {options}])
119 String status of channel {handle}
120changenr() Number current change number
121char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
122charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000123charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100124charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000125 Number char index of byte {idx} in {string}
126chdir({dir}) String change current working directory
127cindent({lnum}) Number C indent for line {lnum}
128clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000129col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000130complete({startcol}, {matches}) none set Insert mode completion
131complete_add({expr}) Number add completion match
132complete_check() Number check for key typed during completion
133complete_info([{what}]) Dict get current completion information
134confirm({msg} [, {choices} [, {default} [, {type}]]])
135 Number number of choice picked by user
136copy({expr}) any make a shallow copy of {expr}
137cos({expr}) Float cosine of {expr}
138cosh({expr}) Float hyperbolic cosine of {expr}
139count({comp}, {expr} [, {ic} [, {start}]])
140 Number count how many {expr} are in {comp}
141cscope_connection([{num}, {dbpath} [, {prepend}]])
142 Number checks existence of cscope connection
143cursor({lnum}, {col} [, {off}])
144 Number move cursor to {lnum}, {col}, {off}
145cursor({list}) Number move cursor to position in {list}
146debugbreak({pid}) Number interrupt process being debugged
147deepcopy({expr} [, {noref}]) any make a full copy of {expr}
148delete({fname} [, {flags}]) Number delete the file or directory {fname}
149deletebufline({buf}, {first} [, {last}])
150 Number delete lines from buffer {buf}
151did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100152diff({fromlist}, {tolist} [, {options}])
153 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000154diff_filler({lnum}) Number diff filler lines about {lnum}
155diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
156digraph_get({chars}) String get the |digraph| of {chars}
157digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200158digraph_set({chars}, {digraph}) Bool register |digraph|
159digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160echoraw({expr}) none output {expr} as-is
161empty({expr}) Number |TRUE| if {expr} is empty
162environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100163err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000164escape({string}, {chars}) String escape {chars} in {string} with '\'
165eval({string}) any evaluate {string} into its value
166eventhandler() Number |TRUE| if inside an event handler
167executable({expr}) Number 1 if executable {expr} exists
168execute({command}) String execute {command} and get the output
169exepath({expr}) String full path of the command {expr}
170exists({expr}) Number |TRUE| if {expr} exists
171exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
172exp({expr}) Float exponential of {expr}
173expand({expr} [, {nosuf} [, {list}]])
174 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100175expandcmd({string} [, {options}])
176 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000177extend({expr1}, {expr2} [, {expr3}])
178 List/Dict insert items of {expr2} into {expr1}
179extendnew({expr1}, {expr2} [, {expr3}])
180 List/Dict like |extend()| but creates a new
181 List or Dictionary
182feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200183filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
184 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000185filereadable({file}) Number |TRUE| if {file} is a readable file
186filewritable({file}) Number |TRUE| if {file} is a writable file
187filter({expr1}, {expr2}) List/Dict/Blob/String
188 remove items from {expr1} where
189 {expr2} is 0
190finddir({name} [, {path} [, {count}]])
191 String find directory {name} in {path}
192findfile({name} [, {path} [, {count}]])
193 String find file {name} in {path}
194flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
195flattennew({list} [, {maxdepth}])
196 List flatten a copy of {list}
197float2nr({expr}) Number convert Float {expr} to a Number
198floor({expr}) Float round {expr} down
199fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
200fnameescape({fname}) String escape special characters in {fname}
201fnamemodify({fname}, {mods}) String modify file name
202foldclosed({lnum}) Number first line of fold at {lnum} if closed
203foldclosedend({lnum}) Number last line of fold at {lnum} if closed
204foldlevel({lnum}) Number fold level at {lnum}
205foldtext() String line displayed for closed fold
206foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100207foreach({expr1}, {expr2}) List/Dict/Blob/String
208 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100210fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211funcref({name} [, {arglist}] [, {dict}])
212 Funcref reference to function {name}
213function({name} [, {arglist}] [, {dict}])
214 Funcref named reference to function {name}
215garbagecollect([{atexit}]) none free memory, breaking cyclic references
216get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
217get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
218get({func}, {what}) any get property of funcref/partial {func}
219getbufinfo([{buf}]) List information about buffers
220getbufline({buf}, {lnum} [, {end}])
221 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000222getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000223getbufvar({buf}, {varname} [, {def}])
224 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000225getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200227getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000228 get one character from the user
229getcharmod() Number modifiers for the last typed character
230getcharpos({expr}) List position of cursor, mark, etc.
231getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200232getcharstr([{expr}]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100233getcmdcompltype() String return the type of the current
234 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000235getcmdline() String return the current command-line
236getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100237getcmdscreenpos() Number return cursor screen position in
238 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000239getcmdtype() String return current command-line type
240getcmdwintype() String return current command-line window type
241getcompletion({pat}, {type} [, {filtered}])
242 List list of cmdline completion matches
243getcurpos([{winnr}]) List position of the cursor
244getcursorcharpos([{winnr}]) List character position of the cursor
245getcwd([{winnr} [, {tabnr}]]) String get the current working directory
246getenv({name}) String return environment variable
247getfontname([{name}]) String name of font being used
248getfperm({fname}) String file permissions of file {fname}
249getfsize({fname}) Number size in bytes of file {fname}
250getftime({fname}) Number last modification time of file
251getftype({fname}) String description of type of file {fname}
252getimstatus() Number |TRUE| if the IME status is active
253getjumplist([{winnr} [, {tabnr}]])
254 List list of jump list items
255getline({lnum}) String line {lnum} of current buffer
256getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
257getloclist({nr}) List list of location list items
258getloclist({nr}, {what}) Dict get specific location list properties
259getmarklist([{buf}]) List list of global/local marks
260getmatches([{win}]) List list of current matches
261getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000262getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000263getpid() Number process ID of Vim
264getpos({expr}) List position of cursor, mark, etc.
265getqflist() List list of quickfix items
266getqflist({what}) Dict get specific quickfix list properties
267getreg([{regname} [, 1 [, {list}]]])
268 String or List contents of a register
269getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100270getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100271 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200272getregionpos({pos1}, {pos2} [, {opts}])
273 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000274getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100275getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000276gettabinfo([{expr}]) List list of tab pages
277gettabvar({nr}, {varname} [, {def}])
278 any variable {varname} in tab {nr} or {def}
279gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
280 any {name} in {winnr} in tab page {tabnr}
281gettagstack([{nr}]) Dict get the tag stack of window {nr}
Christ van Willegence0ef912024-06-20 23:41:59 +0200282gettext({text} [, {package}])
283 String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000285getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286getwinposx() Number X coord in pixels of the Vim window
287getwinposy() Number Y coord in pixels of the Vim window
288getwinvar({nr}, {varname} [, {def}])
289 any variable {varname} in window {nr}
290glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
291 any expand file wildcards in {expr}
292glob2regpat({expr}) String convert a glob pat into a search pat
293globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
294 String do glob({expr}) for all dirs in {path}
295has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
296has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
297haslocaldir([{winnr} [, {tabnr}]])
298 Number |TRUE| if the window executed |:lcd|
299 or |:tcd|
300hasmapto({what} [, {mode} [, {abbr}]])
301 Number |TRUE| if mapping to {what} exists
302histadd({history}, {item}) Number add an item to a history
303histdel({history} [, {item}]) Number remove an item from a history
304histget({history} [, {index}]) String get the item {index} from a history
305histnr({history}) Number highest index of a history
306hlID({name}) Number syntax ID of highlight group {name}
307hlexists({name}) Number |TRUE| if highlight group {name} exists
308hlget([{name} [, {resolve}]]) List get highlight group attributes
309hlset({list}) Number set highlight group attributes
310hostname() String name of the machine Vim is running on
311iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Raelc8e158b2024-07-09 18:39:52 +0200312id({item}) String get address of item as a string
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000313indent({lnum}) Number indent of line {lnum}
314index({object}, {expr} [, {start} [, {ic}]])
315 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100316indexof({object}, {expr} [, {opts}]])
317 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000318input({prompt} [, {text} [, {completion}]])
319 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100320inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000321 String like input() but in a GUI dialog
322inputlist({textlist}) Number let the user pick from a choice list
323inputrestore() Number restore typeahead
324inputsave() Number save and clear typeahead
325inputsecret({prompt} [, {text}]) String like input() but hiding the text
326insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200327instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000328interrupt() none interrupt script execution
329invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100330isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000331isdirectory({directory}) Number |TRUE| if {directory} is a directory
332isinf({expr}) Number determine if {expr} is infinity value
333 (positive or negative)
334islocked({expr}) Number |TRUE| if {expr} is locked
335isnan({expr}) Number |TRUE| if {expr} is NaN
336items({dict}) List key-value pairs in {dict}
337job_getchannel({job}) Channel get the channel handle for {job}
338job_info([{job}]) Dict get information about {job}
339job_setoptions({job}, {options}) none set options for {job}
340job_start({command} [, {options}])
341 Job start a job
342job_status({job}) String get the status of {job}
343job_stop({job} [, {how}]) Number stop {job}
344join({list} [, {sep}]) String join {list} items into one String
345js_decode({string}) any decode JS style JSON
346js_encode({expr}) String encode JS style JSON
347json_decode({string}) any decode JSON
348json_encode({expr}) String encode JSON
349keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100350keytrans({string}) String translate internal keycodes to a form
351 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000352len({expr}) Number the length of {expr}
353libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
354libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
355line({expr} [, {winid}]) Number line nr of cursor, last line or mark
356line2byte({lnum}) Number byte count of line {lnum}
357lispindent({lnum}) Number Lisp indent for line {lnum}
358list2blob({list}) Blob turn {list} of numbers into a Blob
359list2str({list} [, {utf8}]) String turn {list} of numbers into a String
360listener_add({callback} [, {buf}])
361 Number add a callback to listen to changes
362listener_flush([{buf}]) none invoke listener callbacks
363listener_remove({id}) none remove a listener callback
364localtime() Number current time
365log({expr}) Float natural logarithm (base e) of {expr}
366log10({expr}) Float logarithm of Float {expr} to base 10
367luaeval({expr} [, {expr}]) any evaluate |Lua| expression
368map({expr1}, {expr2}) List/Dict/Blob/String
369 change each item in {expr1} to {expr2}
370maparg({name} [, {mode} [, {abbr} [, {dict}]]])
371 String or Dict
372 rhs of mapping {name} in mode {mode}
373mapcheck({name} [, {mode} [, {abbr}]])
374 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100375maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000376mapnew({expr1}, {expr2}) List/Dict/Blob/String
377 like |map()| but creates a new List or
378 Dictionary
379mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
380match({expr}, {pat} [, {start} [, {count}]])
381 Number position where {pat} matches in {expr}
382matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
383 Number highlight {pattern} with {group}
384matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
385 Number highlight positions with {group}
386matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100387matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
388 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000389matchdelete({id} [, {win}]) Number delete match identified by {id}
390matchend({expr}, {pat} [, {start} [, {count}]])
391 Number position where {pat} ends in {expr}
392matchfuzzy({list}, {str} [, {dict}])
393 List fuzzy match {str} in {list}
394matchfuzzypos({list}, {str} [, {dict}])
395 List fuzzy match {str} in {list}
396matchlist({expr}, {pat} [, {start} [, {count}]])
397 List match and submatches of {pat} in {expr}
398matchstr({expr}, {pat} [, {start} [, {count}]])
399 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100400matchstrlist({list}, {pat} [, {dict})
401 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000402matchstrpos({expr}, {pat} [, {start} [, {count}]])
403 List {count}'th match of {pat} in {expr}
404max({expr}) Number maximum value of items in {expr}
405menu_info({name} [, {mode}]) Dict get menu item information
406min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000407mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000408 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200409mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000410mzeval({expr}) any evaluate |MzScheme| expression
411nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
412nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
413or({expr}, {expr}) Number bitwise OR
414pathshorten({expr} [, {len}]) String shorten directory names in a path
415perleval({expr}) any evaluate |Perl| expression
416popup_atcursor({what}, {options}) Number create popup window near the cursor
417popup_beval({what}, {options}) Number create popup window for 'ballooneval'
418popup_clear() none close all popup windows
419popup_close({id} [, {result}]) none close popup window {id}
420popup_create({what}, {options}) Number create a popup window
421popup_dialog({what}, {options}) Number create a popup window used as a dialog
422popup_filter_menu({id}, {key}) Number filter for a menu popup window
423popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100424popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000425popup_findinfo() Number get window ID of info popup window
426popup_findpreview() Number get window ID of preview popup window
427popup_getoptions({id}) Dict get options of popup window {id}
428popup_getpos({id}) Dict get position of popup window {id}
429popup_hide({id}) none hide popup menu {id}
430popup_list() List get a list of window IDs of all popups
431popup_locate({row}, {col}) Number get window ID of popup at position
432popup_menu({what}, {options}) Number create a popup window used as a menu
433popup_move({id}, {options}) none set position of popup window {id}
434popup_notification({what}, {options})
435 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200436popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000437popup_setoptions({id}, {options})
438 none set options for popup window {id}
439popup_settext({id}, {text}) none set the text of popup window {id}
440popup_show({id}) none unhide popup window {id}
441pow({x}, {y}) Float {x} to the power of {y}
442prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
443printf({fmt}, {expr1}...) String format text
444prompt_getprompt({buf}) String get prompt text
445prompt_setcallback({buf}, {expr}) none set prompt callback function
446prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
447prompt_setprompt({buf}, {text}) none set prompt text
448prop_add({lnum}, {col}, {props}) none add one text property
449prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
450 none add multiple text properties
451prop_clear({lnum} [, {lnum-end} [, {props}]])
452 none remove all text properties
453prop_find({props} [, {direction}])
454 Dict search for a text property
455prop_list({lnum} [, {props}]) List text properties in {lnum}
456prop_remove({props} [, {lnum} [, {lnum-end}]])
457 Number remove a text property
458prop_type_add({name}, {props}) none define a new property type
459prop_type_change({name}, {props})
460 none change an existing property type
461prop_type_delete({name} [, {props}])
462 none delete a property type
463prop_type_get({name} [, {props}])
464 Dict get property type values
465prop_type_list([{props}]) List get list of property types
466pum_getpos() Dict position and size of pum if visible
467pumvisible() Number whether popup menu is visible
468py3eval({expr}) any evaluate |python3| expression
469pyeval({expr}) any evaluate |Python| expression
470pyxeval({expr}) any evaluate |python_x| expression
471rand([{expr}]) Number get pseudo-random number
472range({expr} [, {max} [, {stride}]])
473 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100474readblob({fname} [, {offset} [, {size}]])
475 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000476readdir({dir} [, {expr} [, {dict}]])
477 List file names in {dir} selected by {expr}
478readdirex({dir} [, {expr} [, {dict}]])
479 List file info in {dir} selected by {expr}
480readfile({fname} [, {type} [, {max}]])
481 List get list of lines from file {fname}
482reduce({object}, {func} [, {initial}])
483 any reduce {object} using {func}
484reg_executing() String get the executing register name
485reg_recording() String get the recording register name
486reltime([{start} [, {end}]]) List get time value
487reltimefloat({time}) Float turn the time value into a Float
488reltimestr({time}) String turn time value into a String
489remote_expr({server}, {string} [, {idvar} [, {timeout}]])
490 String send expression
491remote_foreground({server}) Number bring Vim server to the foreground
492remote_peek({serverid} [, {retvar}])
493 Number check for reply string
494remote_read({serverid} [, {timeout}])
495 String read reply string
496remote_send({server}, {string} [, {idvar}])
497 String send key sequence
498remote_startserver({name}) none become server {name}
499remove({list}, {idx} [, {end}]) any/List
500 remove items {idx}-{end} from {list}
501remove({blob}, {idx} [, {end}]) Number/Blob
502 remove bytes {idx}-{end} from {blob}
503remove({dict}, {key}) any remove entry {key} from {dict}
504rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100505repeat({expr}, {count}) List/Blob/String
506 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000507resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100508reverse({obj}) List/Blob/String
509 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000510round({expr}) Float round off {expr}
511rubyeval({expr}) any evaluate |Ruby| expression
512screenattr({row}, {col}) Number attribute at screen position
513screenchar({row}, {col}) Number character at screen position
514screenchars({row}, {col}) List List of characters at screen position
515screencol() Number current cursor column
516screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
517screenrow() Number current cursor row
518screenstring({row}, {col}) String characters at screen position
519search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
520 Number search for {pattern}
521searchcount([{options}]) Dict get or update search stats
522searchdecl({name} [, {global} [, {thisblock}]])
523 Number search for variable declaration
524searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
525 Number search for other end of start/end pair
526searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
527 List search for other end of start/end pair
528searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
529 List search for {pattern}
530server2client({clientid}, {string})
531 Number send reply string
532serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700533setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000534 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700535 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000536setbufvar({buf}, {varname}, {val})
537 none set {varname} in buffer {buf} to {val}
538setcellwidths({list}) none set character cell width overrides
539setcharpos({expr}, {list}) Number set the {expr} position to {list}
540setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100541setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000542setcmdpos({pos}) Number set cursor position in command-line
543setcursorcharpos({list}) Number move cursor to position in {list}
544setenv({name}, {val}) none set environment variable
545setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
546setline({lnum}, {line}) Number set line {lnum} to {line}
547setloclist({nr}, {list} [, {action}])
548 Number modify location list using {list}
549setloclist({nr}, {list}, {action}, {what})
550 Number modify specific location list props
551setmatches({list} [, {win}]) Number restore a list of matches
552setpos({expr}, {list}) Number set the {expr} position to {list}
553setqflist({list} [, {action}]) Number modify quickfix list using {list}
554setqflist({list}, {action}, {what})
555 Number modify specific quickfix list props
556setreg({n}, {v} [, {opt}]) Number set register to value and type
557settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
558settabwinvar({tabnr}, {winnr}, {varname}, {val})
559 none set {varname} in window {winnr} in tab
560 page {tabnr} to {val}
561settagstack({nr}, {dict} [, {action}])
562 Number modify tag stack using {dict}
563setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
564sha256({string}) String SHA256 checksum of {string}
565shellescape({string} [, {special}])
566 String escape {string} for use as shell
567 command argument
568shiftwidth([{col}]) Number effective value of 'shiftwidth'
569sign_define({name} [, {dict}]) Number define or update a sign
570sign_define({list}) List define or update a list of signs
571sign_getdefined([{name}]) List get a list of defined signs
572sign_getplaced([{buf} [, {dict}]])
573 List get a list of placed signs
574sign_jump({id}, {group}, {buf})
575 Number jump to a sign
576sign_place({id}, {group}, {name}, {buf} [, {dict}])
577 Number place a sign
578sign_placelist({list}) List place a list of signs
579sign_undefine([{name}]) Number undefine a sign
580sign_undefine({list}) List undefine a list of signs
581sign_unplace({group} [, {dict}])
582 Number unplace a sign
583sign_unplacelist({list}) List unplace a list of signs
584simplify({filename}) String simplify filename as much as possible
585sin({expr}) Float sine of {expr}
586sinh({expr}) Float hyperbolic sine of {expr}
587slice({expr}, {start} [, {end}]) String, List or Blob
588 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000589sort({list} [, {how} [, {dict}]])
590 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000591sound_clear() none stop playing all sounds
592sound_playevent({name} [, {callback}])
593 Number play an event sound
594sound_playfile({path} [, {callback}])
595 Number play sound file {path}
596sound_stop({id}) none stop playing sound {id}
597soundfold({word}) String sound-fold {word}
598spellbadword() String badly spelled word at cursor
599spellsuggest({word} [, {max} [, {capital}]])
600 List spelling suggestions
601split({expr} [, {pat} [, {keepempty}]])
602 List make |List| from {pat} separated {expr}
603sqrt({expr}) Float square root of {expr}
604srand([{expr}]) List get seed for |rand()|
605state([{what}]) String current state of Vim
606str2float({expr} [, {quoted}]) Float convert String to Float
607str2list({expr} [, {utf8}]) List convert each character of {expr} to
608 ASCII/UTF-8 value
609str2nr({expr} [, {base} [, {quoted}]])
610 Number convert String to Number
611strcharlen({expr}) Number character length of the String {expr}
612strcharpart({str}, {start} [, {len} [, {skipcc}]])
613 String {len} characters of {str} at
614 character {start}
615strchars({expr} [, {skipcc}]) Number character count of the String {expr}
616strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
617strftime({format} [, {time}]) String format time with a specified format
618strgetchar({str}, {index}) Number get char {index} from {str}
619stridx({haystack}, {needle} [, {start}])
620 Number index of {needle} in {haystack}
621string({expr}) String String representation of {expr} value
622strlen({expr}) Number length of the String {expr}
623strpart({str}, {start} [, {len} [, {chars}]])
624 String {len} bytes/chars of {str} at
625 byte {start}
626strptime({format}, {timestring})
627 Number Convert {timestring} to unix timestamp
628strridx({haystack}, {needle} [, {start}])
629 Number last index of {needle} in {haystack}
630strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100631strutf16len({string} [, {countcc}])
632 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000633strwidth({expr}) Number display cell length of the String {expr}
634submatch({nr} [, {list}]) String or List
635 specific match in ":s" or substitute()
636substitute({expr}, {pat}, {sub}, {flags})
637 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000638swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000639swapinfo({fname}) Dict information about swap file {fname}
640swapname({buf}) String swap file of buffer {buf}
641synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
642synIDattr({synID}, {what} [, {mode}])
643 String attribute {what} of syntax ID {synID}
644synIDtrans({synID}) Number translated syntax ID of {synID}
645synconcealed({lnum}, {col}) List info about concealing
646synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
647system({expr} [, {input}]) String output of shell command/filter {expr}
648systemlist({expr} [, {input}]) List output of shell command/filter {expr}
649tabpagebuflist([{arg}]) List list of buffer numbers in tab page
650tabpagenr([{arg}]) Number number of current or last tab page
651tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
652tagfiles() List tags files used
653taglist({expr} [, {filename}]) List list of tags matching {expr}
654tan({expr}) Float tangent of {expr}
655tanh({expr}) Float hyperbolic tangent of {expr}
656tempname() String name for a temporary file
657term_dumpdiff({filename}, {filename} [, {options}])
658 Number display difference between two dumps
659term_dumpload({filename} [, {options}])
660 Number displaying a screen dump
661term_dumpwrite({buf}, {filename} [, {options}])
662 none dump terminal window contents
663term_getaltscreen({buf}) Number get the alternate screen flag
664term_getansicolors({buf}) List get ANSI palette in GUI color mode
665term_getattr({attr}, {what}) Number get the value of attribute {what}
666term_getcursor({buf}) List get the cursor position of a terminal
667term_getjob({buf}) Job get the job associated with a terminal
668term_getline({buf}, {row}) String get a line of text from a terminal
669term_getscrolled({buf}) Number get the scroll count of a terminal
670term_getsize({buf}) List get the size of a terminal
671term_getstatus({buf}) String get the status of a terminal
672term_gettitle({buf}) String get the title of a terminal
673term_gettty({buf}, [{input}]) String get the tty name of a terminal
674term_list() List get the list of terminal buffers
675term_scrape({buf}, {row}) List get row of a terminal screen
676term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
677term_setansicolors({buf}, {colors})
678 none set ANSI palette in GUI color mode
679term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
680term_setkill({buf}, {how}) none set signal to stop job in terminal
681term_setrestore({buf}, {command}) none set command to restore terminal
682term_setsize({buf}, {rows}, {cols})
683 none set the size of a terminal
684term_start({cmd} [, {options}]) Number open a terminal window and run a job
685term_wait({buf} [, {time}]) Number wait for screen to be updated
686terminalprops() Dict properties of the terminal
687test_alloc_fail({id}, {countdown}, {repeat})
688 none make memory allocation fail
689test_autochdir() none enable 'autochdir' during startup
690test_feedinput({string}) none add key sequence to input buffer
691test_garbagecollect_now() none free memory right now for testing
692test_garbagecollect_soon() none free memory soon for testing
693test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000694test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000695test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000696test_mswin_event({event}, {args})
697 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000698test_null_blob() Blob null value for testing
699test_null_channel() Channel null value for testing
700test_null_dict() Dict null value for testing
701test_null_function() Funcref null value for testing
702test_null_job() Job null value for testing
703test_null_list() List null value for testing
704test_null_partial() Funcref null value for testing
705test_null_string() String null value for testing
706test_option_not_set({name}) none reset flag indicating option was set
707test_override({expr}, {val}) none test with Vim internal overrides
708test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000709test_setmouse({row}, {col}) none set the mouse position for testing
710test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200711test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000712test_unknown() any unknown value for testing
713test_void() any void value for testing
714timer_info([{id}]) List information about timers
715timer_pause({id}, {pause}) none pause or unpause a timer
716timer_start({time}, {callback} [, {options}])
717 Number create a timer
718timer_stop({timer}) none stop a timer
719timer_stopall() none stop all timers
720tolower({expr}) String the String {expr} switched to lowercase
721toupper({expr}) String the String {expr} switched to uppercase
722tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
723 to chars in {tostr}
724trim({text} [, {mask} [, {dir}]])
725 String trim characters in {mask} from {text}
726trunc({expr}) Float truncate Float {expr}
727type({expr}) Number type of value {expr}
728typename({expr}) String representation of the type of {expr}
729undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500730undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000731uniq({list} [, {func} [, {dict}]])
732 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100733utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
734 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000735values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200736virtcol({expr} [, {list} [, {winid}])
737 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100738 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100739virtcol2col({winid}, {lnum}, {col})
740 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200741visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000742wildmenumode() Number whether 'wildmenu' mode is active
743win_execute({id}, {command} [, {silent}])
744 String execute {command} in window {id}
745win_findbuf({bufnr}) List find windows containing {bufnr}
746win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
747win_gettype([{nr}]) String type of window {nr}
748win_gotoid({expr}) Number go to window with ID {expr}
749win_id2tabwin({expr}) List get tab and window nr from window ID
750win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000751win_move_separator({nr}) Number move window vertical separator
752win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000753win_screenpos({nr}) List get screen position of window {nr}
754win_splitmove({nr}, {target} [, {options}])
755 Number move window {nr} to split of {target}
756winbufnr({nr}) Number buffer number of window {nr}
757wincol() Number window column of the cursor
758windowsversion() String MS-Windows OS version
759winheight({nr}) Number height of window {nr}
760winlayout([{tabnr}]) List layout of windows in tab {tabnr}
761winline() Number window line of the cursor
762winnr([{expr}]) Number number of current window
763winrestcmd() String returns command to restore window sizes
764winrestview({dict}) none restore view of current window
765winsaveview() Dict save view of current window
766winwidth({nr}) Number width of window {nr}
767wordcount() Dict get byte/char/word statistics
768writefile({object}, {fname} [, {flags}])
769 Number write |Blob| or |List| of lines to file
770xor({expr}, {expr}) Number bitwise XOR
771
772==============================================================================
7732. Details *builtin-function-details*
774
775Not all functions are here, some have been moved to a help file covering the
776specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200777Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000778
779abs({expr}) *abs()*
780 Return the absolute value of {expr}. When {expr} evaluates to
781 a |Float| abs() returns a |Float|. When {expr} can be
782 converted to a |Number| abs() returns a |Number|. Otherwise
783 abs() gives an error message and returns -1.
784 Examples: >
785 echo abs(1.456)
786< 1.456 >
787 echo abs(-5.456)
788< 5.456 >
789 echo abs(-4)
790< 4
791
792 Can also be used as a |method|: >
793 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200794<
795 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000797
798acos({expr}) *acos()*
799 Return the arc cosine of {expr} measured in radians, as a
800 |Float| in the range of [0, pi].
801 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100802 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000803 Examples: >
804 :echo acos(0)
805< 1.570796 >
806 :echo acos(-0.5)
807< 2.094395
808
809 Can also be used as a |method|: >
810 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200811<
812 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000813
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000814
815add({object}, {expr}) *add()*
816 Append the item {expr} to |List| or |Blob| {object}. Returns
817 the resulting |List| or |Blob|. Examples: >
818 :let alist = add([1, 2, 3], item)
819 :call add(mylist, "woodstock")
820< Note that when {expr} is a |List| it is appended as a single
821 item. Use |extend()| to concatenate |Lists|.
822 When {object} is a |Blob| then {expr} must be a number.
823 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100824 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000825
826 Can also be used as a |method|: >
827 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200828<
829 Return type: list<{type}> (depending on the given |List|) or
830 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000831
832
833and({expr}, {expr}) *and()*
834 Bitwise AND on the two arguments. The arguments are converted
835 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100836 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000837 Example: >
838 :let flag = and(bits, 0x80)
839< Can also be used as a |method|: >
840 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200841<
842 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000843
844
845append({lnum}, {text}) *append()*
846 When {text} is a |List|: Append each item of the |List| as a
847 text line below line {lnum} in the current buffer.
848 Otherwise append {text} as one text line below line {lnum} in
849 the current buffer.
850 Any type of item is accepted and converted to a String.
851 {lnum} can be zero to insert a line before the first one.
852 {lnum} is used like with |getline()|.
853 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000854 0 for success. When {text} is an empty list zero is returned,
855 no matter the value of {lnum}.
856 In |Vim9| script an invalid argument or negative number
857 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000858 :let failed = append(line('$'), "# THE END")
859 :let failed = append(0, ["Chapter 1", "the beginning"])
860
861< Can also be used as a |method| after a List, the base is
862 passed as the second argument: >
863 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200864<
865 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000866
867
868appendbufline({buf}, {lnum}, {text}) *appendbufline()*
869 Like |append()| but append the text in buffer {buf}.
870
871 This function works only for loaded buffers. First call
872 |bufload()| if needed.
873
874 For the use of {buf}, see |bufname()|.
875
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000876 {lnum} is the line number to append below. Note that using
877 |line()| would use the current buffer, not the one appending
878 to. Use "$" to append at the end of the buffer. Other string
879 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000880
881 On success 0 is returned, on failure 1 is returned.
882 In |Vim9| script an error is given for an invalid {lnum}.
883
884 If {buf} is not a valid buffer or {lnum} is not valid, an
885 error message is given. Example: >
886 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000887< However, when {text} is an empty list then no error is given
888 for an invalid {lnum}, since {lnum} isn't actually used.
889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000890 Can also be used as a |method| after a List, the base is
891 passed as the second argument: >
892 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200893<
894 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895
896
897argc([{winid}]) *argc()*
898 The result is the number of files in the argument list. See
899 |arglist|.
900 If {winid} is not supplied, the argument list of the current
901 window is used.
902 If {winid} is -1, the global argument list is used.
903 Otherwise {winid} specifies the window of which the argument
904 list is used: either the window number or the window ID.
905 Returns -1 if the {winid} argument is invalid.
906
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200907 Return type: |Number|
908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000909 *argidx()*
910argidx() The result is the current index in the argument list. 0 is
911 the first file. argc() - 1 is the last one. See |arglist|.
912
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200913 Return type: |Number|
914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000915 *arglistid()*
916arglistid([{winnr} [, {tabnr}]])
917 Return the argument list ID. This is a number which
918 identifies the argument list being used. Zero is used for the
919 global argument list. See |arglist|.
920 Returns -1 if the arguments are invalid.
921
922 Without arguments use the current window.
923 With {winnr} only use this window in the current tab page.
924 With {winnr} and {tabnr} use the window in the specified tab
925 page.
926 {winnr} can be the window number or the |window-ID|.
927
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200928 Return type: |Number|
929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000930 *argv()*
931argv([{nr} [, {winid}]])
932 The result is the {nr}th file in the argument list. See
933 |arglist|. "argv(0)" is the first one. Example: >
934 :let i = 0
935 :while i < argc()
936 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000937 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000938 : let i = i + 1
939 :endwhile
940< Without the {nr} argument, or when {nr} is -1, a |List| with
941 the whole |arglist| is returned.
942
943 The {winid} argument specifies the window ID, see |argc()|.
944 For the Vim command line arguments see |v:argv|.
945
Bram Moolenaar016188f2022-06-06 20:52:59 +0100946 Returns an empty string if {nr}th argument is not present in
947 the argument list. Returns an empty List if the {winid}
948 argument is invalid.
949
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200950 Return type: |String|
951
952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000953asin({expr}) *asin()*
954 Return the arc sine of {expr} measured in radians, as a |Float|
955 in the range of [-pi/2, pi/2].
956 {expr} must evaluate to a |Float| or a |Number| in the range
957 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100958 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
959 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000960 Examples: >
961 :echo asin(0.8)
962< 0.927295 >
963 :echo asin(-0.5)
964< -0.523599
965
966 Can also be used as a |method|: >
967 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200968<
969 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000970
971assert_ functions are documented here: |assert-functions-details|
972
973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000974atan({expr}) *atan()*
975 Return the principal value of the arc tangent of {expr}, in
976 the range [-pi/2, +pi/2] radians, as a |Float|.
977 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100978 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000979 Examples: >
980 :echo atan(100)
981< 1.560797 >
982 :echo atan(-4.01)
983< -1.326405
984
985 Can also be used as a |method|: >
986 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200987<
988 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000989
990
991atan2({expr1}, {expr2}) *atan2()*
992 Return the arc tangent of {expr1} / {expr2}, measured in
993 radians, as a |Float| in the range [-pi, pi].
994 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100995 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
996 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000997 Examples: >
998 :echo atan2(-1, 1)
999< -0.785398 >
1000 :echo atan2(1, -1)
1001< 2.356194
1002
1003 Can also be used as a |method|: >
1004 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001005<
1006 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001007
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001008
1009autocmd_add({acmds}) *autocmd_add()*
1010 Adds a List of autocmds and autocmd groups.
1011
1012 The {acmds} argument is a List where each item is a Dict with
1013 the following optional items:
1014 bufnr buffer number to add a buffer-local autocmd.
1015 If this item is specified, then the "pattern"
1016 item is ignored.
1017 cmd Ex command to execute for this autocmd event
1018 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001019 This can be either a String with a single
1020 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001021 group autocmd group name. Refer to |autocmd-groups|.
1022 If this group doesn't exist then it is
1023 created. If not specified or empty, then the
1024 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001025 nested boolean flag, set to v:true to add a nested
1026 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001027 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001028 which executes only once. Refer to
1029 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001030 pattern autocmd pattern string. Refer to
1031 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001032 present, then this item is ignored. This can
1033 be a String with a single pattern or a List of
1034 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001035 replace boolean flag, set to v:true to remove all the
1036 commands associated with the specified autocmd
1037 event and group and add the {cmd}. This is
1038 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001039 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001040
1041 Returns v:true on success and v:false on failure.
1042 Examples: >
1043 " Create a buffer-local autocmd for buffer 5
1044 let acmd = {}
1045 let acmd.group = 'MyGroup'
1046 let acmd.event = 'BufEnter'
1047 let acmd.bufnr = 5
1048 let acmd.cmd = 'call BufEnterFunc()'
1049 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001050<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001051 Can also be used as a |method|: >
1052 GetAutocmdList()->autocmd_add()
1053<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001054 Return type: |vim9-boolean|
1055
1056
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001057autocmd_delete({acmds}) *autocmd_delete()*
1058 Deletes a List of autocmds and autocmd groups.
1059
1060 The {acmds} argument is a List where each item is a Dict with
1061 the following optional items:
1062 bufnr buffer number to delete a buffer-local autocmd.
1063 If this item is specified, then the "pattern"
1064 item is ignored.
1065 cmd Ex command for this autocmd event
1066 event autocmd event name. Refer to |autocmd-events|.
1067 If '*' then all the autocmd events in this
1068 group are deleted.
1069 group autocmd group name. Refer to |autocmd-groups|.
1070 If not specified or empty, then the default
1071 group is used.
1072 nested set to v:true for a nested autocmd.
1073 Refer to |autocmd-nested|.
1074 once set to v:true for an autocmd which executes
1075 only once. Refer to |autocmd-once|.
1076 pattern autocmd pattern string. Refer to
1077 |autocmd-patterns|. If "bufnr" item is
1078 present, then this item is ignored.
1079
1080 If only {group} is specified in a {acmds} entry and {event},
1081 {pattern} and {cmd} are not specified, then that autocmd group
1082 is deleted.
1083
Bram Moolenaar016188f2022-06-06 20:52:59 +01001084 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001085 Examples: >
1086 " :autocmd! BufLeave *.vim
1087 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1088 call autocmd_delete([acmd]})
1089 " :autocmd! MyGroup1 BufLeave
1090 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1091 call autocmd_delete([acmd])
1092 " :autocmd! MyGroup2 BufEnter *.c
1093 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1094 \ pattern: '*.c'}
1095 " :autocmd! MyGroup2 * *.c
1096 let acmd = #{group: 'MyGroup2', event: '*',
1097 \ pattern: '*.c'}
1098 call autocmd_delete([acmd])
1099 " :autocmd! MyGroup3
1100 let acmd = #{group: 'MyGroup3'}
1101 call autocmd_delete([acmd])
1102<
1103 Can also be used as a |method|: >
1104 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001105<
1106 Return type: |vim9-boolean|
1107
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001108
1109autocmd_get([{opts}]) *autocmd_get()*
1110 Returns a |List| of autocmds. If {opts} is not supplied, then
1111 returns the autocmds for all the events in all the groups.
1112
1113 The optional {opts} Dict argument supports the following
1114 items:
1115 group Autocmd group name. If specified, returns only
1116 the autocmds defined in this group. If the
1117 specified group doesn't exist, results in an
1118 error message. If set to an empty string,
1119 then the default autocmd group is used.
1120 event Autocmd event name. If specified, returns only
1121 the autocmds defined for this event. If set
1122 to "*", then returns autocmds for all the
1123 events. If the specified event doesn't exist,
1124 results in an error message.
1125 pattern Autocmd pattern. If specified, returns only
1126 the autocmds defined for this pattern.
1127 A combination of the above three times can be supplied in
1128 {opts}.
1129
1130 Each Dict in the returned List contains the following items:
1131 bufnr For buffer-local autocmds, buffer number where
1132 the autocmd is defined.
1133 cmd Command executed for this autocmd.
1134 event Autocmd event name.
1135 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001136 nested Boolean flag, set to v:true for a nested
1137 autocmd. See |autocmd-nested|.
1138 once Boolean flag, set to v:true, if the autocmd
1139 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001140 pattern Autocmd pattern. For a buffer-local
1141 autocmd, this will be of the form "<buffer=n>".
1142 If there are multiple commands for an autocmd event in a
1143 group, then separate items are returned for each command.
1144
Bram Moolenaar016188f2022-06-06 20:52:59 +01001145 Returns an empty List if an autocmd with the specified group
1146 or event or pattern is not found.
1147
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001148 Examples: >
1149 " :autocmd MyGroup
1150 echo autocmd_get(#{group: 'Mygroup'})
1151 " :autocmd G BufUnload
1152 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1153 " :autocmd G * *.ts
1154 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1155 echo autocmd_get(acmd)
1156 " :autocmd Syntax
1157 echo autocmd_get(#{event: 'Syntax'})
1158 " :autocmd G BufEnter *.ts
1159 let acmd = #{group: 'G', event: 'BufEnter',
1160 \ pattern: '*.ts'}
1161 echo autocmd_get(acmd)
1162<
1163 Can also be used as a |method|: >
1164 Getopts()->autocmd_get()
1165<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001166 Return type: list<dict<any>>
1167
1168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001169balloon_gettext() *balloon_gettext()*
1170 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001171 not used for the List. Returns an empty string if balloon
1172 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001173
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001174 Return type: |String|
1175
1176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001177balloon_show({expr}) *balloon_show()*
1178 Show {expr} inside the balloon. For the GUI {expr} is used as
1179 a string. For a terminal {expr} can be a list, which contains
1180 the lines of the balloon. If {expr} is not a list it will be
1181 split with |balloon_split()|.
1182 If {expr} is an empty string any existing balloon is removed.
1183
1184 Example: >
1185 func GetBalloonContent()
1186 " ... initiate getting the content
1187 return ''
1188 endfunc
1189 set balloonexpr=GetBalloonContent()
1190
1191 func BalloonCallback(result)
1192 call balloon_show(a:result)
1193 endfunc
1194< Can also be used as a |method|: >
1195 GetText()->balloon_show()
1196<
1197 The intended use is that fetching the content of the balloon
1198 is initiated from 'balloonexpr'. It will invoke an
1199 asynchronous method, in which a callback invokes
1200 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001201 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001202
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001203 When showing a balloon is not possible then nothing happens,
1204 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001205 {only available when compiled with the |+balloon_eval| or
1206 |+balloon_eval_term| feature}
1207
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001208 Return type: |Number|
1209
1210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001211balloon_split({msg}) *balloon_split()*
1212 Split String {msg} into lines to be displayed in a balloon.
1213 The splits are made for the current window size and optimize
1214 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001215 Returns a |List| with the split lines. Returns an empty List
1216 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001217 Can also be used as a |method|: >
1218 GetText()->balloon_split()->balloon_show()
1219
1220< {only available when compiled with the |+balloon_eval_term|
1221 feature}
1222
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001223 Return type: list<any> or list<string>
1224
Christ van Willegence0ef912024-06-20 23:41:59 +02001225bindtextdomain({package}, {path}) *bindtextdomain()*
1226 Bind a specific {package} to a {path} so that the
1227 |gettext()| function can be used to get language-specific
1228 translations for a package. {path} is the directory name
RestorerZ96509102024-07-11 21:14:15 +02001229 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001230
1231 Return type: none
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001233blob2list({blob}) *blob2list()*
1234 Return a List containing the number value of each byte in Blob
1235 {blob}. Examples: >
1236 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1237 blob2list(0z) returns []
1238< Returns an empty List on error. |list2blob()| does the
1239 opposite.
1240
1241 Can also be used as a |method|: >
1242 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001243<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001244 Return type: list<any> or list<number>
1245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001246 *browse()*
1247browse({save}, {title}, {initdir}, {default})
1248 Put up a file requester. This only works when "has("browse")"
1249 returns |TRUE| (only in some GUI versions).
1250 The input fields are:
1251 {save} when |TRUE|, select file to write
1252 {title} title for the requester
1253 {initdir} directory to start browsing in
1254 {default} default file name
1255 An empty string is returned when the "Cancel" button is hit,
1256 something went wrong, or browsing is not possible.
1257
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001258 Return type: |String|
1259
1260
1261browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001262 Put up a directory requester. This only works when
1263 "has("browse")" returns |TRUE| (only in some GUI versions).
1264 On systems where a directory browser is not supported a file
1265 browser is used. In that case: select a file in the directory
1266 to be used.
1267 The input fields are:
1268 {title} title for the requester
1269 {initdir} directory to start browsing in
1270 When the "Cancel" button is hit, something went wrong, or
1271 browsing is not possible, an empty string is returned.
1272
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001273 Return type: |String|
1274
1275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001276bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001277 Add a buffer to the buffer list with name {name} (must be a
1278 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001279 If a buffer for file {name} already exists, return that buffer
1280 number. Otherwise return the buffer number of the newly
1281 created buffer. When {name} is an empty string then a new
1282 buffer is always created.
1283 The buffer will not have 'buflisted' set and not be loaded
1284 yet. To add some text to the buffer use this: >
1285 let bufnr = bufadd('someName')
1286 call bufload(bufnr)
1287 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001288< Returns 0 on error.
1289 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001290 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001291<
1292 Return type: |Number|
1293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001294
1295bufexists({buf}) *bufexists()*
1296 The result is a Number, which is |TRUE| if a buffer called
1297 {buf} exists.
1298 If the {buf} argument is a number, buffer numbers are used.
1299 Number zero is the alternate buffer for the current window.
1300
1301 If the {buf} argument is a string it must match a buffer name
1302 exactly. The name can be:
1303 - Relative to the current directory.
1304 - A full path.
1305 - The name of a buffer with 'buftype' set to "nofile".
1306 - A URL name.
1307 Unlisted buffers will be found.
1308 Note that help files are listed by their short name in the
1309 output of |:buffers|, but bufexists() requires using their
1310 long name to be able to find them.
1311 bufexists() may report a buffer exists, but to use the name
1312 with a |:buffer| command you may need to use |expand()|. Esp
1313 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1314 Use "bufexists(0)" to test for the existence of an alternate
1315 file name.
1316
1317 Can also be used as a |method|: >
1318 let exists = 'somename'->bufexists()
1319<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001320 Return type: |Number|
1321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001322 Obsolete name: buffer_exists(). *buffer_exists()*
1323
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001325buflisted({buf}) *buflisted()*
1326 The result is a Number, which is |TRUE| if a buffer called
1327 {buf} exists and is listed (has the 'buflisted' option set).
1328 The {buf} argument is used like with |bufexists()|.
1329
1330 Can also be used as a |method|: >
1331 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001332<
1333 Return type: |Number|
1334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001335
1336bufload({buf}) *bufload()*
1337 Ensure the buffer {buf} is loaded. When the buffer name
1338 refers to an existing file then the file is read. Otherwise
1339 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001340 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001341 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001342 If there is an existing swap file for the file of the buffer,
1343 there will be no dialog, the buffer will be loaded anyway.
1344 The {buf} argument is used like with |bufexists()|.
1345
1346 Can also be used as a |method|: >
1347 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001348<
1349 Return type: |Number|
1350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001351
1352bufloaded({buf}) *bufloaded()*
1353 The result is a Number, which is |TRUE| if a buffer called
1354 {buf} exists and is loaded (shown in a window or hidden).
1355 The {buf} argument is used like with |bufexists()|.
1356
1357 Can also be used as a |method|: >
1358 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001359<
1360 Return type: |Number|
1361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001362
1363bufname([{buf}]) *bufname()*
1364 The result is the name of a buffer. Mostly as it is displayed
1365 by the `:ls` command, but not using special names such as
1366 "[No Name]".
1367 If {buf} is omitted the current buffer is used.
1368 If {buf} is a Number, that buffer number's name is given.
1369 Number zero is the alternate buffer for the current window.
1370 If {buf} is a String, it is used as a |file-pattern| to match
1371 with the buffer names. This is always done like 'magic' is
1372 set and 'cpoptions' is empty. When there is more than one
1373 match an empty string is returned.
1374 "" or "%" can be used for the current buffer, "#" for the
1375 alternate buffer.
1376 A full match is preferred, otherwise a match at the start, end
1377 or middle of the buffer name is accepted. If you only want a
1378 full match then put "^" at the start and "$" at the end of the
1379 pattern.
1380 Listed buffers are found first. If there is a single match
1381 with a listed buffer, that one is returned. Next unlisted
1382 buffers are searched for.
1383 If the {buf} is a String, but you want to use it as a buffer
1384 number, force it to be a Number by adding zero to it: >
1385 :echo bufname("3" + 0)
1386< Can also be used as a |method|: >
1387 echo bufnr->bufname()
1388
1389< If the buffer doesn't exist, or doesn't have a name, an empty
1390 string is returned. >
1391 bufname("#") alternate buffer name
1392 bufname(3) name of buffer 3
1393 bufname("%") name of current buffer
1394 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001395<
1396 Return type: |String|
1397 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001398 Obsolete name: buffer_name().
1399
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001400
1401bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001402 The result is the number of a buffer, as it is displayed by
1403 the `:ls` command. For the use of {buf}, see |bufname()|
1404 above.
1405
1406 If the buffer doesn't exist, -1 is returned. Or, if the
1407 {create} argument is present and TRUE, a new, unlisted,
1408 buffer is created and its number is returned. Example: >
1409 let newbuf = bufnr('Scratch001', 1)
1410< Using an empty name uses the current buffer. To create a new
1411 buffer with an empty name use |bufadd()|.
1412
1413 bufnr("$") is the last buffer: >
1414 :let last_buffer = bufnr("$")
1415< The result is a Number, which is the highest buffer number
1416 of existing buffers. Note that not all buffers with a smaller
1417 number necessarily exist, because ":bwipeout" may have removed
1418 them. Use bufexists() to test for the existence of a buffer.
1419
1420 Can also be used as a |method|: >
1421 echo bufref->bufnr()
1422<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001423 Return type: |Number|
1424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001425 Obsolete name: buffer_number(). *buffer_number()*
1426 *last_buffer_nr()*
1427 Obsolete name for bufnr("$"): last_buffer_nr().
1428
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001430bufwinid({buf}) *bufwinid()*
1431 The result is a Number, which is the |window-ID| of the first
1432 window associated with buffer {buf}. For the use of {buf},
1433 see |bufname()| above. If buffer {buf} doesn't exist or
1434 there is no such window, -1 is returned. Example: >
1435
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001436 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001437<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001438 Only deals with the current tab page. See |win_findbuf()| for
1439 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001440
1441 Can also be used as a |method|: >
1442 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001443<
1444 Return type: |Number|
1445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001446
1447bufwinnr({buf}) *bufwinnr()*
1448 Like |bufwinid()| but return the window number instead of the
1449 |window-ID|.
1450 If buffer {buf} doesn't exist or there is no such window, -1
1451 is returned. Example: >
1452
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001453 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001454
1455< The number can be used with |CTRL-W_w| and ":wincmd w"
1456 |:wincmd|.
1457
1458 Can also be used as a |method|: >
1459 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001460<
1461 Return type: |Number|
1462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001463
1464byte2line({byte}) *byte2line()*
1465 Return the line number that contains the character at byte
1466 count {byte} in the current buffer. This includes the
1467 end-of-line character, depending on the 'fileformat' option
1468 for the current buffer. The first character has byte count
1469 one.
1470 Also see |line2byte()|, |go| and |:goto|.
1471
Bram Moolenaar016188f2022-06-06 20:52:59 +01001472 Returns -1 if the {byte} value is invalid.
1473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001474 Can also be used as a |method|: >
1475 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001476<
1477 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001478
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001479 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001480 feature}
1481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001482
Christian Brabandt67672ef2023-04-24 21:09:54 +01001483byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001484 Return byte index of the {nr}'th character in the String
1485 {expr}. Use zero for the first character, it then returns
1486 zero.
1487 If there are no multibyte characters the returned value is
1488 equal to {nr}.
1489 Composing characters are not counted separately, their byte
1490 length is added to the preceding base character. See
1491 |byteidxcomp()| below for counting composing characters
1492 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001493 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1494 index in the String {expr} instead of as the character index.
1495 The UTF-16 index is the index in the string when it is encoded
1496 with 16-bit words. If the specified UTF-16 index is in the
1497 middle of a character (e.g. in a 4-byte character), then the
1498 byte index of the first byte in the character is returned.
1499 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001500 Example : >
1501 echo matchstr(str, ".", byteidx(str, 3))
1502< will display the fourth character. Another way to do the
1503 same: >
1504 let s = strpart(str, byteidx(str, 3))
1505 echo strpart(s, 0, byteidx(s, 1))
1506< Also see |strgetchar()| and |strcharpart()|.
1507
1508 If there are less than {nr} characters -1 is returned.
1509 If there are exactly {nr} characters the length of the string
1510 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001511 See |charidx()| and |utf16idx()| for getting the character and
1512 UTF-16 index respectively from the byte index.
1513 Examples: >
1514 echo byteidx('a😊😊', 2) returns 5
1515 echo byteidx('a😊😊', 2, 1) returns 1
1516 echo byteidx('a😊😊', 3, 1) returns 5
1517<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001518 Can also be used as a |method|: >
1519 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001520<
1521 Return type: |Number|
1522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523
Christian Brabandt67672ef2023-04-24 21:09:54 +01001524byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525 Like byteidx(), except that a composing character is counted
1526 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001527 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001528 echo byteidx(s, 1)
1529 echo byteidxcomp(s, 1)
1530 echo byteidxcomp(s, 2)
1531< The first and third echo result in 3 ('e' plus composing
1532 character is 3 bytes), the second echo results in 1 ('e' is
1533 one byte).
1534 Only works differently from byteidx() when 'encoding' is set
1535 to a Unicode encoding.
1536
1537 Can also be used as a |method|: >
1538 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001539<
1540 Return type: |Number|
1541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001542
1543call({func}, {arglist} [, {dict}]) *call()* *E699*
1544 Call function {func} with the items in |List| {arglist} as
1545 arguments.
1546 {func} can either be a |Funcref| or the name of a function.
1547 a:firstline and a:lastline are set to the cursor line.
1548 Returns the return value of the called function.
1549 {dict} is for functions with the "dict" attribute. It will be
1550 used to set the local variable "self". |Dictionary-function|
1551
1552 Can also be used as a |method|: >
1553 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001554<
1555 Return type: any, depending on {func}
1556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001557
1558ceil({expr}) *ceil()*
1559 Return the smallest integral value greater than or equal to
1560 {expr} as a |Float| (round up).
1561 {expr} must evaluate to a |Float| or a |Number|.
1562 Examples: >
1563 echo ceil(1.456)
1564< 2.0 >
1565 echo ceil(-5.456)
1566< -5.0 >
1567 echo ceil(4.0)
1568< 4.0
1569
Bram Moolenaar016188f2022-06-06 20:52:59 +01001570 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001572 Can also be used as a |method|: >
1573 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001574<
1575 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001576
1577
1578ch_ functions are documented here: |channel-functions-details|
1579
1580
1581changenr() *changenr()*
1582 Return the number of the most recent change. This is the same
1583 number as what is displayed with |:undolist| and can be used
1584 with the |:undo| command.
1585 When a change was made it is the number of that change. After
1586 redo it is the number of the redone change. After undo it is
1587 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001588 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001589
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001590 Return type: |Number|
1591
1592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001593char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001594 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001595 Examples: >
1596 char2nr(" ") returns 32
1597 char2nr("ABC") returns 65
1598< When {utf8} is omitted or zero, the current 'encoding' is used.
1599 Example for "utf-8": >
1600 char2nr("á") returns 225
1601 char2nr("á"[0]) returns 195
1602< When {utf8} is TRUE, always treat as UTF-8 characters.
1603 A combining character is a separate character.
1604 |nr2char()| does the opposite.
1605 To turn a string into a list of character numbers: >
1606 let str = "ABC"
1607 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1608< Result: [65, 66, 67]
1609
Bram Moolenaar016188f2022-06-06 20:52:59 +01001610 Returns 0 if {string} is not a |String|.
1611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001612 Can also be used as a |method|: >
1613 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001614<
1615 Return type: |Number|
1616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001618charclass({string}) *charclass()*
1619 Return the character class of the first character in {string}.
1620 The character class is one of:
1621 0 blank
1622 1 punctuation
1623 2 word character
1624 3 emoji
1625 other specific Unicode class
1626 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001627 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001629 Return type: |Number|
1630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001631
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001632charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001633 Same as |col()| but returns the character index of the column
1634 position given with {expr} instead of the byte position.
1635
1636 Example:
1637 With the cursor on '세' in line 5 with text "여보세요": >
1638 charcol('.') returns 3
1639 col('.') returns 7
1640
1641< Can also be used as a |method|: >
1642 GetPos()->col()
1643<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001644 Return type: |Number|
1645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001646 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001647charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001648 Return the character index of the byte at {idx} in {string}.
1649 The index of the first character is zero.
1650 If there are no multibyte characters the returned value is
1651 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001653 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001654 are not counted separately, their byte length is added to the
1655 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001656 When {countcc} is |TRUE|, then composing characters are
1657 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001658
1659 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1660 index in the String {expr} instead of as the byte index.
1661
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001662 Returns -1 if the arguments are invalid or if there are less
1663 than {idx} bytes. If there are exactly {idx} bytes the length
1664 of the string in characters is returned.
1665
1666 An error is given and -1 is returned if the first argument is
1667 not a string, the second argument is not a number or when the
1668 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001670 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001671 from the character index and |utf16idx()| for getting the
1672 UTF-16 index from the character index.
1673 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001674 Examples: >
1675 echo charidx('áb́ć', 3) returns 1
1676 echo charidx('áb́ć', 6, 1) returns 4
1677 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001678 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679<
1680 Can also be used as a |method|: >
1681 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001682<
1683 Return type: |Number|
1684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001685
1686chdir({dir}) *chdir()*
1687 Change the current working directory to {dir}. The scope of
1688 the directory change depends on the directory of the current
1689 window:
1690 - If the current window has a window-local directory
1691 (|:lcd|), then changes the window local directory.
1692 - Otherwise, if the current tabpage has a local
1693 directory (|:tcd|) then changes the tabpage local
1694 directory.
1695 - Otherwise, changes the global directory.
1696 {dir} must be a String.
1697 If successful, returns the previous working directory. Pass
1698 this to another chdir() to restore the directory.
1699 On failure, returns an empty string.
1700
1701 Example: >
1702 let save_dir = chdir(newdir)
1703 if save_dir != ""
1704 " ... do some work
1705 call chdir(save_dir)
1706 endif
1707
1708< Can also be used as a |method|: >
1709 GetDir()->chdir()
1710<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001711 Return type: |String|
1712
1713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001714cindent({lnum}) *cindent()*
1715 Get the amount of indent for line {lnum} according the C
1716 indenting rules, as with 'cindent'.
1717 The indent is counted in spaces, the value of 'tabstop' is
1718 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001719 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001720 See |C-indenting|.
1721
1722 Can also be used as a |method|: >
1723 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001724<
1725 Return type: |Number|
1726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001727
1728clearmatches([{win}]) *clearmatches()*
1729 Clears all matches previously defined for the current window
1730 by |matchadd()| and the |:match| commands.
1731 If {win} is specified, use the window with this number or
1732 window ID instead of the current window.
1733
1734 Can also be used as a |method|: >
1735 GetWin()->clearmatches()
1736<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001737 Return type: |Number|
1738
1739
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001740col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001741 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001742 position given with {expr}.
1743 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001744 When {expr} is "$", it means the end of the cursor line, so
1745 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001746 Additionally {expr} can be [lnum, col]: a |List| with the line
1747 and column number. Most useful when the column is "$", to get
1748 the last column of a specific line. When "lnum" or "col" is
1749 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001750
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001751 With the optional {winid} argument the values are obtained for
1752 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001754 To get the line number use |line()|. To get both use
1755 |getpos()|.
1756 For the screen column position use |virtcol()|. For the
1757 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001761 Examples: >
1762 col(".") column of cursor
1763 col("$") length of cursor line plus one
1764 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001765 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001766<
1767 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001768 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001769 For an uppercase mark the column may actually be in another
1770 buffer.
1771 For the cursor position, when 'virtualedit' is active, the
1772 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001773 line. Also, when using a <Cmd> mapping the cursor isn't
1774 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001775 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001776
1777< Can also be used as a |method|: >
1778 GetPos()->col()
1779<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001780 Return type: |Number|
1781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001782
1783complete({startcol}, {matches}) *complete()* *E785*
1784 Set the matches for Insert mode completion.
1785 Can only be used in Insert mode. You need to use a mapping
1786 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1787 or with an expression mapping.
1788 {startcol} is the byte offset in the line where the completed
1789 text start. The text up to the cursor is the original text
1790 that will be replaced by the matches. Use col('.') for an
1791 empty string. "col('.') - 1" will replace one character by a
1792 match.
1793 {matches} must be a |List|. Each |List| item is one match.
1794 See |complete-items| for the kind of items that are possible.
1795 "longest" in 'completeopt' is ignored.
1796 Note that the after calling this function you need to avoid
1797 inserting anything that would cause completion to stop.
1798 The match can be selected with CTRL-N and CTRL-P as usual with
1799 Insert mode completion. The popup menu will appear if
1800 specified, see |ins-completion-menu|.
1801 Example: >
1802 inoremap <F5> <C-R>=ListMonths()<CR>
1803
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001804 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001805 call complete(col('.'), ['January', 'February', 'March',
1806 \ 'April', 'May', 'June', 'July', 'August', 'September',
1807 \ 'October', 'November', 'December'])
1808 return ''
1809 endfunc
1810< This isn't very useful, but it shows how it works. Note that
1811 an empty string is returned to avoid a zero being inserted.
1812
1813 Can also be used as a |method|, the base is passed as the
1814 second argument: >
1815 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001816<
1817 Return type: |Number|
1818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001819
1820complete_add({expr}) *complete_add()*
1821 Add {expr} to the list of matches. Only to be used by the
1822 function specified with the 'completefunc' option.
1823 Returns 0 for failure (empty string or out of memory),
1824 1 when the match was added, 2 when the match was already in
1825 the list.
1826 See |complete-functions| for an explanation of {expr}. It is
1827 the same as one item in the list that 'omnifunc' would return.
1828
1829 Can also be used as a |method|: >
1830 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001831<
1832 Return type: |Number|
1833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001834
1835complete_check() *complete_check()*
1836 Check for a key typed while looking for completion matches.
1837 This is to be used when looking for matches takes some time.
1838 Returns |TRUE| when searching for matches is to be aborted,
1839 zero otherwise.
1840 Only to be used by the function specified with the
1841 'completefunc' option.
1842
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001843 Return type: |Number|
1844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001845
1846complete_info([{what}]) *complete_info()*
1847 Returns a |Dictionary| with information about Insert mode
1848 completion. See |ins-completion|.
1849 The items are:
1850 mode Current completion mode name string.
1851 See |complete_info_mode| for the values.
1852 pum_visible |TRUE| if popup menu is visible.
1853 See |pumvisible()|.
1854 items List of completion matches. Each item is a
1855 dictionary containing the entries "word",
1856 "abbr", "menu", "kind", "info" and "user_data".
1857 See |complete-items|.
1858 selected Selected item index. First index is zero.
1859 Index is -1 if no item is selected (showing
1860 typed text only, or the last completion after
1861 no item is selected when using the <Up> or
1862 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001863 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001864
1865 *complete_info_mode*
1866 mode values are:
1867 "" Not in completion mode
1868 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1869 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1870 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1871 |i_CTRL-X_CTRL-Y|
1872 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1873 "files" File names |i_CTRL-X_CTRL-F|
1874 "tags" Tags |i_CTRL-X_CTRL-]|
1875 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1876 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1877 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1878 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1879 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1880 "function" User defined completion |i_CTRL-X_CTRL-U|
1881 "omni" Omni completion |i_CTRL-X_CTRL-O|
1882 "spell" Spelling suggestions |i_CTRL-X_s|
1883 "eval" |complete()| completion
1884 "unknown" Other internal modes
1885
1886 If the optional {what} list argument is supplied, then only
1887 the items listed in {what} are returned. Unsupported items in
1888 {what} are silently ignored.
1889
1890 To get the position and size of the popup menu, see
1891 |pum_getpos()|. It's also available in |v:event| during the
1892 |CompleteChanged| event.
1893
Bram Moolenaar016188f2022-06-06 20:52:59 +01001894 Returns an empty |Dictionary| on error.
1895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001896 Examples: >
1897 " Get all items
1898 call complete_info()
1899 " Get only 'mode'
1900 call complete_info(['mode'])
1901 " Get only 'mode' and 'pum_visible'
1902 call complete_info(['mode', 'pum_visible'])
1903
1904< Can also be used as a |method|: >
1905 GetItems()->complete_info()
1906<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001907 Return type: dict<any>
1908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001909 *confirm()*
1910confirm({msg} [, {choices} [, {default} [, {type}]]])
1911 confirm() offers the user a dialog, from which a choice can be
1912 made. It returns the number of the choice. For the first
1913 choice this is 1.
1914 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001915 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001916
1917 {msg} is displayed in a |dialog| with {choices} as the
1918 alternatives. When {choices} is missing or empty, "&OK" is
1919 used (and translated).
1920 {msg} is a String, use '\n' to include a newline. Only on
1921 some systems the string is wrapped when it doesn't fit.
1922
1923 {choices} is a String, with the individual choices separated
1924 by '\n', e.g. >
1925 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1926< The letter after the '&' is the shortcut key for that choice.
1927 Thus you can type 'c' to select "Cancel". The shortcut does
1928 not need to be the first letter: >
1929 confirm("file has been modified", "&Save\nSave &All")
1930< For the console, the first letter of each choice is used as
1931 the default shortcut key. Case is ignored.
1932
1933 The optional {default} argument is the number of the choice
1934 that is made if the user hits <CR>. Use 1 to make the first
1935 choice the default one. Use 0 to not set a default. If
1936 {default} is omitted, 1 is used.
1937
1938 The optional {type} String argument gives the type of dialog.
1939 This is only used for the icon of the GTK, Mac, Motif and
1940 Win32 GUI. It can be one of these values: "Error",
1941 "Question", "Info", "Warning" or "Generic". Only the first
1942 character is relevant. When {type} is omitted, "Generic" is
1943 used.
1944
1945 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1946 or another valid interrupt key, confirm() returns 0.
1947
1948 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001949 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001950 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001951 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001952 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001953 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001954 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001955 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001956 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001957 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001958< In a GUI dialog, buttons are used. The layout of the buttons
1959 depends on the 'v' flag in 'guioptions'. If it is included,
1960 the buttons are always put vertically. Otherwise, confirm()
1961 tries to put the buttons in one horizontal line. If they
1962 don't fit, a vertical layout is used anyway. For some systems
1963 the horizontal layout is always used.
1964
1965 Can also be used as a |method|in: >
1966 BuildMessage()->confirm("&Yes\n&No")
1967<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001968 Return type: |Number|
1969
1970
1971copy({expr}) *copy()*
1972 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001973 different from using {expr} directly.
1974 When {expr} is a |List| a shallow copy is created. This means
1975 that the original |List| can be changed without changing the
1976 copy, and vice versa. But the items are identical, thus
1977 changing an item changes the contents of both |Lists|.
1978 A |Dictionary| is copied in a similar way as a |List|.
1979 Also see |deepcopy()|.
1980 Can also be used as a |method|: >
1981 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001982<
1983 Return type: any, depending on {expr}
1984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001985
1986cos({expr}) *cos()*
1987 Return the cosine of {expr}, measured in radians, as a |Float|.
1988 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001989 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990 Examples: >
1991 :echo cos(100)
1992< 0.862319 >
1993 :echo cos(-4.01)
1994< -0.646043
1995
1996 Can also be used as a |method|: >
1997 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001998<
1999 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002000
2001
2002cosh({expr}) *cosh()*
2003 Return the hyperbolic cosine of {expr} as a |Float| in the range
2004 [1, inf].
2005 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002006 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002007 Examples: >
2008 :echo cosh(0.5)
2009< 1.127626 >
2010 :echo cosh(-0.5)
2011< -1.127626
2012
2013 Can also be used as a |method|: >
2014 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002015<
2016 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002017
2018
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002019count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002020 Return the number of times an item with value {expr} appears
2021 in |String|, |List| or |Dictionary| {comp}.
2022
2023 If {start} is given then start with the item with this index.
2024 {start} can only be used with a |List|.
2025
2026 When {ic} is given and it's |TRUE| then case is ignored.
2027
2028 When {comp} is a string then the number of not overlapping
2029 occurrences of {expr} is returned. Zero is returned when
2030 {expr} is an empty string.
2031
2032 Can also be used as a |method|: >
2033 mylist->count(val)
2034<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002035 Return type: |Number|
2036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002037 *cscope_connection()*
2038cscope_connection([{num} , {dbpath} [, {prepend}]])
2039 Checks for the existence of a |cscope| connection. If no
2040 parameters are specified, then the function returns:
2041 0, if cscope was not available (not compiled in), or
2042 if there are no cscope connections;
2043 1, if there is at least one cscope connection.
2044
2045 If parameters are specified, then the value of {num}
2046 determines how existence of a cscope connection is checked:
2047
2048 {num} Description of existence check
2049 ----- ------------------------------
2050 0 Same as no parameters (e.g., "cscope_connection()").
2051 1 Ignore {prepend}, and use partial string matches for
2052 {dbpath}.
2053 2 Ignore {prepend}, and use exact string matches for
2054 {dbpath}.
2055 3 Use {prepend}, use partial string matches for both
2056 {dbpath} and {prepend}.
2057 4 Use {prepend}, use exact string matches for both
2058 {dbpath} and {prepend}.
2059
2060 Note: All string comparisons are case sensitive!
2061
2062 Examples. Suppose we had the following (from ":cs show"): >
2063
2064 # pid database name prepend path
2065 0 27664 cscope.out /usr/local
2066<
2067 Invocation Return Val ~
2068 ---------- ---------- >
2069 cscope_connection() 1
2070 cscope_connection(1, "out") 1
2071 cscope_connection(2, "out") 0
2072 cscope_connection(3, "out") 0
2073 cscope_connection(3, "out", "local") 1
2074 cscope_connection(4, "out") 0
2075 cscope_connection(4, "out", "local") 0
2076 cscope_connection(4, "cscope.out", "/usr/local") 1
2077<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002078 Return type: |Number|
2079
2080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002081cursor({lnum}, {col} [, {off}]) *cursor()*
2082cursor({list})
2083 Positions the cursor at the column (byte count) {col} in the
2084 line {lnum}. The first column is one.
2085
2086 When there is one argument {list} this is used as a |List|
2087 with two, three or four item:
2088 [{lnum}, {col}]
2089 [{lnum}, {col}, {off}]
2090 [{lnum}, {col}, {off}, {curswant}]
2091 This is like the return value of |getpos()| or |getcurpos()|,
2092 but without the first item.
2093
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002094 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002095 |setcursorcharpos()|.
2096
2097 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002098 {lnum} is used like with |getline()|, except that if {lnum} is
2099 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002100 If {lnum} is greater than the number of lines in the buffer,
2101 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002102 If {col} is greater than the number of bytes in the line,
2103 the cursor will be positioned at the last character in the
2104 line.
2105 If {col} is zero, the cursor will stay in the current column.
2106 If {curswant} is given it is used to set the preferred column
2107 for vertical movement. Otherwise {col} is used.
2108
2109 When 'virtualedit' is used {off} specifies the offset in
2110 screen columns from the start of the character. E.g., a
2111 position within a <Tab> or after the last character.
2112 Returns 0 when the position could be set, -1 otherwise.
2113
2114 Can also be used as a |method|: >
2115 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002116<
2117 Return type: |Number|
2118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002119
2120debugbreak({pid}) *debugbreak()*
2121 Specifically used to interrupt a program being debugged. It
2122 will cause process {pid} to get a SIGTRAP. Behavior for other
2123 processes is undefined. See |terminal-debugger|.
2124 {only available on MS-Windows}
2125
Bram Moolenaar016188f2022-06-06 20:52:59 +01002126 Returns |TRUE| if successfully interrupted the program.
2127 Otherwise returns |FALSE|.
2128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002129 Can also be used as a |method|: >
2130 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002131<
2132 Return type: |Number|
2133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002134
2135deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2136 Make a copy of {expr}. For Numbers and Strings this isn't
2137 different from using {expr} directly.
2138 When {expr} is a |List| a full copy is created. This means
2139 that the original |List| can be changed without changing the
2140 copy, and vice versa. When an item is a |List| or
2141 |Dictionary|, a copy for it is made, recursively. Thus
2142 changing an item in the copy does not change the contents of
2143 the original |List|.
2144 A |Dictionary| is copied in a similar way as a |List|.
2145
2146 When {noref} is omitted or zero a contained |List| or
2147 |Dictionary| is only copied once. All references point to
2148 this single copy. With {noref} set to 1 every occurrence of a
2149 |List| or |Dictionary| results in a new copy. This also means
2150 that a cyclic reference causes deepcopy() to fail.
2151 *E724*
2152 Nesting is possible up to 100 levels. When there is an item
2153 that refers back to a higher level making a deep copy with
2154 {noref} set to 1 will fail.
2155 Also see |copy()|.
2156
2157 Can also be used as a |method|: >
2158 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002159<
2160 Return type: any, depending on {expr}
2161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002162
2163delete({fname} [, {flags}]) *delete()*
2164 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002165 name {fname}.
2166
2167 This also works when {fname} is a symbolic link. The symbolic
2168 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002169
2170 When {flags} is "d": Deletes the directory by the name
2171 {fname}. This fails when directory {fname} is not empty.
2172
2173 When {flags} is "rf": Deletes the directory by the name
2174 {fname} and everything in it, recursively. BE CAREFUL!
2175 Note: on MS-Windows it is not possible to delete a directory
2176 that is being used.
2177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002178 The result is a Number, which is 0/false if the delete
2179 operation was successful and -1/true when the deletion failed
2180 or partly failed.
2181
2182 Use |remove()| to delete an item from a |List|.
2183 To delete a line from the buffer use |:delete| or
2184 |deletebufline()|.
2185
2186 Can also be used as a |method|: >
2187 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002188<
2189 Return type: |Number|
2190
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002191
2192deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2193 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2194 If {last} is omitted then delete line {first} only.
2195 On success 0 is returned, on failure 1 is returned.
2196
2197 This function works only for loaded buffers. First call
2198 |bufload()| if needed.
2199
2200 For the use of {buf}, see |bufname()| above.
2201
2202 {first} and {last} are used like with |getline()|. Note that
2203 when using |line()| this refers to the current buffer. Use "$"
2204 to refer to the last line in buffer {buf}.
2205
2206 Can also be used as a |method|: >
2207 GetBuffer()->deletebufline(1)
2208<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002209 Return type: |Number|
2210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002211 *did_filetype()*
2212did_filetype() Returns |TRUE| when autocommands are being executed and the
2213 FileType event has been triggered at least once. Can be used
2214 to avoid triggering the FileType event again in the scripts
2215 that detect the file type. |FileType|
2216 Returns |FALSE| when `:setf FALLBACK` was used.
2217 When editing another file, the counter is reset, thus this
2218 really checks if the FileType event has been triggered for the
2219 current buffer. This allows an autocommand that starts
2220 editing another buffer to set 'filetype' and load a syntax
2221 file.
2222
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002223 Return type: |Number|
2224
2225
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002226diff({fromlist}, {tolist} [, {options}]) *diff()*
2227 Returns a String or a List containing the diff between the
2228 strings in {fromlist} and {tolist}. Uses the Vim internal
2229 diff library to compute the diff.
2230
2231 *E106*
2232 The optional "output" item in {options} specifies the returned
2233 diff format. The following values are supported:
2234 indices Return a List of the starting and ending
2235 indices and a count of the strings in each
2236 diff hunk.
2237 unified Return the unified diff output as a String.
2238 This is the default.
2239
2240 If the "output" item in {options} is "indices", then a List is
2241 returned. Each List item contains a Dict with the following
2242 items for each diff hunk:
2243 from_idx start index in {fromlist} for this diff hunk.
2244 from_count number of strings in {fromlist} that are
2245 added/removed/modified in this diff hunk.
2246 to_idx start index in {tolist} for this diff hunk.
2247 to_count number of strings in {tolist} that are
2248 added/removed/modified in this diff hunk.
2249
2250 The {options} Dict argument also specifies diff options
2251 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002252 algorithm Dict specifying the diff algorithm to
2253 use. Supported boolean items are
2254 "myers", "minimal", "patience" and
2255 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002256 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002257 iblank ignore changes where lines are all
2258 blank.
2259 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002260 indent-heuristic use the indent heuristic for the
2261 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002262 iwhite ignore changes in amount of white
2263 space.
2264 iwhiteall ignore all white space changes.
2265 iwhiteeol ignore white space changes at end of
2266 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002267 For more information about these options, refer to 'diffopt'.
2268
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002269 To compute the unified diff, all the items in {fromlist} are
2270 concatenated into a string using a newline separator and the
2271 same for {tolist}. The unified diff output uses line numbers.
2272
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002273 Returns an empty List or String if {fromlist} and {tolist} are
2274 identical.
2275
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002276 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002277 :echo diff(['abc'], ['xxx'])
2278 @@ -1 +1 @@
2279 -abc
2280 +xxx
2281
2282 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2283 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2284 :echo diff(readfile('oldfile'), readfile('newfile'))
2285 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002286<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002287 For more examples, refer to |diff-func-examples|
2288
2289 Can also be used as a |method|: >
2290 GetFromList->diff(to_list)
2291<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002292 Return type: |String| or list<dict<number>> or list<any>
2293 depending on {options}
2294
2295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002296diff_filler({lnum}) *diff_filler()*
2297 Returns the number of filler lines above line {lnum}.
2298 These are the lines that were inserted at this point in
2299 another diff'ed window. These filler lines are shown in the
2300 display but don't exist in the buffer.
2301 {lnum} is used like with |getline()|. Thus "." is the current
2302 line, "'m" mark m, etc.
2303 Returns 0 if the current window is not in diff mode.
2304
2305 Can also be used as a |method|: >
2306 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002307<
2308 Return type: |Number|
2309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002310
2311diff_hlID({lnum}, {col}) *diff_hlID()*
2312 Returns the highlight ID for diff mode at line {lnum} column
2313 {col} (byte index). When the current line does not have a
2314 diff change zero is returned.
2315 {lnum} is used like with |getline()|. Thus "." is the current
2316 line, "'m" mark m, etc.
2317 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2318 line.
2319 The highlight ID can be used with |synIDattr()| to obtain
2320 syntax information about the highlighting.
2321
2322 Can also be used as a |method|: >
2323 GetLnum()->diff_hlID(col)
2324<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002325 Return type: |Number|
2326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002327
2328digraph_get({chars}) *digraph_get()* *E1214*
2329 Return the digraph of {chars}. This should be a string with
2330 exactly two characters. If {chars} are not just two
2331 characters, or the digraph of {chars} does not exist, an error
2332 is given and an empty string is returned.
2333
2334 The character will be converted from Unicode to 'encoding'
2335 when needed. This does require the conversion to be
2336 available, it might fail.
2337
2338 Also see |digraph_getlist()|.
2339
2340 Examples: >
2341 " Get a built-in digraph
2342 :echo digraph_get('00') " Returns '∞'
2343
2344 " Get a user-defined digraph
2345 :call digraph_set('aa', 'あ')
2346 :echo digraph_get('aa') " Returns 'あ'
2347<
2348 Can also be used as a |method|: >
2349 GetChars()->digraph_get()
2350<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002351 Return type: |String|
2352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002353 This function works only when compiled with the |+digraphs|
2354 feature. If this feature is disabled, this function will
2355 display an error message.
2356
2357
2358digraph_getlist([{listall}]) *digraph_getlist()*
2359 Return a list of digraphs. If the {listall} argument is given
2360 and it is TRUE, return all digraphs, including the default
2361 digraphs. Otherwise, return only user-defined digraphs.
2362
2363 The characters will be converted from Unicode to 'encoding'
2364 when needed. This does require the conservation to be
2365 available, it might fail.
2366
2367 Also see |digraph_get()|.
2368
2369 Examples: >
2370 " Get user-defined digraphs
2371 :echo digraph_getlist()
2372
2373 " Get all the digraphs, including default digraphs
2374 :echo digraph_getlist(1)
2375<
2376 Can also be used as a |method|: >
2377 GetNumber()->digraph_getlist()
2378<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002379 Return type: list<list<string>>
2380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002381 This function works only when compiled with the |+digraphs|
2382 feature. If this feature is disabled, this function will
2383 display an error message.
2384
2385
Bram Moolenaara2baa732022-02-04 16:09:54 +00002386digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002387 Add digraph {chars} to the list. {chars} must be a string
2388 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002389 encoded character. *E1215*
2390 Be careful, composing characters are NOT ignored. This
2391 function is similar to |:digraphs| command, but useful to add
2392 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002393
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002394 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002395 this fails an error message is given and v:false is returned.
2396
2397 If you want to define multiple digraphs at once, you can use
2398 |digraph_setlist()|.
2399
2400 Example: >
2401 call digraph_set(' ', 'あ')
2402<
2403 Can be used as a |method|: >
2404 GetString()->digraph_set('あ')
2405<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002406 Return type: |vim9-boolean|
2407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002408 This function works only when compiled with the |+digraphs|
2409 feature. If this feature is disabled, this function will
2410 display an error message.
2411
2412
2413digraph_setlist({digraphlist}) *digraph_setlist()*
2414 Similar to |digraph_set()| but this function can add multiple
2415 digraphs at once. {digraphlist} is a list composed of lists,
2416 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002417 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002418 Example: >
2419 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2420<
2421 It is similar to the following: >
2422 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2423 call digraph_set(chars, digraph)
2424 endfor
2425< Except that the function returns after the first error,
2426 following digraphs will not be added.
2427
2428 Can be used as a |method|: >
2429 GetList()->digraph_setlist()
2430<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002431 Return type: |vim9-boolean|
2432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002433 This function works only when compiled with the |+digraphs|
2434 feature. If this feature is disabled, this function will
2435 display an error message.
2436
2437
2438echoraw({string}) *echoraw()*
2439 Output {string} as-is, including unprintable characters.
2440 This can be used to output a terminal code. For example, to
2441 disable modifyOtherKeys: >
2442 call echoraw(&t_TE)
2443< and to enable it again: >
2444 call echoraw(&t_TI)
2445< Use with care, you can mess up the terminal this way.
2446
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002447 Return type: |Number|
2448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002449
2450empty({expr}) *empty()*
2451 Return the Number 1 if {expr} is empty, zero otherwise.
2452 - A |List| or |Dictionary| is empty when it does not have any
2453 items.
2454 - A |String| is empty when its length is zero.
2455 - A |Number| and |Float| are empty when their value is zero.
2456 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2457 - A |Job| is empty when it failed to start.
2458 - A |Channel| is empty when it is closed.
2459 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002460 - An |Object| is empty, when the empty() method in the object
2461 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002462
2463 For a long |List| this is much faster than comparing the
2464 length with zero.
2465
2466 Can also be used as a |method|: >
2467 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002468<
2469 Return type: |Number|
2470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002471
2472environ() *environ()*
2473 Return all of environment variables as dictionary. You can
2474 check if an environment variable exists like this: >
2475 :echo has_key(environ(), 'HOME')
2476< Note that the variable name may be CamelCase; to ignore case
2477 use this: >
2478 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002479<
2480 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002481
Bram Moolenaar416bd912023-07-07 23:19:18 +01002482
2483err_teapot([{expr}]) *err_teapot()*
2484 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002485 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002486 If {expr} is present and it is TRUE error 503 is given,
2487 indicating that coffee is temporarily not available.
2488 If {expr} is present it must be a String.
2489
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002490 Return type: |Number|
2491
Bram Moolenaar416bd912023-07-07 23:19:18 +01002492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002493escape({string}, {chars}) *escape()*
2494 Escape the characters in {chars} that occur in {string} with a
2495 backslash. Example: >
2496 :echo escape('c:\program files\vim', ' \')
2497< results in: >
2498 c:\\program\ files\\vim
2499< Also see |shellescape()| and |fnameescape()|.
2500
2501 Can also be used as a |method|: >
2502 GetText()->escape(' \')
2503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002504 Return type: |String|
2505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002506 *eval()*
2507eval({string}) Evaluate {string} and return the result. Especially useful to
2508 turn the result of |string()| back into the original value.
2509 This works for Numbers, Floats, Strings, Blobs and composites
2510 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002511 functions. In |Vim9| script, it can be used to obtain |enum|
2512 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002513
2514 Can also be used as a |method|: >
2515 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002516<
2517 Return type: any, depending on {string}
2518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002519
2520eventhandler() *eventhandler()*
2521 Returns 1 when inside an event handler. That is that Vim got
2522 interrupted while waiting for the user to type a character,
2523 e.g., when dropping a file on Vim. This means interactive
2524 commands cannot be used. Otherwise zero is returned.
2525
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002526 Return type: |Number|
2527
2528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002529executable({expr}) *executable()*
2530 This function checks if an executable with the name {expr}
2531 exists. {expr} must be the name of the program without any
2532 arguments.
2533 executable() uses the value of $PATH and/or the normal
2534 searchpath for programs. *PATHEXT*
2535 On MS-Windows the ".exe", ".bat", etc. can optionally be
2536 included. Then the extensions in $PATHEXT are tried. Thus if
2537 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2538 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2539 by itself can be used in $PATHEXT to try using the name
2540 without an extension. When 'shell' looks like a Unix shell,
2541 then the name is also tried without adding an extension.
2542 On MS-Windows it only checks if the file exists and is not a
2543 directory, not if it's really executable.
2544 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002545 normally found. Since this directory is added to $PATH it
2546 should also work to execute it |win32-PATH|. This can be
2547 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2548 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002549 The result is a Number:
2550 1 exists
2551 0 does not exist
2552 -1 not implemented on this system
2553 |exepath()| can be used to get the full path of an executable.
2554
2555 Can also be used as a |method|: >
2556 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002557<
2558 Return type: |Number|
2559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002560
2561execute({command} [, {silent}]) *execute()*
2562 Execute an Ex command or commands and return the output as a
2563 string.
2564 {command} can be a string or a List. In case of a List the
2565 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002566 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002567 redir => var
2568 {command}
2569 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002570< Except that line continuation in {command} is not recognized.
2571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002572 The optional {silent} argument can have these values:
2573 "" no `:silent` used
2574 "silent" `:silent` used
2575 "silent!" `:silent!` used
2576 The default is "silent". Note that with "silent!", unlike
2577 `:redir`, error messages are dropped. When using an external
2578 command the screen may be messed up, use `system()` instead.
2579 *E930*
2580 It is not possible to use `:redir` anywhere in {command}.
2581
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002582 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002583 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002584
2585< To execute a command in another window than the current one
2586 use `win_execute()`.
2587
2588 When used recursively the output of the recursive call is not
2589 included in the output of the higher level call.
2590
2591 Can also be used as a |method|: >
2592 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002593<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002594 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002596
2597exepath({expr}) *exepath()*
2598 If {expr} is an executable and is either an absolute path, a
2599 relative path or found in $PATH, return the full path.
2600 Note that the current directory is used when {expr} starts
2601 with "./", which may be a problem for Vim: >
2602 echo exepath(v:progpath)
2603< If {expr} cannot be found in $PATH or is not executable then
2604 an empty string is returned.
2605
2606 Can also be used as a |method|: >
2607 GetCommand()->exepath()
2608<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002609 Return type: |String|
2610
2611
2612exists({expr}) *exists()*
2613 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002614 zero otherwise.
2615
2616 Note: In a compiled |:def| function the evaluation is done at
2617 runtime. Use `exists_compiled()` to evaluate the expression
2618 at compile time.
2619
2620 For checking for a supported feature use |has()|.
2621 For checking if a file exists use |filereadable()|.
2622
2623 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002624 varname internal variable (see
2625 dict.key |internal-variables|). Also works
2626 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002627 import.Func entries, |List| items, class and
2628 class.Func object methods, imported items, etc.
2629 object.Func Does not work for local variables in a
2630 class.varname compiled `:def` function.
2631 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002632 script, since it can be used as a
2633 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002634 Beware that evaluating an index may
2635 cause an error message for an invalid
2636 expression. E.g.: >
2637 :let l = [1, 2, 3]
2638 :echo exists("l[5]")
2639< 0 >
2640 :echo exists("l[xx]")
2641< E121: Undefined variable: xx
2642 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002643 &option-name Vim option (only checks if it exists,
2644 not if it really works)
2645 +option-name Vim option that works.
2646 $ENVNAME environment variable (could also be
2647 done by comparing with an empty
2648 string)
2649 *funcname built-in function (see |functions|)
2650 or user defined function (see
2651 |user-functions|) that is implemented.
2652 Also works for a variable that is a
2653 Funcref.
2654 ?funcname built-in function that could be
2655 implemented; to be used to check if
2656 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657 :cmdname Ex command: built-in command, user
2658 command or command modifier |:command|.
2659 Returns:
2660 1 for match with start of a command
2661 2 full match with a command
2662 3 matches several user commands
2663 To check for a supported command
2664 always check the return value to be 2.
2665 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002666 :3match The |:3match| command (but you
2667 probably should not use it, it is
2668 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002669 #event autocommand defined for this event
2670 #event#pattern autocommand defined for this event and
2671 pattern (the pattern is taken
2672 literally and compared to the
2673 autocommand patterns character by
2674 character)
2675 #group autocommand group exists
2676 #group#event autocommand defined for this group and
2677 event.
2678 #group#event#pattern
2679 autocommand defined for this group,
2680 event and pattern.
2681 ##event autocommand for this event is
2682 supported.
2683
2684 Examples: >
2685 exists("&shortname")
2686 exists("$HOSTNAME")
2687 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002688 exists("*s:MyFunc") " only for legacy script
2689 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002690 exists("bufcount")
2691 exists(":Make")
2692 exists("#CursorHold")
2693 exists("#BufReadPre#*.gz")
2694 exists("#filetypeindent")
2695 exists("#filetypeindent#FileType")
2696 exists("#filetypeindent#FileType#*")
2697 exists("##ColorScheme")
2698< There must be no space between the symbol (&/$/*/#) and the
2699 name.
2700 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002701 a few cases this is ignored. That may become stricter in the
2702 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002703 Working example: >
2704 exists(":make")
2705< NOT working example: >
2706 exists(":make install")
2707
2708< Note that the argument must be a string, not the name of the
2709 variable itself. For example: >
2710 exists(bufcount)
2711< This doesn't check for existence of the "bufcount" variable,
2712 but gets the value of "bufcount", and checks if that exists.
2713
2714 Can also be used as a |method|: >
2715 Varname()->exists()
2716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002717 Return type: |String|
2718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002719
2720exists_compiled({expr}) *exists_compiled()*
2721 Like `exists()` but evaluated at compile time. This is useful
2722 to skip a block where a function is used that would otherwise
2723 give an error: >
2724 if exists_compiled('*ThatFunction')
2725 ThatFunction('works')
2726 endif
2727< If `exists()` were used then a compilation error would be
2728 given if ThatFunction() is not defined.
2729
2730 {expr} must be a literal string. *E1232*
2731 Can only be used in a |:def| function. *E1233*
2732 This does not work to check for arguments or local variables.
2733
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002734 Return type: |String|
2735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002736
2737exp({expr}) *exp()*
2738 Return the exponential of {expr} as a |Float| in the range
2739 [0, inf].
2740 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002741 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002742 Examples: >
2743 :echo exp(2)
2744< 7.389056 >
2745 :echo exp(-1)
2746< 0.367879
2747
2748 Can also be used as a |method|: >
2749 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002750<
2751 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002752
2753
2754expand({string} [, {nosuf} [, {list}]]) *expand()*
2755 Expand wildcards and the following special keywords in
2756 {string}. 'wildignorecase' applies.
2757
2758 If {list} is given and it is |TRUE|, a List will be returned.
2759 Otherwise the result is a String and when there are several
2760 matches, they are separated by <NL> characters. [Note: in
2761 version 5.0 a space was used, which caused problems when a
2762 file name contains a space]
2763
2764 If the expansion fails, the result is an empty string. A name
2765 for a non-existing file is not included, unless {string} does
2766 not start with '%', '#' or '<', see below.
2767
Christian Brabandtec9c3262024-02-21 20:40:05 +01002768 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002769 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002771 When {string} starts with '%', '#' or '<', the expansion is
2772 done like for the |cmdline-special| variables with their
2773 associated modifiers. Here is a short overview:
2774
2775 % current file name
2776 # alternate file name
2777 #n alternate file name n
2778 <cfile> file name under the cursor
2779 <afile> autocmd file name
2780 <abuf> autocmd buffer number (as a String!)
2781 <amatch> autocmd matched name
2782 <cexpr> C expression under the cursor
2783 <sfile> sourced script file or function name
2784 <slnum> sourced script line number or function
2785 line number
2786 <sflnum> script file line number, also when in
2787 a function
2788 <SID> "<SNR>123_" where "123" is the
2789 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002790 <script> sourced script file, or script file
2791 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002792 <stack> call stack
2793 <cword> word under the cursor
2794 <cWORD> WORD under the cursor
2795 <client> the {clientid} of the last received
2796 message |server2client()|
2797 Modifiers:
2798 :p expand to full path
2799 :h head (last path component removed)
2800 :t tail (last path component only)
2801 :r root (one extension removed)
2802 :e extension only
2803
2804 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002805 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002806< Note that when expanding a string that starts with '%', '#' or
2807 '<', any following text is ignored. This does NOT work: >
2808 :let doesntwork = expand("%:h.bak")
2809< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002810 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002811< Also note that expanding "<cfile>" and others only returns the
2812 referenced file name without further expansion. If "<cfile>"
2813 is "~/.cshrc", you need to do another expand() to have the
2814 "~/" expanded into the path of the home directory: >
2815 :echo expand(expand("<cfile>"))
2816<
2817 There cannot be white space between the variables and the
2818 following modifier. The |fnamemodify()| function can be used
2819 to modify normal file names.
2820
2821 When using '%' or '#', and the current or alternate file name
2822 is not defined, an empty string is used. Using "%:p" in a
2823 buffer with no name, results in the current directory, with a
2824 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002825 When 'verbose' is set then expanding '%', '#' and <> items
2826 will result in an error message if the argument cannot be
2827 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002828
2829 When {string} does not start with '%', '#' or '<', it is
2830 expanded like a file name is expanded on the command line.
2831 'suffixes' and 'wildignore' are used, unless the optional
2832 {nosuf} argument is given and it is |TRUE|.
2833 Names for non-existing files are included. The "**" item can
2834 be used to search in a directory tree. For example, to find
2835 all "README" files in the current directory and below: >
2836 :echo expand("**/README")
2837<
2838 expand() can also be used to expand variables and environment
2839 variables that are only known in a shell. But this can be
2840 slow, because a shell may be used to do the expansion. See
2841 |expr-env-expand|.
2842 The expanded variable is still handled like a list of file
2843 names. When an environment variable cannot be expanded, it is
2844 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2845 "$FOOBAR".
2846
2847 See |glob()| for finding existing files. See |system()| for
2848 getting the raw output of an external command.
2849
2850 Can also be used as a |method|: >
2851 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002852<
2853 Return type: |String| or list<string> depending on {list}
2854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002855
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002856expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002857 Expand special items in String {string} like what is done for
2858 an Ex command such as `:edit`. This expands special keywords,
2859 like with |expand()|, and environment variables, anywhere in
2860 {string}. "~user" and "~/path" are only expanded at the
2861 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002862
2863 The following items are supported in the {options} Dict
2864 argument:
2865 errmsg If set to TRUE, error messages are displayed
2866 if an error is encountered during expansion.
2867 By default, error messages are not displayed.
2868
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002869 Returns the expanded string. If an error is encountered
2870 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002871
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002872 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002873 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002874 make /path/runtime/doc/builtin.o
2875 :echo expandcmd('make %<.o', {'errmsg': v:true})
2876<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002877 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002878 GetCommand()->expandcmd()
2879<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002880 Return type: |String| or list<string> depending on {list}
2881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002882extend({expr1}, {expr2} [, {expr3}]) *extend()*
2883 {expr1} and {expr2} must be both |Lists| or both
2884 |Dictionaries|.
2885
2886 If they are |Lists|: Append {expr2} to {expr1}.
2887 If {expr3} is given insert the items of {expr2} before the
2888 item with index {expr3} in {expr1}. When {expr3} is zero
2889 insert before the first item. When {expr3} is equal to
2890 len({expr1}) then {expr2} is appended.
2891 Examples: >
2892 :echo sort(extend(mylist, [7, 5]))
2893 :call extend(mylist, [2, 3], 1)
2894< When {expr1} is the same List as {expr2} then the number of
2895 items copied is equal to the original length of the List.
2896 E.g., when {expr3} is 1 you get N new copies of the first item
2897 (where N is the original length of the List).
2898 Use |add()| to concatenate one item to a list. To concatenate
2899 two lists into a new list use the + operator: >
2900 :let newlist = [1, 2, 3] + [4, 5]
2901<
2902 If they are |Dictionaries|:
2903 Add all entries from {expr2} to {expr1}.
2904 If a key exists in both {expr1} and {expr2} then {expr3} is
2905 used to decide what to do:
2906 {expr3} = "keep": keep the value of {expr1}
2907 {expr3} = "force": use the value of {expr2}
2908 {expr3} = "error": give an error message *E737*
2909 When {expr3} is omitted then "force" is assumed.
2910
2911 {expr1} is changed when {expr2} is not empty. If necessary
2912 make a copy of {expr1} first.
2913 {expr2} remains unchanged.
2914 When {expr1} is locked and {expr2} is not empty the operation
2915 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002916 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002917
2918 Can also be used as a |method|: >
2919 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002920<
2921 Return type: list<{type}> or dict<{type}> depending on {expr1}
2922 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002923
2924
2925extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2926 Like |extend()| but instead of adding items to {expr1} a new
2927 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002928 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002929
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002930 Return type: list<{type}> or dict<{type}> depending on {expr1}
2931 and {expr2}, in case of error: |Number|
2932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002933
2934feedkeys({string} [, {mode}]) *feedkeys()*
2935 Characters in {string} are queued for processing as if they
2936 come from a mapping or were typed by the user.
2937
2938 By default the string is added to the end of the typeahead
2939 buffer, thus if a mapping is still being executed the
2940 characters come after them. Use the 'i' flag to insert before
2941 other characters, they will be executed next, before any
2942 characters from a mapping.
2943
2944 The function does not wait for processing of keys contained in
2945 {string}.
2946
2947 To include special keys into {string}, use double-quotes
2948 and "\..." notation |expr-quote|. For example,
2949 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2950 feedkeys('\<CR>') pushes 5 characters.
2951 A special code that might be useful is <Ignore>, it exits the
2952 wait for a character without doing anything. *<Ignore>*
2953
2954 {mode} is a String, which can contain these character flags:
2955 'm' Remap keys. This is default. If {mode} is absent,
2956 keys are remapped.
2957 'n' Do not remap keys.
2958 't' Handle keys as if typed; otherwise they are handled as
2959 if coming from a mapping. This matters for undo,
2960 opening folds, etc.
2961 'L' Lowlevel input. Only works for Unix or when using the
2962 GUI. Keys are used as if they were coming from the
2963 terminal. Other flags are not used. *E980*
2964 When a CTRL-C interrupts and 't' is included it sets
2965 the internal "got_int" flag.
2966 'i' Insert the string instead of appending (see above).
2967 'x' Execute commands until typeahead is empty. This is
2968 similar to using ":normal!". You can call feedkeys()
2969 several times without 'x' and then one time with 'x'
2970 (possibly with an empty {string}) to execute all the
2971 typeahead. Note that when Vim ends in Insert mode it
2972 will behave as if <Esc> is typed, to avoid getting
2973 stuck, waiting for a character to be typed before the
2974 script continues.
2975 Note that if you manage to call feedkeys() while
2976 executing commands, thus calling it recursively, then
2977 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002978 'c' Remove any script context when executing, so that
2979 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002980 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002981 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002982 '!' When used with 'x' will not end Insert mode. Can be
2983 used in a test when a timer is set to exit Insert mode
2984 a little later. Useful for testing CursorHoldI.
2985
2986 Return value is always 0.
2987
2988 Can also be used as a |method|: >
2989 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002990<
2991 Return type: |String| or list<string> depending on {list}
2992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002993
Shougo Matsushita60c87432024-06-03 22:59:27 +02002994filecopy({from}, {to}) *filecopy()*
2995 Copy the file pointed to by the name {from} to {to}. The
2996 result is a Number, which is |TRUE| if the file was copied
2997 successfully, and |FALSE| when it failed.
2998 If a file with name {to} already exists, it will fail.
2999 Note that it does not handle directories (yet).
3000
3001 This function is not available in the |sandbox|.
3002
3003 Can also be used as a |method|: >
3004 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003005<
3006 Return type: |Number|
3007
Shougo Matsushita60c87432024-06-03 22:59:27 +02003008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003009filereadable({file}) *filereadable()*
3010 The result is a Number, which is |TRUE| when a file with the
3011 name {file} exists, and can be read. If {file} doesn't exist,
3012 or is a directory, the result is |FALSE|. {file} is any
3013 expression, which is used as a String.
3014 If you don't care about the file being readable you can use
3015 |glob()|.
3016 {file} is used as-is, you may want to expand wildcards first: >
3017 echo filereadable('~/.vimrc')
3018 0
3019 echo filereadable(expand('~/.vimrc'))
3020 1
3021
3022< Can also be used as a |method|: >
3023 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003024<
3025 Return type: |Number|
3026
3027 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003028 Obsolete name: file_readable().
3029
3030
3031filewritable({file}) *filewritable()*
3032 The result is a Number, which is 1 when a file with the
3033 name {file} exists, and can be written. If {file} doesn't
3034 exist, or is not writable, the result is 0. If {file} is a
3035 directory, and we can write to it, the result is 2.
3036
3037 Can also be used as a |method|: >
3038 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003039<
3040 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003041
3042
3043filter({expr1}, {expr2}) *filter()*
3044 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3045 For each item in {expr1} evaluate {expr2} and when the result
3046 is zero or false remove the item from the |List| or
3047 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003048 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003049
3050 {expr2} must be a |string| or |Funcref|.
3051
3052 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3053 of the current item. For a |Dictionary| |v:key| has the key
3054 of the current item and for a |List| |v:key| has the index of
3055 the current item. For a |Blob| |v:key| has the index of the
3056 current byte. For a |String| |v:key| has the index of the
3057 current character.
3058 Examples: >
3059 call filter(mylist, 'v:val !~ "OLD"')
3060< Removes the items where "OLD" appears. >
3061 call filter(mydict, 'v:key >= 8')
3062< Removes the items with a key below 8. >
3063 call filter(var, 0)
3064< Removes all the items, thus clears the |List| or |Dictionary|.
3065
3066 Note that {expr2} is the result of expression and is then
3067 used as an expression again. Often it is good to use a
3068 |literal-string| to avoid having to double backslashes.
3069
3070 If {expr2} is a |Funcref| it must take two arguments:
3071 1. the key or the index of the current item.
3072 2. the value of the current item.
3073 The function must return |TRUE| if the item should be kept.
3074 Example that keeps the odd items of a list: >
3075 func Odd(idx, val)
3076 return a:idx % 2 == 1
3077 endfunc
3078 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003079< It is shorter when using a |lambda|. In |Vim9| syntax: >
3080 call filter(myList, (idx, val) => idx * val <= 42)
3081< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003082 call filter(myList, {idx, val -> idx * val <= 42})
3083< If you do not use "val" you can leave it out: >
3084 call filter(myList, {idx -> idx % 2 == 1})
3085<
3086 In |Vim9| script the result must be true, false, zero or one.
3087 Other values will result in a type error.
3088
3089 For a |List| and a |Dictionary| the operation is done
3090 in-place. If you want it to remain unmodified make a copy
3091 first: >
3092 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3093
3094< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003095 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003096 When an error is encountered while evaluating {expr2} no
3097 further items in {expr1} are processed.
3098 When {expr2} is a Funcref errors inside a function are ignored,
3099 unless it was defined with the "abort" flag.
3100
3101 Can also be used as a |method|: >
3102 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003103<
3104 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3105 depending on {expr1}
3106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003107
3108finddir({name} [, {path} [, {count}]]) *finddir()*
3109 Find directory {name} in {path}. Supports both downwards and
3110 upwards recursive directory searches. See |file-searching|
3111 for the syntax of {path}.
3112
3113 Returns the path of the first found match. When the found
3114 directory is below the current directory a relative path is
3115 returned. Otherwise a full path is returned.
3116 If {path} is omitted or empty then 'path' is used.
3117
3118 If the optional {count} is given, find {count}'s occurrence of
3119 {name} in {path} instead of the first one.
3120 When {count} is negative return all the matches in a |List|.
3121
Bram Moolenaar016188f2022-06-06 20:52:59 +01003122 Returns an empty string if the directory is not found.
3123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003124 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003125
3126 Can also be used as a |method|: >
3127 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003128<
3129 Return type: |String|
3130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003131
3132findfile({name} [, {path} [, {count}]]) *findfile()*
3133 Just like |finddir()|, but find a file instead of a directory.
3134 Uses 'suffixesadd'.
3135 Example: >
3136 :echo findfile("tags.vim", ".;")
3137< Searches from the directory of the current file upwards until
3138 it finds the file "tags.vim".
3139
3140 Can also be used as a |method|: >
3141 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003142<
3143 Return type: |String|
3144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003145
3146flatten({list} [, {maxdepth}]) *flatten()*
3147 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3148 the result is a |List| without nesting, as if {maxdepth} is
3149 a very large number.
3150 The {list} is changed in place, use |flattennew()| if you do
3151 not want that.
3152 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003153 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003154 *E900*
3155 {maxdepth} means how deep in nested lists changes are made.
3156 {list} is not modified when {maxdepth} is 0.
3157 {maxdepth} must be positive number.
3158
3159 If there is an error the number zero is returned.
3160
3161 Example: >
3162 :echo flatten([1, [2, [3, 4]], 5])
3163< [1, 2, 3, 4, 5] >
3164 :echo flatten([1, [2, [3, 4]], 5], 1)
3165< [1, 2, [3, 4], 5]
3166
3167 Can also be used as a |method|: >
3168 mylist->flatten()
3169<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003170 Return type: list<{type}>
3171
3172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003173flattennew({list} [, {maxdepth}]) *flattennew()*
3174 Like |flatten()| but first make a copy of {list}.
3175
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003176 Return type: list<{type}>
3177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003178
3179float2nr({expr}) *float2nr()*
3180 Convert {expr} to a Number by omitting the part after the
3181 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003182 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003183 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003184 When the value of {expr} is out of range for a |Number| the
3185 result is truncated to 0x7fffffff or -0x7fffffff (or when
3186 64-bit Number support is enabled, 0x7fffffffffffffff or
3187 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3188 64-bit Number support is enabled, -0x8000000000000000).
3189 Examples: >
3190 echo float2nr(3.95)
3191< 3 >
3192 echo float2nr(-23.45)
3193< -23 >
3194 echo float2nr(1.0e100)
3195< 2147483647 (or 9223372036854775807) >
3196 echo float2nr(-1.0e150)
3197< -2147483647 (or -9223372036854775807) >
3198 echo float2nr(1.0e-100)
3199< 0
3200
3201 Can also be used as a |method|: >
3202 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003203<
3204 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003205
3206
3207floor({expr}) *floor()*
3208 Return the largest integral value less than or equal to
3209 {expr} as a |Float| (round down).
3210 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003211 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003212 Examples: >
3213 echo floor(1.856)
3214< 1.0 >
3215 echo floor(-5.456)
3216< -6.0 >
3217 echo floor(4.0)
3218< 4.0
3219
3220 Can also be used as a |method|: >
3221 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003222<
3223 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003224
3225
3226fmod({expr1}, {expr2}) *fmod()*
3227 Return the remainder of {expr1} / {expr2}, even if the
3228 division is not representable. Returns {expr1} - i * {expr2}
3229 for some integer i such that if {expr2} is non-zero, the
3230 result has the same sign as {expr1} and magnitude less than
3231 the magnitude of {expr2}. If {expr2} is zero, the value
3232 returned is zero. The value returned is a |Float|.
3233 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003234 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3235 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003236 Examples: >
3237 :echo fmod(12.33, 1.22)
3238< 0.13 >
3239 :echo fmod(-12.33, 1.22)
3240< -0.13
3241
3242 Can also be used as a |method|: >
3243 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003244<
3245 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003246
3247
3248fnameescape({string}) *fnameescape()*
3249 Escape {string} for use as file name command argument. All
3250 characters that have a special meaning, such as '%' and '|'
3251 are escaped with a backslash.
3252 For most systems the characters escaped are
3253 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3254 appears in a filename, it depends on the value of 'isfname'.
3255 A leading '+' and '>' is also escaped (special after |:edit|
3256 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003257 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003258 Example: >
3259 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003260 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003261< results in executing: >
3262 edit \+some\ str\%nge\|name
3263<
3264 Can also be used as a |method|: >
3265 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003266<
3267 Return type: |String|
3268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003269
3270fnamemodify({fname}, {mods}) *fnamemodify()*
3271 Modify file name {fname} according to {mods}. {mods} is a
3272 string of characters like it is used for file names on the
3273 command line. See |filename-modifiers|.
3274 Example: >
3275 :echo fnamemodify("main.c", ":p:h")
3276< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003277 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003278< If {mods} is empty or an unsupported modifier is used then
3279 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003280 When {fname} is empty then with {mods} ":h" returns ".", so
3281 that `:cd` can be used with it. This is different from
3282 expand('%:h') without a buffer name, which returns an empty
3283 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003284 Note: Environment variables don't work in {fname}, use
3285 |expand()| first then.
3286
3287 Can also be used as a |method|: >
3288 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003289<
3290 Return type: |String|
3291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003292
3293foldclosed({lnum}) *foldclosed()*
3294 The result is a Number. If the line {lnum} is in a closed
3295 fold, the result is the number of the first line in that fold.
3296 If the line {lnum} is not in a closed fold, -1 is returned.
3297 {lnum} is used like with |getline()|. Thus "." is the current
3298 line, "'m" mark m, etc.
3299
3300 Can also be used as a |method|: >
3301 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003302<
3303 Return type: |Number|
3304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003305
3306foldclosedend({lnum}) *foldclosedend()*
3307 The result is a Number. If the line {lnum} is in a closed
3308 fold, the result is the number of the last line in that fold.
3309 If the line {lnum} is not in a closed fold, -1 is returned.
3310 {lnum} is used like with |getline()|. Thus "." is the current
3311 line, "'m" mark m, etc.
3312
3313 Can also be used as a |method|: >
3314 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003315<
3316 Return type: |Number|
3317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003318
3319foldlevel({lnum}) *foldlevel()*
3320 The result is a Number, which is the foldlevel of line {lnum}
3321 in the current buffer. For nested folds the deepest level is
3322 returned. If there is no fold at line {lnum}, zero is
3323 returned. It doesn't matter if the folds are open or closed.
3324 When used while updating folds (from 'foldexpr') -1 is
3325 returned for lines where folds are still to be updated and the
3326 foldlevel is unknown. As a special case the level of the
3327 previous line is usually available.
3328 {lnum} is used like with |getline()|. Thus "." is the current
3329 line, "'m" mark m, etc.
3330
3331 Can also be used as a |method|: >
3332 GetLnum()->foldlevel()
3333<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003334 Return type: |Number|
3335
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003336 *foldtext()*
3337foldtext() Returns a String, to be displayed for a closed fold. This is
3338 the default function used for the 'foldtext' option and should
3339 only be called from evaluating 'foldtext'. It uses the
3340 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3341 The returned string looks like this: >
3342 +-- 45 lines: abcdef
3343< The number of leading dashes depends on the foldlevel. The
3344 "45" is the number of lines in the fold. "abcdef" is the text
3345 in the first non-blank line of the fold. Leading white space,
3346 "//" or "/*" and the text from the 'foldmarker' and
3347 'commentstring' options is removed.
3348 When used to draw the actual foldtext, the rest of the line
3349 will be filled with the fold char from the 'fillchars'
3350 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003351 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003352
3353 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003354 {not available when compiled without the |+folding| feature}
3355
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003357foldtextresult({lnum}) *foldtextresult()*
3358 Returns the text that is displayed for the closed fold at line
3359 {lnum}. Evaluates 'foldtext' in the appropriate context.
3360 When there is no closed fold at {lnum} an empty string is
3361 returned.
3362 {lnum} is used like with |getline()|. Thus "." is the current
3363 line, "'m" mark m, etc.
3364 Useful when exporting folded text, e.g., to HTML.
3365 {not available when compiled without the |+folding| feature}
3366
3367
3368 Can also be used as a |method|: >
3369 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003370<
3371 Return type: |String|
3372
Ernie Raele79e2072024-01-13 11:47:33 +01003373
3374foreach({expr1}, {expr2}) *foreach()*
3375 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3376 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003377 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003378 See |map()| and |filter()| to modify {expr1}.
3379
3380 {expr2} must be a |string| or |Funcref|.
3381
3382 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3383 of the current item. For a |Dictionary| |v:key| has the key
3384 of the current item and for a |List| |v:key| has the index of
3385 the current item. For a |Blob| |v:key| has the index of the
3386 current byte. For a |String| |v:key| has the index of the
3387 current character.
3388 Examples: >
3389 call foreach(mylist, 'used[v:val] = true')
3390< This records the items that are in the {expr1} list.
3391
3392 Note that {expr2} is the result of expression and is then used
3393 as a command. Often it is good to use a |literal-string| to
3394 avoid having to double backslashes.
3395
3396 If {expr2} is a |Funcref| it must take two arguments:
3397 1. the key or the index of the current item.
3398 2. the value of the current item.
3399 With a legacy script lambda you don't get an error if it only
3400 accepts one argument, but with a Vim9 lambda you get "E1106:
3401 One argument too many", the number of arguments must match.
3402 If the function returns a value, it is ignored.
3403
3404 Returns {expr1} in all cases.
3405 When an error is encountered while executing {expr2} no
3406 further items in {expr1} are processed.
3407 When {expr2} is a Funcref errors inside a function are ignored,
3408 unless it was defined with the "abort" flag.
3409
3410 Can also be used as a |method|: >
3411 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003412<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003413 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3414 depending on {expr1}
3415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003416 *foreground()*
3417foreground() Move the Vim window to the foreground. Useful when sent from
3418 a client to a Vim server. |remote_send()|
3419 On Win32 systems this might not work, the OS does not always
3420 allow a window to bring itself to the foreground. Use
3421 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003422
3423 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003424 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003425 Win32 console version}
3426
Bram Moolenaaraa534142022-09-15 21:46:02 +01003427fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003428 Get the full command name from a short abbreviated command
3429 name; see |20.2| for details on command abbreviations.
3430
3431 The string argument {name} may start with a `:` and can
3432 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003433 Returns an empty string if a command doesn't exist, if it's
3434 ambiguous (for user-defined commands) or cannot be shortened
3435 this way. |vim9-no-shorten|
3436
3437 Without the {vim9} argument uses the current script version.
3438 If {vim9} is present and FALSE then legacy script rules are
3439 used. When {vim9} is present and TRUE then Vim9 rules are
3440 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003441
3442 For example `fullcommand('s')`, `fullcommand('sub')`,
3443 `fullcommand(':%substitute')` all return "substitute".
3444
3445 Can also be used as a |method|: >
3446 GetName()->fullcommand()
3447<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003448 Return type: |String|
3449
3450
3451funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003452 Just like |function()|, but the returned Funcref will lookup
3453 the function by reference, not by name. This matters when the
3454 function {name} is redefined later.
3455
3456 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003457 It only works for an autoloaded function if it has already
3458 been loaded (to avoid mistakenly loading the autoload script
3459 when only intending to use the function name, use |function()|
3460 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003461 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003462
3463 Can also be used as a |method|: >
3464 GetFuncname()->funcref([arg])
3465<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003466 Return type: func(...): any or |Number| on error
3467
Dominique Pellee764d1b2023-03-12 21:20:59 +00003468 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003469function({name} [, {arglist}] [, {dict}])
3470 Return a |Funcref| variable that refers to function {name}.
3471 {name} can be the name of a user defined function or an
3472 internal function.
3473
3474 {name} can also be a Funcref or a partial. When it is a
3475 partial the dict stored in it will be used and the {dict}
3476 argument is not allowed. E.g.: >
3477 let FuncWithArg = function(dict.Func, [arg])
3478 let Broken = function(dict.Func, [arg], dict)
3479<
3480 When using the Funcref the function will be found by {name},
3481 also when it was redefined later. Use |funcref()| to keep the
3482 same function.
3483
3484 When {arglist} or {dict} is present this creates a partial.
3485 That means the argument list and/or the dictionary is stored in
3486 the Funcref and will be used when the Funcref is called.
3487
3488 The arguments are passed to the function in front of other
3489 arguments, but after any argument from |method|. Example: >
3490 func Callback(arg1, arg2, name)
3491 ...
3492 let Partial = function('Callback', ['one', 'two'])
3493 ...
3494 call Partial('name')
3495< Invokes the function as with: >
3496 call Callback('one', 'two', 'name')
3497
3498< With a |method|: >
3499 func Callback(one, two, three)
3500 ...
3501 let Partial = function('Callback', ['two'])
3502 ...
3503 eval 'one'->Partial('three')
3504< Invokes the function as with: >
3505 call Callback('one', 'two', 'three')
3506
3507< The function() call can be nested to add more arguments to the
3508 Funcref. The extra arguments are appended to the list of
3509 arguments. Example: >
3510 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003511 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003512 let Func = function('Callback', ['one'])
3513 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003514 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003515 call Func2('name')
3516< Invokes the function as with: >
3517 call Callback('one', 'two', 'name')
3518
3519< The Dictionary is only useful when calling a "dict" function.
3520 In that case the {dict} is passed in as "self". Example: >
3521 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003522 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003523 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003524 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003525 let context = {"name": "example"}
3526 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003527 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003528 call Func() " will echo: called for example
3529< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003530 arguments, these two are equivalent, if Callback() is defined
3531 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003532 let Func = function('Callback', context)
3533 let Func = context.Callback
3534
3535< The argument list and the Dictionary can be combined: >
3536 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003537 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 let context = {"name": "example"}
3539 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003540 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003541 call Func(500)
3542< Invokes the function as with: >
3543 call context.Callback('one', 500)
3544<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003545 Returns 0 on error.
3546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003547 Can also be used as a |method|: >
3548 GetFuncname()->function([arg])
3549
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003550<
3551 Return type: func(...): any or |Number| on error
3552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003553
3554garbagecollect([{atexit}]) *garbagecollect()*
3555 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3556 that have circular references.
3557
3558 There is hardly ever a need to invoke this function, as it is
3559 automatically done when Vim runs out of memory or is waiting
3560 for the user to press a key after 'updatetime'. Items without
3561 circular references are always freed when they become unused.
3562 This is useful if you have deleted a very big |List| and/or
3563 |Dictionary| with circular references in a script that runs
3564 for a long time.
3565
3566 When the optional {atexit} argument is one, garbage
3567 collection will also be done when exiting Vim, if it wasn't
3568 done before. This is useful when checking for memory leaks.
3569
3570 The garbage collection is not done immediately but only when
3571 it's safe to perform. This is when waiting for the user to
3572 type a character. To force garbage collection immediately use
3573 |test_garbagecollect_now()|.
3574
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003575 Return type: |String|
3576
3577
LemonBoy48b7d052024-07-09 18:24:59 +02003578get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003579 Get item {idx} from |List| {list}. When this item is not
3580 available return {default}. Return zero when {default} is
3581 omitted.
3582 Preferably used as a |method|: >
3583 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003584<
3585 Return type: any, depending on {list}
3586
LemonBoy48b7d052024-07-09 18:24:59 +02003587get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003588 Get byte {idx} from |Blob| {blob}. When this byte is not
3589 available return {default}. Return -1 when {default} is
3590 omitted.
3591 Preferably used as a |method|: >
3592 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003593<
3594 Return type: |Number|
3595
LemonBoy48b7d052024-07-09 18:24:59 +02003596get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597 Get item with key {key} from |Dictionary| {dict}. When this
3598 item is not available return {default}. Return zero when
3599 {default} is omitted. Useful example: >
3600 let val = get(g:, 'var_name', 'default')
3601< This gets the value of g:var_name if it exists, and uses
3602 'default' when it does not exist.
3603 Preferably used as a |method|: >
3604 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003605<
h-east84ac2122024-06-17 18:12:30 +02003606 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003607
LemonBoy48b7d052024-07-09 18:24:59 +02003608get({func}, {what}) *get()-func*
3609 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003610 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003611 "name" The function name
3612 "func" The function
3613 "dict" The dictionary
3614 "args" The list with arguments
3615 "arity" A dictionary with information about the number of
3616 arguments accepted by the function (minus the
3617 {arglist}) with the following fields:
3618 required the number of positional arguments
3619 optional the number of optional arguments,
3620 in addition to the required ones
3621 varargs |TRUE| if the function accepts a
3622 variable number of arguments |...|
3623
3624 Note: There is no error, if the {arglist} of
3625 the Funcref contains more arguments than the
3626 Funcref expects, it's not validated.
3627
Bram Moolenaar016188f2022-06-06 20:52:59 +01003628 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003630 Preferably used as a |method|: >
3631 myfunc->get(what)
3632<
LemonBoy48b7d052024-07-09 18:24:59 +02003633 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003635 *getbufinfo()*
3636getbufinfo([{buf}])
3637getbufinfo([{dict}])
3638 Get information about buffers as a List of Dictionaries.
3639
3640 Without an argument information about all the buffers is
3641 returned.
3642
3643 When the argument is a |Dictionary| only the buffers matching
3644 the specified criteria are returned. The following keys can
3645 be specified in {dict}:
3646 buflisted include only listed buffers.
3647 bufloaded include only loaded buffers.
3648 bufmodified include only modified buffers.
3649
3650 Otherwise, {buf} specifies a particular buffer to return
3651 information for. For the use of {buf}, see |bufname()|
3652 above. If the buffer is found the returned List has one item.
3653 Otherwise the result is an empty list.
3654
3655 Each returned List item is a dictionary with the following
3656 entries:
3657 bufnr Buffer number.
3658 changed TRUE if the buffer is modified.
3659 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003660 command TRUE if the buffer belongs to the
3661 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003662 hidden TRUE if the buffer is hidden.
3663 lastused Timestamp in seconds, like
3664 |localtime()|, when the buffer was
3665 last used.
3666 {only with the |+viminfo| feature}
3667 listed TRUE if the buffer is listed.
3668 lnum Line number used for the buffer when
3669 opened in the current window.
3670 Only valid if the buffer has been
3671 displayed in the window in the past.
3672 If you want the line number of the
3673 last known cursor position in a given
3674 window, use |line()|: >
3675 :echo line('.', {winid})
3676<
3677 linecount Number of lines in the buffer (only
3678 valid when loaded)
3679 loaded TRUE if the buffer is loaded.
3680 name Full path to the file in the buffer.
3681 signs List of signs placed in the buffer.
3682 Each list item is a dictionary with
3683 the following fields:
3684 id sign identifier
3685 lnum line number
3686 name sign name
3687 variables A reference to the dictionary with
3688 buffer-local variables.
3689 windows List of |window-ID|s that display this
3690 buffer
3691 popups List of popup |window-ID|s that
3692 display this buffer
3693
3694 Examples: >
3695 for buf in getbufinfo()
3696 echo buf.name
3697 endfor
3698 for buf in getbufinfo({'buflisted':1})
3699 if buf.changed
3700 ....
3701 endif
3702 endfor
3703<
3704 To get buffer-local options use: >
3705 getbufvar({bufnr}, '&option_name')
3706<
3707 Can also be used as a |method|: >
3708 GetBufnr()->getbufinfo()
3709<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003710 Return type: list<dict<any>>
3711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003712
3713 *getbufline()*
3714getbufline({buf}, {lnum} [, {end}])
3715 Return a |List| with the lines starting from {lnum} to {end}
3716 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003717 |List| with only the line {lnum} is returned. See
3718 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003719
3720 For the use of {buf}, see |bufname()| above.
3721
3722 For {lnum} and {end} "$" can be used for the last line of the
3723 buffer. Otherwise a number must be used.
3724
3725 When {lnum} is smaller than 1 or bigger than the number of
3726 lines in the buffer, an empty |List| is returned.
3727
3728 When {end} is greater than the number of lines in the buffer,
3729 it is treated as {end} is set to the number of lines in the
3730 buffer. When {end} is before {lnum} an empty |List| is
3731 returned.
3732
3733 This function works only for loaded buffers. For unloaded and
3734 non-existing buffers, an empty |List| is returned.
3735
3736 Example: >
3737 :let lines = getbufline(bufnr("myfile"), 1, "$")
3738
3739< Can also be used as a |method|: >
3740 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003742 Return type: list<string>
3743
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003744 *getbufoneline()*
3745getbufoneline({buf}, {lnum})
3746 Just like `getbufline()` but only get one line and return it
3747 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003748
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003749 Return type: |String|
3750
3751
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003752getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3753 The result is the value of option or local buffer variable
3754 {varname} in buffer {buf}. Note that the name without "b:"
3755 must be used.
3756 The {varname} argument is a string.
3757 When {varname} is empty returns a |Dictionary| with all the
3758 buffer-local variables.
3759 When {varname} is equal to "&" returns a |Dictionary| with all
3760 the buffer-local options.
3761 Otherwise, when {varname} starts with "&" returns the value of
3762 a buffer-local option.
3763 This also works for a global or buffer-local option, but it
3764 doesn't work for a global variable, window-local variable or
3765 window-local option.
3766 For the use of {buf}, see |bufname()| above.
3767 When the buffer or variable doesn't exist {def} or an empty
3768 string is returned, there is no error message.
3769 Examples: >
3770 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003771 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003772
3773< Can also be used as a |method|: >
3774 GetBufnr()->getbufvar(varname)
3775<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003776 Return type: any, depending on {varname}
3777
3778
Kota Kato66bb9ae2023-01-17 18:31:56 +00003779getcellwidths() *getcellwidths()*
3780 Returns a |List| of cell widths of character ranges overridden
3781 by |setcellwidths()|. The format is equal to the argument of
3782 |setcellwidths()|. If no character ranges have their cell
3783 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003784
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003785 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003786
3787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003788getchangelist([{buf}]) *getchangelist()*
3789 Returns the |changelist| for the buffer {buf}. For the use
3790 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3791 exist, an empty list is returned.
3792
3793 The returned list contains two entries: a list with the change
3794 locations and the current position in the list. Each
3795 entry in the change list is a dictionary with the following
3796 entries:
3797 col column number
3798 coladd column offset for 'virtualedit'
3799 lnum line number
3800 If buffer {buf} is the current buffer, then the current
3801 position refers to the position in the list. For other
3802 buffers, it is set to the length of the list.
3803
3804 Can also be used as a |method|: >
3805 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003806<
3807 Return type: list<any>
3808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003809
Doug Kearns9cd9e752024-04-07 17:42:17 +02003810getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003811 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003812 If {expr} is omitted, wait until a character is available.
3813 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003814 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003815 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003816 not consumed. Return zero if no character available.
3817 If you prefer always getting a string use |getcharstr()|.
3818
Doug Kearns9cd9e752024-04-07 17:42:17 +02003819 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003820 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003821 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003822 Otherwise a String is returned with the encoded character.
3823 For a special key it's a String with a sequence of bytes
3824 starting with 0x80 (decimal: 128). This is the same value as
3825 the String "\<Key>", e.g., "\<Left>". The returned value is
3826 also a String when a modifier (shift, control, alt) was used
3827 that is not included in the character.
3828
Doug Kearns9cd9e752024-04-07 17:42:17 +02003829 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003830 while Vim waits to see if this is the start of an escape
3831 sequence.
3832
Doug Kearns9cd9e752024-04-07 17:42:17 +02003833 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003834 one-byte character it is the character itself as a number.
3835 Use nr2char() to convert it to a String.
3836
3837 Use getcharmod() to obtain any additional modifiers.
3838
3839 When the user clicks a mouse button, the mouse event will be
3840 returned. The position can then be found in |v:mouse_col|,
3841 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3842 |getmousepos()| can also be used. Mouse move events will be
3843 ignored.
3844 This example positions the mouse as it would normally happen: >
3845 let c = getchar()
3846 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003847 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003848 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003849 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003850 endif
3851<
3852 When using bracketed paste only the first character is
3853 returned, the rest of the pasted text is dropped.
3854 |xterm-bracketed-paste|.
3855
3856 There is no prompt, you will somehow have to make clear to the
3857 user that a character has to be typed. The screen is not
3858 redrawn, e.g. when resizing the window. When using a popup
3859 window it should work better with a |popup-filter|.
3860
3861 There is no mapping for the character.
3862 Key codes are replaced, thus when the user presses the <Del>
3863 key you get the code for the <Del> key, not the raw character
3864 sequence. Examples: >
3865 getchar() == "\<Del>"
3866 getchar() == "\<S-Left>"
3867< This example redefines "f" to ignore case: >
3868 :nmap f :call FindChar()<CR>
3869 :function FindChar()
3870 : let c = nr2char(getchar())
3871 : while col('.') < col('$') - 1
3872 : normal l
3873 : if getline('.')[col('.') - 1] ==? c
3874 : break
3875 : endif
3876 : endwhile
3877 :endfunction
3878<
3879 You may also receive synthetic characters, such as
3880 |<CursorHold>|. Often you will want to ignore this and get
3881 another character: >
3882 :function GetKey()
3883 : let c = getchar()
3884 : while c == "\<CursorHold>"
3885 : let c = getchar()
3886 : endwhile
3887 : return c
3888 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003889<
3890 Return type: |Number| or |String|
3891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003892
3893getcharmod() *getcharmod()*
3894 The result is a Number which is the state of the modifiers for
3895 the last obtained character with getchar() or in another way.
3896 These values are added together:
3897 2 shift
3898 4 control
3899 8 alt (meta)
3900 16 meta (when it's different from ALT)
3901 32 mouse double click
3902 64 mouse triple click
3903 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003904 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003905 Only the modifiers that have not been included in the
3906 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003907 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003908
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003909 Return type: |Number|
3910
3911
3912getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003913 Get the position for String {expr}. Same as |getpos()| but the
3914 column number in the returned List is a character index
3915 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003916 If |getpos()| returns a very large column number, equal to
3917 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918 of the last character.
3919
3920 Example:
3921 With the cursor on '세' in line 5 with text "여보세요": >
3922 getcharpos('.') returns [0, 5, 3, 0]
3923 getpos('.') returns [0, 5, 7, 0]
3924<
3925 Can also be used as a |method|: >
3926 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003927<
3928 Return type: list<number>
3929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003930
3931getcharsearch() *getcharsearch()*
3932 Return the current character search information as a {dict}
3933 with the following entries:
3934
3935 char character previously used for a character
3936 search (|t|, |f|, |T|, or |F|); empty string
3937 if no character search has been performed
3938 forward direction of character search; 1 for forward,
3939 0 for backward
3940 until type of character search; 1 for a |t| or |T|
3941 character search, 0 for an |f| or |F|
3942 character search
3943
3944 This can be useful to always have |;| and |,| search
3945 forward/backward regardless of the direction of the previous
3946 character search: >
3947 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3948 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3949< Also see |setcharsearch()|.
3950
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003951 Return type: dict<any>
3952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003953
Doug Kearns9cd9e752024-04-07 17:42:17 +02003954getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955 Get a single character from the user or input stream as a
3956 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003957 If {expr} is omitted, wait until a character is available.
3958 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003959 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003960 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003961 available, it is not consumed. Return an empty string
3962 if no character is available.
3963 Otherwise this works like |getchar()|, except that a number
3964 result is converted to a string.
3965
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003966 Return type: |String|
3967
3968
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003969getcmdcompltype() *getcmdcompltype()*
3970 Return the type of the current command-line completion.
3971 Only works when the command line is being edited, thus
3972 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003973 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003974 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3975 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003976 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003977
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003978 Return type: |String|
3979
3980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003981getcmdline() *getcmdline()*
3982 Return the current command-line. Only works when the command
3983 line is being edited, thus requires use of |c_CTRL-\_e| or
3984 |c_CTRL-R_=|.
3985 Example: >
3986 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003987< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3988 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003989 Returns an empty string when entering a password or using
3990 |inputsecret()|.
3991
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003992 Return type: |String|
3993
3994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003995getcmdpos() *getcmdpos()*
3996 Return the position of the cursor in the command line as a
3997 byte count. The first column is 1.
3998 Only works when editing the command line, thus requires use of
3999 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4000 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004001 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
4002 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004003
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004004 Return type: |Number|
4005
4006
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004007getcmdscreenpos() *getcmdscreenpos()*
4008 Return the screen position of the cursor in the command line
4009 as a byte count. The first column is 1.
4010 Instead of |getcmdpos()|, it adds the prompt position.
4011 Only works when editing the command line, thus requires use of
4012 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4013 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004014 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4015 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004016
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004017 Return type: |Number|
4018
4019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004020getcmdtype() *getcmdtype()*
4021 Return the current command-line type. Possible return values
4022 are:
4023 : normal Ex command
4024 > debug mode command |debug-mode|
4025 / forward search command
4026 ? backward search command
4027 @ |input()| command
4028 - |:insert| or |:append| command
4029 = |i_CTRL-R_=|
4030 Only works when editing the command line, thus requires use of
4031 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4032 Returns an empty string otherwise.
4033 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4034
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004035 Return type: |String|
4036
4037
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038getcmdwintype() *getcmdwintype()*
4039 Return the current |command-line-window| type. Possible return
4040 values are the same as |getcmdtype()|. Returns an empty string
4041 when not in the command-line window.
4042
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004043 Return type: |String|
4044
4045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004046getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4047 Return a list of command-line completion matches. The String
4048 {type} argument specifies what for. The following completion
4049 types are supported:
4050
4051 arglist file names in argument list
4052 augroup autocmd groups
4053 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004054 behave |:behave| suboptions
4055 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004056 color color schemes
4057 command Ex command
4058 cmdline |cmdline-completion| result
4059 compiler compilers
4060 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004061 custom,{func} custom completion, defined via {func}
4062 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004063 diff_buffer |:diffget| and |:diffput| completion
4064 dir directory names
4065 environment environment variable names
4066 event autocommand events
4067 expression Vim expression
4068 file file and directory names
4069 file_in_path file and directory names in |'path'|
4070 filetype filetype names |'filetype'|
4071 function function name
4072 help help subjects
4073 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004074 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004075 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004076 locale locale names (as output of locale -a)
4077 mapclear buffer argument
4078 mapping mapping name
4079 menu menus
4080 messages |:messages| suboptions
4081 option options
4082 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004083 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004084 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004085 shellcmd Shell command
4086 sign |:sign| suboptions
4087 syntax syntax file names |'syntax'|
4088 syntime |:syntime| suboptions
4089 tag tags
4090 tag_listfiles tags, file names
4091 user user names
4092 var user variables
4093
4094 If {pat} is an empty string, then all the matches are
4095 returned. Otherwise only items matching {pat} are returned.
4096 See |wildcards| for the use of special characters in {pat}.
4097
4098 If the optional {filtered} flag is set to 1, then 'wildignore'
4099 is applied to filter the results. Otherwise all the matches
4100 are returned. The 'wildignorecase' option always applies.
4101
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004102 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4103 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004104 regular expression matching is used. Thus this function
4105 follows the user preference, what happens on the command line.
4106 If you do not want this you can make 'wildoptions' empty
4107 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004108
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004109 If {type} is "cmdline", then the |cmdline-completion| result is
4110 returned. For example, to complete the possible values after
4111 a ":call" command: >
4112 echo getcompletion('call ', 'cmdline')
4113<
4114 If there are no matches, an empty list is returned. An
4115 invalid value for {type} produces an error.
4116
4117 Can also be used as a |method|: >
4118 GetPattern()->getcompletion('color')
4119<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004120 Return type: list<string>
4121
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004122 *getcurpos()*
4123getcurpos([{winid}])
4124 Get the position of the cursor. This is like getpos('.'), but
4125 includes an extra "curswant" item in the list:
4126 [0, lnum, col, off, curswant] ~
4127 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004128 cursor vertically. After |$| command it will be a very large
4129 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004130 |getpos()|.
4131 The first "bufnum" item is always zero. The byte position of
4132 the cursor is returned in 'col'. To get the character
4133 position, use |getcursorcharpos()|.
4134
4135 The optional {winid} argument can specify the window. It can
4136 be the window number or the |window-ID|. The last known
4137 cursor position is returned, this may be invalid for the
4138 current value of the buffer if it is not the current window.
4139 If {winid} is invalid a list with zeroes is returned.
4140
4141 This can be used to save and restore the cursor position: >
4142 let save_cursor = getcurpos()
4143 MoveTheCursorAround
4144 call setpos('.', save_cursor)
4145< Note that this only works within the window. See
4146 |winrestview()| for restoring more state.
4147
4148 Can also be used as a |method|: >
4149 GetWinid()->getcurpos()
4150<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004151 Return type: list<number>
4152
4153
4154getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004155 Same as |getcurpos()| but the column number in the returned
4156 List is a character index instead of a byte index.
4157
4158 Example:
4159 With the cursor on '보' in line 3 with text "여보세요": >
4160 getcursorcharpos() returns [0, 3, 2, 0, 3]
4161 getcurpos() returns [0, 3, 4, 0, 3]
4162<
4163 Can also be used as a |method|: >
4164 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004165<
4166 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004167
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004168
4169getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004170 The result is a String, which is the name of the current
4171 working directory. 'autochdir' is ignored.
4172
4173 With {winnr} return the local current directory of this window
4174 in the current tab page. {winnr} can be the window number or
4175 the |window-ID|.
4176 If {winnr} is -1 return the name of the global working
4177 directory. See also |haslocaldir()|.
4178
4179 With {winnr} and {tabnr} return the local current directory of
4180 the window in the specified tab page. If {winnr} is -1 return
4181 the working directory of the tabpage.
4182 If {winnr} is zero use the current window, if {tabnr} is zero
4183 use the current tabpage.
4184 Without any arguments, return the actual working directory of
4185 the current window.
4186 Return an empty string if the arguments are invalid.
4187
4188 Examples: >
4189 " Get the working directory of the current window
4190 :echo getcwd()
4191 :echo getcwd(0)
4192 :echo getcwd(0, 0)
4193 " Get the working directory of window 3 in tabpage 2
4194 :echo getcwd(3, 2)
4195 " Get the global working directory
4196 :echo getcwd(-1)
4197 " Get the working directory of tabpage 3
4198 :echo getcwd(-1, 3)
4199 " Get the working directory of current tabpage
4200 :echo getcwd(-1, 0)
4201
4202< Can also be used as a |method|: >
4203 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004204<
4205 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004206
4207getenv({name}) *getenv()*
4208 Return the value of environment variable {name}. The {name}
4209 argument is a string, without a leading '$'. Example: >
4210 myHome = getenv('HOME')
4211
4212< When the variable does not exist |v:null| is returned. That
4213 is different from a variable set to an empty string, although
4214 some systems interpret the empty value as the variable being
4215 deleted. See also |expr-env|.
4216
4217 Can also be used as a |method|: >
4218 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004219<
4220 Return type: |String| or |Number|
4221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004222
4223getfontname([{name}]) *getfontname()*
4224 Without an argument returns the name of the normal font being
4225 used. Like what is used for the Normal highlight group
4226 |hl-Normal|.
4227 With an argument a check is done whether String {name} is a
4228 valid font name. If not then an empty string is returned.
4229 Otherwise the actual font name is returned, or {name} if the
4230 GUI does not support obtaining the real name.
4231 Only works when the GUI is running, thus not in your vimrc or
4232 gvimrc file. Use the |GUIEnter| autocommand to use this
4233 function just after the GUI has started.
4234 Note that the GTK GUI accepts any font name, thus checking for
4235 a valid name does not work.
4236
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004237 Return type: |String|
4238
4239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004240getfperm({fname}) *getfperm()*
4241 The result is a String, which is the read, write, and execute
4242 permissions of the given file {fname}.
4243 If {fname} does not exist or its directory cannot be read, an
4244 empty string is returned.
4245 The result is of the form "rwxrwxrwx", where each group of
4246 "rwx" flags represent, in turn, the permissions of the owner
4247 of the file, the group the file belongs to, and other users.
4248 If a user does not have a given permission the flag for this
4249 is replaced with the string "-". Examples: >
4250 :echo getfperm("/etc/passwd")
4251 :echo getfperm(expand("~/.vimrc"))
4252< This will hopefully (from a security point of view) display
4253 the string "rw-r--r--" or even "rw-------".
4254
4255 Can also be used as a |method|: >
4256 GetFilename()->getfperm()
4257<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004258 Return type: |String|
4259
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004260 For setting permissions use |setfperm()|.
4261
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004263getfsize({fname}) *getfsize()*
4264 The result is a Number, which is the size in bytes of the
4265 given file {fname}.
4266 If {fname} is a directory, 0 is returned.
4267 If the file {fname} can't be found, -1 is returned.
4268 If the size of {fname} is too big to fit in a Number then -2
4269 is returned.
4270
4271 Can also be used as a |method|: >
4272 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004273<
4274 Return type: |Number|
4275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004276
4277getftime({fname}) *getftime()*
4278 The result is a Number, which is the last modification time of
4279 the given file {fname}. The value is measured as seconds
4280 since 1st Jan 1970, and may be passed to strftime(). See also
4281 |localtime()| and |strftime()|.
4282 If the file {fname} can't be found -1 is returned.
4283
4284 Can also be used as a |method|: >
4285 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004286<
4287 Return type: |Number|
4288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004289
4290getftype({fname}) *getftype()*
4291 The result is a String, which is a description of the kind of
4292 file of the given file {fname}.
4293 If {fname} does not exist an empty string is returned.
4294 Here is a table over different kinds of files and their
4295 results:
4296 Normal file "file"
4297 Directory "dir"
4298 Symbolic link "link"
4299 Block device "bdev"
4300 Character device "cdev"
4301 Socket "socket"
4302 FIFO "fifo"
4303 All other "other"
4304 Example: >
4305 getftype("/home")
4306< Note that a type such as "link" will only be returned on
4307 systems that support it. On some systems only "dir" and
4308 "file" are returned. On MS-Windows a symbolic link to a
4309 directory returns "dir" instead of "link".
4310
4311 Can also be used as a |method|: >
4312 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004313<
4314 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004315
4316getimstatus() *getimstatus()*
4317 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004318 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004319 See 'imstatusfunc'.
4320
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004321 Return type: |Number|
4322
4323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004324getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4325 Returns the |jumplist| for the specified window.
4326
4327 Without arguments use the current window.
4328 With {winnr} only use this window in the current tab page.
4329 {winnr} can also be a |window-ID|.
4330 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004331 page. If {winnr} or {tabnr} is invalid, an empty list is
4332 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004333
4334 The returned list contains two entries: a list with the jump
4335 locations and the last used jump position number in the list.
4336 Each entry in the jump location list is a dictionary with
4337 the following entries:
4338 bufnr buffer number
4339 col column number
4340 coladd column offset for 'virtualedit'
4341 filename filename if available
4342 lnum line number
4343
4344 Can also be used as a |method|: >
4345 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004346<
4347 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004349 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004350getline({lnum} [, {end}])
4351 Without {end} the result is a String, which is line {lnum}
4352 from the current buffer. Example: >
4353 getline(1)
4354< When {lnum} is a String that doesn't start with a
4355 digit, |line()| is called to translate the String into a Number.
4356 To get the line under the cursor: >
4357 getline(".")
4358< When {lnum} is a number smaller than 1 or bigger than the
4359 number of lines in the buffer, an empty string is returned.
4360
4361 When {end} is given the result is a |List| where each item is
4362 a line from the current buffer in the range {lnum} to {end},
4363 including line {end}.
4364 {end} is used in the same way as {lnum}.
4365 Non-existing lines are silently omitted.
4366 When {end} is before {lnum} an empty |List| is returned.
4367 Example: >
4368 :let start = line('.')
4369 :let end = search("^$") - 1
4370 :let lines = getline(start, end)
4371
4372< Can also be used as a |method|: >
4373 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004374<
4375 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004376
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004377 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004378 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004379
4380getloclist({nr} [, {what}]) *getloclist()*
4381 Returns a |List| with all the entries in the location list for
4382 window {nr}. {nr} can be the window number or the |window-ID|.
4383 When {nr} is zero the current window is used.
4384
4385 For a location list window, the displayed location list is
4386 returned. For an invalid window number {nr}, an empty list is
4387 returned. Otherwise, same as |getqflist()|.
4388
4389 If the optional {what} dictionary argument is supplied, then
4390 returns the items listed in {what} as a dictionary. Refer to
4391 |getqflist()| for the supported items in {what}.
4392
4393 In addition to the items supported by |getqflist()| in {what},
4394 the following item is supported by |getloclist()|:
4395
4396 filewinid id of the window used to display files
4397 from the location list. This field is
4398 applicable only when called from a
4399 location list window. See
4400 |location-list-file-window| for more
4401 details.
4402
4403 Returns a |Dictionary| with default values if there is no
4404 location list for the window {nr}.
4405 Returns an empty Dictionary if window {nr} does not exist.
4406
4407 Examples (See also |getqflist-examples|): >
4408 :echo getloclist(3, {'all': 0})
4409 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004410<
4411 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004412
4413
4414getmarklist([{buf}]) *getmarklist()*
4415 Without the {buf} argument returns a |List| with information
4416 about all the global marks. |mark|
4417
4418 If the optional {buf} argument is specified, returns the
4419 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004420 see |bufname()|. If {buf} is invalid, an empty list is
4421 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004422
4423 Each item in the returned List is a |Dict| with the following:
4424 mark name of the mark prefixed by "'"
4425 pos a |List| with the position of the mark:
4426 [bufnum, lnum, col, off]
4427 Refer to |getpos()| for more information.
4428 file file name
4429
4430 Refer to |getpos()| for getting information about a specific
4431 mark.
4432
4433 Can also be used as a |method|: >
4434 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004435<
4436 Return type: list<dict<any>> or list<any>
4437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004438
4439getmatches([{win}]) *getmatches()*
4440 Returns a |List| with all matches previously defined for the
4441 current window by |matchadd()| and the |:match| commands.
4442 |getmatches()| is useful in combination with |setmatches()|,
4443 as |setmatches()| can restore a list of matches saved by
4444 |getmatches()|.
4445 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004446 window ID instead of the current window. If {win} is invalid,
4447 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004448 Example: >
4449 :echo getmatches()
4450< [{'group': 'MyGroup1', 'pattern': 'TODO',
4451 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4452 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4453 :let m = getmatches()
4454 :call clearmatches()
4455 :echo getmatches()
4456< [] >
4457 :call setmatches(m)
4458 :echo getmatches()
4459< [{'group': 'MyGroup1', 'pattern': 'TODO',
4460 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4461 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4462 :unlet m
4463<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004464 Return type: list<dict<any>> or list<any>
4465
4466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004467getmousepos() *getmousepos()*
4468 Returns a |Dictionary| with the last known position of the
4469 mouse. This can be used in a mapping for a mouse click or in
4470 a filter of a popup window. The items are:
4471 screenrow screen row
4472 screencol screen column
4473 winid Window ID of the click
4474 winrow row inside "winid"
4475 wincol column inside "winid"
4476 line text line inside "winid"
4477 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004478 coladd offset (in screen columns) from the
4479 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004480 All numbers are 1-based.
4481
4482 If not over a window, e.g. when in the command line, then only
4483 "screenrow" and "screencol" are valid, the others are zero.
4484
4485 When on the status line below a window or the vertical
4486 separator right of a window, the "line" and "column" values
4487 are zero.
4488
4489 When the position is after the text then "column" is the
4490 length of the text in bytes plus one.
4491
4492 If the mouse is over a popup window then that window is used.
4493
4494 When using |getchar()| the Vim variables |v:mouse_lnum|,
4495 |v:mouse_col| and |v:mouse_winid| also provide these values.
4496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004497 Return type: dict<number>
4498
4499
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004500getmouseshape() *getmouseshape()*
4501 Returns the name of the currently showing mouse pointer.
4502 When the |+mouseshape| feature is not supported or the shape
4503 is unknown an empty string is returned.
4504 This function is mainly intended for testing.
4505
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004506 Return type: |String|
4507
4508
4509getpid() *getpid()*
4510 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004511 On Unix and MS-Windows this is a unique number, until Vim
4512 exits.
4513
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004514 Return type: |Number|
4515
4516
4517getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004518 Get the position for String {expr}.
4519 The accepted values for {expr} are: *E1209*
4520 . The cursor position.
4521 $ The last line in the current buffer.
4522 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004523 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004524 w0 First line visible in current window (one if the
4525 display isn't updated, e.g. in silent Ex mode).
4526 w$ Last line visible in current window (this is one
4527 less than "w0" if no lines are visible).
4528 v When not in Visual mode, returns the cursor
4529 position. In Visual mode, returns the other end
4530 of the Visual area. A good way to think about
4531 this is that in Visual mode "v" and "." complement
4532 each other. While "." refers to the cursor
4533 position, "v" refers to where |v_o| would move the
4534 cursor. As a result, you can use "v" and "."
4535 together to work on all of a selection in
4536 characterwise Visual mode. If the cursor is at
4537 the end of a characterwise Visual area, "v" refers
4538 to the start of the same Visual area. And if the
4539 cursor is at the start of a characterwise Visual
4540 area, "v" refers to the end of the same Visual
4541 area. "v" differs from |'<| and |'>| in that it's
4542 updated right away.
4543 Note that a mark in another file can be used. The line number
4544 then applies to another buffer.
4545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004546 The result is a |List| with four numbers:
4547 [bufnum, lnum, col, off]
4548 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4549 is the buffer number of the mark.
4550 "lnum" and "col" are the position in the buffer. The first
4551 column is 1.
4552 The "off" number is zero, unless 'virtualedit' is used. Then
4553 it is the offset in screen columns from the start of the
4554 character. E.g., a position within a <Tab> or after the last
4555 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004556
4557 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004558 The column number in the returned List is the byte position
4559 within the line. To get the character position in the line,
4560 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004561
4562 Note that for '< and '> Visual mode matters: when it is "V"
4563 (visual line mode) the column of '< is zero and the column of
4564 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004565 A very large column number equal to |v:maxcol| can be returned,
4566 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004567 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004569 This can be used to save and restore the position of a mark: >
4570 let save_a_mark = getpos("'a")
4571 ...
4572 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004573<
4574 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004575
4576 Can also be used as a |method|: >
4577 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004578<
4579 Return type: list<number>
4580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004581
4582getqflist([{what}]) *getqflist()*
4583 Returns a |List| with all the current quickfix errors. Each
4584 list item is a dictionary with these entries:
4585 bufnr number of buffer that has the file name, use
4586 bufname() to get the name
4587 module module name
4588 lnum line number in the buffer (first line is 1)
4589 end_lnum
4590 end of line number if the item is multiline
4591 col column number (first column is 1)
4592 end_col end of column number if the item has range
4593 vcol |TRUE|: "col" is visual column
4594 |FALSE|: "col" is byte index
4595 nr error number
h-east84ac2122024-06-17 18:12:30 +02004596 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004597 text description of the error
4598 type type of the error, 'E', '1', etc.
4599 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004600 user_data
4601 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004602 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004603
4604 When there is no error list or it's empty, an empty list is
4605 returned. Quickfix list entries with a non-existing buffer
4606 number are returned with "bufnr" set to zero (Note: some
4607 functions accept buffer number zero for the alternate buffer,
4608 you may need to explicitly check for zero).
4609
4610 Useful application: Find pattern matches in multiple files and
4611 do something with them: >
4612 :vimgrep /theword/jg *.c
4613 :for d in getqflist()
4614 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4615 :endfor
4616<
4617 If the optional {what} dictionary argument is supplied, then
4618 returns only the items listed in {what} as a dictionary. The
4619 following string items are supported in {what}:
4620 changedtick get the total number of changes made
4621 to the list |quickfix-changedtick|
4622 context get the |quickfix-context|
4623 efm errorformat to use when parsing "lines". If
4624 not present, then the 'errorformat' option
4625 value is used.
4626 id get information for the quickfix list with
4627 |quickfix-ID|; zero means the id for the
4628 current list or the list specified by "nr"
4629 idx get information for the quickfix entry at this
4630 index in the list specified by 'id' or 'nr'.
4631 If set to zero, then uses the current entry.
4632 See |quickfix-index|
4633 items quickfix list entries
4634 lines parse a list of lines using 'efm' and return
4635 the resulting entries. Only a |List| type is
4636 accepted. The current quickfix list is not
4637 modified. See |quickfix-parse|.
4638 nr get information for this quickfix list; zero
4639 means the current quickfix list and "$" means
4640 the last quickfix list
4641 qfbufnr number of the buffer displayed in the quickfix
4642 window. Returns 0 if the quickfix buffer is
4643 not present. See |quickfix-buffer|.
4644 size number of entries in the quickfix list
4645 title get the list title |quickfix-title|
4646 winid get the quickfix |window-ID|
4647 all all of the above quickfix properties
4648 Non-string items in {what} are ignored. To get the value of a
4649 particular item, set it to zero.
4650 If "nr" is not present then the current quickfix list is used.
4651 If both "nr" and a non-zero "id" are specified, then the list
4652 specified by "id" is used.
4653 To get the number of lists in the quickfix stack, set "nr" to
4654 "$" in {what}. The "nr" value in the returned dictionary
4655 contains the quickfix stack size.
4656 When "lines" is specified, all the other items except "efm"
4657 are ignored. The returned dictionary contains the entry
4658 "items" with the list of entries.
4659
4660 The returned dictionary contains the following entries:
4661 changedtick total number of changes made to the
4662 list |quickfix-changedtick|
4663 context quickfix list context. See |quickfix-context|
4664 If not present, set to "".
4665 id quickfix list ID |quickfix-ID|. If not
4666 present, set to 0.
4667 idx index of the quickfix entry in the list. If not
4668 present, set to 0.
4669 items quickfix list entries. If not present, set to
4670 an empty list.
4671 nr quickfix list number. If not present, set to 0
4672 qfbufnr number of the buffer displayed in the quickfix
4673 window. If not present, set to 0.
4674 size number of entries in the quickfix list. If not
4675 present, set to 0.
4676 title quickfix list title text. If not present, set
4677 to "".
4678 winid quickfix |window-ID|. If not present, set to 0
4679
4680 Examples (See also |getqflist-examples|): >
4681 :echo getqflist({'all': 1})
4682 :echo getqflist({'nr': 2, 'title': 1})
4683 :echo getqflist({'lines' : ["F1:10:L10"]})
4684<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004685 Return type: list<dict<any>> or list<any>
4686
4687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004688getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4689 The result is a String, which is the contents of register
4690 {regname}. Example: >
4691 :let cliptext = getreg('*')
4692< When register {regname} was not set the result is an empty
4693 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004694 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004695
4696 getreg('=') returns the last evaluated value of the expression
4697 register. (For use in maps.)
4698 getreg('=', 1) returns the expression itself, so that it can
4699 be restored with |setreg()|. For other registers the extra
4700 argument is ignored, thus you can always give it.
4701
4702 If {list} is present and |TRUE|, the result type is changed
4703 to |List|. Each list item is one text line. Use it if you care
4704 about zero bytes possibly present inside register: without
4705 third argument both NLs and zero bytes are represented as NLs
4706 (see |NL-used-for-Nul|).
4707 When the register was not set an empty list is returned.
4708
4709 If {regname} is "", the unnamed register '"' is used.
4710 If {regname} is not specified, |v:register| is used.
4711 In |Vim9-script| {regname} must be one character.
4712
4713 Can also be used as a |method|: >
4714 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004715<
4716 Return type: |String|
4717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004718
4719getreginfo([{regname}]) *getreginfo()*
4720 Returns detailed information about register {regname} as a
4721 Dictionary with the following entries:
4722 regcontents List of lines contained in register
4723 {regname}, like
4724 |getreg|({regname}, 1, 1).
4725 regtype the type of register {regname}, as in
4726 |getregtype()|.
4727 isunnamed Boolean flag, v:true if this register
4728 is currently pointed to by the unnamed
4729 register.
4730 points_to for the unnamed register, gives the
4731 single letter name of the register
4732 currently pointed to (see |quotequote|).
4733 For example, after deleting a line
4734 with `dd`, this field will be "1",
4735 which is the register that got the
4736 deleted text.
4737
4738 The {regname} argument is a string. If {regname} is invalid
4739 or not set, an empty Dictionary will be returned.
4740 If {regname} is "" or "@", the unnamed register '"' is used.
4741 If {regname} is not specified, |v:register| is used.
4742 The returned Dictionary can be passed to |setreg()|.
4743 In |Vim9-script| {regname} must be one character.
4744
4745 Can also be used as a |method|: >
4746 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004747<
4748 Return type: dict<any>
4749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004750
Shougo Matsushita19b71882024-02-28 22:48:12 +01004751getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004752 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004753 buffer.
4754
4755 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004756 See |getpos()| for the format of the list. It's possible
4757 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004758 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004759
4760 The optional argument {opts} is a Dict and supports the
4761 following items:
4762
zeertzjqafc22952024-05-24 19:07:12 +02004763 type Specify the region's selection type.
4764 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004765 except that the width can be omitted
4766 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004767 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004768
zeertzjq87410ab2024-03-02 06:00:23 +08004769 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004770 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004771 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004772
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004773 You can get the last selection type by |visualmode()|.
4774 If Visual mode is active, use |mode()| to get the Visual mode
4775 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004776 This function is useful to get text starting and ending in
4777 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004778
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004779 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004780 Note that:
4781 - Order of {pos1} and {pos2} doesn't matter, it will always
4782 return content from the upper left position to the lower
4783 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004784 - If 'virtualedit' is enabled and the region is past the end
4785 of the lines, resulting lines are padded with spaces.
4786 - If the region is blockwise and it starts or ends in the
4787 middle of a multi-cell character, it is not included but
4788 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004789 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004790 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004791 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004792 - It is evaluated in current window context, which makes a
4793 difference if the buffer is displayed in a window with
4794 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004795
4796 Examples: >
4797 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004798 \ <Cmd>echow getregion(
4799 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004800<
4801 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004802 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004803
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004804<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004805getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4806 Same as |getregion()|, but returns a list of positions
4807 describing the buffer text segments bound by {pos1} and
4808 {pos2}.
4809 The segments are a pair of positions for every line: >
4810 [[{start_pos}, {end_pos}], ...]
4811<
4812 The position is a |List| with four numbers:
4813 [bufnum, lnum, col, off]
4814 "bufnum" is the buffer number.
4815 "lnum" and "col" are the position in the buffer. The first
4816 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004817 If the "off" number of a starting position is non-zero, it is
4818 the offset in screen columns from the start of the character.
4819 E.g., a position within a <Tab> or after the last character.
4820 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004821 the offset of the character's first cell not included in the
4822 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004823
zeertzjq2b09de92024-05-24 07:48:51 +02004824 Apart from the options supported by |getregion()|, {opts} also
4825 supports the following:
4826
4827 eol If |TRUE|, indicate positions beyond
4828 the end of a line with "col" values
4829 one more than the length of the line.
4830 If |FALSE|, positions are limited
4831 within their lines, and if a line is
4832 empty or the selection is entirely
4833 beyond the end of a line, a "col"
4834 value of 0 is used for both positions.
4835 (default: |FALSE|)
4836
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004837 Can also be used as a |method|: >
4838 getpos('.')->getregionpos(getpos("'a"))
4839<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004840 Return type: list<string>
4841
4842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004843getregtype([{regname}]) *getregtype()*
4844 The result is a String, which is type of register {regname}.
4845 The value will be one of:
4846 "v" for |characterwise| text
4847 "V" for |linewise| text
4848 "<CTRL-V>{width}" for |blockwise-visual| text
4849 "" for an empty or unknown register
4850 <CTRL-V> is one character with value 0x16.
4851 The {regname} argument is a string. If {regname} is "", the
4852 unnamed register '"' is used. If {regname} is not specified,
4853 |v:register| is used.
4854 In |Vim9-script| {regname} must be one character.
4855
4856 Can also be used as a |method|: >
4857 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004858<
4859 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004860
Bram Moolenaar71badf92023-04-22 22:40:14 +01004861getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004862 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004863 scripts in the order they were sourced, like what
4864 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004865
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004866 The optional Dict argument {opts} supports the following
4867 optional items:
4868 name Script name match pattern. If specified,
4869 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004870 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004871 "name" are returned.
4872 sid Script ID |<SID>|. If specified, only
4873 information about the script with ID "sid" is
4874 returned and "name" is ignored.
4875
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004876 Each item in the returned List is a |Dict| with the following
4877 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004878 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004879 `import autoload` but was not actually sourced
4880 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004881 functions List of script-local function names defined in
4882 the script. Present only when a particular
4883 script is specified using the "sid" item in
4884 {opts}.
4885 name Vim script file name.
4886 sid Script ID |<SID>|.
4887 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004888 this script name links to, if any, otherwise
4889 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004890 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004891 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004892 specified using the "sid" item in {opts}.
4893 Note that this is a copy, the value of
4894 script-local variables cannot be changed using
4895 this dictionary.
h_east59858792023-10-25 22:47:05 +09004896 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004897
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004898 Examples: >
4899 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004900 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004901<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004902 Return type: list<dict<any>>
4903
4904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004905gettabinfo([{tabnr}]) *gettabinfo()*
4906 If {tabnr} is not specified, then information about all the
4907 tab pages is returned as a |List|. Each List item is a
4908 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4909 number and information about that one is returned. If the tab
4910 page does not exist an empty List is returned.
4911
4912 Each List item is a |Dictionary| with the following entries:
4913 tabnr tab page number.
4914 variables a reference to the dictionary with
4915 tabpage-local variables
4916 windows List of |window-ID|s in the tab page.
4917
4918 Can also be used as a |method|: >
4919 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004920<
4921 Return type: list<dict<any>>
4922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004923
4924gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4925 Get the value of a tab-local variable {varname} in tab page
4926 {tabnr}. |t:var|
4927 Tabs are numbered starting with one.
4928 The {varname} argument is a string. When {varname} is empty a
4929 dictionary with all tab-local variables is returned.
4930 Note that the name without "t:" must be used.
4931 When the tab or variable doesn't exist {def} or an empty
4932 string is returned, there is no error message.
4933
4934 Can also be used as a |method|: >
4935 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004936<
4937 Return type: any, depending on {varname}
4938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004939
4940gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4941 Get the value of window-local variable {varname} in window
4942 {winnr} in tab page {tabnr}.
4943 The {varname} argument is a string. When {varname} is empty a
4944 dictionary with all window-local variables is returned.
4945 When {varname} is equal to "&" get the values of all
4946 window-local options in a |Dictionary|.
4947 Otherwise, when {varname} starts with "&" get the value of a
4948 window-local option.
4949 Note that {varname} must be the name without "w:".
4950 Tabs are numbered starting with one. For the current tabpage
4951 use |getwinvar()|.
4952 {winnr} can be the window number or the |window-ID|.
4953 When {winnr} is zero the current window is used.
4954 This also works for a global option, buffer-local option and
4955 window-local option, but it doesn't work for a global variable
4956 or buffer-local variable.
4957 When the tab, window or variable doesn't exist {def} or an
4958 empty string is returned, there is no error message.
4959 Examples: >
4960 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004961 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004962<
4963 To obtain all window-local variables use: >
4964 gettabwinvar({tabnr}, {winnr}, '&')
4965
4966< Can also be used as a |method|: >
4967 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004968<
4969 Return type: any, depending on {varname}
4970
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004971
4972gettagstack([{winnr}]) *gettagstack()*
4973 The result is a Dict, which is the tag stack of window {winnr}.
4974 {winnr} can be the window number or the |window-ID|.
4975 When {winnr} is not specified, the current window is used.
4976 When window {winnr} doesn't exist, an empty Dict is returned.
4977
4978 The returned dictionary contains the following entries:
4979 curidx Current index in the stack. When at
4980 top of the stack, set to (length + 1).
4981 Index of bottom of the stack is 1.
4982 items List of items in the stack. Each item
4983 is a dictionary containing the
4984 entries described below.
4985 length Number of entries in the stack.
4986
4987 Each item in the stack is a dictionary with the following
4988 entries:
4989 bufnr buffer number of the current jump
4990 from cursor position before the tag jump.
4991 See |getpos()| for the format of the
4992 returned list.
4993 matchnr current matching tag number. Used when
4994 multiple matching tags are found for a
4995 name.
4996 tagname name of the tag
4997
4998 See |tagstack| for more information about the tag stack.
4999
5000 Can also be used as a |method|: >
5001 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005002<
5003 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005004
5005
Christ van Willegence0ef912024-06-20 23:41:59 +02005006gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005007 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005008 This is intended for use in Vim scripts. When generating
5009 message translations the {text} is extracted by `xgettext`,
5010 the translator can add translated messages into the .po file
5011 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005012 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005013 `xgettext` does not support single quoted escaped text.
5014
Christ van Willegence0ef912024-06-20 23:41:59 +02005015 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005016 for that specific package. This is mainly required for
5017 third-party Vim scripts. You need to specify a path to the
5018 translations with the |bindtextdomain()| function before
5019 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005020
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005021 Return type: |String|
5022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005023
5024getwininfo([{winid}]) *getwininfo()*
5025 Returns information about windows as a |List| with Dictionaries.
5026
5027 If {winid} is given Information about the window with that ID
5028 is returned, as a |List| with one item. If the window does not
5029 exist the result is an empty list.
5030
5031 Without {winid} information about all the windows in all the
5032 tab pages is returned.
5033
5034 Each List item is a |Dictionary| with the following entries:
5035 botline last complete displayed buffer line
5036 bufnr number of buffer in the window
5037 height window height (excluding winbar)
5038 loclist 1 if showing a location list
5039 {only with the +quickfix feature}
5040 quickfix 1 if quickfix or location list window
5041 {only with the +quickfix feature}
5042 terminal 1 if a terminal window
5043 {only with the +terminal feature}
5044 tabnr tab page number
5045 topline first displayed buffer line
5046 variables a reference to the dictionary with
5047 window-local variables
5048 width window width
5049 winbar 1 if the window has a toolbar, 0
5050 otherwise
5051 wincol leftmost screen column of the window;
5052 "col" from |win_screenpos()|
5053 textoff number of columns occupied by any
5054 'foldcolumn', 'signcolumn' and line
5055 number in front of the text
5056 winid |window-ID|
5057 winnr window number
5058 winrow topmost screen line of the window;
5059 "row" from |win_screenpos()|
5060
5061 Can also be used as a |method|: >
5062 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005063<
5064 Return type: list<dict<any>>
5065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005066
5067getwinpos([{timeout}]) *getwinpos()*
5068 The result is a |List| with two numbers, the result of
5069 |getwinposx()| and |getwinposy()| combined:
5070 [x-pos, y-pos]
5071 {timeout} can be used to specify how long to wait in msec for
5072 a response from the terminal. When omitted 100 msec is used.
5073 Use a longer time for a remote terminal.
5074 When using a value less than 10 and no response is received
5075 within that time, a previously reported position is returned,
5076 if available. This can be used to poll for the position and
5077 do some work in the meantime: >
5078 while 1
5079 let res = getwinpos(1)
5080 if res[0] >= 0
5081 break
5082 endif
5083 " Do some work here
5084 endwhile
5085<
5086
5087 Can also be used as a |method|: >
5088 GetTimeout()->getwinpos()
5089<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005090 Return type: list<number>
5091
5092
5093getwinposx() *getwinposx()*
5094 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005095 the left hand side of the GUI Vim window. Also works for an
5096 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005097 The result will be -1 if the information is not available
5098 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005099 The value can be used with `:winpos`.
5100
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005101 Return type: |Number|
5102
5103
5104getwinposy() *getwinposy()*
5105 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005106 the top of the GUI Vim window. Also works for an xterm (uses
5107 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005108 The result will be -1 if the information is not available
5109 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005110 The value can be used with `:winpos`.
5111
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005112 Return type: |Number|
5113
5114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005115getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5116 Like |gettabwinvar()| for the current tabpage.
5117 Examples: >
5118 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005119 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005120
5121< Can also be used as a |method|: >
5122 GetWinnr()->getwinvar(varname)
5123<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005124 Return type: any, depending on {varname}
5125
5126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005127glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5128 Expand the file wildcards in {expr}. See |wildcards| for the
5129 use of special characters.
5130
5131 Unless the optional {nosuf} argument is given and is |TRUE|,
5132 the 'suffixes' and 'wildignore' options apply: Names matching
5133 one of the patterns in 'wildignore' will be skipped and
5134 'suffixes' affect the ordering of matches.
5135 'wildignorecase' always applies.
5136
5137 When {list} is present and it is |TRUE| the result is a |List|
5138 with all matching files. The advantage of using a List is,
5139 you also get filenames containing newlines correctly.
5140 Otherwise the result is a String and when there are several
5141 matches, they are separated by <NL> characters.
5142
5143 If the expansion fails, the result is an empty String or List.
5144
5145 You can also use |readdir()| if you need to do complicated
5146 things, such as limiting the number of matches.
5147
5148 A name for a non-existing file is not included. A symbolic
5149 link is only included if it points to an existing file.
5150 However, when the {alllinks} argument is present and it is
5151 |TRUE| then all symbolic links are included.
5152
5153 For most systems backticks can be used to get files names from
5154 any external command. Example: >
5155 :let tagfiles = glob("`find . -name tags -print`")
5156 :let &tags = substitute(tagfiles, "\n", ",", "g")
5157< The result of the program inside the backticks should be one
5158 item per line. Spaces inside an item are allowed.
5159
5160 See |expand()| for expanding special Vim variables. See
5161 |system()| for getting the raw output of an external command.
5162
5163 Can also be used as a |method|: >
5164 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005165<
5166 Return type: |String| or list<string> or list<any> depending
5167 on {list}
5168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005169
5170glob2regpat({string}) *glob2regpat()*
5171 Convert a file pattern, as used by glob(), into a search
5172 pattern. The result can be used to match with a string that
5173 is a file name. E.g. >
5174 if filename =~ glob2regpat('Make*.mak')
5175< This is equivalent to: >
5176 if filename =~ '^Make.*\.mak$'
5177< When {string} is an empty string the result is "^$", match an
5178 empty string.
5179 Note that the result depends on the system. On MS-Windows
5180 a backslash usually means a path separator.
5181
5182 Can also be used as a |method|: >
5183 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005184<
5185 Return type: |String|
5186
5187 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005188globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5189 Perform glob() for String {expr} on all directories in {path}
5190 and concatenate the results. Example: >
5191 :echo globpath(&rtp, "syntax/c.vim")
5192<
5193 {path} is a comma-separated list of directory names. Each
5194 directory name is prepended to {expr} and expanded like with
5195 |glob()|. A path separator is inserted when needed.
5196 To add a comma inside a directory name escape it with a
5197 backslash. Note that on MS-Windows a directory may have a
5198 trailing backslash, remove it if you put a comma after it.
5199 If the expansion fails for one of the directories, there is no
5200 error message.
5201
5202 Unless the optional {nosuf} argument is given and is |TRUE|,
5203 the 'suffixes' and 'wildignore' options apply: Names matching
5204 one of the patterns in 'wildignore' will be skipped and
5205 'suffixes' affect the ordering of matches.
5206
5207 When {list} is present and it is |TRUE| the result is a |List|
5208 with all matching files. The advantage of using a List is, you
5209 also get filenames containing newlines correctly. Otherwise
5210 the result is a String and when there are several matches,
5211 they are separated by <NL> characters. Example: >
5212 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5213<
5214 {alllinks} is used as with |glob()|.
5215
5216 The "**" item can be used to search in a directory tree.
5217 For example, to find all "README.txt" files in the directories
5218 in 'runtimepath' and below: >
5219 :echo globpath(&rtp, "**/README.txt")
5220< Upwards search and limiting the depth of "**" is not
5221 supported, thus using 'path' will not always work properly.
5222
5223 Can also be used as a |method|, the base is passed as the
5224 second argument: >
5225 GetExpr()->globpath(&rtp)
5226<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005227 Return type: |String| or list<string> or list<any> depending
5228 on {list}
5229
5230
5231has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005232 When {check} is omitted or is zero: The result is a Number,
5233 which is 1 if the feature {feature} is supported, zero
5234 otherwise. The {feature} argument is a string, case is
5235 ignored. See |feature-list| below.
5236
5237 When {check} is present and not zero: The result is a Number,
5238 which is 1 if the feature {feature} could ever be supported,
5239 zero otherwise. This is useful to check for a typo in
5240 {feature} and to detect dead code. Keep in mind that an older
5241 Vim version will not know about a feature added later and
5242 features that have been abandoned will not be known by the
5243 current Vim version.
5244
5245 Also see |exists()| and |exists_compiled()|.
5246
5247 Note that to skip code that has a syntax error when the
5248 feature is not available, Vim may skip the rest of the line
5249 and miss a following `endif`. Therefore put the `endif` on a
5250 separate line: >
5251 if has('feature')
5252 let x = this->breaks->without->the->feature
5253 endif
5254< If the `endif` would be moved to the second line as "| endif" it
5255 would not be found.
5256
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005257 Return type: |Number|
5258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005259
5260has_key({dict}, {key}) *has_key()*
5261 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005262 has an entry with key {key}. FALSE otherwise.
5263 The {key} argument is a string. In |Vim9| script a number is
5264 also accepted (and converted to a string) but no other types.
5265 In legacy script the usual automatic conversion to string is
5266 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005267
5268 Can also be used as a |method|: >
5269 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005270<
5271 Return type: |Number|
5272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005273
5274haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5275 The result is a Number:
5276 1 when the window has set a local directory via |:lcd|
5277 2 when the tab-page has set a local directory via |:tcd|
5278 0 otherwise.
5279
5280 Without arguments use the current window.
5281 With {winnr} use this window in the current tab page.
5282 With {winnr} and {tabnr} use the window in the specified tab
5283 page.
5284 {winnr} can be the window number or the |window-ID|.
5285 If {winnr} is -1 it is ignored and only the tabpage is used.
5286 Return 0 if the arguments are invalid.
5287 Examples: >
5288 if haslocaldir() == 1
5289 " window local directory case
5290 elseif haslocaldir() == 2
5291 " tab-local directory case
5292 else
5293 " global directory case
5294 endif
5295
5296 " current window
5297 :echo haslocaldir()
5298 :echo haslocaldir(0)
5299 :echo haslocaldir(0, 0)
5300 " window n in current tab page
5301 :echo haslocaldir(n)
5302 :echo haslocaldir(n, 0)
5303 " window n in tab page m
5304 :echo haslocaldir(n, m)
5305 " tab page m
5306 :echo haslocaldir(-1, m)
5307<
5308 Can also be used as a |method|: >
5309 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005310<
5311 Return type: |Number|
5312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005313
5314hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5315 The result is a Number, which is TRUE if there is a mapping
5316 that contains {what} in somewhere in the rhs (what it is
5317 mapped to) and this mapping exists in one of the modes
5318 indicated by {mode}.
5319 The arguments {what} and {mode} are strings.
5320 When {abbr} is there and it is |TRUE| use abbreviations
5321 instead of mappings. Don't forget to specify Insert and/or
5322 Command-line mode.
5323 Both the global mappings and the mappings local to the current
5324 buffer are checked for a match.
5325 If no matching mapping is found FALSE is returned.
5326 The following characters are recognized in {mode}:
5327 n Normal mode
5328 v Visual and Select mode
5329 x Visual mode
5330 s Select mode
5331 o Operator-pending mode
5332 i Insert mode
5333 l Language-Argument ("r", "f", "t", etc.)
5334 c Command-line mode
5335 When {mode} is omitted, "nvo" is used.
5336
5337 This function is useful to check if a mapping already exists
5338 to a function in a Vim script. Example: >
5339 :if !hasmapto('\ABCdoit')
5340 : map <Leader>d \ABCdoit
5341 :endif
5342< This installs the mapping to "\ABCdoit" only if there isn't
5343 already a mapping to "\ABCdoit".
5344
5345 Can also be used as a |method|: >
5346 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005347<
5348 Return type: |Number|
5349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005350
5351histadd({history}, {item}) *histadd()*
5352 Add the String {item} to the history {history} which can be
5353 one of: *hist-names*
5354 "cmd" or ":" command line history
5355 "search" or "/" search pattern history
5356 "expr" or "=" typed expression history
5357 "input" or "@" input line history
5358 "debug" or ">" debug command history
5359 empty the current or last used history
5360 The {history} string does not need to be the whole name, one
5361 character is sufficient.
5362 If {item} does already exist in the history, it will be
5363 shifted to become the newest entry.
5364 The result is a Number: TRUE if the operation was successful,
5365 otherwise FALSE is returned.
5366
5367 Example: >
5368 :call histadd("input", strftime("%Y %b %d"))
5369 :let date=input("Enter date: ")
5370< This function is not available in the |sandbox|.
5371
5372 Can also be used as a |method|, the base is passed as the
5373 second argument: >
5374 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005375<
5376 Return type: |Number|
5377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005378
5379histdel({history} [, {item}]) *histdel()*
5380 Clear {history}, i.e. delete all its entries. See |hist-names|
5381 for the possible values of {history}.
5382
5383 If the parameter {item} evaluates to a String, it is used as a
5384 regular expression. All entries matching that expression will
5385 be removed from the history (if there are any).
5386 Upper/lowercase must match, unless "\c" is used |/\c|.
5387 If {item} evaluates to a Number, it will be interpreted as
5388 an index, see |:history-indexing|. The respective entry will
5389 be removed if it exists.
5390
5391 The result is TRUE for a successful operation, otherwise FALSE
5392 is returned.
5393
5394 Examples:
5395 Clear expression register history: >
5396 :call histdel("expr")
5397<
5398 Remove all entries starting with "*" from the search history: >
5399 :call histdel("/", '^\*')
5400<
5401 The following three are equivalent: >
5402 :call histdel("search", histnr("search"))
5403 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005404 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005405<
5406 To delete the last search pattern and use the last-but-one for
5407 the "n" command and 'hlsearch': >
5408 :call histdel("search", -1)
5409 :let @/ = histget("search", -1)
5410<
5411 Can also be used as a |method|: >
5412 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005413<
5414 Return type: |Number|
5415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005416
5417histget({history} [, {index}]) *histget()*
5418 The result is a String, the entry with Number {index} from
5419 {history}. See |hist-names| for the possible values of
5420 {history}, and |:history-indexing| for {index}. If there is
5421 no such entry, an empty String is returned. When {index} is
5422 omitted, the most recent item from the history is used.
5423
5424 Examples:
5425 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005426 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005427
5428< Define an Ex command ":H {num}" that supports re-execution of
5429 the {num}th entry from the output of |:history|. >
5430 :command -nargs=1 H execute histget("cmd", 0+<args>)
5431<
5432 Can also be used as a |method|: >
5433 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005434<
5435 Return type: |String|
5436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005437
5438histnr({history}) *histnr()*
5439 The result is the Number of the current entry in {history}.
5440 See |hist-names| for the possible values of {history}.
5441 If an error occurred, -1 is returned.
5442
5443 Example: >
5444 :let inp_index = histnr("expr")
5445
5446< Can also be used as a |method|: >
5447 GetHistory()->histnr()
5448<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005449 Return type: |Number|
5450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005451hlexists({name}) *hlexists()*
5452 The result is a Number, which is TRUE if a highlight group
5453 called {name} exists. This is when the group has been
5454 defined in some way. Not necessarily when highlighting has
5455 been defined for it, it may also have been used for a syntax
5456 item.
5457 *highlight_exists()*
5458 Obsolete name: highlight_exists().
5459
5460 Can also be used as a |method|: >
5461 GetName()->hlexists()
5462<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005463 Return type: |Number|
5464
5465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005466hlget([{name} [, {resolve}]]) *hlget()*
5467 Returns a List of all the highlight group attributes. If the
5468 optional {name} is specified, then returns a List with only
5469 the attributes of the specified highlight group. Returns an
5470 empty List if the highlight group {name} is not present.
5471
5472 If the optional {resolve} argument is set to v:true and the
5473 highlight group {name} is linked to another group, then the
5474 link is resolved recursively and the attributes of the
5475 resolved highlight group are returned.
5476
5477 Each entry in the returned List is a Dictionary with the
5478 following items:
5479 cleared boolean flag, set to v:true if the highlight
5480 group attributes are cleared or not yet
5481 specified. See |highlight-clear|.
5482 cterm cterm attributes. See |highlight-cterm|.
5483 ctermbg cterm background color.
5484 See |highlight-ctermbg|.
5485 ctermfg cterm foreground color.
5486 See |highlight-ctermfg|.
5487 ctermul cterm underline color. See |highlight-ctermul|.
5488 default boolean flag, set to v:true if the highlight
5489 group link is a default link. See
5490 |highlight-default|.
5491 font highlight group font. See |highlight-font|.
5492 gui gui attributes. See |highlight-gui|.
5493 guibg gui background color. See |highlight-guibg|.
5494 guifg gui foreground color. See |highlight-guifg|.
5495 guisp gui special color. See |highlight-guisp|.
5496 id highlight group ID.
5497 linksto linked highlight group name.
5498 See |:highlight-link|.
5499 name highlight group name. See |group-name|.
5500 start start terminal keycode. See |highlight-start|.
5501 stop stop terminal keycode. See |highlight-stop|.
5502 term term attributes. See |highlight-term|.
5503
5504 The 'term', 'cterm' and 'gui' items in the above Dictionary
5505 have a dictionary value with the following optional boolean
5506 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5507 'reverse', 'inverse' and 'strikethrough'.
5508
5509 Example(s): >
5510 :echo hlget()
5511 :echo hlget('ModeMsg')
5512 :echo hlget('Number', v:true)
5513<
5514 Can also be used as a |method|: >
5515 GetName()->hlget()
5516<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005517 Return type: list<dict<any>>
5518
5519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005520hlset({list}) *hlset()*
5521 Creates or modifies the attributes of a List of highlight
5522 groups. Each item in {list} is a dictionary containing the
5523 attributes of a highlight group. See |hlget()| for the list of
5524 supported items in this dictionary.
5525
5526 In addition to the items described in |hlget()|, the following
5527 additional items are supported in the dictionary:
5528
5529 force boolean flag to force the creation of
5530 a link for an existing highlight group
5531 with attributes.
5532
5533 The highlight group is identified using the 'name' item and
5534 the 'id' item (if supplied) is ignored. If a highlight group
5535 with a specified name doesn't exist, then it is created.
5536 Otherwise the attributes of an existing highlight group are
5537 modified.
5538
5539 If an empty dictionary value is used for the 'term' or 'cterm'
5540 or 'gui' entries, then the corresponding attributes are
5541 cleared. If the 'cleared' item is set to v:true, then all the
5542 attributes of the highlight group are cleared.
5543
5544 The 'linksto' item can be used to link a highlight group to
5545 another highlight group. See |:highlight-link|.
5546
5547 Returns zero for success, -1 for failure.
5548
5549 Example(s): >
5550 " add bold attribute to the Visual highlight group
5551 :call hlset([#{name: 'Visual',
5552 \ term: #{reverse: 1 , bold: 1}}])
5553 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5554 :let l = hlget()
5555 :call hlset(l)
5556 " clear the Search highlight group
5557 :call hlset([#{name: 'Search', cleared: v:true}])
5558 " clear the 'term' attributes for a highlight group
5559 :call hlset([#{name: 'Title', term: {}}])
5560 " create the MyHlg group linking it to DiffAdd
5561 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5562 " remove the MyHlg group link
5563 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5564 " clear the attributes and a link
5565 :call hlset([#{name: 'MyHlg', cleared: v:true,
5566 \ linksto: 'NONE'}])
5567<
5568 Can also be used as a |method|: >
5569 GetAttrList()->hlset()
5570<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005571 Return type: |Number|
5572
5573hlID({name}) *hlID()*
5574 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005575 with name {name}. When the highlight group doesn't exist,
5576 zero is returned.
5577 This can be used to retrieve information about the highlight
5578 group. For example, to get the background color of the
5579 "Comment" group: >
5580 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5581< *highlightID()*
5582 Obsolete name: highlightID().
5583
5584 Can also be used as a |method|: >
5585 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005586<
5587 Return type: |Number|
5588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005589
5590hostname() *hostname()*
5591 The result is a String, which is the name of the machine on
5592 which Vim is currently running. Machine names greater than
5593 256 characters long are truncated.
5594
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005595 Return type: |String|
5596
5597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005598iconv({string}, {from}, {to}) *iconv()*
5599 The result is a String, which is the text {string} converted
5600 from encoding {from} to encoding {to}.
5601 When the conversion completely fails an empty string is
5602 returned. When some characters could not be converted they
5603 are replaced with "?".
5604 The encoding names are whatever the iconv() library function
5605 can accept, see ":!man 3 iconv".
5606 Most conversions require Vim to be compiled with the |+iconv|
5607 feature. Otherwise only UTF-8 to latin1 conversion and back
5608 can be done.
5609 This can be used to display messages with special characters,
5610 no matter what 'encoding' is set to. Write the message in
5611 UTF-8 and use: >
5612 echo iconv(utf8_str, "utf-8", &enc)
5613< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5614 from/to UCS-2 is automatically changed to use UTF-8. You
5615 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5616
5617 Can also be used as a |method|: >
5618 GetText()->iconv('latin1', 'utf-8')
5619<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005620 Return type: |String|
5621
5622
Ernie Raelc8e158b2024-07-09 18:39:52 +02005623id({item}) *id()*
5624 The result is a unique String associated with the {item} and
5625 not with the {item}'s contents. It is only valid while the
5626 {item} exists and is referenced. It is valid only in the
5627 instance of vim that produces the result. The whole idea is
5628 that `id({item})` does not change if the contents of {item}
5629 changes. This is useful as a `key` for creating an identity
5630 dictionary, rather than one based on equals.
5631
5632 This operation does not reference {item} and there is no
5633 function to convert the `id` to the {item}. It may be useful to
5634 have a map of `id` to {item}. The following >
5635 var referenceMap: dict<any>
5636 var id = item->id()
5637 referenceMap[id] = item
5638< prevents {item} from being garbage collected and provides a
5639 way to get the {item} from the `id`.
5640
5641 {item} may be a List, Dictionary, Object, Job, Channel or
5642 Blob. If the item is not a permitted type, or it is a null
5643 value, then an empty String is returned.
5644
5645 Can also be used as a |method|: >
5646 GetItem()->id()
5647<
5648 Return type: |String|
5649
5650
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005651indent({lnum}) *indent()*
5652 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005653 current buffer. The indent is counted in spaces, the value
5654 of 'tabstop' is relevant. {lnum} is used just like in
5655 |getline()|.
5656 When {lnum} is invalid -1 is returned. In |Vim9| script an
5657 error is given.
5658
5659 Can also be used as a |method|: >
5660 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005661<
5662 Return type: |Number|
5663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005664
5665index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005666 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005667 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005669 If {object} is a |List| return the lowest index where the item
5670 has a value equal to {expr}. There is no automatic
5671 conversion, so the String "4" is different from the Number 4.
5672 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005673 of 'ignorecase' is not used here, case matters as indicated by
5674 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005675
5676 If {object} is |Blob| return the lowest index where the byte
5677 value is equal to {expr}.
5678
5679 If {start} is given then start looking at the item with index
5680 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005682 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5683 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005685 -1 is returned when {expr} is not found in {object}.
5686 Example: >
5687 :let idx = index(words, "the")
5688 :if index(numbers, 123) >= 0
5689
5690< Can also be used as a |method|: >
5691 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005692<
5693 Return type: |Number|
5694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005695
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005696indexof({object}, {expr} [, {opts}]) *indexof()*
5697 Returns the index of an item in {object} where {expr} is
5698 v:true. {object} must be a |List| or a |Blob|.
5699
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005700 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005701 List until the expression is v:true and return the index of
5702 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005703
5704 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005705 Blob until the expression is v:true and return the index of
5706 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005707
5708 {expr} must be a |string| or |Funcref|.
5709
5710 If {expr} is a |string|: If {object} is a |List|, inside
5711 {expr} |v:key| has the index of the current List item and
5712 |v:val| has the value of the item. If {object} is a |Blob|,
5713 inside {expr} |v:key| has the index of the current byte and
5714 |v:val| has the byte value.
5715
5716 If {expr} is a |Funcref| it must take two arguments:
5717 1. the key or the index of the current item.
5718 2. the value of the current item.
5719 The function must return |TRUE| if the item is found and the
5720 search should stop.
5721
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005722 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005723 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005724 startidx start evaluating {expr} at the item with this
5725 index; may be negative for an item relative to
5726 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005727 Returns -1 when {expr} evaluates to v:false for all the items.
5728 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005729 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5730 :echo indexof(l, "v:val.n == 20")
5731 :echo indexof(l, {i, v -> v.n == 30})
5732 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005733
5734< Can also be used as a |method|: >
5735 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005736<
5737 Return type: |Number|
5738
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005739
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005740input({prompt} [, {text} [, {completion}]]) *input()*
5741 The result is a String, which is whatever the user typed on
5742 the command-line. The {prompt} argument is either a prompt
5743 string, or a blank string (for no prompt). A '\n' can be used
5744 in the prompt to start a new line.
5745 The highlighting set with |:echohl| is used for the prompt.
5746 The input is entered just like a command-line, with the same
5747 editing commands and mappings. There is a separate history
5748 for lines typed for input().
5749 Example: >
5750 :if input("Coffee or beer? ") == "beer"
5751 : echo "Cheers!"
5752 :endif
5753<
5754 If the optional {text} argument is present and not empty, this
5755 is used for the default reply, as if the user typed this.
5756 Example: >
5757 :let color = input("Color? ", "white")
5758
5759< The optional {completion} argument specifies the type of
5760 completion supported for the input. Without it completion is
5761 not performed. The supported completion types are the same as
5762 that can be supplied to a user-defined command using the
5763 "-complete=" argument. Refer to |:command-completion| for
5764 more information. Example: >
5765 let fname = input("File: ", "", "file")
5766<
5767 NOTE: This function must not be used in a startup file, for
5768 the versions that only run in GUI mode (e.g., the Win32 GUI).
5769 Note: When input() is called from within a mapping it will
5770 consume remaining characters from that mapping, because a
5771 mapping is handled like the characters were typed.
5772 Use |inputsave()| before input() and |inputrestore()|
5773 after input() to avoid that. Another solution is to avoid
5774 that further characters follow in the mapping, e.g., by using
5775 |:execute| or |:normal|.
5776
5777 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005778 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005779 :function GetFoo()
5780 : call inputsave()
5781 : let g:Foo = input("enter search pattern: ")
5782 : call inputrestore()
5783 :endfunction
5784
5785< Can also be used as a |method|: >
5786 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005787<
5788 Return type: |String|
5789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005790
5791inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5792 Like |input()|, but when the GUI is running and text dialogs
5793 are supported, a dialog window pops up to input the text.
5794 Example: >
5795 :let n = inputdialog("value for shiftwidth", shiftwidth())
5796 :if n != ""
5797 : let &sw = n
5798 :endif
5799< When the dialog is cancelled {cancelreturn} is returned. When
5800 omitted an empty string is returned.
5801 Hitting <Enter> works like pressing the OK button. Hitting
5802 <Esc> works like pressing the Cancel button.
5803 NOTE: Command-line completion is not supported.
5804
5805 Can also be used as a |method|: >
5806 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005807<
5808 Return type: |String|
5809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005810
5811inputlist({textlist}) *inputlist()*
5812 {textlist} must be a |List| of strings. This |List| is
5813 displayed, one string per line. The user will be prompted to
5814 enter a number, which is returned.
5815 The user can also select an item by clicking on it with the
5816 mouse, if the mouse is enabled in the command line ('mouse' is
5817 "a" or includes "c"). For the first string 0 is returned.
5818 When clicking above the first item a negative number is
5819 returned. When clicking on the prompt one more than the
5820 length of {textlist} is returned.
5821 Make sure {textlist} has less than 'lines' entries, otherwise
5822 it won't work. It's a good idea to put the entry number at
5823 the start of the string. And put a prompt in the first item.
5824 Example: >
5825 let color = inputlist(['Select color:', '1. red',
5826 \ '2. green', '3. blue'])
5827
5828< Can also be used as a |method|: >
5829 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005830<
5831 Return type: |Number|
5832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005833
5834inputrestore() *inputrestore()*
5835 Restore typeahead that was saved with a previous |inputsave()|.
5836 Should be called the same number of times inputsave() is
5837 called. Calling it more often is harmless though.
5838 Returns TRUE when there is nothing to restore, FALSE otherwise.
5839
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005840 Return type: |Number|
5841
5842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005843inputsave() *inputsave()*
5844 Preserve typeahead (also from mappings) and clear it, so that
5845 a following prompt gets input from the user. Should be
5846 followed by a matching inputrestore() after the prompt. Can
5847 be used several times, in which case there must be just as
5848 many inputrestore() calls.
5849 Returns TRUE when out of memory, FALSE otherwise.
5850
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005851 Return type: |Number|
5852
5853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005854inputsecret({prompt} [, {text}]) *inputsecret()*
5855 This function acts much like the |input()| function with but
5856 two exceptions:
5857 a) the user's response will be displayed as a sequence of
5858 asterisks ("*") thereby keeping the entry secret, and
5859 b) the user's response will not be recorded on the input
5860 |history| stack.
5861 The result is a String, which is whatever the user actually
5862 typed on the command-line in response to the issued prompt.
5863 NOTE: Command-line completion is not supported.
5864
5865 Can also be used as a |method|: >
5866 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005867<
5868 Return type: |String|
5869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005870
5871insert({object}, {item} [, {idx}]) *insert()*
5872 When {object} is a |List| or a |Blob| insert {item} at the start
5873 of it.
5874
5875 If {idx} is specified insert {item} before the item with index
5876 {idx}. If {idx} is zero it goes before the first item, just
5877 like omitting {idx}. A negative {idx} is also possible, see
5878 |list-index|. -1 inserts just before the last item.
5879
5880 Returns the resulting |List| or |Blob|. Examples: >
5881 :let mylist = insert([2, 3, 5], 1)
5882 :call insert(mylist, 4, -1)
5883 :call insert(mylist, 6, len(mylist))
5884< The last example can be done simpler with |add()|.
5885 Note that when {item} is a |List| it is inserted as a single
5886 item. Use |extend()| to concatenate |Lists|.
5887
5888 Can also be used as a |method|: >
5889 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005890<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005891 Return type: |Number|
5892
5893
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005894 *instanceof()* *E614* *E616* *E693*
5895instanceof({object}, {class})
5896 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005897 argument is a direct or indirect instance of a |Class|,
5898 |Interface|, or class |:type| alias specified by {class}.
5899 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005900 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005901 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005902 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005903
5904< Can also be used as a |method|: >
5905 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005906<
5907 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005909interrupt() *interrupt()*
5910 Interrupt script execution. It works more or less like the
5911 user typing CTRL-C, most commands won't execute and control
5912 returns to the user. This is useful to abort execution
5913 from lower down, e.g. in an autocommand. Example: >
5914 :function s:check_typoname(file)
5915 : if fnamemodify(a:file, ':t') == '['
5916 : echomsg 'Maybe typo'
5917 : call interrupt()
5918 : endif
5919 :endfunction
5920 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005921<
5922 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005923
5924invert({expr}) *invert()*
5925 Bitwise invert. The argument is converted to a number. A
5926 List, Dict or Float argument causes an error. Example: >
5927 :let bits = invert(bits)
5928< Can also be used as a |method|: >
5929 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005930<
5931 Return type: |Number|
5932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005933
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005934isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005935 The result is a Number, which is |TRUE| when {path} is an
5936 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005937 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005938 On MS-Windows, it is considered absolute when it starts with an
5939 optional drive prefix and is followed by a '\' or '/'. UNC paths
5940 are always absolute.
5941 Example: >
5942 echo isabsolutepath('/usr/share/') " 1
5943 echo isabsolutepath('./foobar') " 0
5944 echo isabsolutepath('C:\Windows') " 1
5945 echo isabsolutepath('foobar') " 0
5946 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005947<
LemonBoydca1d402022-04-28 15:26:33 +01005948 Can also be used as a |method|: >
5949 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005950<
5951 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005952
5953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005954isdirectory({directory}) *isdirectory()*
5955 The result is a Number, which is |TRUE| when a directory
5956 with the name {directory} exists. If {directory} doesn't
5957 exist, or isn't a directory, the result is |FALSE|. {directory}
5958 is any expression, which is used as a String.
5959
5960 Can also be used as a |method|: >
5961 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005962<
5963 Return type: |Number|
5964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005965
5966isinf({expr}) *isinf()*
5967 Return 1 if {expr} is a positive infinity, or -1 a negative
5968 infinity, otherwise 0. >
5969 :echo isinf(1.0 / 0.0)
5970< 1 >
5971 :echo isinf(-1.0 / 0.0)
5972< -1
5973
5974 Can also be used as a |method|: >
5975 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005976<
5977 Return type: |Number|
5978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005979
5980islocked({expr}) *islocked()* *E786*
5981 The result is a Number, which is |TRUE| when {expr} is the
5982 name of a locked variable.
5983 The string argument {expr} must be the name of a variable,
5984 |List| item or |Dictionary| entry, not the variable itself!
5985 Example: >
5986 :let alist = [0, ['a', 'b'], 2, 3]
5987 :lockvar 1 alist
5988 :echo islocked('alist') " 1
5989 :echo islocked('alist[1]') " 0
5990
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005991< When {expr} is a variable that does not exist -1 is returned.
5992 If {expr} uses a range, list or dict index that is out of
5993 range or does not exist you get an error message. Use
5994 |exists()| to check for existence.
5995 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005996
5997 Can also be used as a |method|: >
5998 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005999<
6000 Return type: |Number|
6001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006002
6003isnan({expr}) *isnan()*
6004 Return |TRUE| if {expr} is a float with value NaN. >
6005 echo isnan(0.0 / 0.0)
6006< 1
6007
6008 Can also be used as a |method|: >
6009 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006010<
6011 Return type: |Number|
6012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006013
6014items({dict}) *items()*
6015 Return a |List| with all the key-value pairs of {dict}. Each
6016 |List| item is a list with two items: the key of a {dict}
6017 entry and the value of this entry. The |List| is in arbitrary
6018 order. Also see |keys()| and |values()|.
6019 Example: >
6020 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006021 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006022 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006023<
6024 A List or a String argument is also supported. In these
6025 cases, items() returns a List with the index and the value at
6026 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006027
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006028 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006029 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006030<
6031 Return type: list<list<any>> or list<any>
6032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006033
6034job_ functions are documented here: |job-functions-details|
6035
6036
6037join({list} [, {sep}]) *join()*
6038 Join the items in {list} together into one String.
6039 When {sep} is specified it is put in between the items. If
6040 {sep} is omitted a single space is used.
6041 Note that {sep} is not added at the end. You might want to
6042 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006043 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006044< String items are used as-is. |Lists| and |Dictionaries| are
6045 converted into a string like with |string()|.
6046 The opposite function is |split()|.
6047
6048 Can also be used as a |method|: >
6049 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006050<
6051 Return type: |String|
6052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006053
6054js_decode({string}) *js_decode()*
6055 This is similar to |json_decode()| with these differences:
6056 - Object key names do not have to be in quotes.
6057 - Strings can be in single quotes.
6058 - Empty items in an array (between two commas) are allowed and
6059 result in v:none items.
6060
6061 Can also be used as a |method|: >
6062 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006063<
6064 Return type: any, depending on {varname}
6065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006066
6067js_encode({expr}) *js_encode()*
6068 This is similar to |json_encode()| with these differences:
6069 - Object key names are not in quotes.
6070 - v:none items in an array result in an empty item between
6071 commas.
6072 For example, the Vim object:
6073 [1,v:none,{"one":1},v:none] ~
6074 Will be encoded as:
6075 [1,,{one:1},,] ~
6076 While json_encode() would produce:
6077 [1,null,{"one":1},null] ~
6078 This encoding is valid for JavaScript. It is more efficient
6079 than JSON, especially when using an array with optional items.
6080
6081 Can also be used as a |method|: >
6082 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006083<
6084 Return type: |String|
6085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006086
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006087json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006088 This parses a JSON formatted string and returns the equivalent
6089 in Vim values. See |json_encode()| for the relation between
6090 JSON and Vim values.
6091 The decoding is permissive:
6092 - A trailing comma in an array and object is ignored, e.g.
6093 "[1, 2, ]" is the same as "[1, 2]".
6094 - Integer keys are accepted in objects, e.g. {1:2} is the
6095 same as {"1":2}.
6096 - More floating point numbers are recognized, e.g. "1." for
6097 "1.0", or "001.2" for "1.2". Special floating point values
6098 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6099 are accepted.
6100 - Leading zeroes in integer numbers are ignored, e.g. "012"
6101 for "12" or "-012" for "-12".
6102 - Capitalization is ignored in literal names null, true or
6103 false, e.g. "NULL" for "null", "True" for "true".
6104 - Control characters U+0000 through U+001F which are not
6105 escaped in strings are accepted, e.g. " " (tab
6106 character in string) for "\t".
6107 - An empty JSON expression or made of only spaces is accepted
6108 and results in v:none.
6109 - Backslash in an invalid 2-character sequence escape is
6110 ignored, e.g. "\a" is decoded as "a".
6111 - A correct surrogate pair in JSON strings should normally be
6112 a 12 character sequence such as "\uD834\uDD1E", but
6113 json_decode() silently accepts truncated surrogate pairs
6114 such as "\uD834" or "\uD834\u"
6115 *E938*
6116 A duplicate key in an object, valid in rfc7159, is not
6117 accepted by json_decode() as the result must be a valid Vim
6118 type, e.g. this fails: {"a":"b", "a":"c"}
6119
6120 Can also be used as a |method|: >
6121 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006122<
6123 Return type: any, depending on {varname}
6124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006125
6126json_encode({expr}) *json_encode()*
6127 Encode {expr} as JSON and return this as a string.
6128 The encoding is specified in:
6129 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006130 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006131 |Number| decimal number
6132 |Float| floating point number
6133 Float nan "NaN"
6134 Float inf "Infinity"
6135 Float -inf "-Infinity"
6136 |String| in double quotes (possibly null)
6137 |Funcref| not possible, error
6138 |List| as an array (possibly null); when
6139 used recursively: []
6140 |Dict| as an object (possibly null); when
6141 used recursively: {}
6142 |Blob| as an array of the individual bytes
6143 v:false "false"
6144 v:true "true"
6145 v:none "null"
6146 v:null "null"
6147 Note that NaN and Infinity are passed on as values. This is
6148 missing in the JSON standard, but several implementations do
6149 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006150 If a string contains an illegal character then the replacement
6151 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006152
6153 Can also be used as a |method|: >
6154 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006155<
6156 Return type: |String|
6157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006158
6159keys({dict}) *keys()*
6160 Return a |List| with all the keys of {dict}. The |List| is in
6161 arbitrary order. Also see |items()| and |values()|.
6162
6163 Can also be used as a |method|: >
6164 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006165<
6166 Return type: list<string>
6167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006168
zeertzjqcdc83932022-09-12 13:38:41 +01006169keytrans({string}) *keytrans()*
6170 Turn the internal byte representation of keys into a form that
6171 can be used for |:map|. E.g. >
6172 :let xx = "\<C-Home>"
6173 :echo keytrans(xx)
6174< <C-Home>
6175
6176 Can also be used as a |method|: >
6177 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006178<
6179 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006180
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006181
6182len({expr}) *len()* *E701*
6183 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006184 When {expr} is a String or a Number the length in bytes is
6185 used, as with |strlen()|.
6186 When {expr} is a |List| the number of items in the |List| is
6187 returned.
6188 When {expr} is a |Blob| the number of bytes is returned.
6189 When {expr} is a |Dictionary| the number of entries in the
6190 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006191 When {expr} is an |Object|, invokes the len() method in the
6192 object (if present) to get the length (|object-len()|).
6193 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006194
6195 Can also be used as a |method|: >
6196 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006197<
6198 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006199
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006200
6201 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006202libcall({libname}, {funcname}, {argument})
6203 Call function {funcname} in the run-time library {libname}
6204 with single argument {argument}.
6205 This is useful to call functions in a library that you
6206 especially made to be used with Vim. Since only one argument
6207 is possible, calling standard library functions is rather
6208 limited.
6209 The result is the String returned by the function. If the
6210 function returns NULL, this will appear as an empty string ""
6211 to Vim.
6212 If the function returns a number, use libcallnr()!
6213 If {argument} is a number, it is passed to the function as an
6214 int; if {argument} is a string, it is passed as a
6215 null-terminated string.
6216 This function will fail in |restricted-mode|.
6217
6218 libcall() allows you to write your own 'plug-in' extensions to
6219 Vim without having to recompile the program. It is NOT a
6220 means to call system functions! If you try to do so Vim will
6221 very probably crash.
6222
6223 For Win32, the functions you write must be placed in a DLL
6224 and use the normal C calling convention (NOT Pascal which is
6225 used in Windows System DLLs). The function must take exactly
6226 one parameter, either a character pointer or a long integer,
6227 and must return a character pointer or NULL. The character
6228 pointer returned must point to memory that will remain valid
6229 after the function has returned (e.g. in static data in the
6230 DLL). If it points to allocated memory, that memory will
6231 leak away. Using a static buffer in the function should work,
6232 it's then freed when the DLL is unloaded.
6233
6234 WARNING: If the function returns a non-valid pointer, Vim may
6235 crash! This also happens if the function returns a number,
6236 because Vim thinks it's a pointer.
6237 For Win32 systems, {libname} should be the filename of the DLL
6238 without the ".DLL" suffix. A full path is only required if
6239 the DLL is not in the usual places.
6240 For Unix: When compiling your own plugins, remember that the
6241 object code must be compiled as position-independent ('PIC').
6242 {only in Win32 and some Unix versions, when the |+libcall|
6243 feature is present}
6244 Examples: >
6245 :echo libcall("libc.so", "getenv", "HOME")
6246
6247< Can also be used as a |method|, the base is passed as the
6248 third argument: >
6249 GetValue()->libcall("libc.so", "getenv")
6250<
6251 *libcallnr()*
6252libcallnr({libname}, {funcname}, {argument})
6253 Just like |libcall()|, but used for a function that returns an
6254 int instead of a string.
6255 {only in Win32 on some Unix versions, when the |+libcall|
6256 feature is present}
6257 Examples: >
6258 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6259 :call libcallnr("libc.so", "printf", "Hello World!\n")
6260 :call libcallnr("libc.so", "sleep", 10)
6261<
6262 Can also be used as a |method|, the base is passed as the
6263 third argument: >
6264 GetValue()->libcallnr("libc.so", "printf")
6265<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006266 Return type: |String|
6267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006268
6269line({expr} [, {winid}]) *line()*
6270 The result is a Number, which is the line number of the file
6271 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006272 See |getpos()| for accepted positions.
6273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006274 To get the column number use |col()|. To get both use
6275 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006277 With the optional {winid} argument the values are obtained for
6278 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006279
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006280 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006282 Examples: >
6283 line(".") line number of the cursor
6284 line(".", winid) idem, in window "winid"
6285 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006286 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006287<
6288 To jump to the last known position when opening a file see
6289 |last-position-jump|.
6290
6291 Can also be used as a |method|: >
6292 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006293<
6294 Return type: |Number|
6295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006296
6297line2byte({lnum}) *line2byte()*
6298 Return the byte count from the start of the buffer for line
6299 {lnum}. This includes the end-of-line character, depending on
6300 the 'fileformat' option for the current buffer. The first
6301 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6302 This can also be used to get the byte count for the line just
6303 below the last line: >
6304 line2byte(line("$") + 1)
6305< This is the buffer size plus one. If 'fileencoding' is empty
6306 it is the file size plus one. {lnum} is used like with
6307 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6308 feature has been disabled at compile time, -1 is returned.
6309 Also see |byte2line()|, |go| and |:goto|.
6310
6311 Can also be used as a |method|: >
6312 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006313<
6314 Return type: |Number|
6315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006316
6317lispindent({lnum}) *lispindent()*
6318 Get the amount of indent for line {lnum} according the lisp
6319 indenting rules, as with 'lisp'.
6320 The indent is counted in spaces, the value of 'tabstop' is
6321 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006322 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006323 error is given.
6324
6325 Can also be used as a |method|: >
6326 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006327<
6328 Return type: |Number|
6329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330
6331list2blob({list}) *list2blob()*
6332 Return a Blob concatenating all the number values in {list}.
6333 Examples: >
6334 list2blob([1, 2, 3, 4]) returns 0z01020304
6335 list2blob([]) returns 0z
6336< Returns an empty Blob on error. If one of the numbers is
6337 negative or more than 255 error *E1239* is given.
6338
6339 |blob2list()| does the opposite.
6340
6341 Can also be used as a |method|: >
6342 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006343<
6344 Return type: |Blob|
6345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006346
6347list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006348 Convert each number in {list} to a character string and
6349 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006350 list2str([32]) returns " "
6351 list2str([65, 66, 67]) returns "ABC"
6352< The same can be done (slowly) with: >
6353 join(map(list, {nr, val -> nr2char(val)}), '')
6354< |str2list()| does the opposite.
6355
6356 When {utf8} is omitted or zero, the current 'encoding' is used.
6357 When {utf8} is TRUE, always return UTF-8 characters.
6358 With UTF-8 composing characters work as expected: >
6359 list2str([97, 769]) returns "á"
6360<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006361 Returns an empty string on error.
6362
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006363 Can also be used as a |method|: >
6364 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006365<
6366 Return type: |String|
6367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006368
6369listener_add({callback} [, {buf}]) *listener_add()*
6370 Add a callback function that will be invoked when changes have
6371 been made to buffer {buf}.
6372 {buf} refers to a buffer name or number. For the accepted
6373 values, see |bufname()|. When {buf} is omitted the current
6374 buffer is used.
6375 Returns a unique ID that can be passed to |listener_remove()|.
6376
6377 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006378 bufnr the buffer that was changed
6379 start first changed line number
6380 end first line number below the change
6381 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006382 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006383 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006384
6385 Example: >
6386 func Listener(bufnr, start, end, added, changes)
6387 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6388 endfunc
6389 call listener_add('Listener', bufnr)
6390
Bram Moolenaar944697a2022-02-20 19:48:20 +00006391< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006392 dictionary with these entries:
6393 lnum the first line number of the change
6394 end the first line below the change
6395 added number of lines added; negative if lines were
6396 deleted
6397 col first column in "lnum" that was affected by
6398 the change; one if unknown or the whole line
6399 was affected; this is a byte index, first
6400 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006401 When lines are inserted (not when a line is split, e.g. by
6402 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006403 lnum line above which the new line is added
6404 end equal to "lnum"
6405 added number of lines inserted
6406 col 1
6407 When lines are deleted the values are:
6408 lnum the first deleted line
6409 end the line below the first deleted line, before
6410 the deletion was done
6411 added negative, number of lines deleted
6412 col 1
6413 When lines are changed:
6414 lnum the first changed line
6415 end the line below the last changed line
6416 added 0
6417 col first column with a change or 1
6418
6419 The entries are in the order the changes were made, thus the
6420 most recent change is at the end. The line numbers are valid
6421 when the callback is invoked, but later changes may make them
6422 invalid, thus keeping a copy for later might not work.
6423
6424 The {callback} is invoked just before the screen is updated,
6425 when |listener_flush()| is called or when a change is being
6426 made that changes the line count in a way it causes a line
6427 number in the list of changes to become invalid.
6428
6429 The {callback} is invoked with the text locked, see
6430 |textlock|. If you do need to make changes to the buffer, use
6431 a timer to do this later |timer_start()|.
6432
6433 The {callback} is not invoked when the buffer is first loaded.
6434 Use the |BufReadPost| autocmd event to handle the initial text
6435 of a buffer.
6436 The {callback} is also not invoked when the buffer is
6437 unloaded, use the |BufUnload| autocmd event for that.
6438
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006439 Returns zero if {callback} or {buf} is invalid.
6440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006441 Can also be used as a |method|, the base is passed as the
6442 second argument: >
6443 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006444<
6445 Return type: |Number|
6446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006447
6448listener_flush([{buf}]) *listener_flush()*
6449 Invoke listener callbacks for buffer {buf}. If there are no
6450 pending changes then no callbacks are invoked.
6451
6452 {buf} refers to a buffer name or number. For the accepted
6453 values, see |bufname()|. When {buf} is omitted the current
6454 buffer is used.
6455
6456 Can also be used as a |method|: >
6457 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006458<
6459 Return type: |Number|
6460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006461
6462listener_remove({id}) *listener_remove()*
6463 Remove a listener previously added with listener_add().
6464 Returns FALSE when {id} could not be found, TRUE when {id} was
6465 removed.
6466
6467 Can also be used as a |method|: >
6468 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006469<
6470 Return type: |Number|
6471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006472
6473localtime() *localtime()*
6474 Return the current time, measured as seconds since 1st Jan
6475 1970. See also |strftime()|, |strptime()| and |getftime()|.
6476
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006477 Return type: |Number|
6478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006479
6480log({expr}) *log()*
6481 Return the natural logarithm (base e) of {expr} as a |Float|.
6482 {expr} must evaluate to a |Float| or a |Number| in the range
6483 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006484 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006485 Examples: >
6486 :echo log(10)
6487< 2.302585 >
6488 :echo log(exp(5))
6489< 5.0
6490
6491 Can also be used as a |method|: >
6492 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006493<
6494 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006495
6496
6497log10({expr}) *log10()*
6498 Return the logarithm of Float {expr} to base 10 as a |Float|.
6499 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006500 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006501 Examples: >
6502 :echo log10(1000)
6503< 3.0 >
6504 :echo log10(0.01)
6505< -2.0
6506
6507 Can also be used as a |method|: >
6508 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006509<
6510 Return type: |Float|
6511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006512
6513luaeval({expr} [, {expr}]) *luaeval()*
6514 Evaluate Lua expression {expr} and return its result converted
6515 to Vim data structures. Second {expr} may hold additional
6516 argument accessible as _A inside first {expr}.
6517 Strings are returned as they are.
6518 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006519 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006520 Dictionaries and lists obtained by vim.eval() are returned
6521 as-is.
6522 Other objects are returned as zero without any errors.
6523 See |lua-luaeval| for more details.
6524 Note that in a `:def` function local variables are not visible
6525 to {expr}.
6526
6527 Can also be used as a |method|: >
6528 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006529<
6530 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006531
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006532 {only available when compiled with the |+lua| feature}
6533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006534
6535map({expr1}, {expr2}) *map()*
6536 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006537 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006538 item in {expr1} with the result of evaluating {expr2}.
6539 For a |Blob| each byte is replaced.
6540 For a |String|, each character, including composing
6541 characters, is replaced.
6542 If the item type changes you may want to use |mapnew()| to
6543 create a new List or Dictionary. This is required when using
6544 Vim9 script.
6545
6546 {expr2} must be a |String| or |Funcref|.
6547
6548 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6549 of the current item. For a |Dictionary| |v:key| has the key
6550 of the current item and for a |List| |v:key| has the index of
6551 the current item. For a |Blob| |v:key| has the index of the
6552 current byte. For a |String| |v:key| has the index of the
6553 current character.
6554 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006555 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006556< This puts "> " before and " <" after each item in "mylist".
6557
6558 Note that {expr2} is the result of an expression and is then
6559 used as an expression again. Often it is good to use a
6560 |literal-string| to avoid having to double backslashes. You
6561 still have to double ' quotes
6562
6563 If {expr2} is a |Funcref| it is called with two arguments:
6564 1. The key or the index of the current item.
6565 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006566 With a legacy script lambda you don't get an error if it only
6567 accepts one argument, but with a Vim9 lambda you get "E1106:
6568 One argument too many", the number of arguments must match.
6569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006570 The function must return the new value of the item. Example
6571 that changes each value by "key-value": >
6572 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006573 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006574 endfunc
6575 call map(myDict, function('KeyValue'))
6576< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006577 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006578< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006579 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006580< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006581 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006582<
6583 The operation is done in-place for a |List| and |Dictionary|.
6584 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006585 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006586
6587< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6588 or a new |Blob| or |String|.
6589 When an error is encountered while evaluating {expr2} no
6590 further items in {expr1} are processed.
6591 When {expr2} is a Funcref errors inside a function are ignored,
6592 unless it was defined with the "abort" flag.
6593
6594 Can also be used as a |method|: >
6595 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006596<
6597 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6598 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006599
6600
6601maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6602 When {dict} is omitted or zero: Return the rhs of mapping
6603 {name} in mode {mode}. The returned String has special
6604 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006605 listing. When {dict} is TRUE a dictionary is returned, see
6606 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006607
6608 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006609 returned if {dict} is FALSE, otherwise returns an empty Dict.
6610 When the mapping for {name} is empty, then "<Nop>" is
6611 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006612
6613 The {name} can have special key names, like in the ":map"
6614 command.
6615
6616 {mode} can be one of these strings:
6617 "n" Normal
6618 "v" Visual (including Select)
6619 "o" Operator-pending
6620 "i" Insert
6621 "c" Cmd-line
6622 "s" Select
6623 "x" Visual
6624 "l" langmap |language-mapping|
6625 "t" Terminal-Job
6626 "" Normal, Visual and Operator-pending
6627 When {mode} is omitted, the modes for "" are used.
6628
6629 When {abbr} is there and it is |TRUE| use abbreviations
6630 instead of mappings.
6631
6632 When {dict} is there and it is |TRUE| return a dictionary
6633 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006634 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006635 "lhs" The {lhs} of the mapping as it would be typed
6636 "lhsraw" The {lhs} of the mapping as raw bytes
6637 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6638 form, only present when it differs from "lhsraw"
6639 "rhs" The {rhs} of the mapping as typed.
6640 "silent" 1 for a |:map-silent| mapping, else 0.
6641 "noremap" 1 if the {rhs} of the mapping is not remappable.
6642 "script" 1 if mapping was defined with <script>.
6643 "expr" 1 for an expression mapping (|:map-<expr>|).
6644 "buffer" 1 for a buffer local mapping (|:map-local|).
6645 "mode" Modes for which the mapping is defined. In
6646 addition to the modes mentioned above, these
6647 characters will be used:
6648 " " Normal, Visual and Operator-pending
6649 "!" Insert and Commandline mode
6650 (|mapmode-ic|)
6651 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006652 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006653 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006654 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006655 "lnum" The line number in "sid", zero if unknown.
6656 "nowait" Do not wait for other, longer mappings.
6657 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006658 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006659 "mode_bits" Vim's internal binary representation of "mode".
6660 |mapset()| ignores this; only "mode" is used.
6661 See |maplist()| for usage examples. The values
6662 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006663
6664 The dictionary can be used to restore a mapping with
6665 |mapset()|.
6666
6667 The mappings local to the current buffer are checked first,
6668 then the global mappings.
6669 This function can be used to map a key even when it's already
6670 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006671 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006672
6673< Can also be used as a |method|: >
6674 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006675<
6676 Return type: |String| or dict<any> depending on {dict}
6677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006678
6679mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6680 Check if there is a mapping that matches with {name} in mode
6681 {mode}. See |maparg()| for {mode} and special names in
6682 {name}.
6683 When {abbr} is there and it is |TRUE| use abbreviations
6684 instead of mappings.
6685 A match happens with a mapping that starts with {name} and
6686 with a mapping which is equal to the start of {name}.
6687
6688 matches mapping "a" "ab" "abc" ~
6689 mapcheck("a") yes yes yes
6690 mapcheck("abc") yes yes yes
6691 mapcheck("ax") yes no no
6692 mapcheck("b") no no no
6693
6694 The difference with maparg() is that mapcheck() finds a
6695 mapping that matches with {name}, while maparg() only finds a
6696 mapping for {name} exactly.
6697 When there is no mapping that starts with {name}, an empty
6698 String is returned. If there is one, the RHS of that mapping
6699 is returned. If there are several mappings that start with
6700 {name}, the RHS of one of them is returned. This will be
6701 "<Nop>" if the RHS is empty.
6702 The mappings local to the current buffer are checked first,
6703 then the global mappings.
6704 This function can be used to check if a mapping can be added
6705 without being ambiguous. Example: >
6706 :if mapcheck("_vv") == ""
6707 : map _vv :set guifont=7x13<CR>
6708 :endif
6709< This avoids adding the "_vv" mapping when there already is a
6710 mapping for "_v" or for "_vvv".
6711
6712 Can also be used as a |method|: >
6713 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006714<
6715 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006716
6717
Ernie Rael09661202022-04-25 14:40:44 +01006718maplist([{abbr}]) *maplist()*
6719 Returns a |List| of all mappings. Each List item is a |Dict|,
6720 the same as what is returned by |maparg()|, see
6721 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6722 abbreviations instead of mappings.
6723
6724 Example to show all mappings with 'MultiMatch' in rhs: >
6725 vim9script
6726 echo maplist()->filter(
6727 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006728< It can be tricky to find mappings for particular |:map-modes|.
6729 |mapping-dict|'s "mode_bits" can simplify this. For example,
6730 the mode_bits for Normal, Insert or Command-line modes are
6731 0x19. To find all the mappings available in those modes you
6732 can do: >
6733 vim9script
6734 var saved_maps = []
6735 for m in maplist()
6736 if and(m.mode_bits, 0x19) != 0
6737 saved_maps->add(m)
6738 endif
6739 endfor
6740 echo saved_maps->mapnew((_, m) => m.lhs)
6741< The values of the mode_bits are defined in Vim's src/vim.h
6742 file and they can be discovered at runtime using
6743 |:map-commands| and "maplist()". Example: >
6744 vim9script
6745 omap xyzzy <Nop>
6746 var op_bit = maplist()->filter(
6747 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6748 ounmap xyzzy
6749 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006750<
6751 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006752
6753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006754mapnew({expr1}, {expr2}) *mapnew()*
6755 Like |map()| but instead of replacing items in {expr1} a new
6756 List or Dictionary is created and returned. {expr1} remains
6757 unchanged. Items can still be changed by {expr2}, if you
6758 don't want that use |deepcopy()| first.
6759
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006760 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6761 depending on {expr1}
6762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006763
6764mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006765mapset({dict})
6766 Restore a mapping from a dictionary, possibly returned by
6767 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6768 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006769 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006770 feature allows copying mappings from one buffer to another.
6771 The dict.mode value may restore a single mapping that covers
6772 more than one mode, like with mode values of '!', ' ', 'nox',
6773 or 'v'. *E1276*
6774
6775 In the first form, {mode} and {abbr} should be the same as
6776 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006777 {mode} is used to define the mode in which the mapping is set,
6778 not the "mode" entry in {dict}.
6779 Example for saving and restoring a mapping: >
6780 let save_map = maparg('K', 'n', 0, 1)
6781 nnoremap K somethingelse
6782 ...
6783 call mapset('n', 0, save_map)
6784< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006785 e.g. with `:map!`, you need to save/restore the mapping for
6786 all of them, when they might differ.
6787
6788 In the second form, with {dict} as the only argument, mode
6789 and abbr are taken from the dict.
6790 Example: >
6791 vim9script
6792 var save_maps = maplist()->filter(
6793 (_, m) => m.lhs == 'K')
6794 nnoremap K somethingelse
6795 cnoremap K somethingelse2
6796 # ...
6797 unmap K
6798 for d in save_maps
6799 mapset(d)
6800 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006801<
6802 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006803
6804
6805match({expr}, {pat} [, {start} [, {count}]]) *match()*
6806 When {expr} is a |List| then this returns the index of the
6807 first item where {pat} matches. Each item is used as a
6808 String, |Lists| and |Dictionaries| are used as echoed.
6809
6810 Otherwise, {expr} is used as a String. The result is a
6811 Number, which gives the index (byte offset) in {expr} where
6812 {pat} matches.
6813
6814 A match at the first character or |List| item returns zero.
6815 If there is no match -1 is returned.
6816
6817 For getting submatches see |matchlist()|.
6818 Example: >
6819 :echo match("testing", "ing") " results in 4
6820 :echo match([1, 'x'], '\a') " results in 1
6821< See |string-match| for how {pat} is used.
6822 *strpbrk()*
6823 Vim doesn't have a strpbrk() function. But you can do: >
6824 :let sepidx = match(line, '[.,;: \t]')
6825< *strcasestr()*
6826 Vim doesn't have a strcasestr() function. But you can add
6827 "\c" to the pattern to ignore case: >
6828 :let idx = match(haystack, '\cneedle')
6829<
6830 If {start} is given, the search starts from byte index
6831 {start} in a String or item {start} in a |List|.
6832 The result, however, is still the index counted from the
6833 first character/item. Example: >
6834 :echo match("testing", "ing", 2)
6835< result is again "4". >
6836 :echo match("testing", "ing", 4)
6837< result is again "4". >
6838 :echo match("testing", "t", 2)
6839< result is "3".
6840 For a String, if {start} > 0 then it is like the string starts
6841 {start} bytes later, thus "^" will match at {start}. Except
6842 when {count} is given, then it's like matches before the
6843 {start} byte are ignored (this is a bit complicated to keep it
6844 backwards compatible).
6845 For a String, if {start} < 0, it will be set to 0. For a list
6846 the index is counted from the end.
6847 If {start} is out of range ({start} > strlen({expr}) for a
6848 String or {start} > len({expr}) for a |List|) -1 is returned.
6849
6850 When {count} is given use the {count}'th match. When a match
6851 is found in a String the search for the next one starts one
6852 character further. Thus this example results in 1: >
6853 echo match("testing", "..", 0, 2)
6854< In a |List| the search continues in the next item.
6855 Note that when {count} is added the way {start} works changes,
6856 see above.
6857
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006858 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006859 See |pattern| for the patterns that are accepted.
6860 The 'ignorecase' option is used to set the ignore-caseness of
6861 the pattern. 'smartcase' is NOT used. The matching is always
6862 done like 'magic' is set and 'cpoptions' is empty.
6863 Note that a match at the start is preferred, thus when the
6864 pattern is using "*" (any number of matches) it tends to find
6865 zero matches at the start instead of a number of matches
6866 further down in the text.
6867
6868 Can also be used as a |method|: >
6869 GetText()->match('word')
6870 GetList()->match('word')
6871<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006872 Return type: |Number|
6873
6874
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006875 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006876matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6877 Defines a pattern to be highlighted in the current window (a
6878 "match"). It will be highlighted with {group}. Returns an
6879 identification number (ID), which can be used to delete the
6880 match using |matchdelete()|. The ID is bound to the window.
6881 Matching is case sensitive and magic, unless case sensitivity
6882 or magicness are explicitly overridden in {pattern}. The
6883 'magic', 'smartcase' and 'ignorecase' options are not used.
6884 The "Conceal" value is special, it causes the match to be
6885 concealed.
6886
6887 The optional {priority} argument assigns a priority to the
6888 match. A match with a high priority will have its
6889 highlighting overrule that of a match with a lower priority.
6890 A priority is specified as an integer (negative numbers are no
6891 exception). If the {priority} argument is not specified, the
6892 default priority is 10. The priority of 'hlsearch' is zero,
6893 hence all matches with a priority greater than zero will
6894 overrule it. Syntax highlighting (see 'syntax') is a separate
6895 mechanism, and regardless of the chosen priority a match will
6896 always overrule syntax highlighting.
6897
6898 The optional {id} argument allows the request for a specific
6899 match ID. If a specified ID is already taken, an error
6900 message will appear and the match will not be added. An ID
6901 is specified as a positive integer (zero excluded). IDs 1, 2
6902 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006903 respectively. 3 is reserved for use by the |matchparen|
6904 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006905 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006906 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006907
6908 The optional {dict} argument allows for further custom
6909 values. Currently this is used to specify a match specific
6910 conceal character that will be shown for |hl-Conceal|
6911 highlighted matches. The dict can have the following members:
6912
6913 conceal Special character to show instead of the
6914 match (only for |hl-Conceal| highlighted
6915 matches, see |:syn-cchar|)
6916 window Instead of the current window use the
6917 window with this number or window ID.
6918
6919 The number of matches is not limited, as it is the case with
6920 the |:match| commands.
6921
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006922 Returns -1 on error.
6923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006924 Example: >
6925 :highlight MyGroup ctermbg=green guibg=green
6926 :let m = matchadd("MyGroup", "TODO")
6927< Deletion of the pattern: >
6928 :call matchdelete(m)
6929
6930< A list of matches defined by |matchadd()| and |:match| are
6931 available from |getmatches()|. All matches can be deleted in
6932 one operation by |clearmatches()|.
6933
6934 Can also be used as a |method|: >
6935 GetGroup()->matchadd('TODO')
6936<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006937 Return type: |Number|
6938
6939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006940 *matchaddpos()*
6941matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6942 Same as |matchadd()|, but requires a list of positions {pos}
6943 instead of a pattern. This command is faster than |matchadd()|
6944 because it does not require to handle regular expressions and
6945 sets buffer line boundaries to redraw screen. It is supposed
6946 to be used when fast match additions and deletions are
6947 required, for example to highlight matching parentheses.
6948
6949 {pos} is a list of positions. Each position can be one of
6950 these:
6951 - A number. This whole line will be highlighted. The first
6952 line has number 1.
6953 - A list with one number, e.g., [23]. The whole line with this
6954 number will be highlighted.
6955 - A list with two numbers, e.g., [23, 11]. The first number is
6956 the line number, the second one is the column number (first
6957 column is 1, the value must correspond to the byte index as
6958 |col()| would return). The character at this position will
6959 be highlighted.
6960 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6961 the third number gives the length of the highlight in bytes.
6962
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006963 Returns -1 on error.
6964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006965 Example: >
6966 :highlight MyGroup ctermbg=green guibg=green
6967 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6968< Deletion of the pattern: >
6969 :call matchdelete(m)
6970
6971< Matches added by |matchaddpos()| are returned by
6972 |getmatches()|.
6973
6974 Can also be used as a |method|: >
6975 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006976<
6977 Return type: |Number|
6978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006979
6980matcharg({nr}) *matcharg()*
6981 Selects the {nr} match item, as set with a |:match|,
6982 |:2match| or |:3match| command.
6983 Return a |List| with two elements:
6984 The name of the highlight group used
6985 The pattern used.
6986 When {nr} is not 1, 2 or 3 returns an empty |List|.
6987 When there is no match item set returns ['', ''].
6988 This is useful to save and restore a |:match|.
6989 Highlighting matches using the |:match| commands are limited
6990 to three matches. |matchadd()| does not have this limitation.
6991
6992 Can also be used as a |method|: >
6993 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006994<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006995 Return type: list<string>
6996
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006997 *matchbufline()*
6998matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6999 Returns the |List| of matches in lines from {lnum} to {end} in
7000 buffer {buf} where {pat} matches.
7001
7002 {lnum} and {end} can either be a line number or the string "$"
7003 to refer to the last line in {buf}.
7004
7005 The {dict} argument supports following items:
7006 submatches include submatch information (|/\(|)
7007
7008 For each match, a |Dict| with the following items is returned:
7009 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007010 lnum line number where there is a match
7011 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007012 Note that there can be multiple matches in a single line.
7013
7014 This function works only for loaded buffers. First call
7015 |bufload()| if needed.
7016
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007017 See |match-pattern| for information about the effect of some
7018 option settings on the pattern.
7019
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007020 When {buf} is not a valid buffer, the buffer is not loaded or
7021 {lnum} or {end} is not valid then an error is given and an
7022 empty |List| is returned.
7023
7024 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007025 " Assuming line 3 in buffer 5 contains "a"
7026 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7027 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7028 " Assuming line 4 in buffer 10 contains "tik tok"
7029 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7030 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007031<
7032 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007033 "\1", "\2", etc. are also returned. Example: >
7034 " Assuming line 2 in buffer 2 contains "acd"
7035 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007036 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007037 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007038< The "submatches" List always contains 9 items. If a submatch
7039 is not found, then an empty string is returned for that
7040 submatch.
7041
7042 Can also be used as a |method|: >
7043 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007044<
7045 Return type: list<dict<any>> or list<any>
7046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007047
7048matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
7049 Deletes a match with ID {id} previously defined by |matchadd()|
7050 or one of the |:match| commands. Returns 0 if successful,
7051 otherwise -1. See example for |matchadd()|. All matches can
7052 be deleted in one operation by |clearmatches()|.
7053 If {win} is specified, use the window with this number or
7054 window ID instead of the current window.
7055
7056 Can also be used as a |method|: >
7057 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007058<
7059 Return type: |Number|
7060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007061
7062matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7063 Same as |match()|, but return the index of first character
7064 after the match. Example: >
7065 :echo matchend("testing", "ing")
7066< results in "7".
7067 *strspn()* *strcspn()*
7068 Vim doesn't have a strspn() or strcspn() function, but you can
7069 do it with matchend(): >
7070 :let span = matchend(line, '[a-zA-Z]')
7071 :let span = matchend(line, '[^a-zA-Z]')
7072< Except that -1 is returned when there are no matches.
7073
7074 The {start}, if given, has the same meaning as for |match()|. >
7075 :echo matchend("testing", "ing", 2)
7076< results in "7". >
7077 :echo matchend("testing", "ing", 5)
7078< result is "-1".
7079 When {expr} is a |List| the result is equal to |match()|.
7080
7081 Can also be used as a |method|: >
7082 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007083<
7084 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007085
7086
7087matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7088 If {list} is a list of strings, then returns a |List| with all
7089 the strings in {list} that fuzzy match {str}. The strings in
7090 the returned list are sorted based on the matching score.
7091
7092 The optional {dict} argument always supports the following
7093 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007094 matchseq When this item is present return only matches
7095 that contain the characters in {str} in the
7096 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007097 limit Maximum number of matches in {list} to be
7098 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007099
7100 If {list} is a list of dictionaries, then the optional {dict}
7101 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007102 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007103 {str}. The value of this item should be a
7104 string.
7105 text_cb |Funcref| that will be called for every item
7106 in {list} to get the text for fuzzy matching.
7107 This should accept a dictionary item as the
7108 argument and return the text for that item to
7109 use for fuzzy matching.
7110
7111 {str} is treated as a literal string and regular expression
7112 matching is NOT supported. The maximum supported {str} length
7113 is 256.
7114
7115 When {str} has multiple words each separated by white space,
7116 then the list of strings that have all the words is returned.
7117
7118 If there are no matching strings or there is an error, then an
7119 empty list is returned. If length of {str} is greater than
7120 256, then returns an empty list.
7121
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007122 When {limit} is given, matchfuzzy() will find up to this
7123 number of matches in {list} and return them in sorted order.
7124
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007125 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007126 matching strings.
7127
7128 Example: >
7129 :echo matchfuzzy(["clay", "crow"], "cay")
7130< results in ["clay"]. >
7131 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7132< results in a list of buffer names fuzzy matching "ndl". >
7133 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7134< results in a list of buffer information dicts with buffer
7135 names fuzzy matching "ndl". >
7136 :echo getbufinfo()->matchfuzzy("spl",
7137 \ {'text_cb' : {v -> v.name}})
7138< results in a list of buffer information dicts with buffer
7139 names fuzzy matching "spl". >
7140 :echo v:oldfiles->matchfuzzy("test")
7141< results in a list of file names fuzzy matching "test". >
7142 :let l = readfile("buffer.c")->matchfuzzy("str")
7143< results in a list of lines in "buffer.c" fuzzy matching "str". >
7144 :echo ['one two', 'two one']->matchfuzzy('two one')
7145< results in ['two one', 'one two']. >
7146 :echo ['one two', 'two one']->matchfuzzy('two one',
7147 \ {'matchseq': 1})
7148< results in ['two one'].
7149
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007150 Return type: list<string> or list<any>
7151
7152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007153matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7154 Same as |matchfuzzy()|, but returns the list of matched
7155 strings, the list of character positions where characters
7156 in {str} matches and a list of matching scores. You can
7157 use |byteidx()| to convert a character position to a byte
7158 position.
7159
7160 If {str} matches multiple times in a string, then only the
7161 positions for the best match is returned.
7162
7163 If there are no matching strings or there is an error, then a
7164 list with three empty list items is returned.
7165
7166 Example: >
7167 :echo matchfuzzypos(['testing'], 'tsg')
7168< results in [['testing'], [[0, 2, 6]], [99]] >
7169 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7170< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7171 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7172< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7173
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007174 Return type: list<list<any>>
7175
7176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007177matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7178 Same as |match()|, but return a |List|. The first item in the
7179 list is the matched string, same as what matchstr() would
7180 return. Following items are submatches, like "\1", "\2", etc.
7181 in |:substitute|. When an optional submatch didn't match an
7182 empty string is used. Example: >
7183 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7184< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7185 When there is no match an empty list is returned.
7186
7187 You can pass in a List, but that is not very useful.
7188
7189 Can also be used as a |method|: >
7190 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007191<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007192 Return type: list<string> or list<any>
7193
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007194 *matchstrlist()*
7195matchstrlist({list}, {pat} [, {dict}])
7196 Returns the |List| of matches in {list} where {pat} matches.
7197 {list} is a |List| of strings. {pat} is matched against each
7198 string in {list}.
7199
7200 The {dict} argument supports following items:
7201 submatches include submatch information (|/\(|)
7202
7203 For each match, a |Dict| with the following items is returned:
7204 byteidx starting byte index of the match.
7205 idx index in {list} of the match.
7206 text matched string
7207 submatches a List of submatches. Present only if
7208 "submatches" is set to v:true in {dict}.
7209
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007210 See |match-pattern| for information about the effect of some
7211 option settings on the pattern.
7212
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007213 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007214 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7215 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7216 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7217 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007218<
7219 If "submatches" is present and is v:true, then submatches like
7220 "\1", "\2", etc. are also returned. Example: >
7221 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7222 \ #{submatches: v:true})
7223 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7224< The "submatches" List always contains 9 items. If a submatch
7225 is not found, then an empty string is returned for that
7226 submatch.
7227
7228 Can also be used as a |method|: >
7229 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007230<
7231 Return type: list<dict<any>> or list<any>
7232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007233
7234matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7235 Same as |match()|, but return the matched string. Example: >
7236 :echo matchstr("testing", "ing")
7237< results in "ing".
7238 When there is no match "" is returned.
7239 The {start}, if given, has the same meaning as for |match()|. >
7240 :echo matchstr("testing", "ing", 2)
7241< results in "ing". >
7242 :echo matchstr("testing", "ing", 5)
7243< result is "".
7244 When {expr} is a |List| then the matching item is returned.
7245 The type isn't changed, it's not necessarily a String.
7246
7247 Can also be used as a |method|: >
7248 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007249<
7250 Return type: |String|
7251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007252
7253matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7254 Same as |matchstr()|, but return the matched string, the start
7255 position and the end position of the match. Example: >
7256 :echo matchstrpos("testing", "ing")
7257< results in ["ing", 4, 7].
7258 When there is no match ["", -1, -1] is returned.
7259 The {start}, if given, has the same meaning as for |match()|. >
7260 :echo matchstrpos("testing", "ing", 2)
7261< results in ["ing", 4, 7]. >
7262 :echo matchstrpos("testing", "ing", 5)
7263< result is ["", -1, -1].
7264 When {expr} is a |List| then the matching item, the index
7265 of first item where {pat} matches, the start position and the
7266 end position of the match are returned. >
7267 :echo matchstrpos([1, '__x'], '\a')
7268< result is ["x", 1, 2, 3].
7269 The type isn't changed, it's not necessarily a String.
7270
7271 Can also be used as a |method|: >
7272 GetText()->matchstrpos('word')
7273<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007274 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007275
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007276
7277max({expr}) *max()*
7278 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007279 echo max([apples, pears, oranges])
7280
7281< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7282 it returns the maximum of all values in the Dictionary.
7283 If {expr} is neither a List nor a Dictionary, or one of the
7284 items in {expr} cannot be used as a Number this results in
7285 an error. An empty |List| or |Dictionary| results in zero.
7286
7287 Can also be used as a |method|: >
7288 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007289<
7290 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007291
7292
7293menu_info({name} [, {mode}]) *menu_info()*
7294 Return information about the specified menu {name} in
7295 mode {mode}. The menu name should be specified without the
7296 shortcut character ('&'). If {name} is "", then the top-level
7297 menu names are returned.
7298
7299 {mode} can be one of these strings:
7300 "n" Normal
7301 "v" Visual (including Select)
7302 "o" Operator-pending
7303 "i" Insert
7304 "c" Cmd-line
7305 "s" Select
7306 "x" Visual
7307 "t" Terminal-Job
7308 "" Normal, Visual and Operator-pending
7309 "!" Insert and Cmd-line
7310 When {mode} is omitted, the modes for "" are used.
7311
7312 Returns a |Dictionary| containing the following items:
7313 accel menu item accelerator text |menu-text|
7314 display display name (name without '&')
7315 enabled v:true if this menu item is enabled
7316 Refer to |:menu-enable|
7317 icon name of the icon file (for toolbar)
7318 |toolbar-icon|
7319 iconidx index of a built-in icon
7320 modes modes for which the menu is defined. In
7321 addition to the modes mentioned above, these
7322 characters will be used:
7323 " " Normal, Visual and Operator-pending
7324 name menu item name.
7325 noremenu v:true if the {rhs} of the menu item is not
7326 remappable else v:false.
7327 priority menu order priority |menu-priority|
7328 rhs right-hand-side of the menu item. The returned
7329 string has special characters translated like
7330 in the output of the ":menu" command listing.
7331 When the {rhs} of a menu item is empty, then
7332 "<Nop>" is returned.
7333 script v:true if script-local remapping of {rhs} is
7334 allowed else v:false. See |:menu-script|.
7335 shortcut shortcut key (character after '&' in
7336 the menu name) |menu-shortcut|
7337 silent v:true if the menu item is created
7338 with <silent> argument |:menu-silent|
7339 submenus |List| containing the names of
7340 all the submenus. Present only if the menu
7341 item has submenus.
7342
7343 Returns an empty dictionary if the menu item is not found.
7344
7345 Examples: >
7346 :echo menu_info('Edit.Cut')
7347 :echo menu_info('File.Save', 'n')
7348
7349 " Display the entire menu hierarchy in a buffer
7350 func ShowMenu(name, pfx)
7351 let m = menu_info(a:name)
7352 call append(line('$'), a:pfx .. m.display)
7353 for child in m->get('submenus', [])
7354 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7355 \ a:pfx .. ' ')
7356 endfor
7357 endfunc
7358 new
7359 for topmenu in menu_info('').submenus
7360 call ShowMenu(topmenu, '')
7361 endfor
7362<
7363 Can also be used as a |method|: >
7364 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007365<
7366 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007368min({expr}) *min()*
7369 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007370 echo min([apples, pears, oranges])
7371
7372< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7373 it returns the minimum of all values in the Dictionary.
7374 If {expr} is neither a List nor a Dictionary, or one of the
7375 items in {expr} cannot be used as a Number this results in
7376 an error. An empty |List| or |Dictionary| results in zero.
7377
7378 Can also be used as a |method|: >
7379 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007380<
7381 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007382
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007383
7384mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007385 Create directory {name}.
7386
Bram Moolenaar938ae282023-02-20 20:44:55 +00007387 When {flags} is present it must be a string. An empty string
7388 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007389
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007390 {flags} can contain these character flags:
7391 "p" intermediate directories will be created as necessary
7392 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007393 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007394 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007395 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007396
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007397 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007398 some directories may already exist. Only the first one that
7399 is created and what it contains is scheduled to be deleted.
7400 E.g. when using: >
7401 call mkdir('subdir/tmp/autoload', 'pR')
7402< and "subdir" already exists then "subdir/tmp" will be
7403 scheduled for deletion, like with: >
7404 defer delete('subdir/tmp', 'rf')
7405< Note that if scheduling the defer fails the directory is not
7406 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007407
7408 If {prot} is given it is used to set the protection bits of
7409 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7410 the user, readable for others). Use 0o700 to make it
7411 unreadable for others. This is only used for the last part of
7412 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7413 created with 0o755.
7414 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007415 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007416
7417< This function is not available in the |sandbox|.
7418
7419 There is no error if the directory already exists and the "p"
7420 flag is passed (since patch 8.0.1708). However, without the
7421 "p" option the call will fail.
7422
7423 The function result is a Number, which is TRUE if the call was
7424 successful or FALSE if the directory creation failed or partly
7425 failed.
7426
7427 Not available on all systems. To check use: >
7428 :if exists("*mkdir")
7429
7430< Can also be used as a |method|: >
7431 GetName()->mkdir()
7432<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007433 Return type: |Number|
7434
7435
7436mode([{expr}]) *mode()*
7437 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007438 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007439 a non-empty String (|non-zero-arg|), then the full mode is
7440 returned, otherwise only the first letter is returned.
7441 Also see |state()|.
7442
7443 n Normal
7444 no Operator-pending
7445 nov Operator-pending (forced characterwise |o_v|)
7446 noV Operator-pending (forced linewise |o_V|)
7447 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7448 CTRL-V is one character
7449 niI Normal using |i_CTRL-O| in |Insert-mode|
7450 niR Normal using |i_CTRL-O| in |Replace-mode|
7451 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7452 nt Terminal-Normal (insert goes to Terminal-Job mode)
7453 v Visual by character
7454 vs Visual by character using |v_CTRL-O| in Select mode
7455 V Visual by line
7456 Vs Visual by line using |v_CTRL-O| in Select mode
7457 CTRL-V Visual blockwise
7458 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7459 s Select by character
7460 S Select by line
7461 CTRL-S Select blockwise
7462 i Insert
7463 ic Insert mode completion |compl-generic|
7464 ix Insert mode |i_CTRL-X| completion
7465 R Replace |R|
7466 Rc Replace mode completion |compl-generic|
7467 Rx Replace mode |i_CTRL-X| completion
7468 Rv Virtual Replace |gR|
7469 Rvc Virtual Replace mode completion |compl-generic|
7470 Rvx Virtual Replace mode |i_CTRL-X| completion
7471 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007472 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007473 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007474 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007475 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007476 ce Normal Ex mode |Q|
7477 r Hit-enter prompt
7478 rm The -- more -- prompt
7479 r? A |:confirm| query of some sort
7480 ! Shell or external command is executing
7481 t Terminal-Job mode: keys go to the job
7482
7483 This is useful in the 'statusline' option or when used
7484 with |remote_expr()| In most other places it always returns
7485 "c" or "n".
7486 Note that in the future more modes and more specific modes may
7487 be added. It's better not to compare the whole string but only
7488 the leading character(s).
7489 Also see |visualmode()|.
7490
7491 Can also be used as a |method|: >
7492 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007493<
7494 Return type: |String|
7495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007496
7497mzeval({expr}) *mzeval()*
7498 Evaluate MzScheme expression {expr} and return its result
7499 converted to Vim data structures.
7500 Numbers and strings are returned as they are.
7501 Pairs (including lists and improper lists) and vectors are
7502 returned as Vim |Lists|.
7503 Hash tables are represented as Vim |Dictionary| type with keys
7504 converted to strings.
7505 All other types are converted to string with display function.
7506 Examples: >
7507 :mz (define l (list 1 2 3))
7508 :mz (define h (make-hash)) (hash-set! h "list" l)
7509 :echo mzeval("l")
7510 :echo mzeval("h")
7511<
7512 Note that in a `:def` function local variables are not visible
7513 to {expr}.
7514
7515 Can also be used as a |method|: >
7516 GetExpr()->mzeval()
7517<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007518 Return type: any, depending on {expr}
7519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007520 {only available when compiled with the |+mzscheme| feature}
7521
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007523nextnonblank({lnum}) *nextnonblank()*
7524 Return the line number of the first line at or below {lnum}
7525 that is not blank. Example: >
7526 if getline(nextnonblank(1)) =~ "Java"
7527< When {lnum} is invalid or there is no non-blank line at or
7528 below it, zero is returned.
7529 {lnum} is used like with |getline()|.
7530 See also |prevnonblank()|.
7531
7532 Can also be used as a |method|: >
7533 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007534<
7535 Return type: |Number|
7536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007537
7538nr2char({expr} [, {utf8}]) *nr2char()*
7539 Return a string with a single character, which has the number
7540 value {expr}. Examples: >
7541 nr2char(64) returns "@"
7542 nr2char(32) returns " "
7543< When {utf8} is omitted or zero, the current 'encoding' is used.
7544 Example for "utf-8": >
7545 nr2char(300) returns I with bow character
7546< When {utf8} is TRUE, always return UTF-8 characters.
7547 Note that a NUL character in the file is specified with
7548 nr2char(10), because NULs are represented with newline
7549 characters. nr2char(0) is a real NUL and terminates the
7550 string, thus results in an empty string.
7551 To turn a list of character numbers into a string: >
7552 let list = [65, 66, 67]
7553 let str = join(map(list, {_, val -> nr2char(val)}), '')
7554< Result: "ABC"
7555
7556 Can also be used as a |method|: >
7557 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007558<
7559 Return type: |String|
7560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007561
7562or({expr}, {expr}) *or()*
7563 Bitwise OR on the two arguments. The arguments are converted
7564 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007565 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007566 Example: >
7567 :let bits = or(bits, 0x80)
7568< Can also be used as a |method|: >
7569 :let bits = bits->or(0x80)
7570
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007571< Rationale: The reason this is a function and not using the "|"
7572 character like many languages, is that Vi has always used "|"
7573 to separate commands. In many places it would not be clear if
7574 "|" is an operator or a command separator.
7575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007576 Return type: |Number|
7577
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007578
7579pathshorten({path} [, {len}]) *pathshorten()*
7580 Shorten directory names in the path {path} and return the
7581 result. The tail, the file name, is kept as-is. The other
7582 components in the path are reduced to {len} letters in length.
7583 If {len} is omitted or smaller than 1 then 1 is used (single
7584 letters). Leading '~' and '.' characters are kept. Examples: >
7585 :echo pathshorten('~/.vim/autoload/myfile.vim')
7586< ~/.v/a/myfile.vim ~
7587>
7588 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7589< ~/.vi/au/myfile.vim ~
7590 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007591 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007592
7593 Can also be used as a |method|: >
7594 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007595<
7596 Return type: |String|
7597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007598
7599perleval({expr}) *perleval()*
7600 Evaluate Perl expression {expr} in scalar context and return
7601 its result converted to Vim data structures. If value can't be
7602 converted, it is returned as a string Perl representation.
7603 Note: If you want an array or hash, {expr} must return a
7604 reference to it.
7605 Example: >
7606 :echo perleval('[1 .. 4]')
7607< [1, 2, 3, 4]
7608
7609 Note that in a `:def` function local variables are not visible
7610 to {expr}.
7611
7612 Can also be used as a |method|: >
7613 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007614<
7615 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007616
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007617 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007618
7619
7620popup_ functions are documented here: |popup-functions|
7621
7622
7623pow({x}, {y}) *pow()*
7624 Return the power of {x} to the exponent {y} as a |Float|.
7625 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007626 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007627 Examples: >
7628 :echo pow(3, 3)
7629< 27.0 >
7630 :echo pow(2, 16)
7631< 65536.0 >
7632 :echo pow(32, 0.20)
7633< 2.0
7634
7635 Can also be used as a |method|: >
7636 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007637<
7638 Return type: |Number|
7639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007640
7641prevnonblank({lnum}) *prevnonblank()*
7642 Return the line number of the first line at or above {lnum}
7643 that is not blank. Example: >
7644 let ind = indent(prevnonblank(v:lnum - 1))
7645< When {lnum} is invalid or there is no non-blank line at or
7646 above it, zero is returned.
7647 {lnum} is used like with |getline()|.
7648 Also see |nextnonblank()|.
7649
7650 Can also be used as a |method|: >
7651 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007652<
7653 Return type: |Number|
7654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007655
7656printf({fmt}, {expr1} ...) *printf()*
7657 Return a String with {fmt}, where "%" items are replaced by
7658 the formatted form of their respective arguments. Example: >
7659 printf("%4d: E%d %.30s", lnum, errno, msg)
7660< May result in:
7661 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7662
7663 When used as a |method| the base is passed as the second
7664 argument: >
7665 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007666<
7667 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007668
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007669 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007670 %s string
7671 %6S string right-aligned in 6 display cells
7672 %6s string right-aligned in 6 bytes
7673 %.9s string truncated to 9 bytes
7674 %c single byte
7675 %d decimal number
7676 %5d decimal number padded with spaces to 5 characters
7677 %x hex number
7678 %04x hex number padded with zeros to at least 4 characters
7679 %X hex number using upper case letters
7680 %o octal number
7681 %08b binary number padded with zeros to at least 8 chars
7682 %f floating point number as 12.23, inf, -inf or nan
7683 %F floating point number as 12.23, INF, -INF or NAN
7684 %e floating point number as 1.23e3, inf, -inf or nan
7685 %E floating point number as 1.23E3, INF, -INF or NAN
7686 %g floating point number, as %f or %e depending on value
7687 %G floating point number, as %F or %E depending on value
7688 %% the % character itself
7689
7690 Conversion specifications start with '%' and end with the
7691 conversion type. All other characters are copied unchanged to
7692 the result.
7693
7694 The "%" starts a conversion specification. The following
7695 arguments appear in sequence:
7696
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007697 % [pos-argument] [flags] [field-width] [.precision] type
7698
7699 pos-argument
7700 At most one positional argument specifier. These
7701 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007702
7703 flags
7704 Zero or more of the following flags:
7705
7706 # The value should be converted to an "alternate
7707 form". For c, d, and s conversions, this option
7708 has no effect. For o conversions, the precision
7709 of the number is increased to force the first
7710 character of the output string to a zero (except
7711 if a zero value is printed with an explicit
7712 precision of zero).
7713 For b and B conversions, a non-zero result has
7714 the string "0b" (or "0B" for B conversions)
7715 prepended to it.
7716 For x and X conversions, a non-zero result has
7717 the string "0x" (or "0X" for X conversions)
7718 prepended to it.
7719
7720 0 (zero) Zero padding. For all conversions the converted
7721 value is padded on the left with zeros rather
7722 than blanks. If a precision is given with a
7723 numeric conversion (d, b, B, o, x, and X), the 0
7724 flag is ignored.
7725
7726 - A negative field width flag; the converted value
7727 is to be left adjusted on the field boundary.
7728 The converted value is padded on the right with
7729 blanks, rather than on the left with blanks or
7730 zeros. A - overrides a 0 if both are given.
7731
7732 ' ' (space) A blank should be left before a positive
7733 number produced by a signed conversion (d).
7734
7735 + A sign must always be placed before a number
7736 produced by a signed conversion. A + overrides
7737 a space if both are used.
7738
7739 field-width
7740 An optional decimal digit string specifying a minimum
7741 field width. If the converted value has fewer bytes
7742 than the field width, it will be padded with spaces on
7743 the left (or right, if the left-adjustment flag has
7744 been given) to fill out the field width. For the S
7745 conversion the count is in cells.
7746
7747 .precision
7748 An optional precision, in the form of a period '.'
7749 followed by an optional digit string. If the digit
7750 string is omitted, the precision is taken as zero.
7751 This gives the minimum number of digits to appear for
7752 d, o, x, and X conversions, the maximum number of
7753 bytes to be printed from a string for s conversions,
7754 or the maximum number of cells to be printed from a
7755 string for S conversions.
7756 For floating point it is the number of digits after
7757 the decimal point.
7758
7759 type
7760 A character that specifies the type of conversion to
7761 be applied, see below.
7762
7763 A field width or precision, or both, may be indicated by an
7764 asterisk '*' instead of a digit string. In this case, a
7765 Number argument supplies the field width or precision. A
7766 negative field width is treated as a left adjustment flag
7767 followed by a positive field width; a negative precision is
7768 treated as though it were missing. Example: >
7769 :echo printf("%d: %.*s", nr, width, line)
7770< This limits the length of the text used from "line" to
7771 "width" bytes.
7772
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007773 If the argument to be formatted is specified using a
7774 positional argument specifier, and a '*' is used to indicate
7775 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007776 precision, the argument(s) to be used must also be specified
7777 using a {n$} positional argument specifier. See |printf-$|.
7778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007779 The conversion specifiers and their meanings are:
7780
7781 *printf-d* *printf-b* *printf-B* *printf-o*
7782 *printf-x* *printf-X*
7783 dbBoxX The Number argument is converted to signed decimal
7784 (d), unsigned binary (b and B), unsigned octal (o), or
7785 unsigned hexadecimal (x and X) notation. The letters
7786 "abcdef" are used for x conversions; the letters
7787 "ABCDEF" are used for X conversions.
7788 The precision, if any, gives the minimum number of
7789 digits that must appear; if the converted value
7790 requires fewer digits, it is padded on the left with
7791 zeros.
7792 In no case does a non-existent or small field width
7793 cause truncation of a numeric field; if the result of
7794 a conversion is wider than the field width, the field
7795 is expanded to contain the conversion result.
7796 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007797 The 'l' modifier indicates the argument is a long
7798 integer. The size will be 32 bits or 64 bits
7799 depending on your platform.
7800 The "ll" modifier indicates the argument is 64 bits.
7801 The b and B conversion specifiers never take a width
7802 modifier and always assume their argument is a 64 bit
7803 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007804 Generally, these modifiers are not useful. They are
7805 ignored when type is known from the argument.
7806
7807 i alias for d
7808 D alias for ld
7809 U alias for lu
7810 O alias for lo
7811
7812 *printf-c*
7813 c The Number argument is converted to a byte, and the
7814 resulting character is written.
7815
7816 *printf-s*
7817 s The text of the String argument is used. If a
7818 precision is specified, no more bytes than the number
7819 specified are used.
7820 If the argument is not a String type, it is
7821 automatically converted to text with the same format
7822 as ":echo".
7823 *printf-S*
7824 S The text of the String argument is used. If a
7825 precision is specified, no more display cells than the
7826 number specified are used.
7827
7828 *printf-f* *E807*
7829 f F The Float argument is converted into a string of the
7830 form 123.456. The precision specifies the number of
7831 digits after the decimal point. When the precision is
7832 zero the decimal point is omitted. When the precision
7833 is not specified 6 is used. A really big number
7834 (out of range or dividing by zero) results in "inf"
7835 or "-inf" with %f (INF or -INF with %F).
7836 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7837 Example: >
7838 echo printf("%.2f", 12.115)
7839< 12.12
7840 Note that roundoff depends on the system libraries.
7841 Use |round()| when in doubt.
7842
7843 *printf-e* *printf-E*
7844 e E The Float argument is converted into a string of the
7845 form 1.234e+03 or 1.234E+03 when using 'E'. The
7846 precision specifies the number of digits after the
7847 decimal point, like with 'f'.
7848
7849 *printf-g* *printf-G*
7850 g G The Float argument is converted like with 'f' if the
7851 value is between 0.001 (inclusive) and 10000000.0
7852 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7853 for 'G'. When no precision is specified superfluous
7854 zeroes and '+' signs are removed, except for the zero
7855 immediately after the decimal point. Thus 10000000.0
7856 results in 1.0e7.
7857
7858 *printf-%*
7859 % A '%' is written. No argument is converted. The
7860 complete conversion specification is "%%".
7861
7862 When a Number argument is expected a String argument is also
7863 accepted and automatically converted.
7864 When a Float or String argument is expected a Number argument
7865 is also accepted and automatically converted.
7866 Any other argument type results in an error message.
7867
7868 *E766* *E767*
7869 The number of {exprN} arguments must exactly match the number
7870 of "%" items. If there are not sufficient or too many
7871 arguments an error is given. Up to 18 arguments can be used.
7872
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007873 *printf-$*
7874 In certain languages, error and informative messages are
7875 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007876 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007877 having a different word order, positional arguments may be
7878 used to indicate this. For instance: >
7879
h_east596a9f22023-11-21 21:24:23 +09007880 #, c-format
7881 msgid "%s returning %s"
7882 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007883<
h_east596a9f22023-11-21 21:24:23 +09007884 In this example, the sentence has its 2 string arguments
7885 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007886
h_east596a9f22023-11-21 21:24:23 +09007887 echo printf(
7888 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7889 "Bram", "Moolenaar")
7890< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007891
h_east596a9f22023-11-21 21:24:23 +09007892 echo printf(
7893 "In Belgium, vim's creator's name is: %2$s %1$s",
7894 "Bram", "Moolenaar")
7895< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007896
7897 Width (and precision) can be specified using the '*' specifier.
7898 In this case, you must specify the field width position in the
7899 argument list. >
7900
h_east596a9f22023-11-21 21:24:23 +09007901 echo printf("%1$*2$.*3$d", 1, 2, 3)
7902< 001 >
7903 echo printf("%2$*3$.*1$d", 1, 2, 3)
7904< 2 >
7905 echo printf("%3$*1$.*2$d", 1, 2, 3)
7906< 03 >
7907 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7908< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007909
7910 You can mix specifying the width and/or precision directly
7911 and via positional arguments: >
7912
h_east596a9f22023-11-21 21:24:23 +09007913 echo printf("%1$4.*2$f", 1.4142135, 6)
7914< 1.414214 >
7915 echo printf("%1$*2$.4f", 1.4142135, 6)
7916< 1.4142 >
7917 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7918< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007919
Christ van Willegenc35fc032024-03-14 18:30:41 +01007920 You will get an overflow error |E1510|, when the field-width
7921 or precision will result in a string longer than 6400 chars.
7922
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007923 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007924 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007925 echo printf("%s%1$s", "One", "Two")
7926< E1500: Cannot mix positional and non-positional arguments:
7927 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007928
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007929 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007930 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007931 echo printf("%3$s%1$s", "One", "Two", "Three")
7932< E1501: format argument 2 unused in $-style format:
7933 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007934
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007935 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007936 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007937 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7938< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007939
7940 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007941 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7942< E1502: Positional argument 2 used as field width reused as
7943 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007944
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007945 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007946 When a positional argument is used, but not the correct number
7947 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007948 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7949< E1503: Positional argument 3 out of bounds: %1$d at width
7950 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007951
7952 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007953 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7954< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7955 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007956
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007957 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007958 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007959 echo printf("%1$s %2$s %1$s", "One", "Two")
7960< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007961
7962 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007963 echo printf("%1$s %2$s %1$d", "One", "Two")
7964< E1504: Positional argument 1 type used inconsistently:
7965 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007966
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007967 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007968 Various other errors that lead to a format string being
7969 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007970 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7971< E1505: Invalid format specifier: %1$d at width %2$d is:
7972 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007973
Christ van Willegenea746f92023-10-05 20:48:36 +02007974 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007975 This internal error indicates that the logic to parse a
7976 positional format argument ran into a problem that couldn't be
7977 otherwise reported. Please file a bug against Vim if you run
7978 into this, copying the exact format string and parameters that
7979 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007980
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007981 Return type: |String|
7982
Christ van Willegenea746f92023-10-05 20:48:36 +02007983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007984prompt_getprompt({buf}) *prompt_getprompt()*
7985 Returns the effective prompt text for buffer {buf}. {buf} can
7986 be a buffer name or number. See |prompt-buffer|.
7987
7988 If the buffer doesn't exist or isn't a prompt buffer, an empty
7989 string is returned.
7990
7991 Can also be used as a |method|: >
7992 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007993<
7994 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007995
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007996 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007997
7998
7999prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8000 Set prompt callback for buffer {buf} to {expr}. When {expr}
8001 is an empty string the callback is removed. This has only
8002 effect if {buf} has 'buftype' set to "prompt".
8003
8004 The callback is invoked when pressing Enter. The current
8005 buffer will always be the prompt buffer. A new line for a
8006 prompt is added before invoking the callback, thus the prompt
8007 for which the callback was invoked will be in the last but one
8008 line.
8009 If the callback wants to add text to the buffer, it must
8010 insert it above the last line, since that is where the current
8011 prompt is. This can also be done asynchronously.
8012 The callback is invoked with one argument, which is the text
8013 that was entered at the prompt. This can be an empty string
8014 if the user only typed Enter.
8015 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008016 func s:TextEntered(text)
8017 if a:text == 'exit' || a:text == 'quit'
8018 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008019 " Reset 'modified' to allow the buffer to be closed.
8020 " We assume there is nothing useful to be saved.
8021 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008022 close
8023 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008024 " Do something useful with "a:text". In this example
8025 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008026 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008027 endif
8028 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008029 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008030
8031< Can also be used as a |method|: >
8032 GetBuffer()->prompt_setcallback(callback)
8033
8034< {only available when compiled with the |+channel| feature}
8035
8036prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8037 Set a callback for buffer {buf} to {expr}. When {expr} is an
8038 empty string the callback is removed. This has only effect if
8039 {buf} has 'buftype' set to "prompt".
8040
8041 This callback will be invoked when pressing CTRL-C in Insert
8042 mode. Without setting a callback Vim will exit Insert mode,
8043 as in any buffer.
8044
8045 Can also be used as a |method|: >
8046 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008047<
8048 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008049
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008050 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008051
8052prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8053 Set prompt for buffer {buf} to {text}. You most likely want
8054 {text} to end in a space.
8055 The result is only visible if {buf} has 'buftype' set to
8056 "prompt". Example: >
8057 call prompt_setprompt(bufnr(), 'command: ')
8058<
8059 Can also be used as a |method|: >
8060 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008061<
8062 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008063
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008064 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008065
8066prop_ functions are documented here: |text-prop-functions|
8067
8068pum_getpos() *pum_getpos()*
8069 If the popup menu (see |ins-completion-menu|) is not visible,
8070 returns an empty |Dictionary|, otherwise, returns a
8071 |Dictionary| with the following keys:
8072 height nr of items visible
8073 width screen cells
8074 row top screen row (0 first row)
8075 col leftmost screen column (0 first col)
8076 size total nr of items
8077 scrollbar |TRUE| if scrollbar is visible
8078
8079 The values are the same as in |v:event| during
8080 |CompleteChanged|.
8081
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008082 Return type: dict<any>
8083
8084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008085pumvisible() *pumvisible()*
8086 Returns non-zero when the popup menu is visible, zero
8087 otherwise. See |ins-completion-menu|.
8088 This can be used to avoid some things that would remove the
8089 popup menu.
8090
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008091 Return type: |Number|
8092
8093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008094py3eval({expr}) *py3eval()*
8095 Evaluate Python expression {expr} and return its result
8096 converted to Vim data structures.
8097 Numbers and strings are returned as they are (strings are
8098 copied though, Unicode strings are additionally converted to
8099 'encoding').
8100 Lists are represented as Vim |List| type.
8101 Dictionaries are represented as Vim |Dictionary| type with
8102 keys converted to strings.
8103 Note that in a `:def` function local variables are not visible
8104 to {expr}.
8105
8106 Can also be used as a |method|: >
8107 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008108<
8109 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008110
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008111 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008112
8113 *E858* *E859*
8114pyeval({expr}) *pyeval()*
8115 Evaluate Python expression {expr} and return its result
8116 converted to Vim data structures.
8117 Numbers and strings are returned as they are (strings are
8118 copied though).
8119 Lists are represented as Vim |List| type.
8120 Dictionaries are represented as Vim |Dictionary| type,
8121 non-string keys result in error.
8122 Note that in a `:def` function local variables are not visible
8123 to {expr}.
8124
8125 Can also be used as a |method|: >
8126 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008127<
8128 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008129
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008130 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008131
8132pyxeval({expr}) *pyxeval()*
8133 Evaluate Python expression {expr} and return its result
8134 converted to Vim data structures.
8135 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8136 See also: |pyeval()|, |py3eval()|
8137
8138 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008139 < GetExpr()->pyxeval()
8140<
8141 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008142
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008143 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008144 |+python3| feature}
8145
8146rand([{expr}]) *rand()* *random*
8147 Return a pseudo-random Number generated with an xoshiro128**
8148 algorithm using seed {expr}. The returned number is 32 bits,
8149 also on 64 bits systems, for consistency.
8150 {expr} can be initialized by |srand()| and will be updated by
8151 rand(). If {expr} is omitted, an internal seed value is used
8152 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008153 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008154
8155 Examples: >
8156 :echo rand()
8157 :let seed = srand()
8158 :echo rand(seed)
8159 :echo rand(seed) % 16 " random number 0 - 15
8160<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008161 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008162
8163 *E726* *E727*
8164range({expr} [, {max} [, {stride}]]) *range()*
8165 Returns a |List| with Numbers:
8166 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8167 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8168 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8169 {max}] (increasing {expr} with {stride} each time, not
8170 producing a value past {max}).
8171 When the maximum is one before the start the result is an
8172 empty list. When the maximum is more than one before the
8173 start this is an error.
8174 Examples: >
8175 range(4) " [0, 1, 2, 3]
8176 range(2, 4) " [2, 3, 4]
8177 range(2, 9, 3) " [2, 5, 8]
8178 range(2, -2, -1) " [2, 1, 0, -1, -2]
8179 range(0) " []
8180 range(2, 0) " error!
8181<
8182 Can also be used as a |method|: >
8183 GetExpr()->range()
8184<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008185 Return type: list<number>
8186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008187
K.Takata11df3ae2022-10-19 14:02:40 +01008188readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008189 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008190 If {offset} is specified, read the file from the specified
8191 offset. If it is a negative value, it is used as an offset
8192 from the end of the file. E.g., to read the last 12 bytes: >
8193 readblob('file.bin', -12)
8194< If {size} is specified, only the specified size will be read.
8195 E.g. to read the first 100 bytes of a file: >
8196 readblob('file.bin', 0, 100)
8197< If {size} is -1 or omitted, the whole data starting from
8198 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008199 This can be also used to read the data from a character device
8200 on Unix when {size} is explicitly set. Only if the device
8201 supports seeking {offset} can be used. Otherwise it should be
8202 zero. E.g. to read 10 bytes from a serial console: >
8203 readblob('/dev/ttyS0', 0, 10)
8204< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008205 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008206 When the offset is beyond the end of the file the result is an
8207 empty blob.
8208 When trying to read more bytes than are available the result
8209 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008210 Also see |readfile()| and |writefile()|.
8211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008212 Return type: |Blob|
8213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008214
8215readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8216 Return a list with file and directory names in {directory}.
8217 You can also use |glob()| if you don't need to do complicated
8218 things, such as limiting the number of matches.
8219 The list will be sorted (case sensitive), see the {dict}
8220 argument below for changing the sort order.
8221
8222 When {expr} is omitted all entries are included.
8223 When {expr} is given, it is evaluated to check what to do:
8224 If {expr} results in -1 then no further entries will
8225 be handled.
8226 If {expr} results in 0 then this entry will not be
8227 added to the list.
8228 If {expr} results in 1 then this entry will be added
8229 to the list.
8230 The entries "." and ".." are always excluded.
8231 Each time {expr} is evaluated |v:val| is set to the entry name.
8232 When {expr} is a function the name is passed as the argument.
8233 For example, to get a list of files ending in ".txt": >
8234 readdir(dirname, {n -> n =~ '.txt$'})
8235< To skip hidden and backup files: >
8236 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008237< *E857*
8238 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008239 values. Currently this is used to specify if and how sorting
8240 should be performed. The dict can have the following members:
8241
8242 sort How to sort the result returned from the system.
8243 Valid values are:
8244 "none" do not sort (fastest method)
8245 "case" sort case sensitive (byte value of
8246 each character, technically, using
8247 strcmp()) (default)
8248 "icase" sort case insensitive (technically
8249 using strcasecmp())
8250 "collate" sort using the collation order
8251 of the "POSIX" or "C" |locale|
8252 (technically using strcoll())
8253 Other values are silently ignored.
8254
8255 For example, to get a list of all files in the current
8256 directory without sorting the individual entries: >
8257 readdir('.', '1', #{sort: 'none'})
8258< If you want to get a directory tree: >
8259 function! s:tree(dir)
8260 return {a:dir : map(readdir(a:dir),
8261 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008262 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008263 endfunction
8264 echo s:tree(".")
8265<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008266 Returns an empty List on error.
8267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008268 Can also be used as a |method|: >
8269 GetDirName()->readdir()
8270<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008271 Return type: list<string> or list<any>
8272
8273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008274readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8275 Extended version of |readdir()|.
8276 Return a list of Dictionaries with file and directory
8277 information in {directory}.
8278 This is useful if you want to get the attributes of file and
8279 directory at the same time as getting a list of a directory.
8280 This is much faster than calling |readdir()| then calling
8281 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8282 each file and directory especially on MS-Windows.
8283 The list will by default be sorted by name (case sensitive),
8284 the sorting can be changed by using the optional {dict}
8285 argument, see |readdir()|.
8286
8287 The Dictionary for file and directory information has the
8288 following items:
8289 group Group name of the entry. (Only on Unix)
8290 name Name of the entry.
8291 perm Permissions of the entry. See |getfperm()|.
8292 size Size of the entry. See |getfsize()|.
8293 time Timestamp of the entry. See |getftime()|.
8294 type Type of the entry.
8295 On Unix, almost same as |getftype()| except:
8296 Symlink to a dir "linkd"
8297 Other symlink "link"
8298 On MS-Windows:
8299 Normal file "file"
8300 Directory "dir"
8301 Junction "junction"
8302 Symlink to a dir "linkd"
8303 Other symlink "link"
8304 Other reparse point "reparse"
8305 user User name of the entry's owner. (Only on Unix)
8306 On Unix, if the entry is a symlink, the Dictionary includes
8307 the information of the target (except the "type" item).
8308 On MS-Windows, it includes the information of the symlink
8309 itself because of performance reasons.
8310
8311 When {expr} is omitted all entries are included.
8312 When {expr} is given, it is evaluated to check what to do:
8313 If {expr} results in -1 then no further entries will
8314 be handled.
8315 If {expr} results in 0 then this entry will not be
8316 added to the list.
8317 If {expr} results in 1 then this entry will be added
8318 to the list.
8319 The entries "." and ".." are always excluded.
8320 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8321 of the entry.
8322 When {expr} is a function the entry is passed as the argument.
8323 For example, to get a list of files ending in ".txt": >
8324 readdirex(dirname, {e -> e.name =~ '.txt$'})
8325<
8326 For example, to get a list of all files in the current
8327 directory without sorting the individual entries: >
8328 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008329<
8330 Can also be used as a |method|: >
8331 GetDirName()->readdirex()
8332<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008333 Return type: list<dict<any>> or list<any>
8334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335
8336 *readfile()*
8337readfile({fname} [, {type} [, {max}]])
8338 Read file {fname} and return a |List|, each line of the file
8339 as an item. Lines are broken at NL characters. Macintosh
8340 files separated with CR will result in a single long line
8341 (unless a NL appears somewhere).
8342 All NUL characters are replaced with a NL character.
8343 When {type} contains "b" binary mode is used:
8344 - When the last line ends in a NL an extra empty list item is
8345 added.
8346 - No CR characters are removed.
8347 Otherwise:
8348 - CR characters that appear before a NL are removed.
8349 - Whether the last line ends in a NL or not does not matter.
8350 - When 'encoding' is Unicode any UTF-8 byte order mark is
8351 removed from the text.
8352 When {max} is given this specifies the maximum number of lines
8353 to be read. Useful if you only want to check the first ten
8354 lines of a file: >
8355 :for line in readfile(fname, '', 10)
8356 : if line =~ 'Date' | echo line | endif
8357 :endfor
8358< When {max} is negative -{max} lines from the end of the file
8359 are returned, or as many as there are.
8360 When {max} is zero the result is an empty list.
8361 Note that without {max} the whole file is read into memory.
8362 Also note that there is no recognition of encoding. Read a
8363 file into a buffer if you need to.
8364 Deprecated (use |readblob()| instead): When {type} contains
8365 "B" a |Blob| is returned with the binary data of the file
8366 unmodified.
8367 When the file can't be opened an error message is given and
8368 the result is an empty list.
8369 Also see |writefile()|.
8370
8371 Can also be used as a |method|: >
8372 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008373<
8374 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008375
8376reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8377 {func} is called for every item in {object}, which can be a
8378 |String|, |List| or a |Blob|. {func} is called with two
8379 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008380 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008381
8382 {initial} is the initial result. When omitted, the first item
8383 in {object} is used and {func} is first called for the second
8384 item. If {initial} is not given and {object} is empty no
8385 result can be computed, an E998 error is given.
8386
8387 Examples: >
8388 echo reduce([1, 3, 5], { acc, val -> acc + val })
8389 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8390 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8391 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8392<
8393 Can also be used as a |method|: >
8394 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008395<
8396 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8397 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008398
8399
8400reg_executing() *reg_executing()*
8401 Returns the single letter name of the register being executed.
8402 Returns an empty string when no register is being executed.
8403 See |@|.
8404
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008405 Return type: |String|
8406
8407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008408reg_recording() *reg_recording()*
8409 Returns the single letter name of the register being recorded.
8410 Returns an empty string when not recording. See |q|.
8411
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008412 Return type: |String|
8413
8414
8415reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008416reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008417reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008418 Return an item that represents a time value. The item is a
8419 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008420 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008421 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008422 string or |reltimefloat()| to convert to a Float. For
8423 example, to see the time spent in function Work(): >
8424 var startTime = reltime()
8425 Work()
8426 echo startTime->reltime()->reltimestr()
8427<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008428 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008429 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008430 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008431 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008432 specified in the argument.
8433 With two arguments it returns the time passed between {start}
8434 and {end}.
8435
8436 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008437 reltime(). If there is an error an empty List is returned in
8438 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008439
8440 Can also be used as a |method|: >
8441 GetStart()->reltime()
8442<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008443 Return type: list<number>
8444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008445 {only available when compiled with the |+reltime| feature}
8446
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008448reltimefloat({time}) *reltimefloat()*
8449 Return a Float that represents the time value of {time}.
8450 Example: >
8451 let start = reltime()
8452 call MyFunction()
8453 let seconds = reltimefloat(reltime(start))
8454< See the note of reltimestr() about overhead.
8455 Also see |profiling|.
8456 If there is an error 0.0 is returned in legacy script, in Vim9
8457 script an error is given.
8458
8459 Can also be used as a |method|: >
8460 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008461<
8462 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008463
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008464 {only available when compiled with the |+reltime| feature}
8465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008466
8467reltimestr({time}) *reltimestr()*
8468 Return a String that represents the time value of {time}.
8469 This is the number of seconds, a dot and the number of
8470 microseconds. Example: >
8471 let start = reltime()
8472 call MyFunction()
8473 echo reltimestr(reltime(start))
8474< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008475 The accuracy depends on the system. Use reltimefloat() for the
8476 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008477 Leading spaces are used to make the string align nicely. You
8478 can use split() to remove it. >
8479 echo split(reltimestr(reltime(start)))[0]
8480< Also see |profiling|.
8481 If there is an error an empty string is returned in legacy
8482 script, in Vim9 script an error is given.
8483
8484 Can also be used as a |method|: >
8485 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008486<
8487 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008488
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008489 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008490
8491 *remote_expr()* *E449*
8492remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008493 Send the {string} to {server}. The {server} argument is a
8494 string, also see |{server}|.
8495
8496 The string is sent as an expression and the result is returned
8497 after evaluation. The result must be a String or a |List|. A
8498 |List| is turned into a String by joining the items with a
8499 line break in between (not at the end), like with join(expr,
8500 "\n").
8501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008502 If {idvar} is present and not empty, it is taken as the name
8503 of a variable and a {serverid} for later use with
8504 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008506 If {timeout} is given the read times out after this many
8507 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008509 See also |clientserver| |RemoteReply|.
8510 This function is not available in the |sandbox|.
8511 {only available when compiled with the |+clientserver| feature}
8512 Note: Any errors will cause a local error message to be issued
8513 and the result will be the empty string.
8514
8515 Variables will be evaluated in the global namespace,
8516 independent of a function currently being active. Except
8517 when in debug mode, then local function variables and
8518 arguments can be evaluated.
8519
8520 Examples: >
8521 :echo remote_expr("gvim", "2+2")
8522 :echo remote_expr("gvim1", "b:current_syntax")
8523<
8524 Can also be used as a |method|: >
8525 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008526<
8527 Return type: |String| or list<{type}>
8528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008529
8530remote_foreground({server}) *remote_foreground()*
8531 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008532 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008533 This works like: >
8534 remote_expr({server}, "foreground()")
8535< Except that on Win32 systems the client does the work, to work
8536 around the problem that the OS doesn't always allow the server
8537 to bring itself to the foreground.
8538 Note: This does not restore the window if it was minimized,
8539 like foreground() does.
8540 This function is not available in the |sandbox|.
8541
8542 Can also be used as a |method|: >
8543 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008544<
8545 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008546
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008547 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008548 Win32 console version}
8549
8550
8551remote_peek({serverid} [, {retvar}]) *remote_peek()*
8552 Returns a positive number if there are available strings
8553 from {serverid}. Copies any reply string into the variable
8554 {retvar} if specified. {retvar} must be a string with the
8555 name of a variable.
8556 Returns zero if none are available.
8557 Returns -1 if something is wrong.
8558 See also |clientserver|.
8559 This function is not available in the |sandbox|.
8560 {only available when compiled with the |+clientserver| feature}
8561 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008562 :let repl = ""
8563 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008564
8565< Can also be used as a |method|: >
8566 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008567<
8568 Return type: |Number|
8569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008570
8571remote_read({serverid}, [{timeout}]) *remote_read()*
8572 Return the oldest available reply from {serverid} and consume
8573 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008574 reply is available. Returns an empty string, if a reply is
8575 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008576 See also |clientserver|.
8577 This function is not available in the |sandbox|.
8578 {only available when compiled with the |+clientserver| feature}
8579 Example: >
8580 :echo remote_read(id)
8581
8582< Can also be used as a |method|: >
8583 ServerId()->remote_read()
8584<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008585 Return type: |String|
8586
8587
8588remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008589 Send the {string} to {server}. The {server} argument is a
8590 string, also see |{server}|.
8591
8592 The string is sent as input keys and the function returns
8593 immediately. At the Vim server the keys are not mapped
8594 |:map|.
8595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008596 If {idvar} is present, it is taken as the name of a variable
8597 and a {serverid} for later use with remote_read() is stored
8598 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600 See also |clientserver| |RemoteReply|.
8601 This function is not available in the |sandbox|.
8602 {only available when compiled with the |+clientserver| feature}
8603
8604 Note: Any errors will be reported in the server and may mess
8605 up the display.
8606 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008607 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008608 \ remote_read(serverid)
8609
8610 :autocmd NONE RemoteReply *
8611 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008612 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008613 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8614<
8615 Can also be used as a |method|: >
8616 ServerName()->remote_send(keys)
8617<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008618 Return type: |String|
8619
8620
8621remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008622 Become the server {name}. {name} must be a non-empty string.
8623 This fails if already running as a server, when |v:servername|
8624 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008625
8626 Can also be used as a |method|: >
8627 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008628<
8629 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008630
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008631 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008632
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008633
8634remove({list}, {idx}) *remove()*
8635remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008636 Without {end}: Remove the item at {idx} from |List| {list} and
8637 return the item.
8638 With {end}: Remove items from {idx} to {end} (inclusive) and
8639 return a |List| with these items. When {idx} points to the same
8640 item as {end} a list with one item is returned. When {end}
8641 points to an item before {idx} this is an error.
8642 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008643 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008644 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008645 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008646 :call remove(mylist, 0, 9)
8647<
8648 Use |delete()| to remove a file.
8649
8650 Can also be used as a |method|: >
8651 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008652<
8653 Return type: any, depending on {list}
8654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008655
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008656remove({blob}, {idx})
8657remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008658 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8659 return the byte.
8660 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8661 return a |Blob| with these bytes. When {idx} points to the same
8662 byte as {end} a |Blob| with one byte is returned. When {end}
8663 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008664 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008666 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008667 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008668<
8669 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008670
8671remove({dict}, {key})
8672 Remove the entry from {dict} with key {key} and return it.
8673 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008674 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008675< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008676 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008677
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008678 Return type: any, depending on {dict}
8679
8680
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008681rename({from}, {to}) *rename()*
8682 Rename the file by the name {from} to the name {to}. This
8683 should also work to move files across file systems. The
8684 result is a Number, which is 0 if the file was renamed
8685 successfully, and non-zero when the renaming failed.
8686 NOTE: If {to} exists it is overwritten without warning.
8687 This function is not available in the |sandbox|.
8688
8689 Can also be used as a |method|: >
8690 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008691<
8692 Return type: |Number|
8693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008694
8695repeat({expr}, {count}) *repeat()*
8696 Repeat {expr} {count} times and return the concatenated
8697 result. Example: >
8698 :let separator = repeat('-', 80)
8699< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008700 When {expr} is a |List| or a |Blob| the result is {expr}
8701 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008702 :let longlist = repeat(['a', 'b'], 3)
8703< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8704
8705 Can also be used as a |method|: >
8706 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008707<
8708 Return type: |String|, |Blob| or list<{type}> depending on
8709 {expr}
8710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008711
8712resolve({filename}) *resolve()* *E655*
8713 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8714 returns the path the shortcut points to in a simplified form.
8715 When {filename} is a symbolic link or junction point, return
8716 the full path to the target. If the target of junction is
8717 removed, return {filename}.
8718 On Unix, repeat resolving symbolic links in all path
8719 components of {filename} and return the simplified result.
8720 To cope with link cycles, resolving of symbolic links is
8721 stopped after 100 iterations.
8722 On other systems, return the simplified {filename}.
8723 The simplification step is done as by |simplify()|.
8724 resolve() keeps a leading path component specifying the
8725 current directory (provided the result is still a relative
8726 path name) and also keeps a trailing path separator.
8727
8728 Can also be used as a |method|: >
8729 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008730<
8731 Return type: |String|
8732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008733
8734reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008735 Reverse the order of items in {object}. {object} can be a
8736 |List|, a |Blob| or a |String|. For a List and a Blob the
8737 items are reversed in-place and {object} is returned.
8738 For a String a new String is returned.
8739 Returns zero if {object} is not a List, Blob or a String.
8740 If you want a List or Blob to remain unmodified make a copy
8741 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008742 :let revlist = reverse(copy(mylist))
8743< Can also be used as a |method|: >
8744 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008745<
8746 Return type: |String|, |Blob| or list<{type}> depending on
8747 {object}
8748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008749
8750round({expr}) *round()*
8751 Round off {expr} to the nearest integral value and return it
8752 as a |Float|. If {expr} lies halfway between two integral
8753 values, then use the larger one (away from zero).
8754 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008755 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756 Examples: >
8757 echo round(0.456)
8758< 0.0 >
8759 echo round(4.5)
8760< 5.0 >
8761 echo round(-4.5)
8762< -5.0
8763
8764 Can also be used as a |method|: >
8765 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008766<
8767 Return type: |Float|
8768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008769
8770rubyeval({expr}) *rubyeval()*
8771 Evaluate Ruby expression {expr} and return its result
8772 converted to Vim data structures.
8773 Numbers, floats and strings are returned as they are (strings
8774 are copied though).
8775 Arrays are represented as Vim |List| type.
8776 Hashes are represented as Vim |Dictionary| type.
8777 Other objects are represented as strings resulted from their
8778 "Object#to_s" method.
8779 Note that in a `:def` function local variables are not visible
8780 to {expr}.
8781
8782 Can also be used as a |method|: >
8783 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008784<
8785 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008786
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008787 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008788
8789screenattr({row}, {col}) *screenattr()*
8790 Like |screenchar()|, but return the attribute. This is a rather
8791 arbitrary number that can only be used to compare to the
8792 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008793 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008794
8795 Can also be used as a |method|: >
8796 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008797<
8798 Return type: |Number|
8799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008800
8801screenchar({row}, {col}) *screenchar()*
8802 The result is a Number, which is the character at position
8803 [row, col] on the screen. This works for every possible
8804 screen position, also status lines, window separators and the
8805 command line. The top left position is row one, column one
8806 The character excludes composing characters. For double-byte
8807 encodings it may only be the first byte.
8808 This is mainly to be used for testing.
8809 Returns -1 when row or col is out of range.
8810
8811 Can also be used as a |method|: >
8812 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008813<
8814 Return type: |Number|
8815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008816
8817screenchars({row}, {col}) *screenchars()*
8818 The result is a |List| of Numbers. The first number is the same
8819 as what |screenchar()| returns. Further numbers are
8820 composing characters on top of the base character.
8821 This is mainly to be used for testing.
8822 Returns an empty List when row or col is out of range.
8823
8824 Can also be used as a |method|: >
8825 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008826<
8827 Return type: list<number> or list<any>
8828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008829
8830screencol() *screencol()*
8831 The result is a Number, which is the current screen column of
8832 the cursor. The leftmost column has number 1.
8833 This function is mainly used for testing.
8834
8835 Note: Always returns the current screen column, thus if used
8836 in a command (e.g. ":echo screencol()") it will return the
8837 column inside the command line, which is 1 when the command is
8838 executed. To get the cursor position in the file use one of
8839 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008840 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008841 nnoremap <silent> GG :echom screencol()<CR>
8842 nnoremap GG <Cmd>echom screencol()<CR>
8843<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008844 Return type: |Number|
8845
8846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008847screenpos({winid}, {lnum}, {col}) *screenpos()*
8848 The result is a Dict with the screen position of the text
8849 character in window {winid} at buffer line {lnum} and column
8850 {col}. {col} is a one-based byte index.
8851 The Dict has these members:
8852 row screen row
8853 col first screen column
8854 endcol last screen column
8855 curscol cursor screen column
8856 If the specified position is not visible, all values are zero.
8857 The "endcol" value differs from "col" when the character
8858 occupies more than one screen cell. E.g. for a Tab "col" can
8859 be 1 and "endcol" can be 8.
8860 The "curscol" value is where the cursor would be placed. For
8861 a Tab it would be the same as "endcol", while for a double
8862 width character it would be the same as "col".
8863 The |conceal| feature is ignored here, the column numbers are
8864 as if 'conceallevel' is zero. You can set the cursor to the
8865 right position and use |screencol()| to get the value with
8866 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008867 If the position is in a closed fold the screen position of the
8868 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008869 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008870
8871 Can also be used as a |method|: >
8872 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008873<
8874 Return type: dict<number> or dict<any>
8875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008876
8877screenrow() *screenrow()*
8878 The result is a Number, which is the current screen row of the
8879 cursor. The top line has number one.
8880 This function is mainly used for testing.
8881 Alternatively you can use |winline()|.
8882
8883 Note: Same restrictions as with |screencol()|.
8884
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008885 Return type: |Number|
8886
8887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008888screenstring({row}, {col}) *screenstring()*
8889 The result is a String that contains the base character and
8890 any composing characters at position [row, col] on the screen.
8891 This is like |screenchars()| but returning a String with the
8892 characters.
8893 This is mainly to be used for testing.
8894 Returns an empty String when row or col is out of range.
8895
8896 Can also be used as a |method|: >
8897 GetRow()->screenstring(col)
8898<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008899 Return type: |String|
8900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008901 *search()*
8902search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8903 Search for regexp pattern {pattern}. The search starts at the
8904 cursor position (you can use |cursor()| to set it).
8905
8906 When a match has been found its line number is returned.
8907 If there is no match a 0 is returned and the cursor doesn't
8908 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008909 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008910
8911 {flags} is a String, which can contain these character flags:
8912 'b' search Backward instead of forward
8913 'c' accept a match at the Cursor position
8914 'e' move to the End of the match
8915 'n' do Not move the cursor
8916 'p' return number of matching sub-Pattern (see below)
8917 's' Set the ' mark at the previous location of the cursor
8918 'w' Wrap around the end of the file
8919 'W' don't Wrap around the end of the file
8920 'z' start searching at the cursor column instead of zero
8921 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8922
8923 If the 's' flag is supplied, the ' mark is set, only if the
8924 cursor is moved. The 's' flag cannot be combined with the 'n'
8925 flag.
8926
8927 'ignorecase', 'smartcase' and 'magic' are used.
8928
8929 When the 'z' flag is not given, forward searching always
8930 starts in column zero and then matches before the cursor are
8931 skipped. When the 'c' flag is present in 'cpo' the next
8932 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008933 search starts one column after the start of the match. This
8934 matters for overlapping matches. See |cpo-c|. You can also
8935 insert "\ze" to change where the match ends, see |/\ze|.
8936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008937 When searching backwards and the 'z' flag is given then the
8938 search starts in column zero, thus no match in the current
8939 line will be found (unless wrapping around the end of the
8940 file).
8941
8942 When the {stopline} argument is given then the search stops
8943 after searching this line. This is useful to restrict the
8944 search to a range of lines. Examples: >
8945 let match = search('(', 'b', line("w0"))
8946 let end = search('END', '', line("w$"))
8947< When {stopline} is used and it is not zero this also implies
8948 that the search does not wrap around the end of the file.
8949 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008950 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008951 When the {timeout} argument is given the search stops when
8952 more than this many milliseconds have passed. Thus when
8953 {timeout} is 500 the search stops after half a second.
8954 The value must not be negative. A zero value is like not
8955 giving the argument.
8956 {only available when compiled with the |+reltime| feature}
8957
8958 If the {skip} expression is given it is evaluated with the
8959 cursor positioned on the start of a match. If it evaluates to
8960 non-zero this match is skipped. This can be used, for
8961 example, to skip a match in a comment or a string.
8962 {skip} can be a string, which is evaluated as an expression, a
8963 function reference or a lambda.
8964 When {skip} is omitted or empty, every match is accepted.
8965 When evaluating {skip} causes an error the search is aborted
8966 and -1 returned.
8967 *search()-sub-match*
8968 With the 'p' flag the returned value is one more than the
8969 first sub-match in \(\). One if none of them matched but the
8970 whole pattern did match.
8971 To get the column number too use |searchpos()|.
8972
8973 The cursor will be positioned at the match, unless the 'n'
8974 flag is used.
8975
8976 Example (goes over all files in the argument list): >
8977 :let n = 1
8978 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008979 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008980 : " start at the last char in the file and wrap for the
8981 : " first search to find match at start of file
8982 : normal G$
8983 : let flags = "w"
8984 : while search("foo", flags) > 0
8985 : s/foo/bar/g
8986 : let flags = "W"
8987 : endwhile
8988 : update " write the file if modified
8989 : let n = n + 1
8990 :endwhile
8991<
8992 Example for using some flags: >
8993 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8994< This will search for the keywords "if", "else", and "endif"
8995 under or after the cursor. Because of the 'p' flag, it
8996 returns 1, 2, or 3 depending on which keyword is found, or 0
8997 if the search fails. With the cursor on the first word of the
8998 line:
8999 if (foo == 0) | let foo = foo + 1 | endif ~
9000 the function returns 1. Without the 'c' flag, the function
9001 finds the "endif" and returns 3. The same thing happens
9002 without the 'e' flag if the cursor is on the "f" of "if".
9003 The 'n' flag tells the function not to move the cursor.
9004
9005 Can also be used as a |method|: >
9006 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009007<
9008 Return type: |Number|
9009
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009010
9011searchcount([{options}]) *searchcount()*
9012 Get or update the last search count, like what is displayed
9013 without the "S" flag in 'shortmess'. This works even if
9014 'shortmess' does contain the "S" flag.
9015
9016 This returns a |Dictionary|. The dictionary is empty if the
9017 previous pattern was not set and "pattern" was not specified.
9018
9019 key type meaning ~
9020 current |Number| current position of match;
9021 0 if the cursor position is
9022 before the first match
9023 exact_match |Boolean| 1 if "current" is matched on
9024 "pos", otherwise 0
9025 total |Number| total count of matches found
9026 incomplete |Number| 0: search was fully completed
9027 1: recomputing was timed out
9028 2: max count exceeded
9029
9030 For {options} see further down.
9031
9032 To get the last search count when |n| or |N| was pressed, call
9033 this function with `recompute: 0` . This sometimes returns
9034 wrong information because |n| and |N|'s maximum count is 99.
9035 If it exceeded 99 the result must be max count + 1 (100). If
9036 you want to get correct information, specify `recompute: 1`: >
9037
9038 " result == maxcount + 1 (100) when many matches
9039 let result = searchcount(#{recompute: 0})
9040
9041 " Below returns correct result (recompute defaults
9042 " to 1)
9043 let result = searchcount()
9044<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009045 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009046 function! LastSearchCount() abort
9047 let result = searchcount(#{recompute: 0})
9048 if empty(result)
9049 return ''
9050 endif
9051 if result.incomplete ==# 1 " timed out
9052 return printf(' /%s [?/??]', @/)
9053 elseif result.incomplete ==# 2 " max count exceeded
9054 if result.total > result.maxcount &&
9055 \ result.current > result.maxcount
9056 return printf(' /%s [>%d/>%d]', @/,
9057 \ result.current, result.total)
9058 elseif result.total > result.maxcount
9059 return printf(' /%s [%d/>%d]', @/,
9060 \ result.current, result.total)
9061 endif
9062 endif
9063 return printf(' /%s [%d/%d]', @/,
9064 \ result.current, result.total)
9065 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009066 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009067
9068 " Or if you want to show the count only when
9069 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009070 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009071 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9072<
9073 You can also update the search count, which can be useful in a
9074 |CursorMoved| or |CursorMovedI| autocommand: >
9075
9076 autocmd CursorMoved,CursorMovedI *
9077 \ let s:searchcount_timer = timer_start(
9078 \ 200, function('s:update_searchcount'))
9079 function! s:update_searchcount(timer) abort
9080 if a:timer ==# s:searchcount_timer
9081 call searchcount(#{
9082 \ recompute: 1, maxcount: 0, timeout: 100})
9083 redrawstatus
9084 endif
9085 endfunction
9086<
9087 This can also be used to count matched texts with specified
9088 pattern in the current buffer using "pattern": >
9089
9090 " Count '\<foo\>' in this buffer
9091 " (Note that it also updates search count)
9092 let result = searchcount(#{pattern: '\<foo\>'})
9093
9094 " To restore old search count by old pattern,
9095 " search again
9096 call searchcount()
9097<
9098 {options} must be a |Dictionary|. It can contain:
9099 key type meaning ~
9100 recompute |Boolean| if |TRUE|, recompute the count
9101 like |n| or |N| was executed.
9102 otherwise returns the last
9103 computed result (when |n| or
9104 |N| was used when "S" is not
9105 in 'shortmess', or this
9106 function was called).
9107 (default: |TRUE|)
9108 pattern |String| recompute if this was given
9109 and different with |@/|.
9110 this works as same as the
9111 below command is executed
9112 before calling this function >
9113 let @/ = pattern
9114< (default: |@/|)
9115 timeout |Number| 0 or negative number is no
9116 timeout. timeout milliseconds
9117 for recomputing the result
9118 (default: 0)
9119 maxcount |Number| 0 or negative number is no
9120 limit. max count of matched
9121 text while recomputing the
9122 result. if search exceeded
9123 total count, "total" value
9124 becomes `maxcount + 1`
9125 (default: 99)
9126 pos |List| `[lnum, col, off]` value
9127 when recomputing the result.
9128 this changes "current" result
9129 value. see |cursor()|,
9130 |getpos()|
9131 (default: cursor's position)
9132
9133 Can also be used as a |method|: >
9134 GetSearchOpts()->searchcount()
9135<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009136 Return type: dict<number>
9137
9138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009139searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9140 Search for the declaration of {name}.
9141
9142 With a non-zero {global} argument it works like |gD|, find
9143 first match in the file. Otherwise it works like |gd|, find
9144 first match in the function.
9145
9146 With a non-zero {thisblock} argument matches in a {} block
9147 that ends before the cursor position are ignored. Avoids
9148 finding variable declarations only valid in another scope.
9149
9150 Moves the cursor to the found match.
9151 Returns zero for success, non-zero for failure.
9152 Example: >
9153 if searchdecl('myvar') == 0
9154 echo getline('.')
9155 endif
9156<
9157 Can also be used as a |method|: >
9158 GetName()->searchdecl()
9159<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009160 Return type: |Number|
9161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009162 *searchpair()*
9163searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9164 [, {stopline} [, {timeout}]]]])
9165 Search for the match of a nested start-end pair. This can be
9166 used to find the "endif" that matches an "if", while other
9167 if/endif pairs in between are ignored.
9168 The search starts at the cursor. The default is to search
9169 forward, include 'b' in {flags} to search backward.
9170 If a match is found, the cursor is positioned at it and the
9171 line number is returned. If no match is found 0 or -1 is
9172 returned and the cursor doesn't move. No error message is
9173 given.
9174
9175 {start}, {middle} and {end} are patterns, see |pattern|. They
9176 must not contain \( \) pairs. Use of \%( \) is allowed. When
9177 {middle} is not empty, it is found when searching from either
9178 direction, but only when not in a nested start-end pair. A
9179 typical use is: >
9180 searchpair('\<if\>', '\<else\>', '\<endif\>')
9181< By leaving {middle} empty the "else" is skipped.
9182
9183 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9184 |search()|. Additionally:
9185 'r' Repeat until no more matches found; will find the
9186 outer pair. Implies the 'W' flag.
9187 'm' Return number of matches instead of line number with
9188 the match; will be > 1 when 'r' is used.
9189 Note: it's nearly always a good idea to use the 'W' flag, to
9190 avoid wrapping around the end of the file.
9191
9192 When a match for {start}, {middle} or {end} is found, the
9193 {skip} expression is evaluated with the cursor positioned on
9194 the start of the match. It should return non-zero if this
9195 match is to be skipped. E.g., because it is inside a comment
9196 or a string.
9197 When {skip} is omitted or empty, every match is accepted.
9198 When evaluating {skip} causes an error the search is aborted
9199 and -1 returned.
9200 {skip} can be a string, a lambda, a funcref or a partial.
9201 Anything else makes the function fail.
9202 In a `:def` function when the {skip} argument is a string
9203 constant it is compiled into instructions.
9204
9205 For {stopline} and {timeout} see |search()|.
9206
9207 The value of 'ignorecase' is used. 'magic' is ignored, the
9208 patterns are used like it's on.
9209
9210 The search starts exactly at the cursor. A match with
9211 {start}, {middle} or {end} at the next character, in the
9212 direction of searching, is the first one found. Example: >
9213 if 1
9214 if 2
9215 endif 2
9216 endif 1
9217< When starting at the "if 2", with the cursor on the "i", and
9218 searching forwards, the "endif 2" is found. When starting on
9219 the character just before the "if 2", the "endif 1" will be
9220 found. That's because the "if 2" will be found first, and
9221 then this is considered to be a nested if/endif from "if 2" to
9222 "endif 2".
9223 When searching backwards and {end} is more than one character,
9224 it may be useful to put "\zs" at the end of the pattern, so
9225 that when the cursor is inside a match with the end it finds
9226 the matching start.
9227
9228 Example, to find the "endif" command in a Vim script: >
9229
9230 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9231 \ 'getline(".") =~ "^\\s*\""')
9232
9233< The cursor must be at or after the "if" for which a match is
9234 to be found. Note that single-quote strings are used to avoid
9235 having to double the backslashes. The skip expression only
9236 catches comments at the start of a line, not after a command.
9237 Also, a word "en" or "if" halfway a line is considered a
9238 match.
9239 Another example, to search for the matching "{" of a "}": >
9240
9241 :echo searchpair('{', '', '}', 'bW')
9242
9243< This works when the cursor is at or before the "}" for which a
9244 match is to be found. To reject matches that syntax
9245 highlighting recognized as strings: >
9246
9247 :echo searchpair('{', '', '}', 'bW',
9248 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9249<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009250 Return type: |Number|
9251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009252 *searchpairpos()*
9253searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9254 [, {stopline} [, {timeout}]]]])
9255 Same as |searchpair()|, but returns a |List| with the line and
9256 column position of the match. The first element of the |List|
9257 is the line number and the second element is the byte index of
9258 the column position of the match. If no match is found,
9259 returns [0, 0]. >
9260
9261 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9262<
9263 See |match-parens| for a bigger and more useful example.
9264
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009265 Return type: list<number>
9266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009267 *searchpos()*
9268searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9269 Same as |search()|, but returns a |List| with the line and
9270 column position of the match. The first element of the |List|
9271 is the line number and the second element is the byte index of
9272 the column position of the match. If no match is found,
9273 returns [0, 0].
9274 Example: >
9275 :let [lnum, col] = searchpos('mypattern', 'n')
9276
9277< When the 'p' flag is given then there is an extra item with
9278 the sub-pattern match number |search()-sub-match|. Example: >
9279 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9280< In this example "submatch" is 2 when a lowercase letter is
9281 found |/\l|, 3 when an uppercase letter is found |/\u|.
9282
9283 Can also be used as a |method|: >
9284 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009285<
9286 Return type: list<number>
9287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009288
9289server2client({clientid}, {string}) *server2client()*
9290 Send a reply string to {clientid}. The most recent {clientid}
9291 that sent a string can be retrieved with expand("<client>").
9292 {only available when compiled with the |+clientserver| feature}
9293 Returns zero for success, -1 for failure.
9294 Note:
9295 This id has to be stored before the next command can be
9296 received. I.e. before returning from the received command and
9297 before calling any commands that waits for input.
9298 See also |clientserver|.
9299 Example: >
9300 :echo server2client(expand("<client>"), "HELLO")
9301
9302< Can also be used as a |method|: >
9303 GetClientId()->server2client(string)
9304<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009305 Return type: |Number|
9306
9307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009308serverlist() *serverlist()*
9309 Return a list of available server names, one per line.
9310 When there are no servers or the information is not available
9311 an empty string is returned. See also |clientserver|.
9312 {only available when compiled with the |+clientserver| feature}
9313 Example: >
9314 :echo serverlist()
9315<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009316 Return type: |String|
9317
9318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009319setbufline({buf}, {lnum}, {text}) *setbufline()*
9320 Set line {lnum} to {text} in buffer {buf}. This works like
9321 |setline()| for the specified buffer.
9322
9323 This function works only for loaded buffers. First call
9324 |bufload()| if needed.
9325
9326 To insert lines use |appendbufline()|.
9327 Any text properties in {lnum} are cleared.
9328
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009329 {text} can be a string to set one line, or a List of strings
9330 to set multiple lines. If the List extends below the last
9331 line then those lines are added. If the List is empty then
9332 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009333
9334 For the use of {buf}, see |bufname()| above.
9335
9336 {lnum} is used like with |setline()|.
9337 Use "$" to refer to the last line in buffer {buf}.
9338 When {lnum} is just below the last line the {text} will be
9339 added below the last line.
9340
9341 When {buf} is not a valid buffer, the buffer is not loaded or
9342 {lnum} is not valid then 1 is returned. In |Vim9| script an
9343 error is given.
9344 On success 0 is returned.
9345
9346 Can also be used as a |method|, the base is passed as the
9347 third argument: >
9348 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009349<
9350 Return type: |Number|
9351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009352
9353setbufvar({buf}, {varname}, {val}) *setbufvar()*
9354 Set option or local variable {varname} in buffer {buf} to
9355 {val}.
9356 This also works for a global or local window option, but it
9357 doesn't work for a global or local window variable.
9358 For a local window option the global value is unchanged.
9359 For the use of {buf}, see |bufname()| above.
9360 The {varname} argument is a string.
9361 Note that the variable name without "b:" must be used.
9362 Examples: >
9363 :call setbufvar(1, "&mod", 1)
9364 :call setbufvar("todo", "myvar", "foobar")
9365< This function is not available in the |sandbox|.
9366
9367 Can also be used as a |method|, the base is passed as the
9368 third argument: >
9369 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009370<
9371 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009372
9373
9374setcellwidths({list}) *setcellwidths()*
9375 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009376 tells Vim how wide characters are when displayed in the
9377 terminal, counted in screen cells. The values override
9378 'ambiwidth'. Example: >
9379 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009380 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009381 \ [0x2194, 0x2199, 2],
9382 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009383
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009384< The {list} argument is a List of Lists with each three
9385 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9386 {low} and {high} can be the same, in which case this refers to
9387 one character. Otherwise it is the range of characters from
9388 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009389 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009390
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009391 {width} must be either 1 or 2, indicating the character width
9392 in screen cells. *E1112*
9393 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009394 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009396 If the new value causes 'fillchars' or 'listchars' to become
9397 invalid it is rejected and an error is given.
9398
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009399 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009400 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009402< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009403 the effect for known emoji characters. Move the cursor
9404 through the text to check if the cell widths of your terminal
9405 match with what Vim knows about each emoji. If it doesn't
9406 look right you need to adjust the {list} argument.
9407
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009408 Return type: |Number|
9409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009410
9411setcharpos({expr}, {list}) *setcharpos()*
9412 Same as |setpos()| but uses the specified column number as the
9413 character index instead of the byte index in the line.
9414
9415 Example:
9416 With the text "여보세요" in line 8: >
9417 call setcharpos('.', [0, 8, 4, 0])
9418< positions the cursor on the fourth character '요'. >
9419 call setpos('.', [0, 8, 4, 0])
9420< positions the cursor on the second character '보'.
9421
9422 Can also be used as a |method|: >
9423 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009424<
9425 Return type: |Number|
9426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009427
9428setcharsearch({dict}) *setcharsearch()*
9429 Set the current character search information to {dict},
9430 which contains one or more of the following entries:
9431
9432 char character which will be used for a subsequent
9433 |,| or |;| command; an empty string clears the
9434 character search
9435 forward direction of character search; 1 for forward,
9436 0 for backward
9437 until type of character search; 1 for a |t| or |T|
9438 character search, 0 for an |f| or |F|
9439 character search
9440
9441 This can be useful to save/restore a user's character search
9442 from a script: >
9443 :let prevsearch = getcharsearch()
9444 :" Perform a command which clobbers user's search
9445 :call setcharsearch(prevsearch)
9446< Also see |getcharsearch()|.
9447
9448 Can also be used as a |method|: >
9449 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009450<
9451 Return type: dict<any>
9452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009453
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009454setcmdline({str} [, {pos}]) *setcmdline()*
9455 Set the command line to {str} and set the cursor position to
9456 {pos}.
9457 If {pos} is omitted, the cursor is positioned after the text.
9458 Returns 0 when successful, 1 when not editing the command
9459 line.
9460
9461 Can also be used as a |method|: >
9462 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009463<
9464 Return type: |Number|
9465
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009467setcmdpos({pos}) *setcmdpos()*
9468 Set the cursor position in the command line to byte position
9469 {pos}. The first position is 1.
9470 Use |getcmdpos()| to obtain the current position.
9471 Only works while editing the command line, thus you must use
9472 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9473 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9474 set after the command line is set to the expression. For
9475 |c_CTRL-R_=| it is set after evaluating the expression but
9476 before inserting the resulting text.
9477 When the number is too big the cursor is put at the end of the
9478 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009479 Returns 0 when successful, 1 when not editing the command
9480 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009481
9482 Can also be used as a |method|: >
9483 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009484<
9485 Return type: |Number|
9486
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009487
9488setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9489setcursorcharpos({list})
9490 Same as |cursor()| but uses the specified column number as the
9491 character index instead of the byte index in the line.
9492
9493 Example:
9494 With the text "여보세요" in line 4: >
9495 call setcursorcharpos(4, 3)
9496< positions the cursor on the third character '세'. >
9497 call cursor(4, 3)
9498< positions the cursor on the first character '여'.
9499
9500 Can also be used as a |method|: >
9501 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009502<
9503 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009504
9505
9506setenv({name}, {val}) *setenv()*
9507 Set environment variable {name} to {val}. Example: >
9508 call setenv('HOME', '/home/myhome')
9509
9510< When {val} is |v:null| the environment variable is deleted.
9511 See also |expr-env|.
9512
9513 Can also be used as a |method|, the base is passed as the
9514 second argument: >
9515 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009516<
9517 Return type: |Number|
9518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009519
9520setfperm({fname}, {mode}) *setfperm()* *chmod*
9521 Set the file permissions for {fname} to {mode}.
9522 {mode} must be a string with 9 characters. It is of the form
9523 "rwxrwxrwx", where each group of "rwx" flags represent, in
9524 turn, the permissions of the owner of the file, the group the
9525 file belongs to, and other users. A '-' character means the
9526 permission is off, any other character means on. Multi-byte
9527 characters are not supported.
9528
9529 For example "rw-r-----" means read-write for the user,
9530 readable by the group, not accessible by others. "xx-x-----"
9531 would do the same thing.
9532
9533 Returns non-zero for success, zero for failure.
9534
9535 Can also be used as a |method|: >
9536 GetFilename()->setfperm(mode)
9537<
9538 To read permissions see |getfperm()|.
9539
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009540 Return type: |Number|
9541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009542
9543setline({lnum}, {text}) *setline()*
9544 Set line {lnum} of the current buffer to {text}. To insert
9545 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009546 |setbufline()|.
9547 Any text properties in {lnum} are cleared |text-prop-cleared|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009548
9549 {lnum} is used like with |getline()|.
9550 When {lnum} is just below the last line the {text} will be
9551 added below the last line.
9552 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009553 converted to a String. When {text} is an empty List then
9554 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009555
9556 If this succeeds, FALSE is returned. If this fails (most likely
9557 because {lnum} is invalid) TRUE is returned.
9558 In |Vim9| script an error is given if {lnum} is invalid.
9559
9560 Example: >
9561 :call setline(5, strftime("%c"))
9562
9563< When {text} is a |List| then line {lnum} and following lines
9564 will be set to the items in the list. Example: >
9565 :call setline(5, ['aaa', 'bbb', 'ccc'])
9566< This is equivalent to: >
9567 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9568 : call setline(n, l)
9569 :endfor
9570
9571< Note: The '[ and '] marks are not set.
9572
9573 Can also be used as a |method|, the base is passed as the
9574 second argument: >
9575 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009576<
9577 Return type: |Number|
9578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009579
9580setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9581 Create or replace or add to the location list for window {nr}.
9582 {nr} can be the window number or the |window-ID|.
9583 When {nr} is zero the current window is used.
9584
9585 For a location list window, the displayed location list is
9586 modified. For an invalid window number {nr}, -1 is returned.
9587 Otherwise, same as |setqflist()|.
9588 Also see |location-list|.
9589
9590 For {action} see |setqflist-action|.
9591
9592 If the optional {what} dictionary argument is supplied, then
9593 only the items listed in {what} are set. Refer to |setqflist()|
9594 for the list of supported keys in {what}.
9595
9596 Can also be used as a |method|, the base is passed as the
9597 second argument: >
9598 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009599<
9600 Return type: |Number|
9601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009602
9603setmatches({list} [, {win}]) *setmatches()*
9604 Restores a list of matches saved by |getmatches()| for the
9605 current window. Returns 0 if successful, otherwise -1. All
9606 current matches are cleared before the list is restored. See
9607 example for |getmatches()|.
9608 If {win} is specified, use the window with this number or
9609 window ID instead of the current window.
9610
9611 Can also be used as a |method|: >
9612 GetMatches()->setmatches()
9613<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009614 Return type: |Number|
9615
9616
9617setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009618 Set the position for String {expr}. Possible values:
9619 . the cursor
9620 'x mark x
9621
9622 {list} must be a |List| with four or five numbers:
9623 [bufnum, lnum, col, off]
9624 [bufnum, lnum, col, off, curswant]
9625
9626 "bufnum" is the buffer number. Zero can be used for the
9627 current buffer. When setting an uppercase mark "bufnum" is
9628 used for the mark position. For other marks it specifies the
9629 buffer to set the mark in. You can use the |bufnr()| function
9630 to turn a file name into a buffer number.
9631 For setting the cursor and the ' mark "bufnum" is ignored,
9632 since these are associated with a window, not a buffer.
9633 Does not change the jumplist.
9634
9635 "lnum" and "col" are the position in the buffer. The first
9636 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9637 smaller than 1 then 1 is used. To use the character count
9638 instead of the byte count, use |setcharpos()|.
9639
9640 The "off" number is only used when 'virtualedit' is set. Then
9641 it is the offset in screen columns from the start of the
9642 character. E.g., a position within a <Tab> or after the last
9643 character.
9644
9645 The "curswant" number is only used when setting the cursor
9646 position. It sets the preferred column for when moving the
9647 cursor vertically. When the "curswant" number is missing the
9648 preferred column is not set. When it is present and setting a
9649 mark position it is not used.
9650
9651 Note that for '< and '> changing the line number may result in
9652 the marks to be effectively be swapped, so that '< is always
9653 before '>.
9654
9655 Returns 0 when the position could be set, -1 otherwise.
9656 An error message is given if {expr} is invalid.
9657
9658 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9659
9660 This does not restore the preferred column for moving
9661 vertically; if you set the cursor position with this, |j| and
9662 |k| motions will jump to previous columns! Use |cursor()| to
9663 also set the preferred column. Also see the "curswant" key in
9664 |winrestview()|.
9665
9666 Can also be used as a |method|: >
9667 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009668<
9669 Return type: |Number|
9670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009671
9672setqflist({list} [, {action} [, {what}]]) *setqflist()*
9673 Create or replace or add to the quickfix list.
9674
9675 If the optional {what} dictionary argument is supplied, then
9676 only the items listed in {what} are set. The first {list}
9677 argument is ignored. See below for the supported items in
9678 {what}.
9679 *setqflist-what*
9680 When {what} is not present, the items in {list} are used. Each
9681 item must be a dictionary. Non-dictionary items in {list} are
9682 ignored. Each dictionary item can contain the following
9683 entries:
9684
9685 bufnr buffer number; must be the number of a valid
9686 buffer
9687 filename name of a file; only used when "bufnr" is not
9688 present or it is invalid.
9689 module name of a module; if given it will be used in
9690 quickfix error window instead of the filename.
9691 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009692 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009693 pattern search pattern used to locate the error
9694 col column number
9695 vcol when non-zero: "col" is visual column
9696 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009697 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009698 nr error number
9699 text description of the error
9700 type single-character error type, 'E', 'W', etc.
9701 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009702 user_data custom data associated with the item, can be
9703 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009704
9705 The "col", "vcol", "nr", "type" and "text" entries are
9706 optional. Either "lnum" or "pattern" entry can be used to
9707 locate a matching error line.
9708 If the "filename" and "bufnr" entries are not present or
9709 neither the "lnum" or "pattern" entries are present, then the
9710 item will not be handled as an error line.
9711 If both "pattern" and "lnum" are present then "pattern" will
9712 be used.
9713 If the "valid" entry is not supplied, then the valid flag is
9714 set when "bufnr" is a valid buffer or "filename" exists.
9715 If you supply an empty {list}, the quickfix list will be
9716 cleared.
9717 Note that the list is not exactly the same as what
9718 |getqflist()| returns.
9719
9720 {action} values: *setqflist-action* *E927*
9721 'a' The items from {list} are added to the existing
9722 quickfix list. If there is no existing list, then a
9723 new list is created.
9724
9725 'r' The items from the current quickfix list are replaced
9726 with the items from {list}. This can also be used to
9727 clear the list: >
9728 :call setqflist([], 'r')
9729<
9730 'f' All the quickfix lists in the quickfix stack are
9731 freed.
9732
9733 If {action} is not present or is set to ' ', then a new list
9734 is created. The new quickfix list is added after the current
9735 quickfix list in the stack and all the following lists are
9736 freed. To add a new quickfix list at the end of the stack,
9737 set "nr" in {what} to "$".
9738
9739 The following items can be specified in dictionary {what}:
9740 context quickfix list context. See |quickfix-context|
9741 efm errorformat to use when parsing text from
9742 "lines". If this is not present, then the
9743 'errorformat' option value is used.
9744 See |quickfix-parse|
9745 id quickfix list identifier |quickfix-ID|
9746 idx index of the current entry in the quickfix
9747 list specified by 'id' or 'nr'. If set to '$',
9748 then the last entry in the list is set as the
9749 current entry. See |quickfix-index|
9750 items list of quickfix entries. Same as the {list}
9751 argument.
9752 lines use 'errorformat' to parse a list of lines and
9753 add the resulting entries to the quickfix list
9754 {nr} or {id}. Only a |List| value is supported.
9755 See |quickfix-parse|
9756 nr list number in the quickfix stack; zero
9757 means the current quickfix list and "$" means
9758 the last quickfix list.
9759 quickfixtextfunc
9760 function to get the text to display in the
9761 quickfix window. The value can be the name of
9762 a function or a funcref or a lambda. Refer to
9763 |quickfix-window-function| for an explanation
9764 of how to write the function and an example.
9765 title quickfix list title text. See |quickfix-title|
9766 Unsupported keys in {what} are ignored.
9767 If the "nr" item is not present, then the current quickfix list
9768 is modified. When creating a new quickfix list, "nr" can be
9769 set to a value one greater than the quickfix stack size.
9770 When modifying a quickfix list, to guarantee that the correct
9771 list is modified, "id" should be used instead of "nr" to
9772 specify the list.
9773
9774 Examples (See also |setqflist-examples|): >
9775 :call setqflist([], 'r', {'title': 'My search'})
9776 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9777 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9778<
9779 Returns zero for success, -1 for failure.
9780
9781 This function can be used to create a quickfix list
9782 independent of the 'errorformat' setting. Use a command like
9783 `:cc 1` to jump to the first position.
9784
9785 Can also be used as a |method|, the base is passed as the
9786 second argument: >
9787 GetErrorlist()->setqflist()
9788<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009789 Return type: |Number|
9790
9791
9792setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009793 Set the register {regname} to {value}.
9794 If {regname} is "" or "@", the unnamed register '"' is used.
9795 The {regname} argument is a string. In |Vim9-script|
9796 {regname} must be one character.
9797
9798 {value} may be any value returned by |getreg()| or
9799 |getreginfo()|, including a |List| or |Dict|.
9800 If {options} contains "a" or {regname} is upper case,
9801 then the value is appended.
9802
9803 {options} can also contain a register type specification:
9804 "c" or "v" |characterwise| mode
9805 "l" or "V" |linewise| mode
9806 "b" or "<CTRL-V>" |blockwise-visual| mode
9807 If a number immediately follows "b" or "<CTRL-V>" then this is
9808 used as the width of the selection - if it is not specified
9809 then the width of the block is set to the number of characters
9810 in the longest line (counting a <Tab> as 1 character).
9811
9812 If {options} contains no register settings, then the default
9813 is to use character mode unless {value} ends in a <NL> for
9814 string {value} and linewise mode for list {value}. Blockwise
9815 mode is never selected automatically.
9816 Returns zero for success, non-zero for failure.
9817
9818 *E883*
9819 Note: you may not use |List| containing more than one item to
9820 set search and expression registers. Lists containing no
9821 items act like empty strings.
9822
9823 Examples: >
9824 :call setreg(v:register, @*)
9825 :call setreg('*', @%, 'ac')
9826 :call setreg('a', "1\n2\n3", 'b5')
9827 :call setreg('"', { 'points_to': 'a'})
9828
9829< This example shows using the functions to save and restore a
9830 register: >
9831 :let var_a = getreginfo()
9832 :call setreg('a', var_a)
9833< or: >
9834 :let var_a = getreg('a', 1, 1)
9835 :let var_amode = getregtype('a')
9836 ....
9837 :call setreg('a', var_a, var_amode)
9838< Note: you may not reliably restore register value
9839 without using the third argument to |getreg()| as without it
9840 newlines are represented as newlines AND Nul bytes are
9841 represented as newlines as well, see |NL-used-for-Nul|.
9842
9843 You can also change the type of a register by appending
9844 nothing: >
9845 :call setreg('a', '', 'al')
9846
9847< Can also be used as a |method|, the base is passed as the
9848 second argument: >
9849 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009850<
9851 Return type: |Number|
9852
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009853
9854settabvar({tabnr}, {varname}, {val}) *settabvar()*
9855 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9856 |t:var|
9857 The {varname} argument is a string.
9858 Note that autocommands are blocked, side effects may not be
9859 triggered, e.g. when setting 'filetype'.
9860 Note that the variable name without "t:" must be used.
9861 Tabs are numbered starting with one.
9862 This function is not available in the |sandbox|.
9863
9864 Can also be used as a |method|, the base is passed as the
9865 third argument: >
9866 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009867<
9868 Return type: |Number|
9869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009870
9871settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9872 Set option or local variable {varname} in window {winnr} to
9873 {val}.
9874 Tabs are numbered starting with one. For the current tabpage
9875 use |setwinvar()|.
9876 {winnr} can be the window number or the |window-ID|.
9877 When {winnr} is zero the current window is used.
9878 Note that autocommands are blocked, side effects may not be
9879 triggered, e.g. when setting 'filetype' or 'syntax'.
9880 This also works for a global or local buffer option, but it
9881 doesn't work for a global or local buffer variable.
9882 For a local buffer option the global value is unchanged.
9883 Note that the variable name without "w:" must be used.
9884 Examples: >
9885 :call settabwinvar(1, 1, "&list", 0)
9886 :call settabwinvar(3, 2, "myvar", "foobar")
9887< This function is not available in the |sandbox|.
9888
9889 Can also be used as a |method|, the base is passed as the
9890 fourth argument: >
9891 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009892<
9893 Return type: |Number|
9894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009895
9896settagstack({nr}, {dict} [, {action}]) *settagstack()*
9897 Modify the tag stack of the window {nr} using {dict}.
9898 {nr} can be the window number or the |window-ID|.
9899
9900 For a list of supported items in {dict}, refer to
9901 |gettagstack()|. "curidx" takes effect before changing the tag
9902 stack.
9903 *E962*
9904 How the tag stack is modified depends on the {action}
9905 argument:
9906 - If {action} is not present or is set to 'r', then the tag
9907 stack is replaced.
9908 - If {action} is set to 'a', then new entries from {dict} are
9909 pushed (added) onto the tag stack.
9910 - If {action} is set to 't', then all the entries from the
9911 current entry in the tag stack or "curidx" in {dict} are
9912 removed and then new entries are pushed to the stack.
9913
9914 The current index is set to one after the length of the tag
9915 stack after the modification.
9916
9917 Returns zero for success, -1 for failure.
9918
9919 Examples (for more examples see |tagstack-examples|):
9920 Empty the tag stack of window 3: >
9921 call settagstack(3, {'items' : []})
9922
9923< Save and restore the tag stack: >
9924 let stack = gettagstack(1003)
9925 " do something else
9926 call settagstack(1003, stack)
9927 unlet stack
9928<
9929 Can also be used as a |method|, the base is passed as the
9930 second argument: >
9931 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009932<
9933 Return type: |Number|
9934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009935
9936setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9937 Like |settabwinvar()| for the current tab page.
9938 Examples: >
9939 :call setwinvar(1, "&list", 0)
9940 :call setwinvar(2, "myvar", "foobar")
9941
9942< Can also be used as a |method|, the base is passed as the
9943 third argument: >
9944 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009945<
9946 Return type: |Number|
9947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009948
9949sha256({string}) *sha256()*
9950 Returns a String with 64 hex characters, which is the SHA256
9951 checksum of {string}.
9952
9953 Can also be used as a |method|: >
9954 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009955<
9956 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009957
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009958 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009959
9960shellescape({string} [, {special}]) *shellescape()*
9961 Escape {string} for use as a shell command argument.
9962 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009963 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009964 in single quotes and will double up all internal single
9965 quotes.
9966 On MS-Windows, when 'shellslash' is not set, it will enclose
9967 {string} in double quotes and double all double quotes within
9968 {string}.
9969 Otherwise it will enclose {string} in single quotes and
9970 replace all "'" with "'\''".
9971
Enno5faeb602024-05-15 21:54:19 +02009972 The {special} argument adds additional escaping of keywords
9973 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009974 number or a non-empty String (|non-zero-arg|), then special
9975 items such as "!", "%", "#" and "<cword>" (as listed in
9976 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009977 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009978
9979 The "!" character will be escaped (again with a |non-zero-arg|
9980 {special}) when 'shell' contains "csh" in the tail. That is
9981 because for csh and tcsh "!" is used for history replacement
9982 even when inside single quotes.
9983
9984 With a |non-zero-arg| {special} the <NL> character is also
9985 escaped. When 'shell' containing "csh" in the tail it's
9986 escaped a second time.
9987
9988 The "\" character will be escaped when 'shell' contains "fish"
9989 in the tail. That is because for fish "\" is used as an escape
9990 character inside single quotes.
9991
9992 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009993 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009994< This results in a directory listing for the file under the
9995 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009996 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009997< See also |::S|.
9998
9999 Can also be used as a |method|: >
10000 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010001<
10002 Return type: |String|
10003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010004
10005shiftwidth([{col}]) *shiftwidth()*
10006 Returns the effective value of 'shiftwidth'. This is the
10007 'shiftwidth' value unless it is zero, in which case it is the
10008 'tabstop' value. This function was introduced with patch
10009 7.3.694 in 2012, everybody should have it by now (however it
10010 did not allow for the optional {col} argument until 8.1.542).
10011
10012 When there is one argument {col} this is used as column number
10013 for which to return the 'shiftwidth' value. This matters for the
10014 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10015 no {col} argument is given, column 1 will be assumed.
10016
10017 Can also be used as a |method|: >
10018 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010019<
10020 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010021
10022sign_ functions are documented here: |sign-functions-details|
10023
10024
10025simplify({filename}) *simplify()*
10026 Simplify the file name as much as possible without changing
10027 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10028 Unix) are not resolved. If the first path component in
10029 {filename} designates the current directory, this will be
10030 valid for the result as well. A trailing path separator is
10031 not removed either. On Unix "//path" is unchanged, but
10032 "///path" is simplified to "/path" (this follows the Posix
10033 standard).
10034 Example: >
10035 simplify("./dir/.././/file/") == "./file/"
10036< Note: The combination "dir/.." is only removed if "dir" is
10037 a searchable directory or does not exist. On Unix, it is also
10038 removed when "dir" is a symbolic link within the same
10039 directory. In order to resolve all the involved symbolic
10040 links before simplifying the path name, use |resolve()|.
10041
10042 Can also be used as a |method|: >
10043 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010044<
10045 Return type: |String|
10046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010047
10048sin({expr}) *sin()*
10049 Return the sine of {expr}, measured in radians, as a |Float|.
10050 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010051 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010052 Examples: >
10053 :echo sin(100)
10054< -0.506366 >
10055 :echo sin(-4.01)
10056< 0.763301
10057
10058 Can also be used as a |method|: >
10059 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010060<
10061 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010062
10063
10064sinh({expr}) *sinh()*
10065 Return the hyperbolic sine of {expr} as a |Float| in the range
10066 [-inf, inf].
10067 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010068 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010069 Examples: >
10070 :echo sinh(0.5)
10071< 0.521095 >
10072 :echo sinh(-0.9)
10073< -1.026517
10074
10075 Can also be used as a |method|: >
10076 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010077<
10078 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010079
10080
10081slice({expr}, {start} [, {end}]) *slice()*
10082 Similar to using a |slice| "expr[start : end]", but "end" is
10083 used exclusive. And for a string the indexes are used as
10084 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010085 |vim9script|. Also, composing characters are treated as a
10086 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010087 When {end} is omitted the slice continues to the last item.
10088 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010089 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010090
10091 Can also be used as a |method|: >
10092 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010093<
10094 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010095
10096
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010097sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010098 Sort the items in {list} in-place. Returns {list}.
10099
10100 If you want a list to remain unmodified make a copy first: >
10101 :let sortedlist = sort(copy(mylist))
10102
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010103< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010104 string representation of each item to sort on. Numbers sort
10105 after Strings, |Lists| after Numbers. For sorting text in the
10106 current buffer use |:sort|.
10107
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010108 When {how} is given and it is 'i' then case is ignored.
10109 In legacy script, for backwards compatibility, the value one
10110 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010111
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010112 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010113 locale is used for ordering. Implementation details: strcoll()
10114 is used to compare strings. See |:language| check or set the
10115 collation locale. |v:collate| can also be used to check the
10116 current locale. Sorting using the locale typically ignores
10117 case. Example: >
10118 " ö is sorted similarly to o with English locale.
10119 :language collate en_US.UTF8
10120 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10121< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10122>
10123 " ö is sorted after z with Swedish locale.
10124 :language collate sv_SE.UTF8
10125 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10126< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10127 This does not work properly on Mac.
10128
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010129 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010130 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010131 strtod() function to parse numbers. Strings, Lists, Dicts and
10132 Funcrefs will be considered as being 0). Note that this won't
10133 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010134
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010135 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010136 sorted numerical. This is like 'n' but a string containing
10137 digits will be used as the number they represent.
10138
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010139 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010140 sorted numerical. All values must be a Number or a Float.
10141
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010142 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010143 is called to compare items. The function is invoked with two
10144 items as argument and must return zero if they are equal, 1 or
10145 bigger if the first one sorts after the second one, -1 or
10146 smaller if the first one sorts before the second one.
10147
10148 {dict} is for functions with the "dict" attribute. It will be
10149 used to set the local variable "self". |Dictionary-function|
10150
10151 The sort is stable, items which compare equal (as number or as
10152 string) will keep their relative position. E.g., when sorting
10153 on numbers, text strings will sort next to each other, in the
10154 same order as they were originally.
10155
10156 Can also be used as a |method|: >
10157 mylist->sort()
10158
10159< Also see |uniq()|.
10160
10161 Example: >
10162 func MyCompare(i1, i2)
10163 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10164 endfunc
10165 eval mylist->sort("MyCompare")
10166< A shorter compare version for this specific simple case, which
10167 ignores overflow: >
10168 func MyCompare(i1, i2)
10169 return a:i1 - a:i2
10170 endfunc
10171< For a simple expression you can use a lambda: >
10172 eval mylist->sort({i1, i2 -> i1 - i2})
10173<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010174 Return type: list<{type}>
10175
10176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010177sound_clear() *sound_clear()*
10178 Stop playing all sounds.
10179
10180 On some Linux systems you may need the libcanberra-pulse
10181 package, otherwise sound may not stop.
10182
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010183 Return type: |Number|
10184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010185 {only available when compiled with the |+sound| feature}
10186
10187 *sound_playevent()*
10188sound_playevent({name} [, {callback}])
10189 Play a sound identified by {name}. Which event names are
10190 supported depends on the system. Often the XDG sound names
10191 are used. On Ubuntu they may be found in
10192 /usr/share/sounds/freedesktop/stereo. Example: >
10193 call sound_playevent('bell')
10194< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10195 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10196 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010197 On macOS, {name} refers to files located in
10198 /System/Library/Sounds (e.g. "Tink"). It will also work for
10199 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010200
10201 When {callback} is specified it is invoked when the sound is
10202 finished. The first argument is the sound ID, the second
10203 argument is the status:
10204 0 sound was played to the end
10205 1 sound was interrupted
10206 2 error occurred after sound started
10207 Example: >
10208 func Callback(id, status)
10209 echomsg "sound " .. a:id .. " finished with " .. a:status
10210 endfunc
10211 call sound_playevent('bell', 'Callback')
10212
10213< MS-Windows: {callback} doesn't work for this function.
10214
10215 Returns the sound ID, which can be passed to `sound_stop()`.
10216 Returns zero if the sound could not be played.
10217
10218 Can also be used as a |method|: >
10219 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010220<
10221 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010222
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010223 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010224
10225 *sound_playfile()*
10226sound_playfile({path} [, {callback}])
10227 Like `sound_playevent()` but play sound file {path}. {path}
10228 must be a full path. On Ubuntu you may find files to play
10229 with this command: >
10230 :!find /usr/share/sounds -type f | grep -v index.theme
10231
10232< Can also be used as a |method|: >
10233 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010234<
10235 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010236
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010237 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010238
10239
10240sound_stop({id}) *sound_stop()*
10241 Stop playing sound {id}. {id} must be previously returned by
10242 `sound_playevent()` or `sound_playfile()`.
10243
10244 On some Linux systems you may need the libcanberra-pulse
10245 package, otherwise sound may not stop.
10246
10247 On MS-Windows, this does not work for event sound started by
10248 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10249
10250 Can also be used as a |method|: >
10251 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010252<
10253 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010254
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010255 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010256
10257 *soundfold()*
10258soundfold({word})
10259 Return the sound-folded equivalent of {word}. Uses the first
10260 language in 'spelllang' for the current window that supports
10261 soundfolding. 'spell' must be set. When no sound folding is
10262 possible the {word} is returned unmodified.
10263 This can be used for making spelling suggestions. Note that
10264 the method can be quite slow.
10265
10266 Can also be used as a |method|: >
10267 GetWord()->soundfold()
10268<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010269 Return type: |String|
10270
10271
10272spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010273 Without argument: The result is the badly spelled word under
10274 or after the cursor. The cursor is moved to the start of the
10275 bad word. When no bad word is found in the cursor line the
10276 result is an empty string and the cursor doesn't move.
10277
10278 With argument: The result is the first word in {sentence} that
10279 is badly spelled. If there are no spelling mistakes the
10280 result is an empty string.
10281
10282 The return value is a list with two items:
10283 - The badly spelled word or an empty string.
10284 - The type of the spelling error:
10285 "bad" spelling mistake
10286 "rare" rare word
10287 "local" word only valid in another region
10288 "caps" word should start with Capital
10289 Example: >
10290 echo spellbadword("the quik brown fox")
10291< ['quik', 'bad'] ~
10292
10293 The spelling information for the current window and the value
10294 of 'spelllang' are used.
10295
10296 Can also be used as a |method|: >
10297 GetText()->spellbadword()
10298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010299 Return type: list<string>
10300
10301
10302spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010303 Return a |List| with spelling suggestions to replace {word}.
10304 When {max} is given up to this number of suggestions are
10305 returned. Otherwise up to 25 suggestions are returned.
10306
10307 When the {capital} argument is given and it's non-zero only
10308 suggestions with a leading capital will be given. Use this
10309 after a match with 'spellcapcheck'.
10310
10311 {word} can be a badly spelled word followed by other text.
10312 This allows for joining two words that were split. The
10313 suggestions also include the following text, thus you can
10314 replace a line.
10315
10316 {word} may also be a good word. Similar words will then be
10317 returned. {word} itself is not included in the suggestions,
10318 although it may appear capitalized.
10319
10320 The spelling information for the current window is used. The
10321 values of 'spelllang' and 'spellsuggest' are used.
10322
10323 Can also be used as a |method|: >
10324 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010325<
10326 Return type: list<string> or list<any>
10327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010328
10329split({string} [, {pattern} [, {keepempty}]]) *split()*
10330 Make a |List| out of {string}. When {pattern} is omitted or
10331 empty each white-separated sequence of characters becomes an
10332 item.
10333 Otherwise the string is split where {pattern} matches,
10334 removing the matched characters. 'ignorecase' is not used
10335 here, add \c to ignore case. |/\c|
10336 When the first or last item is empty it is omitted, unless the
10337 {keepempty} argument is given and it's non-zero.
10338 Other empty items are kept when {pattern} matches at least one
10339 character or when {keepempty} is non-zero.
10340 Example: >
10341 :let words = split(getline('.'), '\W\+')
10342< To split a string in individual characters: >
10343 :for c in split(mystring, '\zs')
10344< If you want to keep the separator you can also use '\zs' at
10345 the end of the pattern: >
10346 :echo split('abc:def:ghi', ':\zs')
10347< ['abc:', 'def:', 'ghi'] ~
10348 Splitting a table where the first element can be empty: >
10349 :let items = split(line, ':', 1)
10350< The opposite function is |join()|.
10351
10352 Can also be used as a |method|: >
10353 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010354<
10355 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010356
10357sqrt({expr}) *sqrt()*
10358 Return the non-negative square root of Float {expr} as a
10359 |Float|.
10360 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010361 is negative the result is NaN (Not a Number). Returns 0.0 if
10362 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010363 Examples: >
10364 :echo sqrt(100)
10365< 10.0 >
10366 :echo sqrt(-4.01)
10367< nan
10368 "nan" may be different, it depends on system libraries.
10369
10370 Can also be used as a |method|: >
10371 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010372<
10373 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010374
10375
10376srand([{expr}]) *srand()*
10377 Initialize seed used by |rand()|:
10378 - If {expr} is not given, seed values are initialized by
10379 reading from /dev/urandom, if possible, or using time(NULL)
10380 a.k.a. epoch time otherwise; this only has second accuracy.
10381 - If {expr} is given it must be a Number. It is used to
10382 initialize the seed values. This is useful for testing or
10383 when a predictable sequence is intended.
10384
10385 Examples: >
10386 :let seed = srand()
10387 :let seed = srand(userinput)
10388 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010389<
10390 Return type: list<number>
10391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010392
10393state([{what}]) *state()*
10394 Return a string which contains characters indicating the
10395 current state. Mostly useful in callbacks that want to do
10396 work that may not always be safe. Roughly this works like:
10397 - callback uses state() to check if work is safe to do.
10398 Yes: then do it right away.
10399 No: add to work queue and add a |SafeState| and/or
10400 |SafeStateAgain| autocommand (|SafeState| triggers at
10401 toplevel, |SafeStateAgain| triggers after handling
10402 messages and callbacks).
10403 - When SafeState or SafeStateAgain is triggered and executes
10404 your autocommand, check with `state()` if the work can be
10405 done now, and if yes remove it from the queue and execute.
10406 Remove the autocommand if the queue is now empty.
10407 Also see |mode()|.
10408
10409 When {what} is given only characters in this string will be
10410 added. E.g, this checks if the screen has scrolled: >
10411 if state('s') == ''
10412 " screen has not scrolled
10413<
10414 These characters indicate the state, generally indicating that
10415 something is busy:
10416 m halfway a mapping, :normal command, feedkeys() or
10417 stuffed command
10418 o operator pending, e.g. after |d|
10419 a Insert mode autocomplete active
10420 x executing an autocommand
10421 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10422 ch_readraw() when reading json
10423 S not triggering SafeState or SafeStateAgain, e.g. after
10424 |f| or a count
10425 c callback invoked, including timer (repeats for
10426 recursiveness up to "ccc")
10427 s screen has scrolled for messages
10428
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010429 Return type: |String|
10430
10431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010432str2float({string} [, {quoted}]) *str2float()*
10433 Convert String {string} to a Float. This mostly works the
10434 same as when using a floating point number in an expression,
10435 see |floating-point-format|. But it's a bit more permissive.
10436 E.g., "1e40" is accepted, while in an expression you need to
10437 write "1.0e40". The hexadecimal form "0x123" is also
10438 accepted, but not others, like binary or octal.
10439 When {quoted} is present and non-zero then embedded single
10440 quotes before the dot are ignored, thus "1'000.0" is a
10441 thousand.
10442 Text after the number is silently ignored.
10443 The decimal point is always '.', no matter what the locale is
10444 set to. A comma ends the number: "12,345.67" is converted to
10445 12.0. You can strip out thousands separators with
10446 |substitute()|: >
10447 let f = str2float(substitute(text, ',', '', 'g'))
10448<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010449 Returns 0.0 if the conversion fails.
10450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010451 Can also be used as a |method|: >
10452 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010453<
10454 Return type: |Float|
10455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010456
10457str2list({string} [, {utf8}]) *str2list()*
10458 Return a list containing the number values which represent
10459 each character in String {string}. Examples: >
10460 str2list(" ") returns [32]
10461 str2list("ABC") returns [65, 66, 67]
10462< |list2str()| does the opposite.
10463
10464 When {utf8} is omitted or zero, the current 'encoding' is used.
10465 When {utf8} is TRUE, always treat the String as UTF-8
10466 characters. With UTF-8 composing characters are handled
10467 properly: >
10468 str2list("á") returns [97, 769]
10469
10470< Can also be used as a |method|: >
10471 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010472<
10473 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010474
10475
10476str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10477 Convert string {string} to a number.
10478 {base} is the conversion base, it can be 2, 8, 10 or 16.
10479 When {quoted} is present and non-zero then embedded single
10480 quotes are ignored, thus "1'000'000" is a million.
10481
10482 When {base} is omitted base 10 is used. This also means that
10483 a leading zero doesn't cause octal conversion to be used, as
10484 with the default String to Number conversion. Example: >
10485 let nr = str2nr('0123')
10486<
10487 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10488 different base the result will be zero. Similarly, when
10489 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10490 {base} is 2 a leading "0b" or "0B" is ignored.
10491 Text after the number is silently ignored.
10492
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010493 Returns 0 if {string} is empty or on error.
10494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010495 Can also be used as a |method|: >
10496 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010497<
10498 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010499
10500
10501strcharlen({string}) *strcharlen()*
10502 The result is a Number, which is the number of characters
10503 in String {string}. Composing characters are ignored.
10504 |strchars()| can count the number of characters, counting
10505 composing characters separately.
10506
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010507 Returns 0 if {string} is empty or on error.
10508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010509 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10510
10511 Can also be used as a |method|: >
10512 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010513<
10514 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010515
10516
10517strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10518 Like |strpart()| but using character index and length instead
10519 of byte index and length.
10520 When {skipcc} is omitted or zero, composing characters are
10521 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010522 When {skipcc} set to 1, composing characters are treated as a
10523 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010524 When a character index is used where a character does not
10525 exist it is omitted and counted as one character. For
10526 example: >
10527 strcharpart('abc', -1, 2)
10528< results in 'a'.
10529
Bram Moolenaard592deb2022-06-17 15:42:40 +010010530 Returns an empty string on error.
10531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010532 Can also be used as a |method|: >
10533 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010534<
10535 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010536
10537
10538strchars({string} [, {skipcc}]) *strchars()*
10539 The result is a Number, which is the number of characters
10540 in String {string}.
10541 When {skipcc} is omitted or zero, composing characters are
10542 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010543 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010544 |strcharlen()| always does this.
10545
Bram Moolenaard592deb2022-06-17 15:42:40 +010010546 Returns zero on error.
10547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010548 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10549
10550 {skipcc} is only available after 7.4.755. For backward
10551 compatibility, you can define a wrapper function: >
10552 if has("patch-7.4.755")
10553 function s:strchars(str, skipcc)
10554 return strchars(a:str, a:skipcc)
10555 endfunction
10556 else
10557 function s:strchars(str, skipcc)
10558 if a:skipcc
10559 return strlen(substitute(a:str, ".", "x", "g"))
10560 else
10561 return strchars(a:str)
10562 endif
10563 endfunction
10564 endif
10565<
10566 Can also be used as a |method|: >
10567 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010568<
10569 Return type: |Number|
10570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010571
10572strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10573 The result is a Number, which is the number of display cells
10574 String {string} occupies on the screen when it starts at {col}
10575 (first column is zero). When {col} is omitted zero is used.
10576 Otherwise it is the screen column where to start. This
10577 matters for Tab characters.
10578 The option settings of the current window are used. This
10579 matters for anything that's displayed differently, such as
10580 'tabstop' and 'display'.
10581 When {string} contains characters with East Asian Width Class
10582 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010583 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010584 Also see |strlen()|, |strwidth()| and |strchars()|.
10585
10586 Can also be used as a |method|: >
10587 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010588<
10589 Return type: |Number|
10590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010591
10592strftime({format} [, {time}]) *strftime()*
10593 The result is a String, which is a formatted date and time, as
10594 specified by the {format} string. The given {time} is used,
10595 or the current time if no time is given. The accepted
10596 {format} depends on your system, thus this is not portable!
10597 See the manual page of the C function strftime() for the
10598 format. The maximum length of the result is 80 characters.
10599 See also |localtime()|, |getftime()| and |strptime()|.
10600 The language can be changed with the |:language| command.
10601 Examples: >
10602 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10603 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10604 :echo strftime("%y%m%d %T") 970427 11:53:55
10605 :echo strftime("%H:%M") 11:55
10606 :echo strftime("%c", getftime("file.c"))
10607 Show mod time of file.c.
10608< Not available on all systems. To check use: >
10609 :if exists("*strftime")
10610
10611< Can also be used as a |method|: >
10612 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010613<
10614 Return type: |String|
10615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010616
10617strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010618 Get a Number corresponding to the character at {index} in
10619 {str}. This uses a zero-based character index, not a byte
10620 index. Composing characters are considered separate
10621 characters here. Use |nr2char()| to convert the Number to a
10622 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010623 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010624 Also see |strcharpart()| and |strchars()|.
10625
10626 Can also be used as a |method|: >
10627 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010628<
10629 Return type: |Number|
10630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010631
10632stridx({haystack}, {needle} [, {start}]) *stridx()*
10633 The result is a Number, which gives the byte index in
10634 {haystack} of the first occurrence of the String {needle}.
10635 If {start} is specified, the search starts at index {start}.
10636 This can be used to find a second match: >
10637 :let colon1 = stridx(line, ":")
10638 :let colon2 = stridx(line, ":", colon1 + 1)
10639< The search is done case-sensitive.
10640 For pattern searches use |match()|.
10641 -1 is returned if the {needle} does not occur in {haystack}.
10642 See also |strridx()|.
10643 Examples: >
10644 :echo stridx("An Example", "Example") 3
10645 :echo stridx("Starting point", "Start") 0
10646 :echo stridx("Starting point", "start") -1
10647< *strstr()* *strchr()*
10648 stridx() works similar to the C function strstr(). When used
10649 with a single character it works similar to strchr().
10650
10651 Can also be used as a |method|: >
10652 GetHaystack()->stridx(needle)
10653<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010654 Return type: |Number|
10655
10656
10657string({expr}) *string()*
10658 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010659 Float, String, Blob or a composition of them, then the result
10660 can be parsed back with |eval()|.
10661 {expr} type result ~
10662 String 'string' (single quotes are doubled)
10663 Number 123
10664 Float 123.123456 or 1.123456e8
10665 Funcref function('name')
10666 Blob 0z00112233.44556677.8899
10667 List [item, item]
10668 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010669 Class class SomeName
10670 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010671 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010672 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010673
10674 When a |List| or |Dictionary| has a recursive reference it is
10675 replaced by "[...]" or "{...}". Using eval() on the result
10676 will then fail.
10677
mityu7f0bba22024-03-29 10:14:41 +010010678 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010679 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010680 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010682 Can also be used as a |method|: >
10683 mylist->string()
10684
10685< Also see |strtrans()|.
10686
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010687 Return type: |String|
10688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010689
10690strlen({string}) *strlen()*
10691 The result is a Number, which is the length of the String
10692 {string} in bytes.
10693 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010694 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010695 If you want to count the number of multibyte characters use
10696 |strchars()|.
10697 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10698
10699 Can also be used as a |method|: >
10700 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010701<
10702 Return type: |Number|
10703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010704
10705strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10706 The result is a String, which is part of {src}, starting from
10707 byte {start}, with the byte length {len}.
10708 When {chars} is present and TRUE then {len} is the number of
10709 characters positions (composing characters are not counted
10710 separately, thus "1" means one base character and any
10711 following composing characters).
10712 To count {start} as characters instead of bytes use
10713 |strcharpart()|.
10714
10715 When bytes are selected which do not exist, this doesn't
10716 result in an error, the bytes are simply omitted.
10717 If {len} is missing, the copy continues from {start} till the
10718 end of the {src}. >
10719 strpart("abcdefg", 3, 2) == "de"
10720 strpart("abcdefg", -2, 4) == "ab"
10721 strpart("abcdefg", 5, 4) == "fg"
10722 strpart("abcdefg", 3) == "defg"
10723
10724< Note: To get the first character, {start} must be 0. For
10725 example, to get the character under the cursor: >
10726 strpart(getline("."), col(".") - 1, 1, v:true)
10727<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010728 Returns an empty string on error.
10729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010730 Can also be used as a |method|: >
10731 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010732<
10733 Return type: |String|
10734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010735
10736strptime({format}, {timestring}) *strptime()*
10737 The result is a Number, which is a unix timestamp representing
10738 the date and time in {timestring}, which is expected to match
10739 the format specified in {format}.
10740
10741 The accepted {format} depends on your system, thus this is not
10742 portable! See the manual page of the C function strptime()
10743 for the format. Especially avoid "%c". The value of $TZ also
10744 matters.
10745
10746 If the {timestring} cannot be parsed with {format} zero is
10747 returned. If you do not know the format of {timestring} you
10748 can try different {format} values until you get a non-zero
10749 result.
10750
10751 See also |strftime()|.
10752 Examples: >
10753 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10754< 862156163 >
10755 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10756< Sun Apr 27 11:53:55 1997 >
10757 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10758< Sun Apr 27 12:53:55 1997
10759
10760 Can also be used as a |method|: >
10761 GetFormat()->strptime(timestring)
10762<
10763 Not available on all systems. To check use: >
10764 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010765<
10766 Return type: |Number|
10767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010768
10769strridx({haystack}, {needle} [, {start}]) *strridx()*
10770 The result is a Number, which gives the byte index in
10771 {haystack} of the last occurrence of the String {needle}.
10772 When {start} is specified, matches beyond this index are
10773 ignored. This can be used to find a match before a previous
10774 match: >
10775 :let lastcomma = strridx(line, ",")
10776 :let comma2 = strridx(line, ",", lastcomma - 1)
10777< The search is done case-sensitive.
10778 For pattern searches use |match()|.
10779 -1 is returned if the {needle} does not occur in {haystack}.
10780 If the {needle} is empty the length of {haystack} is returned.
10781 See also |stridx()|. Examples: >
10782 :echo strridx("an angry armadillo", "an") 3
10783< *strrchr()*
10784 When used with a single character it works similar to the C
10785 function strrchr().
10786
10787 Can also be used as a |method|: >
10788 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010789<
10790 Return type: |Number|
10791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010792
10793strtrans({string}) *strtrans()*
10794 The result is a String, which is {string} with all unprintable
10795 characters translated into printable characters |'isprint'|.
10796 Like they are shown in a window. Example: >
10797 echo strtrans(@a)
10798< This displays a newline in register a as "^@" instead of
10799 starting a new line.
10800
Bram Moolenaard592deb2022-06-17 15:42:40 +010010801 Returns an empty string on error.
10802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010803 Can also be used as a |method|: >
10804 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010805<
10806 Return type: |String|
10807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010808
Christian Brabandt67672ef2023-04-24 21:09:54 +010010809strutf16len({string} [, {countcc}]) *strutf16len()*
10810 The result is a Number, which is the number of UTF-16 code
10811 units in String {string} (after converting it to UTF-16).
10812
10813 When {countcc} is TRUE, composing characters are counted
10814 separately.
10815 When {countcc} is omitted or FALSE, composing characters are
10816 ignored.
10817
10818 Returns zero on error.
10819
10820 Also see |strlen()| and |strcharlen()|.
10821 Examples: >
10822 echo strutf16len('a') returns 1
10823 echo strutf16len('©') returns 1
10824 echo strutf16len('😊') returns 2
10825 echo strutf16len('ą́') returns 1
10826 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010827<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010828 Can also be used as a |method|: >
10829 GetText()->strutf16len()
10830<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010831 Return type: |Number|
10832
10833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010834strwidth({string}) *strwidth()*
10835 The result is a Number, which is the number of display cells
10836 String {string} occupies. A Tab character is counted as one
10837 cell, alternatively use |strdisplaywidth()|.
10838 When {string} contains characters with East Asian Width Class
10839 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010840 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10842
10843 Can also be used as a |method|: >
10844 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010845<
10846 Return type: |Number|
10847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010848
10849submatch({nr} [, {list}]) *submatch()* *E935*
10850 Only for an expression in a |:substitute| command or
10851 substitute() function.
10852 Returns the {nr}'th submatch of the matched text. When {nr}
10853 is 0 the whole matched text is returned.
10854 Note that a NL in the string can stand for a line break of a
10855 multi-line match or a NUL character in the text.
10856 Also see |sub-replace-expression|.
10857
10858 If {list} is present and non-zero then submatch() returns
10859 a list of strings, similar to |getline()| with two arguments.
10860 NL characters in the text represent NUL characters in the
10861 text.
10862 Only returns more than one item for |:substitute|, inside
10863 |substitute()| this list will always contain one or zero
10864 items, since there are no real line breaks.
10865
10866 When substitute() is used recursively only the submatches in
10867 the current (deepest) call can be obtained.
10868
Bram Moolenaard592deb2022-06-17 15:42:40 +010010869 Returns an empty string or list on error.
10870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010871 Examples: >
10872 :s/\d\+/\=submatch(0) + 1/
10873 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10874< This finds the first number in the line and adds one to it.
10875 A line break is included as a newline character.
10876
10877 Can also be used as a |method|: >
10878 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010879<
10880 Return type: |String| or list<string> depending on {list}
10881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010882
10883substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10884 The result is a String, which is a copy of {string}, in which
10885 the first match of {pat} is replaced with {sub}.
10886 When {flags} is "g", all matches of {pat} in {string} are
10887 replaced. Otherwise {flags} should be "".
10888
10889 This works like the ":substitute" command (without any flags).
10890 But the matching with {pat} is always done like the 'magic'
10891 option is set and 'cpoptions' is empty (to make scripts
10892 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10893 if you want to ignore or match case and ignore 'ignorecase'.
10894 'smartcase' is not used. See |string-match| for how {pat} is
10895 used.
10896
10897 A "~" in {sub} is not replaced with the previous {sub}.
10898 Note that some codes in {sub} have a special meaning
10899 |sub-replace-special|. For example, to replace something with
10900 "\n" (two characters), use "\\\\n" or '\\n'.
10901
10902 When {pat} does not match in {string}, {string} is returned
10903 unmodified.
10904
10905 Example: >
10906 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10907< This removes the last component of the 'path' option. >
10908 :echo substitute("testing", ".*", "\\U\\0", "")
10909< results in "TESTING".
10910
10911 When {sub} starts with "\=", the remainder is interpreted as
10912 an expression. See |sub-replace-expression|. Example: >
10913 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010914 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010915
10916< When {sub} is a Funcref that function is called, with one
10917 optional argument. Example: >
10918 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10919< The optional argument is a list which contains the whole
10920 matched string and up to nine submatches, like what
10921 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010922 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010923
Bram Moolenaard592deb2022-06-17 15:42:40 +010010924< Returns an empty string on error.
10925
10926 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010927 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010928<
10929 Return type: |String|
10930
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010931
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010932swapfilelist() *swapfilelist()*
10933 Returns a list of swap file names, like what "vim -r" shows.
10934 See the |-r| command argument. The 'directory' option is used
10935 for the directories to inspect. If you only want to get a
10936 list of swap files in the current directory then temporarily
10937 set 'directory' to a dot: >
10938 let save_dir = &directory
10939 let &directory = '.'
10940 let swapfiles = swapfilelist()
10941 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010942<
10943 Return type: list<string>
10944
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010946swapinfo({fname}) *swapinfo()*
10947 The result is a dictionary, which holds information about the
10948 swapfile {fname}. The available fields are:
10949 version Vim version
10950 user user name
10951 host host name
10952 fname original file name
10953 pid PID of the Vim process that created the swap
10954 file
10955 mtime last modification time in seconds
10956 inode Optional: INODE number of the file
10957 dirty 1 if file was modified, 0 if not
10958 Note that "user" and "host" are truncated to at most 39 bytes.
10959 In case of failure an "error" item is added with the reason:
10960 Cannot open file: file not found or in accessible
10961 Cannot read file: cannot read first block
10962 Not a swap file: does not contain correct block ID
10963 Magic number mismatch: Info in first block is invalid
10964
10965 Can also be used as a |method|: >
10966 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010967<
10968 Return type: dict<any> or dict<string>
10969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010970
10971swapname({buf}) *swapname()*
10972 The result is the swap file path of the buffer {expr}.
10973 For the use of {buf}, see |bufname()| above.
10974 If buffer {buf} is the current buffer, the result is equal to
10975 |:swapname| (unless there is no swap file).
10976 If buffer {buf} has no swap file, returns an empty string.
10977
10978 Can also be used as a |method|: >
10979 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010980<
10981 Return type: |String|
10982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010983
10984synID({lnum}, {col}, {trans}) *synID()*
10985 The result is a Number, which is the syntax ID at the position
10986 {lnum} and {col} in the current window.
10987 The syntax ID can be used with |synIDattr()| and
10988 |synIDtrans()| to obtain syntax information about text.
10989
10990 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10991 line. 'synmaxcol' applies, in a longer line zero is returned.
10992 Note that when the position is after the last character,
10993 that's where the cursor can be in Insert mode, synID() returns
10994 zero. {lnum} is used like with |getline()|.
10995
10996 When {trans} is |TRUE|, transparent items are reduced to the
10997 item that they reveal. This is useful when wanting to know
10998 the effective color. When {trans} is |FALSE|, the transparent
10999 item is returned. This is useful when wanting to know which
11000 syntax item is effective (e.g. inside parens).
11001 Warning: This function can be very slow. Best speed is
11002 obtained by going through the file in forward direction.
11003
Bram Moolenaard592deb2022-06-17 15:42:40 +010011004 Returns zero on error.
11005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011006 Example (echoes the name of the syntax item under the cursor): >
11007 :echo synIDattr(synID(line("."), col("."), 1), "name")
11008<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011009 Return type: |Number|
11010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011011
11012synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11013 The result is a String, which is the {what} attribute of
11014 syntax ID {synID}. This can be used to obtain information
11015 about a syntax item.
11016 {mode} can be "gui", "cterm" or "term", to get the attributes
11017 for that mode. When {mode} is omitted, or an invalid value is
11018 used, the attributes for the currently active highlighting are
11019 used (GUI, cterm or term).
11020 Use synIDtrans() to follow linked highlight groups.
11021 {what} result
11022 "name" the name of the syntax item
11023 "fg" foreground color (GUI: color name used to set
11024 the color, cterm: color number as a string,
11025 term: empty string)
11026 "bg" background color (as with "fg")
11027 "font" font name (only available in the GUI)
11028 |highlight-font|
11029 "sp" special color for the GUI (as with "fg")
11030 |highlight-guisp|
11031 "ul" underline color for cterm: number as a string
11032 "fg#" like "fg", but for the GUI and the GUI is
11033 running the name in "#RRGGBB" form
11034 "bg#" like "fg#" for "bg"
11035 "sp#" like "fg#" for "sp"
11036 "bold" "1" if bold
11037 "italic" "1" if italic
11038 "reverse" "1" if reverse
11039 "inverse" "1" if inverse (= reverse)
11040 "standout" "1" if standout
11041 "underline" "1" if underlined
11042 "undercurl" "1" if undercurled
11043 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011044 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011045
Bram Moolenaard592deb2022-06-17 15:42:40 +010011046 Returns an empty string on error.
11047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011048 Example (echoes the color of the syntax item under the
11049 cursor): >
11050 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11051<
11052 Can also be used as a |method|: >
11053 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011054<
11055 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011056
11057
11058synIDtrans({synID}) *synIDtrans()*
11059 The result is a Number, which is the translated syntax ID of
11060 {synID}. This is the syntax group ID of what is being used to
11061 highlight the character. Highlight links given with
11062 ":highlight link" are followed.
11063
Bram Moolenaard592deb2022-06-17 15:42:40 +010011064 Returns zero on error.
11065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011066 Can also be used as a |method|: >
11067 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011068<
11069 Return type: |Number|
11070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011071
11072synconcealed({lnum}, {col}) *synconcealed()*
11073 The result is a |List| with currently three items:
11074 1. The first item in the list is 0 if the character at the
11075 position {lnum} and {col} is not part of a concealable
11076 region, 1 if it is. {lnum} is used like with |getline()|.
11077 2. The second item in the list is a string. If the first item
11078 is 1, the second item contains the text which will be
11079 displayed in place of the concealed text, depending on the
11080 current setting of 'conceallevel' and 'listchars'.
11081 3. The third and final item in the list is a number
11082 representing the specific syntax region matched in the
11083 line. When the character is not concealed the value is
11084 zero. This allows detection of the beginning of a new
11085 concealable region if there are two consecutive regions
11086 with the same replacement character. For an example, if
11087 the text is "123456" and both "23" and "45" are concealed
11088 and replaced by the character "X", then:
11089 call returns ~
11090 synconcealed(lnum, 1) [0, '', 0]
11091 synconcealed(lnum, 2) [1, 'X', 1]
11092 synconcealed(lnum, 3) [1, 'X', 1]
11093 synconcealed(lnum, 4) [1, 'X', 2]
11094 synconcealed(lnum, 5) [1, 'X', 2]
11095 synconcealed(lnum, 6) [0, '', 0]
11096
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011097 Note: Doesn't consider |matchadd()| highlighting items,
11098 since syntax and matching highlighting are two different
11099 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011100<
11101 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011102
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011103
11104synstack({lnum}, {col}) *synstack()*
11105 Return a |List|, which is the stack of syntax items at the
11106 position {lnum} and {col} in the current window. {lnum} is
11107 used like with |getline()|. Each item in the List is an ID
11108 like what |synID()| returns.
11109 The first item in the List is the outer region, following are
11110 items contained in that one. The last one is what |synID()|
11111 returns, unless not the whole item is highlighted or it is a
11112 transparent item.
11113 This function is useful for debugging a syntax file.
11114 Example that shows the syntax stack under the cursor: >
11115 for id in synstack(line("."), col("."))
11116 echo synIDattr(id, "name")
11117 endfor
11118< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011119 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011120 character in a line and the first column in an empty line are
11121 valid positions.
11122
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011123 Return type: list<number> or list<any>
11124
11125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011126system({expr} [, {input}]) *system()* *E677*
11127 Get the output of the shell command {expr} as a |String|. See
11128 |systemlist()| to get the output as a |List|.
11129
11130 When {input} is given and is a |String| this string is written
11131 to a file and passed as stdin to the command. The string is
11132 written as-is, you need to take care of using the correct line
11133 separators yourself.
11134 If {input} is given and is a |List| it is written to the file
11135 in a way |writefile()| does with {binary} set to "b" (i.e.
11136 with a newline between each list item with newlines inside
11137 list items converted to NULs).
11138 When {input} is given and is a number that is a valid id for
11139 an existing buffer then the content of the buffer is written
11140 to the file line by line, each line terminated by a NL and
11141 NULs characters where the text has a NL.
11142
11143 Pipes are not used, the 'shelltemp' option is not used.
11144
11145 When prepended by |:silent| the terminal will not be set to
11146 cooked mode. This is meant to be used for commands that do
11147 not need the user to type. It avoids stray characters showing
11148 up on the screen which require |CTRL-L| to remove. >
11149 :silent let f = system('ls *.vim')
11150<
11151 Note: Use |shellescape()| or |::S| with |expand()| or
11152 |fnamemodify()| to escape special characters in a command
11153 argument. Newlines in {expr} may cause the command to fail.
11154 The characters in 'shellquote' and 'shellxquote' may also
11155 cause trouble.
11156 This is not to be used for interactive commands.
11157
11158 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011159 :let files = system('ls ' .. shellescape(expand('%:h')))
11160 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011161
11162< To make the result more system-independent, the shell output
11163 is filtered to replace <CR> with <NL> for Macintosh, and
11164 <CR><NL> with <NL> for DOS-like systems.
11165 To avoid the string being truncated at a NUL, all NUL
11166 characters are replaced with SOH (0x01).
11167
11168 The command executed is constructed using several options:
11169 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11170 ({tmp} is an automatically generated file name).
11171 For Unix, braces are put around {expr} to allow for
11172 concatenated commands.
11173
11174 The command will be executed in "cooked" mode, so that a
11175 CTRL-C will interrupt the command (on Unix at least).
11176
11177 The resulting error code can be found in |v:shell_error|.
11178 This function will fail in |restricted-mode|.
11179
11180 Note that any wrong value in the options mentioned above may
11181 make the function fail. It has also been reported to fail
11182 when using a security agent application.
11183 Unlike ":!cmd" there is no automatic check for changed files.
11184 Use |:checktime| to force a check.
11185
11186 Can also be used as a |method|: >
11187 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011188<
11189 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011190
11191
11192systemlist({expr} [, {input}]) *systemlist()*
11193 Same as |system()|, but returns a |List| with lines (parts of
11194 output separated by NL) with NULs transformed into NLs. Output
11195 is the same as |readfile()| will output with {binary} argument
11196 set to "b", except that there is no extra empty item when the
11197 result ends in a NL.
11198 Note that on MS-Windows you may get trailing CR characters.
11199
11200 To see the difference between "echo hello" and "echo -n hello"
11201 use |system()| and |split()|: >
11202 echo system('echo hello')->split('\n', 1)
11203<
11204 Returns an empty string on error.
11205
11206 Can also be used as a |method|: >
11207 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011208<
11209 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011210
11211
11212tabpagebuflist([{arg}]) *tabpagebuflist()*
11213 The result is a |List|, where each item is the number of the
11214 buffer associated with each window in the current tab page.
11215 {arg} specifies the number of the tab page to be used. When
11216 omitted the current tab page is used.
11217 When {arg} is invalid the number zero is returned.
11218 To get a list of all buffers in all tabs use this: >
11219 let buflist = []
11220 for i in range(tabpagenr('$'))
11221 call extend(buflist, tabpagebuflist(i + 1))
11222 endfor
11223< Note that a buffer may appear in more than one window.
11224
11225 Can also be used as a |method|: >
11226 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011227<
11228 Return type: list<number>
11229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011230
11231tabpagenr([{arg}]) *tabpagenr()*
11232 The result is a Number, which is the number of the current
11233 tab page. The first tab page has number 1.
11234
11235 The optional argument {arg} supports the following values:
11236 $ the number of the last tab page (the tab page
11237 count).
11238 # the number of the last accessed tab page
11239 (where |g<Tab>| goes to). if there is no
11240 previous tab page 0 is returned.
11241 The number can be used with the |:tab| command.
11242
Bram Moolenaard592deb2022-06-17 15:42:40 +010011243 Returns zero on error.
11244
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011245 Return type: |Number|
11246
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011247
11248tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11249 Like |winnr()| but for tab page {tabarg}.
11250 {tabarg} specifies the number of tab page to be used.
11251 {arg} is used like with |winnr()|:
11252 - When omitted the current window number is returned. This is
11253 the window which will be used when going to this tab page.
11254 - When "$" the number of windows is returned.
11255 - When "#" the previous window nr is returned.
11256 Useful examples: >
11257 tabpagewinnr(1) " current window of tab page 1
11258 tabpagewinnr(4, '$') " number of windows in tab page 4
11259< When {tabarg} is invalid zero is returned.
11260
11261 Can also be used as a |method|: >
11262 GetTabpage()->tabpagewinnr()
11263<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011264 Return type: |Number|
11265
11266
11267tagfiles() *tagfiles()*
11268 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011269 for the current buffer. This is the 'tags' option expanded.
11270
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011271 Return type: list<string> or list<any>
11272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011273
11274taglist({expr} [, {filename}]) *taglist()*
11275 Returns a |List| of tags matching the regular expression {expr}.
11276
11277 If {filename} is passed it is used to prioritize the results
11278 in the same way that |:tselect| does. See |tag-priority|.
11279 {filename} should be the full path of the file.
11280
11281 Each list item is a dictionary with at least the following
11282 entries:
11283 name Name of the tag.
11284 filename Name of the file where the tag is
11285 defined. It is either relative to the
11286 current directory or a full path.
11287 cmd Ex command used to locate the tag in
11288 the file.
11289 kind Type of the tag. The value for this
11290 entry depends on the language specific
11291 kind values. Only available when
11292 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011293 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011294 static A file specific tag. Refer to
11295 |static-tag| for more information.
11296 More entries may be present, depending on the content of the
11297 tags file: access, implementation, inherits and signature.
11298 Refer to the ctags documentation for information about these
11299 fields. For C code the fields "struct", "class" and "enum"
11300 may appear, they give the name of the entity the tag is
11301 contained in.
11302
11303 The ex-command "cmd" can be either an ex search pattern, a
11304 line number or a line number followed by a byte number.
11305
11306 If there are no matching tags, then an empty list is returned.
11307
11308 To get an exact tag match, the anchors '^' and '$' should be
11309 used in {expr}. This also make the function work faster.
11310 Refer to |tag-regexp| for more information about the tag
11311 search regular expression pattern.
11312
11313 Refer to |'tags'| for information about how the tags file is
11314 located by Vim. Refer to |tags-file-format| for the format of
11315 the tags file generated by the different ctags tools.
11316
11317 Can also be used as a |method|: >
11318 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011319<
11320 Return type: list<dict<any>> or list<any>
11321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011322
11323tan({expr}) *tan()*
11324 Return the tangent of {expr}, measured in radians, as a |Float|
11325 in the range [-inf, inf].
11326 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011327 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011328 Examples: >
11329 :echo tan(10)
11330< 0.648361 >
11331 :echo tan(-4.01)
11332< -1.181502
11333
11334 Can also be used as a |method|: >
11335 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011336<
11337 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011338
11339
11340tanh({expr}) *tanh()*
11341 Return the hyperbolic tangent of {expr} as a |Float| in the
11342 range [-1, 1].
11343 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011344 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011345 Examples: >
11346 :echo tanh(0.5)
11347< 0.462117 >
11348 :echo tanh(-1)
11349< -0.761594
11350
11351 Can also be used as a |method|: >
11352 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011353<
11354 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011355
11356
11357tempname() *tempname()* *temp-file-name*
11358 The result is a String, which is the name of a file that
11359 doesn't exist. It can be used for a temporary file. The name
11360 is different for at least 26 consecutive calls. Example: >
11361 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011362 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011363< For Unix, the file will be in a private directory |tempfile|
11364 that is recursively deleted when Vim exits, on other systems
11365 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011366 For MS-Windows forward slashes are used when the 'shellslash'
11367 option is set, or when 'shellcmdflag' starts with '-' and
11368 'shell' does not contain powershell or pwsh.
11369
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011370 Return type: |String|
11371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011372
11373term_ functions are documented here: |terminal-function-details|
11374
11375
11376terminalprops() *terminalprops()*
11377 Returns a |Dictionary| with properties of the terminal that Vim
11378 detected from the response to |t_RV| request. See
11379 |v:termresponse| for the response itself. If |v:termresponse|
11380 is empty most values here will be 'u' for unknown.
11381 cursor_style whether sending |t_RS| works **
11382 cursor_blink_mode whether sending |t_RC| works **
11383 underline_rgb whether |t_8u| works **
11384 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011385 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011386
11387 ** value 'u' for unknown, 'y' for yes, 'n' for no
11388
11389 If the |+termresponse| feature is missing then the result is
11390 an empty dictionary.
11391
11392 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11393 current cursor style.
11394 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11395 request the cursor blink status.
11396 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11397 is not empty, Vim will detect the working of sending |t_RS|
11398 and |t_RC| on startup.
11399
11400 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11401 This avoids sending it to xterm, which would clear the colors.
11402
11403 For "mouse" the value 'u' is unknown
11404
11405 Also see:
11406 - 'ambiwidth' - detected by using |t_u7|.
11407 - |v:termstyleresp| and |v:termblinkresp| for the response to
11408 |t_RS| and |t_RC|.
11409
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011410 Return type: dict<string>
11411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011412
11413test_ functions are documented here: |test-functions-details|
11414
11415
11416 *timer_info()*
11417timer_info([{id}])
11418 Return a list with information about timers.
11419 When {id} is given only information about this timer is
11420 returned. When timer {id} does not exist an empty list is
11421 returned.
11422 When {id} is omitted information about all timers is returned.
11423
11424 For each timer the information is stored in a |Dictionary| with
11425 these items:
11426 "id" the timer ID
11427 "time" time the timer was started with
11428 "remaining" time until the timer fires
11429 "repeat" number of times the timer will still fire;
11430 -1 means forever
11431 "callback" the callback
11432 "paused" 1 if the timer is paused, 0 otherwise
11433
11434 Can also be used as a |method|: >
11435 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011436<
11437 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011438
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011439 {only available when compiled with the |+timers| feature}
11440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011441
11442timer_pause({timer}, {paused}) *timer_pause()*
11443 Pause or unpause a timer. A paused timer does not invoke its
11444 callback when its time expires. Unpausing a timer may cause
11445 the callback to be invoked almost immediately if enough time
11446 has passed.
11447
11448 Pausing a timer is useful to avoid the callback to be called
11449 for a short time.
11450
11451 If {paused} evaluates to a non-zero Number or a non-empty
11452 String, then the timer is paused, otherwise it is unpaused.
11453 See |non-zero-arg|.
11454
11455 Can also be used as a |method|: >
11456 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011457<
11458 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011459
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011460 {only available when compiled with the |+timers| feature}
11461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011462
11463 *timer_start()* *timer* *timers*
11464timer_start({time}, {callback} [, {options}])
11465 Create a timer and return the timer ID.
11466
11467 {time} is the waiting time in milliseconds. This is the
11468 minimum time before invoking the callback. When the system is
11469 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011470 Zero can be used to execute the callback when Vim is back in
11471 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011472
11473 {callback} is the function to call. It can be the name of a
11474 function or a |Funcref|. It is called with one argument, which
11475 is the timer ID. The callback is only invoked when Vim is
11476 waiting for input.
11477 If you want to show a message look at |popup_notification()|
11478 to avoid interfering with what the user is doing.
11479
11480 {options} is a dictionary. Supported entries:
11481 "repeat" Number of times to repeat calling the
11482 callback. -1 means forever. When not present
11483 the callback will be called once.
11484 If the timer causes an error three times in a
11485 row the repeat is cancelled. This avoids that
11486 Vim becomes unusable because of all the error
11487 messages.
11488
Bram Moolenaard592deb2022-06-17 15:42:40 +010011489 Returns -1 on error.
11490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011491 Example: >
11492 func MyHandler(timer)
11493 echo 'Handler called'
11494 endfunc
11495 let timer = timer_start(500, 'MyHandler',
11496 \ {'repeat': 3})
11497< This will invoke MyHandler() three times at 500 msec
11498 intervals.
11499
11500 Can also be used as a |method|: >
11501 GetMsec()->timer_start(callback)
11502
11503< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011504
11505 Return type: |Number|
11506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011507 {only available when compiled with the |+timers| feature}
11508
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011510timer_stop({timer}) *timer_stop()*
11511 Stop a timer. The timer callback will no longer be invoked.
11512 {timer} is an ID returned by timer_start(), thus it must be a
11513 Number. If {timer} does not exist there is no error.
11514
11515 Can also be used as a |method|: >
11516 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011517<
11518 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011519
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011520 {only available when compiled with the |+timers| feature}
11521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011522
11523timer_stopall() *timer_stopall()*
11524 Stop all timers. The timer callbacks will no longer be
11525 invoked. Useful if a timer is misbehaving. If there are no
11526 timers there is no error.
11527
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011528 Return type: |Number|
11529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011530 {only available when compiled with the |+timers| feature}
11531
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011533tolower({expr}) *tolower()*
11534 The result is a copy of the String given, with all uppercase
11535 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011536 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011537
11538 Can also be used as a |method|: >
11539 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011540<
11541 Return type: |String|
11542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011543
11544toupper({expr}) *toupper()*
11545 The result is a copy of the String given, with all lowercase
11546 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011547 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011548
11549 Can also be used as a |method|: >
11550 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011551<
11552 Return type: |String|
11553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011554
11555tr({src}, {fromstr}, {tostr}) *tr()*
11556 The result is a copy of the {src} string with all characters
11557 which appear in {fromstr} replaced by the character in that
11558 position in the {tostr} string. Thus the first character in
11559 {fromstr} is translated into the first character in {tostr}
11560 and so on. Exactly like the unix "tr" command.
11561 This code also deals with multibyte characters properly.
11562
Bram Moolenaard592deb2022-06-17 15:42:40 +010011563 Returns an empty string on error.
11564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011565 Examples: >
11566 echo tr("hello there", "ht", "HT")
11567< returns "Hello THere" >
11568 echo tr("<blob>", "<>", "{}")
11569< returns "{blob}"
11570
11571 Can also be used as a |method|: >
11572 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011573<
11574 Return type: |String|
11575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011576
11577trim({text} [, {mask} [, {dir}]]) *trim()*
11578 Return {text} as a String where any character in {mask} is
11579 removed from the beginning and/or end of {text}.
11580
Illia Bobyr80799172023-10-17 18:00:50 +020011581 If {mask} is not given, or is an empty string, {mask} is all
11582 characters up to 0x20, which includes Tab, space, NL and CR,
11583 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011584
11585 The optional {dir} argument specifies where to remove the
11586 characters:
11587 0 remove from the beginning and end of {text}
11588 1 remove only at the beginning of {text}
11589 2 remove only at the end of {text}
11590 When omitted both ends are trimmed.
11591
11592 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011593 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011594
11595 Examples: >
11596 echo trim(" some text ")
11597< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011598 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011599< returns "RESERVE_TAIL" >
11600 echo trim("rm<Xrm<>X>rrm", "rm<>")
11601< returns "Xrm<>X" (characters in the middle are not removed) >
11602 echo trim(" vim ", " ", 2)
11603< returns " vim"
11604
11605 Can also be used as a |method|: >
11606 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011607<
11608 Return type: |String|
11609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011610
11611trunc({expr}) *trunc()*
11612 Return the largest integral value with magnitude less than or
11613 equal to {expr} as a |Float| (truncate towards zero).
11614 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011615 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011616 Examples: >
11617 echo trunc(1.456)
11618< 1.0 >
11619 echo trunc(-5.456)
11620< -5.0 >
11621 echo trunc(4.0)
11622< 4.0
11623
11624 Can also be used as a |method|: >
11625 Compute()->trunc()
11626<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011627 Return type: |Float|
11628
11629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011630 *type()*
11631type({expr}) The result is a Number representing the type of {expr}.
11632 Instead of using the number directly, it is better to use the
11633 v:t_ variable that has the value:
11634 Number: 0 |v:t_number|
11635 String: 1 |v:t_string|
11636 Funcref: 2 |v:t_func|
11637 List: 3 |v:t_list|
11638 Dictionary: 4 |v:t_dict|
11639 Float: 5 |v:t_float|
11640 Boolean: 6 |v:t_bool| (v:false and v:true)
11641 None: 7 |v:t_none| (v:null and v:none)
11642 Job: 8 |v:t_job|
11643 Channel: 9 |v:t_channel|
11644 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011645 Class: 12 |v:t_class|
11646 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011647 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011648 Enum: 15 |v:t_enum|
11649 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011650 For backward compatibility, this method can be used: >
11651 :if type(myvar) == type(0)
11652 :if type(myvar) == type("")
11653 :if type(myvar) == type(function("tr"))
11654 :if type(myvar) == type([])
11655 :if type(myvar) == type({})
11656 :if type(myvar) == type(0.0)
11657 :if type(myvar) == type(v:false)
11658 :if type(myvar) == type(v:none)
11659< To check if the v:t_ variables exist use this: >
11660 :if exists('v:t_number')
11661
11662< Can also be used as a |method|: >
11663 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011664<
11665 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011666
11667
11668typename({expr}) *typename()*
11669 Return a string representation of the type of {expr}.
11670 Example: >
11671 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011672< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011673
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011674 Return type: |String|
11675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011676
11677undofile({name}) *undofile()*
11678 Return the name of the undo file that would be used for a file
11679 with name {name} when writing. This uses the 'undodir'
11680 option, finding directories that exist. It does not check if
11681 the undo file exists.
11682 {name} is always expanded to the full path, since that is what
11683 is used internally.
11684 If {name} is empty undofile() returns an empty string, since a
11685 buffer without a file name will not write an undo file.
11686 Useful in combination with |:wundo| and |:rundo|.
11687 When compiled without the |+persistent_undo| option this always
11688 returns an empty string.
11689
11690 Can also be used as a |method|: >
11691 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011692<
11693 Return type: |String|
11694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011695
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011696undotree([{buf}]) *undotree()*
11697 Return the current state of the undo tree for the current
11698 buffer, or for a specific buffer if {buf} is given. The
11699 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011700 "seq_last" The highest undo sequence number used.
11701 "seq_cur" The sequence number of the current position in
11702 the undo tree. This differs from "seq_last"
11703 when some changes were undone.
11704 "time_cur" Time last used for |:earlier| and related
11705 commands. Use |strftime()| to convert to
11706 something readable.
11707 "save_last" Number of the last file write. Zero when no
11708 write yet.
11709 "save_cur" Number of the current position in the undo
11710 tree.
11711 "synced" Non-zero when the last undo block was synced.
11712 This happens when waiting from input from the
11713 user. See |undo-blocks|.
11714 "entries" A list of dictionaries with information about
11715 undo blocks.
11716
11717 The first item in the "entries" list is the oldest undo item.
11718 Each List item is a |Dictionary| with these items:
11719 "seq" Undo sequence number. Same as what appears in
11720 |:undolist|.
11721 "time" Timestamp when the change happened. Use
11722 |strftime()| to convert to something readable.
11723 "newhead" Only appears in the item that is the last one
11724 that was added. This marks the last change
11725 and where further changes will be added.
11726 "curhead" Only appears in the item that is the last one
11727 that was undone. This marks the current
11728 position in the undo tree, the block that will
11729 be used by a redo command. When nothing was
11730 undone after the last change this item will
11731 not appear anywhere.
11732 "save" Only appears on the last block before a file
11733 write. The number is the write count. The
11734 first write has number 1, the last one the
11735 "save_last" mentioned above.
11736 "alt" Alternate entry. This is again a List of undo
11737 blocks. Each item may again have an "alt"
11738 item.
11739
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011740 Return type: dict<any>
11741
11742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011743uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11744 Remove second and succeeding copies of repeated adjacent
11745 {list} items in-place. Returns {list}. If you want a list
11746 to remain unmodified make a copy first: >
11747 :let newlist = uniq(copy(mylist))
11748< The default compare function uses the string representation of
11749 each item. For the use of {func} and {dict} see |sort()|.
11750
Bram Moolenaard592deb2022-06-17 15:42:40 +010011751 Returns zero if {list} is not a |List|.
11752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011753 Can also be used as a |method|: >
11754 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011755<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011756 Return type: list<{type}>
11757
11758
Christian Brabandt67672ef2023-04-24 21:09:54 +010011759 *utf16idx()*
11760utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011761 Same as |charidx()| but returns the UTF-16 code unit index of
11762 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011763
11764 When {charidx} is present and TRUE, {idx} is used as the
11765 character index in the String {string} instead of as the byte
11766 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011767 An {idx} in the middle of a UTF-8 sequence is rounded
11768 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011769
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011770 Returns -1 if the arguments are invalid or if there are less
11771 than {idx} bytes in {string}. If there are exactly {idx} bytes
11772 the length of the string in UTF-16 code units is returned.
11773
Christian Brabandt67672ef2023-04-24 21:09:54 +010011774 See |byteidx()| and |byteidxcomp()| for getting the byte index
11775 from the UTF-16 index and |charidx()| for getting the
11776 character index from the UTF-16 index.
11777 Refer to |string-offset-encoding| for more information.
11778 Examples: >
11779 echo utf16idx('a😊😊', 3) returns 2
11780 echo utf16idx('a😊😊', 7) returns 4
11781 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11782 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11783 echo utf16idx('aą́c', 6) returns 2
11784 echo utf16idx('aą́c', 6, 1) returns 4
11785 echo utf16idx('a😊😊', 9) returns -1
11786<
11787 Can also be used as a |method|: >
11788 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011789<
11790 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011792
11793values({dict}) *values()*
11794 Return a |List| with all the values of {dict}. The |List| is
11795 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011796 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011797
11798 Can also be used as a |method|: >
11799 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011800<
11801 Return type: list<any>
11802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011803
zeertzjq825cf812023-08-17 22:55:25 +020011804virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011805 The result is a Number, which is the screen column of the file
11806 position given with {expr}. That is, the last screen position
11807 occupied by the character at that position, when the screen
11808 would be of unlimited width. When there is a <Tab> at the
11809 position, the returned Number will be the column at the end of
11810 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11811 set to 8, it returns 8. |conceal| is ignored.
11812 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011813
zeertzjq02f3eba2024-06-12 20:45:24 +020011814 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011815 When {expr} is "$", it means the end of the cursor line, so
11816 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011817
11818 When 'virtualedit' is used {expr} can be [lnum, col, off],
11819 where "off" is the offset in screen columns from the start of
11820 the character. E.g., a position within a <Tab> or after the
11821 last character. When "off" is omitted zero is used. When
11822 Virtual editing is active in the current mode, a position
11823 beyond the end of the line can be returned. Also see
11824 |'virtualedit'|
11825
zeertzjq825cf812023-08-17 22:55:25 +020011826 If {list} is present and non-zero then virtcol() returns a
11827 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011828 character.
11829
zeertzjq825cf812023-08-17 22:55:25 +020011830 With the optional {winid} argument the values are obtained for
11831 that window instead of the current window.
11832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011833 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011835 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011836 " With text "foo^Lbar" and cursor on the "^L":
11837
11838 virtcol(".") " returns 5
11839 virtcol(".", 1) " returns [4, 5]
11840 virtcol("$") " returns 9
11841
11842 " With text " there", with 't at 'h':
11843
11844 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011845<
11846 The first column is 1. 0 or [0, 0] is returned for an error.
11847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011848 A more advanced example that echoes the maximum length of
11849 all lines: >
11850 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11851
11852< Can also be used as a |method|: >
11853 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011854<
11855 Return type: |Number|
11856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011857
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011858virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11859 The result is a Number, which is the byte index of the
11860 character in window {winid} at buffer line {lnum} and virtual
11861 column {col}.
11862
zeertzjqb583eda2023-10-14 11:32:28 +020011863 If buffer line {lnum} is an empty line, 0 is returned.
11864
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011865 If {col} is greater than the last virtual column in line
11866 {lnum}, then the byte index of the character at the last
11867 virtual column is returned.
11868
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011869 For a multi-byte character, the column number of the first
11870 byte in the character is returned.
11871
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011872 The {winid} argument can be the window number or the
11873 |window-ID|. If this is zero, then the current window is used.
11874
11875 Returns -1 if the window {winid} doesn't exist or the buffer
11876 line {lnum} or virtual column {col} is invalid.
11877
11878 See also |screenpos()|, |virtcol()| and |col()|.
11879
11880 Can also be used as a |method|: >
11881 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011882<
11883 Return type: |Number|
11884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011885
11886visualmode([{expr}]) *visualmode()*
11887 The result is a String, which describes the last Visual mode
11888 used in the current buffer. Initially it returns an empty
11889 string, but once Visual mode has been used, it returns "v",
11890 "V", or "<CTRL-V>" (a single CTRL-V character) for
11891 character-wise, line-wise, or block-wise Visual mode
11892 respectively.
11893 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011894 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011895< This enters the same Visual mode as before. It is also useful
11896 in scripts if you wish to act differently depending on the
11897 Visual mode that was used.
11898 If Visual mode is active, use |mode()| to get the Visual mode
11899 (e.g., in a |:vmap|).
11900 If {expr} is supplied and it evaluates to a non-zero Number or
11901 a non-empty String, then the Visual mode will be cleared and
11902 the old value is returned. See |non-zero-arg|.
11903
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011904 Return type: |String|
11905
11906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011907wildmenumode() *wildmenumode()*
11908 Returns |TRUE| when the wildmenu is active and |FALSE|
11909 otherwise. See 'wildmenu' and 'wildmode'.
11910 This can be used in mappings to handle the 'wildcharm' option
11911 gracefully. (Makes only sense with |mapmode-c| mappings).
11912
11913 For example to make <c-j> work like <down> in wildmode, use: >
11914 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11915<
11916 (Note, this needs the 'wildcharm' option set appropriately).
11917
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011918 Return type: |Number|
11919
11920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011921win_execute({id}, {command} [, {silent}]) *win_execute()*
11922 Like `execute()` but in the context of window {id}.
11923 The window will temporarily be made the current window,
11924 without triggering autocommands or changing directory. When
11925 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011926 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011927 Example: >
11928 call win_execute(winid, 'set syntax=python')
11929< Doing the same with `setwinvar()` would not trigger
11930 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011931 *E994*
11932 Not all commands are allowed in popup windows.
11933 When window {id} does not exist then no error is given and
11934 an empty string is returned.
11935
11936 Can also be used as a |method|, the base is passed as the
11937 second argument: >
11938 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011939<
11940 Return type: |String|
11941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011942
11943win_findbuf({bufnr}) *win_findbuf()*
11944 Returns a |List| with |window-ID|s for windows that contain
11945 buffer {bufnr}. When there is none the list is empty.
11946
11947 Can also be used as a |method|: >
11948 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011949<
11950 Return type: list<number> or list<any>
11951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011952
11953win_getid([{win} [, {tab}]]) *win_getid()*
11954 Get the |window-ID| for the specified window.
11955 When {win} is missing use the current window.
11956 With {win} this is the window number. The top window has
11957 number 1.
11958 Without {tab} use the current tab, otherwise the tab with
11959 number {tab}. The first tab has number one.
11960 Return zero if the window cannot be found.
11961
11962 Can also be used as a |method|: >
11963 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011964<
11965 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011966
11967
11968win_gettype([{nr}]) *win_gettype()*
11969 Return the type of the window:
11970 "autocmd" autocommand window. Temporary window
11971 used to execute autocommands.
11972 "command" command-line window |cmdwin|
11973 (empty) normal window
11974 "loclist" |location-list-window|
11975 "popup" popup window |popup|
11976 "preview" preview window |preview-window|
11977 "quickfix" |quickfix-window|
11978 "unknown" window {nr} not found
11979
11980 When {nr} is omitted return the type of the current window.
11981 When {nr} is given return the type of this window by number or
11982 |window-ID|.
11983
11984 Also see the 'buftype' option. When running a terminal in a
11985 popup window then 'buftype' is "terminal" and win_gettype()
11986 returns "popup".
11987
11988 Can also be used as a |method|: >
11989 GetWinid()->win_gettype()
11990<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011991 Return type: |String|
11992
11993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011994win_gotoid({expr}) *win_gotoid()*
11995 Go to window with ID {expr}. This may also change the current
11996 tabpage.
11997 Return TRUE if successful, FALSE if the window cannot be found.
11998
11999 Can also be used as a |method|: >
12000 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012001<
12002 Return type: |Number|
12003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012004
12005win_id2tabwin({expr}) *win_id2tabwin()*
12006 Return a list with the tab number and window number of window
12007 with ID {expr}: [tabnr, winnr].
12008 Return [0, 0] if the window cannot be found.
12009
12010 Can also be used as a |method|: >
12011 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012012<
12013 Return type: list<number>
12014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012015
12016win_id2win({expr}) *win_id2win()*
12017 Return the window number of window with ID {expr}.
12018 Return 0 if the window cannot be found in the current tabpage.
12019
12020 Can also be used as a |method|: >
12021 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012022<
12023 Return type: |Number|
12024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012025
Daniel Steinbergee630312022-01-10 13:36:34 +000012026win_move_separator({nr}, {offset}) *win_move_separator()*
12027 Move window {nr}'s vertical separator (i.e., the right border)
12028 by {offset} columns, as if being dragged by the mouse. {nr}
12029 can be a window number or |window-ID|. A positive {offset}
12030 moves right and a negative {offset} moves left. Moving a
12031 window's vertical separator will change the width of the
12032 window and the width of other windows adjacent to the vertical
12033 separator. The magnitude of movement may be smaller than
12034 specified (e.g., as a consequence of maintaining
12035 'winminwidth'). Returns TRUE if the window can be found and
12036 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012037 This will fail for the rightmost window and a full-width
12038 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012039 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012040
12041 Can also be used as a |method|: >
12042 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012043<
12044 Return type: |Number|
12045
Daniel Steinbergee630312022-01-10 13:36:34 +000012046
12047win_move_statusline({nr}, {offset}) *win_move_statusline()*
12048 Move window {nr}'s status line (i.e., the bottom border) by
12049 {offset} rows, as if being dragged by the mouse. {nr} can be a
12050 window number or |window-ID|. A positive {offset} moves down
12051 and a negative {offset} moves up. Moving a window's status
12052 line will change the height of the window and the height of
12053 other windows adjacent to the status line. The magnitude of
12054 movement may be smaller than specified (e.g., as a consequence
12055 of maintaining 'winminheight'). Returns TRUE if the window can
12056 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012057 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012058
12059 Can also be used as a |method|: >
12060 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012061<
12062 Return type: |Number|
12063
Daniel Steinbergee630312022-01-10 13:36:34 +000012064
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012065win_screenpos({nr}) *win_screenpos()*
12066 Return the screen position of window {nr} as a list with two
12067 numbers: [row, col]. The first window always has position
12068 [1, 1], unless there is a tabline, then it is [2, 1].
12069 {nr} can be the window number or the |window-ID|. Use zero
12070 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012071 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012072
12073 Can also be used as a |method|: >
12074 GetWinid()->win_screenpos()
12075<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012076 Return type: list<number>
12077
12078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012079win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012080 Temporarily switch to window {target}, then move window {nr}
12081 to a new split adjacent to {target}.
12082 Unlike commands such as |:split|, no new windows are created
12083 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012084
12085 Both {nr} and {target} can be window numbers or |window-ID|s.
12086 Both must be in the current tab page.
12087
12088 Returns zero for success, non-zero for failure.
12089
12090 {options} is a |Dictionary| with the following optional entries:
12091 "vertical" When TRUE, the split is created vertically,
12092 like with |:vsplit|.
12093 "rightbelow" When TRUE, the split is made below or to the
12094 right (if vertical). When FALSE, it is done
12095 above or to the left (if vertical). When not
12096 present, the values of 'splitbelow' and
12097 'splitright' are used.
12098
12099 Can also be used as a |method|: >
12100 GetWinid()->win_splitmove(target)
12101<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012102 Return type: |Number|
12103
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012104
12105 *winbufnr()*
12106winbufnr({nr}) The result is a Number, which is the number of the buffer
12107 associated with window {nr}. {nr} can be the window number or
12108 the |window-ID|.
12109 When {nr} is zero, the number of the buffer in the current
12110 window is returned.
12111 When window {nr} doesn't exist, -1 is returned.
12112 Example: >
12113 :echo "The file in the current window is " . bufname(winbufnr(0))
12114<
12115 Can also be used as a |method|: >
12116 FindWindow()->winbufnr()->bufname()
12117<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012118 Return type: |Number|
12119
12120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012121 *wincol()*
12122wincol() The result is a Number, which is the virtual column of the
12123 cursor in the window. This is counting screen cells from the
12124 left side of the window. The leftmost column is one.
12125
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012126 Return type: |Number|
12127
12128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012129 *windowsversion()*
12130windowsversion()
12131 The result is a String. For MS-Windows it indicates the OS
12132 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12133 Windows XP is "5.1". For non-MS-Windows systems the result is
12134 an empty string.
12135
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012136 Return type: |String|
12137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012138winheight({nr}) *winheight()*
12139 The result is a Number, which is the height of window {nr}.
12140 {nr} can be the window number or the |window-ID|.
12141 When {nr} is zero, the height of the current window is
12142 returned. When window {nr} doesn't exist, -1 is returned.
12143 An existing window always has a height of zero or more.
12144 This excludes any window toolbar line.
12145 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012146 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012147
12148< Can also be used as a |method|: >
12149 GetWinid()->winheight()
12150<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012151 Return type: |Number|
12152
12153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012154winlayout([{tabnr}]) *winlayout()*
12155 The result is a nested List containing the layout of windows
12156 in a tabpage.
12157
12158 Without {tabnr} use the current tabpage, otherwise the tabpage
12159 with number {tabnr}. If the tabpage {tabnr} is not found,
12160 returns an empty list.
12161
12162 For a leaf window, it returns:
12163 ['leaf', {winid}]
12164 For horizontally split windows, which form a column, it
12165 returns:
12166 ['col', [{nested list of windows}]]
12167 For vertically split windows, which form a row, it returns:
12168 ['row', [{nested list of windows}]]
12169
12170 Example: >
12171 " Only one window in the tab page
12172 :echo winlayout()
12173 ['leaf', 1000]
12174 " Two horizontally split windows
12175 :echo winlayout()
12176 ['col', [['leaf', 1000], ['leaf', 1001]]]
12177 " The second tab page, with three horizontally split
12178 " windows, with two vertically split windows in the
12179 " middle window
12180 :echo winlayout(2)
12181 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12182 ['leaf', 1001]]], ['leaf', 1000]]]
12183<
12184 Can also be used as a |method|: >
12185 GetTabnr()->winlayout()
12186<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012187 Return type: list<any>
12188
12189
12190winline() *winline()*
12191 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012192 in the window. This is counting screen lines from the top of
12193 the window. The first line is one.
12194 If the cursor was moved the view on the file will be updated
12195 first, this may cause a scroll.
12196
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012197 Return type: |Number|
12198
12199
12200winnr([{arg}]) *winnr()*
12201 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012202 window. The top window has number 1.
12203 Returns zero for a popup window.
12204
12205 The optional argument {arg} supports the following values:
12206 $ the number of the last window (the window
12207 count).
12208 # the number of the last accessed window (where
12209 |CTRL-W_p| goes to). If there is no previous
12210 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012211 returned. May refer to the current window in
12212 some cases (e.g. when evaluating 'statusline'
12213 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012214 {N}j the number of the Nth window below the
12215 current window (where |CTRL-W_j| goes to).
12216 {N}k the number of the Nth window above the current
12217 window (where |CTRL-W_k| goes to).
12218 {N}h the number of the Nth window left of the
12219 current window (where |CTRL-W_h| goes to).
12220 {N}l the number of the Nth window right of the
12221 current window (where |CTRL-W_l| goes to).
12222 The number can be used with |CTRL-W_w| and ":wincmd w"
12223 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012224 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012225 Also see |tabpagewinnr()| and |win_getid()|.
12226 Examples: >
12227 let window_count = winnr('$')
12228 let prev_window = winnr('#')
12229 let wnum = winnr('3k')
12230
12231< Can also be used as a |method|: >
12232 GetWinval()->winnr()
12233<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012234 Return type: |Number|
12235
12236
12237winrestcmd() *winrestcmd()*
12238 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012239 the current window sizes. Only works properly when no windows
12240 are opened or closed and the current window and tab page is
12241 unchanged.
12242 Example: >
12243 :let cmd = winrestcmd()
12244 :call MessWithWindowSizes()
12245 :exe cmd
12246<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012247 Return type: |String|
12248
12249
12250winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012251 Uses the |Dictionary| returned by |winsaveview()| to restore
12252 the view of the current window.
12253 Note: The {dict} does not have to contain all values, that are
12254 returned by |winsaveview()|. If values are missing, those
12255 settings won't be restored. So you can use: >
12256 :call winrestview({'curswant': 4})
12257<
12258 This will only set the curswant value (the column the cursor
12259 wants to move on vertical movements) of the cursor to column 5
12260 (yes, that is 5), while all other settings will remain the
12261 same. This is useful, if you set the cursor position manually.
12262
12263 If you have changed the values the result is unpredictable.
12264 If the window size changed the result won't be the same.
12265
12266 Can also be used as a |method|: >
12267 GetView()->winrestview()
12268<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012269 Return type: |Number|
12270
12271
12272winsaveview() *winsaveview()*
12273 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012274 the view of the current window. Use |winrestview()| to
12275 restore the view.
12276 This is useful if you have a mapping that jumps around in the
12277 buffer and you want to go back to the original view.
12278 This does not save fold information. Use the 'foldenable'
12279 option to temporarily switch off folding, so that folds are
12280 not opened when moving around. This may have side effects.
12281 The return value includes:
12282 lnum cursor line number
12283 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012284 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012285 returns)
12286 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012287 curswant column for vertical movement (Note:
12288 the first column is zero, as opposed
12289 to what |getcurpos()| returns). After
12290 |$| command it will be a very large
12291 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012292 topline first line in the window
12293 topfill filler lines, only in diff mode
12294 leftcol first column displayed; only used when
12295 'wrap' is off
12296 skipcol columns skipped
12297 Note that no option values are saved.
12298
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012299 Return type: dict<number>
12300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012301
12302winwidth({nr}) *winwidth()*
12303 The result is a Number, which is the width of window {nr}.
12304 {nr} can be the window number or the |window-ID|.
12305 When {nr} is zero, the width of the current window is
12306 returned. When window {nr} doesn't exist, -1 is returned.
12307 An existing window always has a width of zero or more.
12308 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012309 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012310 :if winwidth(0) <= 50
12311 : 50 wincmd |
12312 :endif
12313< For getting the terminal or screen size, see the 'columns'
12314 option.
12315
12316 Can also be used as a |method|: >
12317 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012318<
12319 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012320
12321
12322wordcount() *wordcount()*
12323 The result is a dictionary of byte/chars/word statistics for
12324 the current buffer. This is the same info as provided by
12325 |g_CTRL-G|
12326 The return value includes:
12327 bytes Number of bytes in the buffer
12328 chars Number of chars in the buffer
12329 words Number of words in the buffer
12330 cursor_bytes Number of bytes before cursor position
12331 (not in Visual mode)
12332 cursor_chars Number of chars before cursor position
12333 (not in Visual mode)
12334 cursor_words Number of words before cursor position
12335 (not in Visual mode)
12336 visual_bytes Number of bytes visually selected
12337 (only in Visual mode)
12338 visual_chars Number of chars visually selected
12339 (only in Visual mode)
12340 visual_words Number of words visually selected
12341 (only in Visual mode)
12342
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012343 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012344
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012345
12346writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012347 When {object} is a |List| write it to file {fname}. Each list
12348 item is separated with a NL. Each list item must be a String
12349 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012350 All NL characters are replaced with a NUL character.
12351 Inserting CR characters needs to be done before passing {list}
12352 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012353
12354 When {object} is a |Blob| write the bytes to file {fname}
12355 unmodified, also when binary mode is not specified.
12356
12357 {flags} must be a String. These characters are recognized:
12358
12359 'b' Binary mode is used: There will not be a NL after the
12360 last list item. An empty item at the end does cause the
12361 last line in the file to end in a NL.
12362
12363 'a' Append mode is used, lines are appended to the file: >
12364 :call writefile(["foo"], "event.log", "a")
12365 :call writefile(["bar"], "event.log", "a")
12366<
12367 'D' Delete the file when the current function ends. This
12368 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012369 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012370< Fails when not in a function. Also see |:defer|.
12371
12372 's' fsync() is called after writing the file. This flushes
12373 the file to disk, if possible. This takes more time but
12374 avoids losing the file if the system crashes.
12375
12376 'S' fsync() is not called, even when 'fsync' is set.
12377
12378 When {flags} does not contain "S" or "s" then fsync() is
12379 called if the 'fsync' option is set.
12380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012381 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012383 When the write fails -1 is returned, otherwise 0. There is an
12384 error message if the file can't be created or when writing
12385 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012387 Also see |readfile()|.
12388 To copy a file byte for byte: >
12389 :let fl = readfile("foo", "b")
12390 :call writefile(fl, "foocopy", "b")
12391
12392< Can also be used as a |method|: >
12393 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012394<
12395 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012396
12397
12398xor({expr}, {expr}) *xor()*
12399 Bitwise XOR on the two arguments. The arguments are converted
12400 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012401 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012402 Example: >
12403 :let bits = xor(bits, 0x80)
12404<
12405 Can also be used as a |method|: >
12406 :let bits = bits->xor(0x80)
12407<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012408 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012409
12410==============================================================================
124113. Feature list *feature-list*
12412
12413There are three types of features:
124141. Features that are only supported when they have been enabled when Vim
12415 was compiled |+feature-list|. Example: >
12416 :if has("cindent")
12417< *gui_running*
124182. Features that are only supported when certain conditions have been met.
12419 Example: >
12420 :if has("gui_running")
12421< *has-patch*
124223. Beyond a certain version or at a certain version and including a specific
12423 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12424 later, or it is version 7.4 and patch 248 was included. Example: >
12425 :if has("patch-7.4.248")
12426< Note that it's possible for patch 248 to be omitted even though 249 is
12427 included. Only happens when cherry-picking patches.
12428 Note that this form only works for patch 7.4.237 and later, before that
12429 you need to check for the patch and the v:version. Example (checking
12430 version 6.2.148 or later): >
12431 :if v:version > 602 || (v:version == 602 && has("patch148"))
12432
12433Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12434use: `if exists('+shellslash')`
12435
12436
12437acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012438all_builtin_terms Compiled with all builtin terminals enabled. (always
12439 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012440amiga Amiga version of Vim.
12441arabic Compiled with Arabic support |Arabic|.
12442arp Compiled with ARP support (Amiga).
12443autocmd Compiled with autocommand support. (always true)
12444autochdir Compiled with support for 'autochdir'
12445autoservername Automatically enable |clientserver|
12446balloon_eval Compiled with |balloon-eval| support.
12447balloon_multiline GUI supports multiline balloons.
12448beos BeOS version of Vim.
12449browse Compiled with |:browse| support, and browse() will
12450 work.
12451browsefilter Compiled with support for |browsefilter|.
12452bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012453builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012454byte_offset Compiled with support for 'o' in 'statusline'
12455channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012456cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012457clientserver Compiled with remote invocation support |clientserver|.
12458clipboard Compiled with 'clipboard' support.
12459clipboard_working Compiled with 'clipboard' support and it can be used.
12460cmdline_compl Compiled with |cmdline-completion| support.
12461cmdline_hist Compiled with |cmdline-history| support.
12462cmdline_info Compiled with 'showcmd' and 'ruler' support.
12463comments Compiled with |'comments'| support.
12464compatible Compiled to be very Vi compatible.
12465conpty Platform where |ConPTY| can be used.
12466cryptv Compiled with encryption support |encryption|.
12467cscope Compiled with |cscope| support.
12468cursorbind Compiled with |'cursorbind'| (always true)
12469debug Compiled with "DEBUG" defined.
12470dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012471dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012472dialog_gui Compiled with GUI dialog support.
12473diff Compiled with |vimdiff| and 'diff' support.
12474digraphs Compiled with support for digraphs.
12475directx Compiled with support for DirectX and 'renderoptions'.
12476dnd Compiled with support for the "~ register |quote_~|.
12477drop_file Compiled with |drop_file| support.
12478ebcdic Compiled on a machine with ebcdic character set.
12479emacs_tags Compiled with support for Emacs tags.
12480eval Compiled with expression evaluation support. Always
12481 true, of course!
12482ex_extra |+ex_extra| (always true)
12483extra_search Compiled with support for |'incsearch'| and
12484 |'hlsearch'|
12485farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012486file_in_path Compiled with support for |gf| and |<cfile>| (always
12487 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012488filterpipe When 'shelltemp' is off pipes are used for shell
12489 read/write/filter commands
12490find_in_path Compiled with support for include file searches
12491 |+find_in_path|.
12492float Compiled with support for |Float|.
12493fname_case Case in file names matters (for Amiga and MS-Windows
12494 this is not present).
12495folding Compiled with |folding| support.
12496footer Compiled with GUI footer support. |gui-footer|
12497fork Compiled to use fork()/exec() instead of system().
12498gettext Compiled with message translation |multi-lang|
12499gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012500gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012501gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12502gui_gtk Compiled with GTK+ GUI (any version).
12503gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12504gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12505gui_haiku Compiled with Haiku GUI.
12506gui_mac Compiled with Macintosh GUI.
12507gui_motif Compiled with Motif GUI.
12508gui_photon Compiled with Photon GUI.
12509gui_running Vim is running in the GUI, or it will start soon.
12510gui_win32 Compiled with MS-Windows Win32 GUI.
12511gui_win32s idem, and Win32s system being used (Windows 3.1)
12512haiku Haiku version of Vim.
12513hangul_input Compiled with Hangul input support. |hangul|
12514hpux HP-UX version of Vim.
12515iconv Can use iconv() for conversion.
12516insert_expand Compiled with support for CTRL-X expansion commands in
12517 Insert mode. (always true)
12518job Compiled with support for |channel| and |job|
12519ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012520jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012521keymap Compiled with 'keymap' support.
12522lambda Compiled with |lambda| support.
12523langmap Compiled with 'langmap' support.
12524libcall Compiled with |libcall()| support.
12525linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12526 'breakindent' support.
12527linux Linux version of Vim.
12528lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012529 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012530listcmds Compiled with commands for the buffer list |:files|
12531 and the argument list |arglist|.
12532localmap Compiled with local mappings and abbr. |:map-local|
12533lua Compiled with Lua interface |Lua|.
12534mac Any Macintosh version of Vim cf. osx
12535macunix Synonym for osxdarwin
12536menu Compiled with support for |:menu|.
12537mksession Compiled with support for |:mksession|.
12538modify_fname Compiled with file name modifiers. |filename-modifiers|
12539 (always true)
12540mouse Compiled with support for mouse.
12541mouse_dec Compiled with support for Dec terminal mouse.
12542mouse_gpm Compiled with support for gpm (Linux console mouse)
12543mouse_gpm_enabled GPM mouse is working
12544mouse_netterm Compiled with support for netterm mouse.
12545mouse_pterm Compiled with support for qnx pterm mouse.
12546mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12547mouse_sgr Compiled with support for sgr mouse.
12548mouse_urxvt Compiled with support for urxvt mouse.
12549mouse_xterm Compiled with support for xterm mouse.
12550mouseshape Compiled with support for 'mouseshape'.
12551multi_byte Compiled with support for 'encoding' (always true)
12552multi_byte_encoding 'encoding' is set to a multibyte encoding.
12553multi_byte_ime Compiled with support for IME input method.
12554multi_lang Compiled with support for multiple languages.
12555mzscheme Compiled with MzScheme interface |mzscheme|.
12556nanotime Compiled with sub-second time stamp checks.
12557netbeans_enabled Compiled with support for |netbeans| and connected.
12558netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012559num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012560ole Compiled with OLE automation support for Win32.
12561osx Compiled for macOS cf. mac
12562osxdarwin Compiled for macOS, with |mac-darwin-feature|
12563packages Compiled with |packages| support.
12564path_extra Compiled with up/downwards search in 'path' and 'tags'
12565perl Compiled with Perl interface.
12566persistent_undo Compiled with support for persistent undo history.
12567postscript Compiled with PostScript file printing.
12568printer Compiled with |:hardcopy| support.
12569profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012570prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012571python Python 2.x interface available. |has-python|
12572python_compiled Compiled with Python 2.x interface. |has-python|
12573python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12574python3 Python 3.x interface available. |has-python|
12575python3_compiled Compiled with Python 3.x interface. |has-python|
12576python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012577python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012578pythonx Python 2.x and/or 3.x interface available. |python_x|
12579qnx QNX version of Vim.
12580quickfix Compiled with |quickfix| support.
12581reltime Compiled with |reltime()| support.
12582rightleft Compiled with 'rightleft' support.
12583ruby Compiled with Ruby interface |ruby|.
12584scrollbind Compiled with 'scrollbind' support. (always true)
12585showcmd Compiled with 'showcmd' support.
12586signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012587smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012588sodium Compiled with libsodium for better crypt support
12589sound Compiled with sound support, e.g. `sound_playevent()`
12590spell Compiled with spell checking support |spell|.
12591startuptime Compiled with |--startuptime| support.
12592statusline Compiled with support for 'statusline', 'rulerformat'
12593 and special formats of 'titlestring' and 'iconstring'.
12594sun SunOS version of Vim.
12595sun_workshop Support for Sun |workshop| has been removed.
12596syntax Compiled with syntax highlighting support |syntax|.
12597syntax_items There are active syntax highlighting items for the
12598 current buffer.
12599system Compiled to use system() instead of fork()/exec().
12600tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012601 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012602tag_old_static Support for old static tags was removed, see
12603 |tag-old-static|.
12604tcl Compiled with Tcl interface.
12605termguicolors Compiled with true color in terminal support.
12606terminal Compiled with |terminal| support.
12607terminfo Compiled with terminfo instead of termcap.
12608termresponse Compiled with support for |t_RV| and |v:termresponse|.
12609textobjects Compiled with support for |text-objects|.
12610textprop Compiled with support for |text-properties|.
12611tgetent Compiled with tgetent support, able to use a termcap
12612 or terminfo file.
12613timers Compiled with |timer_start()| support.
12614title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012615 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012616toolbar Compiled with support for |gui-toolbar|.
12617ttyin input is a terminal (tty)
12618ttyout output is a terminal (tty)
12619unix Unix version of Vim. *+unix*
12620unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12621user_commands User-defined commands. (always true)
12622vartabs Compiled with variable tabstop support |'vartabstop'|.
12623vcon Win32: Virtual console support is working, can use
12624 'termguicolors'. Also see |+vtp|.
12625vertsplit Compiled with vertically split windows |:vsplit|.
12626 (always true)
12627vim_starting True while initial source'ing takes place. |startup|
12628 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012629vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012630viminfo Compiled with viminfo support.
12631vimscript-1 Compiled Vim script version 1 support
12632vimscript-2 Compiled Vim script version 2 support
12633vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012634vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012635virtualedit Compiled with 'virtualedit' option. (always true)
12636visual Compiled with Visual mode. (always true)
12637visualextra Compiled with extra Visual mode commands. (always
12638 true) |blockwise-operators|.
12639vms VMS version of Vim.
12640vreplace Compiled with |gR| and |gr| commands. (always true)
12641vtp Compiled for vcon support |+vtp| (check vcon to find
12642 out if it works in the current console).
12643wildignore Compiled with 'wildignore' option.
12644wildmenu Compiled with 'wildmenu' option.
12645win16 old version for MS-Windows 3.1 (always false)
12646win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12647 64 bits)
12648win32unix Win32 version of Vim, using Unix files (Cygwin)
12649win64 Win64 version of Vim (MS-Windows 64 bit).
12650win95 Win32 version for MS-Windows 95/98/ME (always false)
12651winaltkeys Compiled with 'winaltkeys' option.
12652windows Compiled with support for more than one window.
12653 (always true)
12654writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012655xattr Compiled with extended attributes support |xattr|
12656 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012657xfontset Compiled with X fontset support |xfontset|.
12658xim Compiled with X input method support |xim|.
12659xpm Compiled with pixmap support.
12660xpm_w32 Compiled with pixmap support for Win32. (Only for
12661 backward compatibility. Use "xpm" instead.)
12662xsmp Compiled with X session management support.
12663xsmp_interact Compiled with interactive X session management support.
12664xterm_clipboard Compiled with support for xterm clipboard.
12665xterm_save Compiled with support for saving and restoring the
12666 xterm screen.
12667x11 Compiled with X11 support.
12668
12669
12670==============================================================================
126714. Matching a pattern in a String *string-match*
12672
12673This is common between several functions. A regexp pattern as explained at
12674|pattern| is normally used to find a match in the buffer lines. When a
12675pattern is used to find a match in a String, almost everything works in the
12676same way. The difference is that a String is handled like it is one line.
12677When it contains a "\n" character, this is not seen as a line break for the
12678pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12679>
12680 :let a = "aaaa\nxxxx"
12681 :echo matchstr(a, "..\n..")
12682 aa
12683 xx
12684 :echo matchstr(a, "a.x")
12685 a
12686 x
12687
12688Don't forget that "^" will only match at the first character of the String and
12689"$" at the last character of the string. They don't match after or before a
12690"\n".
12691
12692 vim:tw=78:ts=8:noet:ft=help:norl: