blob: 635b7b2218c0cd927182217e0c702ca1a3ca122f [file] [log] [blame]
LemonBoy48b7d052024-07-09 18:24:59 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jul 09
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}
312indent({lnum}) Number indent of line {lnum}
313index({object}, {expr} [, {start} [, {ic}]])
314 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100315indexof({object}, {expr} [, {opts}]])
316 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317input({prompt} [, {text} [, {completion}]])
318 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100319inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320 String like input() but in a GUI dialog
321inputlist({textlist}) Number let the user pick from a choice list
322inputrestore() Number restore typeahead
323inputsave() Number save and clear typeahead
324inputsecret({prompt} [, {text}]) String like input() but hiding the text
325insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200326instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327interrupt() none interrupt script execution
328invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100329isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330isdirectory({directory}) Number |TRUE| if {directory} is a directory
331isinf({expr}) Number determine if {expr} is infinity value
332 (positive or negative)
333islocked({expr}) Number |TRUE| if {expr} is locked
334isnan({expr}) Number |TRUE| if {expr} is NaN
335items({dict}) List key-value pairs in {dict}
336job_getchannel({job}) Channel get the channel handle for {job}
337job_info([{job}]) Dict get information about {job}
338job_setoptions({job}, {options}) none set options for {job}
339job_start({command} [, {options}])
340 Job start a job
341job_status({job}) String get the status of {job}
342job_stop({job} [, {how}]) Number stop {job}
343join({list} [, {sep}]) String join {list} items into one String
344js_decode({string}) any decode JS style JSON
345js_encode({expr}) String encode JS style JSON
346json_decode({string}) any decode JSON
347json_encode({expr}) String encode JSON
348keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100349keytrans({string}) String translate internal keycodes to a form
350 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000351len({expr}) Number the length of {expr}
352libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
353libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
354line({expr} [, {winid}]) Number line nr of cursor, last line or mark
355line2byte({lnum}) Number byte count of line {lnum}
356lispindent({lnum}) Number Lisp indent for line {lnum}
357list2blob({list}) Blob turn {list} of numbers into a Blob
358list2str({list} [, {utf8}]) String turn {list} of numbers into a String
359listener_add({callback} [, {buf}])
360 Number add a callback to listen to changes
361listener_flush([{buf}]) none invoke listener callbacks
362listener_remove({id}) none remove a listener callback
363localtime() Number current time
364log({expr}) Float natural logarithm (base e) of {expr}
365log10({expr}) Float logarithm of Float {expr} to base 10
366luaeval({expr} [, {expr}]) any evaluate |Lua| expression
367map({expr1}, {expr2}) List/Dict/Blob/String
368 change each item in {expr1} to {expr2}
369maparg({name} [, {mode} [, {abbr} [, {dict}]]])
370 String or Dict
371 rhs of mapping {name} in mode {mode}
372mapcheck({name} [, {mode} [, {abbr}]])
373 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100374maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000375mapnew({expr1}, {expr2}) List/Dict/Blob/String
376 like |map()| but creates a new List or
377 Dictionary
378mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
379match({expr}, {pat} [, {start} [, {count}]])
380 Number position where {pat} matches in {expr}
381matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
382 Number highlight {pattern} with {group}
383matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
384 Number highlight positions with {group}
385matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100386matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
387 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000388matchdelete({id} [, {win}]) Number delete match identified by {id}
389matchend({expr}, {pat} [, {start} [, {count}]])
390 Number position where {pat} ends in {expr}
391matchfuzzy({list}, {str} [, {dict}])
392 List fuzzy match {str} in {list}
393matchfuzzypos({list}, {str} [, {dict}])
394 List fuzzy match {str} in {list}
395matchlist({expr}, {pat} [, {start} [, {count}]])
396 List match and submatches of {pat} in {expr}
397matchstr({expr}, {pat} [, {start} [, {count}]])
398 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100399matchstrlist({list}, {pat} [, {dict})
400 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000401matchstrpos({expr}, {pat} [, {start} [, {count}]])
402 List {count}'th match of {pat} in {expr}
403max({expr}) Number maximum value of items in {expr}
404menu_info({name} [, {mode}]) Dict get menu item information
405min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000406mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000407 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200408mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000409mzeval({expr}) any evaluate |MzScheme| expression
410nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
411nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
412or({expr}, {expr}) Number bitwise OR
413pathshorten({expr} [, {len}]) String shorten directory names in a path
414perleval({expr}) any evaluate |Perl| expression
415popup_atcursor({what}, {options}) Number create popup window near the cursor
416popup_beval({what}, {options}) Number create popup window for 'ballooneval'
417popup_clear() none close all popup windows
418popup_close({id} [, {result}]) none close popup window {id}
419popup_create({what}, {options}) Number create a popup window
420popup_dialog({what}, {options}) Number create a popup window used as a dialog
421popup_filter_menu({id}, {key}) Number filter for a menu popup window
422popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100423popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000424popup_findinfo() Number get window ID of info popup window
425popup_findpreview() Number get window ID of preview popup window
426popup_getoptions({id}) Dict get options of popup window {id}
427popup_getpos({id}) Dict get position of popup window {id}
428popup_hide({id}) none hide popup menu {id}
429popup_list() List get a list of window IDs of all popups
430popup_locate({row}, {col}) Number get window ID of popup at position
431popup_menu({what}, {options}) Number create a popup window used as a menu
432popup_move({id}, {options}) none set position of popup window {id}
433popup_notification({what}, {options})
434 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200435popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000436popup_setoptions({id}, {options})
437 none set options for popup window {id}
438popup_settext({id}, {text}) none set the text of popup window {id}
439popup_show({id}) none unhide popup window {id}
440pow({x}, {y}) Float {x} to the power of {y}
441prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
442printf({fmt}, {expr1}...) String format text
443prompt_getprompt({buf}) String get prompt text
444prompt_setcallback({buf}, {expr}) none set prompt callback function
445prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
446prompt_setprompt({buf}, {text}) none set prompt text
447prop_add({lnum}, {col}, {props}) none add one text property
448prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
449 none add multiple text properties
450prop_clear({lnum} [, {lnum-end} [, {props}]])
451 none remove all text properties
452prop_find({props} [, {direction}])
453 Dict search for a text property
454prop_list({lnum} [, {props}]) List text properties in {lnum}
455prop_remove({props} [, {lnum} [, {lnum-end}]])
456 Number remove a text property
457prop_type_add({name}, {props}) none define a new property type
458prop_type_change({name}, {props})
459 none change an existing property type
460prop_type_delete({name} [, {props}])
461 none delete a property type
462prop_type_get({name} [, {props}])
463 Dict get property type values
464prop_type_list([{props}]) List get list of property types
465pum_getpos() Dict position and size of pum if visible
466pumvisible() Number whether popup menu is visible
467py3eval({expr}) any evaluate |python3| expression
468pyeval({expr}) any evaluate |Python| expression
469pyxeval({expr}) any evaluate |python_x| expression
470rand([{expr}]) Number get pseudo-random number
471range({expr} [, {max} [, {stride}]])
472 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100473readblob({fname} [, {offset} [, {size}]])
474 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000475readdir({dir} [, {expr} [, {dict}]])
476 List file names in {dir} selected by {expr}
477readdirex({dir} [, {expr} [, {dict}]])
478 List file info in {dir} selected by {expr}
479readfile({fname} [, {type} [, {max}]])
480 List get list of lines from file {fname}
481reduce({object}, {func} [, {initial}])
482 any reduce {object} using {func}
483reg_executing() String get the executing register name
484reg_recording() String get the recording register name
485reltime([{start} [, {end}]]) List get time value
486reltimefloat({time}) Float turn the time value into a Float
487reltimestr({time}) String turn time value into a String
488remote_expr({server}, {string} [, {idvar} [, {timeout}]])
489 String send expression
490remote_foreground({server}) Number bring Vim server to the foreground
491remote_peek({serverid} [, {retvar}])
492 Number check for reply string
493remote_read({serverid} [, {timeout}])
494 String read reply string
495remote_send({server}, {string} [, {idvar}])
496 String send key sequence
497remote_startserver({name}) none become server {name}
498remove({list}, {idx} [, {end}]) any/List
499 remove items {idx}-{end} from {list}
500remove({blob}, {idx} [, {end}]) Number/Blob
501 remove bytes {idx}-{end} from {blob}
502remove({dict}, {key}) any remove entry {key} from {dict}
503rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100504repeat({expr}, {count}) List/Blob/String
505 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000506resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100507reverse({obj}) List/Blob/String
508 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000509round({expr}) Float round off {expr}
510rubyeval({expr}) any evaluate |Ruby| expression
511screenattr({row}, {col}) Number attribute at screen position
512screenchar({row}, {col}) Number character at screen position
513screenchars({row}, {col}) List List of characters at screen position
514screencol() Number current cursor column
515screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
516screenrow() Number current cursor row
517screenstring({row}, {col}) String characters at screen position
518search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
519 Number search for {pattern}
520searchcount([{options}]) Dict get or update search stats
521searchdecl({name} [, {global} [, {thisblock}]])
522 Number search for variable declaration
523searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
524 Number search for other end of start/end pair
525searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
526 List search for other end of start/end pair
527searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
528 List search for {pattern}
529server2client({clientid}, {string})
530 Number send reply string
531serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700532setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000533 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700534 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000535setbufvar({buf}, {varname}, {val})
536 none set {varname} in buffer {buf} to {val}
537setcellwidths({list}) none set character cell width overrides
538setcharpos({expr}, {list}) Number set the {expr} position to {list}
539setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100540setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000541setcmdpos({pos}) Number set cursor position in command-line
542setcursorcharpos({list}) Number move cursor to position in {list}
543setenv({name}, {val}) none set environment variable
544setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
545setline({lnum}, {line}) Number set line {lnum} to {line}
546setloclist({nr}, {list} [, {action}])
547 Number modify location list using {list}
548setloclist({nr}, {list}, {action}, {what})
549 Number modify specific location list props
550setmatches({list} [, {win}]) Number restore a list of matches
551setpos({expr}, {list}) Number set the {expr} position to {list}
552setqflist({list} [, {action}]) Number modify quickfix list using {list}
553setqflist({list}, {action}, {what})
554 Number modify specific quickfix list props
555setreg({n}, {v} [, {opt}]) Number set register to value and type
556settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
557settabwinvar({tabnr}, {winnr}, {varname}, {val})
558 none set {varname} in window {winnr} in tab
559 page {tabnr} to {val}
560settagstack({nr}, {dict} [, {action}])
561 Number modify tag stack using {dict}
562setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
563sha256({string}) String SHA256 checksum of {string}
564shellescape({string} [, {special}])
565 String escape {string} for use as shell
566 command argument
567shiftwidth([{col}]) Number effective value of 'shiftwidth'
568sign_define({name} [, {dict}]) Number define or update a sign
569sign_define({list}) List define or update a list of signs
570sign_getdefined([{name}]) List get a list of defined signs
571sign_getplaced([{buf} [, {dict}]])
572 List get a list of placed signs
573sign_jump({id}, {group}, {buf})
574 Number jump to a sign
575sign_place({id}, {group}, {name}, {buf} [, {dict}])
576 Number place a sign
577sign_placelist({list}) List place a list of signs
578sign_undefine([{name}]) Number undefine a sign
579sign_undefine({list}) List undefine a list of signs
580sign_unplace({group} [, {dict}])
581 Number unplace a sign
582sign_unplacelist({list}) List unplace a list of signs
583simplify({filename}) String simplify filename as much as possible
584sin({expr}) Float sine of {expr}
585sinh({expr}) Float hyperbolic sine of {expr}
586slice({expr}, {start} [, {end}]) String, List or Blob
587 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000588sort({list} [, {how} [, {dict}]])
589 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000590sound_clear() none stop playing all sounds
591sound_playevent({name} [, {callback}])
592 Number play an event sound
593sound_playfile({path} [, {callback}])
594 Number play sound file {path}
595sound_stop({id}) none stop playing sound {id}
596soundfold({word}) String sound-fold {word}
597spellbadword() String badly spelled word at cursor
598spellsuggest({word} [, {max} [, {capital}]])
599 List spelling suggestions
600split({expr} [, {pat} [, {keepempty}]])
601 List make |List| from {pat} separated {expr}
602sqrt({expr}) Float square root of {expr}
603srand([{expr}]) List get seed for |rand()|
604state([{what}]) String current state of Vim
605str2float({expr} [, {quoted}]) Float convert String to Float
606str2list({expr} [, {utf8}]) List convert each character of {expr} to
607 ASCII/UTF-8 value
608str2nr({expr} [, {base} [, {quoted}]])
609 Number convert String to Number
610strcharlen({expr}) Number character length of the String {expr}
611strcharpart({str}, {start} [, {len} [, {skipcc}]])
612 String {len} characters of {str} at
613 character {start}
614strchars({expr} [, {skipcc}]) Number character count of the String {expr}
615strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
616strftime({format} [, {time}]) String format time with a specified format
617strgetchar({str}, {index}) Number get char {index} from {str}
618stridx({haystack}, {needle} [, {start}])
619 Number index of {needle} in {haystack}
620string({expr}) String String representation of {expr} value
621strlen({expr}) Number length of the String {expr}
622strpart({str}, {start} [, {len} [, {chars}]])
623 String {len} bytes/chars of {str} at
624 byte {start}
625strptime({format}, {timestring})
626 Number Convert {timestring} to unix timestamp
627strridx({haystack}, {needle} [, {start}])
628 Number last index of {needle} in {haystack}
629strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100630strutf16len({string} [, {countcc}])
631 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000632strwidth({expr}) Number display cell length of the String {expr}
633submatch({nr} [, {list}]) String or List
634 specific match in ":s" or substitute()
635substitute({expr}, {pat}, {sub}, {flags})
636 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000637swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000638swapinfo({fname}) Dict information about swap file {fname}
639swapname({buf}) String swap file of buffer {buf}
640synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
641synIDattr({synID}, {what} [, {mode}])
642 String attribute {what} of syntax ID {synID}
643synIDtrans({synID}) Number translated syntax ID of {synID}
644synconcealed({lnum}, {col}) List info about concealing
645synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
646system({expr} [, {input}]) String output of shell command/filter {expr}
647systemlist({expr} [, {input}]) List output of shell command/filter {expr}
648tabpagebuflist([{arg}]) List list of buffer numbers in tab page
649tabpagenr([{arg}]) Number number of current or last tab page
650tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
651tagfiles() List tags files used
652taglist({expr} [, {filename}]) List list of tags matching {expr}
653tan({expr}) Float tangent of {expr}
654tanh({expr}) Float hyperbolic tangent of {expr}
655tempname() String name for a temporary file
656term_dumpdiff({filename}, {filename} [, {options}])
657 Number display difference between two dumps
658term_dumpload({filename} [, {options}])
659 Number displaying a screen dump
660term_dumpwrite({buf}, {filename} [, {options}])
661 none dump terminal window contents
662term_getaltscreen({buf}) Number get the alternate screen flag
663term_getansicolors({buf}) List get ANSI palette in GUI color mode
664term_getattr({attr}, {what}) Number get the value of attribute {what}
665term_getcursor({buf}) List get the cursor position of a terminal
666term_getjob({buf}) Job get the job associated with a terminal
667term_getline({buf}, {row}) String get a line of text from a terminal
668term_getscrolled({buf}) Number get the scroll count of a terminal
669term_getsize({buf}) List get the size of a terminal
670term_getstatus({buf}) String get the status of a terminal
671term_gettitle({buf}) String get the title of a terminal
672term_gettty({buf}, [{input}]) String get the tty name of a terminal
673term_list() List get the list of terminal buffers
674term_scrape({buf}, {row}) List get row of a terminal screen
675term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
676term_setansicolors({buf}, {colors})
677 none set ANSI palette in GUI color mode
678term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
679term_setkill({buf}, {how}) none set signal to stop job in terminal
680term_setrestore({buf}, {command}) none set command to restore terminal
681term_setsize({buf}, {rows}, {cols})
682 none set the size of a terminal
683term_start({cmd} [, {options}]) Number open a terminal window and run a job
684term_wait({buf} [, {time}]) Number wait for screen to be updated
685terminalprops() Dict properties of the terminal
686test_alloc_fail({id}, {countdown}, {repeat})
687 none make memory allocation fail
688test_autochdir() none enable 'autochdir' during startup
689test_feedinput({string}) none add key sequence to input buffer
690test_garbagecollect_now() none free memory right now for testing
691test_garbagecollect_soon() none free memory soon for testing
692test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000693test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000694test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000695test_mswin_event({event}, {args})
696 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000697test_null_blob() Blob null value for testing
698test_null_channel() Channel null value for testing
699test_null_dict() Dict null value for testing
700test_null_function() Funcref null value for testing
701test_null_job() Job null value for testing
702test_null_list() List null value for testing
703test_null_partial() Funcref null value for testing
704test_null_string() String null value for testing
705test_option_not_set({name}) none reset flag indicating option was set
706test_override({expr}, {val}) none test with Vim internal overrides
707test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_setmouse({row}, {col}) none set the mouse position for testing
709test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200710test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_unknown() any unknown value for testing
712test_void() any void value for testing
713timer_info([{id}]) List information about timers
714timer_pause({id}, {pause}) none pause or unpause a timer
715timer_start({time}, {callback} [, {options}])
716 Number create a timer
717timer_stop({timer}) none stop a timer
718timer_stopall() none stop all timers
719tolower({expr}) String the String {expr} switched to lowercase
720toupper({expr}) String the String {expr} switched to uppercase
721tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
722 to chars in {tostr}
723trim({text} [, {mask} [, {dir}]])
724 String trim characters in {mask} from {text}
725trunc({expr}) Float truncate Float {expr}
726type({expr}) Number type of value {expr}
727typename({expr}) String representation of the type of {expr}
728undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500729undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000730uniq({list} [, {func} [, {dict}]])
731 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100732utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
733 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000734values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200735virtcol({expr} [, {list} [, {winid}])
736 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100737 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100738virtcol2col({winid}, {lnum}, {col})
739 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200740visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000741wildmenumode() Number whether 'wildmenu' mode is active
742win_execute({id}, {command} [, {silent}])
743 String execute {command} in window {id}
744win_findbuf({bufnr}) List find windows containing {bufnr}
745win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
746win_gettype([{nr}]) String type of window {nr}
747win_gotoid({expr}) Number go to window with ID {expr}
748win_id2tabwin({expr}) List get tab and window nr from window ID
749win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000750win_move_separator({nr}) Number move window vertical separator
751win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000752win_screenpos({nr}) List get screen position of window {nr}
753win_splitmove({nr}, {target} [, {options}])
754 Number move window {nr} to split of {target}
755winbufnr({nr}) Number buffer number of window {nr}
756wincol() Number window column of the cursor
757windowsversion() String MS-Windows OS version
758winheight({nr}) Number height of window {nr}
759winlayout([{tabnr}]) List layout of windows in tab {tabnr}
760winline() Number window line of the cursor
761winnr([{expr}]) Number number of current window
762winrestcmd() String returns command to restore window sizes
763winrestview({dict}) none restore view of current window
764winsaveview() Dict save view of current window
765winwidth({nr}) Number width of window {nr}
766wordcount() Dict get byte/char/word statistics
767writefile({object}, {fname} [, {flags}])
768 Number write |Blob| or |List| of lines to file
769xor({expr}, {expr}) Number bitwise XOR
770
771==============================================================================
7722. Details *builtin-function-details*
773
774Not all functions are here, some have been moved to a help file covering the
775specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200776Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000777
778abs({expr}) *abs()*
779 Return the absolute value of {expr}. When {expr} evaluates to
780 a |Float| abs() returns a |Float|. When {expr} can be
781 converted to a |Number| abs() returns a |Number|. Otherwise
782 abs() gives an error message and returns -1.
783 Examples: >
784 echo abs(1.456)
785< 1.456 >
786 echo abs(-5.456)
787< 5.456 >
788 echo abs(-4)
789< 4
790
791 Can also be used as a |method|: >
792 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200793<
794 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000796
797acos({expr}) *acos()*
798 Return the arc cosine of {expr} measured in radians, as a
799 |Float| in the range of [0, pi].
800 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100801 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000802 Examples: >
803 :echo acos(0)
804< 1.570796 >
805 :echo acos(-0.5)
806< 2.094395
807
808 Can also be used as a |method|: >
809 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200810<
811 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000813
814add({object}, {expr}) *add()*
815 Append the item {expr} to |List| or |Blob| {object}. Returns
816 the resulting |List| or |Blob|. Examples: >
817 :let alist = add([1, 2, 3], item)
818 :call add(mylist, "woodstock")
819< Note that when {expr} is a |List| it is appended as a single
820 item. Use |extend()| to concatenate |Lists|.
821 When {object} is a |Blob| then {expr} must be a number.
822 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100823 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000824
825 Can also be used as a |method|: >
826 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200827<
828 Return type: list<{type}> (depending on the given |List|) or
829 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000830
831
832and({expr}, {expr}) *and()*
833 Bitwise AND on the two arguments. The arguments are converted
834 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100835 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000836 Example: >
837 :let flag = and(bits, 0x80)
838< Can also be used as a |method|: >
839 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200840<
841 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000842
843
844append({lnum}, {text}) *append()*
845 When {text} is a |List|: Append each item of the |List| as a
846 text line below line {lnum} in the current buffer.
847 Otherwise append {text} as one text line below line {lnum} in
848 the current buffer.
849 Any type of item is accepted and converted to a String.
850 {lnum} can be zero to insert a line before the first one.
851 {lnum} is used like with |getline()|.
852 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000853 0 for success. When {text} is an empty list zero is returned,
854 no matter the value of {lnum}.
855 In |Vim9| script an invalid argument or negative number
856 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000857 :let failed = append(line('$'), "# THE END")
858 :let failed = append(0, ["Chapter 1", "the beginning"])
859
860< Can also be used as a |method| after a List, the base is
861 passed as the second argument: >
862 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200863<
864 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000865
866
867appendbufline({buf}, {lnum}, {text}) *appendbufline()*
868 Like |append()| but append the text in buffer {buf}.
869
870 This function works only for loaded buffers. First call
871 |bufload()| if needed.
872
873 For the use of {buf}, see |bufname()|.
874
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000875 {lnum} is the line number to append below. Note that using
876 |line()| would use the current buffer, not the one appending
877 to. Use "$" to append at the end of the buffer. Other string
878 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000879
880 On success 0 is returned, on failure 1 is returned.
881 In |Vim9| script an error is given for an invalid {lnum}.
882
883 If {buf} is not a valid buffer or {lnum} is not valid, an
884 error message is given. Example: >
885 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000886< However, when {text} is an empty list then no error is given
887 for an invalid {lnum}, since {lnum} isn't actually used.
888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000889 Can also be used as a |method| after a List, the base is
890 passed as the second argument: >
891 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200892<
893 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000894
895
896argc([{winid}]) *argc()*
897 The result is the number of files in the argument list. See
898 |arglist|.
899 If {winid} is not supplied, the argument list of the current
900 window is used.
901 If {winid} is -1, the global argument list is used.
902 Otherwise {winid} specifies the window of which the argument
903 list is used: either the window number or the window ID.
904 Returns -1 if the {winid} argument is invalid.
905
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200906 Return type: |Number|
907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000908 *argidx()*
909argidx() The result is the current index in the argument list. 0 is
910 the first file. argc() - 1 is the last one. See |arglist|.
911
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200912 Return type: |Number|
913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000914 *arglistid()*
915arglistid([{winnr} [, {tabnr}]])
916 Return the argument list ID. This is a number which
917 identifies the argument list being used. Zero is used for the
918 global argument list. See |arglist|.
919 Returns -1 if the arguments are invalid.
920
921 Without arguments use the current window.
922 With {winnr} only use this window in the current tab page.
923 With {winnr} and {tabnr} use the window in the specified tab
924 page.
925 {winnr} can be the window number or the |window-ID|.
926
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200927 Return type: |Number|
928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000929 *argv()*
930argv([{nr} [, {winid}]])
931 The result is the {nr}th file in the argument list. See
932 |arglist|. "argv(0)" is the first one. Example: >
933 :let i = 0
934 :while i < argc()
935 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000936 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000937 : let i = i + 1
938 :endwhile
939< Without the {nr} argument, or when {nr} is -1, a |List| with
940 the whole |arglist| is returned.
941
942 The {winid} argument specifies the window ID, see |argc()|.
943 For the Vim command line arguments see |v:argv|.
944
Bram Moolenaar016188f2022-06-06 20:52:59 +0100945 Returns an empty string if {nr}th argument is not present in
946 the argument list. Returns an empty List if the {winid}
947 argument is invalid.
948
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200949 Return type: |String|
950
951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000952asin({expr}) *asin()*
953 Return the arc sine of {expr} measured in radians, as a |Float|
954 in the range of [-pi/2, pi/2].
955 {expr} must evaluate to a |Float| or a |Number| in the range
956 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100957 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
958 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000959 Examples: >
960 :echo asin(0.8)
961< 0.927295 >
962 :echo asin(-0.5)
963< -0.523599
964
965 Can also be used as a |method|: >
966 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200967<
968 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969
970assert_ functions are documented here: |assert-functions-details|
971
972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000973atan({expr}) *atan()*
974 Return the principal value of the arc tangent of {expr}, in
975 the range [-pi/2, +pi/2] radians, as a |Float|.
976 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100977 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000978 Examples: >
979 :echo atan(100)
980< 1.560797 >
981 :echo atan(-4.01)
982< -1.326405
983
984 Can also be used as a |method|: >
985 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200986<
987 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000988
989
990atan2({expr1}, {expr2}) *atan2()*
991 Return the arc tangent of {expr1} / {expr2}, measured in
992 radians, as a |Float| in the range [-pi, pi].
993 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100994 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
995 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000996 Examples: >
997 :echo atan2(-1, 1)
998< -0.785398 >
999 :echo atan2(1, -1)
1000< 2.356194
1001
1002 Can also be used as a |method|: >
1003 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001004<
1005 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001006
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001007
1008autocmd_add({acmds}) *autocmd_add()*
1009 Adds a List of autocmds and autocmd groups.
1010
1011 The {acmds} argument is a List where each item is a Dict with
1012 the following optional items:
1013 bufnr buffer number to add a buffer-local autocmd.
1014 If this item is specified, then the "pattern"
1015 item is ignored.
1016 cmd Ex command to execute for this autocmd event
1017 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001018 This can be either a String with a single
1019 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001020 group autocmd group name. Refer to |autocmd-groups|.
1021 If this group doesn't exist then it is
1022 created. If not specified or empty, then the
1023 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001024 nested boolean flag, set to v:true to add a nested
1025 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001026 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001027 which executes only once. Refer to
1028 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001029 pattern autocmd pattern string. Refer to
1030 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001031 present, then this item is ignored. This can
1032 be a String with a single pattern or a List of
1033 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001034 replace boolean flag, set to v:true to remove all the
1035 commands associated with the specified autocmd
1036 event and group and add the {cmd}. This is
1037 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001038 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001039
1040 Returns v:true on success and v:false on failure.
1041 Examples: >
1042 " Create a buffer-local autocmd for buffer 5
1043 let acmd = {}
1044 let acmd.group = 'MyGroup'
1045 let acmd.event = 'BufEnter'
1046 let acmd.bufnr = 5
1047 let acmd.cmd = 'call BufEnterFunc()'
1048 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001049<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001050 Can also be used as a |method|: >
1051 GetAutocmdList()->autocmd_add()
1052<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001053 Return type: |vim9-boolean|
1054
1055
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001056autocmd_delete({acmds}) *autocmd_delete()*
1057 Deletes a List of autocmds and autocmd groups.
1058
1059 The {acmds} argument is a List where each item is a Dict with
1060 the following optional items:
1061 bufnr buffer number to delete a buffer-local autocmd.
1062 If this item is specified, then the "pattern"
1063 item is ignored.
1064 cmd Ex command for this autocmd event
1065 event autocmd event name. Refer to |autocmd-events|.
1066 If '*' then all the autocmd events in this
1067 group are deleted.
1068 group autocmd group name. Refer to |autocmd-groups|.
1069 If not specified or empty, then the default
1070 group is used.
1071 nested set to v:true for a nested autocmd.
1072 Refer to |autocmd-nested|.
1073 once set to v:true for an autocmd which executes
1074 only once. Refer to |autocmd-once|.
1075 pattern autocmd pattern string. Refer to
1076 |autocmd-patterns|. If "bufnr" item is
1077 present, then this item is ignored.
1078
1079 If only {group} is specified in a {acmds} entry and {event},
1080 {pattern} and {cmd} are not specified, then that autocmd group
1081 is deleted.
1082
Bram Moolenaar016188f2022-06-06 20:52:59 +01001083 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001084 Examples: >
1085 " :autocmd! BufLeave *.vim
1086 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1087 call autocmd_delete([acmd]})
1088 " :autocmd! MyGroup1 BufLeave
1089 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1090 call autocmd_delete([acmd])
1091 " :autocmd! MyGroup2 BufEnter *.c
1092 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1093 \ pattern: '*.c'}
1094 " :autocmd! MyGroup2 * *.c
1095 let acmd = #{group: 'MyGroup2', event: '*',
1096 \ pattern: '*.c'}
1097 call autocmd_delete([acmd])
1098 " :autocmd! MyGroup3
1099 let acmd = #{group: 'MyGroup3'}
1100 call autocmd_delete([acmd])
1101<
1102 Can also be used as a |method|: >
1103 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001104<
1105 Return type: |vim9-boolean|
1106
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001107
1108autocmd_get([{opts}]) *autocmd_get()*
1109 Returns a |List| of autocmds. If {opts} is not supplied, then
1110 returns the autocmds for all the events in all the groups.
1111
1112 The optional {opts} Dict argument supports the following
1113 items:
1114 group Autocmd group name. If specified, returns only
1115 the autocmds defined in this group. If the
1116 specified group doesn't exist, results in an
1117 error message. If set to an empty string,
1118 then the default autocmd group is used.
1119 event Autocmd event name. If specified, returns only
1120 the autocmds defined for this event. If set
1121 to "*", then returns autocmds for all the
1122 events. If the specified event doesn't exist,
1123 results in an error message.
1124 pattern Autocmd pattern. If specified, returns only
1125 the autocmds defined for this pattern.
1126 A combination of the above three times can be supplied in
1127 {opts}.
1128
1129 Each Dict in the returned List contains the following items:
1130 bufnr For buffer-local autocmds, buffer number where
1131 the autocmd is defined.
1132 cmd Command executed for this autocmd.
1133 event Autocmd event name.
1134 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001135 nested Boolean flag, set to v:true for a nested
1136 autocmd. See |autocmd-nested|.
1137 once Boolean flag, set to v:true, if the autocmd
1138 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001139 pattern Autocmd pattern. For a buffer-local
1140 autocmd, this will be of the form "<buffer=n>".
1141 If there are multiple commands for an autocmd event in a
1142 group, then separate items are returned for each command.
1143
Bram Moolenaar016188f2022-06-06 20:52:59 +01001144 Returns an empty List if an autocmd with the specified group
1145 or event or pattern is not found.
1146
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001147 Examples: >
1148 " :autocmd MyGroup
1149 echo autocmd_get(#{group: 'Mygroup'})
1150 " :autocmd G BufUnload
1151 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1152 " :autocmd G * *.ts
1153 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1154 echo autocmd_get(acmd)
1155 " :autocmd Syntax
1156 echo autocmd_get(#{event: 'Syntax'})
1157 " :autocmd G BufEnter *.ts
1158 let acmd = #{group: 'G', event: 'BufEnter',
1159 \ pattern: '*.ts'}
1160 echo autocmd_get(acmd)
1161<
1162 Can also be used as a |method|: >
1163 Getopts()->autocmd_get()
1164<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001165 Return type: list<dict<any>>
1166
1167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001168balloon_gettext() *balloon_gettext()*
1169 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001170 not used for the List. Returns an empty string if balloon
1171 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001172
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001173 Return type: |String|
1174
1175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001176balloon_show({expr}) *balloon_show()*
1177 Show {expr} inside the balloon. For the GUI {expr} is used as
1178 a string. For a terminal {expr} can be a list, which contains
1179 the lines of the balloon. If {expr} is not a list it will be
1180 split with |balloon_split()|.
1181 If {expr} is an empty string any existing balloon is removed.
1182
1183 Example: >
1184 func GetBalloonContent()
1185 " ... initiate getting the content
1186 return ''
1187 endfunc
1188 set balloonexpr=GetBalloonContent()
1189
1190 func BalloonCallback(result)
1191 call balloon_show(a:result)
1192 endfunc
1193< Can also be used as a |method|: >
1194 GetText()->balloon_show()
1195<
1196 The intended use is that fetching the content of the balloon
1197 is initiated from 'balloonexpr'. It will invoke an
1198 asynchronous method, in which a callback invokes
1199 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001200 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001201
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001202 When showing a balloon is not possible then nothing happens,
1203 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001204 {only available when compiled with the |+balloon_eval| or
1205 |+balloon_eval_term| feature}
1206
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001207 Return type: |Number|
1208
1209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001210balloon_split({msg}) *balloon_split()*
1211 Split String {msg} into lines to be displayed in a balloon.
1212 The splits are made for the current window size and optimize
1213 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001214 Returns a |List| with the split lines. Returns an empty List
1215 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001216 Can also be used as a |method|: >
1217 GetText()->balloon_split()->balloon_show()
1218
1219< {only available when compiled with the |+balloon_eval_term|
1220 feature}
1221
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001222 Return type: list<any> or list<string>
1223
Christ van Willegence0ef912024-06-20 23:41:59 +02001224bindtextdomain({package}, {path}) *bindtextdomain()*
1225 Bind a specific {package} to a {path} so that the
1226 |gettext()| function can be used to get language-specific
1227 translations for a package. {path} is the directory name
1228 for the translations. See |package-create|.
1229
1230 Return type: none
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001232blob2list({blob}) *blob2list()*
1233 Return a List containing the number value of each byte in Blob
1234 {blob}. Examples: >
1235 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1236 blob2list(0z) returns []
1237< Returns an empty List on error. |list2blob()| does the
1238 opposite.
1239
1240 Can also be used as a |method|: >
1241 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001242<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001243 Return type: list<any> or list<number>
1244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001245 *browse()*
1246browse({save}, {title}, {initdir}, {default})
1247 Put up a file requester. This only works when "has("browse")"
1248 returns |TRUE| (only in some GUI versions).
1249 The input fields are:
1250 {save} when |TRUE|, select file to write
1251 {title} title for the requester
1252 {initdir} directory to start browsing in
1253 {default} default file name
1254 An empty string is returned when the "Cancel" button is hit,
1255 something went wrong, or browsing is not possible.
1256
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001257 Return type: |String|
1258
1259
1260browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001261 Put up a directory requester. This only works when
1262 "has("browse")" returns |TRUE| (only in some GUI versions).
1263 On systems where a directory browser is not supported a file
1264 browser is used. In that case: select a file in the directory
1265 to be used.
1266 The input fields are:
1267 {title} title for the requester
1268 {initdir} directory to start browsing in
1269 When the "Cancel" button is hit, something went wrong, or
1270 browsing is not possible, an empty string is returned.
1271
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001272 Return type: |String|
1273
1274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001275bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001276 Add a buffer to the buffer list with name {name} (must be a
1277 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278 If a buffer for file {name} already exists, return that buffer
1279 number. Otherwise return the buffer number of the newly
1280 created buffer. When {name} is an empty string then a new
1281 buffer is always created.
1282 The buffer will not have 'buflisted' set and not be loaded
1283 yet. To add some text to the buffer use this: >
1284 let bufnr = bufadd('someName')
1285 call bufload(bufnr)
1286 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001287< Returns 0 on error.
1288 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001289 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001290<
1291 Return type: |Number|
1292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001293
1294bufexists({buf}) *bufexists()*
1295 The result is a Number, which is |TRUE| if a buffer called
1296 {buf} exists.
1297 If the {buf} argument is a number, buffer numbers are used.
1298 Number zero is the alternate buffer for the current window.
1299
1300 If the {buf} argument is a string it must match a buffer name
1301 exactly. The name can be:
1302 - Relative to the current directory.
1303 - A full path.
1304 - The name of a buffer with 'buftype' set to "nofile".
1305 - A URL name.
1306 Unlisted buffers will be found.
1307 Note that help files are listed by their short name in the
1308 output of |:buffers|, but bufexists() requires using their
1309 long name to be able to find them.
1310 bufexists() may report a buffer exists, but to use the name
1311 with a |:buffer| command you may need to use |expand()|. Esp
1312 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1313 Use "bufexists(0)" to test for the existence of an alternate
1314 file name.
1315
1316 Can also be used as a |method|: >
1317 let exists = 'somename'->bufexists()
1318<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001319 Return type: |Number|
1320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001321 Obsolete name: buffer_exists(). *buffer_exists()*
1322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001324buflisted({buf}) *buflisted()*
1325 The result is a Number, which is |TRUE| if a buffer called
1326 {buf} exists and is listed (has the 'buflisted' option set).
1327 The {buf} argument is used like with |bufexists()|.
1328
1329 Can also be used as a |method|: >
1330 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001331<
1332 Return type: |Number|
1333
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001334
1335bufload({buf}) *bufload()*
1336 Ensure the buffer {buf} is loaded. When the buffer name
1337 refers to an existing file then the file is read. Otherwise
1338 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001339 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001340 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001341 If there is an existing swap file for the file of the buffer,
1342 there will be no dialog, the buffer will be loaded anyway.
1343 The {buf} argument is used like with |bufexists()|.
1344
1345 Can also be used as a |method|: >
1346 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001347<
1348 Return type: |Number|
1349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001350
1351bufloaded({buf}) *bufloaded()*
1352 The result is a Number, which is |TRUE| if a buffer called
1353 {buf} exists and is loaded (shown in a window or hidden).
1354 The {buf} argument is used like with |bufexists()|.
1355
1356 Can also be used as a |method|: >
1357 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001358<
1359 Return type: |Number|
1360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001361
1362bufname([{buf}]) *bufname()*
1363 The result is the name of a buffer. Mostly as it is displayed
1364 by the `:ls` command, but not using special names such as
1365 "[No Name]".
1366 If {buf} is omitted the current buffer is used.
1367 If {buf} is a Number, that buffer number's name is given.
1368 Number zero is the alternate buffer for the current window.
1369 If {buf} is a String, it is used as a |file-pattern| to match
1370 with the buffer names. This is always done like 'magic' is
1371 set and 'cpoptions' is empty. When there is more than one
1372 match an empty string is returned.
1373 "" or "%" can be used for the current buffer, "#" for the
1374 alternate buffer.
1375 A full match is preferred, otherwise a match at the start, end
1376 or middle of the buffer name is accepted. If you only want a
1377 full match then put "^" at the start and "$" at the end of the
1378 pattern.
1379 Listed buffers are found first. If there is a single match
1380 with a listed buffer, that one is returned. Next unlisted
1381 buffers are searched for.
1382 If the {buf} is a String, but you want to use it as a buffer
1383 number, force it to be a Number by adding zero to it: >
1384 :echo bufname("3" + 0)
1385< Can also be used as a |method|: >
1386 echo bufnr->bufname()
1387
1388< If the buffer doesn't exist, or doesn't have a name, an empty
1389 string is returned. >
1390 bufname("#") alternate buffer name
1391 bufname(3) name of buffer 3
1392 bufname("%") name of current buffer
1393 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001394<
1395 Return type: |String|
1396 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001397 Obsolete name: buffer_name().
1398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001399
1400bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001401 The result is the number of a buffer, as it is displayed by
1402 the `:ls` command. For the use of {buf}, see |bufname()|
1403 above.
1404
1405 If the buffer doesn't exist, -1 is returned. Or, if the
1406 {create} argument is present and TRUE, a new, unlisted,
1407 buffer is created and its number is returned. Example: >
1408 let newbuf = bufnr('Scratch001', 1)
1409< Using an empty name uses the current buffer. To create a new
1410 buffer with an empty name use |bufadd()|.
1411
1412 bufnr("$") is the last buffer: >
1413 :let last_buffer = bufnr("$")
1414< The result is a Number, which is the highest buffer number
1415 of existing buffers. Note that not all buffers with a smaller
1416 number necessarily exist, because ":bwipeout" may have removed
1417 them. Use bufexists() to test for the existence of a buffer.
1418
1419 Can also be used as a |method|: >
1420 echo bufref->bufnr()
1421<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001422 Return type: |Number|
1423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001424 Obsolete name: buffer_number(). *buffer_number()*
1425 *last_buffer_nr()*
1426 Obsolete name for bufnr("$"): last_buffer_nr().
1427
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001429bufwinid({buf}) *bufwinid()*
1430 The result is a Number, which is the |window-ID| of the first
1431 window associated with buffer {buf}. For the use of {buf},
1432 see |bufname()| above. If buffer {buf} doesn't exist or
1433 there is no such window, -1 is returned. Example: >
1434
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001435 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001436<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001437 Only deals with the current tab page. See |win_findbuf()| for
1438 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001439
1440 Can also be used as a |method|: >
1441 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001442<
1443 Return type: |Number|
1444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001445
1446bufwinnr({buf}) *bufwinnr()*
1447 Like |bufwinid()| but return the window number instead of the
1448 |window-ID|.
1449 If buffer {buf} doesn't exist or there is no such window, -1
1450 is returned. Example: >
1451
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001452 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001453
1454< The number can be used with |CTRL-W_w| and ":wincmd w"
1455 |:wincmd|.
1456
1457 Can also be used as a |method|: >
1458 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001459<
1460 Return type: |Number|
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462
1463byte2line({byte}) *byte2line()*
1464 Return the line number that contains the character at byte
1465 count {byte} in the current buffer. This includes the
1466 end-of-line character, depending on the 'fileformat' option
1467 for the current buffer. The first character has byte count
1468 one.
1469 Also see |line2byte()|, |go| and |:goto|.
1470
Bram Moolenaar016188f2022-06-06 20:52:59 +01001471 Returns -1 if the {byte} value is invalid.
1472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001473 Can also be used as a |method|: >
1474 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001475<
1476 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001478 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001479 feature}
1480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001481
Christian Brabandt67672ef2023-04-24 21:09:54 +01001482byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483 Return byte index of the {nr}'th character in the String
1484 {expr}. Use zero for the first character, it then returns
1485 zero.
1486 If there are no multibyte characters the returned value is
1487 equal to {nr}.
1488 Composing characters are not counted separately, their byte
1489 length is added to the preceding base character. See
1490 |byteidxcomp()| below for counting composing characters
1491 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001492 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1493 index in the String {expr} instead of as the character index.
1494 The UTF-16 index is the index in the string when it is encoded
1495 with 16-bit words. If the specified UTF-16 index is in the
1496 middle of a character (e.g. in a 4-byte character), then the
1497 byte index of the first byte in the character is returned.
1498 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499 Example : >
1500 echo matchstr(str, ".", byteidx(str, 3))
1501< will display the fourth character. Another way to do the
1502 same: >
1503 let s = strpart(str, byteidx(str, 3))
1504 echo strpart(s, 0, byteidx(s, 1))
1505< Also see |strgetchar()| and |strcharpart()|.
1506
1507 If there are less than {nr} characters -1 is returned.
1508 If there are exactly {nr} characters the length of the string
1509 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001510 See |charidx()| and |utf16idx()| for getting the character and
1511 UTF-16 index respectively from the byte index.
1512 Examples: >
1513 echo byteidx('a😊😊', 2) returns 5
1514 echo byteidx('a😊😊', 2, 1) returns 1
1515 echo byteidx('a😊😊', 3, 1) returns 5
1516<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001517 Can also be used as a |method|: >
1518 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001519<
1520 Return type: |Number|
1521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522
Christian Brabandt67672ef2023-04-24 21:09:54 +01001523byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001524 Like byteidx(), except that a composing character is counted
1525 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001526 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001527 echo byteidx(s, 1)
1528 echo byteidxcomp(s, 1)
1529 echo byteidxcomp(s, 2)
1530< The first and third echo result in 3 ('e' plus composing
1531 character is 3 bytes), the second echo results in 1 ('e' is
1532 one byte).
1533 Only works differently from byteidx() when 'encoding' is set
1534 to a Unicode encoding.
1535
1536 Can also be used as a |method|: >
1537 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001538<
1539 Return type: |Number|
1540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001541
1542call({func}, {arglist} [, {dict}]) *call()* *E699*
1543 Call function {func} with the items in |List| {arglist} as
1544 arguments.
1545 {func} can either be a |Funcref| or the name of a function.
1546 a:firstline and a:lastline are set to the cursor line.
1547 Returns the return value of the called function.
1548 {dict} is for functions with the "dict" attribute. It will be
1549 used to set the local variable "self". |Dictionary-function|
1550
1551 Can also be used as a |method|: >
1552 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001553<
1554 Return type: any, depending on {func}
1555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001556
1557ceil({expr}) *ceil()*
1558 Return the smallest integral value greater than or equal to
1559 {expr} as a |Float| (round up).
1560 {expr} must evaluate to a |Float| or a |Number|.
1561 Examples: >
1562 echo ceil(1.456)
1563< 2.0 >
1564 echo ceil(-5.456)
1565< -5.0 >
1566 echo ceil(4.0)
1567< 4.0
1568
Bram Moolenaar016188f2022-06-06 20:52:59 +01001569 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001571 Can also be used as a |method|: >
1572 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001573<
1574 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575
1576
1577ch_ functions are documented here: |channel-functions-details|
1578
1579
1580changenr() *changenr()*
1581 Return the number of the most recent change. This is the same
1582 number as what is displayed with |:undolist| and can be used
1583 with the |:undo| command.
1584 When a change was made it is the number of that change. After
1585 redo it is the number of the redone change. After undo it is
1586 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001587 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001588
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001589 Return type: |Number|
1590
1591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001592char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001593 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001594 Examples: >
1595 char2nr(" ") returns 32
1596 char2nr("ABC") returns 65
1597< When {utf8} is omitted or zero, the current 'encoding' is used.
1598 Example for "utf-8": >
1599 char2nr("á") returns 225
1600 char2nr("á"[0]) returns 195
1601< When {utf8} is TRUE, always treat as UTF-8 characters.
1602 A combining character is a separate character.
1603 |nr2char()| does the opposite.
1604 To turn a string into a list of character numbers: >
1605 let str = "ABC"
1606 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1607< Result: [65, 66, 67]
1608
Bram Moolenaar016188f2022-06-06 20:52:59 +01001609 Returns 0 if {string} is not a |String|.
1610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001611 Can also be used as a |method|: >
1612 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001613<
1614 Return type: |Number|
1615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617charclass({string}) *charclass()*
1618 Return the character class of the first character in {string}.
1619 The character class is one of:
1620 0 blank
1621 1 punctuation
1622 2 word character
1623 3 emoji
1624 other specific Unicode class
1625 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001626 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001627
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001628 Return type: |Number|
1629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001630
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001631charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001632 Same as |col()| but returns the character index of the column
1633 position given with {expr} instead of the byte position.
1634
1635 Example:
1636 With the cursor on '세' in line 5 with text "여보세요": >
1637 charcol('.') returns 3
1638 col('.') returns 7
1639
1640< Can also be used as a |method|: >
1641 GetPos()->col()
1642<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001643 Return type: |Number|
1644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001645 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001646charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001647 Return the character index of the byte at {idx} in {string}.
1648 The index of the first character is zero.
1649 If there are no multibyte characters the returned value is
1650 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001652 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001653 are not counted separately, their byte length is added to the
1654 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001655 When {countcc} is |TRUE|, then composing characters are
1656 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
1658 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1659 index in the String {expr} instead of as the byte index.
1660
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001661 Returns -1 if the arguments are invalid or if there are less
1662 than {idx} bytes. If there are exactly {idx} bytes the length
1663 of the string in characters is returned.
1664
1665 An error is given and -1 is returned if the first argument is
1666 not a string, the second argument is not a number or when the
1667 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001670 from the character index and |utf16idx()| for getting the
1671 UTF-16 index from the character index.
1672 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673 Examples: >
1674 echo charidx('áb́ć', 3) returns 1
1675 echo charidx('áb́ć', 6, 1) returns 4
1676 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001677 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001678<
1679 Can also be used as a |method|: >
1680 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001681<
1682 Return type: |Number|
1683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684
1685chdir({dir}) *chdir()*
1686 Change the current working directory to {dir}. The scope of
1687 the directory change depends on the directory of the current
1688 window:
1689 - If the current window has a window-local directory
1690 (|:lcd|), then changes the window local directory.
1691 - Otherwise, if the current tabpage has a local
1692 directory (|:tcd|) then changes the tabpage local
1693 directory.
1694 - Otherwise, changes the global directory.
1695 {dir} must be a String.
1696 If successful, returns the previous working directory. Pass
1697 this to another chdir() to restore the directory.
1698 On failure, returns an empty string.
1699
1700 Example: >
1701 let save_dir = chdir(newdir)
1702 if save_dir != ""
1703 " ... do some work
1704 call chdir(save_dir)
1705 endif
1706
1707< Can also be used as a |method|: >
1708 GetDir()->chdir()
1709<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001710 Return type: |String|
1711
1712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001713cindent({lnum}) *cindent()*
1714 Get the amount of indent for line {lnum} according the C
1715 indenting rules, as with 'cindent'.
1716 The indent is counted in spaces, the value of 'tabstop' is
1717 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001718 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 See |C-indenting|.
1720
1721 Can also be used as a |method|: >
1722 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001723<
1724 Return type: |Number|
1725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001726
1727clearmatches([{win}]) *clearmatches()*
1728 Clears all matches previously defined for the current window
1729 by |matchadd()| and the |:match| commands.
1730 If {win} is specified, use the window with this number or
1731 window ID instead of the current window.
1732
1733 Can also be used as a |method|: >
1734 GetWin()->clearmatches()
1735<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001736 Return type: |Number|
1737
1738
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001739col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001740 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001741 position given with {expr}.
1742 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001743 When {expr} is "$", it means the end of the cursor line, so
1744 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Additionally {expr} can be [lnum, col]: a |List| with the line
1746 and column number. Most useful when the column is "$", to get
1747 the last column of a specific line. When "lnum" or "col" is
1748 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001749
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001750 With the optional {winid} argument the values are obtained for
1751 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001753 To get the line number use |line()|. To get both use
1754 |getpos()|.
1755 For the screen column position use |virtcol()|. For the
1756 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001758 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001760 Examples: >
1761 col(".") column of cursor
1762 col("$") length of cursor line plus one
1763 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001764 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001765<
1766 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001767 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001768 For an uppercase mark the column may actually be in another
1769 buffer.
1770 For the cursor position, when 'virtualedit' is active, the
1771 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001772 line. Also, when using a <Cmd> mapping the cursor isn't
1773 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001774 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001775
1776< Can also be used as a |method|: >
1777 GetPos()->col()
1778<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001779 Return type: |Number|
1780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001781
1782complete({startcol}, {matches}) *complete()* *E785*
1783 Set the matches for Insert mode completion.
1784 Can only be used in Insert mode. You need to use a mapping
1785 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1786 or with an expression mapping.
1787 {startcol} is the byte offset in the line where the completed
1788 text start. The text up to the cursor is the original text
1789 that will be replaced by the matches. Use col('.') for an
1790 empty string. "col('.') - 1" will replace one character by a
1791 match.
1792 {matches} must be a |List|. Each |List| item is one match.
1793 See |complete-items| for the kind of items that are possible.
1794 "longest" in 'completeopt' is ignored.
1795 Note that the after calling this function you need to avoid
1796 inserting anything that would cause completion to stop.
1797 The match can be selected with CTRL-N and CTRL-P as usual with
1798 Insert mode completion. The popup menu will appear if
1799 specified, see |ins-completion-menu|.
1800 Example: >
1801 inoremap <F5> <C-R>=ListMonths()<CR>
1802
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001803 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804 call complete(col('.'), ['January', 'February', 'March',
1805 \ 'April', 'May', 'June', 'July', 'August', 'September',
1806 \ 'October', 'November', 'December'])
1807 return ''
1808 endfunc
1809< This isn't very useful, but it shows how it works. Note that
1810 an empty string is returned to avoid a zero being inserted.
1811
1812 Can also be used as a |method|, the base is passed as the
1813 second argument: >
1814 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001815<
1816 Return type: |Number|
1817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001818
1819complete_add({expr}) *complete_add()*
1820 Add {expr} to the list of matches. Only to be used by the
1821 function specified with the 'completefunc' option.
1822 Returns 0 for failure (empty string or out of memory),
1823 1 when the match was added, 2 when the match was already in
1824 the list.
1825 See |complete-functions| for an explanation of {expr}. It is
1826 the same as one item in the list that 'omnifunc' would return.
1827
1828 Can also be used as a |method|: >
1829 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001830<
1831 Return type: |Number|
1832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001833
1834complete_check() *complete_check()*
1835 Check for a key typed while looking for completion matches.
1836 This is to be used when looking for matches takes some time.
1837 Returns |TRUE| when searching for matches is to be aborted,
1838 zero otherwise.
1839 Only to be used by the function specified with the
1840 'completefunc' option.
1841
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001842 Return type: |Number|
1843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001844
1845complete_info([{what}]) *complete_info()*
1846 Returns a |Dictionary| with information about Insert mode
1847 completion. See |ins-completion|.
1848 The items are:
1849 mode Current completion mode name string.
1850 See |complete_info_mode| for the values.
1851 pum_visible |TRUE| if popup menu is visible.
1852 See |pumvisible()|.
1853 items List of completion matches. Each item is a
1854 dictionary containing the entries "word",
1855 "abbr", "menu", "kind", "info" and "user_data".
1856 See |complete-items|.
1857 selected Selected item index. First index is zero.
1858 Index is -1 if no item is selected (showing
1859 typed text only, or the last completion after
1860 no item is selected when using the <Up> or
1861 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001862 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001863
1864 *complete_info_mode*
1865 mode values are:
1866 "" Not in completion mode
1867 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1868 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1869 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1870 |i_CTRL-X_CTRL-Y|
1871 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1872 "files" File names |i_CTRL-X_CTRL-F|
1873 "tags" Tags |i_CTRL-X_CTRL-]|
1874 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1875 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1876 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1877 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1878 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1879 "function" User defined completion |i_CTRL-X_CTRL-U|
1880 "omni" Omni completion |i_CTRL-X_CTRL-O|
1881 "spell" Spelling suggestions |i_CTRL-X_s|
1882 "eval" |complete()| completion
1883 "unknown" Other internal modes
1884
1885 If the optional {what} list argument is supplied, then only
1886 the items listed in {what} are returned. Unsupported items in
1887 {what} are silently ignored.
1888
1889 To get the position and size of the popup menu, see
1890 |pum_getpos()|. It's also available in |v:event| during the
1891 |CompleteChanged| event.
1892
Bram Moolenaar016188f2022-06-06 20:52:59 +01001893 Returns an empty |Dictionary| on error.
1894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001895 Examples: >
1896 " Get all items
1897 call complete_info()
1898 " Get only 'mode'
1899 call complete_info(['mode'])
1900 " Get only 'mode' and 'pum_visible'
1901 call complete_info(['mode', 'pum_visible'])
1902
1903< Can also be used as a |method|: >
1904 GetItems()->complete_info()
1905<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001906 Return type: dict<any>
1907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001908 *confirm()*
1909confirm({msg} [, {choices} [, {default} [, {type}]]])
1910 confirm() offers the user a dialog, from which a choice can be
1911 made. It returns the number of the choice. For the first
1912 choice this is 1.
1913 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001914 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001915
1916 {msg} is displayed in a |dialog| with {choices} as the
1917 alternatives. When {choices} is missing or empty, "&OK" is
1918 used (and translated).
1919 {msg} is a String, use '\n' to include a newline. Only on
1920 some systems the string is wrapped when it doesn't fit.
1921
1922 {choices} is a String, with the individual choices separated
1923 by '\n', e.g. >
1924 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1925< The letter after the '&' is the shortcut key for that choice.
1926 Thus you can type 'c' to select "Cancel". The shortcut does
1927 not need to be the first letter: >
1928 confirm("file has been modified", "&Save\nSave &All")
1929< For the console, the first letter of each choice is used as
1930 the default shortcut key. Case is ignored.
1931
1932 The optional {default} argument is the number of the choice
1933 that is made if the user hits <CR>. Use 1 to make the first
1934 choice the default one. Use 0 to not set a default. If
1935 {default} is omitted, 1 is used.
1936
1937 The optional {type} String argument gives the type of dialog.
1938 This is only used for the icon of the GTK, Mac, Motif and
1939 Win32 GUI. It can be one of these values: "Error",
1940 "Question", "Info", "Warning" or "Generic". Only the first
1941 character is relevant. When {type} is omitted, "Generic" is
1942 used.
1943
1944 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1945 or another valid interrupt key, confirm() returns 0.
1946
1947 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001948 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001949 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001950 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001951 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001952 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001953 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001954 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001955 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001956 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001957< In a GUI dialog, buttons are used. The layout of the buttons
1958 depends on the 'v' flag in 'guioptions'. If it is included,
1959 the buttons are always put vertically. Otherwise, confirm()
1960 tries to put the buttons in one horizontal line. If they
1961 don't fit, a vertical layout is used anyway. For some systems
1962 the horizontal layout is always used.
1963
1964 Can also be used as a |method|in: >
1965 BuildMessage()->confirm("&Yes\n&No")
1966<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001967 Return type: |Number|
1968
1969
1970copy({expr}) *copy()*
1971 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001972 different from using {expr} directly.
1973 When {expr} is a |List| a shallow copy is created. This means
1974 that the original |List| can be changed without changing the
1975 copy, and vice versa. But the items are identical, thus
1976 changing an item changes the contents of both |Lists|.
1977 A |Dictionary| is copied in a similar way as a |List|.
1978 Also see |deepcopy()|.
1979 Can also be used as a |method|: >
1980 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001981<
1982 Return type: any, depending on {expr}
1983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001984
1985cos({expr}) *cos()*
1986 Return the cosine of {expr}, measured in radians, as a |Float|.
1987 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001988 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001989 Examples: >
1990 :echo cos(100)
1991< 0.862319 >
1992 :echo cos(-4.01)
1993< -0.646043
1994
1995 Can also be used as a |method|: >
1996 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001997<
1998 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001999
2000
2001cosh({expr}) *cosh()*
2002 Return the hyperbolic cosine of {expr} as a |Float| in the range
2003 [1, inf].
2004 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002005 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006 Examples: >
2007 :echo cosh(0.5)
2008< 1.127626 >
2009 :echo cosh(-0.5)
2010< -1.127626
2011
2012 Can also be used as a |method|: >
2013 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002014<
2015 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002016
2017
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002018count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002019 Return the number of times an item with value {expr} appears
2020 in |String|, |List| or |Dictionary| {comp}.
2021
2022 If {start} is given then start with the item with this index.
2023 {start} can only be used with a |List|.
2024
2025 When {ic} is given and it's |TRUE| then case is ignored.
2026
2027 When {comp} is a string then the number of not overlapping
2028 occurrences of {expr} is returned. Zero is returned when
2029 {expr} is an empty string.
2030
2031 Can also be used as a |method|: >
2032 mylist->count(val)
2033<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002034 Return type: |Number|
2035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002036 *cscope_connection()*
2037cscope_connection([{num} , {dbpath} [, {prepend}]])
2038 Checks for the existence of a |cscope| connection. If no
2039 parameters are specified, then the function returns:
2040 0, if cscope was not available (not compiled in), or
2041 if there are no cscope connections;
2042 1, if there is at least one cscope connection.
2043
2044 If parameters are specified, then the value of {num}
2045 determines how existence of a cscope connection is checked:
2046
2047 {num} Description of existence check
2048 ----- ------------------------------
2049 0 Same as no parameters (e.g., "cscope_connection()").
2050 1 Ignore {prepend}, and use partial string matches for
2051 {dbpath}.
2052 2 Ignore {prepend}, and use exact string matches for
2053 {dbpath}.
2054 3 Use {prepend}, use partial string matches for both
2055 {dbpath} and {prepend}.
2056 4 Use {prepend}, use exact string matches for both
2057 {dbpath} and {prepend}.
2058
2059 Note: All string comparisons are case sensitive!
2060
2061 Examples. Suppose we had the following (from ":cs show"): >
2062
2063 # pid database name prepend path
2064 0 27664 cscope.out /usr/local
2065<
2066 Invocation Return Val ~
2067 ---------- ---------- >
2068 cscope_connection() 1
2069 cscope_connection(1, "out") 1
2070 cscope_connection(2, "out") 0
2071 cscope_connection(3, "out") 0
2072 cscope_connection(3, "out", "local") 1
2073 cscope_connection(4, "out") 0
2074 cscope_connection(4, "out", "local") 0
2075 cscope_connection(4, "cscope.out", "/usr/local") 1
2076<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002077 Return type: |Number|
2078
2079
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002080cursor({lnum}, {col} [, {off}]) *cursor()*
2081cursor({list})
2082 Positions the cursor at the column (byte count) {col} in the
2083 line {lnum}. The first column is one.
2084
2085 When there is one argument {list} this is used as a |List|
2086 with two, three or four item:
2087 [{lnum}, {col}]
2088 [{lnum}, {col}, {off}]
2089 [{lnum}, {col}, {off}, {curswant}]
2090 This is like the return value of |getpos()| or |getcurpos()|,
2091 but without the first item.
2092
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002093 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002094 |setcursorcharpos()|.
2095
2096 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002097 {lnum} is used like with |getline()|, except that if {lnum} is
2098 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002099 If {lnum} is greater than the number of lines in the buffer,
2100 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002101 If {col} is greater than the number of bytes in the line,
2102 the cursor will be positioned at the last character in the
2103 line.
2104 If {col} is zero, the cursor will stay in the current column.
2105 If {curswant} is given it is used to set the preferred column
2106 for vertical movement. Otherwise {col} is used.
2107
2108 When 'virtualedit' is used {off} specifies the offset in
2109 screen columns from the start of the character. E.g., a
2110 position within a <Tab> or after the last character.
2111 Returns 0 when the position could be set, -1 otherwise.
2112
2113 Can also be used as a |method|: >
2114 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002115<
2116 Return type: |Number|
2117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002118
2119debugbreak({pid}) *debugbreak()*
2120 Specifically used to interrupt a program being debugged. It
2121 will cause process {pid} to get a SIGTRAP. Behavior for other
2122 processes is undefined. See |terminal-debugger|.
2123 {only available on MS-Windows}
2124
Bram Moolenaar016188f2022-06-06 20:52:59 +01002125 Returns |TRUE| if successfully interrupted the program.
2126 Otherwise returns |FALSE|.
2127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002128 Can also be used as a |method|: >
2129 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002130<
2131 Return type: |Number|
2132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002133
2134deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2135 Make a copy of {expr}. For Numbers and Strings this isn't
2136 different from using {expr} directly.
2137 When {expr} is a |List| a full copy is created. This means
2138 that the original |List| can be changed without changing the
2139 copy, and vice versa. When an item is a |List| or
2140 |Dictionary|, a copy for it is made, recursively. Thus
2141 changing an item in the copy does not change the contents of
2142 the original |List|.
2143 A |Dictionary| is copied in a similar way as a |List|.
2144
2145 When {noref} is omitted or zero a contained |List| or
2146 |Dictionary| is only copied once. All references point to
2147 this single copy. With {noref} set to 1 every occurrence of a
2148 |List| or |Dictionary| results in a new copy. This also means
2149 that a cyclic reference causes deepcopy() to fail.
2150 *E724*
2151 Nesting is possible up to 100 levels. When there is an item
2152 that refers back to a higher level making a deep copy with
2153 {noref} set to 1 will fail.
2154 Also see |copy()|.
2155
2156 Can also be used as a |method|: >
2157 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002158<
2159 Return type: any, depending on {expr}
2160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002161
2162delete({fname} [, {flags}]) *delete()*
2163 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002164 name {fname}.
2165
2166 This also works when {fname} is a symbolic link. The symbolic
2167 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002168
2169 When {flags} is "d": Deletes the directory by the name
2170 {fname}. This fails when directory {fname} is not empty.
2171
2172 When {flags} is "rf": Deletes the directory by the name
2173 {fname} and everything in it, recursively. BE CAREFUL!
2174 Note: on MS-Windows it is not possible to delete a directory
2175 that is being used.
2176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002177 The result is a Number, which is 0/false if the delete
2178 operation was successful and -1/true when the deletion failed
2179 or partly failed.
2180
2181 Use |remove()| to delete an item from a |List|.
2182 To delete a line from the buffer use |:delete| or
2183 |deletebufline()|.
2184
2185 Can also be used as a |method|: >
2186 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002187<
2188 Return type: |Number|
2189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002190
2191deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2192 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2193 If {last} is omitted then delete line {first} only.
2194 On success 0 is returned, on failure 1 is returned.
2195
2196 This function works only for loaded buffers. First call
2197 |bufload()| if needed.
2198
2199 For the use of {buf}, see |bufname()| above.
2200
2201 {first} and {last} are used like with |getline()|. Note that
2202 when using |line()| this refers to the current buffer. Use "$"
2203 to refer to the last line in buffer {buf}.
2204
2205 Can also be used as a |method|: >
2206 GetBuffer()->deletebufline(1)
2207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002208 Return type: |Number|
2209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002210 *did_filetype()*
2211did_filetype() Returns |TRUE| when autocommands are being executed and the
2212 FileType event has been triggered at least once. Can be used
2213 to avoid triggering the FileType event again in the scripts
2214 that detect the file type. |FileType|
2215 Returns |FALSE| when `:setf FALLBACK` was used.
2216 When editing another file, the counter is reset, thus this
2217 really checks if the FileType event has been triggered for the
2218 current buffer. This allows an autocommand that starts
2219 editing another buffer to set 'filetype' and load a syntax
2220 file.
2221
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002222 Return type: |Number|
2223
2224
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002225diff({fromlist}, {tolist} [, {options}]) *diff()*
2226 Returns a String or a List containing the diff between the
2227 strings in {fromlist} and {tolist}. Uses the Vim internal
2228 diff library to compute the diff.
2229
2230 *E106*
2231 The optional "output" item in {options} specifies the returned
2232 diff format. The following values are supported:
2233 indices Return a List of the starting and ending
2234 indices and a count of the strings in each
2235 diff hunk.
2236 unified Return the unified diff output as a String.
2237 This is the default.
2238
2239 If the "output" item in {options} is "indices", then a List is
2240 returned. Each List item contains a Dict with the following
2241 items for each diff hunk:
2242 from_idx start index in {fromlist} for this diff hunk.
2243 from_count number of strings in {fromlist} that are
2244 added/removed/modified in this diff hunk.
2245 to_idx start index in {tolist} for this diff hunk.
2246 to_count number of strings in {tolist} that are
2247 added/removed/modified in this diff hunk.
2248
2249 The {options} Dict argument also specifies diff options
2250 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002251 algorithm Dict specifying the diff algorithm to
2252 use. Supported boolean items are
2253 "myers", "minimal", "patience" and
2254 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002255 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002256 iblank ignore changes where lines are all
2257 blank.
2258 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002259 indent-heuristic use the indent heuristic for the
2260 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002261 iwhite ignore changes in amount of white
2262 space.
2263 iwhiteall ignore all white space changes.
2264 iwhiteeol ignore white space changes at end of
2265 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002266 For more information about these options, refer to 'diffopt'.
2267
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002268 To compute the unified diff, all the items in {fromlist} are
2269 concatenated into a string using a newline separator and the
2270 same for {tolist}. The unified diff output uses line numbers.
2271
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002272 Returns an empty List or String if {fromlist} and {tolist} are
2273 identical.
2274
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002275 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002276 :echo diff(['abc'], ['xxx'])
2277 @@ -1 +1 @@
2278 -abc
2279 +xxx
2280
2281 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2282 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2283 :echo diff(readfile('oldfile'), readfile('newfile'))
2284 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002285<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002286 For more examples, refer to |diff-func-examples|
2287
2288 Can also be used as a |method|: >
2289 GetFromList->diff(to_list)
2290<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002291 Return type: |String| or list<dict<number>> or list<any>
2292 depending on {options}
2293
2294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002295diff_filler({lnum}) *diff_filler()*
2296 Returns the number of filler lines above line {lnum}.
2297 These are the lines that were inserted at this point in
2298 another diff'ed window. These filler lines are shown in the
2299 display but don't exist in the buffer.
2300 {lnum} is used like with |getline()|. Thus "." is the current
2301 line, "'m" mark m, etc.
2302 Returns 0 if the current window is not in diff mode.
2303
2304 Can also be used as a |method|: >
2305 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002306<
2307 Return type: |Number|
2308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002309
2310diff_hlID({lnum}, {col}) *diff_hlID()*
2311 Returns the highlight ID for diff mode at line {lnum} column
2312 {col} (byte index). When the current line does not have a
2313 diff change zero is returned.
2314 {lnum} is used like with |getline()|. Thus "." is the current
2315 line, "'m" mark m, etc.
2316 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2317 line.
2318 The highlight ID can be used with |synIDattr()| to obtain
2319 syntax information about the highlighting.
2320
2321 Can also be used as a |method|: >
2322 GetLnum()->diff_hlID(col)
2323<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002324 Return type: |Number|
2325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002326
2327digraph_get({chars}) *digraph_get()* *E1214*
2328 Return the digraph of {chars}. This should be a string with
2329 exactly two characters. If {chars} are not just two
2330 characters, or the digraph of {chars} does not exist, an error
2331 is given and an empty string is returned.
2332
2333 The character will be converted from Unicode to 'encoding'
2334 when needed. This does require the conversion to be
2335 available, it might fail.
2336
2337 Also see |digraph_getlist()|.
2338
2339 Examples: >
2340 " Get a built-in digraph
2341 :echo digraph_get('00') " Returns '∞'
2342
2343 " Get a user-defined digraph
2344 :call digraph_set('aa', 'あ')
2345 :echo digraph_get('aa') " Returns 'あ'
2346<
2347 Can also be used as a |method|: >
2348 GetChars()->digraph_get()
2349<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002350 Return type: |String|
2351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002352 This function works only when compiled with the |+digraphs|
2353 feature. If this feature is disabled, this function will
2354 display an error message.
2355
2356
2357digraph_getlist([{listall}]) *digraph_getlist()*
2358 Return a list of digraphs. If the {listall} argument is given
2359 and it is TRUE, return all digraphs, including the default
2360 digraphs. Otherwise, return only user-defined digraphs.
2361
2362 The characters will be converted from Unicode to 'encoding'
2363 when needed. This does require the conservation to be
2364 available, it might fail.
2365
2366 Also see |digraph_get()|.
2367
2368 Examples: >
2369 " Get user-defined digraphs
2370 :echo digraph_getlist()
2371
2372 " Get all the digraphs, including default digraphs
2373 :echo digraph_getlist(1)
2374<
2375 Can also be used as a |method|: >
2376 GetNumber()->digraph_getlist()
2377<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002378 Return type: list<list<string>>
2379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002380 This function works only when compiled with the |+digraphs|
2381 feature. If this feature is disabled, this function will
2382 display an error message.
2383
2384
Bram Moolenaara2baa732022-02-04 16:09:54 +00002385digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002386 Add digraph {chars} to the list. {chars} must be a string
2387 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002388 encoded character. *E1215*
2389 Be careful, composing characters are NOT ignored. This
2390 function is similar to |:digraphs| command, but useful to add
2391 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002392
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002393 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002394 this fails an error message is given and v:false is returned.
2395
2396 If you want to define multiple digraphs at once, you can use
2397 |digraph_setlist()|.
2398
2399 Example: >
2400 call digraph_set(' ', 'あ')
2401<
2402 Can be used as a |method|: >
2403 GetString()->digraph_set('あ')
2404<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002405 Return type: |vim9-boolean|
2406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002407 This function works only when compiled with the |+digraphs|
2408 feature. If this feature is disabled, this function will
2409 display an error message.
2410
2411
2412digraph_setlist({digraphlist}) *digraph_setlist()*
2413 Similar to |digraph_set()| but this function can add multiple
2414 digraphs at once. {digraphlist} is a list composed of lists,
2415 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002416 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002417 Example: >
2418 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2419<
2420 It is similar to the following: >
2421 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2422 call digraph_set(chars, digraph)
2423 endfor
2424< Except that the function returns after the first error,
2425 following digraphs will not be added.
2426
2427 Can be used as a |method|: >
2428 GetList()->digraph_setlist()
2429<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002430 Return type: |vim9-boolean|
2431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002432 This function works only when compiled with the |+digraphs|
2433 feature. If this feature is disabled, this function will
2434 display an error message.
2435
2436
2437echoraw({string}) *echoraw()*
2438 Output {string} as-is, including unprintable characters.
2439 This can be used to output a terminal code. For example, to
2440 disable modifyOtherKeys: >
2441 call echoraw(&t_TE)
2442< and to enable it again: >
2443 call echoraw(&t_TI)
2444< Use with care, you can mess up the terminal this way.
2445
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002446 Return type: |Number|
2447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002448
2449empty({expr}) *empty()*
2450 Return the Number 1 if {expr} is empty, zero otherwise.
2451 - A |List| or |Dictionary| is empty when it does not have any
2452 items.
2453 - A |String| is empty when its length is zero.
2454 - A |Number| and |Float| are empty when their value is zero.
2455 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2456 - A |Job| is empty when it failed to start.
2457 - A |Channel| is empty when it is closed.
2458 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002459 - An |Object| is empty, when the empty() method in the object
2460 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002461
2462 For a long |List| this is much faster than comparing the
2463 length with zero.
2464
2465 Can also be used as a |method|: >
2466 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002467<
2468 Return type: |Number|
2469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002470
2471environ() *environ()*
2472 Return all of environment variables as dictionary. You can
2473 check if an environment variable exists like this: >
2474 :echo has_key(environ(), 'HOME')
2475< Note that the variable name may be CamelCase; to ignore case
2476 use this: >
2477 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002478<
2479 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002480
Bram Moolenaar416bd912023-07-07 23:19:18 +01002481
2482err_teapot([{expr}]) *err_teapot()*
2483 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002484 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002485 If {expr} is present and it is TRUE error 503 is given,
2486 indicating that coffee is temporarily not available.
2487 If {expr} is present it must be a String.
2488
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002489 Return type: |Number|
2490
Bram Moolenaar416bd912023-07-07 23:19:18 +01002491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002492escape({string}, {chars}) *escape()*
2493 Escape the characters in {chars} that occur in {string} with a
2494 backslash. Example: >
2495 :echo escape('c:\program files\vim', ' \')
2496< results in: >
2497 c:\\program\ files\\vim
2498< Also see |shellescape()| and |fnameescape()|.
2499
2500 Can also be used as a |method|: >
2501 GetText()->escape(' \')
2502<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002503 Return type: |String|
2504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002505 *eval()*
2506eval({string}) Evaluate {string} and return the result. Especially useful to
2507 turn the result of |string()| back into the original value.
2508 This works for Numbers, Floats, Strings, Blobs and composites
2509 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002510 functions. In |Vim9| script, it can be used to obtain |enum|
2511 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002512
2513 Can also be used as a |method|: >
2514 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002515<
2516 Return type: any, depending on {string}
2517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518
2519eventhandler() *eventhandler()*
2520 Returns 1 when inside an event handler. That is that Vim got
2521 interrupted while waiting for the user to type a character,
2522 e.g., when dropping a file on Vim. This means interactive
2523 commands cannot be used. Otherwise zero is returned.
2524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002525 Return type: |Number|
2526
2527
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002528executable({expr}) *executable()*
2529 This function checks if an executable with the name {expr}
2530 exists. {expr} must be the name of the program without any
2531 arguments.
2532 executable() uses the value of $PATH and/or the normal
2533 searchpath for programs. *PATHEXT*
2534 On MS-Windows the ".exe", ".bat", etc. can optionally be
2535 included. Then the extensions in $PATHEXT are tried. Thus if
2536 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2537 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2538 by itself can be used in $PATHEXT to try using the name
2539 without an extension. When 'shell' looks like a Unix shell,
2540 then the name is also tried without adding an extension.
2541 On MS-Windows it only checks if the file exists and is not a
2542 directory, not if it's really executable.
2543 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002544 normally found. Since this directory is added to $PATH it
2545 should also work to execute it |win32-PATH|. This can be
2546 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2547 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002548 The result is a Number:
2549 1 exists
2550 0 does not exist
2551 -1 not implemented on this system
2552 |exepath()| can be used to get the full path of an executable.
2553
2554 Can also be used as a |method|: >
2555 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002556<
2557 Return type: |Number|
2558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559
2560execute({command} [, {silent}]) *execute()*
2561 Execute an Ex command or commands and return the output as a
2562 string.
2563 {command} can be a string or a List. In case of a List the
2564 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002565 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002566 redir => var
2567 {command}
2568 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002569< Except that line continuation in {command} is not recognized.
2570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002571 The optional {silent} argument can have these values:
2572 "" no `:silent` used
2573 "silent" `:silent` used
2574 "silent!" `:silent!` used
2575 The default is "silent". Note that with "silent!", unlike
2576 `:redir`, error messages are dropped. When using an external
2577 command the screen may be messed up, use `system()` instead.
2578 *E930*
2579 It is not possible to use `:redir` anywhere in {command}.
2580
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002581 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002582 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002583
2584< To execute a command in another window than the current one
2585 use `win_execute()`.
2586
2587 When used recursively the output of the recursive call is not
2588 included in the output of the higher level call.
2589
2590 Can also be used as a |method|: >
2591 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002592<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002593 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002595
2596exepath({expr}) *exepath()*
2597 If {expr} is an executable and is either an absolute path, a
2598 relative path or found in $PATH, return the full path.
2599 Note that the current directory is used when {expr} starts
2600 with "./", which may be a problem for Vim: >
2601 echo exepath(v:progpath)
2602< If {expr} cannot be found in $PATH or is not executable then
2603 an empty string is returned.
2604
2605 Can also be used as a |method|: >
2606 GetCommand()->exepath()
2607<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002608 Return type: |String|
2609
2610
2611exists({expr}) *exists()*
2612 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002613 zero otherwise.
2614
2615 Note: In a compiled |:def| function the evaluation is done at
2616 runtime. Use `exists_compiled()` to evaluate the expression
2617 at compile time.
2618
2619 For checking for a supported feature use |has()|.
2620 For checking if a file exists use |filereadable()|.
2621
2622 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002623 varname internal variable (see
2624 dict.key |internal-variables|). Also works
2625 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002626 import.Func entries, |List| items, class and
2627 class.Func object methods, imported items, etc.
2628 object.Func Does not work for local variables in a
2629 class.varname compiled `:def` function.
2630 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002631 script, since it can be used as a
2632 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002633 Beware that evaluating an index may
2634 cause an error message for an invalid
2635 expression. E.g.: >
2636 :let l = [1, 2, 3]
2637 :echo exists("l[5]")
2638< 0 >
2639 :echo exists("l[xx]")
2640< E121: Undefined variable: xx
2641 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002642 &option-name Vim option (only checks if it exists,
2643 not if it really works)
2644 +option-name Vim option that works.
2645 $ENVNAME environment variable (could also be
2646 done by comparing with an empty
2647 string)
2648 *funcname built-in function (see |functions|)
2649 or user defined function (see
2650 |user-functions|) that is implemented.
2651 Also works for a variable that is a
2652 Funcref.
2653 ?funcname built-in function that could be
2654 implemented; to be used to check if
2655 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002656 :cmdname Ex command: built-in command, user
2657 command or command modifier |:command|.
2658 Returns:
2659 1 for match with start of a command
2660 2 full match with a command
2661 3 matches several user commands
2662 To check for a supported command
2663 always check the return value to be 2.
2664 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002665 :3match The |:3match| command (but you
2666 probably should not use it, it is
2667 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002668 #event autocommand defined for this event
2669 #event#pattern autocommand defined for this event and
2670 pattern (the pattern is taken
2671 literally and compared to the
2672 autocommand patterns character by
2673 character)
2674 #group autocommand group exists
2675 #group#event autocommand defined for this group and
2676 event.
2677 #group#event#pattern
2678 autocommand defined for this group,
2679 event and pattern.
2680 ##event autocommand for this event is
2681 supported.
2682
2683 Examples: >
2684 exists("&shortname")
2685 exists("$HOSTNAME")
2686 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002687 exists("*s:MyFunc") " only for legacy script
2688 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002689 exists("bufcount")
2690 exists(":Make")
2691 exists("#CursorHold")
2692 exists("#BufReadPre#*.gz")
2693 exists("#filetypeindent")
2694 exists("#filetypeindent#FileType")
2695 exists("#filetypeindent#FileType#*")
2696 exists("##ColorScheme")
2697< There must be no space between the symbol (&/$/*/#) and the
2698 name.
2699 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002700 a few cases this is ignored. That may become stricter in the
2701 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002702 Working example: >
2703 exists(":make")
2704< NOT working example: >
2705 exists(":make install")
2706
2707< Note that the argument must be a string, not the name of the
2708 variable itself. For example: >
2709 exists(bufcount)
2710< This doesn't check for existence of the "bufcount" variable,
2711 but gets the value of "bufcount", and checks if that exists.
2712
2713 Can also be used as a |method|: >
2714 Varname()->exists()
2715<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002716 Return type: |String|
2717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002718
2719exists_compiled({expr}) *exists_compiled()*
2720 Like `exists()` but evaluated at compile time. This is useful
2721 to skip a block where a function is used that would otherwise
2722 give an error: >
2723 if exists_compiled('*ThatFunction')
2724 ThatFunction('works')
2725 endif
2726< If `exists()` were used then a compilation error would be
2727 given if ThatFunction() is not defined.
2728
2729 {expr} must be a literal string. *E1232*
2730 Can only be used in a |:def| function. *E1233*
2731 This does not work to check for arguments or local variables.
2732
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002733 Return type: |String|
2734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002735
2736exp({expr}) *exp()*
2737 Return the exponential of {expr} as a |Float| in the range
2738 [0, inf].
2739 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002740 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002741 Examples: >
2742 :echo exp(2)
2743< 7.389056 >
2744 :echo exp(-1)
2745< 0.367879
2746
2747 Can also be used as a |method|: >
2748 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002749<
2750 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002751
2752
2753expand({string} [, {nosuf} [, {list}]]) *expand()*
2754 Expand wildcards and the following special keywords in
2755 {string}. 'wildignorecase' applies.
2756
2757 If {list} is given and it is |TRUE|, a List will be returned.
2758 Otherwise the result is a String and when there are several
2759 matches, they are separated by <NL> characters. [Note: in
2760 version 5.0 a space was used, which caused problems when a
2761 file name contains a space]
2762
2763 If the expansion fails, the result is an empty string. A name
2764 for a non-existing file is not included, unless {string} does
2765 not start with '%', '#' or '<', see below.
2766
Christian Brabandtec9c3262024-02-21 20:40:05 +01002767 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002768 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002770 When {string} starts with '%', '#' or '<', the expansion is
2771 done like for the |cmdline-special| variables with their
2772 associated modifiers. Here is a short overview:
2773
2774 % current file name
2775 # alternate file name
2776 #n alternate file name n
2777 <cfile> file name under the cursor
2778 <afile> autocmd file name
2779 <abuf> autocmd buffer number (as a String!)
2780 <amatch> autocmd matched name
2781 <cexpr> C expression under the cursor
2782 <sfile> sourced script file or function name
2783 <slnum> sourced script line number or function
2784 line number
2785 <sflnum> script file line number, also when in
2786 a function
2787 <SID> "<SNR>123_" where "123" is the
2788 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002789 <script> sourced script file, or script file
2790 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002791 <stack> call stack
2792 <cword> word under the cursor
2793 <cWORD> WORD under the cursor
2794 <client> the {clientid} of the last received
2795 message |server2client()|
2796 Modifiers:
2797 :p expand to full path
2798 :h head (last path component removed)
2799 :t tail (last path component only)
2800 :r root (one extension removed)
2801 :e extension only
2802
2803 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002804 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002805< Note that when expanding a string that starts with '%', '#' or
2806 '<', any following text is ignored. This does NOT work: >
2807 :let doesntwork = expand("%:h.bak")
2808< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002809 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002810< Also note that expanding "<cfile>" and others only returns the
2811 referenced file name without further expansion. If "<cfile>"
2812 is "~/.cshrc", you need to do another expand() to have the
2813 "~/" expanded into the path of the home directory: >
2814 :echo expand(expand("<cfile>"))
2815<
2816 There cannot be white space between the variables and the
2817 following modifier. The |fnamemodify()| function can be used
2818 to modify normal file names.
2819
2820 When using '%' or '#', and the current or alternate file name
2821 is not defined, an empty string is used. Using "%:p" in a
2822 buffer with no name, results in the current directory, with a
2823 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002824 When 'verbose' is set then expanding '%', '#' and <> items
2825 will result in an error message if the argument cannot be
2826 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002827
2828 When {string} does not start with '%', '#' or '<', it is
2829 expanded like a file name is expanded on the command line.
2830 'suffixes' and 'wildignore' are used, unless the optional
2831 {nosuf} argument is given and it is |TRUE|.
2832 Names for non-existing files are included. The "**" item can
2833 be used to search in a directory tree. For example, to find
2834 all "README" files in the current directory and below: >
2835 :echo expand("**/README")
2836<
2837 expand() can also be used to expand variables and environment
2838 variables that are only known in a shell. But this can be
2839 slow, because a shell may be used to do the expansion. See
2840 |expr-env-expand|.
2841 The expanded variable is still handled like a list of file
2842 names. When an environment variable cannot be expanded, it is
2843 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2844 "$FOOBAR".
2845
2846 See |glob()| for finding existing files. See |system()| for
2847 getting the raw output of an external command.
2848
2849 Can also be used as a |method|: >
2850 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002851<
2852 Return type: |String| or list<string> depending on {list}
2853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002854
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002855expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002856 Expand special items in String {string} like what is done for
2857 an Ex command such as `:edit`. This expands special keywords,
2858 like with |expand()|, and environment variables, anywhere in
2859 {string}. "~user" and "~/path" are only expanded at the
2860 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002861
2862 The following items are supported in the {options} Dict
2863 argument:
2864 errmsg If set to TRUE, error messages are displayed
2865 if an error is encountered during expansion.
2866 By default, error messages are not displayed.
2867
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002868 Returns the expanded string. If an error is encountered
2869 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002870
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002871 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002872 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002873 make /path/runtime/doc/builtin.o
2874 :echo expandcmd('make %<.o', {'errmsg': v:true})
2875<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002876 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002877 GetCommand()->expandcmd()
2878<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002879 Return type: |String| or list<string> depending on {list}
2880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002881extend({expr1}, {expr2} [, {expr3}]) *extend()*
2882 {expr1} and {expr2} must be both |Lists| or both
2883 |Dictionaries|.
2884
2885 If they are |Lists|: Append {expr2} to {expr1}.
2886 If {expr3} is given insert the items of {expr2} before the
2887 item with index {expr3} in {expr1}. When {expr3} is zero
2888 insert before the first item. When {expr3} is equal to
2889 len({expr1}) then {expr2} is appended.
2890 Examples: >
2891 :echo sort(extend(mylist, [7, 5]))
2892 :call extend(mylist, [2, 3], 1)
2893< When {expr1} is the same List as {expr2} then the number of
2894 items copied is equal to the original length of the List.
2895 E.g., when {expr3} is 1 you get N new copies of the first item
2896 (where N is the original length of the List).
2897 Use |add()| to concatenate one item to a list. To concatenate
2898 two lists into a new list use the + operator: >
2899 :let newlist = [1, 2, 3] + [4, 5]
2900<
2901 If they are |Dictionaries|:
2902 Add all entries from {expr2} to {expr1}.
2903 If a key exists in both {expr1} and {expr2} then {expr3} is
2904 used to decide what to do:
2905 {expr3} = "keep": keep the value of {expr1}
2906 {expr3} = "force": use the value of {expr2}
2907 {expr3} = "error": give an error message *E737*
2908 When {expr3} is omitted then "force" is assumed.
2909
2910 {expr1} is changed when {expr2} is not empty. If necessary
2911 make a copy of {expr1} first.
2912 {expr2} remains unchanged.
2913 When {expr1} is locked and {expr2} is not empty the operation
2914 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002915 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002916
2917 Can also be used as a |method|: >
2918 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002919<
2920 Return type: list<{type}> or dict<{type}> depending on {expr1}
2921 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002922
2923
2924extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2925 Like |extend()| but instead of adding items to {expr1} a new
2926 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002927 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002928
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002929 Return type: list<{type}> or dict<{type}> depending on {expr1}
2930 and {expr2}, in case of error: |Number|
2931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002932
2933feedkeys({string} [, {mode}]) *feedkeys()*
2934 Characters in {string} are queued for processing as if they
2935 come from a mapping or were typed by the user.
2936
2937 By default the string is added to the end of the typeahead
2938 buffer, thus if a mapping is still being executed the
2939 characters come after them. Use the 'i' flag to insert before
2940 other characters, they will be executed next, before any
2941 characters from a mapping.
2942
2943 The function does not wait for processing of keys contained in
2944 {string}.
2945
2946 To include special keys into {string}, use double-quotes
2947 and "\..." notation |expr-quote|. For example,
2948 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2949 feedkeys('\<CR>') pushes 5 characters.
2950 A special code that might be useful is <Ignore>, it exits the
2951 wait for a character without doing anything. *<Ignore>*
2952
2953 {mode} is a String, which can contain these character flags:
2954 'm' Remap keys. This is default. If {mode} is absent,
2955 keys are remapped.
2956 'n' Do not remap keys.
2957 't' Handle keys as if typed; otherwise they are handled as
2958 if coming from a mapping. This matters for undo,
2959 opening folds, etc.
2960 'L' Lowlevel input. Only works for Unix or when using the
2961 GUI. Keys are used as if they were coming from the
2962 terminal. Other flags are not used. *E980*
2963 When a CTRL-C interrupts and 't' is included it sets
2964 the internal "got_int" flag.
2965 'i' Insert the string instead of appending (see above).
2966 'x' Execute commands until typeahead is empty. This is
2967 similar to using ":normal!". You can call feedkeys()
2968 several times without 'x' and then one time with 'x'
2969 (possibly with an empty {string}) to execute all the
2970 typeahead. Note that when Vim ends in Insert mode it
2971 will behave as if <Esc> is typed, to avoid getting
2972 stuck, waiting for a character to be typed before the
2973 script continues.
2974 Note that if you manage to call feedkeys() while
2975 executing commands, thus calling it recursively, then
2976 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002977 'c' Remove any script context when executing, so that
2978 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002979 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002980 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002981 '!' When used with 'x' will not end Insert mode. Can be
2982 used in a test when a timer is set to exit Insert mode
2983 a little later. Useful for testing CursorHoldI.
2984
2985 Return value is always 0.
2986
2987 Can also be used as a |method|: >
2988 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002989<
2990 Return type: |String| or list<string> depending on {list}
2991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002992
Shougo Matsushita60c87432024-06-03 22:59:27 +02002993filecopy({from}, {to}) *filecopy()*
2994 Copy the file pointed to by the name {from} to {to}. The
2995 result is a Number, which is |TRUE| if the file was copied
2996 successfully, and |FALSE| when it failed.
2997 If a file with name {to} already exists, it will fail.
2998 Note that it does not handle directories (yet).
2999
3000 This function is not available in the |sandbox|.
3001
3002 Can also be used as a |method|: >
3003 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003004<
3005 Return type: |Number|
3006
Shougo Matsushita60c87432024-06-03 22:59:27 +02003007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003008filereadable({file}) *filereadable()*
3009 The result is a Number, which is |TRUE| when a file with the
3010 name {file} exists, and can be read. If {file} doesn't exist,
3011 or is a directory, the result is |FALSE|. {file} is any
3012 expression, which is used as a String.
3013 If you don't care about the file being readable you can use
3014 |glob()|.
3015 {file} is used as-is, you may want to expand wildcards first: >
3016 echo filereadable('~/.vimrc')
3017 0
3018 echo filereadable(expand('~/.vimrc'))
3019 1
3020
3021< Can also be used as a |method|: >
3022 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003023<
3024 Return type: |Number|
3025
3026 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003027 Obsolete name: file_readable().
3028
3029
3030filewritable({file}) *filewritable()*
3031 The result is a Number, which is 1 when a file with the
3032 name {file} exists, and can be written. If {file} doesn't
3033 exist, or is not writable, the result is 0. If {file} is a
3034 directory, and we can write to it, the result is 2.
3035
3036 Can also be used as a |method|: >
3037 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003038<
3039 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003040
3041
3042filter({expr1}, {expr2}) *filter()*
3043 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3044 For each item in {expr1} evaluate {expr2} and when the result
3045 is zero or false remove the item from the |List| or
3046 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003047 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003048
3049 {expr2} must be a |string| or |Funcref|.
3050
3051 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3052 of the current item. For a |Dictionary| |v:key| has the key
3053 of the current item and for a |List| |v:key| has the index of
3054 the current item. For a |Blob| |v:key| has the index of the
3055 current byte. For a |String| |v:key| has the index of the
3056 current character.
3057 Examples: >
3058 call filter(mylist, 'v:val !~ "OLD"')
3059< Removes the items where "OLD" appears. >
3060 call filter(mydict, 'v:key >= 8')
3061< Removes the items with a key below 8. >
3062 call filter(var, 0)
3063< Removes all the items, thus clears the |List| or |Dictionary|.
3064
3065 Note that {expr2} is the result of expression and is then
3066 used as an expression again. Often it is good to use a
3067 |literal-string| to avoid having to double backslashes.
3068
3069 If {expr2} is a |Funcref| it must take two arguments:
3070 1. the key or the index of the current item.
3071 2. the value of the current item.
3072 The function must return |TRUE| if the item should be kept.
3073 Example that keeps the odd items of a list: >
3074 func Odd(idx, val)
3075 return a:idx % 2 == 1
3076 endfunc
3077 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003078< It is shorter when using a |lambda|. In |Vim9| syntax: >
3079 call filter(myList, (idx, val) => idx * val <= 42)
3080< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003081 call filter(myList, {idx, val -> idx * val <= 42})
3082< If you do not use "val" you can leave it out: >
3083 call filter(myList, {idx -> idx % 2 == 1})
3084<
3085 In |Vim9| script the result must be true, false, zero or one.
3086 Other values will result in a type error.
3087
3088 For a |List| and a |Dictionary| the operation is done
3089 in-place. If you want it to remain unmodified make a copy
3090 first: >
3091 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3092
3093< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003094 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003095 When an error is encountered while evaluating {expr2} no
3096 further items in {expr1} are processed.
3097 When {expr2} is a Funcref errors inside a function are ignored,
3098 unless it was defined with the "abort" flag.
3099
3100 Can also be used as a |method|: >
3101 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003102<
3103 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3104 depending on {expr1}
3105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003106
3107finddir({name} [, {path} [, {count}]]) *finddir()*
3108 Find directory {name} in {path}. Supports both downwards and
3109 upwards recursive directory searches. See |file-searching|
3110 for the syntax of {path}.
3111
3112 Returns the path of the first found match. When the found
3113 directory is below the current directory a relative path is
3114 returned. Otherwise a full path is returned.
3115 If {path} is omitted or empty then 'path' is used.
3116
3117 If the optional {count} is given, find {count}'s occurrence of
3118 {name} in {path} instead of the first one.
3119 When {count} is negative return all the matches in a |List|.
3120
Bram Moolenaar016188f2022-06-06 20:52:59 +01003121 Returns an empty string if the directory is not found.
3122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003123 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003124
3125 Can also be used as a |method|: >
3126 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003127<
3128 Return type: |String|
3129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003130
3131findfile({name} [, {path} [, {count}]]) *findfile()*
3132 Just like |finddir()|, but find a file instead of a directory.
3133 Uses 'suffixesadd'.
3134 Example: >
3135 :echo findfile("tags.vim", ".;")
3136< Searches from the directory of the current file upwards until
3137 it finds the file "tags.vim".
3138
3139 Can also be used as a |method|: >
3140 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003141<
3142 Return type: |String|
3143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003144
3145flatten({list} [, {maxdepth}]) *flatten()*
3146 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3147 the result is a |List| without nesting, as if {maxdepth} is
3148 a very large number.
3149 The {list} is changed in place, use |flattennew()| if you do
3150 not want that.
3151 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003152 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003153 *E900*
3154 {maxdepth} means how deep in nested lists changes are made.
3155 {list} is not modified when {maxdepth} is 0.
3156 {maxdepth} must be positive number.
3157
3158 If there is an error the number zero is returned.
3159
3160 Example: >
3161 :echo flatten([1, [2, [3, 4]], 5])
3162< [1, 2, 3, 4, 5] >
3163 :echo flatten([1, [2, [3, 4]], 5], 1)
3164< [1, 2, [3, 4], 5]
3165
3166 Can also be used as a |method|: >
3167 mylist->flatten()
3168<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003169 Return type: list<{type}>
3170
3171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003172flattennew({list} [, {maxdepth}]) *flattennew()*
3173 Like |flatten()| but first make a copy of {list}.
3174
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003175 Return type: list<{type}>
3176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003177
3178float2nr({expr}) *float2nr()*
3179 Convert {expr} to a Number by omitting the part after the
3180 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003181 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003182 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183 When the value of {expr} is out of range for a |Number| the
3184 result is truncated to 0x7fffffff or -0x7fffffff (or when
3185 64-bit Number support is enabled, 0x7fffffffffffffff or
3186 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3187 64-bit Number support is enabled, -0x8000000000000000).
3188 Examples: >
3189 echo float2nr(3.95)
3190< 3 >
3191 echo float2nr(-23.45)
3192< -23 >
3193 echo float2nr(1.0e100)
3194< 2147483647 (or 9223372036854775807) >
3195 echo float2nr(-1.0e150)
3196< -2147483647 (or -9223372036854775807) >
3197 echo float2nr(1.0e-100)
3198< 0
3199
3200 Can also be used as a |method|: >
3201 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003202<
3203 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003204
3205
3206floor({expr}) *floor()*
3207 Return the largest integral value less than or equal to
3208 {expr} as a |Float| (round down).
3209 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003210 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003211 Examples: >
3212 echo floor(1.856)
3213< 1.0 >
3214 echo floor(-5.456)
3215< -6.0 >
3216 echo floor(4.0)
3217< 4.0
3218
3219 Can also be used as a |method|: >
3220 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003221<
3222 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003223
3224
3225fmod({expr1}, {expr2}) *fmod()*
3226 Return the remainder of {expr1} / {expr2}, even if the
3227 division is not representable. Returns {expr1} - i * {expr2}
3228 for some integer i such that if {expr2} is non-zero, the
3229 result has the same sign as {expr1} and magnitude less than
3230 the magnitude of {expr2}. If {expr2} is zero, the value
3231 returned is zero. The value returned is a |Float|.
3232 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003233 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3234 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003235 Examples: >
3236 :echo fmod(12.33, 1.22)
3237< 0.13 >
3238 :echo fmod(-12.33, 1.22)
3239< -0.13
3240
3241 Can also be used as a |method|: >
3242 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003243<
3244 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003245
3246
3247fnameescape({string}) *fnameescape()*
3248 Escape {string} for use as file name command argument. All
3249 characters that have a special meaning, such as '%' and '|'
3250 are escaped with a backslash.
3251 For most systems the characters escaped are
3252 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3253 appears in a filename, it depends on the value of 'isfname'.
3254 A leading '+' and '>' is also escaped (special after |:edit|
3255 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003256 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003257 Example: >
3258 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003259 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003260< results in executing: >
3261 edit \+some\ str\%nge\|name
3262<
3263 Can also be used as a |method|: >
3264 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003265<
3266 Return type: |String|
3267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268
3269fnamemodify({fname}, {mods}) *fnamemodify()*
3270 Modify file name {fname} according to {mods}. {mods} is a
3271 string of characters like it is used for file names on the
3272 command line. See |filename-modifiers|.
3273 Example: >
3274 :echo fnamemodify("main.c", ":p:h")
3275< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003276 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003277< If {mods} is empty or an unsupported modifier is used then
3278 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003279 When {fname} is empty then with {mods} ":h" returns ".", so
3280 that `:cd` can be used with it. This is different from
3281 expand('%:h') without a buffer name, which returns an empty
3282 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003283 Note: Environment variables don't work in {fname}, use
3284 |expand()| first then.
3285
3286 Can also be used as a |method|: >
3287 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003288<
3289 Return type: |String|
3290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003291
3292foldclosed({lnum}) *foldclosed()*
3293 The result is a Number. If the line {lnum} is in a closed
3294 fold, the result is the number of the first line in that fold.
3295 If the line {lnum} is not in a closed fold, -1 is returned.
3296 {lnum} is used like with |getline()|. Thus "." is the current
3297 line, "'m" mark m, etc.
3298
3299 Can also be used as a |method|: >
3300 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003301<
3302 Return type: |Number|
3303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003304
3305foldclosedend({lnum}) *foldclosedend()*
3306 The result is a Number. If the line {lnum} is in a closed
3307 fold, the result is the number of the last line in that fold.
3308 If the line {lnum} is not in a closed fold, -1 is returned.
3309 {lnum} is used like with |getline()|. Thus "." is the current
3310 line, "'m" mark m, etc.
3311
3312 Can also be used as a |method|: >
3313 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003314<
3315 Return type: |Number|
3316
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003317
3318foldlevel({lnum}) *foldlevel()*
3319 The result is a Number, which is the foldlevel of line {lnum}
3320 in the current buffer. For nested folds the deepest level is
3321 returned. If there is no fold at line {lnum}, zero is
3322 returned. It doesn't matter if the folds are open or closed.
3323 When used while updating folds (from 'foldexpr') -1 is
3324 returned for lines where folds are still to be updated and the
3325 foldlevel is unknown. As a special case the level of the
3326 previous line is usually available.
3327 {lnum} is used like with |getline()|. Thus "." is the current
3328 line, "'m" mark m, etc.
3329
3330 Can also be used as a |method|: >
3331 GetLnum()->foldlevel()
3332<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003333 Return type: |Number|
3334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003335 *foldtext()*
3336foldtext() Returns a String, to be displayed for a closed fold. This is
3337 the default function used for the 'foldtext' option and should
3338 only be called from evaluating 'foldtext'. It uses the
3339 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3340 The returned string looks like this: >
3341 +-- 45 lines: abcdef
3342< The number of leading dashes depends on the foldlevel. The
3343 "45" is the number of lines in the fold. "abcdef" is the text
3344 in the first non-blank line of the fold. Leading white space,
3345 "//" or "/*" and the text from the 'foldmarker' and
3346 'commentstring' options is removed.
3347 When used to draw the actual foldtext, the rest of the line
3348 will be filled with the fold char from the 'fillchars'
3349 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003350 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003351
3352 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003353 {not available when compiled without the |+folding| feature}
3354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003356foldtextresult({lnum}) *foldtextresult()*
3357 Returns the text that is displayed for the closed fold at line
3358 {lnum}. Evaluates 'foldtext' in the appropriate context.
3359 When there is no closed fold at {lnum} an empty string is
3360 returned.
3361 {lnum} is used like with |getline()|. Thus "." is the current
3362 line, "'m" mark m, etc.
3363 Useful when exporting folded text, e.g., to HTML.
3364 {not available when compiled without the |+folding| feature}
3365
3366
3367 Can also be used as a |method|: >
3368 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003369<
3370 Return type: |String|
3371
Ernie Raele79e2072024-01-13 11:47:33 +01003372
3373foreach({expr1}, {expr2}) *foreach()*
3374 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3375 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003376 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003377 See |map()| and |filter()| to modify {expr1}.
3378
3379 {expr2} must be a |string| or |Funcref|.
3380
3381 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3382 of the current item. For a |Dictionary| |v:key| has the key
3383 of the current item and for a |List| |v:key| has the index of
3384 the current item. For a |Blob| |v:key| has the index of the
3385 current byte. For a |String| |v:key| has the index of the
3386 current character.
3387 Examples: >
3388 call foreach(mylist, 'used[v:val] = true')
3389< This records the items that are in the {expr1} list.
3390
3391 Note that {expr2} is the result of expression and is then used
3392 as a command. Often it is good to use a |literal-string| to
3393 avoid having to double backslashes.
3394
3395 If {expr2} is a |Funcref| it must take two arguments:
3396 1. the key or the index of the current item.
3397 2. the value of the current item.
3398 With a legacy script lambda you don't get an error if it only
3399 accepts one argument, but with a Vim9 lambda you get "E1106:
3400 One argument too many", the number of arguments must match.
3401 If the function returns a value, it is ignored.
3402
3403 Returns {expr1} in all cases.
3404 When an error is encountered while executing {expr2} no
3405 further items in {expr1} are processed.
3406 When {expr2} is a Funcref errors inside a function are ignored,
3407 unless it was defined with the "abort" flag.
3408
3409 Can also be used as a |method|: >
3410 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003412 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3413 depending on {expr1}
3414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003415 *foreground()*
3416foreground() Move the Vim window to the foreground. Useful when sent from
3417 a client to a Vim server. |remote_send()|
3418 On Win32 systems this might not work, the OS does not always
3419 allow a window to bring itself to the foreground. Use
3420 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003421
3422 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003423 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003424 Win32 console version}
3425
Bram Moolenaaraa534142022-09-15 21:46:02 +01003426fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427 Get the full command name from a short abbreviated command
3428 name; see |20.2| for details on command abbreviations.
3429
3430 The string argument {name} may start with a `:` and can
3431 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003432 Returns an empty string if a command doesn't exist, if it's
3433 ambiguous (for user-defined commands) or cannot be shortened
3434 this way. |vim9-no-shorten|
3435
3436 Without the {vim9} argument uses the current script version.
3437 If {vim9} is present and FALSE then legacy script rules are
3438 used. When {vim9} is present and TRUE then Vim9 rules are
3439 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003440
3441 For example `fullcommand('s')`, `fullcommand('sub')`,
3442 `fullcommand(':%substitute')` all return "substitute".
3443
3444 Can also be used as a |method|: >
3445 GetName()->fullcommand()
3446<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003447 Return type: |String|
3448
3449
3450funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451 Just like |function()|, but the returned Funcref will lookup
3452 the function by reference, not by name. This matters when the
3453 function {name} is redefined later.
3454
3455 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003456 It only works for an autoloaded function if it has already
3457 been loaded (to avoid mistakenly loading the autoload script
3458 when only intending to use the function name, use |function()|
3459 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003460 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003461
3462 Can also be used as a |method|: >
3463 GetFuncname()->funcref([arg])
3464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003465 Return type: func(...): any or |Number| on error
3466
Dominique Pellee764d1b2023-03-12 21:20:59 +00003467 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003468function({name} [, {arglist}] [, {dict}])
3469 Return a |Funcref| variable that refers to function {name}.
3470 {name} can be the name of a user defined function or an
3471 internal function.
3472
3473 {name} can also be a Funcref or a partial. When it is a
3474 partial the dict stored in it will be used and the {dict}
3475 argument is not allowed. E.g.: >
3476 let FuncWithArg = function(dict.Func, [arg])
3477 let Broken = function(dict.Func, [arg], dict)
3478<
3479 When using the Funcref the function will be found by {name},
3480 also when it was redefined later. Use |funcref()| to keep the
3481 same function.
3482
3483 When {arglist} or {dict} is present this creates a partial.
3484 That means the argument list and/or the dictionary is stored in
3485 the Funcref and will be used when the Funcref is called.
3486
3487 The arguments are passed to the function in front of other
3488 arguments, but after any argument from |method|. Example: >
3489 func Callback(arg1, arg2, name)
3490 ...
3491 let Partial = function('Callback', ['one', 'two'])
3492 ...
3493 call Partial('name')
3494< Invokes the function as with: >
3495 call Callback('one', 'two', 'name')
3496
3497< With a |method|: >
3498 func Callback(one, two, three)
3499 ...
3500 let Partial = function('Callback', ['two'])
3501 ...
3502 eval 'one'->Partial('three')
3503< Invokes the function as with: >
3504 call Callback('one', 'two', 'three')
3505
3506< The function() call can be nested to add more arguments to the
3507 Funcref. The extra arguments are appended to the list of
3508 arguments. Example: >
3509 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003510 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003511 let Func = function('Callback', ['one'])
3512 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003513 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 call Func2('name')
3515< Invokes the function as with: >
3516 call Callback('one', 'two', 'name')
3517
3518< The Dictionary is only useful when calling a "dict" function.
3519 In that case the {dict} is passed in as "self". Example: >
3520 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003521 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003523 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003524 let context = {"name": "example"}
3525 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003526 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003527 call Func() " will echo: called for example
3528< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003529 arguments, these two are equivalent, if Callback() is defined
3530 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003531 let Func = function('Callback', context)
3532 let Func = context.Callback
3533
3534< The argument list and the Dictionary can be combined: >
3535 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003536 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003537 let context = {"name": "example"}
3538 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003539 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003540 call Func(500)
3541< Invokes the function as with: >
3542 call context.Callback('one', 500)
3543<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003544 Returns 0 on error.
3545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003546 Can also be used as a |method|: >
3547 GetFuncname()->function([arg])
3548
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003549<
3550 Return type: func(...): any or |Number| on error
3551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003552
3553garbagecollect([{atexit}]) *garbagecollect()*
3554 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3555 that have circular references.
3556
3557 There is hardly ever a need to invoke this function, as it is
3558 automatically done when Vim runs out of memory or is waiting
3559 for the user to press a key after 'updatetime'. Items without
3560 circular references are always freed when they become unused.
3561 This is useful if you have deleted a very big |List| and/or
3562 |Dictionary| with circular references in a script that runs
3563 for a long time.
3564
3565 When the optional {atexit} argument is one, garbage
3566 collection will also be done when exiting Vim, if it wasn't
3567 done before. This is useful when checking for memory leaks.
3568
3569 The garbage collection is not done immediately but only when
3570 it's safe to perform. This is when waiting for the user to
3571 type a character. To force garbage collection immediately use
3572 |test_garbagecollect_now()|.
3573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003574 Return type: |String|
3575
3576
LemonBoy48b7d052024-07-09 18:24:59 +02003577get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003578 Get item {idx} from |List| {list}. When this item is not
3579 available return {default}. Return zero when {default} is
3580 omitted.
3581 Preferably used as a |method|: >
3582 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003583<
3584 Return type: any, depending on {list}
3585
LemonBoy48b7d052024-07-09 18:24:59 +02003586get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003587 Get byte {idx} from |Blob| {blob}. When this byte is not
3588 available return {default}. Return -1 when {default} is
3589 omitted.
3590 Preferably used as a |method|: >
3591 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003592<
3593 Return type: |Number|
3594
LemonBoy48b7d052024-07-09 18:24:59 +02003595get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003596 Get item with key {key} from |Dictionary| {dict}. When this
3597 item is not available return {default}. Return zero when
3598 {default} is omitted. Useful example: >
3599 let val = get(g:, 'var_name', 'default')
3600< This gets the value of g:var_name if it exists, and uses
3601 'default' when it does not exist.
3602 Preferably used as a |method|: >
3603 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003604<
h-east84ac2122024-06-17 18:12:30 +02003605 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003606
LemonBoy48b7d052024-07-09 18:24:59 +02003607get({func}, {what}) *get()-func*
3608 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003609 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003610 "name" The function name
3611 "func" The function
3612 "dict" The dictionary
3613 "args" The list with arguments
3614 "arity" A dictionary with information about the number of
3615 arguments accepted by the function (minus the
3616 {arglist}) with the following fields:
3617 required the number of positional arguments
3618 optional the number of optional arguments,
3619 in addition to the required ones
3620 varargs |TRUE| if the function accepts a
3621 variable number of arguments |...|
3622
3623 Note: There is no error, if the {arglist} of
3624 the Funcref contains more arguments than the
3625 Funcref expects, it's not validated.
3626
Bram Moolenaar016188f2022-06-06 20:52:59 +01003627 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003628
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003629 Preferably used as a |method|: >
3630 myfunc->get(what)
3631<
LemonBoy48b7d052024-07-09 18:24:59 +02003632 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003634 *getbufinfo()*
3635getbufinfo([{buf}])
3636getbufinfo([{dict}])
3637 Get information about buffers as a List of Dictionaries.
3638
3639 Without an argument information about all the buffers is
3640 returned.
3641
3642 When the argument is a |Dictionary| only the buffers matching
3643 the specified criteria are returned. The following keys can
3644 be specified in {dict}:
3645 buflisted include only listed buffers.
3646 bufloaded include only loaded buffers.
3647 bufmodified include only modified buffers.
3648
3649 Otherwise, {buf} specifies a particular buffer to return
3650 information for. For the use of {buf}, see |bufname()|
3651 above. If the buffer is found the returned List has one item.
3652 Otherwise the result is an empty list.
3653
3654 Each returned List item is a dictionary with the following
3655 entries:
3656 bufnr Buffer number.
3657 changed TRUE if the buffer is modified.
3658 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003659 command TRUE if the buffer belongs to the
3660 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003661 hidden TRUE if the buffer is hidden.
3662 lastused Timestamp in seconds, like
3663 |localtime()|, when the buffer was
3664 last used.
3665 {only with the |+viminfo| feature}
3666 listed TRUE if the buffer is listed.
3667 lnum Line number used for the buffer when
3668 opened in the current window.
3669 Only valid if the buffer has been
3670 displayed in the window in the past.
3671 If you want the line number of the
3672 last known cursor position in a given
3673 window, use |line()|: >
3674 :echo line('.', {winid})
3675<
3676 linecount Number of lines in the buffer (only
3677 valid when loaded)
3678 loaded TRUE if the buffer is loaded.
3679 name Full path to the file in the buffer.
3680 signs List of signs placed in the buffer.
3681 Each list item is a dictionary with
3682 the following fields:
3683 id sign identifier
3684 lnum line number
3685 name sign name
3686 variables A reference to the dictionary with
3687 buffer-local variables.
3688 windows List of |window-ID|s that display this
3689 buffer
3690 popups List of popup |window-ID|s that
3691 display this buffer
3692
3693 Examples: >
3694 for buf in getbufinfo()
3695 echo buf.name
3696 endfor
3697 for buf in getbufinfo({'buflisted':1})
3698 if buf.changed
3699 ....
3700 endif
3701 endfor
3702<
3703 To get buffer-local options use: >
3704 getbufvar({bufnr}, '&option_name')
3705<
3706 Can also be used as a |method|: >
3707 GetBufnr()->getbufinfo()
3708<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003709 Return type: list<dict<any>>
3710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003711
3712 *getbufline()*
3713getbufline({buf}, {lnum} [, {end}])
3714 Return a |List| with the lines starting from {lnum} to {end}
3715 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003716 |List| with only the line {lnum} is returned. See
3717 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003718
3719 For the use of {buf}, see |bufname()| above.
3720
3721 For {lnum} and {end} "$" can be used for the last line of the
3722 buffer. Otherwise a number must be used.
3723
3724 When {lnum} is smaller than 1 or bigger than the number of
3725 lines in the buffer, an empty |List| is returned.
3726
3727 When {end} is greater than the number of lines in the buffer,
3728 it is treated as {end} is set to the number of lines in the
3729 buffer. When {end} is before {lnum} an empty |List| is
3730 returned.
3731
3732 This function works only for loaded buffers. For unloaded and
3733 non-existing buffers, an empty |List| is returned.
3734
3735 Example: >
3736 :let lines = getbufline(bufnr("myfile"), 1, "$")
3737
3738< Can also be used as a |method|: >
3739 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003740<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003741 Return type: list<string>
3742
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003743 *getbufoneline()*
3744getbufoneline({buf}, {lnum})
3745 Just like `getbufline()` but only get one line and return it
3746 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003747
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003748 Return type: |String|
3749
3750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003751getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3752 The result is the value of option or local buffer variable
3753 {varname} in buffer {buf}. Note that the name without "b:"
3754 must be used.
3755 The {varname} argument is a string.
3756 When {varname} is empty returns a |Dictionary| with all the
3757 buffer-local variables.
3758 When {varname} is equal to "&" returns a |Dictionary| with all
3759 the buffer-local options.
3760 Otherwise, when {varname} starts with "&" returns the value of
3761 a buffer-local option.
3762 This also works for a global or buffer-local option, but it
3763 doesn't work for a global variable, window-local variable or
3764 window-local option.
3765 For the use of {buf}, see |bufname()| above.
3766 When the buffer or variable doesn't exist {def} or an empty
3767 string is returned, there is no error message.
3768 Examples: >
3769 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003770 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003771
3772< Can also be used as a |method|: >
3773 GetBufnr()->getbufvar(varname)
3774<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003775 Return type: any, depending on {varname}
3776
3777
Kota Kato66bb9ae2023-01-17 18:31:56 +00003778getcellwidths() *getcellwidths()*
3779 Returns a |List| of cell widths of character ranges overridden
3780 by |setcellwidths()|. The format is equal to the argument of
3781 |setcellwidths()|. If no character ranges have their cell
3782 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003783
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003784 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003785
3786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003787getchangelist([{buf}]) *getchangelist()*
3788 Returns the |changelist| for the buffer {buf}. For the use
3789 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3790 exist, an empty list is returned.
3791
3792 The returned list contains two entries: a list with the change
3793 locations and the current position in the list. Each
3794 entry in the change list is a dictionary with the following
3795 entries:
3796 col column number
3797 coladd column offset for 'virtualedit'
3798 lnum line number
3799 If buffer {buf} is the current buffer, then the current
3800 position refers to the position in the list. For other
3801 buffers, it is set to the length of the list.
3802
3803 Can also be used as a |method|: >
3804 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003805<
3806 Return type: list<any>
3807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003808
Doug Kearns9cd9e752024-04-07 17:42:17 +02003809getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003810 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003811 If {expr} is omitted, wait until a character is available.
3812 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003813 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003814 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003815 not consumed. Return zero if no character available.
3816 If you prefer always getting a string use |getcharstr()|.
3817
Doug Kearns9cd9e752024-04-07 17:42:17 +02003818 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003819 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003820 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003821 Otherwise a String is returned with the encoded character.
3822 For a special key it's a String with a sequence of bytes
3823 starting with 0x80 (decimal: 128). This is the same value as
3824 the String "\<Key>", e.g., "\<Left>". The returned value is
3825 also a String when a modifier (shift, control, alt) was used
3826 that is not included in the character.
3827
Doug Kearns9cd9e752024-04-07 17:42:17 +02003828 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003829 while Vim waits to see if this is the start of an escape
3830 sequence.
3831
Doug Kearns9cd9e752024-04-07 17:42:17 +02003832 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003833 one-byte character it is the character itself as a number.
3834 Use nr2char() to convert it to a String.
3835
3836 Use getcharmod() to obtain any additional modifiers.
3837
3838 When the user clicks a mouse button, the mouse event will be
3839 returned. The position can then be found in |v:mouse_col|,
3840 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3841 |getmousepos()| can also be used. Mouse move events will be
3842 ignored.
3843 This example positions the mouse as it would normally happen: >
3844 let c = getchar()
3845 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003846 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003847 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003848 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003849 endif
3850<
3851 When using bracketed paste only the first character is
3852 returned, the rest of the pasted text is dropped.
3853 |xterm-bracketed-paste|.
3854
3855 There is no prompt, you will somehow have to make clear to the
3856 user that a character has to be typed. The screen is not
3857 redrawn, e.g. when resizing the window. When using a popup
3858 window it should work better with a |popup-filter|.
3859
3860 There is no mapping for the character.
3861 Key codes are replaced, thus when the user presses the <Del>
3862 key you get the code for the <Del> key, not the raw character
3863 sequence. Examples: >
3864 getchar() == "\<Del>"
3865 getchar() == "\<S-Left>"
3866< This example redefines "f" to ignore case: >
3867 :nmap f :call FindChar()<CR>
3868 :function FindChar()
3869 : let c = nr2char(getchar())
3870 : while col('.') < col('$') - 1
3871 : normal l
3872 : if getline('.')[col('.') - 1] ==? c
3873 : break
3874 : endif
3875 : endwhile
3876 :endfunction
3877<
3878 You may also receive synthetic characters, such as
3879 |<CursorHold>|. Often you will want to ignore this and get
3880 another character: >
3881 :function GetKey()
3882 : let c = getchar()
3883 : while c == "\<CursorHold>"
3884 : let c = getchar()
3885 : endwhile
3886 : return c
3887 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003888<
3889 Return type: |Number| or |String|
3890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003891
3892getcharmod() *getcharmod()*
3893 The result is a Number which is the state of the modifiers for
3894 the last obtained character with getchar() or in another way.
3895 These values are added together:
3896 2 shift
3897 4 control
3898 8 alt (meta)
3899 16 meta (when it's different from ALT)
3900 32 mouse double click
3901 64 mouse triple click
3902 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003903 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003904 Only the modifiers that have not been included in the
3905 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003906 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003907
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003908 Return type: |Number|
3909
3910
3911getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003912 Get the position for String {expr}. Same as |getpos()| but the
3913 column number in the returned List is a character index
3914 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003915 If |getpos()| returns a very large column number, equal to
3916 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003917 of the last character.
3918
3919 Example:
3920 With the cursor on '세' in line 5 with text "여보세요": >
3921 getcharpos('.') returns [0, 5, 3, 0]
3922 getpos('.') returns [0, 5, 7, 0]
3923<
3924 Can also be used as a |method|: >
3925 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003926<
3927 Return type: list<number>
3928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003929
3930getcharsearch() *getcharsearch()*
3931 Return the current character search information as a {dict}
3932 with the following entries:
3933
3934 char character previously used for a character
3935 search (|t|, |f|, |T|, or |F|); empty string
3936 if no character search has been performed
3937 forward direction of character search; 1 for forward,
3938 0 for backward
3939 until type of character search; 1 for a |t| or |T|
3940 character search, 0 for an |f| or |F|
3941 character search
3942
3943 This can be useful to always have |;| and |,| search
3944 forward/backward regardless of the direction of the previous
3945 character search: >
3946 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3947 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3948< Also see |setcharsearch()|.
3949
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003950 Return type: dict<any>
3951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003952
Doug Kearns9cd9e752024-04-07 17:42:17 +02003953getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003954 Get a single character from the user or input stream as a
3955 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003956 If {expr} is omitted, wait until a character is available.
3957 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003958 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003959 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003960 available, it is not consumed. Return an empty string
3961 if no character is available.
3962 Otherwise this works like |getchar()|, except that a number
3963 result is converted to a string.
3964
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003965 Return type: |String|
3966
3967
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003968getcmdcompltype() *getcmdcompltype()*
3969 Return the type of the current command-line completion.
3970 Only works when the command line is being edited, thus
3971 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003972 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003973 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3974 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003975 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003976
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003977 Return type: |String|
3978
3979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003980getcmdline() *getcmdline()*
3981 Return the current command-line. Only works when the command
3982 line is being edited, thus requires use of |c_CTRL-\_e| or
3983 |c_CTRL-R_=|.
3984 Example: >
3985 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003986< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3987 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003988 Returns an empty string when entering a password or using
3989 |inputsecret()|.
3990
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003991 Return type: |String|
3992
3993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003994getcmdpos() *getcmdpos()*
3995 Return the position of the cursor in the command line as a
3996 byte count. The first column is 1.
3997 Only works when editing the command line, thus requires use of
3998 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3999 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004000 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
4001 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004002
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004003 Return type: |Number|
4004
4005
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004006getcmdscreenpos() *getcmdscreenpos()*
4007 Return the screen position of the cursor in the command line
4008 as a byte count. The first column is 1.
4009 Instead of |getcmdpos()|, it adds the prompt position.
4010 Only works when editing the command line, thus requires use of
4011 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4012 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004013 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4014 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004015
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004016 Return type: |Number|
4017
4018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004019getcmdtype() *getcmdtype()*
4020 Return the current command-line type. Possible return values
4021 are:
4022 : normal Ex command
4023 > debug mode command |debug-mode|
4024 / forward search command
4025 ? backward search command
4026 @ |input()| command
4027 - |:insert| or |:append| command
4028 = |i_CTRL-R_=|
4029 Only works when editing the command line, thus requires use of
4030 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4031 Returns an empty string otherwise.
4032 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004034 Return type: |String|
4035
4036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004037getcmdwintype() *getcmdwintype()*
4038 Return the current |command-line-window| type. Possible return
4039 values are the same as |getcmdtype()|. Returns an empty string
4040 when not in the command-line window.
4041
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004042 Return type: |String|
4043
4044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004045getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4046 Return a list of command-line completion matches. The String
4047 {type} argument specifies what for. The following completion
4048 types are supported:
4049
4050 arglist file names in argument list
4051 augroup autocmd groups
4052 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004053 behave |:behave| suboptions
4054 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004055 color color schemes
4056 command Ex command
4057 cmdline |cmdline-completion| result
4058 compiler compilers
4059 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004060 custom,{func} custom completion, defined via {func}
4061 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004062 diff_buffer |:diffget| and |:diffput| completion
4063 dir directory names
4064 environment environment variable names
4065 event autocommand events
4066 expression Vim expression
4067 file file and directory names
4068 file_in_path file and directory names in |'path'|
4069 filetype filetype names |'filetype'|
4070 function function name
4071 help help subjects
4072 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004073 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004074 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004075 locale locale names (as output of locale -a)
4076 mapclear buffer argument
4077 mapping mapping name
4078 menu menus
4079 messages |:messages| suboptions
4080 option options
4081 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004082 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004083 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004084 shellcmd Shell command
4085 sign |:sign| suboptions
4086 syntax syntax file names |'syntax'|
4087 syntime |:syntime| suboptions
4088 tag tags
4089 tag_listfiles tags, file names
4090 user user names
4091 var user variables
4092
4093 If {pat} is an empty string, then all the matches are
4094 returned. Otherwise only items matching {pat} are returned.
4095 See |wildcards| for the use of special characters in {pat}.
4096
4097 If the optional {filtered} flag is set to 1, then 'wildignore'
4098 is applied to filter the results. Otherwise all the matches
4099 are returned. The 'wildignorecase' option always applies.
4100
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004101 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4102 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004103 regular expression matching is used. Thus this function
4104 follows the user preference, what happens on the command line.
4105 If you do not want this you can make 'wildoptions' empty
4106 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004108 If {type} is "cmdline", then the |cmdline-completion| result is
4109 returned. For example, to complete the possible values after
4110 a ":call" command: >
4111 echo getcompletion('call ', 'cmdline')
4112<
4113 If there are no matches, an empty list is returned. An
4114 invalid value for {type} produces an error.
4115
4116 Can also be used as a |method|: >
4117 GetPattern()->getcompletion('color')
4118<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004119 Return type: list<string>
4120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004121 *getcurpos()*
4122getcurpos([{winid}])
4123 Get the position of the cursor. This is like getpos('.'), but
4124 includes an extra "curswant" item in the list:
4125 [0, lnum, col, off, curswant] ~
4126 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004127 cursor vertically. After |$| command it will be a very large
4128 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004129 |getpos()|.
4130 The first "bufnum" item is always zero. The byte position of
4131 the cursor is returned in 'col'. To get the character
4132 position, use |getcursorcharpos()|.
4133
4134 The optional {winid} argument can specify the window. It can
4135 be the window number or the |window-ID|. The last known
4136 cursor position is returned, this may be invalid for the
4137 current value of the buffer if it is not the current window.
4138 If {winid} is invalid a list with zeroes is returned.
4139
4140 This can be used to save and restore the cursor position: >
4141 let save_cursor = getcurpos()
4142 MoveTheCursorAround
4143 call setpos('.', save_cursor)
4144< Note that this only works within the window. See
4145 |winrestview()| for restoring more state.
4146
4147 Can also be used as a |method|: >
4148 GetWinid()->getcurpos()
4149<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004150 Return type: list<number>
4151
4152
4153getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004154 Same as |getcurpos()| but the column number in the returned
4155 List is a character index instead of a byte index.
4156
4157 Example:
4158 With the cursor on '보' in line 3 with text "여보세요": >
4159 getcursorcharpos() returns [0, 3, 2, 0, 3]
4160 getcurpos() returns [0, 3, 4, 0, 3]
4161<
4162 Can also be used as a |method|: >
4163 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004164<
4165 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004166
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004167
4168getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004169 The result is a String, which is the name of the current
4170 working directory. 'autochdir' is ignored.
4171
4172 With {winnr} return the local current directory of this window
4173 in the current tab page. {winnr} can be the window number or
4174 the |window-ID|.
4175 If {winnr} is -1 return the name of the global working
4176 directory. See also |haslocaldir()|.
4177
4178 With {winnr} and {tabnr} return the local current directory of
4179 the window in the specified tab page. If {winnr} is -1 return
4180 the working directory of the tabpage.
4181 If {winnr} is zero use the current window, if {tabnr} is zero
4182 use the current tabpage.
4183 Without any arguments, return the actual working directory of
4184 the current window.
4185 Return an empty string if the arguments are invalid.
4186
4187 Examples: >
4188 " Get the working directory of the current window
4189 :echo getcwd()
4190 :echo getcwd(0)
4191 :echo getcwd(0, 0)
4192 " Get the working directory of window 3 in tabpage 2
4193 :echo getcwd(3, 2)
4194 " Get the global working directory
4195 :echo getcwd(-1)
4196 " Get the working directory of tabpage 3
4197 :echo getcwd(-1, 3)
4198 " Get the working directory of current tabpage
4199 :echo getcwd(-1, 0)
4200
4201< Can also be used as a |method|: >
4202 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004203<
4204 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004205
4206getenv({name}) *getenv()*
4207 Return the value of environment variable {name}. The {name}
4208 argument is a string, without a leading '$'. Example: >
4209 myHome = getenv('HOME')
4210
4211< When the variable does not exist |v:null| is returned. That
4212 is different from a variable set to an empty string, although
4213 some systems interpret the empty value as the variable being
4214 deleted. See also |expr-env|.
4215
4216 Can also be used as a |method|: >
4217 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004218<
4219 Return type: |String| or |Number|
4220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004221
4222getfontname([{name}]) *getfontname()*
4223 Without an argument returns the name of the normal font being
4224 used. Like what is used for the Normal highlight group
4225 |hl-Normal|.
4226 With an argument a check is done whether String {name} is a
4227 valid font name. If not then an empty string is returned.
4228 Otherwise the actual font name is returned, or {name} if the
4229 GUI does not support obtaining the real name.
4230 Only works when the GUI is running, thus not in your vimrc or
4231 gvimrc file. Use the |GUIEnter| autocommand to use this
4232 function just after the GUI has started.
4233 Note that the GTK GUI accepts any font name, thus checking for
4234 a valid name does not work.
4235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004236 Return type: |String|
4237
4238
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004239getfperm({fname}) *getfperm()*
4240 The result is a String, which is the read, write, and execute
4241 permissions of the given file {fname}.
4242 If {fname} does not exist or its directory cannot be read, an
4243 empty string is returned.
4244 The result is of the form "rwxrwxrwx", where each group of
4245 "rwx" flags represent, in turn, the permissions of the owner
4246 of the file, the group the file belongs to, and other users.
4247 If a user does not have a given permission the flag for this
4248 is replaced with the string "-". Examples: >
4249 :echo getfperm("/etc/passwd")
4250 :echo getfperm(expand("~/.vimrc"))
4251< This will hopefully (from a security point of view) display
4252 the string "rw-r--r--" or even "rw-------".
4253
4254 Can also be used as a |method|: >
4255 GetFilename()->getfperm()
4256<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004257 Return type: |String|
4258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004259 For setting permissions use |setfperm()|.
4260
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004262getfsize({fname}) *getfsize()*
4263 The result is a Number, which is the size in bytes of the
4264 given file {fname}.
4265 If {fname} is a directory, 0 is returned.
4266 If the file {fname} can't be found, -1 is returned.
4267 If the size of {fname} is too big to fit in a Number then -2
4268 is returned.
4269
4270 Can also be used as a |method|: >
4271 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004272<
4273 Return type: |Number|
4274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004275
4276getftime({fname}) *getftime()*
4277 The result is a Number, which is the last modification time of
4278 the given file {fname}. The value is measured as seconds
4279 since 1st Jan 1970, and may be passed to strftime(). See also
4280 |localtime()| and |strftime()|.
4281 If the file {fname} can't be found -1 is returned.
4282
4283 Can also be used as a |method|: >
4284 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004285<
4286 Return type: |Number|
4287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004288
4289getftype({fname}) *getftype()*
4290 The result is a String, which is a description of the kind of
4291 file of the given file {fname}.
4292 If {fname} does not exist an empty string is returned.
4293 Here is a table over different kinds of files and their
4294 results:
4295 Normal file "file"
4296 Directory "dir"
4297 Symbolic link "link"
4298 Block device "bdev"
4299 Character device "cdev"
4300 Socket "socket"
4301 FIFO "fifo"
4302 All other "other"
4303 Example: >
4304 getftype("/home")
4305< Note that a type such as "link" will only be returned on
4306 systems that support it. On some systems only "dir" and
4307 "file" are returned. On MS-Windows a symbolic link to a
4308 directory returns "dir" instead of "link".
4309
4310 Can also be used as a |method|: >
4311 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004312<
4313 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004314
4315getimstatus() *getimstatus()*
4316 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004317 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004318 See 'imstatusfunc'.
4319
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004320 Return type: |Number|
4321
4322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004323getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4324 Returns the |jumplist| for the specified window.
4325
4326 Without arguments use the current window.
4327 With {winnr} only use this window in the current tab page.
4328 {winnr} can also be a |window-ID|.
4329 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004330 page. If {winnr} or {tabnr} is invalid, an empty list is
4331 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004332
4333 The returned list contains two entries: a list with the jump
4334 locations and the last used jump position number in the list.
4335 Each entry in the jump location list is a dictionary with
4336 the following entries:
4337 bufnr buffer number
4338 col column number
4339 coladd column offset for 'virtualedit'
4340 filename filename if available
4341 lnum line number
4342
4343 Can also be used as a |method|: >
4344 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004345<
4346 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004347
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004348 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004349getline({lnum} [, {end}])
4350 Without {end} the result is a String, which is line {lnum}
4351 from the current buffer. Example: >
4352 getline(1)
4353< When {lnum} is a String that doesn't start with a
4354 digit, |line()| is called to translate the String into a Number.
4355 To get the line under the cursor: >
4356 getline(".")
4357< When {lnum} is a number smaller than 1 or bigger than the
4358 number of lines in the buffer, an empty string is returned.
4359
4360 When {end} is given the result is a |List| where each item is
4361 a line from the current buffer in the range {lnum} to {end},
4362 including line {end}.
4363 {end} is used in the same way as {lnum}.
4364 Non-existing lines are silently omitted.
4365 When {end} is before {lnum} an empty |List| is returned.
4366 Example: >
4367 :let start = line('.')
4368 :let end = search("^$") - 1
4369 :let lines = getline(start, end)
4370
4371< Can also be used as a |method|: >
4372 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004373<
4374 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004375
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004376 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004377 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004378
4379getloclist({nr} [, {what}]) *getloclist()*
4380 Returns a |List| with all the entries in the location list for
4381 window {nr}. {nr} can be the window number or the |window-ID|.
4382 When {nr} is zero the current window is used.
4383
4384 For a location list window, the displayed location list is
4385 returned. For an invalid window number {nr}, an empty list is
4386 returned. Otherwise, same as |getqflist()|.
4387
4388 If the optional {what} dictionary argument is supplied, then
4389 returns the items listed in {what} as a dictionary. Refer to
4390 |getqflist()| for the supported items in {what}.
4391
4392 In addition to the items supported by |getqflist()| in {what},
4393 the following item is supported by |getloclist()|:
4394
4395 filewinid id of the window used to display files
4396 from the location list. This field is
4397 applicable only when called from a
4398 location list window. See
4399 |location-list-file-window| for more
4400 details.
4401
4402 Returns a |Dictionary| with default values if there is no
4403 location list for the window {nr}.
4404 Returns an empty Dictionary if window {nr} does not exist.
4405
4406 Examples (See also |getqflist-examples|): >
4407 :echo getloclist(3, {'all': 0})
4408 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004409<
4410 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004411
4412
4413getmarklist([{buf}]) *getmarklist()*
4414 Without the {buf} argument returns a |List| with information
4415 about all the global marks. |mark|
4416
4417 If the optional {buf} argument is specified, returns the
4418 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004419 see |bufname()|. If {buf} is invalid, an empty list is
4420 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004421
4422 Each item in the returned List is a |Dict| with the following:
4423 mark name of the mark prefixed by "'"
4424 pos a |List| with the position of the mark:
4425 [bufnum, lnum, col, off]
4426 Refer to |getpos()| for more information.
4427 file file name
4428
4429 Refer to |getpos()| for getting information about a specific
4430 mark.
4431
4432 Can also be used as a |method|: >
4433 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004434<
4435 Return type: list<dict<any>> or list<any>
4436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004437
4438getmatches([{win}]) *getmatches()*
4439 Returns a |List| with all matches previously defined for the
4440 current window by |matchadd()| and the |:match| commands.
4441 |getmatches()| is useful in combination with |setmatches()|,
4442 as |setmatches()| can restore a list of matches saved by
4443 |getmatches()|.
4444 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004445 window ID instead of the current window. If {win} is invalid,
4446 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004447 Example: >
4448 :echo getmatches()
4449< [{'group': 'MyGroup1', 'pattern': 'TODO',
4450 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4451 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4452 :let m = getmatches()
4453 :call clearmatches()
4454 :echo getmatches()
4455< [] >
4456 :call setmatches(m)
4457 :echo getmatches()
4458< [{'group': 'MyGroup1', 'pattern': 'TODO',
4459 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4460 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4461 :unlet m
4462<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004463 Return type: list<dict<any>> or list<any>
4464
4465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004466getmousepos() *getmousepos()*
4467 Returns a |Dictionary| with the last known position of the
4468 mouse. This can be used in a mapping for a mouse click or in
4469 a filter of a popup window. The items are:
4470 screenrow screen row
4471 screencol screen column
4472 winid Window ID of the click
4473 winrow row inside "winid"
4474 wincol column inside "winid"
4475 line text line inside "winid"
4476 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004477 coladd offset (in screen columns) from the
4478 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004479 All numbers are 1-based.
4480
4481 If not over a window, e.g. when in the command line, then only
4482 "screenrow" and "screencol" are valid, the others are zero.
4483
4484 When on the status line below a window or the vertical
4485 separator right of a window, the "line" and "column" values
4486 are zero.
4487
4488 When the position is after the text then "column" is the
4489 length of the text in bytes plus one.
4490
4491 If the mouse is over a popup window then that window is used.
4492
4493 When using |getchar()| the Vim variables |v:mouse_lnum|,
4494 |v:mouse_col| and |v:mouse_winid| also provide these values.
4495
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004496 Return type: dict<number>
4497
4498
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004499getmouseshape() *getmouseshape()*
4500 Returns the name of the currently showing mouse pointer.
4501 When the |+mouseshape| feature is not supported or the shape
4502 is unknown an empty string is returned.
4503 This function is mainly intended for testing.
4504
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004505 Return type: |String|
4506
4507
4508getpid() *getpid()*
4509 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004510 On Unix and MS-Windows this is a unique number, until Vim
4511 exits.
4512
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004513 Return type: |Number|
4514
4515
4516getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004517 Get the position for String {expr}.
4518 The accepted values for {expr} are: *E1209*
4519 . The cursor position.
4520 $ The last line in the current buffer.
4521 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004522 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004523 w0 First line visible in current window (one if the
4524 display isn't updated, e.g. in silent Ex mode).
4525 w$ Last line visible in current window (this is one
4526 less than "w0" if no lines are visible).
4527 v When not in Visual mode, returns the cursor
4528 position. In Visual mode, returns the other end
4529 of the Visual area. A good way to think about
4530 this is that in Visual mode "v" and "." complement
4531 each other. While "." refers to the cursor
4532 position, "v" refers to where |v_o| would move the
4533 cursor. As a result, you can use "v" and "."
4534 together to work on all of a selection in
4535 characterwise Visual mode. If the cursor is at
4536 the end of a characterwise Visual area, "v" refers
4537 to the start of the same Visual area. And if the
4538 cursor is at the start of a characterwise Visual
4539 area, "v" refers to the end of the same Visual
4540 area. "v" differs from |'<| and |'>| in that it's
4541 updated right away.
4542 Note that a mark in another file can be used. The line number
4543 then applies to another buffer.
4544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004545 The result is a |List| with four numbers:
4546 [bufnum, lnum, col, off]
4547 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4548 is the buffer number of the mark.
4549 "lnum" and "col" are the position in the buffer. The first
4550 column is 1.
4551 The "off" number is zero, unless 'virtualedit' is used. Then
4552 it is the offset in screen columns from the start of the
4553 character. E.g., a position within a <Tab> or after the last
4554 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004555
4556 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004557 The column number in the returned List is the byte position
4558 within the line. To get the character position in the line,
4559 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004560
4561 Note that for '< and '> Visual mode matters: when it is "V"
4562 (visual line mode) the column of '< is zero and the column of
4563 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004564 A very large column number equal to |v:maxcol| can be returned,
4565 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004566 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004568 This can be used to save and restore the position of a mark: >
4569 let save_a_mark = getpos("'a")
4570 ...
4571 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004572<
4573 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004574
4575 Can also be used as a |method|: >
4576 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004577<
4578 Return type: list<number>
4579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004580
4581getqflist([{what}]) *getqflist()*
4582 Returns a |List| with all the current quickfix errors. Each
4583 list item is a dictionary with these entries:
4584 bufnr number of buffer that has the file name, use
4585 bufname() to get the name
4586 module module name
4587 lnum line number in the buffer (first line is 1)
4588 end_lnum
4589 end of line number if the item is multiline
4590 col column number (first column is 1)
4591 end_col end of column number if the item has range
4592 vcol |TRUE|: "col" is visual column
4593 |FALSE|: "col" is byte index
4594 nr error number
h-east84ac2122024-06-17 18:12:30 +02004595 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004596 text description of the error
4597 type type of the error, 'E', '1', etc.
4598 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004599 user_data
4600 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004601 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004602
4603 When there is no error list or it's empty, an empty list is
4604 returned. Quickfix list entries with a non-existing buffer
4605 number are returned with "bufnr" set to zero (Note: some
4606 functions accept buffer number zero for the alternate buffer,
4607 you may need to explicitly check for zero).
4608
4609 Useful application: Find pattern matches in multiple files and
4610 do something with them: >
4611 :vimgrep /theword/jg *.c
4612 :for d in getqflist()
4613 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4614 :endfor
4615<
4616 If the optional {what} dictionary argument is supplied, then
4617 returns only the items listed in {what} as a dictionary. The
4618 following string items are supported in {what}:
4619 changedtick get the total number of changes made
4620 to the list |quickfix-changedtick|
4621 context get the |quickfix-context|
4622 efm errorformat to use when parsing "lines". If
4623 not present, then the 'errorformat' option
4624 value is used.
4625 id get information for the quickfix list with
4626 |quickfix-ID|; zero means the id for the
4627 current list or the list specified by "nr"
4628 idx get information for the quickfix entry at this
4629 index in the list specified by 'id' or 'nr'.
4630 If set to zero, then uses the current entry.
4631 See |quickfix-index|
4632 items quickfix list entries
4633 lines parse a list of lines using 'efm' and return
4634 the resulting entries. Only a |List| type is
4635 accepted. The current quickfix list is not
4636 modified. See |quickfix-parse|.
4637 nr get information for this quickfix list; zero
4638 means the current quickfix list and "$" means
4639 the last quickfix list
4640 qfbufnr number of the buffer displayed in the quickfix
4641 window. Returns 0 if the quickfix buffer is
4642 not present. See |quickfix-buffer|.
4643 size number of entries in the quickfix list
4644 title get the list title |quickfix-title|
4645 winid get the quickfix |window-ID|
4646 all all of the above quickfix properties
4647 Non-string items in {what} are ignored. To get the value of a
4648 particular item, set it to zero.
4649 If "nr" is not present then the current quickfix list is used.
4650 If both "nr" and a non-zero "id" are specified, then the list
4651 specified by "id" is used.
4652 To get the number of lists in the quickfix stack, set "nr" to
4653 "$" in {what}. The "nr" value in the returned dictionary
4654 contains the quickfix stack size.
4655 When "lines" is specified, all the other items except "efm"
4656 are ignored. The returned dictionary contains the entry
4657 "items" with the list of entries.
4658
4659 The returned dictionary contains the following entries:
4660 changedtick total number of changes made to the
4661 list |quickfix-changedtick|
4662 context quickfix list context. See |quickfix-context|
4663 If not present, set to "".
4664 id quickfix list ID |quickfix-ID|. If not
4665 present, set to 0.
4666 idx index of the quickfix entry in the list. If not
4667 present, set to 0.
4668 items quickfix list entries. If not present, set to
4669 an empty list.
4670 nr quickfix list number. If not present, set to 0
4671 qfbufnr number of the buffer displayed in the quickfix
4672 window. If not present, set to 0.
4673 size number of entries in the quickfix list. If not
4674 present, set to 0.
4675 title quickfix list title text. If not present, set
4676 to "".
4677 winid quickfix |window-ID|. If not present, set to 0
4678
4679 Examples (See also |getqflist-examples|): >
4680 :echo getqflist({'all': 1})
4681 :echo getqflist({'nr': 2, 'title': 1})
4682 :echo getqflist({'lines' : ["F1:10:L10"]})
4683<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004684 Return type: list<dict<any>> or list<any>
4685
4686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004687getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4688 The result is a String, which is the contents of register
4689 {regname}. Example: >
4690 :let cliptext = getreg('*')
4691< When register {regname} was not set the result is an empty
4692 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004693 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004694
4695 getreg('=') returns the last evaluated value of the expression
4696 register. (For use in maps.)
4697 getreg('=', 1) returns the expression itself, so that it can
4698 be restored with |setreg()|. For other registers the extra
4699 argument is ignored, thus you can always give it.
4700
4701 If {list} is present and |TRUE|, the result type is changed
4702 to |List|. Each list item is one text line. Use it if you care
4703 about zero bytes possibly present inside register: without
4704 third argument both NLs and zero bytes are represented as NLs
4705 (see |NL-used-for-Nul|).
4706 When the register was not set an empty list is returned.
4707
4708 If {regname} is "", the unnamed register '"' is used.
4709 If {regname} is not specified, |v:register| is used.
4710 In |Vim9-script| {regname} must be one character.
4711
4712 Can also be used as a |method|: >
4713 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004714<
4715 Return type: |String|
4716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004717
4718getreginfo([{regname}]) *getreginfo()*
4719 Returns detailed information about register {regname} as a
4720 Dictionary with the following entries:
4721 regcontents List of lines contained in register
4722 {regname}, like
4723 |getreg|({regname}, 1, 1).
4724 regtype the type of register {regname}, as in
4725 |getregtype()|.
4726 isunnamed Boolean flag, v:true if this register
4727 is currently pointed to by the unnamed
4728 register.
4729 points_to for the unnamed register, gives the
4730 single letter name of the register
4731 currently pointed to (see |quotequote|).
4732 For example, after deleting a line
4733 with `dd`, this field will be "1",
4734 which is the register that got the
4735 deleted text.
4736
4737 The {regname} argument is a string. If {regname} is invalid
4738 or not set, an empty Dictionary will be returned.
4739 If {regname} is "" or "@", the unnamed register '"' is used.
4740 If {regname} is not specified, |v:register| is used.
4741 The returned Dictionary can be passed to |setreg()|.
4742 In |Vim9-script| {regname} must be one character.
4743
4744 Can also be used as a |method|: >
4745 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004746<
4747 Return type: dict<any>
4748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004749
Shougo Matsushita19b71882024-02-28 22:48:12 +01004750getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004751 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004752 buffer.
4753
4754 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004755 See |getpos()| for the format of the list. It's possible
4756 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004757 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004758
4759 The optional argument {opts} is a Dict and supports the
4760 following items:
4761
zeertzjqafc22952024-05-24 19:07:12 +02004762 type Specify the region's selection type.
4763 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004764 except that the width can be omitted
4765 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004766 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004767
zeertzjq87410ab2024-03-02 06:00:23 +08004768 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004769 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004770 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004771
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004772 You can get the last selection type by |visualmode()|.
4773 If Visual mode is active, use |mode()| to get the Visual mode
4774 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004775 This function is useful to get text starting and ending in
4776 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004777
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004778 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004779 Note that:
4780 - Order of {pos1} and {pos2} doesn't matter, it will always
4781 return content from the upper left position to the lower
4782 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004783 - If 'virtualedit' is enabled and the region is past the end
4784 of the lines, resulting lines are padded with spaces.
4785 - If the region is blockwise and it starts or ends in the
4786 middle of a multi-cell character, it is not included but
4787 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004788 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004789 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004790 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004791 - It is evaluated in current window context, which makes a
4792 difference if the buffer is displayed in a window with
4793 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004794
4795 Examples: >
4796 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004797 \ <Cmd>echow getregion(
4798 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004799<
4800 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004801 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004802
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004803<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004804getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4805 Same as |getregion()|, but returns a list of positions
4806 describing the buffer text segments bound by {pos1} and
4807 {pos2}.
4808 The segments are a pair of positions for every line: >
4809 [[{start_pos}, {end_pos}], ...]
4810<
4811 The position is a |List| with four numbers:
4812 [bufnum, lnum, col, off]
4813 "bufnum" is the buffer number.
4814 "lnum" and "col" are the position in the buffer. The first
4815 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004816 If the "off" number of a starting position is non-zero, it is
4817 the offset in screen columns from the start of the character.
4818 E.g., a position within a <Tab> or after the last character.
4819 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004820 the offset of the character's first cell not included in the
4821 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004822
zeertzjq2b09de92024-05-24 07:48:51 +02004823 Apart from the options supported by |getregion()|, {opts} also
4824 supports the following:
4825
4826 eol If |TRUE|, indicate positions beyond
4827 the end of a line with "col" values
4828 one more than the length of the line.
4829 If |FALSE|, positions are limited
4830 within their lines, and if a line is
4831 empty or the selection is entirely
4832 beyond the end of a line, a "col"
4833 value of 0 is used for both positions.
4834 (default: |FALSE|)
4835
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004836 Can also be used as a |method|: >
4837 getpos('.')->getregionpos(getpos("'a"))
4838<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004839 Return type: list<string>
4840
4841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004842getregtype([{regname}]) *getregtype()*
4843 The result is a String, which is type of register {regname}.
4844 The value will be one of:
4845 "v" for |characterwise| text
4846 "V" for |linewise| text
4847 "<CTRL-V>{width}" for |blockwise-visual| text
4848 "" for an empty or unknown register
4849 <CTRL-V> is one character with value 0x16.
4850 The {regname} argument is a string. If {regname} is "", the
4851 unnamed register '"' is used. If {regname} is not specified,
4852 |v:register| is used.
4853 In |Vim9-script| {regname} must be one character.
4854
4855 Can also be used as a |method|: >
4856 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004857<
4858 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004859
Bram Moolenaar71badf92023-04-22 22:40:14 +01004860getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004861 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004862 scripts in the order they were sourced, like what
4863 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004864
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004865 The optional Dict argument {opts} supports the following
4866 optional items:
4867 name Script name match pattern. If specified,
4868 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004869 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004870 "name" are returned.
4871 sid Script ID |<SID>|. If specified, only
4872 information about the script with ID "sid" is
4873 returned and "name" is ignored.
4874
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004875 Each item in the returned List is a |Dict| with the following
4876 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004877 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004878 `import autoload` but was not actually sourced
4879 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004880 functions List of script-local function names defined in
4881 the script. Present only when a particular
4882 script is specified using the "sid" item in
4883 {opts}.
4884 name Vim script file name.
4885 sid Script ID |<SID>|.
4886 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004887 this script name links to, if any, otherwise
4888 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004889 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004890 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004891 specified using the "sid" item in {opts}.
4892 Note that this is a copy, the value of
4893 script-local variables cannot be changed using
4894 this dictionary.
h_east59858792023-10-25 22:47:05 +09004895 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004896
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004897 Examples: >
4898 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004899 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004900<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004901 Return type: list<dict<any>>
4902
4903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004904gettabinfo([{tabnr}]) *gettabinfo()*
4905 If {tabnr} is not specified, then information about all the
4906 tab pages is returned as a |List|. Each List item is a
4907 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4908 number and information about that one is returned. If the tab
4909 page does not exist an empty List is returned.
4910
4911 Each List item is a |Dictionary| with the following entries:
4912 tabnr tab page number.
4913 variables a reference to the dictionary with
4914 tabpage-local variables
4915 windows List of |window-ID|s in the tab page.
4916
4917 Can also be used as a |method|: >
4918 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004919<
4920 Return type: list<dict<any>>
4921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004922
4923gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4924 Get the value of a tab-local variable {varname} in tab page
4925 {tabnr}. |t:var|
4926 Tabs are numbered starting with one.
4927 The {varname} argument is a string. When {varname} is empty a
4928 dictionary with all tab-local variables is returned.
4929 Note that the name without "t:" must be used.
4930 When the tab or variable doesn't exist {def} or an empty
4931 string is returned, there is no error message.
4932
4933 Can also be used as a |method|: >
4934 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004935<
4936 Return type: any, depending on {varname}
4937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004938
4939gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4940 Get the value of window-local variable {varname} in window
4941 {winnr} in tab page {tabnr}.
4942 The {varname} argument is a string. When {varname} is empty a
4943 dictionary with all window-local variables is returned.
4944 When {varname} is equal to "&" get the values of all
4945 window-local options in a |Dictionary|.
4946 Otherwise, when {varname} starts with "&" get the value of a
4947 window-local option.
4948 Note that {varname} must be the name without "w:".
4949 Tabs are numbered starting with one. For the current tabpage
4950 use |getwinvar()|.
4951 {winnr} can be the window number or the |window-ID|.
4952 When {winnr} is zero the current window is used.
4953 This also works for a global option, buffer-local option and
4954 window-local option, but it doesn't work for a global variable
4955 or buffer-local variable.
4956 When the tab, window or variable doesn't exist {def} or an
4957 empty string is returned, there is no error message.
4958 Examples: >
4959 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004960 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004961<
4962 To obtain all window-local variables use: >
4963 gettabwinvar({tabnr}, {winnr}, '&')
4964
4965< Can also be used as a |method|: >
4966 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004967<
4968 Return type: any, depending on {varname}
4969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004970
4971gettagstack([{winnr}]) *gettagstack()*
4972 The result is a Dict, which is the tag stack of window {winnr}.
4973 {winnr} can be the window number or the |window-ID|.
4974 When {winnr} is not specified, the current window is used.
4975 When window {winnr} doesn't exist, an empty Dict is returned.
4976
4977 The returned dictionary contains the following entries:
4978 curidx Current index in the stack. When at
4979 top of the stack, set to (length + 1).
4980 Index of bottom of the stack is 1.
4981 items List of items in the stack. Each item
4982 is a dictionary containing the
4983 entries described below.
4984 length Number of entries in the stack.
4985
4986 Each item in the stack is a dictionary with the following
4987 entries:
4988 bufnr buffer number of the current jump
4989 from cursor position before the tag jump.
4990 See |getpos()| for the format of the
4991 returned list.
4992 matchnr current matching tag number. Used when
4993 multiple matching tags are found for a
4994 name.
4995 tagname name of the tag
4996
4997 See |tagstack| for more information about the tag stack.
4998
4999 Can also be used as a |method|: >
5000 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005001<
5002 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005003
5004
Christ van Willegence0ef912024-06-20 23:41:59 +02005005gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005006 Translate String {text} if possible.
5007 This is mainly for use in the distributed Vim scripts. When
5008 generating message translations the {text} is extracted by
5009 xgettext, the translator can add the translated message in the
5010 .po file and Vim will lookup the translation when gettext() is
5011 called.
5012 For {text} double quoted strings are preferred, because
5013 xgettext does not understand escaping in single quoted
5014 strings.
Christ van Willegence0ef912024-06-20 23:41:59 +02005015 When the {package} is specified, the translation is looked up
5016 for that specific package. You need to specify the path to
5017 look for translations with the |bindtextdomain()| function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005018
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005019 Return type: |String|
5020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005021
5022getwininfo([{winid}]) *getwininfo()*
5023 Returns information about windows as a |List| with Dictionaries.
5024
5025 If {winid} is given Information about the window with that ID
5026 is returned, as a |List| with one item. If the window does not
5027 exist the result is an empty list.
5028
5029 Without {winid} information about all the windows in all the
5030 tab pages is returned.
5031
5032 Each List item is a |Dictionary| with the following entries:
5033 botline last complete displayed buffer line
5034 bufnr number of buffer in the window
5035 height window height (excluding winbar)
5036 loclist 1 if showing a location list
5037 {only with the +quickfix feature}
5038 quickfix 1 if quickfix or location list window
5039 {only with the +quickfix feature}
5040 terminal 1 if a terminal window
5041 {only with the +terminal feature}
5042 tabnr tab page number
5043 topline first displayed buffer line
5044 variables a reference to the dictionary with
5045 window-local variables
5046 width window width
5047 winbar 1 if the window has a toolbar, 0
5048 otherwise
5049 wincol leftmost screen column of the window;
5050 "col" from |win_screenpos()|
5051 textoff number of columns occupied by any
5052 'foldcolumn', 'signcolumn' and line
5053 number in front of the text
5054 winid |window-ID|
5055 winnr window number
5056 winrow topmost screen line of the window;
5057 "row" from |win_screenpos()|
5058
5059 Can also be used as a |method|: >
5060 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005061<
5062 Return type: list<dict<any>>
5063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005064
5065getwinpos([{timeout}]) *getwinpos()*
5066 The result is a |List| with two numbers, the result of
5067 |getwinposx()| and |getwinposy()| combined:
5068 [x-pos, y-pos]
5069 {timeout} can be used to specify how long to wait in msec for
5070 a response from the terminal. When omitted 100 msec is used.
5071 Use a longer time for a remote terminal.
5072 When using a value less than 10 and no response is received
5073 within that time, a previously reported position is returned,
5074 if available. This can be used to poll for the position and
5075 do some work in the meantime: >
5076 while 1
5077 let res = getwinpos(1)
5078 if res[0] >= 0
5079 break
5080 endif
5081 " Do some work here
5082 endwhile
5083<
5084
5085 Can also be used as a |method|: >
5086 GetTimeout()->getwinpos()
5087<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005088 Return type: list<number>
5089
5090
5091getwinposx() *getwinposx()*
5092 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005093 the left hand side of the GUI Vim window. Also works for an
5094 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005095 The result will be -1 if the information is not available
5096 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005097 The value can be used with `:winpos`.
5098
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005099 Return type: |Number|
5100
5101
5102getwinposy() *getwinposy()*
5103 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005104 the top of the GUI Vim window. Also works for an xterm (uses
5105 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005106 The result will be -1 if the information is not available
5107 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005108 The value can be used with `:winpos`.
5109
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005110 Return type: |Number|
5111
5112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005113getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5114 Like |gettabwinvar()| for the current tabpage.
5115 Examples: >
5116 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005117 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005118
5119< Can also be used as a |method|: >
5120 GetWinnr()->getwinvar(varname)
5121<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005122 Return type: any, depending on {varname}
5123
5124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005125glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5126 Expand the file wildcards in {expr}. See |wildcards| for the
5127 use of special characters.
5128
5129 Unless the optional {nosuf} argument is given and is |TRUE|,
5130 the 'suffixes' and 'wildignore' options apply: Names matching
5131 one of the patterns in 'wildignore' will be skipped and
5132 'suffixes' affect the ordering of matches.
5133 'wildignorecase' always applies.
5134
5135 When {list} is present and it is |TRUE| the result is a |List|
5136 with all matching files. The advantage of using a List is,
5137 you also get filenames containing newlines correctly.
5138 Otherwise the result is a String and when there are several
5139 matches, they are separated by <NL> characters.
5140
5141 If the expansion fails, the result is an empty String or List.
5142
5143 You can also use |readdir()| if you need to do complicated
5144 things, such as limiting the number of matches.
5145
5146 A name for a non-existing file is not included. A symbolic
5147 link is only included if it points to an existing file.
5148 However, when the {alllinks} argument is present and it is
5149 |TRUE| then all symbolic links are included.
5150
5151 For most systems backticks can be used to get files names from
5152 any external command. Example: >
5153 :let tagfiles = glob("`find . -name tags -print`")
5154 :let &tags = substitute(tagfiles, "\n", ",", "g")
5155< The result of the program inside the backticks should be one
5156 item per line. Spaces inside an item are allowed.
5157
5158 See |expand()| for expanding special Vim variables. See
5159 |system()| for getting the raw output of an external command.
5160
5161 Can also be used as a |method|: >
5162 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005163<
5164 Return type: |String| or list<string> or list<any> depending
5165 on {list}
5166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005167
5168glob2regpat({string}) *glob2regpat()*
5169 Convert a file pattern, as used by glob(), into a search
5170 pattern. The result can be used to match with a string that
5171 is a file name. E.g. >
5172 if filename =~ glob2regpat('Make*.mak')
5173< This is equivalent to: >
5174 if filename =~ '^Make.*\.mak$'
5175< When {string} is an empty string the result is "^$", match an
5176 empty string.
5177 Note that the result depends on the system. On MS-Windows
5178 a backslash usually means a path separator.
5179
5180 Can also be used as a |method|: >
5181 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005182<
5183 Return type: |String|
5184
5185 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005186globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5187 Perform glob() for String {expr} on all directories in {path}
5188 and concatenate the results. Example: >
5189 :echo globpath(&rtp, "syntax/c.vim")
5190<
5191 {path} is a comma-separated list of directory names. Each
5192 directory name is prepended to {expr} and expanded like with
5193 |glob()|. A path separator is inserted when needed.
5194 To add a comma inside a directory name escape it with a
5195 backslash. Note that on MS-Windows a directory may have a
5196 trailing backslash, remove it if you put a comma after it.
5197 If the expansion fails for one of the directories, there is no
5198 error message.
5199
5200 Unless the optional {nosuf} argument is given and is |TRUE|,
5201 the 'suffixes' and 'wildignore' options apply: Names matching
5202 one of the patterns in 'wildignore' will be skipped and
5203 'suffixes' affect the ordering of matches.
5204
5205 When {list} is present and it is |TRUE| the result is a |List|
5206 with all matching files. The advantage of using a List is, you
5207 also get filenames containing newlines correctly. Otherwise
5208 the result is a String and when there are several matches,
5209 they are separated by <NL> characters. Example: >
5210 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5211<
5212 {alllinks} is used as with |glob()|.
5213
5214 The "**" item can be used to search in a directory tree.
5215 For example, to find all "README.txt" files in the directories
5216 in 'runtimepath' and below: >
5217 :echo globpath(&rtp, "**/README.txt")
5218< Upwards search and limiting the depth of "**" is not
5219 supported, thus using 'path' will not always work properly.
5220
5221 Can also be used as a |method|, the base is passed as the
5222 second argument: >
5223 GetExpr()->globpath(&rtp)
5224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005225 Return type: |String| or list<string> or list<any> depending
5226 on {list}
5227
5228
5229has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005230 When {check} is omitted or is zero: The result is a Number,
5231 which is 1 if the feature {feature} is supported, zero
5232 otherwise. The {feature} argument is a string, case is
5233 ignored. See |feature-list| below.
5234
5235 When {check} is present and not zero: The result is a Number,
5236 which is 1 if the feature {feature} could ever be supported,
5237 zero otherwise. This is useful to check for a typo in
5238 {feature} and to detect dead code. Keep in mind that an older
5239 Vim version will not know about a feature added later and
5240 features that have been abandoned will not be known by the
5241 current Vim version.
5242
5243 Also see |exists()| and |exists_compiled()|.
5244
5245 Note that to skip code that has a syntax error when the
5246 feature is not available, Vim may skip the rest of the line
5247 and miss a following `endif`. Therefore put the `endif` on a
5248 separate line: >
5249 if has('feature')
5250 let x = this->breaks->without->the->feature
5251 endif
5252< If the `endif` would be moved to the second line as "| endif" it
5253 would not be found.
5254
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005255 Return type: |Number|
5256
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005257
5258has_key({dict}, {key}) *has_key()*
5259 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005260 has an entry with key {key}. FALSE otherwise.
5261 The {key} argument is a string. In |Vim9| script a number is
5262 also accepted (and converted to a string) but no other types.
5263 In legacy script the usual automatic conversion to string is
5264 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005265
5266 Can also be used as a |method|: >
5267 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005268<
5269 Return type: |Number|
5270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005271
5272haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5273 The result is a Number:
5274 1 when the window has set a local directory via |:lcd|
5275 2 when the tab-page has set a local directory via |:tcd|
5276 0 otherwise.
5277
5278 Without arguments use the current window.
5279 With {winnr} use this window in the current tab page.
5280 With {winnr} and {tabnr} use the window in the specified tab
5281 page.
5282 {winnr} can be the window number or the |window-ID|.
5283 If {winnr} is -1 it is ignored and only the tabpage is used.
5284 Return 0 if the arguments are invalid.
5285 Examples: >
5286 if haslocaldir() == 1
5287 " window local directory case
5288 elseif haslocaldir() == 2
5289 " tab-local directory case
5290 else
5291 " global directory case
5292 endif
5293
5294 " current window
5295 :echo haslocaldir()
5296 :echo haslocaldir(0)
5297 :echo haslocaldir(0, 0)
5298 " window n in current tab page
5299 :echo haslocaldir(n)
5300 :echo haslocaldir(n, 0)
5301 " window n in tab page m
5302 :echo haslocaldir(n, m)
5303 " tab page m
5304 :echo haslocaldir(-1, m)
5305<
5306 Can also be used as a |method|: >
5307 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005308<
5309 Return type: |Number|
5310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005311
5312hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5313 The result is a Number, which is TRUE if there is a mapping
5314 that contains {what} in somewhere in the rhs (what it is
5315 mapped to) and this mapping exists in one of the modes
5316 indicated by {mode}.
5317 The arguments {what} and {mode} are strings.
5318 When {abbr} is there and it is |TRUE| use abbreviations
5319 instead of mappings. Don't forget to specify Insert and/or
5320 Command-line mode.
5321 Both the global mappings and the mappings local to the current
5322 buffer are checked for a match.
5323 If no matching mapping is found FALSE is returned.
5324 The following characters are recognized in {mode}:
5325 n Normal mode
5326 v Visual and Select mode
5327 x Visual mode
5328 s Select mode
5329 o Operator-pending mode
5330 i Insert mode
5331 l Language-Argument ("r", "f", "t", etc.)
5332 c Command-line mode
5333 When {mode} is omitted, "nvo" is used.
5334
5335 This function is useful to check if a mapping already exists
5336 to a function in a Vim script. Example: >
5337 :if !hasmapto('\ABCdoit')
5338 : map <Leader>d \ABCdoit
5339 :endif
5340< This installs the mapping to "\ABCdoit" only if there isn't
5341 already a mapping to "\ABCdoit".
5342
5343 Can also be used as a |method|: >
5344 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005345<
5346 Return type: |Number|
5347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005348
5349histadd({history}, {item}) *histadd()*
5350 Add the String {item} to the history {history} which can be
5351 one of: *hist-names*
5352 "cmd" or ":" command line history
5353 "search" or "/" search pattern history
5354 "expr" or "=" typed expression history
5355 "input" or "@" input line history
5356 "debug" or ">" debug command history
5357 empty the current or last used history
5358 The {history} string does not need to be the whole name, one
5359 character is sufficient.
5360 If {item} does already exist in the history, it will be
5361 shifted to become the newest entry.
5362 The result is a Number: TRUE if the operation was successful,
5363 otherwise FALSE is returned.
5364
5365 Example: >
5366 :call histadd("input", strftime("%Y %b %d"))
5367 :let date=input("Enter date: ")
5368< This function is not available in the |sandbox|.
5369
5370 Can also be used as a |method|, the base is passed as the
5371 second argument: >
5372 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005373<
5374 Return type: |Number|
5375
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005376
5377histdel({history} [, {item}]) *histdel()*
5378 Clear {history}, i.e. delete all its entries. See |hist-names|
5379 for the possible values of {history}.
5380
5381 If the parameter {item} evaluates to a String, it is used as a
5382 regular expression. All entries matching that expression will
5383 be removed from the history (if there are any).
5384 Upper/lowercase must match, unless "\c" is used |/\c|.
5385 If {item} evaluates to a Number, it will be interpreted as
5386 an index, see |:history-indexing|. The respective entry will
5387 be removed if it exists.
5388
5389 The result is TRUE for a successful operation, otherwise FALSE
5390 is returned.
5391
5392 Examples:
5393 Clear expression register history: >
5394 :call histdel("expr")
5395<
5396 Remove all entries starting with "*" from the search history: >
5397 :call histdel("/", '^\*')
5398<
5399 The following three are equivalent: >
5400 :call histdel("search", histnr("search"))
5401 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005402 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005403<
5404 To delete the last search pattern and use the last-but-one for
5405 the "n" command and 'hlsearch': >
5406 :call histdel("search", -1)
5407 :let @/ = histget("search", -1)
5408<
5409 Can also be used as a |method|: >
5410 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005411<
5412 Return type: |Number|
5413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005414
5415histget({history} [, {index}]) *histget()*
5416 The result is a String, the entry with Number {index} from
5417 {history}. See |hist-names| for the possible values of
5418 {history}, and |:history-indexing| for {index}. If there is
5419 no such entry, an empty String is returned. When {index} is
5420 omitted, the most recent item from the history is used.
5421
5422 Examples:
5423 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005424 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005425
5426< Define an Ex command ":H {num}" that supports re-execution of
5427 the {num}th entry from the output of |:history|. >
5428 :command -nargs=1 H execute histget("cmd", 0+<args>)
5429<
5430 Can also be used as a |method|: >
5431 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005432<
5433 Return type: |String|
5434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005435
5436histnr({history}) *histnr()*
5437 The result is the Number of the current entry in {history}.
5438 See |hist-names| for the possible values of {history}.
5439 If an error occurred, -1 is returned.
5440
5441 Example: >
5442 :let inp_index = histnr("expr")
5443
5444< Can also be used as a |method|: >
5445 GetHistory()->histnr()
5446<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005447 Return type: |Number|
5448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005449hlexists({name}) *hlexists()*
5450 The result is a Number, which is TRUE if a highlight group
5451 called {name} exists. This is when the group has been
5452 defined in some way. Not necessarily when highlighting has
5453 been defined for it, it may also have been used for a syntax
5454 item.
5455 *highlight_exists()*
5456 Obsolete name: highlight_exists().
5457
5458 Can also be used as a |method|: >
5459 GetName()->hlexists()
5460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005461 Return type: |Number|
5462
5463
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005464hlget([{name} [, {resolve}]]) *hlget()*
5465 Returns a List of all the highlight group attributes. If the
5466 optional {name} is specified, then returns a List with only
5467 the attributes of the specified highlight group. Returns an
5468 empty List if the highlight group {name} is not present.
5469
5470 If the optional {resolve} argument is set to v:true and the
5471 highlight group {name} is linked to another group, then the
5472 link is resolved recursively and the attributes of the
5473 resolved highlight group are returned.
5474
5475 Each entry in the returned List is a Dictionary with the
5476 following items:
5477 cleared boolean flag, set to v:true if the highlight
5478 group attributes are cleared or not yet
5479 specified. See |highlight-clear|.
5480 cterm cterm attributes. See |highlight-cterm|.
5481 ctermbg cterm background color.
5482 See |highlight-ctermbg|.
5483 ctermfg cterm foreground color.
5484 See |highlight-ctermfg|.
5485 ctermul cterm underline color. See |highlight-ctermul|.
5486 default boolean flag, set to v:true if the highlight
5487 group link is a default link. See
5488 |highlight-default|.
5489 font highlight group font. See |highlight-font|.
5490 gui gui attributes. See |highlight-gui|.
5491 guibg gui background color. See |highlight-guibg|.
5492 guifg gui foreground color. See |highlight-guifg|.
5493 guisp gui special color. See |highlight-guisp|.
5494 id highlight group ID.
5495 linksto linked highlight group name.
5496 See |:highlight-link|.
5497 name highlight group name. See |group-name|.
5498 start start terminal keycode. See |highlight-start|.
5499 stop stop terminal keycode. See |highlight-stop|.
5500 term term attributes. See |highlight-term|.
5501
5502 The 'term', 'cterm' and 'gui' items in the above Dictionary
5503 have a dictionary value with the following optional boolean
5504 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5505 'reverse', 'inverse' and 'strikethrough'.
5506
5507 Example(s): >
5508 :echo hlget()
5509 :echo hlget('ModeMsg')
5510 :echo hlget('Number', v:true)
5511<
5512 Can also be used as a |method|: >
5513 GetName()->hlget()
5514<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005515 Return type: list<dict<any>>
5516
5517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005518hlset({list}) *hlset()*
5519 Creates or modifies the attributes of a List of highlight
5520 groups. Each item in {list} is a dictionary containing the
5521 attributes of a highlight group. See |hlget()| for the list of
5522 supported items in this dictionary.
5523
5524 In addition to the items described in |hlget()|, the following
5525 additional items are supported in the dictionary:
5526
5527 force boolean flag to force the creation of
5528 a link for an existing highlight group
5529 with attributes.
5530
5531 The highlight group is identified using the 'name' item and
5532 the 'id' item (if supplied) is ignored. If a highlight group
5533 with a specified name doesn't exist, then it is created.
5534 Otherwise the attributes of an existing highlight group are
5535 modified.
5536
5537 If an empty dictionary value is used for the 'term' or 'cterm'
5538 or 'gui' entries, then the corresponding attributes are
5539 cleared. If the 'cleared' item is set to v:true, then all the
5540 attributes of the highlight group are cleared.
5541
5542 The 'linksto' item can be used to link a highlight group to
5543 another highlight group. See |:highlight-link|.
5544
5545 Returns zero for success, -1 for failure.
5546
5547 Example(s): >
5548 " add bold attribute to the Visual highlight group
5549 :call hlset([#{name: 'Visual',
5550 \ term: #{reverse: 1 , bold: 1}}])
5551 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5552 :let l = hlget()
5553 :call hlset(l)
5554 " clear the Search highlight group
5555 :call hlset([#{name: 'Search', cleared: v:true}])
5556 " clear the 'term' attributes for a highlight group
5557 :call hlset([#{name: 'Title', term: {}}])
5558 " create the MyHlg group linking it to DiffAdd
5559 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5560 " remove the MyHlg group link
5561 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5562 " clear the attributes and a link
5563 :call hlset([#{name: 'MyHlg', cleared: v:true,
5564 \ linksto: 'NONE'}])
5565<
5566 Can also be used as a |method|: >
5567 GetAttrList()->hlset()
5568<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005569 Return type: |Number|
5570
5571hlID({name}) *hlID()*
5572 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005573 with name {name}. When the highlight group doesn't exist,
5574 zero is returned.
5575 This can be used to retrieve information about the highlight
5576 group. For example, to get the background color of the
5577 "Comment" group: >
5578 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5579< *highlightID()*
5580 Obsolete name: highlightID().
5581
5582 Can also be used as a |method|: >
5583 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005584<
5585 Return type: |Number|
5586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005587
5588hostname() *hostname()*
5589 The result is a String, which is the name of the machine on
5590 which Vim is currently running. Machine names greater than
5591 256 characters long are truncated.
5592
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005593 Return type: |String|
5594
5595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005596iconv({string}, {from}, {to}) *iconv()*
5597 The result is a String, which is the text {string} converted
5598 from encoding {from} to encoding {to}.
5599 When the conversion completely fails an empty string is
5600 returned. When some characters could not be converted they
5601 are replaced with "?".
5602 The encoding names are whatever the iconv() library function
5603 can accept, see ":!man 3 iconv".
5604 Most conversions require Vim to be compiled with the |+iconv|
5605 feature. Otherwise only UTF-8 to latin1 conversion and back
5606 can be done.
5607 This can be used to display messages with special characters,
5608 no matter what 'encoding' is set to. Write the message in
5609 UTF-8 and use: >
5610 echo iconv(utf8_str, "utf-8", &enc)
5611< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5612 from/to UCS-2 is automatically changed to use UTF-8. You
5613 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5614
5615 Can also be used as a |method|: >
5616 GetText()->iconv('latin1', 'utf-8')
5617<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005618 Return type: |String|
5619
5620
5621indent({lnum}) *indent()*
5622 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005623 current buffer. The indent is counted in spaces, the value
5624 of 'tabstop' is relevant. {lnum} is used just like in
5625 |getline()|.
5626 When {lnum} is invalid -1 is returned. In |Vim9| script an
5627 error is given.
5628
5629 Can also be used as a |method|: >
5630 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005631<
5632 Return type: |Number|
5633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005634
5635index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005636 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005637 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005639 If {object} is a |List| return the lowest index where the item
5640 has a value equal to {expr}. There is no automatic
5641 conversion, so the String "4" is different from the Number 4.
5642 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005643 of 'ignorecase' is not used here, case matters as indicated by
5644 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005645
5646 If {object} is |Blob| return the lowest index where the byte
5647 value is equal to {expr}.
5648
5649 If {start} is given then start looking at the item with index
5650 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005652 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5653 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005655 -1 is returned when {expr} is not found in {object}.
5656 Example: >
5657 :let idx = index(words, "the")
5658 :if index(numbers, 123) >= 0
5659
5660< Can also be used as a |method|: >
5661 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005662<
5663 Return type: |Number|
5664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005665
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005666indexof({object}, {expr} [, {opts}]) *indexof()*
5667 Returns the index of an item in {object} where {expr} is
5668 v:true. {object} must be a |List| or a |Blob|.
5669
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005670 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005671 List until the expression is v:true and return the index of
5672 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005673
5674 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005675 Blob until the expression is v:true and return the index of
5676 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005677
5678 {expr} must be a |string| or |Funcref|.
5679
5680 If {expr} is a |string|: If {object} is a |List|, inside
5681 {expr} |v:key| has the index of the current List item and
5682 |v:val| has the value of the item. If {object} is a |Blob|,
5683 inside {expr} |v:key| has the index of the current byte and
5684 |v:val| has the byte value.
5685
5686 If {expr} is a |Funcref| it must take two arguments:
5687 1. the key or the index of the current item.
5688 2. the value of the current item.
5689 The function must return |TRUE| if the item is found and the
5690 search should stop.
5691
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005692 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005693 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005694 startidx start evaluating {expr} at the item with this
5695 index; may be negative for an item relative to
5696 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005697 Returns -1 when {expr} evaluates to v:false for all the items.
5698 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005699 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5700 :echo indexof(l, "v:val.n == 20")
5701 :echo indexof(l, {i, v -> v.n == 30})
5702 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005703
5704< Can also be used as a |method|: >
5705 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005706<
5707 Return type: |Number|
5708
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005710input({prompt} [, {text} [, {completion}]]) *input()*
5711 The result is a String, which is whatever the user typed on
5712 the command-line. The {prompt} argument is either a prompt
5713 string, or a blank string (for no prompt). A '\n' can be used
5714 in the prompt to start a new line.
5715 The highlighting set with |:echohl| is used for the prompt.
5716 The input is entered just like a command-line, with the same
5717 editing commands and mappings. There is a separate history
5718 for lines typed for input().
5719 Example: >
5720 :if input("Coffee or beer? ") == "beer"
5721 : echo "Cheers!"
5722 :endif
5723<
5724 If the optional {text} argument is present and not empty, this
5725 is used for the default reply, as if the user typed this.
5726 Example: >
5727 :let color = input("Color? ", "white")
5728
5729< The optional {completion} argument specifies the type of
5730 completion supported for the input. Without it completion is
5731 not performed. The supported completion types are the same as
5732 that can be supplied to a user-defined command using the
5733 "-complete=" argument. Refer to |:command-completion| for
5734 more information. Example: >
5735 let fname = input("File: ", "", "file")
5736<
5737 NOTE: This function must not be used in a startup file, for
5738 the versions that only run in GUI mode (e.g., the Win32 GUI).
5739 Note: When input() is called from within a mapping it will
5740 consume remaining characters from that mapping, because a
5741 mapping is handled like the characters were typed.
5742 Use |inputsave()| before input() and |inputrestore()|
5743 after input() to avoid that. Another solution is to avoid
5744 that further characters follow in the mapping, e.g., by using
5745 |:execute| or |:normal|.
5746
5747 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005748 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005749 :function GetFoo()
5750 : call inputsave()
5751 : let g:Foo = input("enter search pattern: ")
5752 : call inputrestore()
5753 :endfunction
5754
5755< Can also be used as a |method|: >
5756 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005757<
5758 Return type: |String|
5759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005760
5761inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5762 Like |input()|, but when the GUI is running and text dialogs
5763 are supported, a dialog window pops up to input the text.
5764 Example: >
5765 :let n = inputdialog("value for shiftwidth", shiftwidth())
5766 :if n != ""
5767 : let &sw = n
5768 :endif
5769< When the dialog is cancelled {cancelreturn} is returned. When
5770 omitted an empty string is returned.
5771 Hitting <Enter> works like pressing the OK button. Hitting
5772 <Esc> works like pressing the Cancel button.
5773 NOTE: Command-line completion is not supported.
5774
5775 Can also be used as a |method|: >
5776 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005777<
5778 Return type: |String|
5779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005780
5781inputlist({textlist}) *inputlist()*
5782 {textlist} must be a |List| of strings. This |List| is
5783 displayed, one string per line. The user will be prompted to
5784 enter a number, which is returned.
5785 The user can also select an item by clicking on it with the
5786 mouse, if the mouse is enabled in the command line ('mouse' is
5787 "a" or includes "c"). For the first string 0 is returned.
5788 When clicking above the first item a negative number is
5789 returned. When clicking on the prompt one more than the
5790 length of {textlist} is returned.
5791 Make sure {textlist} has less than 'lines' entries, otherwise
5792 it won't work. It's a good idea to put the entry number at
5793 the start of the string. And put a prompt in the first item.
5794 Example: >
5795 let color = inputlist(['Select color:', '1. red',
5796 \ '2. green', '3. blue'])
5797
5798< Can also be used as a |method|: >
5799 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005800<
5801 Return type: |Number|
5802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005803
5804inputrestore() *inputrestore()*
5805 Restore typeahead that was saved with a previous |inputsave()|.
5806 Should be called the same number of times inputsave() is
5807 called. Calling it more often is harmless though.
5808 Returns TRUE when there is nothing to restore, FALSE otherwise.
5809
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005810 Return type: |Number|
5811
5812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005813inputsave() *inputsave()*
5814 Preserve typeahead (also from mappings) and clear it, so that
5815 a following prompt gets input from the user. Should be
5816 followed by a matching inputrestore() after the prompt. Can
5817 be used several times, in which case there must be just as
5818 many inputrestore() calls.
5819 Returns TRUE when out of memory, FALSE otherwise.
5820
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005821 Return type: |Number|
5822
5823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005824inputsecret({prompt} [, {text}]) *inputsecret()*
5825 This function acts much like the |input()| function with but
5826 two exceptions:
5827 a) the user's response will be displayed as a sequence of
5828 asterisks ("*") thereby keeping the entry secret, and
5829 b) the user's response will not be recorded on the input
5830 |history| stack.
5831 The result is a String, which is whatever the user actually
5832 typed on the command-line in response to the issued prompt.
5833 NOTE: Command-line completion is not supported.
5834
5835 Can also be used as a |method|: >
5836 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005837<
5838 Return type: |String|
5839
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005840
5841insert({object}, {item} [, {idx}]) *insert()*
5842 When {object} is a |List| or a |Blob| insert {item} at the start
5843 of it.
5844
5845 If {idx} is specified insert {item} before the item with index
5846 {idx}. If {idx} is zero it goes before the first item, just
5847 like omitting {idx}. A negative {idx} is also possible, see
5848 |list-index|. -1 inserts just before the last item.
5849
5850 Returns the resulting |List| or |Blob|. Examples: >
5851 :let mylist = insert([2, 3, 5], 1)
5852 :call insert(mylist, 4, -1)
5853 :call insert(mylist, 6, len(mylist))
5854< The last example can be done simpler with |add()|.
5855 Note that when {item} is a |List| it is inserted as a single
5856 item. Use |extend()| to concatenate |Lists|.
5857
5858 Can also be used as a |method|: >
5859 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005861 Return type: |Number|
5862
5863
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005864 *instanceof()* *E614* *E616* *E693*
5865instanceof({object}, {class})
5866 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005867 argument is a direct or indirect instance of a |Class|,
5868 |Interface|, or class |:type| alias specified by {class}.
5869 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005870 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005871 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005872 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005873
5874< Can also be used as a |method|: >
5875 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005876<
5877 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005879interrupt() *interrupt()*
5880 Interrupt script execution. It works more or less like the
5881 user typing CTRL-C, most commands won't execute and control
5882 returns to the user. This is useful to abort execution
5883 from lower down, e.g. in an autocommand. Example: >
5884 :function s:check_typoname(file)
5885 : if fnamemodify(a:file, ':t') == '['
5886 : echomsg 'Maybe typo'
5887 : call interrupt()
5888 : endif
5889 :endfunction
5890 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005891<
5892 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005893
5894invert({expr}) *invert()*
5895 Bitwise invert. The argument is converted to a number. A
5896 List, Dict or Float argument causes an error. Example: >
5897 :let bits = invert(bits)
5898< Can also be used as a |method|: >
5899 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005900<
5901 Return type: |Number|
5902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005903
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005904isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005905 The result is a Number, which is |TRUE| when {path} is an
5906 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005907 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005908 On MS-Windows, it is considered absolute when it starts with an
5909 optional drive prefix and is followed by a '\' or '/'. UNC paths
5910 are always absolute.
5911 Example: >
5912 echo isabsolutepath('/usr/share/') " 1
5913 echo isabsolutepath('./foobar') " 0
5914 echo isabsolutepath('C:\Windows') " 1
5915 echo isabsolutepath('foobar') " 0
5916 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005917<
LemonBoydca1d402022-04-28 15:26:33 +01005918 Can also be used as a |method|: >
5919 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005920<
5921 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005922
5923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005924isdirectory({directory}) *isdirectory()*
5925 The result is a Number, which is |TRUE| when a directory
5926 with the name {directory} exists. If {directory} doesn't
5927 exist, or isn't a directory, the result is |FALSE|. {directory}
5928 is any expression, which is used as a String.
5929
5930 Can also be used as a |method|: >
5931 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005932<
5933 Return type: |Number|
5934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005935
5936isinf({expr}) *isinf()*
5937 Return 1 if {expr} is a positive infinity, or -1 a negative
5938 infinity, otherwise 0. >
5939 :echo isinf(1.0 / 0.0)
5940< 1 >
5941 :echo isinf(-1.0 / 0.0)
5942< -1
5943
5944 Can also be used as a |method|: >
5945 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005946<
5947 Return type: |Number|
5948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005949
5950islocked({expr}) *islocked()* *E786*
5951 The result is a Number, which is |TRUE| when {expr} is the
5952 name of a locked variable.
5953 The string argument {expr} must be the name of a variable,
5954 |List| item or |Dictionary| entry, not the variable itself!
5955 Example: >
5956 :let alist = [0, ['a', 'b'], 2, 3]
5957 :lockvar 1 alist
5958 :echo islocked('alist') " 1
5959 :echo islocked('alist[1]') " 0
5960
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005961< When {expr} is a variable that does not exist -1 is returned.
5962 If {expr} uses a range, list or dict index that is out of
5963 range or does not exist you get an error message. Use
5964 |exists()| to check for existence.
5965 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005966
5967 Can also be used as a |method|: >
5968 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005969<
5970 Return type: |Number|
5971
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005972
5973isnan({expr}) *isnan()*
5974 Return |TRUE| if {expr} is a float with value NaN. >
5975 echo isnan(0.0 / 0.0)
5976< 1
5977
5978 Can also be used as a |method|: >
5979 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005980<
5981 Return type: |Number|
5982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005983
5984items({dict}) *items()*
5985 Return a |List| with all the key-value pairs of {dict}. Each
5986 |List| item is a list with two items: the key of a {dict}
5987 entry and the value of this entry. The |List| is in arbitrary
5988 order. Also see |keys()| and |values()|.
5989 Example: >
5990 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005991 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005992 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005993<
5994 A List or a String argument is also supported. In these
5995 cases, items() returns a List with the index and the value at
5996 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005997
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005998 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005999 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006000<
6001 Return type: list<list<any>> or list<any>
6002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006003
6004job_ functions are documented here: |job-functions-details|
6005
6006
6007join({list} [, {sep}]) *join()*
6008 Join the items in {list} together into one String.
6009 When {sep} is specified it is put in between the items. If
6010 {sep} is omitted a single space is used.
6011 Note that {sep} is not added at the end. You might want to
6012 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006013 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006014< String items are used as-is. |Lists| and |Dictionaries| are
6015 converted into a string like with |string()|.
6016 The opposite function is |split()|.
6017
6018 Can also be used as a |method|: >
6019 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006020<
6021 Return type: |String|
6022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006023
6024js_decode({string}) *js_decode()*
6025 This is similar to |json_decode()| with these differences:
6026 - Object key names do not have to be in quotes.
6027 - Strings can be in single quotes.
6028 - Empty items in an array (between two commas) are allowed and
6029 result in v:none items.
6030
6031 Can also be used as a |method|: >
6032 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006033<
6034 Return type: any, depending on {varname}
6035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006036
6037js_encode({expr}) *js_encode()*
6038 This is similar to |json_encode()| with these differences:
6039 - Object key names are not in quotes.
6040 - v:none items in an array result in an empty item between
6041 commas.
6042 For example, the Vim object:
6043 [1,v:none,{"one":1},v:none] ~
6044 Will be encoded as:
6045 [1,,{one:1},,] ~
6046 While json_encode() would produce:
6047 [1,null,{"one":1},null] ~
6048 This encoding is valid for JavaScript. It is more efficient
6049 than JSON, especially when using an array with optional items.
6050
6051 Can also be used as a |method|: >
6052 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006053<
6054 Return type: |String|
6055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006056
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006057json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006058 This parses a JSON formatted string and returns the equivalent
6059 in Vim values. See |json_encode()| for the relation between
6060 JSON and Vim values.
6061 The decoding is permissive:
6062 - A trailing comma in an array and object is ignored, e.g.
6063 "[1, 2, ]" is the same as "[1, 2]".
6064 - Integer keys are accepted in objects, e.g. {1:2} is the
6065 same as {"1":2}.
6066 - More floating point numbers are recognized, e.g. "1." for
6067 "1.0", or "001.2" for "1.2". Special floating point values
6068 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6069 are accepted.
6070 - Leading zeroes in integer numbers are ignored, e.g. "012"
6071 for "12" or "-012" for "-12".
6072 - Capitalization is ignored in literal names null, true or
6073 false, e.g. "NULL" for "null", "True" for "true".
6074 - Control characters U+0000 through U+001F which are not
6075 escaped in strings are accepted, e.g. " " (tab
6076 character in string) for "\t".
6077 - An empty JSON expression or made of only spaces is accepted
6078 and results in v:none.
6079 - Backslash in an invalid 2-character sequence escape is
6080 ignored, e.g. "\a" is decoded as "a".
6081 - A correct surrogate pair in JSON strings should normally be
6082 a 12 character sequence such as "\uD834\uDD1E", but
6083 json_decode() silently accepts truncated surrogate pairs
6084 such as "\uD834" or "\uD834\u"
6085 *E938*
6086 A duplicate key in an object, valid in rfc7159, is not
6087 accepted by json_decode() as the result must be a valid Vim
6088 type, e.g. this fails: {"a":"b", "a":"c"}
6089
6090 Can also be used as a |method|: >
6091 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006092<
6093 Return type: any, depending on {varname}
6094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006095
6096json_encode({expr}) *json_encode()*
6097 Encode {expr} as JSON and return this as a string.
6098 The encoding is specified in:
6099 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006100 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006101 |Number| decimal number
6102 |Float| floating point number
6103 Float nan "NaN"
6104 Float inf "Infinity"
6105 Float -inf "-Infinity"
6106 |String| in double quotes (possibly null)
6107 |Funcref| not possible, error
6108 |List| as an array (possibly null); when
6109 used recursively: []
6110 |Dict| as an object (possibly null); when
6111 used recursively: {}
6112 |Blob| as an array of the individual bytes
6113 v:false "false"
6114 v:true "true"
6115 v:none "null"
6116 v:null "null"
6117 Note that NaN and Infinity are passed on as values. This is
6118 missing in the JSON standard, but several implementations do
6119 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006120 If a string contains an illegal character then the replacement
6121 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006122
6123 Can also be used as a |method|: >
6124 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006125<
6126 Return type: |String|
6127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006128
6129keys({dict}) *keys()*
6130 Return a |List| with all the keys of {dict}. The |List| is in
6131 arbitrary order. Also see |items()| and |values()|.
6132
6133 Can also be used as a |method|: >
6134 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006135<
6136 Return type: list<string>
6137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006138
zeertzjqcdc83932022-09-12 13:38:41 +01006139keytrans({string}) *keytrans()*
6140 Turn the internal byte representation of keys into a form that
6141 can be used for |:map|. E.g. >
6142 :let xx = "\<C-Home>"
6143 :echo keytrans(xx)
6144< <C-Home>
6145
6146 Can also be used as a |method|: >
6147 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006148<
6149 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006150
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006151
6152len({expr}) *len()* *E701*
6153 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006154 When {expr} is a String or a Number the length in bytes is
6155 used, as with |strlen()|.
6156 When {expr} is a |List| the number of items in the |List| is
6157 returned.
6158 When {expr} is a |Blob| the number of bytes is returned.
6159 When {expr} is a |Dictionary| the number of entries in the
6160 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006161 When {expr} is an |Object|, invokes the len() method in the
6162 object (if present) to get the length (|object-len()|).
6163 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006164
6165 Can also be used as a |method|: >
6166 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006167<
6168 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006169
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006170
6171 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006172libcall({libname}, {funcname}, {argument})
6173 Call function {funcname} in the run-time library {libname}
6174 with single argument {argument}.
6175 This is useful to call functions in a library that you
6176 especially made to be used with Vim. Since only one argument
6177 is possible, calling standard library functions is rather
6178 limited.
6179 The result is the String returned by the function. If the
6180 function returns NULL, this will appear as an empty string ""
6181 to Vim.
6182 If the function returns a number, use libcallnr()!
6183 If {argument} is a number, it is passed to the function as an
6184 int; if {argument} is a string, it is passed as a
6185 null-terminated string.
6186 This function will fail in |restricted-mode|.
6187
6188 libcall() allows you to write your own 'plug-in' extensions to
6189 Vim without having to recompile the program. It is NOT a
6190 means to call system functions! If you try to do so Vim will
6191 very probably crash.
6192
6193 For Win32, the functions you write must be placed in a DLL
6194 and use the normal C calling convention (NOT Pascal which is
6195 used in Windows System DLLs). The function must take exactly
6196 one parameter, either a character pointer or a long integer,
6197 and must return a character pointer or NULL. The character
6198 pointer returned must point to memory that will remain valid
6199 after the function has returned (e.g. in static data in the
6200 DLL). If it points to allocated memory, that memory will
6201 leak away. Using a static buffer in the function should work,
6202 it's then freed when the DLL is unloaded.
6203
6204 WARNING: If the function returns a non-valid pointer, Vim may
6205 crash! This also happens if the function returns a number,
6206 because Vim thinks it's a pointer.
6207 For Win32 systems, {libname} should be the filename of the DLL
6208 without the ".DLL" suffix. A full path is only required if
6209 the DLL is not in the usual places.
6210 For Unix: When compiling your own plugins, remember that the
6211 object code must be compiled as position-independent ('PIC').
6212 {only in Win32 and some Unix versions, when the |+libcall|
6213 feature is present}
6214 Examples: >
6215 :echo libcall("libc.so", "getenv", "HOME")
6216
6217< Can also be used as a |method|, the base is passed as the
6218 third argument: >
6219 GetValue()->libcall("libc.so", "getenv")
6220<
6221 *libcallnr()*
6222libcallnr({libname}, {funcname}, {argument})
6223 Just like |libcall()|, but used for a function that returns an
6224 int instead of a string.
6225 {only in Win32 on some Unix versions, when the |+libcall|
6226 feature is present}
6227 Examples: >
6228 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6229 :call libcallnr("libc.so", "printf", "Hello World!\n")
6230 :call libcallnr("libc.so", "sleep", 10)
6231<
6232 Can also be used as a |method|, the base is passed as the
6233 third argument: >
6234 GetValue()->libcallnr("libc.so", "printf")
6235<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006236 Return type: |String|
6237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238
6239line({expr} [, {winid}]) *line()*
6240 The result is a Number, which is the line number of the file
6241 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006242 See |getpos()| for accepted positions.
6243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006244 To get the column number use |col()|. To get both use
6245 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006246
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006247 With the optional {winid} argument the values are obtained for
6248 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006249
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006250 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252 Examples: >
6253 line(".") line number of the cursor
6254 line(".", winid) idem, in window "winid"
6255 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006256 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006257<
6258 To jump to the last known position when opening a file see
6259 |last-position-jump|.
6260
6261 Can also be used as a |method|: >
6262 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006263<
6264 Return type: |Number|
6265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006266
6267line2byte({lnum}) *line2byte()*
6268 Return the byte count from the start of the buffer for line
6269 {lnum}. This includes the end-of-line character, depending on
6270 the 'fileformat' option for the current buffer. The first
6271 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6272 This can also be used to get the byte count for the line just
6273 below the last line: >
6274 line2byte(line("$") + 1)
6275< This is the buffer size plus one. If 'fileencoding' is empty
6276 it is the file size plus one. {lnum} is used like with
6277 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6278 feature has been disabled at compile time, -1 is returned.
6279 Also see |byte2line()|, |go| and |:goto|.
6280
6281 Can also be used as a |method|: >
6282 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006283<
6284 Return type: |Number|
6285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006286
6287lispindent({lnum}) *lispindent()*
6288 Get the amount of indent for line {lnum} according the lisp
6289 indenting rules, as with 'lisp'.
6290 The indent is counted in spaces, the value of 'tabstop' is
6291 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006292 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006293 error is given.
6294
6295 Can also be used as a |method|: >
6296 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006297<
6298 Return type: |Number|
6299
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006300
6301list2blob({list}) *list2blob()*
6302 Return a Blob concatenating all the number values in {list}.
6303 Examples: >
6304 list2blob([1, 2, 3, 4]) returns 0z01020304
6305 list2blob([]) returns 0z
6306< Returns an empty Blob on error. If one of the numbers is
6307 negative or more than 255 error *E1239* is given.
6308
6309 |blob2list()| does the opposite.
6310
6311 Can also be used as a |method|: >
6312 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006313<
6314 Return type: |Blob|
6315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006316
6317list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006318 Convert each number in {list} to a character string and
6319 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006320 list2str([32]) returns " "
6321 list2str([65, 66, 67]) returns "ABC"
6322< The same can be done (slowly) with: >
6323 join(map(list, {nr, val -> nr2char(val)}), '')
6324< |str2list()| does the opposite.
6325
6326 When {utf8} is omitted or zero, the current 'encoding' is used.
6327 When {utf8} is TRUE, always return UTF-8 characters.
6328 With UTF-8 composing characters work as expected: >
6329 list2str([97, 769]) returns "á"
6330<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006331 Returns an empty string on error.
6332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006333 Can also be used as a |method|: >
6334 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006335<
6336 Return type: |String|
6337
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006338
6339listener_add({callback} [, {buf}]) *listener_add()*
6340 Add a callback function that will be invoked when changes have
6341 been made to buffer {buf}.
6342 {buf} refers to a buffer name or number. For the accepted
6343 values, see |bufname()|. When {buf} is omitted the current
6344 buffer is used.
6345 Returns a unique ID that can be passed to |listener_remove()|.
6346
6347 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006348 bufnr the buffer that was changed
6349 start first changed line number
6350 end first line number below the change
6351 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006352 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006353 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006354
6355 Example: >
6356 func Listener(bufnr, start, end, added, changes)
6357 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6358 endfunc
6359 call listener_add('Listener', bufnr)
6360
Bram Moolenaar944697a2022-02-20 19:48:20 +00006361< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006362 dictionary with these entries:
6363 lnum the first line number of the change
6364 end the first line below the change
6365 added number of lines added; negative if lines were
6366 deleted
6367 col first column in "lnum" that was affected by
6368 the change; one if unknown or the whole line
6369 was affected; this is a byte index, first
6370 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006371 When lines are inserted (not when a line is split, e.g. by
6372 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006373 lnum line above which the new line is added
6374 end equal to "lnum"
6375 added number of lines inserted
6376 col 1
6377 When lines are deleted the values are:
6378 lnum the first deleted line
6379 end the line below the first deleted line, before
6380 the deletion was done
6381 added negative, number of lines deleted
6382 col 1
6383 When lines are changed:
6384 lnum the first changed line
6385 end the line below the last changed line
6386 added 0
6387 col first column with a change or 1
6388
6389 The entries are in the order the changes were made, thus the
6390 most recent change is at the end. The line numbers are valid
6391 when the callback is invoked, but later changes may make them
6392 invalid, thus keeping a copy for later might not work.
6393
6394 The {callback} is invoked just before the screen is updated,
6395 when |listener_flush()| is called or when a change is being
6396 made that changes the line count in a way it causes a line
6397 number in the list of changes to become invalid.
6398
6399 The {callback} is invoked with the text locked, see
6400 |textlock|. If you do need to make changes to the buffer, use
6401 a timer to do this later |timer_start()|.
6402
6403 The {callback} is not invoked when the buffer is first loaded.
6404 Use the |BufReadPost| autocmd event to handle the initial text
6405 of a buffer.
6406 The {callback} is also not invoked when the buffer is
6407 unloaded, use the |BufUnload| autocmd event for that.
6408
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006409 Returns zero if {callback} or {buf} is invalid.
6410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006411 Can also be used as a |method|, the base is passed as the
6412 second argument: >
6413 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006414<
6415 Return type: |Number|
6416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006417
6418listener_flush([{buf}]) *listener_flush()*
6419 Invoke listener callbacks for buffer {buf}. If there are no
6420 pending changes then no callbacks are invoked.
6421
6422 {buf} refers to a buffer name or number. For the accepted
6423 values, see |bufname()|. When {buf} is omitted the current
6424 buffer is used.
6425
6426 Can also be used as a |method|: >
6427 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006428<
6429 Return type: |Number|
6430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006431
6432listener_remove({id}) *listener_remove()*
6433 Remove a listener previously added with listener_add().
6434 Returns FALSE when {id} could not be found, TRUE when {id} was
6435 removed.
6436
6437 Can also be used as a |method|: >
6438 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006439<
6440 Return type: |Number|
6441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006442
6443localtime() *localtime()*
6444 Return the current time, measured as seconds since 1st Jan
6445 1970. See also |strftime()|, |strptime()| and |getftime()|.
6446
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006447 Return type: |Number|
6448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006449
6450log({expr}) *log()*
6451 Return the natural logarithm (base e) of {expr} as a |Float|.
6452 {expr} must evaluate to a |Float| or a |Number| in the range
6453 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006454 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006455 Examples: >
6456 :echo log(10)
6457< 2.302585 >
6458 :echo log(exp(5))
6459< 5.0
6460
6461 Can also be used as a |method|: >
6462 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006463<
6464 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006465
6466
6467log10({expr}) *log10()*
6468 Return the logarithm of Float {expr} to base 10 as a |Float|.
6469 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006470 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471 Examples: >
6472 :echo log10(1000)
6473< 3.0 >
6474 :echo log10(0.01)
6475< -2.0
6476
6477 Can also be used as a |method|: >
6478 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006479<
6480 Return type: |Float|
6481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006482
6483luaeval({expr} [, {expr}]) *luaeval()*
6484 Evaluate Lua expression {expr} and return its result converted
6485 to Vim data structures. Second {expr} may hold additional
6486 argument accessible as _A inside first {expr}.
6487 Strings are returned as they are.
6488 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006489 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006490 Dictionaries and lists obtained by vim.eval() are returned
6491 as-is.
6492 Other objects are returned as zero without any errors.
6493 See |lua-luaeval| for more details.
6494 Note that in a `:def` function local variables are not visible
6495 to {expr}.
6496
6497 Can also be used as a |method|: >
6498 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006499<
6500 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006501
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006502 {only available when compiled with the |+lua| feature}
6503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006504
6505map({expr1}, {expr2}) *map()*
6506 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006507 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006508 item in {expr1} with the result of evaluating {expr2}.
6509 For a |Blob| each byte is replaced.
6510 For a |String|, each character, including composing
6511 characters, is replaced.
6512 If the item type changes you may want to use |mapnew()| to
6513 create a new List or Dictionary. This is required when using
6514 Vim9 script.
6515
6516 {expr2} must be a |String| or |Funcref|.
6517
6518 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6519 of the current item. For a |Dictionary| |v:key| has the key
6520 of the current item and for a |List| |v:key| has the index of
6521 the current item. For a |Blob| |v:key| has the index of the
6522 current byte. For a |String| |v:key| has the index of the
6523 current character.
6524 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006525 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526< This puts "> " before and " <" after each item in "mylist".
6527
6528 Note that {expr2} is the result of an expression and is then
6529 used as an expression again. Often it is good to use a
6530 |literal-string| to avoid having to double backslashes. You
6531 still have to double ' quotes
6532
6533 If {expr2} is a |Funcref| it is called with two arguments:
6534 1. The key or the index of the current item.
6535 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006536 With a legacy script lambda you don't get an error if it only
6537 accepts one argument, but with a Vim9 lambda you get "E1106:
6538 One argument too many", the number of arguments must match.
6539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006540 The function must return the new value of the item. Example
6541 that changes each value by "key-value": >
6542 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006543 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006544 endfunc
6545 call map(myDict, function('KeyValue'))
6546< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006547 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006548< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006549 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006550< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006551 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006552<
6553 The operation is done in-place for a |List| and |Dictionary|.
6554 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006555 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006556
6557< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6558 or a new |Blob| or |String|.
6559 When an error is encountered while evaluating {expr2} no
6560 further items in {expr1} are processed.
6561 When {expr2} is a Funcref errors inside a function are ignored,
6562 unless it was defined with the "abort" flag.
6563
6564 Can also be used as a |method|: >
6565 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006566<
6567 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6568 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006569
6570
6571maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6572 When {dict} is omitted or zero: Return the rhs of mapping
6573 {name} in mode {mode}. The returned String has special
6574 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006575 listing. When {dict} is TRUE a dictionary is returned, see
6576 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006577
6578 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006579 returned if {dict} is FALSE, otherwise returns an empty Dict.
6580 When the mapping for {name} is empty, then "<Nop>" is
6581 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006582
6583 The {name} can have special key names, like in the ":map"
6584 command.
6585
6586 {mode} can be one of these strings:
6587 "n" Normal
6588 "v" Visual (including Select)
6589 "o" Operator-pending
6590 "i" Insert
6591 "c" Cmd-line
6592 "s" Select
6593 "x" Visual
6594 "l" langmap |language-mapping|
6595 "t" Terminal-Job
6596 "" Normal, Visual and Operator-pending
6597 When {mode} is omitted, the modes for "" are used.
6598
6599 When {abbr} is there and it is |TRUE| use abbreviations
6600 instead of mappings.
6601
6602 When {dict} is there and it is |TRUE| return a dictionary
6603 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006604 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006605 "lhs" The {lhs} of the mapping as it would be typed
6606 "lhsraw" The {lhs} of the mapping as raw bytes
6607 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6608 form, only present when it differs from "lhsraw"
6609 "rhs" The {rhs} of the mapping as typed.
6610 "silent" 1 for a |:map-silent| mapping, else 0.
6611 "noremap" 1 if the {rhs} of the mapping is not remappable.
6612 "script" 1 if mapping was defined with <script>.
6613 "expr" 1 for an expression mapping (|:map-<expr>|).
6614 "buffer" 1 for a buffer local mapping (|:map-local|).
6615 "mode" Modes for which the mapping is defined. In
6616 addition to the modes mentioned above, these
6617 characters will be used:
6618 " " Normal, Visual and Operator-pending
6619 "!" Insert and Commandline mode
6620 (|mapmode-ic|)
6621 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006622 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006623 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006624 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006625 "lnum" The line number in "sid", zero if unknown.
6626 "nowait" Do not wait for other, longer mappings.
6627 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006628 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006629 "mode_bits" Vim's internal binary representation of "mode".
6630 |mapset()| ignores this; only "mode" is used.
6631 See |maplist()| for usage examples. The values
6632 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006633
6634 The dictionary can be used to restore a mapping with
6635 |mapset()|.
6636
6637 The mappings local to the current buffer are checked first,
6638 then the global mappings.
6639 This function can be used to map a key even when it's already
6640 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006641 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006642
6643< Can also be used as a |method|: >
6644 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006645<
6646 Return type: |String| or dict<any> depending on {dict}
6647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006648
6649mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6650 Check if there is a mapping that matches with {name} in mode
6651 {mode}. See |maparg()| for {mode} and special names in
6652 {name}.
6653 When {abbr} is there and it is |TRUE| use abbreviations
6654 instead of mappings.
6655 A match happens with a mapping that starts with {name} and
6656 with a mapping which is equal to the start of {name}.
6657
6658 matches mapping "a" "ab" "abc" ~
6659 mapcheck("a") yes yes yes
6660 mapcheck("abc") yes yes yes
6661 mapcheck("ax") yes no no
6662 mapcheck("b") no no no
6663
6664 The difference with maparg() is that mapcheck() finds a
6665 mapping that matches with {name}, while maparg() only finds a
6666 mapping for {name} exactly.
6667 When there is no mapping that starts with {name}, an empty
6668 String is returned. If there is one, the RHS of that mapping
6669 is returned. If there are several mappings that start with
6670 {name}, the RHS of one of them is returned. This will be
6671 "<Nop>" if the RHS is empty.
6672 The mappings local to the current buffer are checked first,
6673 then the global mappings.
6674 This function can be used to check if a mapping can be added
6675 without being ambiguous. Example: >
6676 :if mapcheck("_vv") == ""
6677 : map _vv :set guifont=7x13<CR>
6678 :endif
6679< This avoids adding the "_vv" mapping when there already is a
6680 mapping for "_v" or for "_vvv".
6681
6682 Can also be used as a |method|: >
6683 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006684<
6685 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006686
6687
Ernie Rael09661202022-04-25 14:40:44 +01006688maplist([{abbr}]) *maplist()*
6689 Returns a |List| of all mappings. Each List item is a |Dict|,
6690 the same as what is returned by |maparg()|, see
6691 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6692 abbreviations instead of mappings.
6693
6694 Example to show all mappings with 'MultiMatch' in rhs: >
6695 vim9script
6696 echo maplist()->filter(
6697 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006698< It can be tricky to find mappings for particular |:map-modes|.
6699 |mapping-dict|'s "mode_bits" can simplify this. For example,
6700 the mode_bits for Normal, Insert or Command-line modes are
6701 0x19. To find all the mappings available in those modes you
6702 can do: >
6703 vim9script
6704 var saved_maps = []
6705 for m in maplist()
6706 if and(m.mode_bits, 0x19) != 0
6707 saved_maps->add(m)
6708 endif
6709 endfor
6710 echo saved_maps->mapnew((_, m) => m.lhs)
6711< The values of the mode_bits are defined in Vim's src/vim.h
6712 file and they can be discovered at runtime using
6713 |:map-commands| and "maplist()". Example: >
6714 vim9script
6715 omap xyzzy <Nop>
6716 var op_bit = maplist()->filter(
6717 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6718 ounmap xyzzy
6719 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006720<
6721 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006722
6723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006724mapnew({expr1}, {expr2}) *mapnew()*
6725 Like |map()| but instead of replacing items in {expr1} a new
6726 List or Dictionary is created and returned. {expr1} remains
6727 unchanged. Items can still be changed by {expr2}, if you
6728 don't want that use |deepcopy()| first.
6729
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006730 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6731 depending on {expr1}
6732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006733
6734mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006735mapset({dict})
6736 Restore a mapping from a dictionary, possibly returned by
6737 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6738 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006739 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006740 feature allows copying mappings from one buffer to another.
6741 The dict.mode value may restore a single mapping that covers
6742 more than one mode, like with mode values of '!', ' ', 'nox',
6743 or 'v'. *E1276*
6744
6745 In the first form, {mode} and {abbr} should be the same as
6746 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006747 {mode} is used to define the mode in which the mapping is set,
6748 not the "mode" entry in {dict}.
6749 Example for saving and restoring a mapping: >
6750 let save_map = maparg('K', 'n', 0, 1)
6751 nnoremap K somethingelse
6752 ...
6753 call mapset('n', 0, save_map)
6754< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006755 e.g. with `:map!`, you need to save/restore the mapping for
6756 all of them, when they might differ.
6757
6758 In the second form, with {dict} as the only argument, mode
6759 and abbr are taken from the dict.
6760 Example: >
6761 vim9script
6762 var save_maps = maplist()->filter(
6763 (_, m) => m.lhs == 'K')
6764 nnoremap K somethingelse
6765 cnoremap K somethingelse2
6766 # ...
6767 unmap K
6768 for d in save_maps
6769 mapset(d)
6770 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006771<
6772 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006773
6774
6775match({expr}, {pat} [, {start} [, {count}]]) *match()*
6776 When {expr} is a |List| then this returns the index of the
6777 first item where {pat} matches. Each item is used as a
6778 String, |Lists| and |Dictionaries| are used as echoed.
6779
6780 Otherwise, {expr} is used as a String. The result is a
6781 Number, which gives the index (byte offset) in {expr} where
6782 {pat} matches.
6783
6784 A match at the first character or |List| item returns zero.
6785 If there is no match -1 is returned.
6786
6787 For getting submatches see |matchlist()|.
6788 Example: >
6789 :echo match("testing", "ing") " results in 4
6790 :echo match([1, 'x'], '\a') " results in 1
6791< See |string-match| for how {pat} is used.
6792 *strpbrk()*
6793 Vim doesn't have a strpbrk() function. But you can do: >
6794 :let sepidx = match(line, '[.,;: \t]')
6795< *strcasestr()*
6796 Vim doesn't have a strcasestr() function. But you can add
6797 "\c" to the pattern to ignore case: >
6798 :let idx = match(haystack, '\cneedle')
6799<
6800 If {start} is given, the search starts from byte index
6801 {start} in a String or item {start} in a |List|.
6802 The result, however, is still the index counted from the
6803 first character/item. Example: >
6804 :echo match("testing", "ing", 2)
6805< result is again "4". >
6806 :echo match("testing", "ing", 4)
6807< result is again "4". >
6808 :echo match("testing", "t", 2)
6809< result is "3".
6810 For a String, if {start} > 0 then it is like the string starts
6811 {start} bytes later, thus "^" will match at {start}. Except
6812 when {count} is given, then it's like matches before the
6813 {start} byte are ignored (this is a bit complicated to keep it
6814 backwards compatible).
6815 For a String, if {start} < 0, it will be set to 0. For a list
6816 the index is counted from the end.
6817 If {start} is out of range ({start} > strlen({expr}) for a
6818 String or {start} > len({expr}) for a |List|) -1 is returned.
6819
6820 When {count} is given use the {count}'th match. When a match
6821 is found in a String the search for the next one starts one
6822 character further. Thus this example results in 1: >
6823 echo match("testing", "..", 0, 2)
6824< In a |List| the search continues in the next item.
6825 Note that when {count} is added the way {start} works changes,
6826 see above.
6827
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006828 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006829 See |pattern| for the patterns that are accepted.
6830 The 'ignorecase' option is used to set the ignore-caseness of
6831 the pattern. 'smartcase' is NOT used. The matching is always
6832 done like 'magic' is set and 'cpoptions' is empty.
6833 Note that a match at the start is preferred, thus when the
6834 pattern is using "*" (any number of matches) it tends to find
6835 zero matches at the start instead of a number of matches
6836 further down in the text.
6837
6838 Can also be used as a |method|: >
6839 GetText()->match('word')
6840 GetList()->match('word')
6841<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006842 Return type: |Number|
6843
6844
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006845 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006846matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6847 Defines a pattern to be highlighted in the current window (a
6848 "match"). It will be highlighted with {group}. Returns an
6849 identification number (ID), which can be used to delete the
6850 match using |matchdelete()|. The ID is bound to the window.
6851 Matching is case sensitive and magic, unless case sensitivity
6852 or magicness are explicitly overridden in {pattern}. The
6853 'magic', 'smartcase' and 'ignorecase' options are not used.
6854 The "Conceal" value is special, it causes the match to be
6855 concealed.
6856
6857 The optional {priority} argument assigns a priority to the
6858 match. A match with a high priority will have its
6859 highlighting overrule that of a match with a lower priority.
6860 A priority is specified as an integer (negative numbers are no
6861 exception). If the {priority} argument is not specified, the
6862 default priority is 10. The priority of 'hlsearch' is zero,
6863 hence all matches with a priority greater than zero will
6864 overrule it. Syntax highlighting (see 'syntax') is a separate
6865 mechanism, and regardless of the chosen priority a match will
6866 always overrule syntax highlighting.
6867
6868 The optional {id} argument allows the request for a specific
6869 match ID. If a specified ID is already taken, an error
6870 message will appear and the match will not be added. An ID
6871 is specified as a positive integer (zero excluded). IDs 1, 2
6872 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006873 respectively. 3 is reserved for use by the |matchparen|
6874 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006875 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006876 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006877
6878 The optional {dict} argument allows for further custom
6879 values. Currently this is used to specify a match specific
6880 conceal character that will be shown for |hl-Conceal|
6881 highlighted matches. The dict can have the following members:
6882
6883 conceal Special character to show instead of the
6884 match (only for |hl-Conceal| highlighted
6885 matches, see |:syn-cchar|)
6886 window Instead of the current window use the
6887 window with this number or window ID.
6888
6889 The number of matches is not limited, as it is the case with
6890 the |:match| commands.
6891
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006892 Returns -1 on error.
6893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006894 Example: >
6895 :highlight MyGroup ctermbg=green guibg=green
6896 :let m = matchadd("MyGroup", "TODO")
6897< Deletion of the pattern: >
6898 :call matchdelete(m)
6899
6900< A list of matches defined by |matchadd()| and |:match| are
6901 available from |getmatches()|. All matches can be deleted in
6902 one operation by |clearmatches()|.
6903
6904 Can also be used as a |method|: >
6905 GetGroup()->matchadd('TODO')
6906<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006907 Return type: |Number|
6908
6909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006910 *matchaddpos()*
6911matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6912 Same as |matchadd()|, but requires a list of positions {pos}
6913 instead of a pattern. This command is faster than |matchadd()|
6914 because it does not require to handle regular expressions and
6915 sets buffer line boundaries to redraw screen. It is supposed
6916 to be used when fast match additions and deletions are
6917 required, for example to highlight matching parentheses.
6918
6919 {pos} is a list of positions. Each position can be one of
6920 these:
6921 - A number. This whole line will be highlighted. The first
6922 line has number 1.
6923 - A list with one number, e.g., [23]. The whole line with this
6924 number will be highlighted.
6925 - A list with two numbers, e.g., [23, 11]. The first number is
6926 the line number, the second one is the column number (first
6927 column is 1, the value must correspond to the byte index as
6928 |col()| would return). The character at this position will
6929 be highlighted.
6930 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6931 the third number gives the length of the highlight in bytes.
6932
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006933 Returns -1 on error.
6934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006935 Example: >
6936 :highlight MyGroup ctermbg=green guibg=green
6937 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6938< Deletion of the pattern: >
6939 :call matchdelete(m)
6940
6941< Matches added by |matchaddpos()| are returned by
6942 |getmatches()|.
6943
6944 Can also be used as a |method|: >
6945 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006946<
6947 Return type: |Number|
6948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006949
6950matcharg({nr}) *matcharg()*
6951 Selects the {nr} match item, as set with a |:match|,
6952 |:2match| or |:3match| command.
6953 Return a |List| with two elements:
6954 The name of the highlight group used
6955 The pattern used.
6956 When {nr} is not 1, 2 or 3 returns an empty |List|.
6957 When there is no match item set returns ['', ''].
6958 This is useful to save and restore a |:match|.
6959 Highlighting matches using the |:match| commands are limited
6960 to three matches. |matchadd()| does not have this limitation.
6961
6962 Can also be used as a |method|: >
6963 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006964<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006965 Return type: list<string>
6966
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006967 *matchbufline()*
6968matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6969 Returns the |List| of matches in lines from {lnum} to {end} in
6970 buffer {buf} where {pat} matches.
6971
6972 {lnum} and {end} can either be a line number or the string "$"
6973 to refer to the last line in {buf}.
6974
6975 The {dict} argument supports following items:
6976 submatches include submatch information (|/\(|)
6977
6978 For each match, a |Dict| with the following items is returned:
6979 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006980 lnum line number where there is a match
6981 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006982 Note that there can be multiple matches in a single line.
6983
6984 This function works only for loaded buffers. First call
6985 |bufload()| if needed.
6986
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006987 See |match-pattern| for information about the effect of some
6988 option settings on the pattern.
6989
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006990 When {buf} is not a valid buffer, the buffer is not loaded or
6991 {lnum} or {end} is not valid then an error is given and an
6992 empty |List| is returned.
6993
6994 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006995 " Assuming line 3 in buffer 5 contains "a"
6996 :echo matchbufline(5, '\<\k\+\>', 3, 3)
6997 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6998 " Assuming line 4 in buffer 10 contains "tik tok"
6999 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7000 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007001<
7002 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007003 "\1", "\2", etc. are also returned. Example: >
7004 " Assuming line 2 in buffer 2 contains "acd"
7005 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007006 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007007 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007008< The "submatches" List always contains 9 items. If a submatch
7009 is not found, then an empty string is returned for that
7010 submatch.
7011
7012 Can also be used as a |method|: >
7013 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007014<
7015 Return type: list<dict<any>> or list<any>
7016
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007017
7018matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
7019 Deletes a match with ID {id} previously defined by |matchadd()|
7020 or one of the |:match| commands. Returns 0 if successful,
7021 otherwise -1. See example for |matchadd()|. All matches can
7022 be deleted in one operation by |clearmatches()|.
7023 If {win} is specified, use the window with this number or
7024 window ID instead of the current window.
7025
7026 Can also be used as a |method|: >
7027 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007028<
7029 Return type: |Number|
7030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007031
7032matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7033 Same as |match()|, but return the index of first character
7034 after the match. Example: >
7035 :echo matchend("testing", "ing")
7036< results in "7".
7037 *strspn()* *strcspn()*
7038 Vim doesn't have a strspn() or strcspn() function, but you can
7039 do it with matchend(): >
7040 :let span = matchend(line, '[a-zA-Z]')
7041 :let span = matchend(line, '[^a-zA-Z]')
7042< Except that -1 is returned when there are no matches.
7043
7044 The {start}, if given, has the same meaning as for |match()|. >
7045 :echo matchend("testing", "ing", 2)
7046< results in "7". >
7047 :echo matchend("testing", "ing", 5)
7048< result is "-1".
7049 When {expr} is a |List| the result is equal to |match()|.
7050
7051 Can also be used as a |method|: >
7052 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007053<
7054 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007055
7056
7057matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7058 If {list} is a list of strings, then returns a |List| with all
7059 the strings in {list} that fuzzy match {str}. The strings in
7060 the returned list are sorted based on the matching score.
7061
7062 The optional {dict} argument always supports the following
7063 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007064 matchseq When this item is present return only matches
7065 that contain the characters in {str} in the
7066 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007067 limit Maximum number of matches in {list} to be
7068 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007069
7070 If {list} is a list of dictionaries, then the optional {dict}
7071 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007072 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007073 {str}. The value of this item should be a
7074 string.
7075 text_cb |Funcref| that will be called for every item
7076 in {list} to get the text for fuzzy matching.
7077 This should accept a dictionary item as the
7078 argument and return the text for that item to
7079 use for fuzzy matching.
7080
7081 {str} is treated as a literal string and regular expression
7082 matching is NOT supported. The maximum supported {str} length
7083 is 256.
7084
7085 When {str} has multiple words each separated by white space,
7086 then the list of strings that have all the words is returned.
7087
7088 If there are no matching strings or there is an error, then an
7089 empty list is returned. If length of {str} is greater than
7090 256, then returns an empty list.
7091
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007092 When {limit} is given, matchfuzzy() will find up to this
7093 number of matches in {list} and return them in sorted order.
7094
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007095 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007096 matching strings.
7097
7098 Example: >
7099 :echo matchfuzzy(["clay", "crow"], "cay")
7100< results in ["clay"]. >
7101 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7102< results in a list of buffer names fuzzy matching "ndl". >
7103 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7104< results in a list of buffer information dicts with buffer
7105 names fuzzy matching "ndl". >
7106 :echo getbufinfo()->matchfuzzy("spl",
7107 \ {'text_cb' : {v -> v.name}})
7108< results in a list of buffer information dicts with buffer
7109 names fuzzy matching "spl". >
7110 :echo v:oldfiles->matchfuzzy("test")
7111< results in a list of file names fuzzy matching "test". >
7112 :let l = readfile("buffer.c")->matchfuzzy("str")
7113< results in a list of lines in "buffer.c" fuzzy matching "str". >
7114 :echo ['one two', 'two one']->matchfuzzy('two one')
7115< results in ['two one', 'one two']. >
7116 :echo ['one two', 'two one']->matchfuzzy('two one',
7117 \ {'matchseq': 1})
7118< results in ['two one'].
7119
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007120 Return type: list<string> or list<any>
7121
7122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007123matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7124 Same as |matchfuzzy()|, but returns the list of matched
7125 strings, the list of character positions where characters
7126 in {str} matches and a list of matching scores. You can
7127 use |byteidx()| to convert a character position to a byte
7128 position.
7129
7130 If {str} matches multiple times in a string, then only the
7131 positions for the best match is returned.
7132
7133 If there are no matching strings or there is an error, then a
7134 list with three empty list items is returned.
7135
7136 Example: >
7137 :echo matchfuzzypos(['testing'], 'tsg')
7138< results in [['testing'], [[0, 2, 6]], [99]] >
7139 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7140< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7141 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7142< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7143
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007144 Return type: list<list<any>>
7145
7146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007147matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7148 Same as |match()|, but return a |List|. The first item in the
7149 list is the matched string, same as what matchstr() would
7150 return. Following items are submatches, like "\1", "\2", etc.
7151 in |:substitute|. When an optional submatch didn't match an
7152 empty string is used. Example: >
7153 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7154< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7155 When there is no match an empty list is returned.
7156
7157 You can pass in a List, but that is not very useful.
7158
7159 Can also be used as a |method|: >
7160 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007161<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007162 Return type: list<string> or list<any>
7163
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007164 *matchstrlist()*
7165matchstrlist({list}, {pat} [, {dict}])
7166 Returns the |List| of matches in {list} where {pat} matches.
7167 {list} is a |List| of strings. {pat} is matched against each
7168 string in {list}.
7169
7170 The {dict} argument supports following items:
7171 submatches include submatch information (|/\(|)
7172
7173 For each match, a |Dict| with the following items is returned:
7174 byteidx starting byte index of the match.
7175 idx index in {list} of the match.
7176 text matched string
7177 submatches a List of submatches. Present only if
7178 "submatches" is set to v:true in {dict}.
7179
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007180 See |match-pattern| for information about the effect of some
7181 option settings on the pattern.
7182
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007183 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007184 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7185 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7186 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7187 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007188<
7189 If "submatches" is present and is v:true, then submatches like
7190 "\1", "\2", etc. are also returned. Example: >
7191 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7192 \ #{submatches: v:true})
7193 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7194< The "submatches" List always contains 9 items. If a submatch
7195 is not found, then an empty string is returned for that
7196 submatch.
7197
7198 Can also be used as a |method|: >
7199 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007200<
7201 Return type: list<dict<any>> or list<any>
7202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007203
7204matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7205 Same as |match()|, but return the matched string. Example: >
7206 :echo matchstr("testing", "ing")
7207< results in "ing".
7208 When there is no match "" is returned.
7209 The {start}, if given, has the same meaning as for |match()|. >
7210 :echo matchstr("testing", "ing", 2)
7211< results in "ing". >
7212 :echo matchstr("testing", "ing", 5)
7213< result is "".
7214 When {expr} is a |List| then the matching item is returned.
7215 The type isn't changed, it's not necessarily a String.
7216
7217 Can also be used as a |method|: >
7218 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007219<
7220 Return type: |String|
7221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007222
7223matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7224 Same as |matchstr()|, but return the matched string, the start
7225 position and the end position of the match. Example: >
7226 :echo matchstrpos("testing", "ing")
7227< results in ["ing", 4, 7].
7228 When there is no match ["", -1, -1] is returned.
7229 The {start}, if given, has the same meaning as for |match()|. >
7230 :echo matchstrpos("testing", "ing", 2)
7231< results in ["ing", 4, 7]. >
7232 :echo matchstrpos("testing", "ing", 5)
7233< result is ["", -1, -1].
7234 When {expr} is a |List| then the matching item, the index
7235 of first item where {pat} matches, the start position and the
7236 end position of the match are returned. >
7237 :echo matchstrpos([1, '__x'], '\a')
7238< result is ["x", 1, 2, 3].
7239 The type isn't changed, it's not necessarily a String.
7240
7241 Can also be used as a |method|: >
7242 GetText()->matchstrpos('word')
7243<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007244 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007245
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007246
7247max({expr}) *max()*
7248 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007249 echo max([apples, pears, oranges])
7250
7251< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7252 it returns the maximum of all values in the Dictionary.
7253 If {expr} is neither a List nor a Dictionary, or one of the
7254 items in {expr} cannot be used as a Number this results in
7255 an error. An empty |List| or |Dictionary| results in zero.
7256
7257 Can also be used as a |method|: >
7258 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007259<
7260 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007261
7262
7263menu_info({name} [, {mode}]) *menu_info()*
7264 Return information about the specified menu {name} in
7265 mode {mode}. The menu name should be specified without the
7266 shortcut character ('&'). If {name} is "", then the top-level
7267 menu names are returned.
7268
7269 {mode} can be one of these strings:
7270 "n" Normal
7271 "v" Visual (including Select)
7272 "o" Operator-pending
7273 "i" Insert
7274 "c" Cmd-line
7275 "s" Select
7276 "x" Visual
7277 "t" Terminal-Job
7278 "" Normal, Visual and Operator-pending
7279 "!" Insert and Cmd-line
7280 When {mode} is omitted, the modes for "" are used.
7281
7282 Returns a |Dictionary| containing the following items:
7283 accel menu item accelerator text |menu-text|
7284 display display name (name without '&')
7285 enabled v:true if this menu item is enabled
7286 Refer to |:menu-enable|
7287 icon name of the icon file (for toolbar)
7288 |toolbar-icon|
7289 iconidx index of a built-in icon
7290 modes modes for which the menu is defined. In
7291 addition to the modes mentioned above, these
7292 characters will be used:
7293 " " Normal, Visual and Operator-pending
7294 name menu item name.
7295 noremenu v:true if the {rhs} of the menu item is not
7296 remappable else v:false.
7297 priority menu order priority |menu-priority|
7298 rhs right-hand-side of the menu item. The returned
7299 string has special characters translated like
7300 in the output of the ":menu" command listing.
7301 When the {rhs} of a menu item is empty, then
7302 "<Nop>" is returned.
7303 script v:true if script-local remapping of {rhs} is
7304 allowed else v:false. See |:menu-script|.
7305 shortcut shortcut key (character after '&' in
7306 the menu name) |menu-shortcut|
7307 silent v:true if the menu item is created
7308 with <silent> argument |:menu-silent|
7309 submenus |List| containing the names of
7310 all the submenus. Present only if the menu
7311 item has submenus.
7312
7313 Returns an empty dictionary if the menu item is not found.
7314
7315 Examples: >
7316 :echo menu_info('Edit.Cut')
7317 :echo menu_info('File.Save', 'n')
7318
7319 " Display the entire menu hierarchy in a buffer
7320 func ShowMenu(name, pfx)
7321 let m = menu_info(a:name)
7322 call append(line('$'), a:pfx .. m.display)
7323 for child in m->get('submenus', [])
7324 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7325 \ a:pfx .. ' ')
7326 endfor
7327 endfunc
7328 new
7329 for topmenu in menu_info('').submenus
7330 call ShowMenu(topmenu, '')
7331 endfor
7332<
7333 Can also be used as a |method|: >
7334 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007335<
7336 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007337
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007338min({expr}) *min()*
7339 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007340 echo min([apples, pears, oranges])
7341
7342< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7343 it returns the minimum of all values in the Dictionary.
7344 If {expr} is neither a List nor a Dictionary, or one of the
7345 items in {expr} cannot be used as a Number this results in
7346 an error. An empty |List| or |Dictionary| results in zero.
7347
7348 Can also be used as a |method|: >
7349 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007350<
7351 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007352
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007353
7354mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007355 Create directory {name}.
7356
Bram Moolenaar938ae282023-02-20 20:44:55 +00007357 When {flags} is present it must be a string. An empty string
7358 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007359
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007360 {flags} can contain these character flags:
7361 "p" intermediate directories will be created as necessary
7362 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007363 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007364 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007365 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007366
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007367 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007368 some directories may already exist. Only the first one that
7369 is created and what it contains is scheduled to be deleted.
7370 E.g. when using: >
7371 call mkdir('subdir/tmp/autoload', 'pR')
7372< and "subdir" already exists then "subdir/tmp" will be
7373 scheduled for deletion, like with: >
7374 defer delete('subdir/tmp', 'rf')
7375< Note that if scheduling the defer fails the directory is not
7376 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007377
7378 If {prot} is given it is used to set the protection bits of
7379 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7380 the user, readable for others). Use 0o700 to make it
7381 unreadable for others. This is only used for the last part of
7382 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7383 created with 0o755.
7384 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007385 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007386
7387< This function is not available in the |sandbox|.
7388
7389 There is no error if the directory already exists and the "p"
7390 flag is passed (since patch 8.0.1708). However, without the
7391 "p" option the call will fail.
7392
7393 The function result is a Number, which is TRUE if the call was
7394 successful or FALSE if the directory creation failed or partly
7395 failed.
7396
7397 Not available on all systems. To check use: >
7398 :if exists("*mkdir")
7399
7400< Can also be used as a |method|: >
7401 GetName()->mkdir()
7402<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007403 Return type: |Number|
7404
7405
7406mode([{expr}]) *mode()*
7407 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007408 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007409 a non-empty String (|non-zero-arg|), then the full mode is
7410 returned, otherwise only the first letter is returned.
7411 Also see |state()|.
7412
7413 n Normal
7414 no Operator-pending
7415 nov Operator-pending (forced characterwise |o_v|)
7416 noV Operator-pending (forced linewise |o_V|)
7417 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7418 CTRL-V is one character
7419 niI Normal using |i_CTRL-O| in |Insert-mode|
7420 niR Normal using |i_CTRL-O| in |Replace-mode|
7421 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7422 nt Terminal-Normal (insert goes to Terminal-Job mode)
7423 v Visual by character
7424 vs Visual by character using |v_CTRL-O| in Select mode
7425 V Visual by line
7426 Vs Visual by line using |v_CTRL-O| in Select mode
7427 CTRL-V Visual blockwise
7428 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7429 s Select by character
7430 S Select by line
7431 CTRL-S Select blockwise
7432 i Insert
7433 ic Insert mode completion |compl-generic|
7434 ix Insert mode |i_CTRL-X| completion
7435 R Replace |R|
7436 Rc Replace mode completion |compl-generic|
7437 Rx Replace mode |i_CTRL-X| completion
7438 Rv Virtual Replace |gR|
7439 Rvc Virtual Replace mode completion |compl-generic|
7440 Rvx Virtual Replace mode |i_CTRL-X| completion
7441 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007442 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007443 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007444 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007445 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007446 ce Normal Ex mode |Q|
7447 r Hit-enter prompt
7448 rm The -- more -- prompt
7449 r? A |:confirm| query of some sort
7450 ! Shell or external command is executing
7451 t Terminal-Job mode: keys go to the job
7452
7453 This is useful in the 'statusline' option or when used
7454 with |remote_expr()| In most other places it always returns
7455 "c" or "n".
7456 Note that in the future more modes and more specific modes may
7457 be added. It's better not to compare the whole string but only
7458 the leading character(s).
7459 Also see |visualmode()|.
7460
7461 Can also be used as a |method|: >
7462 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007463<
7464 Return type: |String|
7465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007466
7467mzeval({expr}) *mzeval()*
7468 Evaluate MzScheme expression {expr} and return its result
7469 converted to Vim data structures.
7470 Numbers and strings are returned as they are.
7471 Pairs (including lists and improper lists) and vectors are
7472 returned as Vim |Lists|.
7473 Hash tables are represented as Vim |Dictionary| type with keys
7474 converted to strings.
7475 All other types are converted to string with display function.
7476 Examples: >
7477 :mz (define l (list 1 2 3))
7478 :mz (define h (make-hash)) (hash-set! h "list" l)
7479 :echo mzeval("l")
7480 :echo mzeval("h")
7481<
7482 Note that in a `:def` function local variables are not visible
7483 to {expr}.
7484
7485 Can also be used as a |method|: >
7486 GetExpr()->mzeval()
7487<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007488 Return type: any, depending on {expr}
7489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007490 {only available when compiled with the |+mzscheme| feature}
7491
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007493nextnonblank({lnum}) *nextnonblank()*
7494 Return the line number of the first line at or below {lnum}
7495 that is not blank. Example: >
7496 if getline(nextnonblank(1)) =~ "Java"
7497< When {lnum} is invalid or there is no non-blank line at or
7498 below it, zero is returned.
7499 {lnum} is used like with |getline()|.
7500 See also |prevnonblank()|.
7501
7502 Can also be used as a |method|: >
7503 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007504<
7505 Return type: |Number|
7506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007507
7508nr2char({expr} [, {utf8}]) *nr2char()*
7509 Return a string with a single character, which has the number
7510 value {expr}. Examples: >
7511 nr2char(64) returns "@"
7512 nr2char(32) returns " "
7513< When {utf8} is omitted or zero, the current 'encoding' is used.
7514 Example for "utf-8": >
7515 nr2char(300) returns I with bow character
7516< When {utf8} is TRUE, always return UTF-8 characters.
7517 Note that a NUL character in the file is specified with
7518 nr2char(10), because NULs are represented with newline
7519 characters. nr2char(0) is a real NUL and terminates the
7520 string, thus results in an empty string.
7521 To turn a list of character numbers into a string: >
7522 let list = [65, 66, 67]
7523 let str = join(map(list, {_, val -> nr2char(val)}), '')
7524< Result: "ABC"
7525
7526 Can also be used as a |method|: >
7527 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007528<
7529 Return type: |String|
7530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007531
7532or({expr}, {expr}) *or()*
7533 Bitwise OR on the two arguments. The arguments are converted
7534 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007535 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007536 Example: >
7537 :let bits = or(bits, 0x80)
7538< Can also be used as a |method|: >
7539 :let bits = bits->or(0x80)
7540
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007541< Rationale: The reason this is a function and not using the "|"
7542 character like many languages, is that Vi has always used "|"
7543 to separate commands. In many places it would not be clear if
7544 "|" is an operator or a command separator.
7545
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007546 Return type: |Number|
7547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007548
7549pathshorten({path} [, {len}]) *pathshorten()*
7550 Shorten directory names in the path {path} and return the
7551 result. The tail, the file name, is kept as-is. The other
7552 components in the path are reduced to {len} letters in length.
7553 If {len} is omitted or smaller than 1 then 1 is used (single
7554 letters). Leading '~' and '.' characters are kept. Examples: >
7555 :echo pathshorten('~/.vim/autoload/myfile.vim')
7556< ~/.v/a/myfile.vim ~
7557>
7558 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7559< ~/.vi/au/myfile.vim ~
7560 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007561 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007562
7563 Can also be used as a |method|: >
7564 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007565<
7566 Return type: |String|
7567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007568
7569perleval({expr}) *perleval()*
7570 Evaluate Perl expression {expr} in scalar context and return
7571 its result converted to Vim data structures. If value can't be
7572 converted, it is returned as a string Perl representation.
7573 Note: If you want an array or hash, {expr} must return a
7574 reference to it.
7575 Example: >
7576 :echo perleval('[1 .. 4]')
7577< [1, 2, 3, 4]
7578
7579 Note that in a `:def` function local variables are not visible
7580 to {expr}.
7581
7582 Can also be used as a |method|: >
7583 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007584<
7585 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007586
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007587 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007588
7589
7590popup_ functions are documented here: |popup-functions|
7591
7592
7593pow({x}, {y}) *pow()*
7594 Return the power of {x} to the exponent {y} as a |Float|.
7595 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007596 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007597 Examples: >
7598 :echo pow(3, 3)
7599< 27.0 >
7600 :echo pow(2, 16)
7601< 65536.0 >
7602 :echo pow(32, 0.20)
7603< 2.0
7604
7605 Can also be used as a |method|: >
7606 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007607<
7608 Return type: |Number|
7609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007610
7611prevnonblank({lnum}) *prevnonblank()*
7612 Return the line number of the first line at or above {lnum}
7613 that is not blank. Example: >
7614 let ind = indent(prevnonblank(v:lnum - 1))
7615< When {lnum} is invalid or there is no non-blank line at or
7616 above it, zero is returned.
7617 {lnum} is used like with |getline()|.
7618 Also see |nextnonblank()|.
7619
7620 Can also be used as a |method|: >
7621 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007622<
7623 Return type: |Number|
7624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007625
7626printf({fmt}, {expr1} ...) *printf()*
7627 Return a String with {fmt}, where "%" items are replaced by
7628 the formatted form of their respective arguments. Example: >
7629 printf("%4d: E%d %.30s", lnum, errno, msg)
7630< May result in:
7631 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7632
7633 When used as a |method| the base is passed as the second
7634 argument: >
7635 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007636<
7637 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007638
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007639 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007640 %s string
7641 %6S string right-aligned in 6 display cells
7642 %6s string right-aligned in 6 bytes
7643 %.9s string truncated to 9 bytes
7644 %c single byte
7645 %d decimal number
7646 %5d decimal number padded with spaces to 5 characters
7647 %x hex number
7648 %04x hex number padded with zeros to at least 4 characters
7649 %X hex number using upper case letters
7650 %o octal number
7651 %08b binary number padded with zeros to at least 8 chars
7652 %f floating point number as 12.23, inf, -inf or nan
7653 %F floating point number as 12.23, INF, -INF or NAN
7654 %e floating point number as 1.23e3, inf, -inf or nan
7655 %E floating point number as 1.23E3, INF, -INF or NAN
7656 %g floating point number, as %f or %e depending on value
7657 %G floating point number, as %F or %E depending on value
7658 %% the % character itself
7659
7660 Conversion specifications start with '%' and end with the
7661 conversion type. All other characters are copied unchanged to
7662 the result.
7663
7664 The "%" starts a conversion specification. The following
7665 arguments appear in sequence:
7666
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007667 % [pos-argument] [flags] [field-width] [.precision] type
7668
7669 pos-argument
7670 At most one positional argument specifier. These
7671 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007672
7673 flags
7674 Zero or more of the following flags:
7675
7676 # The value should be converted to an "alternate
7677 form". For c, d, and s conversions, this option
7678 has no effect. For o conversions, the precision
7679 of the number is increased to force the first
7680 character of the output string to a zero (except
7681 if a zero value is printed with an explicit
7682 precision of zero).
7683 For b and B conversions, a non-zero result has
7684 the string "0b" (or "0B" for B conversions)
7685 prepended to it.
7686 For x and X conversions, a non-zero result has
7687 the string "0x" (or "0X" for X conversions)
7688 prepended to it.
7689
7690 0 (zero) Zero padding. For all conversions the converted
7691 value is padded on the left with zeros rather
7692 than blanks. If a precision is given with a
7693 numeric conversion (d, b, B, o, x, and X), the 0
7694 flag is ignored.
7695
7696 - A negative field width flag; the converted value
7697 is to be left adjusted on the field boundary.
7698 The converted value is padded on the right with
7699 blanks, rather than on the left with blanks or
7700 zeros. A - overrides a 0 if both are given.
7701
7702 ' ' (space) A blank should be left before a positive
7703 number produced by a signed conversion (d).
7704
7705 + A sign must always be placed before a number
7706 produced by a signed conversion. A + overrides
7707 a space if both are used.
7708
7709 field-width
7710 An optional decimal digit string specifying a minimum
7711 field width. If the converted value has fewer bytes
7712 than the field width, it will be padded with spaces on
7713 the left (or right, if the left-adjustment flag has
7714 been given) to fill out the field width. For the S
7715 conversion the count is in cells.
7716
7717 .precision
7718 An optional precision, in the form of a period '.'
7719 followed by an optional digit string. If the digit
7720 string is omitted, the precision is taken as zero.
7721 This gives the minimum number of digits to appear for
7722 d, o, x, and X conversions, the maximum number of
7723 bytes to be printed from a string for s conversions,
7724 or the maximum number of cells to be printed from a
7725 string for S conversions.
7726 For floating point it is the number of digits after
7727 the decimal point.
7728
7729 type
7730 A character that specifies the type of conversion to
7731 be applied, see below.
7732
7733 A field width or precision, or both, may be indicated by an
7734 asterisk '*' instead of a digit string. In this case, a
7735 Number argument supplies the field width or precision. A
7736 negative field width is treated as a left adjustment flag
7737 followed by a positive field width; a negative precision is
7738 treated as though it were missing. Example: >
7739 :echo printf("%d: %.*s", nr, width, line)
7740< This limits the length of the text used from "line" to
7741 "width" bytes.
7742
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007743 If the argument to be formatted is specified using a
7744 positional argument specifier, and a '*' is used to indicate
7745 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007746 precision, the argument(s) to be used must also be specified
7747 using a {n$} positional argument specifier. See |printf-$|.
7748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007749 The conversion specifiers and their meanings are:
7750
7751 *printf-d* *printf-b* *printf-B* *printf-o*
7752 *printf-x* *printf-X*
7753 dbBoxX The Number argument is converted to signed decimal
7754 (d), unsigned binary (b and B), unsigned octal (o), or
7755 unsigned hexadecimal (x and X) notation. The letters
7756 "abcdef" are used for x conversions; the letters
7757 "ABCDEF" are used for X conversions.
7758 The precision, if any, gives the minimum number of
7759 digits that must appear; if the converted value
7760 requires fewer digits, it is padded on the left with
7761 zeros.
7762 In no case does a non-existent or small field width
7763 cause truncation of a numeric field; if the result of
7764 a conversion is wider than the field width, the field
7765 is expanded to contain the conversion result.
7766 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007767 The 'l' modifier indicates the argument is a long
7768 integer. The size will be 32 bits or 64 bits
7769 depending on your platform.
7770 The "ll" modifier indicates the argument is 64 bits.
7771 The b and B conversion specifiers never take a width
7772 modifier and always assume their argument is a 64 bit
7773 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007774 Generally, these modifiers are not useful. They are
7775 ignored when type is known from the argument.
7776
7777 i alias for d
7778 D alias for ld
7779 U alias for lu
7780 O alias for lo
7781
7782 *printf-c*
7783 c The Number argument is converted to a byte, and the
7784 resulting character is written.
7785
7786 *printf-s*
7787 s The text of the String argument is used. If a
7788 precision is specified, no more bytes than the number
7789 specified are used.
7790 If the argument is not a String type, it is
7791 automatically converted to text with the same format
7792 as ":echo".
7793 *printf-S*
7794 S The text of the String argument is used. If a
7795 precision is specified, no more display cells than the
7796 number specified are used.
7797
7798 *printf-f* *E807*
7799 f F The Float argument is converted into a string of the
7800 form 123.456. The precision specifies the number of
7801 digits after the decimal point. When the precision is
7802 zero the decimal point is omitted. When the precision
7803 is not specified 6 is used. A really big number
7804 (out of range or dividing by zero) results in "inf"
7805 or "-inf" with %f (INF or -INF with %F).
7806 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7807 Example: >
7808 echo printf("%.2f", 12.115)
7809< 12.12
7810 Note that roundoff depends on the system libraries.
7811 Use |round()| when in doubt.
7812
7813 *printf-e* *printf-E*
7814 e E The Float argument is converted into a string of the
7815 form 1.234e+03 or 1.234E+03 when using 'E'. The
7816 precision specifies the number of digits after the
7817 decimal point, like with 'f'.
7818
7819 *printf-g* *printf-G*
7820 g G The Float argument is converted like with 'f' if the
7821 value is between 0.001 (inclusive) and 10000000.0
7822 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7823 for 'G'. When no precision is specified superfluous
7824 zeroes and '+' signs are removed, except for the zero
7825 immediately after the decimal point. Thus 10000000.0
7826 results in 1.0e7.
7827
7828 *printf-%*
7829 % A '%' is written. No argument is converted. The
7830 complete conversion specification is "%%".
7831
7832 When a Number argument is expected a String argument is also
7833 accepted and automatically converted.
7834 When a Float or String argument is expected a Number argument
7835 is also accepted and automatically converted.
7836 Any other argument type results in an error message.
7837
7838 *E766* *E767*
7839 The number of {exprN} arguments must exactly match the number
7840 of "%" items. If there are not sufficient or too many
7841 arguments an error is given. Up to 18 arguments can be used.
7842
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007843 *printf-$*
7844 In certain languages, error and informative messages are
7845 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007846 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007847 having a different word order, positional arguments may be
7848 used to indicate this. For instance: >
7849
h_east596a9f22023-11-21 21:24:23 +09007850 #, c-format
7851 msgid "%s returning %s"
7852 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007853<
h_east596a9f22023-11-21 21:24:23 +09007854 In this example, the sentence has its 2 string arguments
7855 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007856
h_east596a9f22023-11-21 21:24:23 +09007857 echo printf(
7858 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7859 "Bram", "Moolenaar")
7860< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007861
h_east596a9f22023-11-21 21:24:23 +09007862 echo printf(
7863 "In Belgium, vim's creator's name is: %2$s %1$s",
7864 "Bram", "Moolenaar")
7865< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007866
7867 Width (and precision) can be specified using the '*' specifier.
7868 In this case, you must specify the field width position in the
7869 argument list. >
7870
h_east596a9f22023-11-21 21:24:23 +09007871 echo printf("%1$*2$.*3$d", 1, 2, 3)
7872< 001 >
7873 echo printf("%2$*3$.*1$d", 1, 2, 3)
7874< 2 >
7875 echo printf("%3$*1$.*2$d", 1, 2, 3)
7876< 03 >
7877 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7878< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007879
7880 You can mix specifying the width and/or precision directly
7881 and via positional arguments: >
7882
h_east596a9f22023-11-21 21:24:23 +09007883 echo printf("%1$4.*2$f", 1.4142135, 6)
7884< 1.414214 >
7885 echo printf("%1$*2$.4f", 1.4142135, 6)
7886< 1.4142 >
7887 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7888< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007889
Christ van Willegenc35fc032024-03-14 18:30:41 +01007890 You will get an overflow error |E1510|, when the field-width
7891 or precision will result in a string longer than 6400 chars.
7892
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007893 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007894 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007895 echo printf("%s%1$s", "One", "Two")
7896< E1500: Cannot mix positional and non-positional arguments:
7897 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007898
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007899 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007900 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007901 echo printf("%3$s%1$s", "One", "Two", "Three")
7902< E1501: format argument 2 unused in $-style format:
7903 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007904
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007905 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007906 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007907 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7908< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007909
7910 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007911 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7912< E1502: Positional argument 2 used as field width reused as
7913 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007914
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007915 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007916 When a positional argument is used, but not the correct number
7917 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007918 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7919< E1503: Positional argument 3 out of bounds: %1$d at width
7920 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007921
7922 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007923 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7924< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7925 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007926
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007927 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007928 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007929 echo printf("%1$s %2$s %1$s", "One", "Two")
7930< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007931
7932 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007933 echo printf("%1$s %2$s %1$d", "One", "Two")
7934< E1504: Positional argument 1 type used inconsistently:
7935 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007936
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007937 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007938 Various other errors that lead to a format string being
7939 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007940 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7941< E1505: Invalid format specifier: %1$d at width %2$d is:
7942 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007943
Christ van Willegenea746f92023-10-05 20:48:36 +02007944 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007945 This internal error indicates that the logic to parse a
7946 positional format argument ran into a problem that couldn't be
7947 otherwise reported. Please file a bug against Vim if you run
7948 into this, copying the exact format string and parameters that
7949 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007950
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007951 Return type: |String|
7952
Christ van Willegenea746f92023-10-05 20:48:36 +02007953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007954prompt_getprompt({buf}) *prompt_getprompt()*
7955 Returns the effective prompt text for buffer {buf}. {buf} can
7956 be a buffer name or number. See |prompt-buffer|.
7957
7958 If the buffer doesn't exist or isn't a prompt buffer, an empty
7959 string is returned.
7960
7961 Can also be used as a |method|: >
7962 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007963<
7964 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007965
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007966 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007967
7968
7969prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
7970 Set prompt callback for buffer {buf} to {expr}. When {expr}
7971 is an empty string the callback is removed. This has only
7972 effect if {buf} has 'buftype' set to "prompt".
7973
7974 The callback is invoked when pressing Enter. The current
7975 buffer will always be the prompt buffer. A new line for a
7976 prompt is added before invoking the callback, thus the prompt
7977 for which the callback was invoked will be in the last but one
7978 line.
7979 If the callback wants to add text to the buffer, it must
7980 insert it above the last line, since that is where the current
7981 prompt is. This can also be done asynchronously.
7982 The callback is invoked with one argument, which is the text
7983 that was entered at the prompt. This can be an empty string
7984 if the user only typed Enter.
7985 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007986 func s:TextEntered(text)
7987 if a:text == 'exit' || a:text == 'quit'
7988 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007989 " Reset 'modified' to allow the buffer to be closed.
7990 " We assume there is nothing useful to be saved.
7991 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007992 close
7993 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007994 " Do something useful with "a:text". In this example
7995 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007996 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007997 endif
7998 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007999 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008000
8001< Can also be used as a |method|: >
8002 GetBuffer()->prompt_setcallback(callback)
8003
8004< {only available when compiled with the |+channel| feature}
8005
8006prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8007 Set a callback for buffer {buf} to {expr}. When {expr} is an
8008 empty string the callback is removed. This has only effect if
8009 {buf} has 'buftype' set to "prompt".
8010
8011 This callback will be invoked when pressing CTRL-C in Insert
8012 mode. Without setting a callback Vim will exit Insert mode,
8013 as in any buffer.
8014
8015 Can also be used as a |method|: >
8016 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008017<
8018 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008020 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008021
8022prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8023 Set prompt for buffer {buf} to {text}. You most likely want
8024 {text} to end in a space.
8025 The result is only visible if {buf} has 'buftype' set to
8026 "prompt". Example: >
8027 call prompt_setprompt(bufnr(), 'command: ')
8028<
8029 Can also be used as a |method|: >
8030 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008031<
8032 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008034 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008035
8036prop_ functions are documented here: |text-prop-functions|
8037
8038pum_getpos() *pum_getpos()*
8039 If the popup menu (see |ins-completion-menu|) is not visible,
8040 returns an empty |Dictionary|, otherwise, returns a
8041 |Dictionary| with the following keys:
8042 height nr of items visible
8043 width screen cells
8044 row top screen row (0 first row)
8045 col leftmost screen column (0 first col)
8046 size total nr of items
8047 scrollbar |TRUE| if scrollbar is visible
8048
8049 The values are the same as in |v:event| during
8050 |CompleteChanged|.
8051
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008052 Return type: dict<any>
8053
8054
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008055pumvisible() *pumvisible()*
8056 Returns non-zero when the popup menu is visible, zero
8057 otherwise. See |ins-completion-menu|.
8058 This can be used to avoid some things that would remove the
8059 popup menu.
8060
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008061 Return type: |Number|
8062
8063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008064py3eval({expr}) *py3eval()*
8065 Evaluate Python expression {expr} and return its result
8066 converted to Vim data structures.
8067 Numbers and strings are returned as they are (strings are
8068 copied though, Unicode strings are additionally converted to
8069 'encoding').
8070 Lists are represented as Vim |List| type.
8071 Dictionaries are represented as Vim |Dictionary| type with
8072 keys converted to strings.
8073 Note that in a `:def` function local variables are not visible
8074 to {expr}.
8075
8076 Can also be used as a |method|: >
8077 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008078<
8079 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008080
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008081 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008082
8083 *E858* *E859*
8084pyeval({expr}) *pyeval()*
8085 Evaluate Python expression {expr} and return its result
8086 converted to Vim data structures.
8087 Numbers and strings are returned as they are (strings are
8088 copied though).
8089 Lists are represented as Vim |List| type.
8090 Dictionaries are represented as Vim |Dictionary| type,
8091 non-string keys result in error.
8092 Note that in a `:def` function local variables are not visible
8093 to {expr}.
8094
8095 Can also be used as a |method|: >
8096 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008097<
8098 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008099
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008100 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008101
8102pyxeval({expr}) *pyxeval()*
8103 Evaluate Python expression {expr} and return its result
8104 converted to Vim data structures.
8105 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8106 See also: |pyeval()|, |py3eval()|
8107
8108 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008109 < GetExpr()->pyxeval()
8110<
8111 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008112
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008113 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008114 |+python3| feature}
8115
8116rand([{expr}]) *rand()* *random*
8117 Return a pseudo-random Number generated with an xoshiro128**
8118 algorithm using seed {expr}. The returned number is 32 bits,
8119 also on 64 bits systems, for consistency.
8120 {expr} can be initialized by |srand()| and will be updated by
8121 rand(). If {expr} is omitted, an internal seed value is used
8122 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008123 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008124
8125 Examples: >
8126 :echo rand()
8127 :let seed = srand()
8128 :echo rand(seed)
8129 :echo rand(seed) % 16 " random number 0 - 15
8130<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008131 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008132
8133 *E726* *E727*
8134range({expr} [, {max} [, {stride}]]) *range()*
8135 Returns a |List| with Numbers:
8136 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8137 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8138 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8139 {max}] (increasing {expr} with {stride} each time, not
8140 producing a value past {max}).
8141 When the maximum is one before the start the result is an
8142 empty list. When the maximum is more than one before the
8143 start this is an error.
8144 Examples: >
8145 range(4) " [0, 1, 2, 3]
8146 range(2, 4) " [2, 3, 4]
8147 range(2, 9, 3) " [2, 5, 8]
8148 range(2, -2, -1) " [2, 1, 0, -1, -2]
8149 range(0) " []
8150 range(2, 0) " error!
8151<
8152 Can also be used as a |method|: >
8153 GetExpr()->range()
8154<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008155 Return type: list<number>
8156
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008157
K.Takata11df3ae2022-10-19 14:02:40 +01008158readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008159 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008160 If {offset} is specified, read the file from the specified
8161 offset. If it is a negative value, it is used as an offset
8162 from the end of the file. E.g., to read the last 12 bytes: >
8163 readblob('file.bin', -12)
8164< If {size} is specified, only the specified size will be read.
8165 E.g. to read the first 100 bytes of a file: >
8166 readblob('file.bin', 0, 100)
8167< If {size} is -1 or omitted, the whole data starting from
8168 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008169 This can be also used to read the data from a character device
8170 on Unix when {size} is explicitly set. Only if the device
8171 supports seeking {offset} can be used. Otherwise it should be
8172 zero. E.g. to read 10 bytes from a serial console: >
8173 readblob('/dev/ttyS0', 0, 10)
8174< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008175 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008176 When the offset is beyond the end of the file the result is an
8177 empty blob.
8178 When trying to read more bytes than are available the result
8179 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008180 Also see |readfile()| and |writefile()|.
8181
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008182 Return type: |Blob|
8183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008184
8185readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8186 Return a list with file and directory names in {directory}.
8187 You can also use |glob()| if you don't need to do complicated
8188 things, such as limiting the number of matches.
8189 The list will be sorted (case sensitive), see the {dict}
8190 argument below for changing the sort order.
8191
8192 When {expr} is omitted all entries are included.
8193 When {expr} is given, it is evaluated to check what to do:
8194 If {expr} results in -1 then no further entries will
8195 be handled.
8196 If {expr} results in 0 then this entry will not be
8197 added to the list.
8198 If {expr} results in 1 then this entry will be added
8199 to the list.
8200 The entries "." and ".." are always excluded.
8201 Each time {expr} is evaluated |v:val| is set to the entry name.
8202 When {expr} is a function the name is passed as the argument.
8203 For example, to get a list of files ending in ".txt": >
8204 readdir(dirname, {n -> n =~ '.txt$'})
8205< To skip hidden and backup files: >
8206 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008207< *E857*
8208 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008209 values. Currently this is used to specify if and how sorting
8210 should be performed. The dict can have the following members:
8211
8212 sort How to sort the result returned from the system.
8213 Valid values are:
8214 "none" do not sort (fastest method)
8215 "case" sort case sensitive (byte value of
8216 each character, technically, using
8217 strcmp()) (default)
8218 "icase" sort case insensitive (technically
8219 using strcasecmp())
8220 "collate" sort using the collation order
8221 of the "POSIX" or "C" |locale|
8222 (technically using strcoll())
8223 Other values are silently ignored.
8224
8225 For example, to get a list of all files in the current
8226 directory without sorting the individual entries: >
8227 readdir('.', '1', #{sort: 'none'})
8228< If you want to get a directory tree: >
8229 function! s:tree(dir)
8230 return {a:dir : map(readdir(a:dir),
8231 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008232 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008233 endfunction
8234 echo s:tree(".")
8235<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008236 Returns an empty List on error.
8237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008238 Can also be used as a |method|: >
8239 GetDirName()->readdir()
8240<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008241 Return type: list<string> or list<any>
8242
8243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008244readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8245 Extended version of |readdir()|.
8246 Return a list of Dictionaries with file and directory
8247 information in {directory}.
8248 This is useful if you want to get the attributes of file and
8249 directory at the same time as getting a list of a directory.
8250 This is much faster than calling |readdir()| then calling
8251 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8252 each file and directory especially on MS-Windows.
8253 The list will by default be sorted by name (case sensitive),
8254 the sorting can be changed by using the optional {dict}
8255 argument, see |readdir()|.
8256
8257 The Dictionary for file and directory information has the
8258 following items:
8259 group Group name of the entry. (Only on Unix)
8260 name Name of the entry.
8261 perm Permissions of the entry. See |getfperm()|.
8262 size Size of the entry. See |getfsize()|.
8263 time Timestamp of the entry. See |getftime()|.
8264 type Type of the entry.
8265 On Unix, almost same as |getftype()| except:
8266 Symlink to a dir "linkd"
8267 Other symlink "link"
8268 On MS-Windows:
8269 Normal file "file"
8270 Directory "dir"
8271 Junction "junction"
8272 Symlink to a dir "linkd"
8273 Other symlink "link"
8274 Other reparse point "reparse"
8275 user User name of the entry's owner. (Only on Unix)
8276 On Unix, if the entry is a symlink, the Dictionary includes
8277 the information of the target (except the "type" item).
8278 On MS-Windows, it includes the information of the symlink
8279 itself because of performance reasons.
8280
8281 When {expr} is omitted all entries are included.
8282 When {expr} is given, it is evaluated to check what to do:
8283 If {expr} results in -1 then no further entries will
8284 be handled.
8285 If {expr} results in 0 then this entry will not be
8286 added to the list.
8287 If {expr} results in 1 then this entry will be added
8288 to the list.
8289 The entries "." and ".." are always excluded.
8290 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8291 of the entry.
8292 When {expr} is a function the entry is passed as the argument.
8293 For example, to get a list of files ending in ".txt": >
8294 readdirex(dirname, {e -> e.name =~ '.txt$'})
8295<
8296 For example, to get a list of all files in the current
8297 directory without sorting the individual entries: >
8298 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008299<
8300 Can also be used as a |method|: >
8301 GetDirName()->readdirex()
8302<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008303 Return type: list<dict<any>> or list<any>
8304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008305
8306 *readfile()*
8307readfile({fname} [, {type} [, {max}]])
8308 Read file {fname} and return a |List|, each line of the file
8309 as an item. Lines are broken at NL characters. Macintosh
8310 files separated with CR will result in a single long line
8311 (unless a NL appears somewhere).
8312 All NUL characters are replaced with a NL character.
8313 When {type} contains "b" binary mode is used:
8314 - When the last line ends in a NL an extra empty list item is
8315 added.
8316 - No CR characters are removed.
8317 Otherwise:
8318 - CR characters that appear before a NL are removed.
8319 - Whether the last line ends in a NL or not does not matter.
8320 - When 'encoding' is Unicode any UTF-8 byte order mark is
8321 removed from the text.
8322 When {max} is given this specifies the maximum number of lines
8323 to be read. Useful if you only want to check the first ten
8324 lines of a file: >
8325 :for line in readfile(fname, '', 10)
8326 : if line =~ 'Date' | echo line | endif
8327 :endfor
8328< When {max} is negative -{max} lines from the end of the file
8329 are returned, or as many as there are.
8330 When {max} is zero the result is an empty list.
8331 Note that without {max} the whole file is read into memory.
8332 Also note that there is no recognition of encoding. Read a
8333 file into a buffer if you need to.
8334 Deprecated (use |readblob()| instead): When {type} contains
8335 "B" a |Blob| is returned with the binary data of the file
8336 unmodified.
8337 When the file can't be opened an error message is given and
8338 the result is an empty list.
8339 Also see |writefile()|.
8340
8341 Can also be used as a |method|: >
8342 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008343<
8344 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008345
8346reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8347 {func} is called for every item in {object}, which can be a
8348 |String|, |List| or a |Blob|. {func} is called with two
8349 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008350 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008351
8352 {initial} is the initial result. When omitted, the first item
8353 in {object} is used and {func} is first called for the second
8354 item. If {initial} is not given and {object} is empty no
8355 result can be computed, an E998 error is given.
8356
8357 Examples: >
8358 echo reduce([1, 3, 5], { acc, val -> acc + val })
8359 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8360 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8361 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8362<
8363 Can also be used as a |method|: >
8364 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008365<
8366 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8367 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008368
8369
8370reg_executing() *reg_executing()*
8371 Returns the single letter name of the register being executed.
8372 Returns an empty string when no register is being executed.
8373 See |@|.
8374
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008375 Return type: |String|
8376
8377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008378reg_recording() *reg_recording()*
8379 Returns the single letter name of the register being recorded.
8380 Returns an empty string when not recording. See |q|.
8381
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008382 Return type: |String|
8383
8384
8385reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008386reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008387reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008388 Return an item that represents a time value. The item is a
8389 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008390 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008391 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008392 string or |reltimefloat()| to convert to a Float. For
8393 example, to see the time spent in function Work(): >
8394 var startTime = reltime()
8395 Work()
8396 echo startTime->reltime()->reltimestr()
8397<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008398 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008399 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008400 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008401 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008402 specified in the argument.
8403 With two arguments it returns the time passed between {start}
8404 and {end}.
8405
8406 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008407 reltime(). If there is an error an empty List is returned in
8408 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008409
8410 Can also be used as a |method|: >
8411 GetStart()->reltime()
8412<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008413 Return type: list<number>
8414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008415 {only available when compiled with the |+reltime| feature}
8416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008418reltimefloat({time}) *reltimefloat()*
8419 Return a Float that represents the time value of {time}.
8420 Example: >
8421 let start = reltime()
8422 call MyFunction()
8423 let seconds = reltimefloat(reltime(start))
8424< See the note of reltimestr() about overhead.
8425 Also see |profiling|.
8426 If there is an error 0.0 is returned in legacy script, in Vim9
8427 script an error is given.
8428
8429 Can also be used as a |method|: >
8430 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008431<
8432 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008433
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008434 {only available when compiled with the |+reltime| feature}
8435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008436
8437reltimestr({time}) *reltimestr()*
8438 Return a String that represents the time value of {time}.
8439 This is the number of seconds, a dot and the number of
8440 microseconds. Example: >
8441 let start = reltime()
8442 call MyFunction()
8443 echo reltimestr(reltime(start))
8444< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008445 The accuracy depends on the system. Use reltimefloat() for the
8446 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008447 Leading spaces are used to make the string align nicely. You
8448 can use split() to remove it. >
8449 echo split(reltimestr(reltime(start)))[0]
8450< Also see |profiling|.
8451 If there is an error an empty string is returned in legacy
8452 script, in Vim9 script an error is given.
8453
8454 Can also be used as a |method|: >
8455 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008456<
8457 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008458
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008459 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008460
8461 *remote_expr()* *E449*
8462remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008463 Send the {string} to {server}. The {server} argument is a
8464 string, also see |{server}|.
8465
8466 The string is sent as an expression and the result is returned
8467 after evaluation. The result must be a String or a |List|. A
8468 |List| is turned into a String by joining the items with a
8469 line break in between (not at the end), like with join(expr,
8470 "\n").
8471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008472 If {idvar} is present and not empty, it is taken as the name
8473 of a variable and a {serverid} for later use with
8474 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008476 If {timeout} is given the read times out after this many
8477 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008479 See also |clientserver| |RemoteReply|.
8480 This function is not available in the |sandbox|.
8481 {only available when compiled with the |+clientserver| feature}
8482 Note: Any errors will cause a local error message to be issued
8483 and the result will be the empty string.
8484
8485 Variables will be evaluated in the global namespace,
8486 independent of a function currently being active. Except
8487 when in debug mode, then local function variables and
8488 arguments can be evaluated.
8489
8490 Examples: >
8491 :echo remote_expr("gvim", "2+2")
8492 :echo remote_expr("gvim1", "b:current_syntax")
8493<
8494 Can also be used as a |method|: >
8495 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008496<
8497 Return type: |String| or list<{type}>
8498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008499
8500remote_foreground({server}) *remote_foreground()*
8501 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008502 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008503 This works like: >
8504 remote_expr({server}, "foreground()")
8505< Except that on Win32 systems the client does the work, to work
8506 around the problem that the OS doesn't always allow the server
8507 to bring itself to the foreground.
8508 Note: This does not restore the window if it was minimized,
8509 like foreground() does.
8510 This function is not available in the |sandbox|.
8511
8512 Can also be used as a |method|: >
8513 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008514<
8515 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008516
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008517 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008518 Win32 console version}
8519
8520
8521remote_peek({serverid} [, {retvar}]) *remote_peek()*
8522 Returns a positive number if there are available strings
8523 from {serverid}. Copies any reply string into the variable
8524 {retvar} if specified. {retvar} must be a string with the
8525 name of a variable.
8526 Returns zero if none are available.
8527 Returns -1 if something is wrong.
8528 See also |clientserver|.
8529 This function is not available in the |sandbox|.
8530 {only available when compiled with the |+clientserver| feature}
8531 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008532 :let repl = ""
8533 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008534
8535< Can also be used as a |method|: >
8536 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008537<
8538 Return type: |Number|
8539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008540
8541remote_read({serverid}, [{timeout}]) *remote_read()*
8542 Return the oldest available reply from {serverid} and consume
8543 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008544 reply is available. Returns an empty string, if a reply is
8545 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008546 See also |clientserver|.
8547 This function is not available in the |sandbox|.
8548 {only available when compiled with the |+clientserver| feature}
8549 Example: >
8550 :echo remote_read(id)
8551
8552< Can also be used as a |method|: >
8553 ServerId()->remote_read()
8554<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008555 Return type: |String|
8556
8557
8558remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008559 Send the {string} to {server}. The {server} argument is a
8560 string, also see |{server}|.
8561
8562 The string is sent as input keys and the function returns
8563 immediately. At the Vim server the keys are not mapped
8564 |:map|.
8565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008566 If {idvar} is present, it is taken as the name of a variable
8567 and a {serverid} for later use with remote_read() is stored
8568 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008570 See also |clientserver| |RemoteReply|.
8571 This function is not available in the |sandbox|.
8572 {only available when compiled with the |+clientserver| feature}
8573
8574 Note: Any errors will be reported in the server and may mess
8575 up the display.
8576 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008577 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008578 \ remote_read(serverid)
8579
8580 :autocmd NONE RemoteReply *
8581 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008582 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008583 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8584<
8585 Can also be used as a |method|: >
8586 ServerName()->remote_send(keys)
8587<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008588 Return type: |String|
8589
8590
8591remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008592 Become the server {name}. {name} must be a non-empty string.
8593 This fails if already running as a server, when |v:servername|
8594 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008595
8596 Can also be used as a |method|: >
8597 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008598<
8599 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008601 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008602
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008603
8604remove({list}, {idx}) *remove()*
8605remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008606 Without {end}: Remove the item at {idx} from |List| {list} and
8607 return the item.
8608 With {end}: Remove items from {idx} to {end} (inclusive) and
8609 return a |List| with these items. When {idx} points to the same
8610 item as {end} a list with one item is returned. When {end}
8611 points to an item before {idx} this is an error.
8612 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008613 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008614 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008615 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008616 :call remove(mylist, 0, 9)
8617<
8618 Use |delete()| to remove a file.
8619
8620 Can also be used as a |method|: >
8621 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008622<
8623 Return type: any, depending on {list}
8624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008625
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008626remove({blob}, {idx})
8627remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008628 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8629 return the byte.
8630 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8631 return a |Blob| with these bytes. When {idx} points to the same
8632 byte as {end} a |Blob| with one byte is returned. When {end}
8633 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008634 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008635 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008636 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008637 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008638<
8639 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008640
8641remove({dict}, {key})
8642 Remove the entry from {dict} with key {key} and return it.
8643 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008644 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008645< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008646 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008647
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008648 Return type: any, depending on {dict}
8649
8650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008651rename({from}, {to}) *rename()*
8652 Rename the file by the name {from} to the name {to}. This
8653 should also work to move files across file systems. The
8654 result is a Number, which is 0 if the file was renamed
8655 successfully, and non-zero when the renaming failed.
8656 NOTE: If {to} exists it is overwritten without warning.
8657 This function is not available in the |sandbox|.
8658
8659 Can also be used as a |method|: >
8660 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008661<
8662 Return type: |Number|
8663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008664
8665repeat({expr}, {count}) *repeat()*
8666 Repeat {expr} {count} times and return the concatenated
8667 result. Example: >
8668 :let separator = repeat('-', 80)
8669< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008670 When {expr} is a |List| or a |Blob| the result is {expr}
8671 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008672 :let longlist = repeat(['a', 'b'], 3)
8673< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8674
8675 Can also be used as a |method|: >
8676 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008677<
8678 Return type: |String|, |Blob| or list<{type}> depending on
8679 {expr}
8680
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008681
8682resolve({filename}) *resolve()* *E655*
8683 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8684 returns the path the shortcut points to in a simplified form.
8685 When {filename} is a symbolic link or junction point, return
8686 the full path to the target. If the target of junction is
8687 removed, return {filename}.
8688 On Unix, repeat resolving symbolic links in all path
8689 components of {filename} and return the simplified result.
8690 To cope with link cycles, resolving of symbolic links is
8691 stopped after 100 iterations.
8692 On other systems, return the simplified {filename}.
8693 The simplification step is done as by |simplify()|.
8694 resolve() keeps a leading path component specifying the
8695 current directory (provided the result is still a relative
8696 path name) and also keeps a trailing path separator.
8697
8698 Can also be used as a |method|: >
8699 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008700<
8701 Return type: |String|
8702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008703
8704reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008705 Reverse the order of items in {object}. {object} can be a
8706 |List|, a |Blob| or a |String|. For a List and a Blob the
8707 items are reversed in-place and {object} is returned.
8708 For a String a new String is returned.
8709 Returns zero if {object} is not a List, Blob or a String.
8710 If you want a List or Blob to remain unmodified make a copy
8711 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008712 :let revlist = reverse(copy(mylist))
8713< Can also be used as a |method|: >
8714 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008715<
8716 Return type: |String|, |Blob| or list<{type}> depending on
8717 {object}
8718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008719
8720round({expr}) *round()*
8721 Round off {expr} to the nearest integral value and return it
8722 as a |Float|. If {expr} lies halfway between two integral
8723 values, then use the larger one (away from zero).
8724 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008725 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008726 Examples: >
8727 echo round(0.456)
8728< 0.0 >
8729 echo round(4.5)
8730< 5.0 >
8731 echo round(-4.5)
8732< -5.0
8733
8734 Can also be used as a |method|: >
8735 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008736<
8737 Return type: |Float|
8738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008739
8740rubyeval({expr}) *rubyeval()*
8741 Evaluate Ruby expression {expr} and return its result
8742 converted to Vim data structures.
8743 Numbers, floats and strings are returned as they are (strings
8744 are copied though).
8745 Arrays are represented as Vim |List| type.
8746 Hashes are represented as Vim |Dictionary| type.
8747 Other objects are represented as strings resulted from their
8748 "Object#to_s" method.
8749 Note that in a `:def` function local variables are not visible
8750 to {expr}.
8751
8752 Can also be used as a |method|: >
8753 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008754<
8755 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008757 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008758
8759screenattr({row}, {col}) *screenattr()*
8760 Like |screenchar()|, but return the attribute. This is a rather
8761 arbitrary number that can only be used to compare to the
8762 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008763 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008764
8765 Can also be used as a |method|: >
8766 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008767<
8768 Return type: |Number|
8769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008770
8771screenchar({row}, {col}) *screenchar()*
8772 The result is a Number, which is the character at position
8773 [row, col] on the screen. This works for every possible
8774 screen position, also status lines, window separators and the
8775 command line. The top left position is row one, column one
8776 The character excludes composing characters. For double-byte
8777 encodings it may only be the first byte.
8778 This is mainly to be used for testing.
8779 Returns -1 when row or col is out of range.
8780
8781 Can also be used as a |method|: >
8782 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008783<
8784 Return type: |Number|
8785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008786
8787screenchars({row}, {col}) *screenchars()*
8788 The result is a |List| of Numbers. The first number is the same
8789 as what |screenchar()| returns. Further numbers are
8790 composing characters on top of the base character.
8791 This is mainly to be used for testing.
8792 Returns an empty List when row or col is out of range.
8793
8794 Can also be used as a |method|: >
8795 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008796<
8797 Return type: list<number> or list<any>
8798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008799
8800screencol() *screencol()*
8801 The result is a Number, which is the current screen column of
8802 the cursor. The leftmost column has number 1.
8803 This function is mainly used for testing.
8804
8805 Note: Always returns the current screen column, thus if used
8806 in a command (e.g. ":echo screencol()") it will return the
8807 column inside the command line, which is 1 when the command is
8808 executed. To get the cursor position in the file use one of
8809 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008810 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008811 nnoremap <silent> GG :echom screencol()<CR>
8812 nnoremap GG <Cmd>echom screencol()<CR>
8813<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008814 Return type: |Number|
8815
8816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008817screenpos({winid}, {lnum}, {col}) *screenpos()*
8818 The result is a Dict with the screen position of the text
8819 character in window {winid} at buffer line {lnum} and column
8820 {col}. {col} is a one-based byte index.
8821 The Dict has these members:
8822 row screen row
8823 col first screen column
8824 endcol last screen column
8825 curscol cursor screen column
8826 If the specified position is not visible, all values are zero.
8827 The "endcol" value differs from "col" when the character
8828 occupies more than one screen cell. E.g. for a Tab "col" can
8829 be 1 and "endcol" can be 8.
8830 The "curscol" value is where the cursor would be placed. For
8831 a Tab it would be the same as "endcol", while for a double
8832 width character it would be the same as "col".
8833 The |conceal| feature is ignored here, the column numbers are
8834 as if 'conceallevel' is zero. You can set the cursor to the
8835 right position and use |screencol()| to get the value with
8836 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008837 If the position is in a closed fold the screen position of the
8838 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008839 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008840
8841 Can also be used as a |method|: >
8842 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008843<
8844 Return type: dict<number> or dict<any>
8845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008846
8847screenrow() *screenrow()*
8848 The result is a Number, which is the current screen row of the
8849 cursor. The top line has number one.
8850 This function is mainly used for testing.
8851 Alternatively you can use |winline()|.
8852
8853 Note: Same restrictions as with |screencol()|.
8854
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008855 Return type: |Number|
8856
8857
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008858screenstring({row}, {col}) *screenstring()*
8859 The result is a String that contains the base character and
8860 any composing characters at position [row, col] on the screen.
8861 This is like |screenchars()| but returning a String with the
8862 characters.
8863 This is mainly to be used for testing.
8864 Returns an empty String when row or col is out of range.
8865
8866 Can also be used as a |method|: >
8867 GetRow()->screenstring(col)
8868<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008869 Return type: |String|
8870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008871 *search()*
8872search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8873 Search for regexp pattern {pattern}. The search starts at the
8874 cursor position (you can use |cursor()| to set it).
8875
8876 When a match has been found its line number is returned.
8877 If there is no match a 0 is returned and the cursor doesn't
8878 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008879 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008880
8881 {flags} is a String, which can contain these character flags:
8882 'b' search Backward instead of forward
8883 'c' accept a match at the Cursor position
8884 'e' move to the End of the match
8885 'n' do Not move the cursor
8886 'p' return number of matching sub-Pattern (see below)
8887 's' Set the ' mark at the previous location of the cursor
8888 'w' Wrap around the end of the file
8889 'W' don't Wrap around the end of the file
8890 'z' start searching at the cursor column instead of zero
8891 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8892
8893 If the 's' flag is supplied, the ' mark is set, only if the
8894 cursor is moved. The 's' flag cannot be combined with the 'n'
8895 flag.
8896
8897 'ignorecase', 'smartcase' and 'magic' are used.
8898
8899 When the 'z' flag is not given, forward searching always
8900 starts in column zero and then matches before the cursor are
8901 skipped. When the 'c' flag is present in 'cpo' the next
8902 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008903 search starts one column after the start of the match. This
8904 matters for overlapping matches. See |cpo-c|. You can also
8905 insert "\ze" to change where the match ends, see |/\ze|.
8906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008907 When searching backwards and the 'z' flag is given then the
8908 search starts in column zero, thus no match in the current
8909 line will be found (unless wrapping around the end of the
8910 file).
8911
8912 When the {stopline} argument is given then the search stops
8913 after searching this line. This is useful to restrict the
8914 search to a range of lines. Examples: >
8915 let match = search('(', 'b', line("w0"))
8916 let end = search('END', '', line("w$"))
8917< When {stopline} is used and it is not zero this also implies
8918 that the search does not wrap around the end of the file.
8919 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008920 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008921 When the {timeout} argument is given the search stops when
8922 more than this many milliseconds have passed. Thus when
8923 {timeout} is 500 the search stops after half a second.
8924 The value must not be negative. A zero value is like not
8925 giving the argument.
8926 {only available when compiled with the |+reltime| feature}
8927
8928 If the {skip} expression is given it is evaluated with the
8929 cursor positioned on the start of a match. If it evaluates to
8930 non-zero this match is skipped. This can be used, for
8931 example, to skip a match in a comment or a string.
8932 {skip} can be a string, which is evaluated as an expression, a
8933 function reference or a lambda.
8934 When {skip} is omitted or empty, every match is accepted.
8935 When evaluating {skip} causes an error the search is aborted
8936 and -1 returned.
8937 *search()-sub-match*
8938 With the 'p' flag the returned value is one more than the
8939 first sub-match in \(\). One if none of them matched but the
8940 whole pattern did match.
8941 To get the column number too use |searchpos()|.
8942
8943 The cursor will be positioned at the match, unless the 'n'
8944 flag is used.
8945
8946 Example (goes over all files in the argument list): >
8947 :let n = 1
8948 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008949 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008950 : " start at the last char in the file and wrap for the
8951 : " first search to find match at start of file
8952 : normal G$
8953 : let flags = "w"
8954 : while search("foo", flags) > 0
8955 : s/foo/bar/g
8956 : let flags = "W"
8957 : endwhile
8958 : update " write the file if modified
8959 : let n = n + 1
8960 :endwhile
8961<
8962 Example for using some flags: >
8963 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8964< This will search for the keywords "if", "else", and "endif"
8965 under or after the cursor. Because of the 'p' flag, it
8966 returns 1, 2, or 3 depending on which keyword is found, or 0
8967 if the search fails. With the cursor on the first word of the
8968 line:
8969 if (foo == 0) | let foo = foo + 1 | endif ~
8970 the function returns 1. Without the 'c' flag, the function
8971 finds the "endif" and returns 3. The same thing happens
8972 without the 'e' flag if the cursor is on the "f" of "if".
8973 The 'n' flag tells the function not to move the cursor.
8974
8975 Can also be used as a |method|: >
8976 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008977<
8978 Return type: |Number|
8979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008980
8981searchcount([{options}]) *searchcount()*
8982 Get or update the last search count, like what is displayed
8983 without the "S" flag in 'shortmess'. This works even if
8984 'shortmess' does contain the "S" flag.
8985
8986 This returns a |Dictionary|. The dictionary is empty if the
8987 previous pattern was not set and "pattern" was not specified.
8988
8989 key type meaning ~
8990 current |Number| current position of match;
8991 0 if the cursor position is
8992 before the first match
8993 exact_match |Boolean| 1 if "current" is matched on
8994 "pos", otherwise 0
8995 total |Number| total count of matches found
8996 incomplete |Number| 0: search was fully completed
8997 1: recomputing was timed out
8998 2: max count exceeded
8999
9000 For {options} see further down.
9001
9002 To get the last search count when |n| or |N| was pressed, call
9003 this function with `recompute: 0` . This sometimes returns
9004 wrong information because |n| and |N|'s maximum count is 99.
9005 If it exceeded 99 the result must be max count + 1 (100). If
9006 you want to get correct information, specify `recompute: 1`: >
9007
9008 " result == maxcount + 1 (100) when many matches
9009 let result = searchcount(#{recompute: 0})
9010
9011 " Below returns correct result (recompute defaults
9012 " to 1)
9013 let result = searchcount()
9014<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009015 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009016 function! LastSearchCount() abort
9017 let result = searchcount(#{recompute: 0})
9018 if empty(result)
9019 return ''
9020 endif
9021 if result.incomplete ==# 1 " timed out
9022 return printf(' /%s [?/??]', @/)
9023 elseif result.incomplete ==# 2 " max count exceeded
9024 if result.total > result.maxcount &&
9025 \ result.current > result.maxcount
9026 return printf(' /%s [>%d/>%d]', @/,
9027 \ result.current, result.total)
9028 elseif result.total > result.maxcount
9029 return printf(' /%s [%d/>%d]', @/,
9030 \ result.current, result.total)
9031 endif
9032 endif
9033 return printf(' /%s [%d/%d]', @/,
9034 \ result.current, result.total)
9035 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009036 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009037
9038 " Or if you want to show the count only when
9039 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009040 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009041 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9042<
9043 You can also update the search count, which can be useful in a
9044 |CursorMoved| or |CursorMovedI| autocommand: >
9045
9046 autocmd CursorMoved,CursorMovedI *
9047 \ let s:searchcount_timer = timer_start(
9048 \ 200, function('s:update_searchcount'))
9049 function! s:update_searchcount(timer) abort
9050 if a:timer ==# s:searchcount_timer
9051 call searchcount(#{
9052 \ recompute: 1, maxcount: 0, timeout: 100})
9053 redrawstatus
9054 endif
9055 endfunction
9056<
9057 This can also be used to count matched texts with specified
9058 pattern in the current buffer using "pattern": >
9059
9060 " Count '\<foo\>' in this buffer
9061 " (Note that it also updates search count)
9062 let result = searchcount(#{pattern: '\<foo\>'})
9063
9064 " To restore old search count by old pattern,
9065 " search again
9066 call searchcount()
9067<
9068 {options} must be a |Dictionary|. It can contain:
9069 key type meaning ~
9070 recompute |Boolean| if |TRUE|, recompute the count
9071 like |n| or |N| was executed.
9072 otherwise returns the last
9073 computed result (when |n| or
9074 |N| was used when "S" is not
9075 in 'shortmess', or this
9076 function was called).
9077 (default: |TRUE|)
9078 pattern |String| recompute if this was given
9079 and different with |@/|.
9080 this works as same as the
9081 below command is executed
9082 before calling this function >
9083 let @/ = pattern
9084< (default: |@/|)
9085 timeout |Number| 0 or negative number is no
9086 timeout. timeout milliseconds
9087 for recomputing the result
9088 (default: 0)
9089 maxcount |Number| 0 or negative number is no
9090 limit. max count of matched
9091 text while recomputing the
9092 result. if search exceeded
9093 total count, "total" value
9094 becomes `maxcount + 1`
9095 (default: 99)
9096 pos |List| `[lnum, col, off]` value
9097 when recomputing the result.
9098 this changes "current" result
9099 value. see |cursor()|,
9100 |getpos()|
9101 (default: cursor's position)
9102
9103 Can also be used as a |method|: >
9104 GetSearchOpts()->searchcount()
9105<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009106 Return type: dict<number>
9107
9108
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009109searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9110 Search for the declaration of {name}.
9111
9112 With a non-zero {global} argument it works like |gD|, find
9113 first match in the file. Otherwise it works like |gd|, find
9114 first match in the function.
9115
9116 With a non-zero {thisblock} argument matches in a {} block
9117 that ends before the cursor position are ignored. Avoids
9118 finding variable declarations only valid in another scope.
9119
9120 Moves the cursor to the found match.
9121 Returns zero for success, non-zero for failure.
9122 Example: >
9123 if searchdecl('myvar') == 0
9124 echo getline('.')
9125 endif
9126<
9127 Can also be used as a |method|: >
9128 GetName()->searchdecl()
9129<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009130 Return type: |Number|
9131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009132 *searchpair()*
9133searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9134 [, {stopline} [, {timeout}]]]])
9135 Search for the match of a nested start-end pair. This can be
9136 used to find the "endif" that matches an "if", while other
9137 if/endif pairs in between are ignored.
9138 The search starts at the cursor. The default is to search
9139 forward, include 'b' in {flags} to search backward.
9140 If a match is found, the cursor is positioned at it and the
9141 line number is returned. If no match is found 0 or -1 is
9142 returned and the cursor doesn't move. No error message is
9143 given.
9144
9145 {start}, {middle} and {end} are patterns, see |pattern|. They
9146 must not contain \( \) pairs. Use of \%( \) is allowed. When
9147 {middle} is not empty, it is found when searching from either
9148 direction, but only when not in a nested start-end pair. A
9149 typical use is: >
9150 searchpair('\<if\>', '\<else\>', '\<endif\>')
9151< By leaving {middle} empty the "else" is skipped.
9152
9153 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9154 |search()|. Additionally:
9155 'r' Repeat until no more matches found; will find the
9156 outer pair. Implies the 'W' flag.
9157 'm' Return number of matches instead of line number with
9158 the match; will be > 1 when 'r' is used.
9159 Note: it's nearly always a good idea to use the 'W' flag, to
9160 avoid wrapping around the end of the file.
9161
9162 When a match for {start}, {middle} or {end} is found, the
9163 {skip} expression is evaluated with the cursor positioned on
9164 the start of the match. It should return non-zero if this
9165 match is to be skipped. E.g., because it is inside a comment
9166 or a string.
9167 When {skip} is omitted or empty, every match is accepted.
9168 When evaluating {skip} causes an error the search is aborted
9169 and -1 returned.
9170 {skip} can be a string, a lambda, a funcref or a partial.
9171 Anything else makes the function fail.
9172 In a `:def` function when the {skip} argument is a string
9173 constant it is compiled into instructions.
9174
9175 For {stopline} and {timeout} see |search()|.
9176
9177 The value of 'ignorecase' is used. 'magic' is ignored, the
9178 patterns are used like it's on.
9179
9180 The search starts exactly at the cursor. A match with
9181 {start}, {middle} or {end} at the next character, in the
9182 direction of searching, is the first one found. Example: >
9183 if 1
9184 if 2
9185 endif 2
9186 endif 1
9187< When starting at the "if 2", with the cursor on the "i", and
9188 searching forwards, the "endif 2" is found. When starting on
9189 the character just before the "if 2", the "endif 1" will be
9190 found. That's because the "if 2" will be found first, and
9191 then this is considered to be a nested if/endif from "if 2" to
9192 "endif 2".
9193 When searching backwards and {end} is more than one character,
9194 it may be useful to put "\zs" at the end of the pattern, so
9195 that when the cursor is inside a match with the end it finds
9196 the matching start.
9197
9198 Example, to find the "endif" command in a Vim script: >
9199
9200 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9201 \ 'getline(".") =~ "^\\s*\""')
9202
9203< The cursor must be at or after the "if" for which a match is
9204 to be found. Note that single-quote strings are used to avoid
9205 having to double the backslashes. The skip expression only
9206 catches comments at the start of a line, not after a command.
9207 Also, a word "en" or "if" halfway a line is considered a
9208 match.
9209 Another example, to search for the matching "{" of a "}": >
9210
9211 :echo searchpair('{', '', '}', 'bW')
9212
9213< This works when the cursor is at or before the "}" for which a
9214 match is to be found. To reject matches that syntax
9215 highlighting recognized as strings: >
9216
9217 :echo searchpair('{', '', '}', 'bW',
9218 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9219<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009220 Return type: |Number|
9221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009222 *searchpairpos()*
9223searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9224 [, {stopline} [, {timeout}]]]])
9225 Same as |searchpair()|, but returns a |List| with the line and
9226 column position of the match. The first element of the |List|
9227 is the line number and the second element is the byte index of
9228 the column position of the match. If no match is found,
9229 returns [0, 0]. >
9230
9231 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9232<
9233 See |match-parens| for a bigger and more useful example.
9234
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009235 Return type: list<number>
9236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009237 *searchpos()*
9238searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9239 Same as |search()|, but returns a |List| with the line and
9240 column position of the match. The first element of the |List|
9241 is the line number and the second element is the byte index of
9242 the column position of the match. If no match is found,
9243 returns [0, 0].
9244 Example: >
9245 :let [lnum, col] = searchpos('mypattern', 'n')
9246
9247< When the 'p' flag is given then there is an extra item with
9248 the sub-pattern match number |search()-sub-match|. Example: >
9249 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9250< In this example "submatch" is 2 when a lowercase letter is
9251 found |/\l|, 3 when an uppercase letter is found |/\u|.
9252
9253 Can also be used as a |method|: >
9254 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009255<
9256 Return type: list<number>
9257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009258
9259server2client({clientid}, {string}) *server2client()*
9260 Send a reply string to {clientid}. The most recent {clientid}
9261 that sent a string can be retrieved with expand("<client>").
9262 {only available when compiled with the |+clientserver| feature}
9263 Returns zero for success, -1 for failure.
9264 Note:
9265 This id has to be stored before the next command can be
9266 received. I.e. before returning from the received command and
9267 before calling any commands that waits for input.
9268 See also |clientserver|.
9269 Example: >
9270 :echo server2client(expand("<client>"), "HELLO")
9271
9272< Can also be used as a |method|: >
9273 GetClientId()->server2client(string)
9274<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009275 Return type: |Number|
9276
9277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009278serverlist() *serverlist()*
9279 Return a list of available server names, one per line.
9280 When there are no servers or the information is not available
9281 an empty string is returned. See also |clientserver|.
9282 {only available when compiled with the |+clientserver| feature}
9283 Example: >
9284 :echo serverlist()
9285<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009286 Return type: |String|
9287
9288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009289setbufline({buf}, {lnum}, {text}) *setbufline()*
9290 Set line {lnum} to {text} in buffer {buf}. This works like
9291 |setline()| for the specified buffer.
9292
9293 This function works only for loaded buffers. First call
9294 |bufload()| if needed.
9295
9296 To insert lines use |appendbufline()|.
9297 Any text properties in {lnum} are cleared.
9298
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009299 {text} can be a string to set one line, or a List of strings
9300 to set multiple lines. If the List extends below the last
9301 line then those lines are added. If the List is empty then
9302 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009303
9304 For the use of {buf}, see |bufname()| above.
9305
9306 {lnum} is used like with |setline()|.
9307 Use "$" to refer to the last line in buffer {buf}.
9308 When {lnum} is just below the last line the {text} will be
9309 added below the last line.
9310
9311 When {buf} is not a valid buffer, the buffer is not loaded or
9312 {lnum} is not valid then 1 is returned. In |Vim9| script an
9313 error is given.
9314 On success 0 is returned.
9315
9316 Can also be used as a |method|, the base is passed as the
9317 third argument: >
9318 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009319<
9320 Return type: |Number|
9321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009322
9323setbufvar({buf}, {varname}, {val}) *setbufvar()*
9324 Set option or local variable {varname} in buffer {buf} to
9325 {val}.
9326 This also works for a global or local window option, but it
9327 doesn't work for a global or local window variable.
9328 For a local window option the global value is unchanged.
9329 For the use of {buf}, see |bufname()| above.
9330 The {varname} argument is a string.
9331 Note that the variable name without "b:" must be used.
9332 Examples: >
9333 :call setbufvar(1, "&mod", 1)
9334 :call setbufvar("todo", "myvar", "foobar")
9335< This function is not available in the |sandbox|.
9336
9337 Can also be used as a |method|, the base is passed as the
9338 third argument: >
9339 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009340<
9341 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009342
9343
9344setcellwidths({list}) *setcellwidths()*
9345 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009346 tells Vim how wide characters are when displayed in the
9347 terminal, counted in screen cells. The values override
9348 'ambiwidth'. Example: >
9349 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009350 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009351 \ [0x2194, 0x2199, 2],
9352 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009353
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009354< The {list} argument is a List of Lists with each three
9355 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9356 {low} and {high} can be the same, in which case this refers to
9357 one character. Otherwise it is the range of characters from
9358 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009359 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009360
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009361 {width} must be either 1 or 2, indicating the character width
9362 in screen cells. *E1112*
9363 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009364 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009366 If the new value causes 'fillchars' or 'listchars' to become
9367 invalid it is rejected and an error is given.
9368
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009369 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009370 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009372< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009373 the effect for known emoji characters. Move the cursor
9374 through the text to check if the cell widths of your terminal
9375 match with what Vim knows about each emoji. If it doesn't
9376 look right you need to adjust the {list} argument.
9377
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009378 Return type: |Number|
9379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009380
9381setcharpos({expr}, {list}) *setcharpos()*
9382 Same as |setpos()| but uses the specified column number as the
9383 character index instead of the byte index in the line.
9384
9385 Example:
9386 With the text "여보세요" in line 8: >
9387 call setcharpos('.', [0, 8, 4, 0])
9388< positions the cursor on the fourth character '요'. >
9389 call setpos('.', [0, 8, 4, 0])
9390< positions the cursor on the second character '보'.
9391
9392 Can also be used as a |method|: >
9393 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009394<
9395 Return type: |Number|
9396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009397
9398setcharsearch({dict}) *setcharsearch()*
9399 Set the current character search information to {dict},
9400 which contains one or more of the following entries:
9401
9402 char character which will be used for a subsequent
9403 |,| or |;| command; an empty string clears the
9404 character search
9405 forward direction of character search; 1 for forward,
9406 0 for backward
9407 until type of character search; 1 for a |t| or |T|
9408 character search, 0 for an |f| or |F|
9409 character search
9410
9411 This can be useful to save/restore a user's character search
9412 from a script: >
9413 :let prevsearch = getcharsearch()
9414 :" Perform a command which clobbers user's search
9415 :call setcharsearch(prevsearch)
9416< Also see |getcharsearch()|.
9417
9418 Can also be used as a |method|: >
9419 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009420<
9421 Return type: dict<any>
9422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009423
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009424setcmdline({str} [, {pos}]) *setcmdline()*
9425 Set the command line to {str} and set the cursor position to
9426 {pos}.
9427 If {pos} is omitted, the cursor is positioned after the text.
9428 Returns 0 when successful, 1 when not editing the command
9429 line.
9430
9431 Can also be used as a |method|: >
9432 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009433<
9434 Return type: |Number|
9435
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009437setcmdpos({pos}) *setcmdpos()*
9438 Set the cursor position in the command line to byte position
9439 {pos}. The first position is 1.
9440 Use |getcmdpos()| to obtain the current position.
9441 Only works while editing the command line, thus you must use
9442 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9443 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9444 set after the command line is set to the expression. For
9445 |c_CTRL-R_=| it is set after evaluating the expression but
9446 before inserting the resulting text.
9447 When the number is too big the cursor is put at the end of the
9448 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009449 Returns 0 when successful, 1 when not editing the command
9450 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009451
9452 Can also be used as a |method|: >
9453 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009454<
9455 Return type: |Number|
9456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009457
9458setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9459setcursorcharpos({list})
9460 Same as |cursor()| but uses the specified column number as the
9461 character index instead of the byte index in the line.
9462
9463 Example:
9464 With the text "여보세요" in line 4: >
9465 call setcursorcharpos(4, 3)
9466< positions the cursor on the third character '세'. >
9467 call cursor(4, 3)
9468< positions the cursor on the first character '여'.
9469
9470 Can also be used as a |method|: >
9471 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009472<
9473 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009474
9475
9476setenv({name}, {val}) *setenv()*
9477 Set environment variable {name} to {val}. Example: >
9478 call setenv('HOME', '/home/myhome')
9479
9480< When {val} is |v:null| the environment variable is deleted.
9481 See also |expr-env|.
9482
9483 Can also be used as a |method|, the base is passed as the
9484 second argument: >
9485 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009486<
9487 Return type: |Number|
9488
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009489
9490setfperm({fname}, {mode}) *setfperm()* *chmod*
9491 Set the file permissions for {fname} to {mode}.
9492 {mode} must be a string with 9 characters. It is of the form
9493 "rwxrwxrwx", where each group of "rwx" flags represent, in
9494 turn, the permissions of the owner of the file, the group the
9495 file belongs to, and other users. A '-' character means the
9496 permission is off, any other character means on. Multi-byte
9497 characters are not supported.
9498
9499 For example "rw-r-----" means read-write for the user,
9500 readable by the group, not accessible by others. "xx-x-----"
9501 would do the same thing.
9502
9503 Returns non-zero for success, zero for failure.
9504
9505 Can also be used as a |method|: >
9506 GetFilename()->setfperm(mode)
9507<
9508 To read permissions see |getfperm()|.
9509
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009510 Return type: |Number|
9511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009512
9513setline({lnum}, {text}) *setline()*
9514 Set line {lnum} of the current buffer to {text}. To insert
9515 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009516 |setbufline()|.
9517 Any text properties in {lnum} are cleared |text-prop-cleared|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009518
9519 {lnum} is used like with |getline()|.
9520 When {lnum} is just below the last line the {text} will be
9521 added below the last line.
9522 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009523 converted to a String. When {text} is an empty List then
9524 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009525
9526 If this succeeds, FALSE is returned. If this fails (most likely
9527 because {lnum} is invalid) TRUE is returned.
9528 In |Vim9| script an error is given if {lnum} is invalid.
9529
9530 Example: >
9531 :call setline(5, strftime("%c"))
9532
9533< When {text} is a |List| then line {lnum} and following lines
9534 will be set to the items in the list. Example: >
9535 :call setline(5, ['aaa', 'bbb', 'ccc'])
9536< This is equivalent to: >
9537 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9538 : call setline(n, l)
9539 :endfor
9540
9541< Note: The '[ and '] marks are not set.
9542
9543 Can also be used as a |method|, the base is passed as the
9544 second argument: >
9545 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009546<
9547 Return type: |Number|
9548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009549
9550setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9551 Create or replace or add to the location list for window {nr}.
9552 {nr} can be the window number or the |window-ID|.
9553 When {nr} is zero the current window is used.
9554
9555 For a location list window, the displayed location list is
9556 modified. For an invalid window number {nr}, -1 is returned.
9557 Otherwise, same as |setqflist()|.
9558 Also see |location-list|.
9559
9560 For {action} see |setqflist-action|.
9561
9562 If the optional {what} dictionary argument is supplied, then
9563 only the items listed in {what} are set. Refer to |setqflist()|
9564 for the list of supported keys in {what}.
9565
9566 Can also be used as a |method|, the base is passed as the
9567 second argument: >
9568 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009569<
9570 Return type: |Number|
9571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009572
9573setmatches({list} [, {win}]) *setmatches()*
9574 Restores a list of matches saved by |getmatches()| for the
9575 current window. Returns 0 if successful, otherwise -1. All
9576 current matches are cleared before the list is restored. See
9577 example for |getmatches()|.
9578 If {win} is specified, use the window with this number or
9579 window ID instead of the current window.
9580
9581 Can also be used as a |method|: >
9582 GetMatches()->setmatches()
9583<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009584 Return type: |Number|
9585
9586
9587setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009588 Set the position for String {expr}. Possible values:
9589 . the cursor
9590 'x mark x
9591
9592 {list} must be a |List| with four or five numbers:
9593 [bufnum, lnum, col, off]
9594 [bufnum, lnum, col, off, curswant]
9595
9596 "bufnum" is the buffer number. Zero can be used for the
9597 current buffer. When setting an uppercase mark "bufnum" is
9598 used for the mark position. For other marks it specifies the
9599 buffer to set the mark in. You can use the |bufnr()| function
9600 to turn a file name into a buffer number.
9601 For setting the cursor and the ' mark "bufnum" is ignored,
9602 since these are associated with a window, not a buffer.
9603 Does not change the jumplist.
9604
9605 "lnum" and "col" are the position in the buffer. The first
9606 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9607 smaller than 1 then 1 is used. To use the character count
9608 instead of the byte count, use |setcharpos()|.
9609
9610 The "off" number is only used when 'virtualedit' is set. Then
9611 it is the offset in screen columns from the start of the
9612 character. E.g., a position within a <Tab> or after the last
9613 character.
9614
9615 The "curswant" number is only used when setting the cursor
9616 position. It sets the preferred column for when moving the
9617 cursor vertically. When the "curswant" number is missing the
9618 preferred column is not set. When it is present and setting a
9619 mark position it is not used.
9620
9621 Note that for '< and '> changing the line number may result in
9622 the marks to be effectively be swapped, so that '< is always
9623 before '>.
9624
9625 Returns 0 when the position could be set, -1 otherwise.
9626 An error message is given if {expr} is invalid.
9627
9628 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9629
9630 This does not restore the preferred column for moving
9631 vertically; if you set the cursor position with this, |j| and
9632 |k| motions will jump to previous columns! Use |cursor()| to
9633 also set the preferred column. Also see the "curswant" key in
9634 |winrestview()|.
9635
9636 Can also be used as a |method|: >
9637 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009638<
9639 Return type: |Number|
9640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009641
9642setqflist({list} [, {action} [, {what}]]) *setqflist()*
9643 Create or replace or add to the quickfix list.
9644
9645 If the optional {what} dictionary argument is supplied, then
9646 only the items listed in {what} are set. The first {list}
9647 argument is ignored. See below for the supported items in
9648 {what}.
9649 *setqflist-what*
9650 When {what} is not present, the items in {list} are used. Each
9651 item must be a dictionary. Non-dictionary items in {list} are
9652 ignored. Each dictionary item can contain the following
9653 entries:
9654
9655 bufnr buffer number; must be the number of a valid
9656 buffer
9657 filename name of a file; only used when "bufnr" is not
9658 present or it is invalid.
9659 module name of a module; if given it will be used in
9660 quickfix error window instead of the filename.
9661 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009662 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009663 pattern search pattern used to locate the error
9664 col column number
9665 vcol when non-zero: "col" is visual column
9666 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009667 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009668 nr error number
9669 text description of the error
9670 type single-character error type, 'E', 'W', etc.
9671 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009672 user_data custom data associated with the item, can be
9673 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009674
9675 The "col", "vcol", "nr", "type" and "text" entries are
9676 optional. Either "lnum" or "pattern" entry can be used to
9677 locate a matching error line.
9678 If the "filename" and "bufnr" entries are not present or
9679 neither the "lnum" or "pattern" entries are present, then the
9680 item will not be handled as an error line.
9681 If both "pattern" and "lnum" are present then "pattern" will
9682 be used.
9683 If the "valid" entry is not supplied, then the valid flag is
9684 set when "bufnr" is a valid buffer or "filename" exists.
9685 If you supply an empty {list}, the quickfix list will be
9686 cleared.
9687 Note that the list is not exactly the same as what
9688 |getqflist()| returns.
9689
9690 {action} values: *setqflist-action* *E927*
9691 'a' The items from {list} are added to the existing
9692 quickfix list. If there is no existing list, then a
9693 new list is created.
9694
9695 'r' The items from the current quickfix list are replaced
9696 with the items from {list}. This can also be used to
9697 clear the list: >
9698 :call setqflist([], 'r')
9699<
9700 'f' All the quickfix lists in the quickfix stack are
9701 freed.
9702
9703 If {action} is not present or is set to ' ', then a new list
9704 is created. The new quickfix list is added after the current
9705 quickfix list in the stack and all the following lists are
9706 freed. To add a new quickfix list at the end of the stack,
9707 set "nr" in {what} to "$".
9708
9709 The following items can be specified in dictionary {what}:
9710 context quickfix list context. See |quickfix-context|
9711 efm errorformat to use when parsing text from
9712 "lines". If this is not present, then the
9713 'errorformat' option value is used.
9714 See |quickfix-parse|
9715 id quickfix list identifier |quickfix-ID|
9716 idx index of the current entry in the quickfix
9717 list specified by 'id' or 'nr'. If set to '$',
9718 then the last entry in the list is set as the
9719 current entry. See |quickfix-index|
9720 items list of quickfix entries. Same as the {list}
9721 argument.
9722 lines use 'errorformat' to parse a list of lines and
9723 add the resulting entries to the quickfix list
9724 {nr} or {id}. Only a |List| value is supported.
9725 See |quickfix-parse|
9726 nr list number in the quickfix stack; zero
9727 means the current quickfix list and "$" means
9728 the last quickfix list.
9729 quickfixtextfunc
9730 function to get the text to display in the
9731 quickfix window. The value can be the name of
9732 a function or a funcref or a lambda. Refer to
9733 |quickfix-window-function| for an explanation
9734 of how to write the function and an example.
9735 title quickfix list title text. See |quickfix-title|
9736 Unsupported keys in {what} are ignored.
9737 If the "nr" item is not present, then the current quickfix list
9738 is modified. When creating a new quickfix list, "nr" can be
9739 set to a value one greater than the quickfix stack size.
9740 When modifying a quickfix list, to guarantee that the correct
9741 list is modified, "id" should be used instead of "nr" to
9742 specify the list.
9743
9744 Examples (See also |setqflist-examples|): >
9745 :call setqflist([], 'r', {'title': 'My search'})
9746 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9747 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9748<
9749 Returns zero for success, -1 for failure.
9750
9751 This function can be used to create a quickfix list
9752 independent of the 'errorformat' setting. Use a command like
9753 `:cc 1` to jump to the first position.
9754
9755 Can also be used as a |method|, the base is passed as the
9756 second argument: >
9757 GetErrorlist()->setqflist()
9758<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009759 Return type: |Number|
9760
9761
9762setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009763 Set the register {regname} to {value}.
9764 If {regname} is "" or "@", the unnamed register '"' is used.
9765 The {regname} argument is a string. In |Vim9-script|
9766 {regname} must be one character.
9767
9768 {value} may be any value returned by |getreg()| or
9769 |getreginfo()|, including a |List| or |Dict|.
9770 If {options} contains "a" or {regname} is upper case,
9771 then the value is appended.
9772
9773 {options} can also contain a register type specification:
9774 "c" or "v" |characterwise| mode
9775 "l" or "V" |linewise| mode
9776 "b" or "<CTRL-V>" |blockwise-visual| mode
9777 If a number immediately follows "b" or "<CTRL-V>" then this is
9778 used as the width of the selection - if it is not specified
9779 then the width of the block is set to the number of characters
9780 in the longest line (counting a <Tab> as 1 character).
9781
9782 If {options} contains no register settings, then the default
9783 is to use character mode unless {value} ends in a <NL> for
9784 string {value} and linewise mode for list {value}. Blockwise
9785 mode is never selected automatically.
9786 Returns zero for success, non-zero for failure.
9787
9788 *E883*
9789 Note: you may not use |List| containing more than one item to
9790 set search and expression registers. Lists containing no
9791 items act like empty strings.
9792
9793 Examples: >
9794 :call setreg(v:register, @*)
9795 :call setreg('*', @%, 'ac')
9796 :call setreg('a', "1\n2\n3", 'b5')
9797 :call setreg('"', { 'points_to': 'a'})
9798
9799< This example shows using the functions to save and restore a
9800 register: >
9801 :let var_a = getreginfo()
9802 :call setreg('a', var_a)
9803< or: >
9804 :let var_a = getreg('a', 1, 1)
9805 :let var_amode = getregtype('a')
9806 ....
9807 :call setreg('a', var_a, var_amode)
9808< Note: you may not reliably restore register value
9809 without using the third argument to |getreg()| as without it
9810 newlines are represented as newlines AND Nul bytes are
9811 represented as newlines as well, see |NL-used-for-Nul|.
9812
9813 You can also change the type of a register by appending
9814 nothing: >
9815 :call setreg('a', '', 'al')
9816
9817< Can also be used as a |method|, the base is passed as the
9818 second argument: >
9819 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009820<
9821 Return type: |Number|
9822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009823
9824settabvar({tabnr}, {varname}, {val}) *settabvar()*
9825 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9826 |t:var|
9827 The {varname} argument is a string.
9828 Note that autocommands are blocked, side effects may not be
9829 triggered, e.g. when setting 'filetype'.
9830 Note that the variable name without "t:" must be used.
9831 Tabs are numbered starting with one.
9832 This function is not available in the |sandbox|.
9833
9834 Can also be used as a |method|, the base is passed as the
9835 third argument: >
9836 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009837<
9838 Return type: |Number|
9839
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009840
9841settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9842 Set option or local variable {varname} in window {winnr} to
9843 {val}.
9844 Tabs are numbered starting with one. For the current tabpage
9845 use |setwinvar()|.
9846 {winnr} can be the window number or the |window-ID|.
9847 When {winnr} is zero the current window is used.
9848 Note that autocommands are blocked, side effects may not be
9849 triggered, e.g. when setting 'filetype' or 'syntax'.
9850 This also works for a global or local buffer option, but it
9851 doesn't work for a global or local buffer variable.
9852 For a local buffer option the global value is unchanged.
9853 Note that the variable name without "w:" must be used.
9854 Examples: >
9855 :call settabwinvar(1, 1, "&list", 0)
9856 :call settabwinvar(3, 2, "myvar", "foobar")
9857< This function is not available in the |sandbox|.
9858
9859 Can also be used as a |method|, the base is passed as the
9860 fourth argument: >
9861 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009862<
9863 Return type: |Number|
9864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009865
9866settagstack({nr}, {dict} [, {action}]) *settagstack()*
9867 Modify the tag stack of the window {nr} using {dict}.
9868 {nr} can be the window number or the |window-ID|.
9869
9870 For a list of supported items in {dict}, refer to
9871 |gettagstack()|. "curidx" takes effect before changing the tag
9872 stack.
9873 *E962*
9874 How the tag stack is modified depends on the {action}
9875 argument:
9876 - If {action} is not present or is set to 'r', then the tag
9877 stack is replaced.
9878 - If {action} is set to 'a', then new entries from {dict} are
9879 pushed (added) onto the tag stack.
9880 - If {action} is set to 't', then all the entries from the
9881 current entry in the tag stack or "curidx" in {dict} are
9882 removed and then new entries are pushed to the stack.
9883
9884 The current index is set to one after the length of the tag
9885 stack after the modification.
9886
9887 Returns zero for success, -1 for failure.
9888
9889 Examples (for more examples see |tagstack-examples|):
9890 Empty the tag stack of window 3: >
9891 call settagstack(3, {'items' : []})
9892
9893< Save and restore the tag stack: >
9894 let stack = gettagstack(1003)
9895 " do something else
9896 call settagstack(1003, stack)
9897 unlet stack
9898<
9899 Can also be used as a |method|, the base is passed as the
9900 second argument: >
9901 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009902<
9903 Return type: |Number|
9904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009905
9906setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9907 Like |settabwinvar()| for the current tab page.
9908 Examples: >
9909 :call setwinvar(1, "&list", 0)
9910 :call setwinvar(2, "myvar", "foobar")
9911
9912< Can also be used as a |method|, the base is passed as the
9913 third argument: >
9914 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009915<
9916 Return type: |Number|
9917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009918
9919sha256({string}) *sha256()*
9920 Returns a String with 64 hex characters, which is the SHA256
9921 checksum of {string}.
9922
9923 Can also be used as a |method|: >
9924 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009925<
9926 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009927
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009928 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009929
9930shellescape({string} [, {special}]) *shellescape()*
9931 Escape {string} for use as a shell command argument.
9932 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009933 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009934 in single quotes and will double up all internal single
9935 quotes.
9936 On MS-Windows, when 'shellslash' is not set, it will enclose
9937 {string} in double quotes and double all double quotes within
9938 {string}.
9939 Otherwise it will enclose {string} in single quotes and
9940 replace all "'" with "'\''".
9941
Enno5faeb602024-05-15 21:54:19 +02009942 The {special} argument adds additional escaping of keywords
9943 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009944 number or a non-empty String (|non-zero-arg|), then special
9945 items such as "!", "%", "#" and "<cword>" (as listed in
9946 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009947 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009948
9949 The "!" character will be escaped (again with a |non-zero-arg|
9950 {special}) when 'shell' contains "csh" in the tail. That is
9951 because for csh and tcsh "!" is used for history replacement
9952 even when inside single quotes.
9953
9954 With a |non-zero-arg| {special} the <NL> character is also
9955 escaped. When 'shell' containing "csh" in the tail it's
9956 escaped a second time.
9957
9958 The "\" character will be escaped when 'shell' contains "fish"
9959 in the tail. That is because for fish "\" is used as an escape
9960 character inside single quotes.
9961
9962 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009963 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009964< This results in a directory listing for the file under the
9965 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009966 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009967< See also |::S|.
9968
9969 Can also be used as a |method|: >
9970 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009971<
9972 Return type: |String|
9973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009974
9975shiftwidth([{col}]) *shiftwidth()*
9976 Returns the effective value of 'shiftwidth'. This is the
9977 'shiftwidth' value unless it is zero, in which case it is the
9978 'tabstop' value. This function was introduced with patch
9979 7.3.694 in 2012, everybody should have it by now (however it
9980 did not allow for the optional {col} argument until 8.1.542).
9981
9982 When there is one argument {col} this is used as column number
9983 for which to return the 'shiftwidth' value. This matters for the
9984 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9985 no {col} argument is given, column 1 will be assumed.
9986
9987 Can also be used as a |method|: >
9988 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009989<
9990 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009991
9992sign_ functions are documented here: |sign-functions-details|
9993
9994
9995simplify({filename}) *simplify()*
9996 Simplify the file name as much as possible without changing
9997 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9998 Unix) are not resolved. If the first path component in
9999 {filename} designates the current directory, this will be
10000 valid for the result as well. A trailing path separator is
10001 not removed either. On Unix "//path" is unchanged, but
10002 "///path" is simplified to "/path" (this follows the Posix
10003 standard).
10004 Example: >
10005 simplify("./dir/.././/file/") == "./file/"
10006< Note: The combination "dir/.." is only removed if "dir" is
10007 a searchable directory or does not exist. On Unix, it is also
10008 removed when "dir" is a symbolic link within the same
10009 directory. In order to resolve all the involved symbolic
10010 links before simplifying the path name, use |resolve()|.
10011
10012 Can also be used as a |method|: >
10013 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010014<
10015 Return type: |String|
10016
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010017
10018sin({expr}) *sin()*
10019 Return the sine of {expr}, measured in radians, as a |Float|.
10020 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010021 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010022 Examples: >
10023 :echo sin(100)
10024< -0.506366 >
10025 :echo sin(-4.01)
10026< 0.763301
10027
10028 Can also be used as a |method|: >
10029 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010030<
10031 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010032
10033
10034sinh({expr}) *sinh()*
10035 Return the hyperbolic sine of {expr} as a |Float| in the range
10036 [-inf, inf].
10037 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010038 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010039 Examples: >
10040 :echo sinh(0.5)
10041< 0.521095 >
10042 :echo sinh(-0.9)
10043< -1.026517
10044
10045 Can also be used as a |method|: >
10046 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010047<
10048 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010049
10050
10051slice({expr}, {start} [, {end}]) *slice()*
10052 Similar to using a |slice| "expr[start : end]", but "end" is
10053 used exclusive. And for a string the indexes are used as
10054 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010055 |vim9script|. Also, composing characters are treated as a
10056 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010057 When {end} is omitted the slice continues to the last item.
10058 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010059 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010060
10061 Can also be used as a |method|: >
10062 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010063<
10064 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010065
10066
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010067sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010068 Sort the items in {list} in-place. Returns {list}.
10069
10070 If you want a list to remain unmodified make a copy first: >
10071 :let sortedlist = sort(copy(mylist))
10072
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010073< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010074 string representation of each item to sort on. Numbers sort
10075 after Strings, |Lists| after Numbers. For sorting text in the
10076 current buffer use |:sort|.
10077
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010078 When {how} is given and it is 'i' then case is ignored.
10079 In legacy script, for backwards compatibility, the value one
10080 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010081
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010082 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010083 locale is used for ordering. Implementation details: strcoll()
10084 is used to compare strings. See |:language| check or set the
10085 collation locale. |v:collate| can also be used to check the
10086 current locale. Sorting using the locale typically ignores
10087 case. Example: >
10088 " ö is sorted similarly to o with English locale.
10089 :language collate en_US.UTF8
10090 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10091< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10092>
10093 " ö is sorted after z with Swedish locale.
10094 :language collate sv_SE.UTF8
10095 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10096< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10097 This does not work properly on Mac.
10098
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010099 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010100 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010101 strtod() function to parse numbers. Strings, Lists, Dicts and
10102 Funcrefs will be considered as being 0). Note that this won't
10103 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010104
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010105 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010106 sorted numerical. This is like 'n' but a string containing
10107 digits will be used as the number they represent.
10108
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010109 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010110 sorted numerical. All values must be a Number or a Float.
10111
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010112 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010113 is called to compare items. The function is invoked with two
10114 items as argument and must return zero if they are equal, 1 or
10115 bigger if the first one sorts after the second one, -1 or
10116 smaller if the first one sorts before the second one.
10117
10118 {dict} is for functions with the "dict" attribute. It will be
10119 used to set the local variable "self". |Dictionary-function|
10120
10121 The sort is stable, items which compare equal (as number or as
10122 string) will keep their relative position. E.g., when sorting
10123 on numbers, text strings will sort next to each other, in the
10124 same order as they were originally.
10125
10126 Can also be used as a |method|: >
10127 mylist->sort()
10128
10129< Also see |uniq()|.
10130
10131 Example: >
10132 func MyCompare(i1, i2)
10133 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10134 endfunc
10135 eval mylist->sort("MyCompare")
10136< A shorter compare version for this specific simple case, which
10137 ignores overflow: >
10138 func MyCompare(i1, i2)
10139 return a:i1 - a:i2
10140 endfunc
10141< For a simple expression you can use a lambda: >
10142 eval mylist->sort({i1, i2 -> i1 - i2})
10143<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010144 Return type: list<{type}>
10145
10146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010147sound_clear() *sound_clear()*
10148 Stop playing all sounds.
10149
10150 On some Linux systems you may need the libcanberra-pulse
10151 package, otherwise sound may not stop.
10152
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010153 Return type: |Number|
10154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010155 {only available when compiled with the |+sound| feature}
10156
10157 *sound_playevent()*
10158sound_playevent({name} [, {callback}])
10159 Play a sound identified by {name}. Which event names are
10160 supported depends on the system. Often the XDG sound names
10161 are used. On Ubuntu they may be found in
10162 /usr/share/sounds/freedesktop/stereo. Example: >
10163 call sound_playevent('bell')
10164< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10165 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10166 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010167 On macOS, {name} refers to files located in
10168 /System/Library/Sounds (e.g. "Tink"). It will also work for
10169 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010170
10171 When {callback} is specified it is invoked when the sound is
10172 finished. The first argument is the sound ID, the second
10173 argument is the status:
10174 0 sound was played to the end
10175 1 sound was interrupted
10176 2 error occurred after sound started
10177 Example: >
10178 func Callback(id, status)
10179 echomsg "sound " .. a:id .. " finished with " .. a:status
10180 endfunc
10181 call sound_playevent('bell', 'Callback')
10182
10183< MS-Windows: {callback} doesn't work for this function.
10184
10185 Returns the sound ID, which can be passed to `sound_stop()`.
10186 Returns zero if the sound could not be played.
10187
10188 Can also be used as a |method|: >
10189 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010190<
10191 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010192
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010193 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010194
10195 *sound_playfile()*
10196sound_playfile({path} [, {callback}])
10197 Like `sound_playevent()` but play sound file {path}. {path}
10198 must be a full path. On Ubuntu you may find files to play
10199 with this command: >
10200 :!find /usr/share/sounds -type f | grep -v index.theme
10201
10202< Can also be used as a |method|: >
10203 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010204<
10205 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010206
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010207 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010208
10209
10210sound_stop({id}) *sound_stop()*
10211 Stop playing sound {id}. {id} must be previously returned by
10212 `sound_playevent()` or `sound_playfile()`.
10213
10214 On some Linux systems you may need the libcanberra-pulse
10215 package, otherwise sound may not stop.
10216
10217 On MS-Windows, this does not work for event sound started by
10218 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10219
10220 Can also be used as a |method|: >
10221 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010222<
10223 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010224
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010225 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010226
10227 *soundfold()*
10228soundfold({word})
10229 Return the sound-folded equivalent of {word}. Uses the first
10230 language in 'spelllang' for the current window that supports
10231 soundfolding. 'spell' must be set. When no sound folding is
10232 possible the {word} is returned unmodified.
10233 This can be used for making spelling suggestions. Note that
10234 the method can be quite slow.
10235
10236 Can also be used as a |method|: >
10237 GetWord()->soundfold()
10238<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010239 Return type: |String|
10240
10241
10242spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010243 Without argument: The result is the badly spelled word under
10244 or after the cursor. The cursor is moved to the start of the
10245 bad word. When no bad word is found in the cursor line the
10246 result is an empty string and the cursor doesn't move.
10247
10248 With argument: The result is the first word in {sentence} that
10249 is badly spelled. If there are no spelling mistakes the
10250 result is an empty string.
10251
10252 The return value is a list with two items:
10253 - The badly spelled word or an empty string.
10254 - The type of the spelling error:
10255 "bad" spelling mistake
10256 "rare" rare word
10257 "local" word only valid in another region
10258 "caps" word should start with Capital
10259 Example: >
10260 echo spellbadword("the quik brown fox")
10261< ['quik', 'bad'] ~
10262
10263 The spelling information for the current window and the value
10264 of 'spelllang' are used.
10265
10266 Can also be used as a |method|: >
10267 GetText()->spellbadword()
10268<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010269 Return type: list<string>
10270
10271
10272spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010273 Return a |List| with spelling suggestions to replace {word}.
10274 When {max} is given up to this number of suggestions are
10275 returned. Otherwise up to 25 suggestions are returned.
10276
10277 When the {capital} argument is given and it's non-zero only
10278 suggestions with a leading capital will be given. Use this
10279 after a match with 'spellcapcheck'.
10280
10281 {word} can be a badly spelled word followed by other text.
10282 This allows for joining two words that were split. The
10283 suggestions also include the following text, thus you can
10284 replace a line.
10285
10286 {word} may also be a good word. Similar words will then be
10287 returned. {word} itself is not included in the suggestions,
10288 although it may appear capitalized.
10289
10290 The spelling information for the current window is used. The
10291 values of 'spelllang' and 'spellsuggest' are used.
10292
10293 Can also be used as a |method|: >
10294 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010295<
10296 Return type: list<string> or list<any>
10297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010298
10299split({string} [, {pattern} [, {keepempty}]]) *split()*
10300 Make a |List| out of {string}. When {pattern} is omitted or
10301 empty each white-separated sequence of characters becomes an
10302 item.
10303 Otherwise the string is split where {pattern} matches,
10304 removing the matched characters. 'ignorecase' is not used
10305 here, add \c to ignore case. |/\c|
10306 When the first or last item is empty it is omitted, unless the
10307 {keepempty} argument is given and it's non-zero.
10308 Other empty items are kept when {pattern} matches at least one
10309 character or when {keepempty} is non-zero.
10310 Example: >
10311 :let words = split(getline('.'), '\W\+')
10312< To split a string in individual characters: >
10313 :for c in split(mystring, '\zs')
10314< If you want to keep the separator you can also use '\zs' at
10315 the end of the pattern: >
10316 :echo split('abc:def:ghi', ':\zs')
10317< ['abc:', 'def:', 'ghi'] ~
10318 Splitting a table where the first element can be empty: >
10319 :let items = split(line, ':', 1)
10320< The opposite function is |join()|.
10321
10322 Can also be used as a |method|: >
10323 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010324<
10325 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010326
10327sqrt({expr}) *sqrt()*
10328 Return the non-negative square root of Float {expr} as a
10329 |Float|.
10330 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010331 is negative the result is NaN (Not a Number). Returns 0.0 if
10332 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010333 Examples: >
10334 :echo sqrt(100)
10335< 10.0 >
10336 :echo sqrt(-4.01)
10337< nan
10338 "nan" may be different, it depends on system libraries.
10339
10340 Can also be used as a |method|: >
10341 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010342<
10343 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010344
10345
10346srand([{expr}]) *srand()*
10347 Initialize seed used by |rand()|:
10348 - If {expr} is not given, seed values are initialized by
10349 reading from /dev/urandom, if possible, or using time(NULL)
10350 a.k.a. epoch time otherwise; this only has second accuracy.
10351 - If {expr} is given it must be a Number. It is used to
10352 initialize the seed values. This is useful for testing or
10353 when a predictable sequence is intended.
10354
10355 Examples: >
10356 :let seed = srand()
10357 :let seed = srand(userinput)
10358 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010359<
10360 Return type: list<number>
10361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010362
10363state([{what}]) *state()*
10364 Return a string which contains characters indicating the
10365 current state. Mostly useful in callbacks that want to do
10366 work that may not always be safe. Roughly this works like:
10367 - callback uses state() to check if work is safe to do.
10368 Yes: then do it right away.
10369 No: add to work queue and add a |SafeState| and/or
10370 |SafeStateAgain| autocommand (|SafeState| triggers at
10371 toplevel, |SafeStateAgain| triggers after handling
10372 messages and callbacks).
10373 - When SafeState or SafeStateAgain is triggered and executes
10374 your autocommand, check with `state()` if the work can be
10375 done now, and if yes remove it from the queue and execute.
10376 Remove the autocommand if the queue is now empty.
10377 Also see |mode()|.
10378
10379 When {what} is given only characters in this string will be
10380 added. E.g, this checks if the screen has scrolled: >
10381 if state('s') == ''
10382 " screen has not scrolled
10383<
10384 These characters indicate the state, generally indicating that
10385 something is busy:
10386 m halfway a mapping, :normal command, feedkeys() or
10387 stuffed command
10388 o operator pending, e.g. after |d|
10389 a Insert mode autocomplete active
10390 x executing an autocommand
10391 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10392 ch_readraw() when reading json
10393 S not triggering SafeState or SafeStateAgain, e.g. after
10394 |f| or a count
10395 c callback invoked, including timer (repeats for
10396 recursiveness up to "ccc")
10397 s screen has scrolled for messages
10398
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010399 Return type: |String|
10400
10401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010402str2float({string} [, {quoted}]) *str2float()*
10403 Convert String {string} to a Float. This mostly works the
10404 same as when using a floating point number in an expression,
10405 see |floating-point-format|. But it's a bit more permissive.
10406 E.g., "1e40" is accepted, while in an expression you need to
10407 write "1.0e40". The hexadecimal form "0x123" is also
10408 accepted, but not others, like binary or octal.
10409 When {quoted} is present and non-zero then embedded single
10410 quotes before the dot are ignored, thus "1'000.0" is a
10411 thousand.
10412 Text after the number is silently ignored.
10413 The decimal point is always '.', no matter what the locale is
10414 set to. A comma ends the number: "12,345.67" is converted to
10415 12.0. You can strip out thousands separators with
10416 |substitute()|: >
10417 let f = str2float(substitute(text, ',', '', 'g'))
10418<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010419 Returns 0.0 if the conversion fails.
10420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010421 Can also be used as a |method|: >
10422 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010423<
10424 Return type: |Float|
10425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010426
10427str2list({string} [, {utf8}]) *str2list()*
10428 Return a list containing the number values which represent
10429 each character in String {string}. Examples: >
10430 str2list(" ") returns [32]
10431 str2list("ABC") returns [65, 66, 67]
10432< |list2str()| does the opposite.
10433
10434 When {utf8} is omitted or zero, the current 'encoding' is used.
10435 When {utf8} is TRUE, always treat the String as UTF-8
10436 characters. With UTF-8 composing characters are handled
10437 properly: >
10438 str2list("á") returns [97, 769]
10439
10440< Can also be used as a |method|: >
10441 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010442<
10443 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010444
10445
10446str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10447 Convert string {string} to a number.
10448 {base} is the conversion base, it can be 2, 8, 10 or 16.
10449 When {quoted} is present and non-zero then embedded single
10450 quotes are ignored, thus "1'000'000" is a million.
10451
10452 When {base} is omitted base 10 is used. This also means that
10453 a leading zero doesn't cause octal conversion to be used, as
10454 with the default String to Number conversion. Example: >
10455 let nr = str2nr('0123')
10456<
10457 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10458 different base the result will be zero. Similarly, when
10459 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10460 {base} is 2 a leading "0b" or "0B" is ignored.
10461 Text after the number is silently ignored.
10462
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010463 Returns 0 if {string} is empty or on error.
10464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010465 Can also be used as a |method|: >
10466 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010467<
10468 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010469
10470
10471strcharlen({string}) *strcharlen()*
10472 The result is a Number, which is the number of characters
10473 in String {string}. Composing characters are ignored.
10474 |strchars()| can count the number of characters, counting
10475 composing characters separately.
10476
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010477 Returns 0 if {string} is empty or on error.
10478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010479 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10480
10481 Can also be used as a |method|: >
10482 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010483<
10484 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010485
10486
10487strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10488 Like |strpart()| but using character index and length instead
10489 of byte index and length.
10490 When {skipcc} is omitted or zero, composing characters are
10491 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010492 When {skipcc} set to 1, composing characters are treated as a
10493 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010494 When a character index is used where a character does not
10495 exist it is omitted and counted as one character. For
10496 example: >
10497 strcharpart('abc', -1, 2)
10498< results in 'a'.
10499
Bram Moolenaard592deb2022-06-17 15:42:40 +010010500 Returns an empty string on error.
10501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010502 Can also be used as a |method|: >
10503 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010504<
10505 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010506
10507
10508strchars({string} [, {skipcc}]) *strchars()*
10509 The result is a Number, which is the number of characters
10510 in String {string}.
10511 When {skipcc} is omitted or zero, composing characters are
10512 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010513 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010514 |strcharlen()| always does this.
10515
Bram Moolenaard592deb2022-06-17 15:42:40 +010010516 Returns zero on error.
10517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010518 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10519
10520 {skipcc} is only available after 7.4.755. For backward
10521 compatibility, you can define a wrapper function: >
10522 if has("patch-7.4.755")
10523 function s:strchars(str, skipcc)
10524 return strchars(a:str, a:skipcc)
10525 endfunction
10526 else
10527 function s:strchars(str, skipcc)
10528 if a:skipcc
10529 return strlen(substitute(a:str, ".", "x", "g"))
10530 else
10531 return strchars(a:str)
10532 endif
10533 endfunction
10534 endif
10535<
10536 Can also be used as a |method|: >
10537 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010538<
10539 Return type: |Number|
10540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010541
10542strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10543 The result is a Number, which is the number of display cells
10544 String {string} occupies on the screen when it starts at {col}
10545 (first column is zero). When {col} is omitted zero is used.
10546 Otherwise it is the screen column where to start. This
10547 matters for Tab characters.
10548 The option settings of the current window are used. This
10549 matters for anything that's displayed differently, such as
10550 'tabstop' and 'display'.
10551 When {string} contains characters with East Asian Width Class
10552 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010553 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010554 Also see |strlen()|, |strwidth()| and |strchars()|.
10555
10556 Can also be used as a |method|: >
10557 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010558<
10559 Return type: |Number|
10560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010561
10562strftime({format} [, {time}]) *strftime()*
10563 The result is a String, which is a formatted date and time, as
10564 specified by the {format} string. The given {time} is used,
10565 or the current time if no time is given. The accepted
10566 {format} depends on your system, thus this is not portable!
10567 See the manual page of the C function strftime() for the
10568 format. The maximum length of the result is 80 characters.
10569 See also |localtime()|, |getftime()| and |strptime()|.
10570 The language can be changed with the |:language| command.
10571 Examples: >
10572 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10573 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10574 :echo strftime("%y%m%d %T") 970427 11:53:55
10575 :echo strftime("%H:%M") 11:55
10576 :echo strftime("%c", getftime("file.c"))
10577 Show mod time of file.c.
10578< Not available on all systems. To check use: >
10579 :if exists("*strftime")
10580
10581< Can also be used as a |method|: >
10582 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010583<
10584 Return type: |String|
10585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010586
10587strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010588 Get a Number corresponding to the character at {index} in
10589 {str}. This uses a zero-based character index, not a byte
10590 index. Composing characters are considered separate
10591 characters here. Use |nr2char()| to convert the Number to a
10592 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010593 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010594 Also see |strcharpart()| and |strchars()|.
10595
10596 Can also be used as a |method|: >
10597 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010598<
10599 Return type: |Number|
10600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010601
10602stridx({haystack}, {needle} [, {start}]) *stridx()*
10603 The result is a Number, which gives the byte index in
10604 {haystack} of the first occurrence of the String {needle}.
10605 If {start} is specified, the search starts at index {start}.
10606 This can be used to find a second match: >
10607 :let colon1 = stridx(line, ":")
10608 :let colon2 = stridx(line, ":", colon1 + 1)
10609< The search is done case-sensitive.
10610 For pattern searches use |match()|.
10611 -1 is returned if the {needle} does not occur in {haystack}.
10612 See also |strridx()|.
10613 Examples: >
10614 :echo stridx("An Example", "Example") 3
10615 :echo stridx("Starting point", "Start") 0
10616 :echo stridx("Starting point", "start") -1
10617< *strstr()* *strchr()*
10618 stridx() works similar to the C function strstr(). When used
10619 with a single character it works similar to strchr().
10620
10621 Can also be used as a |method|: >
10622 GetHaystack()->stridx(needle)
10623<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010624 Return type: |Number|
10625
10626
10627string({expr}) *string()*
10628 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010629 Float, String, Blob or a composition of them, then the result
10630 can be parsed back with |eval()|.
10631 {expr} type result ~
10632 String 'string' (single quotes are doubled)
10633 Number 123
10634 Float 123.123456 or 1.123456e8
10635 Funcref function('name')
10636 Blob 0z00112233.44556677.8899
10637 List [item, item]
10638 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010639 Class class SomeName
10640 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010641 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010642 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010643
10644 When a |List| or |Dictionary| has a recursive reference it is
10645 replaced by "[...]" or "{...}". Using eval() on the result
10646 will then fail.
10647
mityu7f0bba22024-03-29 10:14:41 +010010648 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010649 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010650 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010652 Can also be used as a |method|: >
10653 mylist->string()
10654
10655< Also see |strtrans()|.
10656
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010657 Return type: |String|
10658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010659
10660strlen({string}) *strlen()*
10661 The result is a Number, which is the length of the String
10662 {string} in bytes.
10663 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010664 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010665 If you want to count the number of multibyte characters use
10666 |strchars()|.
10667 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10668
10669 Can also be used as a |method|: >
10670 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010671<
10672 Return type: |Number|
10673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010674
10675strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10676 The result is a String, which is part of {src}, starting from
10677 byte {start}, with the byte length {len}.
10678 When {chars} is present and TRUE then {len} is the number of
10679 characters positions (composing characters are not counted
10680 separately, thus "1" means one base character and any
10681 following composing characters).
10682 To count {start} as characters instead of bytes use
10683 |strcharpart()|.
10684
10685 When bytes are selected which do not exist, this doesn't
10686 result in an error, the bytes are simply omitted.
10687 If {len} is missing, the copy continues from {start} till the
10688 end of the {src}. >
10689 strpart("abcdefg", 3, 2) == "de"
10690 strpart("abcdefg", -2, 4) == "ab"
10691 strpart("abcdefg", 5, 4) == "fg"
10692 strpart("abcdefg", 3) == "defg"
10693
10694< Note: To get the first character, {start} must be 0. For
10695 example, to get the character under the cursor: >
10696 strpart(getline("."), col(".") - 1, 1, v:true)
10697<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010698 Returns an empty string on error.
10699
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010700 Can also be used as a |method|: >
10701 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010702<
10703 Return type: |String|
10704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010705
10706strptime({format}, {timestring}) *strptime()*
10707 The result is a Number, which is a unix timestamp representing
10708 the date and time in {timestring}, which is expected to match
10709 the format specified in {format}.
10710
10711 The accepted {format} depends on your system, thus this is not
10712 portable! See the manual page of the C function strptime()
10713 for the format. Especially avoid "%c". The value of $TZ also
10714 matters.
10715
10716 If the {timestring} cannot be parsed with {format} zero is
10717 returned. If you do not know the format of {timestring} you
10718 can try different {format} values until you get a non-zero
10719 result.
10720
10721 See also |strftime()|.
10722 Examples: >
10723 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10724< 862156163 >
10725 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10726< Sun Apr 27 11:53:55 1997 >
10727 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10728< Sun Apr 27 12:53:55 1997
10729
10730 Can also be used as a |method|: >
10731 GetFormat()->strptime(timestring)
10732<
10733 Not available on all systems. To check use: >
10734 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010735<
10736 Return type: |Number|
10737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010738
10739strridx({haystack}, {needle} [, {start}]) *strridx()*
10740 The result is a Number, which gives the byte index in
10741 {haystack} of the last occurrence of the String {needle}.
10742 When {start} is specified, matches beyond this index are
10743 ignored. This can be used to find a match before a previous
10744 match: >
10745 :let lastcomma = strridx(line, ",")
10746 :let comma2 = strridx(line, ",", lastcomma - 1)
10747< The search is done case-sensitive.
10748 For pattern searches use |match()|.
10749 -1 is returned if the {needle} does not occur in {haystack}.
10750 If the {needle} is empty the length of {haystack} is returned.
10751 See also |stridx()|. Examples: >
10752 :echo strridx("an angry armadillo", "an") 3
10753< *strrchr()*
10754 When used with a single character it works similar to the C
10755 function strrchr().
10756
10757 Can also be used as a |method|: >
10758 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010759<
10760 Return type: |Number|
10761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010762
10763strtrans({string}) *strtrans()*
10764 The result is a String, which is {string} with all unprintable
10765 characters translated into printable characters |'isprint'|.
10766 Like they are shown in a window. Example: >
10767 echo strtrans(@a)
10768< This displays a newline in register a as "^@" instead of
10769 starting a new line.
10770
Bram Moolenaard592deb2022-06-17 15:42:40 +010010771 Returns an empty string on error.
10772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010773 Can also be used as a |method|: >
10774 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010775<
10776 Return type: |String|
10777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010778
Christian Brabandt67672ef2023-04-24 21:09:54 +010010779strutf16len({string} [, {countcc}]) *strutf16len()*
10780 The result is a Number, which is the number of UTF-16 code
10781 units in String {string} (after converting it to UTF-16).
10782
10783 When {countcc} is TRUE, composing characters are counted
10784 separately.
10785 When {countcc} is omitted or FALSE, composing characters are
10786 ignored.
10787
10788 Returns zero on error.
10789
10790 Also see |strlen()| and |strcharlen()|.
10791 Examples: >
10792 echo strutf16len('a') returns 1
10793 echo strutf16len('©') returns 1
10794 echo strutf16len('😊') returns 2
10795 echo strutf16len('ą́') returns 1
10796 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010797<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010798 Can also be used as a |method|: >
10799 GetText()->strutf16len()
10800<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010801 Return type: |Number|
10802
10803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010804strwidth({string}) *strwidth()*
10805 The result is a Number, which is the number of display cells
10806 String {string} occupies. A Tab character is counted as one
10807 cell, alternatively use |strdisplaywidth()|.
10808 When {string} contains characters with East Asian Width Class
10809 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010810 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010811 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10812
10813 Can also be used as a |method|: >
10814 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010815<
10816 Return type: |Number|
10817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010818
10819submatch({nr} [, {list}]) *submatch()* *E935*
10820 Only for an expression in a |:substitute| command or
10821 substitute() function.
10822 Returns the {nr}'th submatch of the matched text. When {nr}
10823 is 0 the whole matched text is returned.
10824 Note that a NL in the string can stand for a line break of a
10825 multi-line match or a NUL character in the text.
10826 Also see |sub-replace-expression|.
10827
10828 If {list} is present and non-zero then submatch() returns
10829 a list of strings, similar to |getline()| with two arguments.
10830 NL characters in the text represent NUL characters in the
10831 text.
10832 Only returns more than one item for |:substitute|, inside
10833 |substitute()| this list will always contain one or zero
10834 items, since there are no real line breaks.
10835
10836 When substitute() is used recursively only the submatches in
10837 the current (deepest) call can be obtained.
10838
Bram Moolenaard592deb2022-06-17 15:42:40 +010010839 Returns an empty string or list on error.
10840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841 Examples: >
10842 :s/\d\+/\=submatch(0) + 1/
10843 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10844< This finds the first number in the line and adds one to it.
10845 A line break is included as a newline character.
10846
10847 Can also be used as a |method|: >
10848 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010849<
10850 Return type: |String| or list<string> depending on {list}
10851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010852
10853substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10854 The result is a String, which is a copy of {string}, in which
10855 the first match of {pat} is replaced with {sub}.
10856 When {flags} is "g", all matches of {pat} in {string} are
10857 replaced. Otherwise {flags} should be "".
10858
10859 This works like the ":substitute" command (without any flags).
10860 But the matching with {pat} is always done like the 'magic'
10861 option is set and 'cpoptions' is empty (to make scripts
10862 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10863 if you want to ignore or match case and ignore 'ignorecase'.
10864 'smartcase' is not used. See |string-match| for how {pat} is
10865 used.
10866
10867 A "~" in {sub} is not replaced with the previous {sub}.
10868 Note that some codes in {sub} have a special meaning
10869 |sub-replace-special|. For example, to replace something with
10870 "\n" (two characters), use "\\\\n" or '\\n'.
10871
10872 When {pat} does not match in {string}, {string} is returned
10873 unmodified.
10874
10875 Example: >
10876 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10877< This removes the last component of the 'path' option. >
10878 :echo substitute("testing", ".*", "\\U\\0", "")
10879< results in "TESTING".
10880
10881 When {sub} starts with "\=", the remainder is interpreted as
10882 an expression. See |sub-replace-expression|. Example: >
10883 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010884 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010885
10886< When {sub} is a Funcref that function is called, with one
10887 optional argument. Example: >
10888 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10889< The optional argument is a list which contains the whole
10890 matched string and up to nine submatches, like what
10891 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010892 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010893
Bram Moolenaard592deb2022-06-17 15:42:40 +010010894< Returns an empty string on error.
10895
10896 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010897 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010898<
10899 Return type: |String|
10900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010901
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010902swapfilelist() *swapfilelist()*
10903 Returns a list of swap file names, like what "vim -r" shows.
10904 See the |-r| command argument. The 'directory' option is used
10905 for the directories to inspect. If you only want to get a
10906 list of swap files in the current directory then temporarily
10907 set 'directory' to a dot: >
10908 let save_dir = &directory
10909 let &directory = '.'
10910 let swapfiles = swapfilelist()
10911 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010912<
10913 Return type: list<string>
10914
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010915
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010916swapinfo({fname}) *swapinfo()*
10917 The result is a dictionary, which holds information about the
10918 swapfile {fname}. The available fields are:
10919 version Vim version
10920 user user name
10921 host host name
10922 fname original file name
10923 pid PID of the Vim process that created the swap
10924 file
10925 mtime last modification time in seconds
10926 inode Optional: INODE number of the file
10927 dirty 1 if file was modified, 0 if not
10928 Note that "user" and "host" are truncated to at most 39 bytes.
10929 In case of failure an "error" item is added with the reason:
10930 Cannot open file: file not found or in accessible
10931 Cannot read file: cannot read first block
10932 Not a swap file: does not contain correct block ID
10933 Magic number mismatch: Info in first block is invalid
10934
10935 Can also be used as a |method|: >
10936 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010937<
10938 Return type: dict<any> or dict<string>
10939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010940
10941swapname({buf}) *swapname()*
10942 The result is the swap file path of the buffer {expr}.
10943 For the use of {buf}, see |bufname()| above.
10944 If buffer {buf} is the current buffer, the result is equal to
10945 |:swapname| (unless there is no swap file).
10946 If buffer {buf} has no swap file, returns an empty string.
10947
10948 Can also be used as a |method|: >
10949 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010950<
10951 Return type: |String|
10952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010953
10954synID({lnum}, {col}, {trans}) *synID()*
10955 The result is a Number, which is the syntax ID at the position
10956 {lnum} and {col} in the current window.
10957 The syntax ID can be used with |synIDattr()| and
10958 |synIDtrans()| to obtain syntax information about text.
10959
10960 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10961 line. 'synmaxcol' applies, in a longer line zero is returned.
10962 Note that when the position is after the last character,
10963 that's where the cursor can be in Insert mode, synID() returns
10964 zero. {lnum} is used like with |getline()|.
10965
10966 When {trans} is |TRUE|, transparent items are reduced to the
10967 item that they reveal. This is useful when wanting to know
10968 the effective color. When {trans} is |FALSE|, the transparent
10969 item is returned. This is useful when wanting to know which
10970 syntax item is effective (e.g. inside parens).
10971 Warning: This function can be very slow. Best speed is
10972 obtained by going through the file in forward direction.
10973
Bram Moolenaard592deb2022-06-17 15:42:40 +010010974 Returns zero on error.
10975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010976 Example (echoes the name of the syntax item under the cursor): >
10977 :echo synIDattr(synID(line("."), col("."), 1), "name")
10978<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010979 Return type: |Number|
10980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010981
10982synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10983 The result is a String, which is the {what} attribute of
10984 syntax ID {synID}. This can be used to obtain information
10985 about a syntax item.
10986 {mode} can be "gui", "cterm" or "term", to get the attributes
10987 for that mode. When {mode} is omitted, or an invalid value is
10988 used, the attributes for the currently active highlighting are
10989 used (GUI, cterm or term).
10990 Use synIDtrans() to follow linked highlight groups.
10991 {what} result
10992 "name" the name of the syntax item
10993 "fg" foreground color (GUI: color name used to set
10994 the color, cterm: color number as a string,
10995 term: empty string)
10996 "bg" background color (as with "fg")
10997 "font" font name (only available in the GUI)
10998 |highlight-font|
10999 "sp" special color for the GUI (as with "fg")
11000 |highlight-guisp|
11001 "ul" underline color for cterm: number as a string
11002 "fg#" like "fg", but for the GUI and the GUI is
11003 running the name in "#RRGGBB" form
11004 "bg#" like "fg#" for "bg"
11005 "sp#" like "fg#" for "sp"
11006 "bold" "1" if bold
11007 "italic" "1" if italic
11008 "reverse" "1" if reverse
11009 "inverse" "1" if inverse (= reverse)
11010 "standout" "1" if standout
11011 "underline" "1" if underlined
11012 "undercurl" "1" if undercurled
11013 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011014 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011015
Bram Moolenaard592deb2022-06-17 15:42:40 +010011016 Returns an empty string on error.
11017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011018 Example (echoes the color of the syntax item under the
11019 cursor): >
11020 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11021<
11022 Can also be used as a |method|: >
11023 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011024<
11025 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011026
11027
11028synIDtrans({synID}) *synIDtrans()*
11029 The result is a Number, which is the translated syntax ID of
11030 {synID}. This is the syntax group ID of what is being used to
11031 highlight the character. Highlight links given with
11032 ":highlight link" are followed.
11033
Bram Moolenaard592deb2022-06-17 15:42:40 +010011034 Returns zero on error.
11035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011036 Can also be used as a |method|: >
11037 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011038<
11039 Return type: |Number|
11040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011041
11042synconcealed({lnum}, {col}) *synconcealed()*
11043 The result is a |List| with currently three items:
11044 1. The first item in the list is 0 if the character at the
11045 position {lnum} and {col} is not part of a concealable
11046 region, 1 if it is. {lnum} is used like with |getline()|.
11047 2. The second item in the list is a string. If the first item
11048 is 1, the second item contains the text which will be
11049 displayed in place of the concealed text, depending on the
11050 current setting of 'conceallevel' and 'listchars'.
11051 3. The third and final item in the list is a number
11052 representing the specific syntax region matched in the
11053 line. When the character is not concealed the value is
11054 zero. This allows detection of the beginning of a new
11055 concealable region if there are two consecutive regions
11056 with the same replacement character. For an example, if
11057 the text is "123456" and both "23" and "45" are concealed
11058 and replaced by the character "X", then:
11059 call returns ~
11060 synconcealed(lnum, 1) [0, '', 0]
11061 synconcealed(lnum, 2) [1, 'X', 1]
11062 synconcealed(lnum, 3) [1, 'X', 1]
11063 synconcealed(lnum, 4) [1, 'X', 2]
11064 synconcealed(lnum, 5) [1, 'X', 2]
11065 synconcealed(lnum, 6) [0, '', 0]
11066
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011067 Note: Doesn't consider |matchadd()| highlighting items,
11068 since syntax and matching highlighting are two different
11069 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011070<
11071 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011073
11074synstack({lnum}, {col}) *synstack()*
11075 Return a |List|, which is the stack of syntax items at the
11076 position {lnum} and {col} in the current window. {lnum} is
11077 used like with |getline()|. Each item in the List is an ID
11078 like what |synID()| returns.
11079 The first item in the List is the outer region, following are
11080 items contained in that one. The last one is what |synID()|
11081 returns, unless not the whole item is highlighted or it is a
11082 transparent item.
11083 This function is useful for debugging a syntax file.
11084 Example that shows the syntax stack under the cursor: >
11085 for id in synstack(line("."), col("."))
11086 echo synIDattr(id, "name")
11087 endfor
11088< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011089 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011090 character in a line and the first column in an empty line are
11091 valid positions.
11092
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011093 Return type: list<number> or list<any>
11094
11095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011096system({expr} [, {input}]) *system()* *E677*
11097 Get the output of the shell command {expr} as a |String|. See
11098 |systemlist()| to get the output as a |List|.
11099
11100 When {input} is given and is a |String| this string is written
11101 to a file and passed as stdin to the command. The string is
11102 written as-is, you need to take care of using the correct line
11103 separators yourself.
11104 If {input} is given and is a |List| it is written to the file
11105 in a way |writefile()| does with {binary} set to "b" (i.e.
11106 with a newline between each list item with newlines inside
11107 list items converted to NULs).
11108 When {input} is given and is a number that is a valid id for
11109 an existing buffer then the content of the buffer is written
11110 to the file line by line, each line terminated by a NL and
11111 NULs characters where the text has a NL.
11112
11113 Pipes are not used, the 'shelltemp' option is not used.
11114
11115 When prepended by |:silent| the terminal will not be set to
11116 cooked mode. This is meant to be used for commands that do
11117 not need the user to type. It avoids stray characters showing
11118 up on the screen which require |CTRL-L| to remove. >
11119 :silent let f = system('ls *.vim')
11120<
11121 Note: Use |shellescape()| or |::S| with |expand()| or
11122 |fnamemodify()| to escape special characters in a command
11123 argument. Newlines in {expr} may cause the command to fail.
11124 The characters in 'shellquote' and 'shellxquote' may also
11125 cause trouble.
11126 This is not to be used for interactive commands.
11127
11128 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011129 :let files = system('ls ' .. shellescape(expand('%:h')))
11130 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011131
11132< To make the result more system-independent, the shell output
11133 is filtered to replace <CR> with <NL> for Macintosh, and
11134 <CR><NL> with <NL> for DOS-like systems.
11135 To avoid the string being truncated at a NUL, all NUL
11136 characters are replaced with SOH (0x01).
11137
11138 The command executed is constructed using several options:
11139 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11140 ({tmp} is an automatically generated file name).
11141 For Unix, braces are put around {expr} to allow for
11142 concatenated commands.
11143
11144 The command will be executed in "cooked" mode, so that a
11145 CTRL-C will interrupt the command (on Unix at least).
11146
11147 The resulting error code can be found in |v:shell_error|.
11148 This function will fail in |restricted-mode|.
11149
11150 Note that any wrong value in the options mentioned above may
11151 make the function fail. It has also been reported to fail
11152 when using a security agent application.
11153 Unlike ":!cmd" there is no automatic check for changed files.
11154 Use |:checktime| to force a check.
11155
11156 Can also be used as a |method|: >
11157 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011158<
11159 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011160
11161
11162systemlist({expr} [, {input}]) *systemlist()*
11163 Same as |system()|, but returns a |List| with lines (parts of
11164 output separated by NL) with NULs transformed into NLs. Output
11165 is the same as |readfile()| will output with {binary} argument
11166 set to "b", except that there is no extra empty item when the
11167 result ends in a NL.
11168 Note that on MS-Windows you may get trailing CR characters.
11169
11170 To see the difference between "echo hello" and "echo -n hello"
11171 use |system()| and |split()|: >
11172 echo system('echo hello')->split('\n', 1)
11173<
11174 Returns an empty string on error.
11175
11176 Can also be used as a |method|: >
11177 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011178<
11179 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011180
11181
11182tabpagebuflist([{arg}]) *tabpagebuflist()*
11183 The result is a |List|, where each item is the number of the
11184 buffer associated with each window in the current tab page.
11185 {arg} specifies the number of the tab page to be used. When
11186 omitted the current tab page is used.
11187 When {arg} is invalid the number zero is returned.
11188 To get a list of all buffers in all tabs use this: >
11189 let buflist = []
11190 for i in range(tabpagenr('$'))
11191 call extend(buflist, tabpagebuflist(i + 1))
11192 endfor
11193< Note that a buffer may appear in more than one window.
11194
11195 Can also be used as a |method|: >
11196 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011197<
11198 Return type: list<number>
11199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011200
11201tabpagenr([{arg}]) *tabpagenr()*
11202 The result is a Number, which is the number of the current
11203 tab page. The first tab page has number 1.
11204
11205 The optional argument {arg} supports the following values:
11206 $ the number of the last tab page (the tab page
11207 count).
11208 # the number of the last accessed tab page
11209 (where |g<Tab>| goes to). if there is no
11210 previous tab page 0 is returned.
11211 The number can be used with the |:tab| command.
11212
Bram Moolenaard592deb2022-06-17 15:42:40 +010011213 Returns zero on error.
11214
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011215 Return type: |Number|
11216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011217
11218tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11219 Like |winnr()| but for tab page {tabarg}.
11220 {tabarg} specifies the number of tab page to be used.
11221 {arg} is used like with |winnr()|:
11222 - When omitted the current window number is returned. This is
11223 the window which will be used when going to this tab page.
11224 - When "$" the number of windows is returned.
11225 - When "#" the previous window nr is returned.
11226 Useful examples: >
11227 tabpagewinnr(1) " current window of tab page 1
11228 tabpagewinnr(4, '$') " number of windows in tab page 4
11229< When {tabarg} is invalid zero is returned.
11230
11231 Can also be used as a |method|: >
11232 GetTabpage()->tabpagewinnr()
11233<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011234 Return type: |Number|
11235
11236
11237tagfiles() *tagfiles()*
11238 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011239 for the current buffer. This is the 'tags' option expanded.
11240
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011241 Return type: list<string> or list<any>
11242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011243
11244taglist({expr} [, {filename}]) *taglist()*
11245 Returns a |List| of tags matching the regular expression {expr}.
11246
11247 If {filename} is passed it is used to prioritize the results
11248 in the same way that |:tselect| does. See |tag-priority|.
11249 {filename} should be the full path of the file.
11250
11251 Each list item is a dictionary with at least the following
11252 entries:
11253 name Name of the tag.
11254 filename Name of the file where the tag is
11255 defined. It is either relative to the
11256 current directory or a full path.
11257 cmd Ex command used to locate the tag in
11258 the file.
11259 kind Type of the tag. The value for this
11260 entry depends on the language specific
11261 kind values. Only available when
11262 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011263 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011264 static A file specific tag. Refer to
11265 |static-tag| for more information.
11266 More entries may be present, depending on the content of the
11267 tags file: access, implementation, inherits and signature.
11268 Refer to the ctags documentation for information about these
11269 fields. For C code the fields "struct", "class" and "enum"
11270 may appear, they give the name of the entity the tag is
11271 contained in.
11272
11273 The ex-command "cmd" can be either an ex search pattern, a
11274 line number or a line number followed by a byte number.
11275
11276 If there are no matching tags, then an empty list is returned.
11277
11278 To get an exact tag match, the anchors '^' and '$' should be
11279 used in {expr}. This also make the function work faster.
11280 Refer to |tag-regexp| for more information about the tag
11281 search regular expression pattern.
11282
11283 Refer to |'tags'| for information about how the tags file is
11284 located by Vim. Refer to |tags-file-format| for the format of
11285 the tags file generated by the different ctags tools.
11286
11287 Can also be used as a |method|: >
11288 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011289<
11290 Return type: list<dict<any>> or list<any>
11291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011292
11293tan({expr}) *tan()*
11294 Return the tangent of {expr}, measured in radians, as a |Float|
11295 in the range [-inf, inf].
11296 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011297 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011298 Examples: >
11299 :echo tan(10)
11300< 0.648361 >
11301 :echo tan(-4.01)
11302< -1.181502
11303
11304 Can also be used as a |method|: >
11305 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011306<
11307 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011308
11309
11310tanh({expr}) *tanh()*
11311 Return the hyperbolic tangent of {expr} as a |Float| in the
11312 range [-1, 1].
11313 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011314 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011315 Examples: >
11316 :echo tanh(0.5)
11317< 0.462117 >
11318 :echo tanh(-1)
11319< -0.761594
11320
11321 Can also be used as a |method|: >
11322 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011323<
11324 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011325
11326
11327tempname() *tempname()* *temp-file-name*
11328 The result is a String, which is the name of a file that
11329 doesn't exist. It can be used for a temporary file. The name
11330 is different for at least 26 consecutive calls. Example: >
11331 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011332 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011333< For Unix, the file will be in a private directory |tempfile|
11334 that is recursively deleted when Vim exits, on other systems
11335 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011336 For MS-Windows forward slashes are used when the 'shellslash'
11337 option is set, or when 'shellcmdflag' starts with '-' and
11338 'shell' does not contain powershell or pwsh.
11339
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011340 Return type: |String|
11341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011342
11343term_ functions are documented here: |terminal-function-details|
11344
11345
11346terminalprops() *terminalprops()*
11347 Returns a |Dictionary| with properties of the terminal that Vim
11348 detected from the response to |t_RV| request. See
11349 |v:termresponse| for the response itself. If |v:termresponse|
11350 is empty most values here will be 'u' for unknown.
11351 cursor_style whether sending |t_RS| works **
11352 cursor_blink_mode whether sending |t_RC| works **
11353 underline_rgb whether |t_8u| works **
11354 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011355 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011356
11357 ** value 'u' for unknown, 'y' for yes, 'n' for no
11358
11359 If the |+termresponse| feature is missing then the result is
11360 an empty dictionary.
11361
11362 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11363 current cursor style.
11364 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11365 request the cursor blink status.
11366 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11367 is not empty, Vim will detect the working of sending |t_RS|
11368 and |t_RC| on startup.
11369
11370 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11371 This avoids sending it to xterm, which would clear the colors.
11372
11373 For "mouse" the value 'u' is unknown
11374
11375 Also see:
11376 - 'ambiwidth' - detected by using |t_u7|.
11377 - |v:termstyleresp| and |v:termblinkresp| for the response to
11378 |t_RS| and |t_RC|.
11379
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011380 Return type: dict<string>
11381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011382
11383test_ functions are documented here: |test-functions-details|
11384
11385
11386 *timer_info()*
11387timer_info([{id}])
11388 Return a list with information about timers.
11389 When {id} is given only information about this timer is
11390 returned. When timer {id} does not exist an empty list is
11391 returned.
11392 When {id} is omitted information about all timers is returned.
11393
11394 For each timer the information is stored in a |Dictionary| with
11395 these items:
11396 "id" the timer ID
11397 "time" time the timer was started with
11398 "remaining" time until the timer fires
11399 "repeat" number of times the timer will still fire;
11400 -1 means forever
11401 "callback" the callback
11402 "paused" 1 if the timer is paused, 0 otherwise
11403
11404 Can also be used as a |method|: >
11405 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011406<
11407 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011408
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011409 {only available when compiled with the |+timers| feature}
11410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011411
11412timer_pause({timer}, {paused}) *timer_pause()*
11413 Pause or unpause a timer. A paused timer does not invoke its
11414 callback when its time expires. Unpausing a timer may cause
11415 the callback to be invoked almost immediately if enough time
11416 has passed.
11417
11418 Pausing a timer is useful to avoid the callback to be called
11419 for a short time.
11420
11421 If {paused} evaluates to a non-zero Number or a non-empty
11422 String, then the timer is paused, otherwise it is unpaused.
11423 See |non-zero-arg|.
11424
11425 Can also be used as a |method|: >
11426 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011427<
11428 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011429
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011430 {only available when compiled with the |+timers| feature}
11431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011432
11433 *timer_start()* *timer* *timers*
11434timer_start({time}, {callback} [, {options}])
11435 Create a timer and return the timer ID.
11436
11437 {time} is the waiting time in milliseconds. This is the
11438 minimum time before invoking the callback. When the system is
11439 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011440 Zero can be used to execute the callback when Vim is back in
11441 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011442
11443 {callback} is the function to call. It can be the name of a
11444 function or a |Funcref|. It is called with one argument, which
11445 is the timer ID. The callback is only invoked when Vim is
11446 waiting for input.
11447 If you want to show a message look at |popup_notification()|
11448 to avoid interfering with what the user is doing.
11449
11450 {options} is a dictionary. Supported entries:
11451 "repeat" Number of times to repeat calling the
11452 callback. -1 means forever. When not present
11453 the callback will be called once.
11454 If the timer causes an error three times in a
11455 row the repeat is cancelled. This avoids that
11456 Vim becomes unusable because of all the error
11457 messages.
11458
Bram Moolenaard592deb2022-06-17 15:42:40 +010011459 Returns -1 on error.
11460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011461 Example: >
11462 func MyHandler(timer)
11463 echo 'Handler called'
11464 endfunc
11465 let timer = timer_start(500, 'MyHandler',
11466 \ {'repeat': 3})
11467< This will invoke MyHandler() three times at 500 msec
11468 intervals.
11469
11470 Can also be used as a |method|: >
11471 GetMsec()->timer_start(callback)
11472
11473< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011474
11475 Return type: |Number|
11476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011477 {only available when compiled with the |+timers| feature}
11478
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011480timer_stop({timer}) *timer_stop()*
11481 Stop a timer. The timer callback will no longer be invoked.
11482 {timer} is an ID returned by timer_start(), thus it must be a
11483 Number. If {timer} does not exist there is no error.
11484
11485 Can also be used as a |method|: >
11486 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011487<
11488 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011489
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011490 {only available when compiled with the |+timers| feature}
11491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011492
11493timer_stopall() *timer_stopall()*
11494 Stop all timers. The timer callbacks will no longer be
11495 invoked. Useful if a timer is misbehaving. If there are no
11496 timers there is no error.
11497
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011498 Return type: |Number|
11499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011500 {only available when compiled with the |+timers| feature}
11501
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011502
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011503tolower({expr}) *tolower()*
11504 The result is a copy of the String given, with all uppercase
11505 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011506 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011507
11508 Can also be used as a |method|: >
11509 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011510<
11511 Return type: |String|
11512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011513
11514toupper({expr}) *toupper()*
11515 The result is a copy of the String given, with all lowercase
11516 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011517 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011518
11519 Can also be used as a |method|: >
11520 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011521<
11522 Return type: |String|
11523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011524
11525tr({src}, {fromstr}, {tostr}) *tr()*
11526 The result is a copy of the {src} string with all characters
11527 which appear in {fromstr} replaced by the character in that
11528 position in the {tostr} string. Thus the first character in
11529 {fromstr} is translated into the first character in {tostr}
11530 and so on. Exactly like the unix "tr" command.
11531 This code also deals with multibyte characters properly.
11532
Bram Moolenaard592deb2022-06-17 15:42:40 +010011533 Returns an empty string on error.
11534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011535 Examples: >
11536 echo tr("hello there", "ht", "HT")
11537< returns "Hello THere" >
11538 echo tr("<blob>", "<>", "{}")
11539< returns "{blob}"
11540
11541 Can also be used as a |method|: >
11542 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011543<
11544 Return type: |String|
11545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011546
11547trim({text} [, {mask} [, {dir}]]) *trim()*
11548 Return {text} as a String where any character in {mask} is
11549 removed from the beginning and/or end of {text}.
11550
Illia Bobyr80799172023-10-17 18:00:50 +020011551 If {mask} is not given, or is an empty string, {mask} is all
11552 characters up to 0x20, which includes Tab, space, NL and CR,
11553 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011554
11555 The optional {dir} argument specifies where to remove the
11556 characters:
11557 0 remove from the beginning and end of {text}
11558 1 remove only at the beginning of {text}
11559 2 remove only at the end of {text}
11560 When omitted both ends are trimmed.
11561
11562 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011563 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011564
11565 Examples: >
11566 echo trim(" some text ")
11567< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011568 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011569< returns "RESERVE_TAIL" >
11570 echo trim("rm<Xrm<>X>rrm", "rm<>")
11571< returns "Xrm<>X" (characters in the middle are not removed) >
11572 echo trim(" vim ", " ", 2)
11573< returns " vim"
11574
11575 Can also be used as a |method|: >
11576 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011577<
11578 Return type: |String|
11579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011580
11581trunc({expr}) *trunc()*
11582 Return the largest integral value with magnitude less than or
11583 equal to {expr} as a |Float| (truncate towards zero).
11584 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011585 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011586 Examples: >
11587 echo trunc(1.456)
11588< 1.0 >
11589 echo trunc(-5.456)
11590< -5.0 >
11591 echo trunc(4.0)
11592< 4.0
11593
11594 Can also be used as a |method|: >
11595 Compute()->trunc()
11596<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011597 Return type: |Float|
11598
11599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011600 *type()*
11601type({expr}) The result is a Number representing the type of {expr}.
11602 Instead of using the number directly, it is better to use the
11603 v:t_ variable that has the value:
11604 Number: 0 |v:t_number|
11605 String: 1 |v:t_string|
11606 Funcref: 2 |v:t_func|
11607 List: 3 |v:t_list|
11608 Dictionary: 4 |v:t_dict|
11609 Float: 5 |v:t_float|
11610 Boolean: 6 |v:t_bool| (v:false and v:true)
11611 None: 7 |v:t_none| (v:null and v:none)
11612 Job: 8 |v:t_job|
11613 Channel: 9 |v:t_channel|
11614 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011615 Class: 12 |v:t_class|
11616 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011617 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011618 Enum: 15 |v:t_enum|
11619 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011620 For backward compatibility, this method can be used: >
11621 :if type(myvar) == type(0)
11622 :if type(myvar) == type("")
11623 :if type(myvar) == type(function("tr"))
11624 :if type(myvar) == type([])
11625 :if type(myvar) == type({})
11626 :if type(myvar) == type(0.0)
11627 :if type(myvar) == type(v:false)
11628 :if type(myvar) == type(v:none)
11629< To check if the v:t_ variables exist use this: >
11630 :if exists('v:t_number')
11631
11632< Can also be used as a |method|: >
11633 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011634<
11635 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011636
11637
11638typename({expr}) *typename()*
11639 Return a string representation of the type of {expr}.
11640 Example: >
11641 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011642< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011643
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011644 Return type: |String|
11645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011646
11647undofile({name}) *undofile()*
11648 Return the name of the undo file that would be used for a file
11649 with name {name} when writing. This uses the 'undodir'
11650 option, finding directories that exist. It does not check if
11651 the undo file exists.
11652 {name} is always expanded to the full path, since that is what
11653 is used internally.
11654 If {name} is empty undofile() returns an empty string, since a
11655 buffer without a file name will not write an undo file.
11656 Useful in combination with |:wundo| and |:rundo|.
11657 When compiled without the |+persistent_undo| option this always
11658 returns an empty string.
11659
11660 Can also be used as a |method|: >
11661 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011662<
11663 Return type: |String|
11664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011665
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011666undotree([{buf}]) *undotree()*
11667 Return the current state of the undo tree for the current
11668 buffer, or for a specific buffer if {buf} is given. The
11669 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011670 "seq_last" The highest undo sequence number used.
11671 "seq_cur" The sequence number of the current position in
11672 the undo tree. This differs from "seq_last"
11673 when some changes were undone.
11674 "time_cur" Time last used for |:earlier| and related
11675 commands. Use |strftime()| to convert to
11676 something readable.
11677 "save_last" Number of the last file write. Zero when no
11678 write yet.
11679 "save_cur" Number of the current position in the undo
11680 tree.
11681 "synced" Non-zero when the last undo block was synced.
11682 This happens when waiting from input from the
11683 user. See |undo-blocks|.
11684 "entries" A list of dictionaries with information about
11685 undo blocks.
11686
11687 The first item in the "entries" list is the oldest undo item.
11688 Each List item is a |Dictionary| with these items:
11689 "seq" Undo sequence number. Same as what appears in
11690 |:undolist|.
11691 "time" Timestamp when the change happened. Use
11692 |strftime()| to convert to something readable.
11693 "newhead" Only appears in the item that is the last one
11694 that was added. This marks the last change
11695 and where further changes will be added.
11696 "curhead" Only appears in the item that is the last one
11697 that was undone. This marks the current
11698 position in the undo tree, the block that will
11699 be used by a redo command. When nothing was
11700 undone after the last change this item will
11701 not appear anywhere.
11702 "save" Only appears on the last block before a file
11703 write. The number is the write count. The
11704 first write has number 1, the last one the
11705 "save_last" mentioned above.
11706 "alt" Alternate entry. This is again a List of undo
11707 blocks. Each item may again have an "alt"
11708 item.
11709
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011710 Return type: dict<any>
11711
11712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011713uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11714 Remove second and succeeding copies of repeated adjacent
11715 {list} items in-place. Returns {list}. If you want a list
11716 to remain unmodified make a copy first: >
11717 :let newlist = uniq(copy(mylist))
11718< The default compare function uses the string representation of
11719 each item. For the use of {func} and {dict} see |sort()|.
11720
Bram Moolenaard592deb2022-06-17 15:42:40 +010011721 Returns zero if {list} is not a |List|.
11722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011723 Can also be used as a |method|: >
11724 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011725<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011726 Return type: list<{type}>
11727
11728
Christian Brabandt67672ef2023-04-24 21:09:54 +010011729 *utf16idx()*
11730utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011731 Same as |charidx()| but returns the UTF-16 code unit index of
11732 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011733
11734 When {charidx} is present and TRUE, {idx} is used as the
11735 character index in the String {string} instead of as the byte
11736 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011737 An {idx} in the middle of a UTF-8 sequence is rounded
11738 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011739
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011740 Returns -1 if the arguments are invalid or if there are less
11741 than {idx} bytes in {string}. If there are exactly {idx} bytes
11742 the length of the string in UTF-16 code units is returned.
11743
Christian Brabandt67672ef2023-04-24 21:09:54 +010011744 See |byteidx()| and |byteidxcomp()| for getting the byte index
11745 from the UTF-16 index and |charidx()| for getting the
11746 character index from the UTF-16 index.
11747 Refer to |string-offset-encoding| for more information.
11748 Examples: >
11749 echo utf16idx('a😊😊', 3) returns 2
11750 echo utf16idx('a😊😊', 7) returns 4
11751 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11752 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11753 echo utf16idx('aą́c', 6) returns 2
11754 echo utf16idx('aą́c', 6, 1) returns 4
11755 echo utf16idx('a😊😊', 9) returns -1
11756<
11757 Can also be used as a |method|: >
11758 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011759<
11760 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011762
11763values({dict}) *values()*
11764 Return a |List| with all the values of {dict}. The |List| is
11765 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011766 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011767
11768 Can also be used as a |method|: >
11769 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011770<
11771 Return type: list<any>
11772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011773
zeertzjq825cf812023-08-17 22:55:25 +020011774virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011775 The result is a Number, which is the screen column of the file
11776 position given with {expr}. That is, the last screen position
11777 occupied by the character at that position, when the screen
11778 would be of unlimited width. When there is a <Tab> at the
11779 position, the returned Number will be the column at the end of
11780 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11781 set to 8, it returns 8. |conceal| is ignored.
11782 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011783
zeertzjq02f3eba2024-06-12 20:45:24 +020011784 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011785 When {expr} is "$", it means the end of the cursor line, so
11786 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011787
11788 When 'virtualedit' is used {expr} can be [lnum, col, off],
11789 where "off" is the offset in screen columns from the start of
11790 the character. E.g., a position within a <Tab> or after the
11791 last character. When "off" is omitted zero is used. When
11792 Virtual editing is active in the current mode, a position
11793 beyond the end of the line can be returned. Also see
11794 |'virtualedit'|
11795
zeertzjq825cf812023-08-17 22:55:25 +020011796 If {list} is present and non-zero then virtcol() returns a
11797 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011798 character.
11799
zeertzjq825cf812023-08-17 22:55:25 +020011800 With the optional {winid} argument the values are obtained for
11801 that window instead of the current window.
11802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011803 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011805 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011806 " With text "foo^Lbar" and cursor on the "^L":
11807
11808 virtcol(".") " returns 5
11809 virtcol(".", 1) " returns [4, 5]
11810 virtcol("$") " returns 9
11811
11812 " With text " there", with 't at 'h':
11813
11814 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011815<
11816 The first column is 1. 0 or [0, 0] is returned for an error.
11817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011818 A more advanced example that echoes the maximum length of
11819 all lines: >
11820 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11821
11822< Can also be used as a |method|: >
11823 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011824<
11825 Return type: |Number|
11826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011827
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011828virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11829 The result is a Number, which is the byte index of the
11830 character in window {winid} at buffer line {lnum} and virtual
11831 column {col}.
11832
zeertzjqb583eda2023-10-14 11:32:28 +020011833 If buffer line {lnum} is an empty line, 0 is returned.
11834
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011835 If {col} is greater than the last virtual column in line
11836 {lnum}, then the byte index of the character at the last
11837 virtual column is returned.
11838
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011839 For a multi-byte character, the column number of the first
11840 byte in the character is returned.
11841
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011842 The {winid} argument can be the window number or the
11843 |window-ID|. If this is zero, then the current window is used.
11844
11845 Returns -1 if the window {winid} doesn't exist or the buffer
11846 line {lnum} or virtual column {col} is invalid.
11847
11848 See also |screenpos()|, |virtcol()| and |col()|.
11849
11850 Can also be used as a |method|: >
11851 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011852<
11853 Return type: |Number|
11854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011855
11856visualmode([{expr}]) *visualmode()*
11857 The result is a String, which describes the last Visual mode
11858 used in the current buffer. Initially it returns an empty
11859 string, but once Visual mode has been used, it returns "v",
11860 "V", or "<CTRL-V>" (a single CTRL-V character) for
11861 character-wise, line-wise, or block-wise Visual mode
11862 respectively.
11863 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011864 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011865< This enters the same Visual mode as before. It is also useful
11866 in scripts if you wish to act differently depending on the
11867 Visual mode that was used.
11868 If Visual mode is active, use |mode()| to get the Visual mode
11869 (e.g., in a |:vmap|).
11870 If {expr} is supplied and it evaluates to a non-zero Number or
11871 a non-empty String, then the Visual mode will be cleared and
11872 the old value is returned. See |non-zero-arg|.
11873
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011874 Return type: |String|
11875
11876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011877wildmenumode() *wildmenumode()*
11878 Returns |TRUE| when the wildmenu is active and |FALSE|
11879 otherwise. See 'wildmenu' and 'wildmode'.
11880 This can be used in mappings to handle the 'wildcharm' option
11881 gracefully. (Makes only sense with |mapmode-c| mappings).
11882
11883 For example to make <c-j> work like <down> in wildmode, use: >
11884 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11885<
11886 (Note, this needs the 'wildcharm' option set appropriately).
11887
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011888 Return type: |Number|
11889
11890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011891win_execute({id}, {command} [, {silent}]) *win_execute()*
11892 Like `execute()` but in the context of window {id}.
11893 The window will temporarily be made the current window,
11894 without triggering autocommands or changing directory. When
11895 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011896 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011897 Example: >
11898 call win_execute(winid, 'set syntax=python')
11899< Doing the same with `setwinvar()` would not trigger
11900 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011901 *E994*
11902 Not all commands are allowed in popup windows.
11903 When window {id} does not exist then no error is given and
11904 an empty string is returned.
11905
11906 Can also be used as a |method|, the base is passed as the
11907 second argument: >
11908 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011909<
11910 Return type: |String|
11911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011912
11913win_findbuf({bufnr}) *win_findbuf()*
11914 Returns a |List| with |window-ID|s for windows that contain
11915 buffer {bufnr}. When there is none the list is empty.
11916
11917 Can also be used as a |method|: >
11918 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011919<
11920 Return type: list<number> or list<any>
11921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011922
11923win_getid([{win} [, {tab}]]) *win_getid()*
11924 Get the |window-ID| for the specified window.
11925 When {win} is missing use the current window.
11926 With {win} this is the window number. The top window has
11927 number 1.
11928 Without {tab} use the current tab, otherwise the tab with
11929 number {tab}. The first tab has number one.
11930 Return zero if the window cannot be found.
11931
11932 Can also be used as a |method|: >
11933 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011934<
11935 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011936
11937
11938win_gettype([{nr}]) *win_gettype()*
11939 Return the type of the window:
11940 "autocmd" autocommand window. Temporary window
11941 used to execute autocommands.
11942 "command" command-line window |cmdwin|
11943 (empty) normal window
11944 "loclist" |location-list-window|
11945 "popup" popup window |popup|
11946 "preview" preview window |preview-window|
11947 "quickfix" |quickfix-window|
11948 "unknown" window {nr} not found
11949
11950 When {nr} is omitted return the type of the current window.
11951 When {nr} is given return the type of this window by number or
11952 |window-ID|.
11953
11954 Also see the 'buftype' option. When running a terminal in a
11955 popup window then 'buftype' is "terminal" and win_gettype()
11956 returns "popup".
11957
11958 Can also be used as a |method|: >
11959 GetWinid()->win_gettype()
11960<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011961 Return type: |String|
11962
11963
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011964win_gotoid({expr}) *win_gotoid()*
11965 Go to window with ID {expr}. This may also change the current
11966 tabpage.
11967 Return TRUE if successful, FALSE if the window cannot be found.
11968
11969 Can also be used as a |method|: >
11970 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011971<
11972 Return type: |Number|
11973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011974
11975win_id2tabwin({expr}) *win_id2tabwin()*
11976 Return a list with the tab number and window number of window
11977 with ID {expr}: [tabnr, winnr].
11978 Return [0, 0] if the window cannot be found.
11979
11980 Can also be used as a |method|: >
11981 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011982<
11983 Return type: list<number>
11984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011985
11986win_id2win({expr}) *win_id2win()*
11987 Return the window number of window with ID {expr}.
11988 Return 0 if the window cannot be found in the current tabpage.
11989
11990 Can also be used as a |method|: >
11991 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011992<
11993 Return type: |Number|
11994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011995
Daniel Steinbergee630312022-01-10 13:36:34 +000011996win_move_separator({nr}, {offset}) *win_move_separator()*
11997 Move window {nr}'s vertical separator (i.e., the right border)
11998 by {offset} columns, as if being dragged by the mouse. {nr}
11999 can be a window number or |window-ID|. A positive {offset}
12000 moves right and a negative {offset} moves left. Moving a
12001 window's vertical separator will change the width of the
12002 window and the width of other windows adjacent to the vertical
12003 separator. The magnitude of movement may be smaller than
12004 specified (e.g., as a consequence of maintaining
12005 'winminwidth'). Returns TRUE if the window can be found and
12006 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012007 This will fail for the rightmost window and a full-width
12008 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012009 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012010
12011 Can also be used as a |method|: >
12012 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012013<
12014 Return type: |Number|
12015
Daniel Steinbergee630312022-01-10 13:36:34 +000012016
12017win_move_statusline({nr}, {offset}) *win_move_statusline()*
12018 Move window {nr}'s status line (i.e., the bottom border) by
12019 {offset} rows, as if being dragged by the mouse. {nr} can be a
12020 window number or |window-ID|. A positive {offset} moves down
12021 and a negative {offset} moves up. Moving a window's status
12022 line will change the height of the window and the height of
12023 other windows adjacent to the status line. The magnitude of
12024 movement may be smaller than specified (e.g., as a consequence
12025 of maintaining 'winminheight'). Returns TRUE if the window can
12026 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012027 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012028
12029 Can also be used as a |method|: >
12030 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012031<
12032 Return type: |Number|
12033
Daniel Steinbergee630312022-01-10 13:36:34 +000012034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012035win_screenpos({nr}) *win_screenpos()*
12036 Return the screen position of window {nr} as a list with two
12037 numbers: [row, col]. The first window always has position
12038 [1, 1], unless there is a tabline, then it is [2, 1].
12039 {nr} can be the window number or the |window-ID|. Use zero
12040 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012041 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012042
12043 Can also be used as a |method|: >
12044 GetWinid()->win_screenpos()
12045<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012046 Return type: list<number>
12047
12048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012049win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012050 Temporarily switch to window {target}, then move window {nr}
12051 to a new split adjacent to {target}.
12052 Unlike commands such as |:split|, no new windows are created
12053 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012054
12055 Both {nr} and {target} can be window numbers or |window-ID|s.
12056 Both must be in the current tab page.
12057
12058 Returns zero for success, non-zero for failure.
12059
12060 {options} is a |Dictionary| with the following optional entries:
12061 "vertical" When TRUE, the split is created vertically,
12062 like with |:vsplit|.
12063 "rightbelow" When TRUE, the split is made below or to the
12064 right (if vertical). When FALSE, it is done
12065 above or to the left (if vertical). When not
12066 present, the values of 'splitbelow' and
12067 'splitright' are used.
12068
12069 Can also be used as a |method|: >
12070 GetWinid()->win_splitmove(target)
12071<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012072 Return type: |Number|
12073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012074
12075 *winbufnr()*
12076winbufnr({nr}) The result is a Number, which is the number of the buffer
12077 associated with window {nr}. {nr} can be the window number or
12078 the |window-ID|.
12079 When {nr} is zero, the number of the buffer in the current
12080 window is returned.
12081 When window {nr} doesn't exist, -1 is returned.
12082 Example: >
12083 :echo "The file in the current window is " . bufname(winbufnr(0))
12084<
12085 Can also be used as a |method|: >
12086 FindWindow()->winbufnr()->bufname()
12087<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012088 Return type: |Number|
12089
12090
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012091 *wincol()*
12092wincol() The result is a Number, which is the virtual column of the
12093 cursor in the window. This is counting screen cells from the
12094 left side of the window. The leftmost column is one.
12095
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012096 Return type: |Number|
12097
12098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012099 *windowsversion()*
12100windowsversion()
12101 The result is a String. For MS-Windows it indicates the OS
12102 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12103 Windows XP is "5.1". For non-MS-Windows systems the result is
12104 an empty string.
12105
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012106 Return type: |String|
12107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012108winheight({nr}) *winheight()*
12109 The result is a Number, which is the height of window {nr}.
12110 {nr} can be the window number or the |window-ID|.
12111 When {nr} is zero, the height of the current window is
12112 returned. When window {nr} doesn't exist, -1 is returned.
12113 An existing window always has a height of zero or more.
12114 This excludes any window toolbar line.
12115 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012116 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012117
12118< Can also be used as a |method|: >
12119 GetWinid()->winheight()
12120<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012121 Return type: |Number|
12122
12123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012124winlayout([{tabnr}]) *winlayout()*
12125 The result is a nested List containing the layout of windows
12126 in a tabpage.
12127
12128 Without {tabnr} use the current tabpage, otherwise the tabpage
12129 with number {tabnr}. If the tabpage {tabnr} is not found,
12130 returns an empty list.
12131
12132 For a leaf window, it returns:
12133 ['leaf', {winid}]
12134 For horizontally split windows, which form a column, it
12135 returns:
12136 ['col', [{nested list of windows}]]
12137 For vertically split windows, which form a row, it returns:
12138 ['row', [{nested list of windows}]]
12139
12140 Example: >
12141 " Only one window in the tab page
12142 :echo winlayout()
12143 ['leaf', 1000]
12144 " Two horizontally split windows
12145 :echo winlayout()
12146 ['col', [['leaf', 1000], ['leaf', 1001]]]
12147 " The second tab page, with three horizontally split
12148 " windows, with two vertically split windows in the
12149 " middle window
12150 :echo winlayout(2)
12151 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12152 ['leaf', 1001]]], ['leaf', 1000]]]
12153<
12154 Can also be used as a |method|: >
12155 GetTabnr()->winlayout()
12156<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012157 Return type: list<any>
12158
12159
12160winline() *winline()*
12161 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012162 in the window. This is counting screen lines from the top of
12163 the window. The first line is one.
12164 If the cursor was moved the view on the file will be updated
12165 first, this may cause a scroll.
12166
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012167 Return type: |Number|
12168
12169
12170winnr([{arg}]) *winnr()*
12171 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012172 window. The top window has number 1.
12173 Returns zero for a popup window.
12174
12175 The optional argument {arg} supports the following values:
12176 $ the number of the last window (the window
12177 count).
12178 # the number of the last accessed window (where
12179 |CTRL-W_p| goes to). If there is no previous
12180 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012181 returned. May refer to the current window in
12182 some cases (e.g. when evaluating 'statusline'
12183 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012184 {N}j the number of the Nth window below the
12185 current window (where |CTRL-W_j| goes to).
12186 {N}k the number of the Nth window above the current
12187 window (where |CTRL-W_k| goes to).
12188 {N}h the number of the Nth window left of the
12189 current window (where |CTRL-W_h| goes to).
12190 {N}l the number of the Nth window right of the
12191 current window (where |CTRL-W_l| goes to).
12192 The number can be used with |CTRL-W_w| and ":wincmd w"
12193 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012194 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012195 Also see |tabpagewinnr()| and |win_getid()|.
12196 Examples: >
12197 let window_count = winnr('$')
12198 let prev_window = winnr('#')
12199 let wnum = winnr('3k')
12200
12201< Can also be used as a |method|: >
12202 GetWinval()->winnr()
12203<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012204 Return type: |Number|
12205
12206
12207winrestcmd() *winrestcmd()*
12208 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012209 the current window sizes. Only works properly when no windows
12210 are opened or closed and the current window and tab page is
12211 unchanged.
12212 Example: >
12213 :let cmd = winrestcmd()
12214 :call MessWithWindowSizes()
12215 :exe cmd
12216<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012217 Return type: |String|
12218
12219
12220winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012221 Uses the |Dictionary| returned by |winsaveview()| to restore
12222 the view of the current window.
12223 Note: The {dict} does not have to contain all values, that are
12224 returned by |winsaveview()|. If values are missing, those
12225 settings won't be restored. So you can use: >
12226 :call winrestview({'curswant': 4})
12227<
12228 This will only set the curswant value (the column the cursor
12229 wants to move on vertical movements) of the cursor to column 5
12230 (yes, that is 5), while all other settings will remain the
12231 same. This is useful, if you set the cursor position manually.
12232
12233 If you have changed the values the result is unpredictable.
12234 If the window size changed the result won't be the same.
12235
12236 Can also be used as a |method|: >
12237 GetView()->winrestview()
12238<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012239 Return type: |Number|
12240
12241
12242winsaveview() *winsaveview()*
12243 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012244 the view of the current window. Use |winrestview()| to
12245 restore the view.
12246 This is useful if you have a mapping that jumps around in the
12247 buffer and you want to go back to the original view.
12248 This does not save fold information. Use the 'foldenable'
12249 option to temporarily switch off folding, so that folds are
12250 not opened when moving around. This may have side effects.
12251 The return value includes:
12252 lnum cursor line number
12253 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012254 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012255 returns)
12256 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012257 curswant column for vertical movement (Note:
12258 the first column is zero, as opposed
12259 to what |getcurpos()| returns). After
12260 |$| command it will be a very large
12261 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012262 topline first line in the window
12263 topfill filler lines, only in diff mode
12264 leftcol first column displayed; only used when
12265 'wrap' is off
12266 skipcol columns skipped
12267 Note that no option values are saved.
12268
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012269 Return type: dict<number>
12270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012271
12272winwidth({nr}) *winwidth()*
12273 The result is a Number, which is the width of window {nr}.
12274 {nr} can be the window number or the |window-ID|.
12275 When {nr} is zero, the width of the current window is
12276 returned. When window {nr} doesn't exist, -1 is returned.
12277 An existing window always has a width of zero or more.
12278 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012279 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012280 :if winwidth(0) <= 50
12281 : 50 wincmd |
12282 :endif
12283< For getting the terminal or screen size, see the 'columns'
12284 option.
12285
12286 Can also be used as a |method|: >
12287 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012288<
12289 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012290
12291
12292wordcount() *wordcount()*
12293 The result is a dictionary of byte/chars/word statistics for
12294 the current buffer. This is the same info as provided by
12295 |g_CTRL-G|
12296 The return value includes:
12297 bytes Number of bytes in the buffer
12298 chars Number of chars in the buffer
12299 words Number of words in the buffer
12300 cursor_bytes Number of bytes before cursor position
12301 (not in Visual mode)
12302 cursor_chars Number of chars before cursor position
12303 (not in Visual mode)
12304 cursor_words Number of words before cursor position
12305 (not in Visual mode)
12306 visual_bytes Number of bytes visually selected
12307 (only in Visual mode)
12308 visual_chars Number of chars visually selected
12309 (only in Visual mode)
12310 visual_words Number of words visually selected
12311 (only in Visual mode)
12312
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012313 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012314
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012315
12316writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012317 When {object} is a |List| write it to file {fname}. Each list
12318 item is separated with a NL. Each list item must be a String
12319 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012320 All NL characters are replaced with a NUL character.
12321 Inserting CR characters needs to be done before passing {list}
12322 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012323
12324 When {object} is a |Blob| write the bytes to file {fname}
12325 unmodified, also when binary mode is not specified.
12326
12327 {flags} must be a String. These characters are recognized:
12328
12329 'b' Binary mode is used: There will not be a NL after the
12330 last list item. An empty item at the end does cause the
12331 last line in the file to end in a NL.
12332
12333 'a' Append mode is used, lines are appended to the file: >
12334 :call writefile(["foo"], "event.log", "a")
12335 :call writefile(["bar"], "event.log", "a")
12336<
12337 'D' Delete the file when the current function ends. This
12338 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012339 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012340< Fails when not in a function. Also see |:defer|.
12341
12342 's' fsync() is called after writing the file. This flushes
12343 the file to disk, if possible. This takes more time but
12344 avoids losing the file if the system crashes.
12345
12346 'S' fsync() is not called, even when 'fsync' is set.
12347
12348 When {flags} does not contain "S" or "s" then fsync() is
12349 called if the 'fsync' option is set.
12350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012351 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012353 When the write fails -1 is returned, otherwise 0. There is an
12354 error message if the file can't be created or when writing
12355 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012357 Also see |readfile()|.
12358 To copy a file byte for byte: >
12359 :let fl = readfile("foo", "b")
12360 :call writefile(fl, "foocopy", "b")
12361
12362< Can also be used as a |method|: >
12363 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012364<
12365 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012366
12367
12368xor({expr}, {expr}) *xor()*
12369 Bitwise XOR on the two arguments. The arguments are converted
12370 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012371 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012372 Example: >
12373 :let bits = xor(bits, 0x80)
12374<
12375 Can also be used as a |method|: >
12376 :let bits = bits->xor(0x80)
12377<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012378 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012379
12380==============================================================================
123813. Feature list *feature-list*
12382
12383There are three types of features:
123841. Features that are only supported when they have been enabled when Vim
12385 was compiled |+feature-list|. Example: >
12386 :if has("cindent")
12387< *gui_running*
123882. Features that are only supported when certain conditions have been met.
12389 Example: >
12390 :if has("gui_running")
12391< *has-patch*
123923. Beyond a certain version or at a certain version and including a specific
12393 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12394 later, or it is version 7.4 and patch 248 was included. Example: >
12395 :if has("patch-7.4.248")
12396< Note that it's possible for patch 248 to be omitted even though 249 is
12397 included. Only happens when cherry-picking patches.
12398 Note that this form only works for patch 7.4.237 and later, before that
12399 you need to check for the patch and the v:version. Example (checking
12400 version 6.2.148 or later): >
12401 :if v:version > 602 || (v:version == 602 && has("patch148"))
12402
12403Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12404use: `if exists('+shellslash')`
12405
12406
12407acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012408all_builtin_terms Compiled with all builtin terminals enabled. (always
12409 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012410amiga Amiga version of Vim.
12411arabic Compiled with Arabic support |Arabic|.
12412arp Compiled with ARP support (Amiga).
12413autocmd Compiled with autocommand support. (always true)
12414autochdir Compiled with support for 'autochdir'
12415autoservername Automatically enable |clientserver|
12416balloon_eval Compiled with |balloon-eval| support.
12417balloon_multiline GUI supports multiline balloons.
12418beos BeOS version of Vim.
12419browse Compiled with |:browse| support, and browse() will
12420 work.
12421browsefilter Compiled with support for |browsefilter|.
12422bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012423builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012424byte_offset Compiled with support for 'o' in 'statusline'
12425channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012426cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012427clientserver Compiled with remote invocation support |clientserver|.
12428clipboard Compiled with 'clipboard' support.
12429clipboard_working Compiled with 'clipboard' support and it can be used.
12430cmdline_compl Compiled with |cmdline-completion| support.
12431cmdline_hist Compiled with |cmdline-history| support.
12432cmdline_info Compiled with 'showcmd' and 'ruler' support.
12433comments Compiled with |'comments'| support.
12434compatible Compiled to be very Vi compatible.
12435conpty Platform where |ConPTY| can be used.
12436cryptv Compiled with encryption support |encryption|.
12437cscope Compiled with |cscope| support.
12438cursorbind Compiled with |'cursorbind'| (always true)
12439debug Compiled with "DEBUG" defined.
12440dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012441dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012442dialog_gui Compiled with GUI dialog support.
12443diff Compiled with |vimdiff| and 'diff' support.
12444digraphs Compiled with support for digraphs.
12445directx Compiled with support for DirectX and 'renderoptions'.
12446dnd Compiled with support for the "~ register |quote_~|.
12447drop_file Compiled with |drop_file| support.
12448ebcdic Compiled on a machine with ebcdic character set.
12449emacs_tags Compiled with support for Emacs tags.
12450eval Compiled with expression evaluation support. Always
12451 true, of course!
12452ex_extra |+ex_extra| (always true)
12453extra_search Compiled with support for |'incsearch'| and
12454 |'hlsearch'|
12455farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012456file_in_path Compiled with support for |gf| and |<cfile>| (always
12457 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012458filterpipe When 'shelltemp' is off pipes are used for shell
12459 read/write/filter commands
12460find_in_path Compiled with support for include file searches
12461 |+find_in_path|.
12462float Compiled with support for |Float|.
12463fname_case Case in file names matters (for Amiga and MS-Windows
12464 this is not present).
12465folding Compiled with |folding| support.
12466footer Compiled with GUI footer support. |gui-footer|
12467fork Compiled to use fork()/exec() instead of system().
12468gettext Compiled with message translation |multi-lang|
12469gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012470gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012471gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12472gui_gtk Compiled with GTK+ GUI (any version).
12473gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12474gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12475gui_haiku Compiled with Haiku GUI.
12476gui_mac Compiled with Macintosh GUI.
12477gui_motif Compiled with Motif GUI.
12478gui_photon Compiled with Photon GUI.
12479gui_running Vim is running in the GUI, or it will start soon.
12480gui_win32 Compiled with MS-Windows Win32 GUI.
12481gui_win32s idem, and Win32s system being used (Windows 3.1)
12482haiku Haiku version of Vim.
12483hangul_input Compiled with Hangul input support. |hangul|
12484hpux HP-UX version of Vim.
12485iconv Can use iconv() for conversion.
12486insert_expand Compiled with support for CTRL-X expansion commands in
12487 Insert mode. (always true)
12488job Compiled with support for |channel| and |job|
12489ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012490jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012491keymap Compiled with 'keymap' support.
12492lambda Compiled with |lambda| support.
12493langmap Compiled with 'langmap' support.
12494libcall Compiled with |libcall()| support.
12495linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12496 'breakindent' support.
12497linux Linux version of Vim.
12498lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012499 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012500listcmds Compiled with commands for the buffer list |:files|
12501 and the argument list |arglist|.
12502localmap Compiled with local mappings and abbr. |:map-local|
12503lua Compiled with Lua interface |Lua|.
12504mac Any Macintosh version of Vim cf. osx
12505macunix Synonym for osxdarwin
12506menu Compiled with support for |:menu|.
12507mksession Compiled with support for |:mksession|.
12508modify_fname Compiled with file name modifiers. |filename-modifiers|
12509 (always true)
12510mouse Compiled with support for mouse.
12511mouse_dec Compiled with support for Dec terminal mouse.
12512mouse_gpm Compiled with support for gpm (Linux console mouse)
12513mouse_gpm_enabled GPM mouse is working
12514mouse_netterm Compiled with support for netterm mouse.
12515mouse_pterm Compiled with support for qnx pterm mouse.
12516mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12517mouse_sgr Compiled with support for sgr mouse.
12518mouse_urxvt Compiled with support for urxvt mouse.
12519mouse_xterm Compiled with support for xterm mouse.
12520mouseshape Compiled with support for 'mouseshape'.
12521multi_byte Compiled with support for 'encoding' (always true)
12522multi_byte_encoding 'encoding' is set to a multibyte encoding.
12523multi_byte_ime Compiled with support for IME input method.
12524multi_lang Compiled with support for multiple languages.
12525mzscheme Compiled with MzScheme interface |mzscheme|.
12526nanotime Compiled with sub-second time stamp checks.
12527netbeans_enabled Compiled with support for |netbeans| and connected.
12528netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012529num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012530ole Compiled with OLE automation support for Win32.
12531osx Compiled for macOS cf. mac
12532osxdarwin Compiled for macOS, with |mac-darwin-feature|
12533packages Compiled with |packages| support.
12534path_extra Compiled with up/downwards search in 'path' and 'tags'
12535perl Compiled with Perl interface.
12536persistent_undo Compiled with support for persistent undo history.
12537postscript Compiled with PostScript file printing.
12538printer Compiled with |:hardcopy| support.
12539profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012540prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012541python Python 2.x interface available. |has-python|
12542python_compiled Compiled with Python 2.x interface. |has-python|
12543python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12544python3 Python 3.x interface available. |has-python|
12545python3_compiled Compiled with Python 3.x interface. |has-python|
12546python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012547python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012548pythonx Python 2.x and/or 3.x interface available. |python_x|
12549qnx QNX version of Vim.
12550quickfix Compiled with |quickfix| support.
12551reltime Compiled with |reltime()| support.
12552rightleft Compiled with 'rightleft' support.
12553ruby Compiled with Ruby interface |ruby|.
12554scrollbind Compiled with 'scrollbind' support. (always true)
12555showcmd Compiled with 'showcmd' support.
12556signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012557smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012558sodium Compiled with libsodium for better crypt support
12559sound Compiled with sound support, e.g. `sound_playevent()`
12560spell Compiled with spell checking support |spell|.
12561startuptime Compiled with |--startuptime| support.
12562statusline Compiled with support for 'statusline', 'rulerformat'
12563 and special formats of 'titlestring' and 'iconstring'.
12564sun SunOS version of Vim.
12565sun_workshop Support for Sun |workshop| has been removed.
12566syntax Compiled with syntax highlighting support |syntax|.
12567syntax_items There are active syntax highlighting items for the
12568 current buffer.
12569system Compiled to use system() instead of fork()/exec().
12570tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012571 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012572tag_old_static Support for old static tags was removed, see
12573 |tag-old-static|.
12574tcl Compiled with Tcl interface.
12575termguicolors Compiled with true color in terminal support.
12576terminal Compiled with |terminal| support.
12577terminfo Compiled with terminfo instead of termcap.
12578termresponse Compiled with support for |t_RV| and |v:termresponse|.
12579textobjects Compiled with support for |text-objects|.
12580textprop Compiled with support for |text-properties|.
12581tgetent Compiled with tgetent support, able to use a termcap
12582 or terminfo file.
12583timers Compiled with |timer_start()| support.
12584title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012585 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012586toolbar Compiled with support for |gui-toolbar|.
12587ttyin input is a terminal (tty)
12588ttyout output is a terminal (tty)
12589unix Unix version of Vim. *+unix*
12590unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12591user_commands User-defined commands. (always true)
12592vartabs Compiled with variable tabstop support |'vartabstop'|.
12593vcon Win32: Virtual console support is working, can use
12594 'termguicolors'. Also see |+vtp|.
12595vertsplit Compiled with vertically split windows |:vsplit|.
12596 (always true)
12597vim_starting True while initial source'ing takes place. |startup|
12598 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012599vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012600viminfo Compiled with viminfo support.
12601vimscript-1 Compiled Vim script version 1 support
12602vimscript-2 Compiled Vim script version 2 support
12603vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012604vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012605virtualedit Compiled with 'virtualedit' option. (always true)
12606visual Compiled with Visual mode. (always true)
12607visualextra Compiled with extra Visual mode commands. (always
12608 true) |blockwise-operators|.
12609vms VMS version of Vim.
12610vreplace Compiled with |gR| and |gr| commands. (always true)
12611vtp Compiled for vcon support |+vtp| (check vcon to find
12612 out if it works in the current console).
12613wildignore Compiled with 'wildignore' option.
12614wildmenu Compiled with 'wildmenu' option.
12615win16 old version for MS-Windows 3.1 (always false)
12616win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12617 64 bits)
12618win32unix Win32 version of Vim, using Unix files (Cygwin)
12619win64 Win64 version of Vim (MS-Windows 64 bit).
12620win95 Win32 version for MS-Windows 95/98/ME (always false)
12621winaltkeys Compiled with 'winaltkeys' option.
12622windows Compiled with support for more than one window.
12623 (always true)
12624writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012625xattr Compiled with extended attributes support |xattr|
12626 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012627xfontset Compiled with X fontset support |xfontset|.
12628xim Compiled with X input method support |xim|.
12629xpm Compiled with pixmap support.
12630xpm_w32 Compiled with pixmap support for Win32. (Only for
12631 backward compatibility. Use "xpm" instead.)
12632xsmp Compiled with X session management support.
12633xsmp_interact Compiled with interactive X session management support.
12634xterm_clipboard Compiled with support for xterm clipboard.
12635xterm_save Compiled with support for saving and restoring the
12636 xterm screen.
12637x11 Compiled with X11 support.
12638
12639
12640==============================================================================
126414. Matching a pattern in a String *string-match*
12642
12643This is common between several functions. A regexp pattern as explained at
12644|pattern| is normally used to find a match in the buffer lines. When a
12645pattern is used to find a match in a String, almost everything works in the
12646same way. The difference is that a String is handled like it is one line.
12647When it contains a "\n" character, this is not seen as a line break for the
12648pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12649>
12650 :let a = "aaaa\nxxxx"
12651 :echo matchstr(a, "..\n..")
12652 aa
12653 xx
12654 :echo matchstr(a, "a.x")
12655 a
12656 x
12657
12658Don't forget that "^" will only match at the first character of the String and
12659"$" at the last character of the string. They don't match after or before a
12660"\n".
12661
12662 vim:tw=78:ts=8:noet:ft=help:norl: