blob: 15de27db5799107aa314a0d6e293b19f19ed8ec3 [file] [log] [blame]
Christian Brabandt1961caf2024-10-12 11:57:12 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Oct 12
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})
Christ van Willegen8252ef12024-07-11 21:36:21 +020071 Bool bind text domain to specified 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
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200233getcmdcomplpat() String return the completion pattern of the
234 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100235getcmdcompltype() String return the type of the current
236 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200237getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000238getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200239getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100240getcmdscreenpos() Number return cursor screen position in
241 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdtype() String return current command-line type
243getcmdwintype() String return current command-line window type
244getcompletion({pat}, {type} [, {filtered}])
245 List list of cmdline completion matches
246getcurpos([{winnr}]) List position of the cursor
247getcursorcharpos([{winnr}]) List character position of the cursor
248getcwd([{winnr} [, {tabnr}]]) String get the current working directory
249getenv({name}) String return environment variable
250getfontname([{name}]) String name of font being used
251getfperm({fname}) String file permissions of file {fname}
252getfsize({fname}) Number size in bytes of file {fname}
253getftime({fname}) Number last modification time of file
254getftype({fname}) String description of type of file {fname}
255getimstatus() Number |TRUE| if the IME status is active
256getjumplist([{winnr} [, {tabnr}]])
257 List list of jump list items
258getline({lnum}) String line {lnum} of current buffer
259getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
260getloclist({nr}) List list of location list items
261getloclist({nr}, {what}) Dict get specific location list properties
262getmarklist([{buf}]) List list of global/local marks
263getmatches([{win}]) List list of current matches
264getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000265getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000266getpid() Number process ID of Vim
267getpos({expr}) List position of cursor, mark, etc.
268getqflist() List list of quickfix items
269getqflist({what}) Dict get specific quickfix list properties
270getreg([{regname} [, 1 [, {list}]]])
271 String or List contents of a register
272getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100273getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100274 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200275getregionpos({pos1}, {pos2} [, {opts}])
276 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000277getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100278getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000279gettabinfo([{expr}]) List list of tab pages
280gettabvar({nr}, {varname} [, {def}])
281 any variable {varname} in tab {nr} or {def}
282gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
283 any {name} in {winnr} in tab page {tabnr}
284gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200285gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000287getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000288getwinposx() Number X coord in pixels of the Vim window
289getwinposy() Number Y coord in pixels of the Vim window
290getwinvar({nr}, {varname} [, {def}])
291 any variable {varname} in window {nr}
292glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
293 any expand file wildcards in {expr}
294glob2regpat({expr}) String convert a glob pat into a search pat
295globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
296 String do glob({expr}) for all dirs in {path}
297has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
298has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
299haslocaldir([{winnr} [, {tabnr}]])
300 Number |TRUE| if the window executed |:lcd|
301 or |:tcd|
302hasmapto({what} [, {mode} [, {abbr}]])
303 Number |TRUE| if mapping to {what} exists
304histadd({history}, {item}) Number add an item to a history
305histdel({history} [, {item}]) Number remove an item from a history
306histget({history} [, {index}]) String get the item {index} from a history
307histnr({history}) Number highest index of a history
308hlID({name}) Number syntax ID of highlight group {name}
309hlexists({name}) Number |TRUE| if highlight group {name} exists
310hlget([{name} [, {resolve}]]) List get highlight group attributes
311hlset({list}) Number set highlight group attributes
312hostname() String name of the machine Vim is running on
313iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200314id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000315indent({lnum}) Number indent of line {lnum}
316index({object}, {expr} [, {start} [, {ic}]])
317 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100318indexof({object}, {expr} [, {opts}]])
319 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320input({prompt} [, {text} [, {completion}]])
321 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100322inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000323 String like input() but in a GUI dialog
324inputlist({textlist}) Number let the user pick from a choice list
325inputrestore() Number restore typeahead
326inputsave() Number save and clear typeahead
327inputsecret({prompt} [, {text}]) String like input() but hiding the text
328insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200329instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330interrupt() none interrupt script execution
331invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100332isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000333isdirectory({directory}) Number |TRUE| if {directory} is a directory
334isinf({expr}) Number determine if {expr} is infinity value
335 (positive or negative)
336islocked({expr}) Number |TRUE| if {expr} is locked
337isnan({expr}) Number |TRUE| if {expr} is NaN
338items({dict}) List key-value pairs in {dict}
339job_getchannel({job}) Channel get the channel handle for {job}
340job_info([{job}]) Dict get information about {job}
341job_setoptions({job}, {options}) none set options for {job}
342job_start({command} [, {options}])
343 Job start a job
344job_status({job}) String get the status of {job}
345job_stop({job} [, {how}]) Number stop {job}
346join({list} [, {sep}]) String join {list} items into one String
347js_decode({string}) any decode JS style JSON
348js_encode({expr}) String encode JS style JSON
349json_decode({string}) any decode JSON
350json_encode({expr}) String encode JSON
351keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100352keytrans({string}) String translate internal keycodes to a form
353 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000354len({expr}) Number the length of {expr}
355libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
356libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
357line({expr} [, {winid}]) Number line nr of cursor, last line or mark
358line2byte({lnum}) Number byte count of line {lnum}
359lispindent({lnum}) Number Lisp indent for line {lnum}
360list2blob({list}) Blob turn {list} of numbers into a Blob
361list2str({list} [, {utf8}]) String turn {list} of numbers into a String
362listener_add({callback} [, {buf}])
363 Number add a callback to listen to changes
364listener_flush([{buf}]) none invoke listener callbacks
365listener_remove({id}) none remove a listener callback
366localtime() Number current time
367log({expr}) Float natural logarithm (base e) of {expr}
368log10({expr}) Float logarithm of Float {expr} to base 10
369luaeval({expr} [, {expr}]) any evaluate |Lua| expression
370map({expr1}, {expr2}) List/Dict/Blob/String
371 change each item in {expr1} to {expr2}
372maparg({name} [, {mode} [, {abbr} [, {dict}]]])
373 String or Dict
374 rhs of mapping {name} in mode {mode}
375mapcheck({name} [, {mode} [, {abbr}]])
376 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100377maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000378mapnew({expr1}, {expr2}) List/Dict/Blob/String
379 like |map()| but creates a new List or
380 Dictionary
381mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
382match({expr}, {pat} [, {start} [, {count}]])
383 Number position where {pat} matches in {expr}
384matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
385 Number highlight {pattern} with {group}
386matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
387 Number highlight positions with {group}
388matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100389matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
390 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000391matchdelete({id} [, {win}]) Number delete match identified by {id}
392matchend({expr}, {pat} [, {start} [, {count}]])
393 Number position where {pat} ends in {expr}
394matchfuzzy({list}, {str} [, {dict}])
395 List fuzzy match {str} in {list}
396matchfuzzypos({list}, {str} [, {dict}])
397 List fuzzy match {str} in {list}
398matchlist({expr}, {pat} [, {start} [, {count}]])
399 List match and submatches of {pat} in {expr}
400matchstr({expr}, {pat} [, {start} [, {count}]])
401 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100402matchstrlist({list}, {pat} [, {dict})
403 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000404matchstrpos({expr}, {pat} [, {start} [, {count}]])
405 List {count}'th match of {pat} in {expr}
406max({expr}) Number maximum value of items in {expr}
407menu_info({name} [, {mode}]) Dict get menu item information
408min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000409mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000410 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200411mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000412mzeval({expr}) any evaluate |MzScheme| expression
413nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
414nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
415or({expr}, {expr}) Number bitwise OR
416pathshorten({expr} [, {len}]) String shorten directory names in a path
417perleval({expr}) any evaluate |Perl| expression
418popup_atcursor({what}, {options}) Number create popup window near the cursor
419popup_beval({what}, {options}) Number create popup window for 'ballooneval'
420popup_clear() none close all popup windows
421popup_close({id} [, {result}]) none close popup window {id}
422popup_create({what}, {options}) Number create a popup window
423popup_dialog({what}, {options}) Number create a popup window used as a dialog
424popup_filter_menu({id}, {key}) Number filter for a menu popup window
425popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100426popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000427popup_findinfo() Number get window ID of info popup window
428popup_findpreview() Number get window ID of preview popup window
429popup_getoptions({id}) Dict get options of popup window {id}
430popup_getpos({id}) Dict get position of popup window {id}
431popup_hide({id}) none hide popup menu {id}
432popup_list() List get a list of window IDs of all popups
433popup_locate({row}, {col}) Number get window ID of popup at position
434popup_menu({what}, {options}) Number create a popup window used as a menu
435popup_move({id}, {options}) none set position of popup window {id}
436popup_notification({what}, {options})
437 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200438popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000439popup_setoptions({id}, {options})
440 none set options for popup window {id}
441popup_settext({id}, {text}) none set the text of popup window {id}
442popup_show({id}) none unhide popup window {id}
443pow({x}, {y}) Float {x} to the power of {y}
444prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
445printf({fmt}, {expr1}...) String format text
446prompt_getprompt({buf}) String get prompt text
447prompt_setcallback({buf}, {expr}) none set prompt callback function
448prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
449prompt_setprompt({buf}, {text}) none set prompt text
450prop_add({lnum}, {col}, {props}) none add one text property
451prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
452 none add multiple text properties
453prop_clear({lnum} [, {lnum-end} [, {props}]])
454 none remove all text properties
455prop_find({props} [, {direction}])
456 Dict search for a text property
457prop_list({lnum} [, {props}]) List text properties in {lnum}
458prop_remove({props} [, {lnum} [, {lnum-end}]])
459 Number remove a text property
460prop_type_add({name}, {props}) none define a new property type
461prop_type_change({name}, {props})
462 none change an existing property type
463prop_type_delete({name} [, {props}])
464 none delete a property type
465prop_type_get({name} [, {props}])
466 Dict get property type values
467prop_type_list([{props}]) List get list of property types
468pum_getpos() Dict position and size of pum if visible
469pumvisible() Number whether popup menu is visible
470py3eval({expr}) any evaluate |python3| expression
471pyeval({expr}) any evaluate |Python| expression
472pyxeval({expr}) any evaluate |python_x| expression
473rand([{expr}]) Number get pseudo-random number
474range({expr} [, {max} [, {stride}]])
475 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100476readblob({fname} [, {offset} [, {size}]])
477 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000478readdir({dir} [, {expr} [, {dict}]])
479 List file names in {dir} selected by {expr}
480readdirex({dir} [, {expr} [, {dict}]])
481 List file info in {dir} selected by {expr}
482readfile({fname} [, {type} [, {max}]])
483 List get list of lines from file {fname}
484reduce({object}, {func} [, {initial}])
485 any reduce {object} using {func}
486reg_executing() String get the executing register name
487reg_recording() String get the recording register name
488reltime([{start} [, {end}]]) List get time value
489reltimefloat({time}) Float turn the time value into a Float
490reltimestr({time}) String turn time value into a String
491remote_expr({server}, {string} [, {idvar} [, {timeout}]])
492 String send expression
493remote_foreground({server}) Number bring Vim server to the foreground
494remote_peek({serverid} [, {retvar}])
495 Number check for reply string
496remote_read({serverid} [, {timeout}])
497 String read reply string
498remote_send({server}, {string} [, {idvar}])
499 String send key sequence
500remote_startserver({name}) none become server {name}
501remove({list}, {idx} [, {end}]) any/List
502 remove items {idx}-{end} from {list}
503remove({blob}, {idx} [, {end}]) Number/Blob
504 remove bytes {idx}-{end} from {blob}
505remove({dict}, {key}) any remove entry {key} from {dict}
506rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100507repeat({expr}, {count}) List/Blob/String
508 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000509resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100510reverse({obj}) List/Blob/String
511 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000512round({expr}) Float round off {expr}
513rubyeval({expr}) any evaluate |Ruby| expression
514screenattr({row}, {col}) Number attribute at screen position
515screenchar({row}, {col}) Number character at screen position
516screenchars({row}, {col}) List List of characters at screen position
517screencol() Number current cursor column
518screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
519screenrow() Number current cursor row
520screenstring({row}, {col}) String characters at screen position
521search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
522 Number search for {pattern}
523searchcount([{options}]) Dict get or update search stats
524searchdecl({name} [, {global} [, {thisblock}]])
525 Number search for variable declaration
526searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
527 Number search for other end of start/end pair
528searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
529 List search for other end of start/end pair
530searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
531 List search for {pattern}
532server2client({clientid}, {string})
533 Number send reply string
534serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700535setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000536 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700537 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000538setbufvar({buf}, {varname}, {val})
539 none set {varname} in buffer {buf} to {val}
540setcellwidths({list}) none set character cell width overrides
541setcharpos({expr}, {list}) Number set the {expr} position to {list}
542setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100543setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000544setcmdpos({pos}) Number set cursor position in command-line
545setcursorcharpos({list}) Number move cursor to position in {list}
546setenv({name}, {val}) none set environment variable
547setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
548setline({lnum}, {line}) Number set line {lnum} to {line}
549setloclist({nr}, {list} [, {action}])
550 Number modify location list using {list}
551setloclist({nr}, {list}, {action}, {what})
552 Number modify specific location list props
553setmatches({list} [, {win}]) Number restore a list of matches
554setpos({expr}, {list}) Number set the {expr} position to {list}
555setqflist({list} [, {action}]) Number modify quickfix list using {list}
556setqflist({list}, {action}, {what})
557 Number modify specific quickfix list props
558setreg({n}, {v} [, {opt}]) Number set register to value and type
559settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
560settabwinvar({tabnr}, {winnr}, {varname}, {val})
561 none set {varname} in window {winnr} in tab
562 page {tabnr} to {val}
563settagstack({nr}, {dict} [, {action}])
564 Number modify tag stack using {dict}
565setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
566sha256({string}) String SHA256 checksum of {string}
567shellescape({string} [, {special}])
568 String escape {string} for use as shell
569 command argument
570shiftwidth([{col}]) Number effective value of 'shiftwidth'
571sign_define({name} [, {dict}]) Number define or update a sign
572sign_define({list}) List define or update a list of signs
573sign_getdefined([{name}]) List get a list of defined signs
574sign_getplaced([{buf} [, {dict}]])
575 List get a list of placed signs
576sign_jump({id}, {group}, {buf})
577 Number jump to a sign
578sign_place({id}, {group}, {name}, {buf} [, {dict}])
579 Number place a sign
580sign_placelist({list}) List place a list of signs
581sign_undefine([{name}]) Number undefine a sign
582sign_undefine({list}) List undefine a list of signs
583sign_unplace({group} [, {dict}])
584 Number unplace a sign
585sign_unplacelist({list}) List unplace a list of signs
586simplify({filename}) String simplify filename as much as possible
587sin({expr}) Float sine of {expr}
588sinh({expr}) Float hyperbolic sine of {expr}
589slice({expr}, {start} [, {end}]) String, List or Blob
590 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000591sort({list} [, {how} [, {dict}]])
592 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000593sound_clear() none stop playing all sounds
594sound_playevent({name} [, {callback}])
595 Number play an event sound
596sound_playfile({path} [, {callback}])
597 Number play sound file {path}
598sound_stop({id}) none stop playing sound {id}
599soundfold({word}) String sound-fold {word}
600spellbadword() String badly spelled word at cursor
601spellsuggest({word} [, {max} [, {capital}]])
602 List spelling suggestions
603split({expr} [, {pat} [, {keepempty}]])
604 List make |List| from {pat} separated {expr}
605sqrt({expr}) Float square root of {expr}
606srand([{expr}]) List get seed for |rand()|
607state([{what}]) String current state of Vim
608str2float({expr} [, {quoted}]) Float convert String to Float
609str2list({expr} [, {utf8}]) List convert each character of {expr} to
610 ASCII/UTF-8 value
611str2nr({expr} [, {base} [, {quoted}]])
612 Number convert String to Number
613strcharlen({expr}) Number character length of the String {expr}
614strcharpart({str}, {start} [, {len} [, {skipcc}]])
615 String {len} characters of {str} at
616 character {start}
617strchars({expr} [, {skipcc}]) Number character count of the String {expr}
618strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
619strftime({format} [, {time}]) String format time with a specified format
620strgetchar({str}, {index}) Number get char {index} from {str}
621stridx({haystack}, {needle} [, {start}])
622 Number index of {needle} in {haystack}
623string({expr}) String String representation of {expr} value
624strlen({expr}) Number length of the String {expr}
625strpart({str}, {start} [, {len} [, {chars}]])
626 String {len} bytes/chars of {str} at
627 byte {start}
628strptime({format}, {timestring})
629 Number Convert {timestring} to unix timestamp
630strridx({haystack}, {needle} [, {start}])
631 Number last index of {needle} in {haystack}
632strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100633strutf16len({string} [, {countcc}])
634 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000635strwidth({expr}) Number display cell length of the String {expr}
636submatch({nr} [, {list}]) String or List
637 specific match in ":s" or substitute()
638substitute({expr}, {pat}, {sub}, {flags})
639 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000640swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000641swapinfo({fname}) Dict information about swap file {fname}
642swapname({buf}) String swap file of buffer {buf}
643synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
644synIDattr({synID}, {what} [, {mode}])
645 String attribute {what} of syntax ID {synID}
646synIDtrans({synID}) Number translated syntax ID of {synID}
647synconcealed({lnum}, {col}) List info about concealing
648synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
649system({expr} [, {input}]) String output of shell command/filter {expr}
650systemlist({expr} [, {input}]) List output of shell command/filter {expr}
651tabpagebuflist([{arg}]) List list of buffer numbers in tab page
652tabpagenr([{arg}]) Number number of current or last tab page
653tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
654tagfiles() List tags files used
655taglist({expr} [, {filename}]) List list of tags matching {expr}
656tan({expr}) Float tangent of {expr}
657tanh({expr}) Float hyperbolic tangent of {expr}
658tempname() String name for a temporary file
659term_dumpdiff({filename}, {filename} [, {options}])
660 Number display difference between two dumps
661term_dumpload({filename} [, {options}])
662 Number displaying a screen dump
663term_dumpwrite({buf}, {filename} [, {options}])
664 none dump terminal window contents
665term_getaltscreen({buf}) Number get the alternate screen flag
666term_getansicolors({buf}) List get ANSI palette in GUI color mode
667term_getattr({attr}, {what}) Number get the value of attribute {what}
668term_getcursor({buf}) List get the cursor position of a terminal
669term_getjob({buf}) Job get the job associated with a terminal
670term_getline({buf}, {row}) String get a line of text from a terminal
671term_getscrolled({buf}) Number get the scroll count of a terminal
672term_getsize({buf}) List get the size of a terminal
673term_getstatus({buf}) String get the status of a terminal
674term_gettitle({buf}) String get the title of a terminal
675term_gettty({buf}, [{input}]) String get the tty name of a terminal
676term_list() List get the list of terminal buffers
677term_scrape({buf}, {row}) List get row of a terminal screen
678term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
679term_setansicolors({buf}, {colors})
680 none set ANSI palette in GUI color mode
681term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
682term_setkill({buf}, {how}) none set signal to stop job in terminal
683term_setrestore({buf}, {command}) none set command to restore terminal
684term_setsize({buf}, {rows}, {cols})
685 none set the size of a terminal
686term_start({cmd} [, {options}]) Number open a terminal window and run a job
687term_wait({buf} [, {time}]) Number wait for screen to be updated
688terminalprops() Dict properties of the terminal
689test_alloc_fail({id}, {countdown}, {repeat})
690 none make memory allocation fail
691test_autochdir() none enable 'autochdir' during startup
692test_feedinput({string}) none add key sequence to input buffer
693test_garbagecollect_now() none free memory right now for testing
694test_garbagecollect_soon() none free memory soon for testing
695test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000696test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000697test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000698test_mswin_event({event}, {args})
699 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000700test_null_blob() Blob null value for testing
701test_null_channel() Channel null value for testing
702test_null_dict() Dict null value for testing
703test_null_function() Funcref null value for testing
704test_null_job() Job null value for testing
705test_null_list() List null value for testing
706test_null_partial() Funcref null value for testing
707test_null_string() String null value for testing
708test_option_not_set({name}) none reset flag indicating option was set
709test_override({expr}, {val}) none test with Vim internal overrides
710test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_setmouse({row}, {col}) none set the mouse position for testing
712test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200713test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000714test_unknown() any unknown value for testing
715test_void() any void value for testing
716timer_info([{id}]) List information about timers
717timer_pause({id}, {pause}) none pause or unpause a timer
718timer_start({time}, {callback} [, {options}])
719 Number create a timer
720timer_stop({timer}) none stop a timer
721timer_stopall() none stop all timers
722tolower({expr}) String the String {expr} switched to lowercase
723toupper({expr}) String the String {expr} switched to uppercase
724tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
725 to chars in {tostr}
726trim({text} [, {mask} [, {dir}]])
727 String trim characters in {mask} from {text}
728trunc({expr}) Float truncate Float {expr}
729type({expr}) Number type of value {expr}
730typename({expr}) String representation of the type of {expr}
731undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500732undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000733uniq({list} [, {func} [, {dict}]])
734 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100735utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
736 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000737values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200738virtcol({expr} [, {list} [, {winid}])
739 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100740 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100741virtcol2col({winid}, {lnum}, {col})
742 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200743visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000744wildmenumode() Number whether 'wildmenu' mode is active
745win_execute({id}, {command} [, {silent}])
746 String execute {command} in window {id}
747win_findbuf({bufnr}) List find windows containing {bufnr}
748win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
749win_gettype([{nr}]) String type of window {nr}
750win_gotoid({expr}) Number go to window with ID {expr}
751win_id2tabwin({expr}) List get tab and window nr from window ID
752win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000753win_move_separator({nr}) Number move window vertical separator
754win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000755win_screenpos({nr}) List get screen position of window {nr}
756win_splitmove({nr}, {target} [, {options}])
757 Number move window {nr} to split of {target}
758winbufnr({nr}) Number buffer number of window {nr}
759wincol() Number window column of the cursor
760windowsversion() String MS-Windows OS version
761winheight({nr}) Number height of window {nr}
762winlayout([{tabnr}]) List layout of windows in tab {tabnr}
763winline() Number window line of the cursor
764winnr([{expr}]) Number number of current window
765winrestcmd() String returns command to restore window sizes
766winrestview({dict}) none restore view of current window
767winsaveview() Dict save view of current window
768winwidth({nr}) Number width of window {nr}
769wordcount() Dict get byte/char/word statistics
770writefile({object}, {fname} [, {flags}])
771 Number write |Blob| or |List| of lines to file
772xor({expr}, {expr}) Number bitwise XOR
773
774==============================================================================
7752. Details *builtin-function-details*
776
777Not all functions are here, some have been moved to a help file covering the
778specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200779Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000780
781abs({expr}) *abs()*
782 Return the absolute value of {expr}. When {expr} evaluates to
783 a |Float| abs() returns a |Float|. When {expr} can be
784 converted to a |Number| abs() returns a |Number|. Otherwise
785 abs() gives an error message and returns -1.
786 Examples: >
787 echo abs(1.456)
788< 1.456 >
789 echo abs(-5.456)
790< 5.456 >
791 echo abs(-4)
792< 4
793
794 Can also be used as a |method|: >
795 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200796<
797 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000799
800acos({expr}) *acos()*
801 Return the arc cosine of {expr} measured in radians, as a
802 |Float| in the range of [0, pi].
803 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100804 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000805 Examples: >
806 :echo acos(0)
807< 1.570796 >
808 :echo acos(-0.5)
809< 2.094395
810
811 Can also be used as a |method|: >
812 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200813<
814 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000816
817add({object}, {expr}) *add()*
818 Append the item {expr} to |List| or |Blob| {object}. Returns
819 the resulting |List| or |Blob|. Examples: >
820 :let alist = add([1, 2, 3], item)
821 :call add(mylist, "woodstock")
822< Note that when {expr} is a |List| it is appended as a single
823 item. Use |extend()| to concatenate |Lists|.
824 When {object} is a |Blob| then {expr} must be a number.
825 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100826 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827
828 Can also be used as a |method|: >
829 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200830<
831 Return type: list<{type}> (depending on the given |List|) or
832 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000833
834
835and({expr}, {expr}) *and()*
836 Bitwise AND on the two arguments. The arguments are converted
837 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100838 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000839 Example: >
840 :let flag = and(bits, 0x80)
841< Can also be used as a |method|: >
842 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200843<
844 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000845
846
847append({lnum}, {text}) *append()*
848 When {text} is a |List|: Append each item of the |List| as a
849 text line below line {lnum} in the current buffer.
850 Otherwise append {text} as one text line below line {lnum} in
851 the current buffer.
852 Any type of item is accepted and converted to a String.
853 {lnum} can be zero to insert a line before the first one.
854 {lnum} is used like with |getline()|.
855 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000856 0 for success. When {text} is an empty list zero is returned,
857 no matter the value of {lnum}.
858 In |Vim9| script an invalid argument or negative number
859 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000860 :let failed = append(line('$'), "# THE END")
861 :let failed = append(0, ["Chapter 1", "the beginning"])
862
863< Can also be used as a |method| after a List, the base is
864 passed as the second argument: >
865 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200866<
867 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000868
869
870appendbufline({buf}, {lnum}, {text}) *appendbufline()*
871 Like |append()| but append the text in buffer {buf}.
872
873 This function works only for loaded buffers. First call
874 |bufload()| if needed.
875
876 For the use of {buf}, see |bufname()|.
877
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000878 {lnum} is the line number to append below. Note that using
879 |line()| would use the current buffer, not the one appending
880 to. Use "$" to append at the end of the buffer. Other string
881 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000882
883 On success 0 is returned, on failure 1 is returned.
884 In |Vim9| script an error is given for an invalid {lnum}.
885
886 If {buf} is not a valid buffer or {lnum} is not valid, an
887 error message is given. Example: >
888 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000889< However, when {text} is an empty list then no error is given
890 for an invalid {lnum}, since {lnum} isn't actually used.
891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000892 Can also be used as a |method| after a List, the base is
893 passed as the second argument: >
894 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200895<
896 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000897
898
899argc([{winid}]) *argc()*
900 The result is the number of files in the argument list. See
901 |arglist|.
902 If {winid} is not supplied, the argument list of the current
903 window is used.
904 If {winid} is -1, the global argument list is used.
905 Otherwise {winid} specifies the window of which the argument
906 list is used: either the window number or the window ID.
907 Returns -1 if the {winid} argument is invalid.
908
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200909 Return type: |Number|
910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000911 *argidx()*
912argidx() The result is the current index in the argument list. 0 is
913 the first file. argc() - 1 is the last one. See |arglist|.
914
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200915 Return type: |Number|
916
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000917 *arglistid()*
918arglistid([{winnr} [, {tabnr}]])
919 Return the argument list ID. This is a number which
920 identifies the argument list being used. Zero is used for the
921 global argument list. See |arglist|.
922 Returns -1 if the arguments are invalid.
923
924 Without arguments use the current window.
925 With {winnr} only use this window in the current tab page.
926 With {winnr} and {tabnr} use the window in the specified tab
927 page.
928 {winnr} can be the window number or the |window-ID|.
929
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200930 Return type: |Number|
931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000932 *argv()*
933argv([{nr} [, {winid}]])
934 The result is the {nr}th file in the argument list. See
935 |arglist|. "argv(0)" is the first one. Example: >
936 :let i = 0
937 :while i < argc()
938 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000939 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000940 : let i = i + 1
941 :endwhile
942< Without the {nr} argument, or when {nr} is -1, a |List| with
943 the whole |arglist| is returned.
944
945 The {winid} argument specifies the window ID, see |argc()|.
946 For the Vim command line arguments see |v:argv|.
947
Bram Moolenaar016188f2022-06-06 20:52:59 +0100948 Returns an empty string if {nr}th argument is not present in
949 the argument list. Returns an empty List if the {winid}
950 argument is invalid.
951
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200952 Return type: |String|
953
954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000955asin({expr}) *asin()*
956 Return the arc sine of {expr} measured in radians, as a |Float|
957 in the range of [-pi/2, pi/2].
958 {expr} must evaluate to a |Float| or a |Number| in the range
959 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100960 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
961 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000962 Examples: >
963 :echo asin(0.8)
964< 0.927295 >
965 :echo asin(-0.5)
966< -0.523599
967
968 Can also be used as a |method|: >
969 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200970<
971 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000972
973assert_ functions are documented here: |assert-functions-details|
974
975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000976atan({expr}) *atan()*
977 Return the principal value of the arc tangent of {expr}, in
978 the range [-pi/2, +pi/2] radians, as a |Float|.
979 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100980 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000981 Examples: >
982 :echo atan(100)
983< 1.560797 >
984 :echo atan(-4.01)
985< -1.326405
986
987 Can also be used as a |method|: >
988 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200989<
990 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000991
992
993atan2({expr1}, {expr2}) *atan2()*
994 Return the arc tangent of {expr1} / {expr2}, measured in
995 radians, as a |Float| in the range [-pi, pi].
996 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100997 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
998 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000999 Examples: >
1000 :echo atan2(-1, 1)
1001< -0.785398 >
1002 :echo atan2(1, -1)
1003< 2.356194
1004
1005 Can also be used as a |method|: >
1006 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001007<
1008 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001009
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001010
1011autocmd_add({acmds}) *autocmd_add()*
1012 Adds a List of autocmds and autocmd groups.
1013
1014 The {acmds} argument is a List where each item is a Dict with
1015 the following optional items:
1016 bufnr buffer number to add a buffer-local autocmd.
1017 If this item is specified, then the "pattern"
1018 item is ignored.
1019 cmd Ex command to execute for this autocmd event
1020 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001021 This can be either a String with a single
1022 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001023 group autocmd group name. Refer to |autocmd-groups|.
1024 If this group doesn't exist then it is
1025 created. If not specified or empty, then the
1026 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001027 nested boolean flag, set to v:true to add a nested
1028 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001029 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 which executes only once. Refer to
1031 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001032 pattern autocmd pattern string. Refer to
1033 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001034 present, then this item is ignored. This can
1035 be a String with a single pattern or a List of
1036 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001037 replace boolean flag, set to v:true to remove all the
1038 commands associated with the specified autocmd
1039 event and group and add the {cmd}. This is
1040 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001041 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001042
1043 Returns v:true on success and v:false on failure.
1044 Examples: >
1045 " Create a buffer-local autocmd for buffer 5
1046 let acmd = {}
1047 let acmd.group = 'MyGroup'
1048 let acmd.event = 'BufEnter'
1049 let acmd.bufnr = 5
1050 let acmd.cmd = 'call BufEnterFunc()'
1051 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001052<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001053 Can also be used as a |method|: >
1054 GetAutocmdList()->autocmd_add()
1055<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001056 Return type: |vim9-boolean|
1057
1058
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001059autocmd_delete({acmds}) *autocmd_delete()*
1060 Deletes a List of autocmds and autocmd groups.
1061
1062 The {acmds} argument is a List where each item is a Dict with
1063 the following optional items:
1064 bufnr buffer number to delete a buffer-local autocmd.
1065 If this item is specified, then the "pattern"
1066 item is ignored.
1067 cmd Ex command for this autocmd event
1068 event autocmd event name. Refer to |autocmd-events|.
1069 If '*' then all the autocmd events in this
1070 group are deleted.
1071 group autocmd group name. Refer to |autocmd-groups|.
1072 If not specified or empty, then the default
1073 group is used.
1074 nested set to v:true for a nested autocmd.
1075 Refer to |autocmd-nested|.
1076 once set to v:true for an autocmd which executes
1077 only once. Refer to |autocmd-once|.
1078 pattern autocmd pattern string. Refer to
1079 |autocmd-patterns|. If "bufnr" item is
1080 present, then this item is ignored.
1081
1082 If only {group} is specified in a {acmds} entry and {event},
1083 {pattern} and {cmd} are not specified, then that autocmd group
1084 is deleted.
1085
Bram Moolenaar016188f2022-06-06 20:52:59 +01001086 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001087 Examples: >
1088 " :autocmd! BufLeave *.vim
1089 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1090 call autocmd_delete([acmd]})
1091 " :autocmd! MyGroup1 BufLeave
1092 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1093 call autocmd_delete([acmd])
1094 " :autocmd! MyGroup2 BufEnter *.c
1095 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1096 \ pattern: '*.c'}
1097 " :autocmd! MyGroup2 * *.c
1098 let acmd = #{group: 'MyGroup2', event: '*',
1099 \ pattern: '*.c'}
1100 call autocmd_delete([acmd])
1101 " :autocmd! MyGroup3
1102 let acmd = #{group: 'MyGroup3'}
1103 call autocmd_delete([acmd])
1104<
1105 Can also be used as a |method|: >
1106 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001107<
1108 Return type: |vim9-boolean|
1109
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001110
1111autocmd_get([{opts}]) *autocmd_get()*
1112 Returns a |List| of autocmds. If {opts} is not supplied, then
1113 returns the autocmds for all the events in all the groups.
1114
1115 The optional {opts} Dict argument supports the following
1116 items:
1117 group Autocmd group name. If specified, returns only
1118 the autocmds defined in this group. If the
1119 specified group doesn't exist, results in an
1120 error message. If set to an empty string,
1121 then the default autocmd group is used.
1122 event Autocmd event name. If specified, returns only
1123 the autocmds defined for this event. If set
1124 to "*", then returns autocmds for all the
1125 events. If the specified event doesn't exist,
1126 results in an error message.
1127 pattern Autocmd pattern. If specified, returns only
1128 the autocmds defined for this pattern.
1129 A combination of the above three times can be supplied in
1130 {opts}.
1131
1132 Each Dict in the returned List contains the following items:
1133 bufnr For buffer-local autocmds, buffer number where
1134 the autocmd is defined.
1135 cmd Command executed for this autocmd.
1136 event Autocmd event name.
1137 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001138 nested Boolean flag, set to v:true for a nested
1139 autocmd. See |autocmd-nested|.
1140 once Boolean flag, set to v:true, if the autocmd
1141 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001142 pattern Autocmd pattern. For a buffer-local
1143 autocmd, this will be of the form "<buffer=n>".
1144 If there are multiple commands for an autocmd event in a
1145 group, then separate items are returned for each command.
1146
Bram Moolenaar016188f2022-06-06 20:52:59 +01001147 Returns an empty List if an autocmd with the specified group
1148 or event or pattern is not found.
1149
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001150 Examples: >
1151 " :autocmd MyGroup
1152 echo autocmd_get(#{group: 'Mygroup'})
1153 " :autocmd G BufUnload
1154 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1155 " :autocmd G * *.ts
1156 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1157 echo autocmd_get(acmd)
1158 " :autocmd Syntax
1159 echo autocmd_get(#{event: 'Syntax'})
1160 " :autocmd G BufEnter *.ts
1161 let acmd = #{group: 'G', event: 'BufEnter',
1162 \ pattern: '*.ts'}
1163 echo autocmd_get(acmd)
1164<
1165 Can also be used as a |method|: >
1166 Getopts()->autocmd_get()
1167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001168 Return type: list<dict<any>>
1169
1170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001171balloon_gettext() *balloon_gettext()*
1172 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001173 not used for the List. Returns an empty string if balloon
1174 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001175
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001176 Return type: |String|
1177
1178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001179balloon_show({expr}) *balloon_show()*
1180 Show {expr} inside the balloon. For the GUI {expr} is used as
1181 a string. For a terminal {expr} can be a list, which contains
1182 the lines of the balloon. If {expr} is not a list it will be
1183 split with |balloon_split()|.
1184 If {expr} is an empty string any existing balloon is removed.
1185
1186 Example: >
1187 func GetBalloonContent()
1188 " ... initiate getting the content
1189 return ''
1190 endfunc
1191 set balloonexpr=GetBalloonContent()
1192
1193 func BalloonCallback(result)
1194 call balloon_show(a:result)
1195 endfunc
1196< Can also be used as a |method|: >
1197 GetText()->balloon_show()
1198<
1199 The intended use is that fetching the content of the balloon
1200 is initiated from 'balloonexpr'. It will invoke an
1201 asynchronous method, in which a callback invokes
1202 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001203 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001204
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001205 When showing a balloon is not possible then nothing happens,
1206 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001207 {only available when compiled with the |+balloon_eval| or
1208 |+balloon_eval_term| feature}
1209
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001210 Return type: |Number|
1211
1212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001213balloon_split({msg}) *balloon_split()*
1214 Split String {msg} into lines to be displayed in a balloon.
1215 The splits are made for the current window size and optimize
1216 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001217 Returns a |List| with the split lines. Returns an empty List
1218 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001219 Can also be used as a |method|: >
1220 GetText()->balloon_split()->balloon_show()
1221
1222< {only available when compiled with the |+balloon_eval_term|
1223 feature}
1224
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001225 Return type: list<any> or list<string>
1226
Christ van Willegence0ef912024-06-20 23:41:59 +02001227bindtextdomain({package}, {path}) *bindtextdomain()*
1228 Bind a specific {package} to a {path} so that the
1229 |gettext()| function can be used to get language-specific
1230 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001231 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001232
Christ van Willegen8252ef12024-07-11 21:36:21 +02001233 Returns v:true on success and v:false on failure (out of
1234 memory).
1235
1236 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001238blob2list({blob}) *blob2list()*
1239 Return a List containing the number value of each byte in Blob
1240 {blob}. Examples: >
1241 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1242 blob2list(0z) returns []
1243< Returns an empty List on error. |list2blob()| does the
1244 opposite.
1245
1246 Can also be used as a |method|: >
1247 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001248<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001249 Return type: list<any> or list<number>
1250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001251 *browse()*
1252browse({save}, {title}, {initdir}, {default})
1253 Put up a file requester. This only works when "has("browse")"
1254 returns |TRUE| (only in some GUI versions).
1255 The input fields are:
1256 {save} when |TRUE|, select file to write
1257 {title} title for the requester
1258 {initdir} directory to start browsing in
1259 {default} default file name
1260 An empty string is returned when the "Cancel" button is hit,
1261 something went wrong, or browsing is not possible.
1262
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001263 Return type: |String|
1264
1265
1266browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001267 Put up a directory requester. This only works when
1268 "has("browse")" returns |TRUE| (only in some GUI versions).
1269 On systems where a directory browser is not supported a file
1270 browser is used. In that case: select a file in the directory
1271 to be used.
1272 The input fields are:
1273 {title} title for the requester
1274 {initdir} directory to start browsing in
1275 When the "Cancel" button is hit, something went wrong, or
1276 browsing is not possible, an empty string is returned.
1277
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001278 Return type: |String|
1279
1280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001281bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001282 Add a buffer to the buffer list with name {name} (must be a
1283 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001284 If a buffer for file {name} already exists, return that buffer
1285 number. Otherwise return the buffer number of the newly
1286 created buffer. When {name} is an empty string then a new
1287 buffer is always created.
1288 The buffer will not have 'buflisted' set and not be loaded
1289 yet. To add some text to the buffer use this: >
1290 let bufnr = bufadd('someName')
1291 call bufload(bufnr)
1292 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001293< Returns 0 on error.
1294 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001295 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001296<
1297 Return type: |Number|
1298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001299
1300bufexists({buf}) *bufexists()*
1301 The result is a Number, which is |TRUE| if a buffer called
1302 {buf} exists.
1303 If the {buf} argument is a number, buffer numbers are used.
1304 Number zero is the alternate buffer for the current window.
1305
1306 If the {buf} argument is a string it must match a buffer name
1307 exactly. The name can be:
1308 - Relative to the current directory.
1309 - A full path.
1310 - The name of a buffer with 'buftype' set to "nofile".
1311 - A URL name.
1312 Unlisted buffers will be found.
1313 Note that help files are listed by their short name in the
1314 output of |:buffers|, but bufexists() requires using their
1315 long name to be able to find them.
1316 bufexists() may report a buffer exists, but to use the name
1317 with a |:buffer| command you may need to use |expand()|. Esp
1318 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1319 Use "bufexists(0)" to test for the existence of an alternate
1320 file name.
1321
1322 Can also be used as a |method|: >
1323 let exists = 'somename'->bufexists()
1324<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001325 Return type: |Number|
1326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001327 Obsolete name: buffer_exists(). *buffer_exists()*
1328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001330buflisted({buf}) *buflisted()*
1331 The result is a Number, which is |TRUE| if a buffer called
1332 {buf} exists and is listed (has the 'buflisted' option set).
1333 The {buf} argument is used like with |bufexists()|.
1334
1335 Can also be used as a |method|: >
1336 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001337<
1338 Return type: |Number|
1339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001340
1341bufload({buf}) *bufload()*
1342 Ensure the buffer {buf} is loaded. When the buffer name
1343 refers to an existing file then the file is read. Otherwise
1344 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001345 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001346 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001347 If there is an existing swap file for the file of the buffer,
1348 there will be no dialog, the buffer will be loaded anyway.
1349 The {buf} argument is used like with |bufexists()|.
1350
1351 Can also be used as a |method|: >
1352 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001353<
1354 Return type: |Number|
1355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001356
1357bufloaded({buf}) *bufloaded()*
1358 The result is a Number, which is |TRUE| if a buffer called
1359 {buf} exists and is loaded (shown in a window or hidden).
1360 The {buf} argument is used like with |bufexists()|.
1361
1362 Can also be used as a |method|: >
1363 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001364<
1365 Return type: |Number|
1366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001367
1368bufname([{buf}]) *bufname()*
1369 The result is the name of a buffer. Mostly as it is displayed
1370 by the `:ls` command, but not using special names such as
1371 "[No Name]".
1372 If {buf} is omitted the current buffer is used.
1373 If {buf} is a Number, that buffer number's name is given.
1374 Number zero is the alternate buffer for the current window.
1375 If {buf} is a String, it is used as a |file-pattern| to match
1376 with the buffer names. This is always done like 'magic' is
1377 set and 'cpoptions' is empty. When there is more than one
1378 match an empty string is returned.
1379 "" or "%" can be used for the current buffer, "#" for the
1380 alternate buffer.
1381 A full match is preferred, otherwise a match at the start, end
1382 or middle of the buffer name is accepted. If you only want a
1383 full match then put "^" at the start and "$" at the end of the
1384 pattern.
1385 Listed buffers are found first. If there is a single match
1386 with a listed buffer, that one is returned. Next unlisted
1387 buffers are searched for.
1388 If the {buf} is a String, but you want to use it as a buffer
1389 number, force it to be a Number by adding zero to it: >
1390 :echo bufname("3" + 0)
1391< Can also be used as a |method|: >
1392 echo bufnr->bufname()
1393
1394< If the buffer doesn't exist, or doesn't have a name, an empty
1395 string is returned. >
1396 bufname("#") alternate buffer name
1397 bufname(3) name of buffer 3
1398 bufname("%") name of current buffer
1399 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001400<
1401 Return type: |String|
1402 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001403 Obsolete name: buffer_name().
1404
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001405
1406bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001407 The result is the number of a buffer, as it is displayed by
1408 the `:ls` command. For the use of {buf}, see |bufname()|
1409 above.
1410
1411 If the buffer doesn't exist, -1 is returned. Or, if the
1412 {create} argument is present and TRUE, a new, unlisted,
1413 buffer is created and its number is returned. Example: >
1414 let newbuf = bufnr('Scratch001', 1)
1415< Using an empty name uses the current buffer. To create a new
1416 buffer with an empty name use |bufadd()|.
1417
1418 bufnr("$") is the last buffer: >
1419 :let last_buffer = bufnr("$")
1420< The result is a Number, which is the highest buffer number
1421 of existing buffers. Note that not all buffers with a smaller
1422 number necessarily exist, because ":bwipeout" may have removed
1423 them. Use bufexists() to test for the existence of a buffer.
1424
1425 Can also be used as a |method|: >
1426 echo bufref->bufnr()
1427<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001428 Return type: |Number|
1429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001430 Obsolete name: buffer_number(). *buffer_number()*
1431 *last_buffer_nr()*
1432 Obsolete name for bufnr("$"): last_buffer_nr().
1433
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001435bufwinid({buf}) *bufwinid()*
1436 The result is a Number, which is the |window-ID| of the first
1437 window associated with buffer {buf}. For the use of {buf},
1438 see |bufname()| above. If buffer {buf} doesn't exist or
1439 there is no such window, -1 is returned. Example: >
1440
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001441 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001443 Only deals with the current tab page. See |win_findbuf()| for
1444 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001445
1446 Can also be used as a |method|: >
1447 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001448<
1449 Return type: |Number|
1450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001451
1452bufwinnr({buf}) *bufwinnr()*
1453 Like |bufwinid()| but return the window number instead of the
1454 |window-ID|.
1455 If buffer {buf} doesn't exist or there is no such window, -1
1456 is returned. Example: >
1457
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001458 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001459
1460< The number can be used with |CTRL-W_w| and ":wincmd w"
1461 |:wincmd|.
1462
1463 Can also be used as a |method|: >
1464 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001465<
1466 Return type: |Number|
1467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468
1469byte2line({byte}) *byte2line()*
1470 Return the line number that contains the character at byte
1471 count {byte} in the current buffer. This includes the
1472 end-of-line character, depending on the 'fileformat' option
1473 for the current buffer. The first character has byte count
1474 one.
1475 Also see |line2byte()|, |go| and |:goto|.
1476
Bram Moolenaar016188f2022-06-06 20:52:59 +01001477 Returns -1 if the {byte} value is invalid.
1478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001479 Can also be used as a |method|: >
1480 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001481<
1482 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001484 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001485 feature}
1486
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001487
Christian Brabandt67672ef2023-04-24 21:09:54 +01001488byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001489 Return byte index of the {nr}'th character in the String
1490 {expr}. Use zero for the first character, it then returns
1491 zero.
1492 If there are no multibyte characters the returned value is
1493 equal to {nr}.
1494 Composing characters are not counted separately, their byte
1495 length is added to the preceding base character. See
1496 |byteidxcomp()| below for counting composing characters
1497 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001498 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1499 index in the String {expr} instead of as the character index.
1500 The UTF-16 index is the index in the string when it is encoded
1501 with 16-bit words. If the specified UTF-16 index is in the
1502 middle of a character (e.g. in a 4-byte character), then the
1503 byte index of the first byte in the character is returned.
1504 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001505 Example : >
1506 echo matchstr(str, ".", byteidx(str, 3))
1507< will display the fourth character. Another way to do the
1508 same: >
1509 let s = strpart(str, byteidx(str, 3))
1510 echo strpart(s, 0, byteidx(s, 1))
1511< Also see |strgetchar()| and |strcharpart()|.
1512
1513 If there are less than {nr} characters -1 is returned.
1514 If there are exactly {nr} characters the length of the string
1515 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001516 See |charidx()| and |utf16idx()| for getting the character and
1517 UTF-16 index respectively from the byte index.
1518 Examples: >
1519 echo byteidx('a😊😊', 2) returns 5
1520 echo byteidx('a😊😊', 2, 1) returns 1
1521 echo byteidx('a😊😊', 3, 1) returns 5
1522<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523 Can also be used as a |method|: >
1524 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001525<
1526 Return type: |Number|
1527
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001528
Christian Brabandt67672ef2023-04-24 21:09:54 +01001529byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530 Like byteidx(), except that a composing character is counted
1531 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001532 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001533 echo byteidx(s, 1)
1534 echo byteidxcomp(s, 1)
1535 echo byteidxcomp(s, 2)
1536< The first and third echo result in 3 ('e' plus composing
1537 character is 3 bytes), the second echo results in 1 ('e' is
1538 one byte).
1539 Only works differently from byteidx() when 'encoding' is set
1540 to a Unicode encoding.
1541
1542 Can also be used as a |method|: >
1543 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001544<
1545 Return type: |Number|
1546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001547
1548call({func}, {arglist} [, {dict}]) *call()* *E699*
1549 Call function {func} with the items in |List| {arglist} as
1550 arguments.
1551 {func} can either be a |Funcref| or the name of a function.
1552 a:firstline and a:lastline are set to the cursor line.
1553 Returns the return value of the called function.
1554 {dict} is for functions with the "dict" attribute. It will be
1555 used to set the local variable "self". |Dictionary-function|
1556
1557 Can also be used as a |method|: >
1558 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001559<
1560 Return type: any, depending on {func}
1561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001562
1563ceil({expr}) *ceil()*
1564 Return the smallest integral value greater than or equal to
1565 {expr} as a |Float| (round up).
1566 {expr} must evaluate to a |Float| or a |Number|.
1567 Examples: >
1568 echo ceil(1.456)
1569< 2.0 >
1570 echo ceil(-5.456)
1571< -5.0 >
1572 echo ceil(4.0)
1573< 4.0
1574
Bram Moolenaar016188f2022-06-06 20:52:59 +01001575 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577 Can also be used as a |method|: >
1578 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001579<
1580 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581
1582
1583ch_ functions are documented here: |channel-functions-details|
1584
1585
1586changenr() *changenr()*
1587 Return the number of the most recent change. This is the same
1588 number as what is displayed with |:undolist| and can be used
1589 with the |:undo| command.
1590 When a change was made it is the number of that change. After
1591 redo it is the number of the redone change. After undo it is
1592 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001593 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001594
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001595 Return type: |Number|
1596
1597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001598char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001599 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600 Examples: >
1601 char2nr(" ") returns 32
1602 char2nr("ABC") returns 65
1603< When {utf8} is omitted or zero, the current 'encoding' is used.
1604 Example for "utf-8": >
1605 char2nr("á") returns 225
1606 char2nr("á"[0]) returns 195
1607< When {utf8} is TRUE, always treat as UTF-8 characters.
1608 A combining character is a separate character.
1609 |nr2char()| does the opposite.
1610 To turn a string into a list of character numbers: >
1611 let str = "ABC"
1612 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1613< Result: [65, 66, 67]
1614
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0 if {string} is not a |String|.
1616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617 Can also be used as a |method|: >
1618 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001619<
1620 Return type: |Number|
1621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001623charclass({string}) *charclass()*
1624 Return the character class of the first character in {string}.
1625 The character class is one of:
1626 0 blank
1627 1 punctuation
1628 2 word character
1629 3 emoji
1630 other specific Unicode class
1631 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001632 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001633
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001634 Return type: |Number|
1635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001636
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001637charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001638 Same as |col()| but returns the character index of the column
1639 position given with {expr} instead of the byte position.
1640
1641 Example:
1642 With the cursor on '세' in line 5 with text "여보세요": >
1643 charcol('.') returns 3
1644 col('.') returns 7
1645
1646< Can also be used as a |method|: >
1647 GetPos()->col()
1648<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001649 Return type: |Number|
1650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001651 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001652charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001653 Return the character index of the byte at {idx} in {string}.
1654 The index of the first character is zero.
1655 If there are no multibyte characters the returned value is
1656 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001659 are not counted separately, their byte length is added to the
1660 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001661 When {countcc} is |TRUE|, then composing characters are
1662 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001663
1664 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1665 index in the String {expr} instead of as the byte index.
1666
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001667 Returns -1 if the arguments are invalid or if there are less
1668 than {idx} bytes. If there are exactly {idx} bytes the length
1669 of the string in characters is returned.
1670
1671 An error is given and -1 is returned if the first argument is
1672 not a string, the second argument is not a number or when the
1673 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001675 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001676 from the character index and |utf16idx()| for getting the
1677 UTF-16 index from the character index.
1678 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679 Examples: >
1680 echo charidx('áb́ć', 3) returns 1
1681 echo charidx('áb́ć', 6, 1) returns 4
1682 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001683 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684<
1685 Can also be used as a |method|: >
1686 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001687<
1688 Return type: |Number|
1689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690
1691chdir({dir}) *chdir()*
1692 Change the current working directory to {dir}. The scope of
1693 the directory change depends on the directory of the current
1694 window:
1695 - If the current window has a window-local directory
1696 (|:lcd|), then changes the window local directory.
1697 - Otherwise, if the current tabpage has a local
1698 directory (|:tcd|) then changes the tabpage local
1699 directory.
1700 - Otherwise, changes the global directory.
1701 {dir} must be a String.
1702 If successful, returns the previous working directory. Pass
1703 this to another chdir() to restore the directory.
1704 On failure, returns an empty string.
1705
1706 Example: >
1707 let save_dir = chdir(newdir)
1708 if save_dir != ""
1709 " ... do some work
1710 call chdir(save_dir)
1711 endif
1712
1713< Can also be used as a |method|: >
1714 GetDir()->chdir()
1715<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001716 Return type: |String|
1717
1718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719cindent({lnum}) *cindent()*
1720 Get the amount of indent for line {lnum} according the C
1721 indenting rules, as with 'cindent'.
1722 The indent is counted in spaces, the value of 'tabstop' is
1723 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001724 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725 See |C-indenting|.
1726
1727 Can also be used as a |method|: >
1728 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001729<
1730 Return type: |Number|
1731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001732
1733clearmatches([{win}]) *clearmatches()*
1734 Clears all matches previously defined for the current window
1735 by |matchadd()| and the |:match| commands.
1736 If {win} is specified, use the window with this number or
1737 window ID instead of the current window.
1738
1739 Can also be used as a |method|: >
1740 GetWin()->clearmatches()
1741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001742 Return type: |Number|
1743
1744
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001745col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001746 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001747 position given with {expr}.
1748 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001749 When {expr} is "$", it means the end of the cursor line, so
1750 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 Additionally {expr} can be [lnum, col]: a |List| with the line
1752 and column number. Most useful when the column is "$", to get
1753 the last column of a specific line. When "lnum" or "col" is
1754 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001755
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001756 With the optional {winid} argument the values are obtained for
1757 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759 To get the line number use |line()|. To get both use
1760 |getpos()|.
1761 For the screen column position use |virtcol()|. For the
1762 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001764 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001766 Examples: >
1767 col(".") column of cursor
1768 col("$") length of cursor line plus one
1769 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001770 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001771<
1772 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001773 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001774 For an uppercase mark the column may actually be in another
1775 buffer.
1776 For the cursor position, when 'virtualedit' is active, the
1777 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001778 line. Also, when using a <Cmd> mapping the cursor isn't
1779 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001780 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001781
1782< Can also be used as a |method|: >
1783 GetPos()->col()
1784<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001785 Return type: |Number|
1786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001787
1788complete({startcol}, {matches}) *complete()* *E785*
1789 Set the matches for Insert mode completion.
1790 Can only be used in Insert mode. You need to use a mapping
1791 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1792 or with an expression mapping.
1793 {startcol} is the byte offset in the line where the completed
1794 text start. The text up to the cursor is the original text
1795 that will be replaced by the matches. Use col('.') for an
1796 empty string. "col('.') - 1" will replace one character by a
1797 match.
1798 {matches} must be a |List|. Each |List| item is one match.
1799 See |complete-items| for the kind of items that are possible.
1800 "longest" in 'completeopt' is ignored.
1801 Note that the after calling this function you need to avoid
1802 inserting anything that would cause completion to stop.
1803 The match can be selected with CTRL-N and CTRL-P as usual with
1804 Insert mode completion. The popup menu will appear if
1805 specified, see |ins-completion-menu|.
1806 Example: >
1807 inoremap <F5> <C-R>=ListMonths()<CR>
1808
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001809 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001810 call complete(col('.'), ['January', 'February', 'March',
1811 \ 'April', 'May', 'June', 'July', 'August', 'September',
1812 \ 'October', 'November', 'December'])
1813 return ''
1814 endfunc
1815< This isn't very useful, but it shows how it works. Note that
1816 an empty string is returned to avoid a zero being inserted.
1817
1818 Can also be used as a |method|, the base is passed as the
1819 second argument: >
1820 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821<
1822 Return type: |Number|
1823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001824
1825complete_add({expr}) *complete_add()*
1826 Add {expr} to the list of matches. Only to be used by the
1827 function specified with the 'completefunc' option.
1828 Returns 0 for failure (empty string or out of memory),
1829 1 when the match was added, 2 when the match was already in
1830 the list.
1831 See |complete-functions| for an explanation of {expr}. It is
1832 the same as one item in the list that 'omnifunc' would return.
1833
1834 Can also be used as a |method|: >
1835 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001836<
1837 Return type: |Number|
1838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001839
1840complete_check() *complete_check()*
1841 Check for a key typed while looking for completion matches.
1842 This is to be used when looking for matches takes some time.
1843 Returns |TRUE| when searching for matches is to be aborted,
1844 zero otherwise.
1845 Only to be used by the function specified with the
1846 'completefunc' option.
1847
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001848 Return type: |Number|
1849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850
1851complete_info([{what}]) *complete_info()*
1852 Returns a |Dictionary| with information about Insert mode
1853 completion. See |ins-completion|.
1854 The items are:
1855 mode Current completion mode name string.
1856 See |complete_info_mode| for the values.
1857 pum_visible |TRUE| if popup menu is visible.
1858 See |pumvisible()|.
1859 items List of completion matches. Each item is a
1860 dictionary containing the entries "word",
1861 "abbr", "menu", "kind", "info" and "user_data".
1862 See |complete-items|.
1863 selected Selected item index. First index is zero.
1864 Index is -1 if no item is selected (showing
1865 typed text only, or the last completion after
1866 no item is selected when using the <Up> or
1867 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001868 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001869
1870 *complete_info_mode*
1871 mode values are:
1872 "" Not in completion mode
1873 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1874 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1875 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1876 |i_CTRL-X_CTRL-Y|
1877 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1878 "files" File names |i_CTRL-X_CTRL-F|
1879 "tags" Tags |i_CTRL-X_CTRL-]|
1880 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1881 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1882 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1883 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1884 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1885 "function" User defined completion |i_CTRL-X_CTRL-U|
1886 "omni" Omni completion |i_CTRL-X_CTRL-O|
1887 "spell" Spelling suggestions |i_CTRL-X_s|
1888 "eval" |complete()| completion
1889 "unknown" Other internal modes
1890
1891 If the optional {what} list argument is supplied, then only
1892 the items listed in {what} are returned. Unsupported items in
1893 {what} are silently ignored.
1894
1895 To get the position and size of the popup menu, see
1896 |pum_getpos()|. It's also available in |v:event| during the
1897 |CompleteChanged| event.
1898
Bram Moolenaar016188f2022-06-06 20:52:59 +01001899 Returns an empty |Dictionary| on error.
1900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001901 Examples: >
1902 " Get all items
1903 call complete_info()
1904 " Get only 'mode'
1905 call complete_info(['mode'])
1906 " Get only 'mode' and 'pum_visible'
1907 call complete_info(['mode', 'pum_visible'])
1908
1909< Can also be used as a |method|: >
1910 GetItems()->complete_info()
1911<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001912 Return type: dict<any>
1913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001914 *confirm()*
1915confirm({msg} [, {choices} [, {default} [, {type}]]])
1916 confirm() offers the user a dialog, from which a choice can be
1917 made. It returns the number of the choice. For the first
1918 choice this is 1.
1919 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001920 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001921
1922 {msg} is displayed in a |dialog| with {choices} as the
1923 alternatives. When {choices} is missing or empty, "&OK" is
1924 used (and translated).
1925 {msg} is a String, use '\n' to include a newline. Only on
1926 some systems the string is wrapped when it doesn't fit.
1927
1928 {choices} is a String, with the individual choices separated
1929 by '\n', e.g. >
1930 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1931< The letter after the '&' is the shortcut key for that choice.
1932 Thus you can type 'c' to select "Cancel". The shortcut does
1933 not need to be the first letter: >
1934 confirm("file has been modified", "&Save\nSave &All")
1935< For the console, the first letter of each choice is used as
1936 the default shortcut key. Case is ignored.
1937
1938 The optional {default} argument is the number of the choice
1939 that is made if the user hits <CR>. Use 1 to make the first
1940 choice the default one. Use 0 to not set a default. If
1941 {default} is omitted, 1 is used.
1942
1943 The optional {type} String argument gives the type of dialog.
1944 This is only used for the icon of the GTK, Mac, Motif and
1945 Win32 GUI. It can be one of these values: "Error",
1946 "Question", "Info", "Warning" or "Generic". Only the first
1947 character is relevant. When {type} is omitted, "Generic" is
1948 used.
1949
1950 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1951 or another valid interrupt key, confirm() returns 0.
1952
1953 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001954 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001955 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001956 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001957 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001958 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001959 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001960 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001961 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001962 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001963< In a GUI dialog, buttons are used. The layout of the buttons
1964 depends on the 'v' flag in 'guioptions'. If it is included,
1965 the buttons are always put vertically. Otherwise, confirm()
1966 tries to put the buttons in one horizontal line. If they
1967 don't fit, a vertical layout is used anyway. For some systems
1968 the horizontal layout is always used.
1969
1970 Can also be used as a |method|in: >
1971 BuildMessage()->confirm("&Yes\n&No")
1972<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001973 Return type: |Number|
1974
1975
1976copy({expr}) *copy()*
1977 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001978 different from using {expr} directly.
1979 When {expr} is a |List| a shallow copy is created. This means
1980 that the original |List| can be changed without changing the
1981 copy, and vice versa. But the items are identical, thus
1982 changing an item changes the contents of both |Lists|.
1983 A |Dictionary| is copied in a similar way as a |List|.
1984 Also see |deepcopy()|.
1985 Can also be used as a |method|: >
1986 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001987<
1988 Return type: any, depending on {expr}
1989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990
1991cos({expr}) *cos()*
1992 Return the cosine of {expr}, measured in radians, as a |Float|.
1993 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001994 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001995 Examples: >
1996 :echo cos(100)
1997< 0.862319 >
1998 :echo cos(-4.01)
1999< -0.646043
2000
2001 Can also be used as a |method|: >
2002 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002003<
2004 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002005
2006
2007cosh({expr}) *cosh()*
2008 Return the hyperbolic cosine of {expr} as a |Float| in the range
2009 [1, inf].
2010 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002011 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002012 Examples: >
2013 :echo cosh(0.5)
2014< 1.127626 >
2015 :echo cosh(-0.5)
2016< -1.127626
2017
2018 Can also be used as a |method|: >
2019 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002020<
2021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002022
2023
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002024count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002025 Return the number of times an item with value {expr} appears
2026 in |String|, |List| or |Dictionary| {comp}.
2027
2028 If {start} is given then start with the item with this index.
2029 {start} can only be used with a |List|.
2030
2031 When {ic} is given and it's |TRUE| then case is ignored.
2032
2033 When {comp} is a string then the number of not overlapping
2034 occurrences of {expr} is returned. Zero is returned when
2035 {expr} is an empty string.
2036
2037 Can also be used as a |method|: >
2038 mylist->count(val)
2039<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002040 Return type: |Number|
2041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002042 *cscope_connection()*
2043cscope_connection([{num} , {dbpath} [, {prepend}]])
2044 Checks for the existence of a |cscope| connection. If no
2045 parameters are specified, then the function returns:
2046 0, if cscope was not available (not compiled in), or
2047 if there are no cscope connections;
2048 1, if there is at least one cscope connection.
2049
2050 If parameters are specified, then the value of {num}
2051 determines how existence of a cscope connection is checked:
2052
2053 {num} Description of existence check
2054 ----- ------------------------------
2055 0 Same as no parameters (e.g., "cscope_connection()").
2056 1 Ignore {prepend}, and use partial string matches for
2057 {dbpath}.
2058 2 Ignore {prepend}, and use exact string matches for
2059 {dbpath}.
2060 3 Use {prepend}, use partial string matches for both
2061 {dbpath} and {prepend}.
2062 4 Use {prepend}, use exact string matches for both
2063 {dbpath} and {prepend}.
2064
2065 Note: All string comparisons are case sensitive!
2066
2067 Examples. Suppose we had the following (from ":cs show"): >
2068
2069 # pid database name prepend path
2070 0 27664 cscope.out /usr/local
2071<
2072 Invocation Return Val ~
2073 ---------- ---------- >
2074 cscope_connection() 1
2075 cscope_connection(1, "out") 1
2076 cscope_connection(2, "out") 0
2077 cscope_connection(3, "out") 0
2078 cscope_connection(3, "out", "local") 1
2079 cscope_connection(4, "out") 0
2080 cscope_connection(4, "out", "local") 0
2081 cscope_connection(4, "cscope.out", "/usr/local") 1
2082<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002083 Return type: |Number|
2084
2085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002086cursor({lnum}, {col} [, {off}]) *cursor()*
2087cursor({list})
2088 Positions the cursor at the column (byte count) {col} in the
2089 line {lnum}. The first column is one.
2090
2091 When there is one argument {list} this is used as a |List|
2092 with two, three or four item:
2093 [{lnum}, {col}]
2094 [{lnum}, {col}, {off}]
2095 [{lnum}, {col}, {off}, {curswant}]
2096 This is like the return value of |getpos()| or |getcurpos()|,
2097 but without the first item.
2098
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002099 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002100 |setcursorcharpos()|.
2101
2102 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002103 {lnum} is used like with |getline()|, except that if {lnum} is
2104 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002105 If {lnum} is greater than the number of lines in the buffer,
2106 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002107 If {col} is greater than the number of bytes in the line,
2108 the cursor will be positioned at the last character in the
2109 line.
2110 If {col} is zero, the cursor will stay in the current column.
2111 If {curswant} is given it is used to set the preferred column
2112 for vertical movement. Otherwise {col} is used.
2113
2114 When 'virtualedit' is used {off} specifies the offset in
2115 screen columns from the start of the character. E.g., a
2116 position within a <Tab> or after the last character.
2117 Returns 0 when the position could be set, -1 otherwise.
2118
2119 Can also be used as a |method|: >
2120 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002121<
2122 Return type: |Number|
2123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002124
2125debugbreak({pid}) *debugbreak()*
2126 Specifically used to interrupt a program being debugged. It
2127 will cause process {pid} to get a SIGTRAP. Behavior for other
2128 processes is undefined. See |terminal-debugger|.
2129 {only available on MS-Windows}
2130
Bram Moolenaar016188f2022-06-06 20:52:59 +01002131 Returns |TRUE| if successfully interrupted the program.
2132 Otherwise returns |FALSE|.
2133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002134 Can also be used as a |method|: >
2135 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002136<
2137 Return type: |Number|
2138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002139
2140deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2141 Make a copy of {expr}. For Numbers and Strings this isn't
2142 different from using {expr} directly.
2143 When {expr} is a |List| a full copy is created. This means
2144 that the original |List| can be changed without changing the
2145 copy, and vice versa. When an item is a |List| or
2146 |Dictionary|, a copy for it is made, recursively. Thus
2147 changing an item in the copy does not change the contents of
2148 the original |List|.
2149 A |Dictionary| is copied in a similar way as a |List|.
2150
2151 When {noref} is omitted or zero a contained |List| or
2152 |Dictionary| is only copied once. All references point to
2153 this single copy. With {noref} set to 1 every occurrence of a
2154 |List| or |Dictionary| results in a new copy. This also means
2155 that a cyclic reference causes deepcopy() to fail.
2156 *E724*
2157 Nesting is possible up to 100 levels. When there is an item
2158 that refers back to a higher level making a deep copy with
2159 {noref} set to 1 will fail.
2160 Also see |copy()|.
2161
2162 Can also be used as a |method|: >
2163 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002164<
2165 Return type: any, depending on {expr}
2166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002167
2168delete({fname} [, {flags}]) *delete()*
2169 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002170 name {fname}.
2171
2172 This also works when {fname} is a symbolic link. The symbolic
2173 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002174
2175 When {flags} is "d": Deletes the directory by the name
2176 {fname}. This fails when directory {fname} is not empty.
2177
2178 When {flags} is "rf": Deletes the directory by the name
2179 {fname} and everything in it, recursively. BE CAREFUL!
2180 Note: on MS-Windows it is not possible to delete a directory
2181 that is being used.
2182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002183 The result is a Number, which is 0/false if the delete
2184 operation was successful and -1/true when the deletion failed
2185 or partly failed.
2186
2187 Use |remove()| to delete an item from a |List|.
2188 To delete a line from the buffer use |:delete| or
2189 |deletebufline()|.
2190
2191 Can also be used as a |method|: >
2192 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002193<
2194 Return type: |Number|
2195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002196
2197deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2198 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2199 If {last} is omitted then delete line {first} only.
2200 On success 0 is returned, on failure 1 is returned.
2201
2202 This function works only for loaded buffers. First call
2203 |bufload()| if needed.
2204
2205 For the use of {buf}, see |bufname()| above.
2206
2207 {first} and {last} are used like with |getline()|. Note that
2208 when using |line()| this refers to the current buffer. Use "$"
2209 to refer to the last line in buffer {buf}.
2210
2211 Can also be used as a |method|: >
2212 GetBuffer()->deletebufline(1)
2213<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002214 Return type: |Number|
2215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002216 *did_filetype()*
2217did_filetype() Returns |TRUE| when autocommands are being executed and the
2218 FileType event has been triggered at least once. Can be used
2219 to avoid triggering the FileType event again in the scripts
2220 that detect the file type. |FileType|
2221 Returns |FALSE| when `:setf FALLBACK` was used.
2222 When editing another file, the counter is reset, thus this
2223 really checks if the FileType event has been triggered for the
2224 current buffer. This allows an autocommand that starts
2225 editing another buffer to set 'filetype' and load a syntax
2226 file.
2227
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002228 Return type: |Number|
2229
2230
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002231diff({fromlist}, {tolist} [, {options}]) *diff()*
2232 Returns a String or a List containing the diff between the
2233 strings in {fromlist} and {tolist}. Uses the Vim internal
2234 diff library to compute the diff.
2235
2236 *E106*
2237 The optional "output" item in {options} specifies the returned
2238 diff format. The following values are supported:
2239 indices Return a List of the starting and ending
2240 indices and a count of the strings in each
2241 diff hunk.
2242 unified Return the unified diff output as a String.
2243 This is the default.
2244
2245 If the "output" item in {options} is "indices", then a List is
2246 returned. Each List item contains a Dict with the following
2247 items for each diff hunk:
2248 from_idx start index in {fromlist} for this diff hunk.
2249 from_count number of strings in {fromlist} that are
2250 added/removed/modified in this diff hunk.
2251 to_idx start index in {tolist} for this diff hunk.
2252 to_count number of strings in {tolist} that are
2253 added/removed/modified in this diff hunk.
2254
2255 The {options} Dict argument also specifies diff options
2256 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002257 algorithm Dict specifying the diff algorithm to
2258 use. Supported boolean items are
2259 "myers", "minimal", "patience" and
2260 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002261 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002262 iblank ignore changes where lines are all
2263 blank.
2264 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002265 indent-heuristic use the indent heuristic for the
2266 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002267 iwhite ignore changes in amount of white
2268 space.
2269 iwhiteall ignore all white space changes.
2270 iwhiteeol ignore white space changes at end of
2271 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002272 For more information about these options, refer to 'diffopt'.
2273
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002274 To compute the unified diff, all the items in {fromlist} are
2275 concatenated into a string using a newline separator and the
2276 same for {tolist}. The unified diff output uses line numbers.
2277
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002278 Returns an empty List or String if {fromlist} and {tolist} are
2279 identical.
2280
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002281 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002282 :echo diff(['abc'], ['xxx'])
2283 @@ -1 +1 @@
2284 -abc
2285 +xxx
2286
2287 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2288 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2289 :echo diff(readfile('oldfile'), readfile('newfile'))
2290 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002291<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002292 For more examples, refer to |diff-func-examples|
2293
2294 Can also be used as a |method|: >
2295 GetFromList->diff(to_list)
2296<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002297 Return type: |String| or list<dict<number>> or list<any>
2298 depending on {options}
2299
2300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002301diff_filler({lnum}) *diff_filler()*
2302 Returns the number of filler lines above line {lnum}.
2303 These are the lines that were inserted at this point in
2304 another diff'ed window. These filler lines are shown in the
2305 display but don't exist in the buffer.
2306 {lnum} is used like with |getline()|. Thus "." is the current
2307 line, "'m" mark m, etc.
2308 Returns 0 if the current window is not in diff mode.
2309
2310 Can also be used as a |method|: >
2311 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002312<
2313 Return type: |Number|
2314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002315
2316diff_hlID({lnum}, {col}) *diff_hlID()*
2317 Returns the highlight ID for diff mode at line {lnum} column
2318 {col} (byte index). When the current line does not have a
2319 diff change zero is returned.
2320 {lnum} is used like with |getline()|. Thus "." is the current
2321 line, "'m" mark m, etc.
2322 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2323 line.
2324 The highlight ID can be used with |synIDattr()| to obtain
2325 syntax information about the highlighting.
2326
2327 Can also be used as a |method|: >
2328 GetLnum()->diff_hlID(col)
2329<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002330 Return type: |Number|
2331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002332
2333digraph_get({chars}) *digraph_get()* *E1214*
2334 Return the digraph of {chars}. This should be a string with
2335 exactly two characters. If {chars} are not just two
2336 characters, or the digraph of {chars} does not exist, an error
2337 is given and an empty string is returned.
2338
2339 The character will be converted from Unicode to 'encoding'
2340 when needed. This does require the conversion to be
2341 available, it might fail.
2342
2343 Also see |digraph_getlist()|.
2344
2345 Examples: >
2346 " Get a built-in digraph
2347 :echo digraph_get('00') " Returns '∞'
2348
2349 " Get a user-defined digraph
2350 :call digraph_set('aa', 'あ')
2351 :echo digraph_get('aa') " Returns 'あ'
2352<
2353 Can also be used as a |method|: >
2354 GetChars()->digraph_get()
2355<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002356 Return type: |String|
2357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002358 This function works only when compiled with the |+digraphs|
2359 feature. If this feature is disabled, this function will
2360 display an error message.
2361
2362
2363digraph_getlist([{listall}]) *digraph_getlist()*
2364 Return a list of digraphs. If the {listall} argument is given
2365 and it is TRUE, return all digraphs, including the default
2366 digraphs. Otherwise, return only user-defined digraphs.
2367
2368 The characters will be converted from Unicode to 'encoding'
2369 when needed. This does require the conservation to be
2370 available, it might fail.
2371
2372 Also see |digraph_get()|.
2373
2374 Examples: >
2375 " Get user-defined digraphs
2376 :echo digraph_getlist()
2377
2378 " Get all the digraphs, including default digraphs
2379 :echo digraph_getlist(1)
2380<
2381 Can also be used as a |method|: >
2382 GetNumber()->digraph_getlist()
2383<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002384 Return type: list<list<string>>
2385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002386 This function works only when compiled with the |+digraphs|
2387 feature. If this feature is disabled, this function will
2388 display an error message.
2389
2390
Bram Moolenaara2baa732022-02-04 16:09:54 +00002391digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002392 Add digraph {chars} to the list. {chars} must be a string
2393 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002394 encoded character. *E1215*
2395 Be careful, composing characters are NOT ignored. This
2396 function is similar to |:digraphs| command, but useful to add
2397 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002399 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002400 this fails an error message is given and v:false is returned.
2401
2402 If you want to define multiple digraphs at once, you can use
2403 |digraph_setlist()|.
2404
2405 Example: >
2406 call digraph_set(' ', 'あ')
2407<
2408 Can be used as a |method|: >
2409 GetString()->digraph_set('あ')
2410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002411 Return type: |vim9-boolean|
2412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002413 This function works only when compiled with the |+digraphs|
2414 feature. If this feature is disabled, this function will
2415 display an error message.
2416
2417
2418digraph_setlist({digraphlist}) *digraph_setlist()*
2419 Similar to |digraph_set()| but this function can add multiple
2420 digraphs at once. {digraphlist} is a list composed of lists,
2421 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002422 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002423 Example: >
2424 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2425<
2426 It is similar to the following: >
2427 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2428 call digraph_set(chars, digraph)
2429 endfor
2430< Except that the function returns after the first error,
2431 following digraphs will not be added.
2432
2433 Can be used as a |method|: >
2434 GetList()->digraph_setlist()
2435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002436 Return type: |vim9-boolean|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438 This function works only when compiled with the |+digraphs|
2439 feature. If this feature is disabled, this function will
2440 display an error message.
2441
2442
2443echoraw({string}) *echoraw()*
2444 Output {string} as-is, including unprintable characters.
2445 This can be used to output a terminal code. For example, to
2446 disable modifyOtherKeys: >
2447 call echoraw(&t_TE)
2448< and to enable it again: >
2449 call echoraw(&t_TI)
2450< Use with care, you can mess up the terminal this way.
2451
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002452 Return type: |Number|
2453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002454
2455empty({expr}) *empty()*
2456 Return the Number 1 if {expr} is empty, zero otherwise.
2457 - A |List| or |Dictionary| is empty when it does not have any
2458 items.
2459 - A |String| is empty when its length is zero.
2460 - A |Number| and |Float| are empty when their value is zero.
2461 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2462 - A |Job| is empty when it failed to start.
2463 - A |Channel| is empty when it is closed.
2464 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002465 - An |Object| is empty, when the empty() method in the object
2466 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002467
2468 For a long |List| this is much faster than comparing the
2469 length with zero.
2470
2471 Can also be used as a |method|: >
2472 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002473<
2474 Return type: |Number|
2475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002476
2477environ() *environ()*
2478 Return all of environment variables as dictionary. You can
2479 check if an environment variable exists like this: >
2480 :echo has_key(environ(), 'HOME')
2481< Note that the variable name may be CamelCase; to ignore case
2482 use this: >
2483 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002484<
2485 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002486
Bram Moolenaar416bd912023-07-07 23:19:18 +01002487
2488err_teapot([{expr}]) *err_teapot()*
2489 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002490 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002491 If {expr} is present and it is TRUE error 503 is given,
2492 indicating that coffee is temporarily not available.
2493 If {expr} is present it must be a String.
2494
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002495 Return type: |Number|
2496
Bram Moolenaar416bd912023-07-07 23:19:18 +01002497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002498escape({string}, {chars}) *escape()*
2499 Escape the characters in {chars} that occur in {string} with a
2500 backslash. Example: >
2501 :echo escape('c:\program files\vim', ' \')
2502< results in: >
2503 c:\\program\ files\\vim
2504< Also see |shellescape()| and |fnameescape()|.
2505
2506 Can also be used as a |method|: >
2507 GetText()->escape(' \')
2508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002509 Return type: |String|
2510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002511 *eval()*
2512eval({string}) Evaluate {string} and return the result. Especially useful to
2513 turn the result of |string()| back into the original value.
2514 This works for Numbers, Floats, Strings, Blobs and composites
2515 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002516 functions. In |Vim9| script, it can be used to obtain |enum|
2517 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518
2519 Can also be used as a |method|: >
2520 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002521<
2522 Return type: any, depending on {string}
2523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002524
2525eventhandler() *eventhandler()*
2526 Returns 1 when inside an event handler. That is that Vim got
2527 interrupted while waiting for the user to type a character,
2528 e.g., when dropping a file on Vim. This means interactive
2529 commands cannot be used. Otherwise zero is returned.
2530
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002531 Return type: |Number|
2532
2533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002534executable({expr}) *executable()*
2535 This function checks if an executable with the name {expr}
2536 exists. {expr} must be the name of the program without any
2537 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002539 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002540 searchpath for programs.
2541 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002542 On MS-Windows the ".exe", ".bat", etc. can optionally be
2543 included. Then the extensions in $PATHEXT are tried. Thus if
2544 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2545 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2546 by itself can be used in $PATHEXT to try using the name
2547 without an extension. When 'shell' looks like a Unix shell,
2548 then the name is also tried without adding an extension.
2549 On MS-Windows it only checks if the file exists and is not a
2550 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002551 On MS-Windows an executable in the same directory as the Vim
2552 executable is always found. Since this directory is added to
2553 $PATH it should also work to execute it |win32-PATH|.
2554 *NoDefaultCurrentDirectoryInExePath*
2555 On MS-Windows an executable in Vim's current working directory
2556 is also normally found, but this can be disabled by setting
2557 the $NoDefaultCurrentDirectoryInExePath environment variable.
2558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559 The result is a Number:
2560 1 exists
2561 0 does not exist
2562 -1 not implemented on this system
2563 |exepath()| can be used to get the full path of an executable.
2564
2565 Can also be used as a |method|: >
2566 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002567<
2568 Return type: |Number|
2569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002570
2571execute({command} [, {silent}]) *execute()*
2572 Execute an Ex command or commands and return the output as a
2573 string.
2574 {command} can be a string or a List. In case of a List the
2575 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002576 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002577 redir => var
2578 {command}
2579 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002580< Except that line continuation in {command} is not recognized.
2581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582 The optional {silent} argument can have these values:
2583 "" no `:silent` used
2584 "silent" `:silent` used
2585 "silent!" `:silent!` used
2586 The default is "silent". Note that with "silent!", unlike
2587 `:redir`, error messages are dropped. When using an external
2588 command the screen may be messed up, use `system()` instead.
2589 *E930*
2590 It is not possible to use `:redir` anywhere in {command}.
2591
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002592 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002593 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002594
2595< To execute a command in another window than the current one
2596 use `win_execute()`.
2597
2598 When used recursively the output of the recursive call is not
2599 included in the output of the higher level call.
2600
2601 Can also be used as a |method|: >
2602 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002603<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002604 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002606
2607exepath({expr}) *exepath()*
2608 If {expr} is an executable and is either an absolute path, a
2609 relative path or found in $PATH, return the full path.
2610 Note that the current directory is used when {expr} starts
2611 with "./", which may be a problem for Vim: >
2612 echo exepath(v:progpath)
2613< If {expr} cannot be found in $PATH or is not executable then
2614 an empty string is returned.
2615
2616 Can also be used as a |method|: >
2617 GetCommand()->exepath()
2618<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002619 Return type: |String|
2620
2621
2622exists({expr}) *exists()*
2623 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002624 zero otherwise.
2625
2626 Note: In a compiled |:def| function the evaluation is done at
2627 runtime. Use `exists_compiled()` to evaluate the expression
2628 at compile time.
2629
2630 For checking for a supported feature use |has()|.
2631 For checking if a file exists use |filereadable()|.
2632
2633 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002634 varname internal variable (see
2635 dict.key |internal-variables|). Also works
2636 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002637 import.Func entries, |List| items, class and
2638 class.Func object methods, imported items, etc.
2639 object.Func Does not work for local variables in a
2640 class.varname compiled `:def` function.
2641 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002642 script, since it can be used as a
2643 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002644 Beware that evaluating an index may
2645 cause an error message for an invalid
2646 expression. E.g.: >
2647 :let l = [1, 2, 3]
2648 :echo exists("l[5]")
2649< 0 >
2650 :echo exists("l[xx]")
2651< E121: Undefined variable: xx
2652 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002653 &option-name Vim option (only checks if it exists,
2654 not if it really works)
2655 +option-name Vim option that works.
2656 $ENVNAME environment variable (could also be
2657 done by comparing with an empty
2658 string)
2659 *funcname built-in function (see |functions|)
2660 or user defined function (see
2661 |user-functions|) that is implemented.
2662 Also works for a variable that is a
2663 Funcref.
2664 ?funcname built-in function that could be
2665 implemented; to be used to check if
2666 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002667 :cmdname Ex command: built-in command, user
2668 command or command modifier |:command|.
2669 Returns:
2670 1 for match with start of a command
2671 2 full match with a command
2672 3 matches several user commands
2673 To check for a supported command
2674 always check the return value to be 2.
2675 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002676 :3match The |:3match| command (but you
2677 probably should not use it, it is
2678 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679 #event autocommand defined for this event
2680 #event#pattern autocommand defined for this event and
2681 pattern (the pattern is taken
2682 literally and compared to the
2683 autocommand patterns character by
2684 character)
2685 #group autocommand group exists
2686 #group#event autocommand defined for this group and
2687 event.
2688 #group#event#pattern
2689 autocommand defined for this group,
2690 event and pattern.
2691 ##event autocommand for this event is
2692 supported.
2693
2694 Examples: >
2695 exists("&shortname")
2696 exists("$HOSTNAME")
2697 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002698 exists("*s:MyFunc") " only for legacy script
2699 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002700 exists("bufcount")
2701 exists(":Make")
2702 exists("#CursorHold")
2703 exists("#BufReadPre#*.gz")
2704 exists("#filetypeindent")
2705 exists("#filetypeindent#FileType")
2706 exists("#filetypeindent#FileType#*")
2707 exists("##ColorScheme")
2708< There must be no space between the symbol (&/$/*/#) and the
2709 name.
2710 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002711 a few cases this is ignored. That may become stricter in the
2712 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002713 Working example: >
2714 exists(":make")
2715< NOT working example: >
2716 exists(":make install")
2717
2718< Note that the argument must be a string, not the name of the
2719 variable itself. For example: >
2720 exists(bufcount)
2721< This doesn't check for existence of the "bufcount" variable,
2722 but gets the value of "bufcount", and checks if that exists.
2723
2724 Can also be used as a |method|: >
2725 Varname()->exists()
2726<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002727 Return type: |String|
2728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002729
2730exists_compiled({expr}) *exists_compiled()*
2731 Like `exists()` but evaluated at compile time. This is useful
2732 to skip a block where a function is used that would otherwise
2733 give an error: >
2734 if exists_compiled('*ThatFunction')
2735 ThatFunction('works')
2736 endif
2737< If `exists()` were used then a compilation error would be
2738 given if ThatFunction() is not defined.
2739
2740 {expr} must be a literal string. *E1232*
2741 Can only be used in a |:def| function. *E1233*
2742 This does not work to check for arguments or local variables.
2743
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002744 Return type: |String|
2745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002746
2747exp({expr}) *exp()*
2748 Return the exponential of {expr} as a |Float| in the range
2749 [0, inf].
2750 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002751 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002752 Examples: >
2753 :echo exp(2)
2754< 7.389056 >
2755 :echo exp(-1)
2756< 0.367879
2757
2758 Can also be used as a |method|: >
2759 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002760<
2761 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002762
2763
2764expand({string} [, {nosuf} [, {list}]]) *expand()*
2765 Expand wildcards and the following special keywords in
2766 {string}. 'wildignorecase' applies.
2767
2768 If {list} is given and it is |TRUE|, a List will be returned.
2769 Otherwise the result is a String and when there are several
2770 matches, they are separated by <NL> characters. [Note: in
2771 version 5.0 a space was used, which caused problems when a
2772 file name contains a space]
2773
2774 If the expansion fails, the result is an empty string. A name
2775 for a non-existing file is not included, unless {string} does
2776 not start with '%', '#' or '<', see below.
2777
Christian Brabandtec9c3262024-02-21 20:40:05 +01002778 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002779 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002781 When {string} starts with '%', '#' or '<', the expansion is
2782 done like for the |cmdline-special| variables with their
2783 associated modifiers. Here is a short overview:
2784
2785 % current file name
2786 # alternate file name
2787 #n alternate file name n
2788 <cfile> file name under the cursor
2789 <afile> autocmd file name
2790 <abuf> autocmd buffer number (as a String!)
2791 <amatch> autocmd matched name
2792 <cexpr> C expression under the cursor
2793 <sfile> sourced script file or function name
2794 <slnum> sourced script line number or function
2795 line number
2796 <sflnum> script file line number, also when in
2797 a function
2798 <SID> "<SNR>123_" where "123" is the
2799 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002800 <script> sourced script file, or script file
2801 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002802 <stack> call stack
2803 <cword> word under the cursor
2804 <cWORD> WORD under the cursor
2805 <client> the {clientid} of the last received
2806 message |server2client()|
2807 Modifiers:
2808 :p expand to full path
2809 :h head (last path component removed)
2810 :t tail (last path component only)
2811 :r root (one extension removed)
2812 :e extension only
2813
2814 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002815 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002816< Note that when expanding a string that starts with '%', '#' or
2817 '<', any following text is ignored. This does NOT work: >
2818 :let doesntwork = expand("%:h.bak")
2819< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002820 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002821< Also note that expanding "<cfile>" and others only returns the
2822 referenced file name without further expansion. If "<cfile>"
2823 is "~/.cshrc", you need to do another expand() to have the
2824 "~/" expanded into the path of the home directory: >
2825 :echo expand(expand("<cfile>"))
2826<
2827 There cannot be white space between the variables and the
2828 following modifier. The |fnamemodify()| function can be used
2829 to modify normal file names.
2830
2831 When using '%' or '#', and the current or alternate file name
2832 is not defined, an empty string is used. Using "%:p" in a
2833 buffer with no name, results in the current directory, with a
2834 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002835 When 'verbose' is set then expanding '%', '#' and <> items
2836 will result in an error message if the argument cannot be
2837 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838
2839 When {string} does not start with '%', '#' or '<', it is
2840 expanded like a file name is expanded on the command line.
2841 'suffixes' and 'wildignore' are used, unless the optional
2842 {nosuf} argument is given and it is |TRUE|.
2843 Names for non-existing files are included. The "**" item can
2844 be used to search in a directory tree. For example, to find
2845 all "README" files in the current directory and below: >
2846 :echo expand("**/README")
2847<
2848 expand() can also be used to expand variables and environment
2849 variables that are only known in a shell. But this can be
2850 slow, because a shell may be used to do the expansion. See
2851 |expr-env-expand|.
2852 The expanded variable is still handled like a list of file
2853 names. When an environment variable cannot be expanded, it is
2854 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2855 "$FOOBAR".
2856
2857 See |glob()| for finding existing files. See |system()| for
2858 getting the raw output of an external command.
2859
2860 Can also be used as a |method|: >
2861 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002862<
2863 Return type: |String| or list<string> depending on {list}
2864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002865
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002866expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 Expand special items in String {string} like what is done for
2868 an Ex command such as `:edit`. This expands special keywords,
2869 like with |expand()|, and environment variables, anywhere in
2870 {string}. "~user" and "~/path" are only expanded at the
2871 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002872
2873 The following items are supported in the {options} Dict
2874 argument:
2875 errmsg If set to TRUE, error messages are displayed
2876 if an error is encountered during expansion.
2877 By default, error messages are not displayed.
2878
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002879 Returns the expanded string. If an error is encountered
2880 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002881
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002882 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002884 make /path/runtime/doc/builtin.o
2885 :echo expandcmd('make %<.o', {'errmsg': v:true})
2886<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002887 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002888 GetCommand()->expandcmd()
2889<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002890 Return type: |String| or list<string> depending on {list}
2891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002892extend({expr1}, {expr2} [, {expr3}]) *extend()*
2893 {expr1} and {expr2} must be both |Lists| or both
2894 |Dictionaries|.
2895
2896 If they are |Lists|: Append {expr2} to {expr1}.
2897 If {expr3} is given insert the items of {expr2} before the
2898 item with index {expr3} in {expr1}. When {expr3} is zero
2899 insert before the first item. When {expr3} is equal to
2900 len({expr1}) then {expr2} is appended.
2901 Examples: >
2902 :echo sort(extend(mylist, [7, 5]))
2903 :call extend(mylist, [2, 3], 1)
2904< When {expr1} is the same List as {expr2} then the number of
2905 items copied is equal to the original length of the List.
2906 E.g., when {expr3} is 1 you get N new copies of the first item
2907 (where N is the original length of the List).
2908 Use |add()| to concatenate one item to a list. To concatenate
2909 two lists into a new list use the + operator: >
2910 :let newlist = [1, 2, 3] + [4, 5]
2911<
2912 If they are |Dictionaries|:
2913 Add all entries from {expr2} to {expr1}.
2914 If a key exists in both {expr1} and {expr2} then {expr3} is
2915 used to decide what to do:
2916 {expr3} = "keep": keep the value of {expr1}
2917 {expr3} = "force": use the value of {expr2}
2918 {expr3} = "error": give an error message *E737*
2919 When {expr3} is omitted then "force" is assumed.
2920
2921 {expr1} is changed when {expr2} is not empty. If necessary
2922 make a copy of {expr1} first.
2923 {expr2} remains unchanged.
2924 When {expr1} is locked and {expr2} is not empty the operation
2925 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002926 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002927
2928 Can also be used as a |method|: >
2929 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002930<
2931 Return type: list<{type}> or dict<{type}> depending on {expr1}
2932 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002933
2934
2935extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2936 Like |extend()| but instead of adding items to {expr1} a new
2937 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002938 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002939
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002940 Return type: list<{type}> or dict<{type}> depending on {expr1}
2941 and {expr2}, in case of error: |Number|
2942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002943
2944feedkeys({string} [, {mode}]) *feedkeys()*
2945 Characters in {string} are queued for processing as if they
2946 come from a mapping or were typed by the user.
2947
2948 By default the string is added to the end of the typeahead
2949 buffer, thus if a mapping is still being executed the
2950 characters come after them. Use the 'i' flag to insert before
2951 other characters, they will be executed next, before any
2952 characters from a mapping.
2953
2954 The function does not wait for processing of keys contained in
2955 {string}.
2956
2957 To include special keys into {string}, use double-quotes
2958 and "\..." notation |expr-quote|. For example,
2959 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2960 feedkeys('\<CR>') pushes 5 characters.
2961 A special code that might be useful is <Ignore>, it exits the
2962 wait for a character without doing anything. *<Ignore>*
2963
2964 {mode} is a String, which can contain these character flags:
2965 'm' Remap keys. This is default. If {mode} is absent,
2966 keys are remapped.
2967 'n' Do not remap keys.
2968 't' Handle keys as if typed; otherwise they are handled as
2969 if coming from a mapping. This matters for undo,
2970 opening folds, etc.
2971 'L' Lowlevel input. Only works for Unix or when using the
2972 GUI. Keys are used as if they were coming from the
2973 terminal. Other flags are not used. *E980*
2974 When a CTRL-C interrupts and 't' is included it sets
2975 the internal "got_int" flag.
2976 'i' Insert the string instead of appending (see above).
2977 'x' Execute commands until typeahead is empty. This is
2978 similar to using ":normal!". You can call feedkeys()
2979 several times without 'x' and then one time with 'x'
2980 (possibly with an empty {string}) to execute all the
2981 typeahead. Note that when Vim ends in Insert mode it
2982 will behave as if <Esc> is typed, to avoid getting
2983 stuck, waiting for a character to be typed before the
2984 script continues.
2985 Note that if you manage to call feedkeys() while
2986 executing commands, thus calling it recursively, then
2987 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002988 'c' Remove any script context when executing, so that
2989 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002990 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002991 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002992 '!' When used with 'x' will not end Insert mode. Can be
2993 used in a test when a timer is set to exit Insert mode
2994 a little later. Useful for testing CursorHoldI.
2995
2996 Return value is always 0.
2997
2998 Can also be used as a |method|: >
2999 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003000<
3001 Return type: |String| or list<string> depending on {list}
3002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003003
Shougo Matsushita60c87432024-06-03 22:59:27 +02003004filecopy({from}, {to}) *filecopy()*
3005 Copy the file pointed to by the name {from} to {to}. The
3006 result is a Number, which is |TRUE| if the file was copied
3007 successfully, and |FALSE| when it failed.
3008 If a file with name {to} already exists, it will fail.
3009 Note that it does not handle directories (yet).
3010
3011 This function is not available in the |sandbox|.
3012
3013 Can also be used as a |method|: >
3014 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003015<
3016 Return type: |Number|
3017
Shougo Matsushita60c87432024-06-03 22:59:27 +02003018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003019filereadable({file}) *filereadable()*
3020 The result is a Number, which is |TRUE| when a file with the
3021 name {file} exists, and can be read. If {file} doesn't exist,
3022 or is a directory, the result is |FALSE|. {file} is any
3023 expression, which is used as a String.
3024 If you don't care about the file being readable you can use
3025 |glob()|.
3026 {file} is used as-is, you may want to expand wildcards first: >
3027 echo filereadable('~/.vimrc')
3028 0
3029 echo filereadable(expand('~/.vimrc'))
3030 1
3031
3032< Can also be used as a |method|: >
3033 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003034<
3035 Return type: |Number|
3036
3037 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038 Obsolete name: file_readable().
3039
3040
3041filewritable({file}) *filewritable()*
3042 The result is a Number, which is 1 when a file with the
3043 name {file} exists, and can be written. If {file} doesn't
3044 exist, or is not writable, the result is 0. If {file} is a
3045 directory, and we can write to it, the result is 2.
3046
3047 Can also be used as a |method|: >
3048 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003049<
3050 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051
3052
3053filter({expr1}, {expr2}) *filter()*
3054 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3055 For each item in {expr1} evaluate {expr2} and when the result
3056 is zero or false remove the item from the |List| or
3057 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003058 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003059
3060 {expr2} must be a |string| or |Funcref|.
3061
3062 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3063 of the current item. For a |Dictionary| |v:key| has the key
3064 of the current item and for a |List| |v:key| has the index of
3065 the current item. For a |Blob| |v:key| has the index of the
3066 current byte. For a |String| |v:key| has the index of the
3067 current character.
3068 Examples: >
3069 call filter(mylist, 'v:val !~ "OLD"')
3070< Removes the items where "OLD" appears. >
3071 call filter(mydict, 'v:key >= 8')
3072< Removes the items with a key below 8. >
3073 call filter(var, 0)
3074< Removes all the items, thus clears the |List| or |Dictionary|.
3075
3076 Note that {expr2} is the result of expression and is then
3077 used as an expression again. Often it is good to use a
3078 |literal-string| to avoid having to double backslashes.
3079
3080 If {expr2} is a |Funcref| it must take two arguments:
3081 1. the key or the index of the current item.
3082 2. the value of the current item.
3083 The function must return |TRUE| if the item should be kept.
3084 Example that keeps the odd items of a list: >
3085 func Odd(idx, val)
3086 return a:idx % 2 == 1
3087 endfunc
3088 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003089< It is shorter when using a |lambda|. In |Vim9| syntax: >
3090 call filter(myList, (idx, val) => idx * val <= 42)
3091< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003092 call filter(myList, {idx, val -> idx * val <= 42})
3093< If you do not use "val" you can leave it out: >
3094 call filter(myList, {idx -> idx % 2 == 1})
3095<
3096 In |Vim9| script the result must be true, false, zero or one.
3097 Other values will result in a type error.
3098
3099 For a |List| and a |Dictionary| the operation is done
3100 in-place. If you want it to remain unmodified make a copy
3101 first: >
3102 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3103
3104< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003105 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003106 When an error is encountered while evaluating {expr2} no
3107 further items in {expr1} are processed.
3108 When {expr2} is a Funcref errors inside a function are ignored,
3109 unless it was defined with the "abort" flag.
3110
3111 Can also be used as a |method|: >
3112 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003113<
3114 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3115 depending on {expr1}
3116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003117
3118finddir({name} [, {path} [, {count}]]) *finddir()*
3119 Find directory {name} in {path}. Supports both downwards and
3120 upwards recursive directory searches. See |file-searching|
3121 for the syntax of {path}.
3122
3123 Returns the path of the first found match. When the found
3124 directory is below the current directory a relative path is
3125 returned. Otherwise a full path is returned.
3126 If {path} is omitted or empty then 'path' is used.
3127
3128 If the optional {count} is given, find {count}'s occurrence of
3129 {name} in {path} instead of the first one.
3130 When {count} is negative return all the matches in a |List|.
3131
Bram Moolenaar016188f2022-06-06 20:52:59 +01003132 Returns an empty string if the directory is not found.
3133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003134 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003135
3136 Can also be used as a |method|: >
3137 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003138<
3139 Return type: |String|
3140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003141
3142findfile({name} [, {path} [, {count}]]) *findfile()*
3143 Just like |finddir()|, but find a file instead of a directory.
3144 Uses 'suffixesadd'.
3145 Example: >
3146 :echo findfile("tags.vim", ".;")
3147< Searches from the directory of the current file upwards until
3148 it finds the file "tags.vim".
3149
3150 Can also be used as a |method|: >
3151 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003152<
3153 Return type: |String|
3154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003155
3156flatten({list} [, {maxdepth}]) *flatten()*
3157 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3158 the result is a |List| without nesting, as if {maxdepth} is
3159 a very large number.
3160 The {list} is changed in place, use |flattennew()| if you do
3161 not want that.
3162 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003163 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003164 *E900*
3165 {maxdepth} means how deep in nested lists changes are made.
3166 {list} is not modified when {maxdepth} is 0.
3167 {maxdepth} must be positive number.
3168
3169 If there is an error the number zero is returned.
3170
3171 Example: >
3172 :echo flatten([1, [2, [3, 4]], 5])
3173< [1, 2, 3, 4, 5] >
3174 :echo flatten([1, [2, [3, 4]], 5], 1)
3175< [1, 2, [3, 4], 5]
3176
3177 Can also be used as a |method|: >
3178 mylist->flatten()
3179<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003180 Return type: list<{type}>
3181
3182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183flattennew({list} [, {maxdepth}]) *flattennew()*
3184 Like |flatten()| but first make a copy of {list}.
3185
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003186 Return type: list<{type}>
3187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003188
3189float2nr({expr}) *float2nr()*
3190 Convert {expr} to a Number by omitting the part after the
3191 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003192 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003193 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003194 When the value of {expr} is out of range for a |Number| the
3195 result is truncated to 0x7fffffff or -0x7fffffff (or when
3196 64-bit Number support is enabled, 0x7fffffffffffffff or
3197 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3198 64-bit Number support is enabled, -0x8000000000000000).
3199 Examples: >
3200 echo float2nr(3.95)
3201< 3 >
3202 echo float2nr(-23.45)
3203< -23 >
3204 echo float2nr(1.0e100)
3205< 2147483647 (or 9223372036854775807) >
3206 echo float2nr(-1.0e150)
3207< -2147483647 (or -9223372036854775807) >
3208 echo float2nr(1.0e-100)
3209< 0
3210
3211 Can also be used as a |method|: >
3212 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003213<
3214 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003215
3216
3217floor({expr}) *floor()*
3218 Return the largest integral value less than or equal to
3219 {expr} as a |Float| (round down).
3220 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003221 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222 Examples: >
3223 echo floor(1.856)
3224< 1.0 >
3225 echo floor(-5.456)
3226< -6.0 >
3227 echo floor(4.0)
3228< 4.0
3229
3230 Can also be used as a |method|: >
3231 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003232<
3233 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235
3236fmod({expr1}, {expr2}) *fmod()*
3237 Return the remainder of {expr1} / {expr2}, even if the
3238 division is not representable. Returns {expr1} - i * {expr2}
3239 for some integer i such that if {expr2} is non-zero, the
3240 result has the same sign as {expr1} and magnitude less than
3241 the magnitude of {expr2}. If {expr2} is zero, the value
3242 returned is zero. The value returned is a |Float|.
3243 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003244 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3245 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003246 Examples: >
3247 :echo fmod(12.33, 1.22)
3248< 0.13 >
3249 :echo fmod(-12.33, 1.22)
3250< -0.13
3251
3252 Can also be used as a |method|: >
3253 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003254<
3255 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003256
3257
3258fnameescape({string}) *fnameescape()*
3259 Escape {string} for use as file name command argument. All
3260 characters that have a special meaning, such as '%' and '|'
3261 are escaped with a backslash.
3262 For most systems the characters escaped are
3263 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3264 appears in a filename, it depends on the value of 'isfname'.
3265 A leading '+' and '>' is also escaped (special after |:edit|
3266 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003267 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268 Example: >
3269 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003270 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003271< results in executing: >
3272 edit \+some\ str\%nge\|name
3273<
3274 Can also be used as a |method|: >
3275 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003276<
3277 Return type: |String|
3278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003279
3280fnamemodify({fname}, {mods}) *fnamemodify()*
3281 Modify file name {fname} according to {mods}. {mods} is a
3282 string of characters like it is used for file names on the
3283 command line. See |filename-modifiers|.
3284 Example: >
3285 :echo fnamemodify("main.c", ":p:h")
3286< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003287 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003288< If {mods} is empty or an unsupported modifier is used then
3289 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003290 When {fname} is empty then with {mods} ":h" returns ".", so
3291 that `:cd` can be used with it. This is different from
3292 expand('%:h') without a buffer name, which returns an empty
3293 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003294 Note: Environment variables don't work in {fname}, use
3295 |expand()| first then.
3296
3297 Can also be used as a |method|: >
3298 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003299<
3300 Return type: |String|
3301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302
3303foldclosed({lnum}) *foldclosed()*
3304 The result is a Number. If the line {lnum} is in a closed
3305 fold, the result is the number of the first line in that fold.
3306 If the line {lnum} is not in a closed fold, -1 is returned.
3307 {lnum} is used like with |getline()|. Thus "." is the current
3308 line, "'m" mark m, etc.
3309
3310 Can also be used as a |method|: >
3311 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003312<
3313 Return type: |Number|
3314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003315
3316foldclosedend({lnum}) *foldclosedend()*
3317 The result is a Number. If the line {lnum} is in a closed
3318 fold, the result is the number of the last line in that fold.
3319 If the line {lnum} is not in a closed fold, -1 is returned.
3320 {lnum} is used like with |getline()|. Thus "." is the current
3321 line, "'m" mark m, etc.
3322
3323 Can also be used as a |method|: >
3324 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003325<
3326 Return type: |Number|
3327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003328
3329foldlevel({lnum}) *foldlevel()*
3330 The result is a Number, which is the foldlevel of line {lnum}
3331 in the current buffer. For nested folds the deepest level is
3332 returned. If there is no fold at line {lnum}, zero is
3333 returned. It doesn't matter if the folds are open or closed.
3334 When used while updating folds (from 'foldexpr') -1 is
3335 returned for lines where folds are still to be updated and the
3336 foldlevel is unknown. As a special case the level of the
3337 previous line is usually available.
3338 {lnum} is used like with |getline()|. Thus "." is the current
3339 line, "'m" mark m, etc.
3340
3341 Can also be used as a |method|: >
3342 GetLnum()->foldlevel()
3343<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003344 Return type: |Number|
3345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003346 *foldtext()*
3347foldtext() Returns a String, to be displayed for a closed fold. This is
3348 the default function used for the 'foldtext' option and should
3349 only be called from evaluating 'foldtext'. It uses the
3350 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3351 The returned string looks like this: >
3352 +-- 45 lines: abcdef
3353< The number of leading dashes depends on the foldlevel. The
3354 "45" is the number of lines in the fold. "abcdef" is the text
3355 in the first non-blank line of the fold. Leading white space,
3356 "//" or "/*" and the text from the 'foldmarker' and
3357 'commentstring' options is removed.
3358 When used to draw the actual foldtext, the rest of the line
3359 will be filled with the fold char from the 'fillchars'
3360 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003361 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003362
3363 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003364 {not available when compiled without the |+folding| feature}
3365
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003367foldtextresult({lnum}) *foldtextresult()*
3368 Returns the text that is displayed for the closed fold at line
3369 {lnum}. Evaluates 'foldtext' in the appropriate context.
3370 When there is no closed fold at {lnum} an empty string is
3371 returned.
3372 {lnum} is used like with |getline()|. Thus "." is the current
3373 line, "'m" mark m, etc.
3374 Useful when exporting folded text, e.g., to HTML.
3375 {not available when compiled without the |+folding| feature}
3376
3377
3378 Can also be used as a |method|: >
3379 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003380<
3381 Return type: |String|
3382
Ernie Raele79e2072024-01-13 11:47:33 +01003383
3384foreach({expr1}, {expr2}) *foreach()*
3385 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3386 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003387 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003388 See |map()| and |filter()| to modify {expr1}.
3389
3390 {expr2} must be a |string| or |Funcref|.
3391
3392 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3393 of the current item. For a |Dictionary| |v:key| has the key
3394 of the current item and for a |List| |v:key| has the index of
3395 the current item. For a |Blob| |v:key| has the index of the
3396 current byte. For a |String| |v:key| has the index of the
3397 current character.
3398 Examples: >
3399 call foreach(mylist, 'used[v:val] = true')
3400< This records the items that are in the {expr1} list.
3401
3402 Note that {expr2} is the result of expression and is then used
3403 as a command. Often it is good to use a |literal-string| to
3404 avoid having to double backslashes.
3405
3406 If {expr2} is a |Funcref| it must take two arguments:
3407 1. the key or the index of the current item.
3408 2. the value of the current item.
3409 With a legacy script lambda you don't get an error if it only
3410 accepts one argument, but with a Vim9 lambda you get "E1106:
3411 One argument too many", the number of arguments must match.
3412 If the function returns a value, it is ignored.
3413
3414 Returns {expr1} in all cases.
3415 When an error is encountered while executing {expr2} no
3416 further items in {expr1} are processed.
3417 When {expr2} is a Funcref errors inside a function are ignored,
3418 unless it was defined with the "abort" flag.
3419
3420 Can also be used as a |method|: >
3421 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003422<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003423 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3424 depending on {expr1}
3425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003426 *foreground()*
3427foreground() Move the Vim window to the foreground. Useful when sent from
3428 a client to a Vim server. |remote_send()|
3429 On Win32 systems this might not work, the OS does not always
3430 allow a window to bring itself to the foreground. Use
3431 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003432
3433 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003434 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003435 Win32 console version}
3436
Bram Moolenaaraa534142022-09-15 21:46:02 +01003437fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003438 Get the full command name from a short abbreviated command
3439 name; see |20.2| for details on command abbreviations.
3440
3441 The string argument {name} may start with a `:` and can
3442 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003443 Returns an empty string if a command doesn't exist, if it's
3444 ambiguous (for user-defined commands) or cannot be shortened
3445 this way. |vim9-no-shorten|
3446
3447 Without the {vim9} argument uses the current script version.
3448 If {vim9} is present and FALSE then legacy script rules are
3449 used. When {vim9} is present and TRUE then Vim9 rules are
3450 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451
3452 For example `fullcommand('s')`, `fullcommand('sub')`,
3453 `fullcommand(':%substitute')` all return "substitute".
3454
3455 Can also be used as a |method|: >
3456 GetName()->fullcommand()
3457<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003458 Return type: |String|
3459
3460
3461funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003462 Just like |function()|, but the returned Funcref will lookup
3463 the function by reference, not by name. This matters when the
3464 function {name} is redefined later.
3465
3466 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003467 It only works for an autoloaded function if it has already
3468 been loaded (to avoid mistakenly loading the autoload script
3469 when only intending to use the function name, use |function()|
3470 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003471 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003472
3473 Can also be used as a |method|: >
3474 GetFuncname()->funcref([arg])
3475<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003476 Return type: func(...): any or |Number| on error
3477
Dominique Pellee764d1b2023-03-12 21:20:59 +00003478 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003479function({name} [, {arglist}] [, {dict}])
3480 Return a |Funcref| variable that refers to function {name}.
3481 {name} can be the name of a user defined function or an
3482 internal function.
3483
3484 {name} can also be a Funcref or a partial. When it is a
3485 partial the dict stored in it will be used and the {dict}
3486 argument is not allowed. E.g.: >
3487 let FuncWithArg = function(dict.Func, [arg])
3488 let Broken = function(dict.Func, [arg], dict)
3489<
3490 When using the Funcref the function will be found by {name},
3491 also when it was redefined later. Use |funcref()| to keep the
3492 same function.
3493
3494 When {arglist} or {dict} is present this creates a partial.
3495 That means the argument list and/or the dictionary is stored in
3496 the Funcref and will be used when the Funcref is called.
3497
3498 The arguments are passed to the function in front of other
3499 arguments, but after any argument from |method|. Example: >
3500 func Callback(arg1, arg2, name)
3501 ...
3502 let Partial = function('Callback', ['one', 'two'])
3503 ...
3504 call Partial('name')
3505< Invokes the function as with: >
3506 call Callback('one', 'two', 'name')
3507
3508< With a |method|: >
3509 func Callback(one, two, three)
3510 ...
3511 let Partial = function('Callback', ['two'])
3512 ...
3513 eval 'one'->Partial('three')
3514< Invokes the function as with: >
3515 call Callback('one', 'two', 'three')
3516
3517< The function() call can be nested to add more arguments to the
3518 Funcref. The extra arguments are appended to the list of
3519 arguments. Example: >
3520 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003521 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522 let Func = function('Callback', ['one'])
3523 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003524 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003525 call Func2('name')
3526< Invokes the function as with: >
3527 call Callback('one', 'two', 'name')
3528
3529< The Dictionary is only useful when calling a "dict" function.
3530 In that case the {dict} is passed in as "self". Example: >
3531 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003532 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003533 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003534 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 let context = {"name": "example"}
3536 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003537 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 call Func() " will echo: called for example
3539< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003540 arguments, these two are equivalent, if Callback() is defined
3541 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003542 let Func = function('Callback', context)
3543 let Func = context.Callback
3544
3545< The argument list and the Dictionary can be combined: >
3546 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003547 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003548 let context = {"name": "example"}
3549 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003550 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003551 call Func(500)
3552< Invokes the function as with: >
3553 call context.Callback('one', 500)
3554<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003555 Returns 0 on error.
3556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003557 Can also be used as a |method|: >
3558 GetFuncname()->function([arg])
3559
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003560<
3561 Return type: func(...): any or |Number| on error
3562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003563
3564garbagecollect([{atexit}]) *garbagecollect()*
3565 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3566 that have circular references.
3567
3568 There is hardly ever a need to invoke this function, as it is
3569 automatically done when Vim runs out of memory or is waiting
3570 for the user to press a key after 'updatetime'. Items without
3571 circular references are always freed when they become unused.
3572 This is useful if you have deleted a very big |List| and/or
3573 |Dictionary| with circular references in a script that runs
3574 for a long time.
3575
3576 When the optional {atexit} argument is one, garbage
3577 collection will also be done when exiting Vim, if it wasn't
3578 done before. This is useful when checking for memory leaks.
3579
3580 The garbage collection is not done immediately but only when
3581 it's safe to perform. This is when waiting for the user to
3582 type a character. To force garbage collection immediately use
3583 |test_garbagecollect_now()|.
3584
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003585 Return type: |String|
3586
3587
LemonBoy48b7d052024-07-09 18:24:59 +02003588get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003589 Get item {idx} from |List| {list}. When this item is not
3590 available return {default}. Return zero when {default} is
3591 omitted.
3592 Preferably used as a |method|: >
3593 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003594<
3595 Return type: any, depending on {list}
3596
LemonBoy48b7d052024-07-09 18:24:59 +02003597get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003598 Get byte {idx} from |Blob| {blob}. When this byte is not
3599 available return {default}. Return -1 when {default} is
3600 omitted.
3601 Preferably used as a |method|: >
3602 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003603<
3604 Return type: |Number|
3605
LemonBoy48b7d052024-07-09 18:24:59 +02003606get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 Get item with key {key} from |Dictionary| {dict}. When this
3608 item is not available return {default}. Return zero when
3609 {default} is omitted. Useful example: >
3610 let val = get(g:, 'var_name', 'default')
3611< This gets the value of g:var_name if it exists, and uses
3612 'default' when it does not exist.
3613 Preferably used as a |method|: >
3614 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003615<
h-east84ac2122024-06-17 18:12:30 +02003616 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003617
LemonBoy48b7d052024-07-09 18:24:59 +02003618get({func}, {what}) *get()-func*
3619 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003620 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003621 "name" The function name
3622 "func" The function
3623 "dict" The dictionary
3624 "args" The list with arguments
3625 "arity" A dictionary with information about the number of
3626 arguments accepted by the function (minus the
3627 {arglist}) with the following fields:
3628 required the number of positional arguments
3629 optional the number of optional arguments,
3630 in addition to the required ones
3631 varargs |TRUE| if the function accepts a
3632 variable number of arguments |...|
3633
3634 Note: There is no error, if the {arglist} of
3635 the Funcref contains more arguments than the
3636 Funcref expects, it's not validated.
3637
Bram Moolenaar016188f2022-06-06 20:52:59 +01003638 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003640 Preferably used as a |method|: >
3641 myfunc->get(what)
3642<
LemonBoy48b7d052024-07-09 18:24:59 +02003643 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003645 *getbufinfo()*
3646getbufinfo([{buf}])
3647getbufinfo([{dict}])
3648 Get information about buffers as a List of Dictionaries.
3649
3650 Without an argument information about all the buffers is
3651 returned.
3652
3653 When the argument is a |Dictionary| only the buffers matching
3654 the specified criteria are returned. The following keys can
3655 be specified in {dict}:
3656 buflisted include only listed buffers.
3657 bufloaded include only loaded buffers.
3658 bufmodified include only modified buffers.
3659
3660 Otherwise, {buf} specifies a particular buffer to return
3661 information for. For the use of {buf}, see |bufname()|
3662 above. If the buffer is found the returned List has one item.
3663 Otherwise the result is an empty list.
3664
3665 Each returned List item is a dictionary with the following
3666 entries:
3667 bufnr Buffer number.
3668 changed TRUE if the buffer is modified.
3669 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003670 command TRUE if the buffer belongs to the
3671 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003672 hidden TRUE if the buffer is hidden.
3673 lastused Timestamp in seconds, like
3674 |localtime()|, when the buffer was
3675 last used.
3676 {only with the |+viminfo| feature}
3677 listed TRUE if the buffer is listed.
3678 lnum Line number used for the buffer when
3679 opened in the current window.
3680 Only valid if the buffer has been
3681 displayed in the window in the past.
3682 If you want the line number of the
3683 last known cursor position in a given
3684 window, use |line()|: >
3685 :echo line('.', {winid})
3686<
3687 linecount Number of lines in the buffer (only
3688 valid when loaded)
3689 loaded TRUE if the buffer is loaded.
3690 name Full path to the file in the buffer.
3691 signs List of signs placed in the buffer.
3692 Each list item is a dictionary with
3693 the following fields:
3694 id sign identifier
3695 lnum line number
3696 name sign name
3697 variables A reference to the dictionary with
3698 buffer-local variables.
3699 windows List of |window-ID|s that display this
3700 buffer
3701 popups List of popup |window-ID|s that
3702 display this buffer
3703
3704 Examples: >
3705 for buf in getbufinfo()
3706 echo buf.name
3707 endfor
3708 for buf in getbufinfo({'buflisted':1})
3709 if buf.changed
3710 ....
3711 endif
3712 endfor
3713<
3714 To get buffer-local options use: >
3715 getbufvar({bufnr}, '&option_name')
3716<
3717 Can also be used as a |method|: >
3718 GetBufnr()->getbufinfo()
3719<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003720 Return type: list<dict<any>>
3721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722
3723 *getbufline()*
3724getbufline({buf}, {lnum} [, {end}])
3725 Return a |List| with the lines starting from {lnum} to {end}
3726 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003727 |List| with only the line {lnum} is returned. See
3728 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003729
3730 For the use of {buf}, see |bufname()| above.
3731
3732 For {lnum} and {end} "$" can be used for the last line of the
3733 buffer. Otherwise a number must be used.
3734
3735 When {lnum} is smaller than 1 or bigger than the number of
3736 lines in the buffer, an empty |List| is returned.
3737
3738 When {end} is greater than the number of lines in the buffer,
3739 it is treated as {end} is set to the number of lines in the
3740 buffer. When {end} is before {lnum} an empty |List| is
3741 returned.
3742
3743 This function works only for loaded buffers. For unloaded and
3744 non-existing buffers, an empty |List| is returned.
3745
3746 Example: >
3747 :let lines = getbufline(bufnr("myfile"), 1, "$")
3748
3749< Can also be used as a |method|: >
3750 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003751<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003752 Return type: list<string>
3753
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003754 *getbufoneline()*
3755getbufoneline({buf}, {lnum})
3756 Just like `getbufline()` but only get one line and return it
3757 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003758
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003759 Return type: |String|
3760
3761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003762getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3763 The result is the value of option or local buffer variable
3764 {varname} in buffer {buf}. Note that the name without "b:"
3765 must be used.
3766 The {varname} argument is a string.
3767 When {varname} is empty returns a |Dictionary| with all the
3768 buffer-local variables.
3769 When {varname} is equal to "&" returns a |Dictionary| with all
3770 the buffer-local options.
3771 Otherwise, when {varname} starts with "&" returns the value of
3772 a buffer-local option.
3773 This also works for a global or buffer-local option, but it
3774 doesn't work for a global variable, window-local variable or
3775 window-local option.
3776 For the use of {buf}, see |bufname()| above.
3777 When the buffer or variable doesn't exist {def} or an empty
3778 string is returned, there is no error message.
3779 Examples: >
3780 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003781 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003782
3783< Can also be used as a |method|: >
3784 GetBufnr()->getbufvar(varname)
3785<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003786 Return type: any, depending on {varname}
3787
3788
Kota Kato66bb9ae2023-01-17 18:31:56 +00003789getcellwidths() *getcellwidths()*
3790 Returns a |List| of cell widths of character ranges overridden
3791 by |setcellwidths()|. The format is equal to the argument of
3792 |setcellwidths()|. If no character ranges have their cell
3793 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003794
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003795 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003796
3797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003798getchangelist([{buf}]) *getchangelist()*
3799 Returns the |changelist| for the buffer {buf}. For the use
3800 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3801 exist, an empty list is returned.
3802
3803 The returned list contains two entries: a list with the change
3804 locations and the current position in the list. Each
3805 entry in the change list is a dictionary with the following
3806 entries:
3807 col column number
3808 coladd column offset for 'virtualedit'
3809 lnum line number
3810 If buffer {buf} is the current buffer, then the current
3811 position refers to the position in the list. For other
3812 buffers, it is set to the length of the list.
3813
3814 Can also be used as a |method|: >
3815 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003816<
3817 Return type: list<any>
3818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003819
Doug Kearns9cd9e752024-04-07 17:42:17 +02003820getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003821 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003822 If {expr} is omitted, wait until a character is available.
3823 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003824 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003825 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003826 not consumed. Return zero if no character available.
3827 If you prefer always getting a string use |getcharstr()|.
3828
Doug Kearns9cd9e752024-04-07 17:42:17 +02003829 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003830 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003831 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003832 Otherwise a String is returned with the encoded character.
3833 For a special key it's a String with a sequence of bytes
3834 starting with 0x80 (decimal: 128). This is the same value as
3835 the String "\<Key>", e.g., "\<Left>". The returned value is
3836 also a String when a modifier (shift, control, alt) was used
3837 that is not included in the character.
3838
Doug Kearns9cd9e752024-04-07 17:42:17 +02003839 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003840 while Vim waits to see if this is the start of an escape
3841 sequence.
3842
Doug Kearns9cd9e752024-04-07 17:42:17 +02003843 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003844 one-byte character it is the character itself as a number.
3845 Use nr2char() to convert it to a String.
3846
3847 Use getcharmod() to obtain any additional modifiers.
3848
3849 When the user clicks a mouse button, the mouse event will be
3850 returned. The position can then be found in |v:mouse_col|,
3851 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3852 |getmousepos()| can also be used. Mouse move events will be
3853 ignored.
3854 This example positions the mouse as it would normally happen: >
3855 let c = getchar()
3856 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003857 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003858 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003859 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003860 endif
3861<
3862 When using bracketed paste only the first character is
3863 returned, the rest of the pasted text is dropped.
3864 |xterm-bracketed-paste|.
3865
3866 There is no prompt, you will somehow have to make clear to the
3867 user that a character has to be typed. The screen is not
3868 redrawn, e.g. when resizing the window. When using a popup
3869 window it should work better with a |popup-filter|.
3870
3871 There is no mapping for the character.
3872 Key codes are replaced, thus when the user presses the <Del>
3873 key you get the code for the <Del> key, not the raw character
3874 sequence. Examples: >
3875 getchar() == "\<Del>"
3876 getchar() == "\<S-Left>"
3877< This example redefines "f" to ignore case: >
3878 :nmap f :call FindChar()<CR>
3879 :function FindChar()
3880 : let c = nr2char(getchar())
3881 : while col('.') < col('$') - 1
3882 : normal l
3883 : if getline('.')[col('.') - 1] ==? c
3884 : break
3885 : endif
3886 : endwhile
3887 :endfunction
3888<
3889 You may also receive synthetic characters, such as
3890 |<CursorHold>|. Often you will want to ignore this and get
3891 another character: >
3892 :function GetKey()
3893 : let c = getchar()
3894 : while c == "\<CursorHold>"
3895 : let c = getchar()
3896 : endwhile
3897 : return c
3898 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003899<
3900 Return type: |Number| or |String|
3901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003902
3903getcharmod() *getcharmod()*
3904 The result is a Number which is the state of the modifiers for
3905 the last obtained character with getchar() or in another way.
3906 These values are added together:
3907 2 shift
3908 4 control
3909 8 alt (meta)
3910 16 meta (when it's different from ALT)
3911 32 mouse double click
3912 64 mouse triple click
3913 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003914 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003915 Only the modifiers that have not been included in the
3916 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003917 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003919 Return type: |Number|
3920
3921
3922getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003923 Get the position for String {expr}. Same as |getpos()| but the
3924 column number in the returned List is a character index
3925 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003926 If |getpos()| returns a very large column number, equal to
3927 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928 of the last character.
3929
3930 Example:
3931 With the cursor on '세' in line 5 with text "여보세요": >
3932 getcharpos('.') returns [0, 5, 3, 0]
3933 getpos('.') returns [0, 5, 7, 0]
3934<
3935 Can also be used as a |method|: >
3936 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003937<
3938 Return type: list<number>
3939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940
3941getcharsearch() *getcharsearch()*
3942 Return the current character search information as a {dict}
3943 with the following entries:
3944
3945 char character previously used for a character
3946 search (|t|, |f|, |T|, or |F|); empty string
3947 if no character search has been performed
3948 forward direction of character search; 1 for forward,
3949 0 for backward
3950 until type of character search; 1 for a |t| or |T|
3951 character search, 0 for an |f| or |F|
3952 character search
3953
3954 This can be useful to always have |;| and |,| search
3955 forward/backward regardless of the direction of the previous
3956 character search: >
3957 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3958 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3959< Also see |setcharsearch()|.
3960
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003961 Return type: dict<any>
3962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003963
Doug Kearns9cd9e752024-04-07 17:42:17 +02003964getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003965 Get a single character from the user or input stream as a
3966 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003967 If {expr} is omitted, wait until a character is available.
3968 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003970 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003971 available, it is not consumed. Return an empty string
3972 if no character is available.
3973 Otherwise this works like |getchar()|, except that a number
3974 result is converted to a string.
3975
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003976 Return type: |String|
3977
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003978getcmdcomplpat() *getcmdcomplpat()*
3979 Return completion pattern of the current command-line.
3980 Only works when the command line is being edited, thus
3981 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3982 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3983 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
3984 Returns an empty string when completion is not defined.
3985
3986 Return type: |String|
3987
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003988
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003989getcmdcompltype() *getcmdcompltype()*
3990 Return the type of the current command-line completion.
3991 Only works when the command line is being edited, thus
3992 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003993 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02003994 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003995 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003996 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003997
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003998 Return type: |String|
3999
4000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004001getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004002 Return the current command-line input. Only works when the
4003 command line is being edited, thus requires use of
4004 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004005 Example: >
4006 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004007< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4008 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004009 Returns an empty string when entering a password or using
4010 |inputsecret()|.
4011
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004012 Return type: |String|
4013
4014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004015getcmdpos() *getcmdpos()*
4016 Return the position of the cursor in the command line as a
4017 byte count. The first column is 1.
4018 Only works when editing the command line, thus requires use of
4019 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4020 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004021 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4022 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004024 Return type: |Number|
4025
4026
Shougo Matsushita69084282024-09-23 20:34:47 +02004027getcmdprompt() *getcmdprompt()*
4028 Return the current command-line prompt when using functions
4029 like |input()| or |confirm()|.
4030 Only works when the command line is being edited, thus
4031 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4032 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4033 |setcmdpos()| and |setcmdline()|.
4034
4035 Return type: |String|
4036
4037
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004038getcmdscreenpos() *getcmdscreenpos()*
4039 Return the screen position of the cursor in the command line
4040 as a byte count. The first column is 1.
4041 Instead of |getcmdpos()|, it adds the prompt position.
4042 Only works when editing the command line, thus requires use of
4043 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4044 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004045 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4046 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004047
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004048 Return type: |Number|
4049
4050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051getcmdtype() *getcmdtype()*
4052 Return the current command-line type. Possible return values
4053 are:
4054 : normal Ex command
4055 > debug mode command |debug-mode|
4056 / forward search command
4057 ? backward search command
4058 @ |input()| command
4059 - |:insert| or |:append| command
4060 = |i_CTRL-R_=|
4061 Only works when editing the command line, thus requires use of
4062 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4063 Returns an empty string otherwise.
4064 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4065
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004066 Return type: |String|
4067
4068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069getcmdwintype() *getcmdwintype()*
4070 Return the current |command-line-window| type. Possible return
4071 values are the same as |getcmdtype()|. Returns an empty string
4072 when not in the command-line window.
4073
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004074 Return type: |String|
4075
4076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004077getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4078 Return a list of command-line completion matches. The String
4079 {type} argument specifies what for. The following completion
4080 types are supported:
4081
4082 arglist file names in argument list
4083 augroup autocmd groups
4084 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004085 behave |:behave| suboptions
4086 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004087 color color schemes
4088 command Ex command
4089 cmdline |cmdline-completion| result
4090 compiler compilers
4091 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004092 custom,{func} custom completion, defined via {func}
4093 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004094 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004095 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004096 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097 environment environment variable names
4098 event autocommand events
4099 expression Vim expression
4100 file file and directory names
4101 file_in_path file and directory names in |'path'|
4102 filetype filetype names |'filetype'|
4103 function function name
4104 help help subjects
4105 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004106 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004107 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004108 locale locale names (as output of locale -a)
4109 mapclear buffer argument
4110 mapping mapping name
4111 menu menus
4112 messages |:messages| suboptions
4113 option options
4114 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004115 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004116 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004117 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004118 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004119 sign |:sign| suboptions
4120 syntax syntax file names |'syntax'|
4121 syntime |:syntime| suboptions
4122 tag tags
4123 tag_listfiles tags, file names
4124 user user names
4125 var user variables
4126
4127 If {pat} is an empty string, then all the matches are
4128 returned. Otherwise only items matching {pat} are returned.
4129 See |wildcards| for the use of special characters in {pat}.
4130
4131 If the optional {filtered} flag is set to 1, then 'wildignore'
4132 is applied to filter the results. Otherwise all the matches
4133 are returned. The 'wildignorecase' option always applies.
4134
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004135 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4136 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004137 regular expression matching is used. Thus this function
4138 follows the user preference, what happens on the command line.
4139 If you do not want this you can make 'wildoptions' empty
4140 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004142 If {type} is "cmdline", then the |cmdline-completion| result is
4143 returned. For example, to complete the possible values after
4144 a ":call" command: >
4145 echo getcompletion('call ', 'cmdline')
4146<
4147 If there are no matches, an empty list is returned. An
4148 invalid value for {type} produces an error.
4149
4150 Can also be used as a |method|: >
4151 GetPattern()->getcompletion('color')
4152<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004153 Return type: list<string>
4154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004155 *getcurpos()*
4156getcurpos([{winid}])
4157 Get the position of the cursor. This is like getpos('.'), but
4158 includes an extra "curswant" item in the list:
4159 [0, lnum, col, off, curswant] ~
4160 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004161 cursor vertically. After |$| command it will be a very large
4162 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004163 |getpos()|.
4164 The first "bufnum" item is always zero. The byte position of
4165 the cursor is returned in 'col'. To get the character
4166 position, use |getcursorcharpos()|.
4167
4168 The optional {winid} argument can specify the window. It can
4169 be the window number or the |window-ID|. The last known
4170 cursor position is returned, this may be invalid for the
4171 current value of the buffer if it is not the current window.
4172 If {winid} is invalid a list with zeroes is returned.
4173
4174 This can be used to save and restore the cursor position: >
4175 let save_cursor = getcurpos()
4176 MoveTheCursorAround
4177 call setpos('.', save_cursor)
4178< Note that this only works within the window. See
4179 |winrestview()| for restoring more state.
4180
4181 Can also be used as a |method|: >
4182 GetWinid()->getcurpos()
4183<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004184 Return type: list<number>
4185
4186
4187getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004188 Same as |getcurpos()| but the column number in the returned
4189 List is a character index instead of a byte index.
4190
4191 Example:
4192 With the cursor on '보' in line 3 with text "여보세요": >
4193 getcursorcharpos() returns [0, 3, 2, 0, 3]
4194 getcurpos() returns [0, 3, 4, 0, 3]
4195<
4196 Can also be used as a |method|: >
4197 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004198<
4199 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004200
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004201
4202getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004203 The result is a String, which is the name of the current
4204 working directory. 'autochdir' is ignored.
4205
4206 With {winnr} return the local current directory of this window
4207 in the current tab page. {winnr} can be the window number or
4208 the |window-ID|.
4209 If {winnr} is -1 return the name of the global working
4210 directory. See also |haslocaldir()|.
4211
4212 With {winnr} and {tabnr} return the local current directory of
4213 the window in the specified tab page. If {winnr} is -1 return
4214 the working directory of the tabpage.
4215 If {winnr} is zero use the current window, if {tabnr} is zero
4216 use the current tabpage.
4217 Without any arguments, return the actual working directory of
4218 the current window.
4219 Return an empty string if the arguments are invalid.
4220
4221 Examples: >
4222 " Get the working directory of the current window
4223 :echo getcwd()
4224 :echo getcwd(0)
4225 :echo getcwd(0, 0)
4226 " Get the working directory of window 3 in tabpage 2
4227 :echo getcwd(3, 2)
4228 " Get the global working directory
4229 :echo getcwd(-1)
4230 " Get the working directory of tabpage 3
4231 :echo getcwd(-1, 3)
4232 " Get the working directory of current tabpage
4233 :echo getcwd(-1, 0)
4234
4235< Can also be used as a |method|: >
4236 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004237<
4238 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004239
4240getenv({name}) *getenv()*
4241 Return the value of environment variable {name}. The {name}
4242 argument is a string, without a leading '$'. Example: >
4243 myHome = getenv('HOME')
4244
4245< When the variable does not exist |v:null| is returned. That
4246 is different from a variable set to an empty string, although
4247 some systems interpret the empty value as the variable being
4248 deleted. See also |expr-env|.
4249
4250 Can also be used as a |method|: >
4251 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004252<
4253 Return type: |String| or |Number|
4254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004255
4256getfontname([{name}]) *getfontname()*
4257 Without an argument returns the name of the normal font being
4258 used. Like what is used for the Normal highlight group
4259 |hl-Normal|.
4260 With an argument a check is done whether String {name} is a
4261 valid font name. If not then an empty string is returned.
4262 Otherwise the actual font name is returned, or {name} if the
4263 GUI does not support obtaining the real name.
4264 Only works when the GUI is running, thus not in your vimrc or
4265 gvimrc file. Use the |GUIEnter| autocommand to use this
4266 function just after the GUI has started.
4267 Note that the GTK GUI accepts any font name, thus checking for
4268 a valid name does not work.
4269
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004270 Return type: |String|
4271
4272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004273getfperm({fname}) *getfperm()*
4274 The result is a String, which is the read, write, and execute
4275 permissions of the given file {fname}.
4276 If {fname} does not exist or its directory cannot be read, an
4277 empty string is returned.
4278 The result is of the form "rwxrwxrwx", where each group of
4279 "rwx" flags represent, in turn, the permissions of the owner
4280 of the file, the group the file belongs to, and other users.
4281 If a user does not have a given permission the flag for this
4282 is replaced with the string "-". Examples: >
4283 :echo getfperm("/etc/passwd")
4284 :echo getfperm(expand("~/.vimrc"))
4285< This will hopefully (from a security point of view) display
4286 the string "rw-r--r--" or even "rw-------".
4287
4288 Can also be used as a |method|: >
4289 GetFilename()->getfperm()
4290<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004291 Return type: |String|
4292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004293 For setting permissions use |setfperm()|.
4294
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004296getfsize({fname}) *getfsize()*
4297 The result is a Number, which is the size in bytes of the
4298 given file {fname}.
4299 If {fname} is a directory, 0 is returned.
4300 If the file {fname} can't be found, -1 is returned.
4301 If the size of {fname} is too big to fit in a Number then -2
4302 is returned.
4303
4304 Can also be used as a |method|: >
4305 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004306<
4307 Return type: |Number|
4308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004309
4310getftime({fname}) *getftime()*
4311 The result is a Number, which is the last modification time of
4312 the given file {fname}. The value is measured as seconds
4313 since 1st Jan 1970, and may be passed to strftime(). See also
4314 |localtime()| and |strftime()|.
4315 If the file {fname} can't be found -1 is returned.
4316
4317 Can also be used as a |method|: >
4318 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004319<
4320 Return type: |Number|
4321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004322
4323getftype({fname}) *getftype()*
4324 The result is a String, which is a description of the kind of
4325 file of the given file {fname}.
4326 If {fname} does not exist an empty string is returned.
4327 Here is a table over different kinds of files and their
4328 results:
4329 Normal file "file"
4330 Directory "dir"
4331 Symbolic link "link"
4332 Block device "bdev"
4333 Character device "cdev"
4334 Socket "socket"
4335 FIFO "fifo"
4336 All other "other"
4337 Example: >
4338 getftype("/home")
4339< Note that a type such as "link" will only be returned on
4340 systems that support it. On some systems only "dir" and
4341 "file" are returned. On MS-Windows a symbolic link to a
4342 directory returns "dir" instead of "link".
4343
4344 Can also be used as a |method|: >
4345 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004346<
4347 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004348
4349getimstatus() *getimstatus()*
4350 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004351 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004352 See 'imstatusfunc'.
4353
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004354 Return type: |Number|
4355
4356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004357getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4358 Returns the |jumplist| for the specified window.
4359
4360 Without arguments use the current window.
4361 With {winnr} only use this window in the current tab page.
4362 {winnr} can also be a |window-ID|.
4363 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004364 page. If {winnr} or {tabnr} is invalid, an empty list is
4365 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004366
4367 The returned list contains two entries: a list with the jump
4368 locations and the last used jump position number in the list.
4369 Each entry in the jump location list is a dictionary with
4370 the following entries:
4371 bufnr buffer number
4372 col column number
4373 coladd column offset for 'virtualedit'
4374 filename filename if available
4375 lnum line number
4376
4377 Can also be used as a |method|: >
4378 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004379<
4380 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004381
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004382 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004383getline({lnum} [, {end}])
4384 Without {end} the result is a String, which is line {lnum}
4385 from the current buffer. Example: >
4386 getline(1)
4387< When {lnum} is a String that doesn't start with a
4388 digit, |line()| is called to translate the String into a Number.
4389 To get the line under the cursor: >
4390 getline(".")
4391< When {lnum} is a number smaller than 1 or bigger than the
4392 number of lines in the buffer, an empty string is returned.
4393
4394 When {end} is given the result is a |List| where each item is
4395 a line from the current buffer in the range {lnum} to {end},
4396 including line {end}.
4397 {end} is used in the same way as {lnum}.
4398 Non-existing lines are silently omitted.
4399 When {end} is before {lnum} an empty |List| is returned.
4400 Example: >
4401 :let start = line('.')
4402 :let end = search("^$") - 1
4403 :let lines = getline(start, end)
4404
4405< Can also be used as a |method|: >
4406 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004407<
4408 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004409
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004410 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004411 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004412
4413getloclist({nr} [, {what}]) *getloclist()*
4414 Returns a |List| with all the entries in the location list for
4415 window {nr}. {nr} can be the window number or the |window-ID|.
4416 When {nr} is zero the current window is used.
4417
4418 For a location list window, the displayed location list is
4419 returned. For an invalid window number {nr}, an empty list is
4420 returned. Otherwise, same as |getqflist()|.
4421
4422 If the optional {what} dictionary argument is supplied, then
4423 returns the items listed in {what} as a dictionary. Refer to
4424 |getqflist()| for the supported items in {what}.
4425
4426 In addition to the items supported by |getqflist()| in {what},
4427 the following item is supported by |getloclist()|:
4428
4429 filewinid id of the window used to display files
4430 from the location list. This field is
4431 applicable only when called from a
4432 location list window. See
4433 |location-list-file-window| for more
4434 details.
4435
4436 Returns a |Dictionary| with default values if there is no
4437 location list for the window {nr}.
4438 Returns an empty Dictionary if window {nr} does not exist.
4439
4440 Examples (See also |getqflist-examples|): >
4441 :echo getloclist(3, {'all': 0})
4442 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004443<
4444 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004445
4446
4447getmarklist([{buf}]) *getmarklist()*
4448 Without the {buf} argument returns a |List| with information
4449 about all the global marks. |mark|
4450
4451 If the optional {buf} argument is specified, returns the
4452 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004453 see |bufname()|. If {buf} is invalid, an empty list is
4454 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004455
4456 Each item in the returned List is a |Dict| with the following:
4457 mark name of the mark prefixed by "'"
4458 pos a |List| with the position of the mark:
4459 [bufnum, lnum, col, off]
4460 Refer to |getpos()| for more information.
4461 file file name
4462
4463 Refer to |getpos()| for getting information about a specific
4464 mark.
4465
4466 Can also be used as a |method|: >
4467 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004468<
4469 Return type: list<dict<any>> or list<any>
4470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004471
4472getmatches([{win}]) *getmatches()*
4473 Returns a |List| with all matches previously defined for the
4474 current window by |matchadd()| and the |:match| commands.
4475 |getmatches()| is useful in combination with |setmatches()|,
4476 as |setmatches()| can restore a list of matches saved by
4477 |getmatches()|.
4478 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004479 window ID instead of the current window. If {win} is invalid,
4480 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004481 Example: >
4482 :echo getmatches()
4483< [{'group': 'MyGroup1', 'pattern': 'TODO',
4484 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4485 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4486 :let m = getmatches()
4487 :call clearmatches()
4488 :echo getmatches()
4489< [] >
4490 :call setmatches(m)
4491 :echo getmatches()
4492< [{'group': 'MyGroup1', 'pattern': 'TODO',
4493 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4494 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4495 :unlet m
4496<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004497 Return type: list<dict<any>> or list<any>
4498
4499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004500getmousepos() *getmousepos()*
4501 Returns a |Dictionary| with the last known position of the
4502 mouse. This can be used in a mapping for a mouse click or in
4503 a filter of a popup window. The items are:
4504 screenrow screen row
4505 screencol screen column
4506 winid Window ID of the click
4507 winrow row inside "winid"
4508 wincol column inside "winid"
4509 line text line inside "winid"
4510 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004511 coladd offset (in screen columns) from the
4512 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004513 All numbers are 1-based.
4514
4515 If not over a window, e.g. when in the command line, then only
4516 "screenrow" and "screencol" are valid, the others are zero.
4517
4518 When on the status line below a window or the vertical
4519 separator right of a window, the "line" and "column" values
4520 are zero.
4521
4522 When the position is after the text then "column" is the
4523 length of the text in bytes plus one.
4524
4525 If the mouse is over a popup window then that window is used.
4526
4527 When using |getchar()| the Vim variables |v:mouse_lnum|,
4528 |v:mouse_col| and |v:mouse_winid| also provide these values.
4529
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004530 Return type: dict<number>
4531
4532
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004533getmouseshape() *getmouseshape()*
4534 Returns the name of the currently showing mouse pointer.
4535 When the |+mouseshape| feature is not supported or the shape
4536 is unknown an empty string is returned.
4537 This function is mainly intended for testing.
4538
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004539 Return type: |String|
4540
4541
4542getpid() *getpid()*
4543 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004544 On Unix and MS-Windows this is a unique number, until Vim
4545 exits.
4546
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004547 Return type: |Number|
4548
4549
4550getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004551 Get the position for String {expr}.
4552 The accepted values for {expr} are: *E1209*
4553 . The cursor position.
4554 $ The last line in the current buffer.
4555 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004556 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004557 w0 First line visible in current window (one if the
4558 display isn't updated, e.g. in silent Ex mode).
4559 w$ Last line visible in current window (this is one
4560 less than "w0" if no lines are visible).
4561 v When not in Visual mode, returns the cursor
4562 position. In Visual mode, returns the other end
4563 of the Visual area. A good way to think about
4564 this is that in Visual mode "v" and "." complement
4565 each other. While "." refers to the cursor
4566 position, "v" refers to where |v_o| would move the
4567 cursor. As a result, you can use "v" and "."
4568 together to work on all of a selection in
4569 characterwise Visual mode. If the cursor is at
4570 the end of a characterwise Visual area, "v" refers
4571 to the start of the same Visual area. And if the
4572 cursor is at the start of a characterwise Visual
4573 area, "v" refers to the end of the same Visual
4574 area. "v" differs from |'<| and |'>| in that it's
4575 updated right away.
4576 Note that a mark in another file can be used. The line number
4577 then applies to another buffer.
4578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004579 The result is a |List| with four numbers:
4580 [bufnum, lnum, col, off]
4581 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4582 is the buffer number of the mark.
4583 "lnum" and "col" are the position in the buffer. The first
4584 column is 1.
4585 The "off" number is zero, unless 'virtualedit' is used. Then
4586 it is the offset in screen columns from the start of the
4587 character. E.g., a position within a <Tab> or after the last
4588 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004589
4590 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004591 The column number in the returned List is the byte position
4592 within the line. To get the character position in the line,
4593 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004594
4595 Note that for '< and '> Visual mode matters: when it is "V"
4596 (visual line mode) the column of '< is zero and the column of
4597 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004598 A very large column number equal to |v:maxcol| can be returned,
4599 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004600 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004602 This can be used to save and restore the position of a mark: >
4603 let save_a_mark = getpos("'a")
4604 ...
4605 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004606<
4607 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004608
4609 Can also be used as a |method|: >
4610 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004611<
4612 Return type: list<number>
4613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004614
4615getqflist([{what}]) *getqflist()*
4616 Returns a |List| with all the current quickfix errors. Each
4617 list item is a dictionary with these entries:
4618 bufnr number of buffer that has the file name, use
4619 bufname() to get the name
4620 module module name
4621 lnum line number in the buffer (first line is 1)
4622 end_lnum
4623 end of line number if the item is multiline
4624 col column number (first column is 1)
4625 end_col end of column number if the item has range
4626 vcol |TRUE|: "col" is visual column
4627 |FALSE|: "col" is byte index
4628 nr error number
h-east84ac2122024-06-17 18:12:30 +02004629 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004630 text description of the error
4631 type type of the error, 'E', '1', etc.
4632 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004633 user_data
4634 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004635 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004636
4637 When there is no error list or it's empty, an empty list is
4638 returned. Quickfix list entries with a non-existing buffer
4639 number are returned with "bufnr" set to zero (Note: some
4640 functions accept buffer number zero for the alternate buffer,
4641 you may need to explicitly check for zero).
4642
4643 Useful application: Find pattern matches in multiple files and
4644 do something with them: >
4645 :vimgrep /theword/jg *.c
4646 :for d in getqflist()
4647 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4648 :endfor
4649<
4650 If the optional {what} dictionary argument is supplied, then
4651 returns only the items listed in {what} as a dictionary. The
4652 following string items are supported in {what}:
4653 changedtick get the total number of changes made
4654 to the list |quickfix-changedtick|
4655 context get the |quickfix-context|
4656 efm errorformat to use when parsing "lines". If
4657 not present, then the 'errorformat' option
4658 value is used.
4659 id get information for the quickfix list with
4660 |quickfix-ID|; zero means the id for the
4661 current list or the list specified by "nr"
4662 idx get information for the quickfix entry at this
4663 index in the list specified by 'id' or 'nr'.
4664 If set to zero, then uses the current entry.
4665 See |quickfix-index|
4666 items quickfix list entries
4667 lines parse a list of lines using 'efm' and return
4668 the resulting entries. Only a |List| type is
4669 accepted. The current quickfix list is not
4670 modified. See |quickfix-parse|.
4671 nr get information for this quickfix list; zero
4672 means the current quickfix list and "$" means
4673 the last quickfix list
4674 qfbufnr number of the buffer displayed in the quickfix
4675 window. Returns 0 if the quickfix buffer is
4676 not present. See |quickfix-buffer|.
4677 size number of entries in the quickfix list
4678 title get the list title |quickfix-title|
4679 winid get the quickfix |window-ID|
4680 all all of the above quickfix properties
4681 Non-string items in {what} are ignored. To get the value of a
4682 particular item, set it to zero.
4683 If "nr" is not present then the current quickfix list is used.
4684 If both "nr" and a non-zero "id" are specified, then the list
4685 specified by "id" is used.
4686 To get the number of lists in the quickfix stack, set "nr" to
4687 "$" in {what}. The "nr" value in the returned dictionary
4688 contains the quickfix stack size.
4689 When "lines" is specified, all the other items except "efm"
4690 are ignored. The returned dictionary contains the entry
4691 "items" with the list of entries.
4692
4693 The returned dictionary contains the following entries:
4694 changedtick total number of changes made to the
4695 list |quickfix-changedtick|
4696 context quickfix list context. See |quickfix-context|
4697 If not present, set to "".
4698 id quickfix list ID |quickfix-ID|. If not
4699 present, set to 0.
4700 idx index of the quickfix entry in the list. If not
4701 present, set to 0.
4702 items quickfix list entries. If not present, set to
4703 an empty list.
4704 nr quickfix list number. If not present, set to 0
4705 qfbufnr number of the buffer displayed in the quickfix
4706 window. If not present, set to 0.
4707 size number of entries in the quickfix list. If not
4708 present, set to 0.
4709 title quickfix list title text. If not present, set
4710 to "".
4711 winid quickfix |window-ID|. If not present, set to 0
4712
4713 Examples (See also |getqflist-examples|): >
4714 :echo getqflist({'all': 1})
4715 :echo getqflist({'nr': 2, 'title': 1})
4716 :echo getqflist({'lines' : ["F1:10:L10"]})
4717<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004718 Return type: list<dict<any>> or list<any>
4719
4720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004721getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4722 The result is a String, which is the contents of register
4723 {regname}. Example: >
4724 :let cliptext = getreg('*')
4725< When register {regname} was not set the result is an empty
4726 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004727 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004728
4729 getreg('=') returns the last evaluated value of the expression
4730 register. (For use in maps.)
4731 getreg('=', 1) returns the expression itself, so that it can
4732 be restored with |setreg()|. For other registers the extra
4733 argument is ignored, thus you can always give it.
4734
4735 If {list} is present and |TRUE|, the result type is changed
4736 to |List|. Each list item is one text line. Use it if you care
4737 about zero bytes possibly present inside register: without
4738 third argument both NLs and zero bytes are represented as NLs
4739 (see |NL-used-for-Nul|).
4740 When the register was not set an empty list is returned.
4741
4742 If {regname} is "", the unnamed register '"' is used.
4743 If {regname} is not specified, |v:register| is used.
4744 In |Vim9-script| {regname} must be one character.
4745
4746 Can also be used as a |method|: >
4747 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004748<
4749 Return type: |String|
4750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004751
4752getreginfo([{regname}]) *getreginfo()*
4753 Returns detailed information about register {regname} as a
4754 Dictionary with the following entries:
4755 regcontents List of lines contained in register
4756 {regname}, like
4757 |getreg|({regname}, 1, 1).
4758 regtype the type of register {regname}, as in
4759 |getregtype()|.
4760 isunnamed Boolean flag, v:true if this register
4761 is currently pointed to by the unnamed
4762 register.
4763 points_to for the unnamed register, gives the
4764 single letter name of the register
4765 currently pointed to (see |quotequote|).
4766 For example, after deleting a line
4767 with `dd`, this field will be "1",
4768 which is the register that got the
4769 deleted text.
4770
4771 The {regname} argument is a string. If {regname} is invalid
4772 or not set, an empty Dictionary will be returned.
4773 If {regname} is "" or "@", the unnamed register '"' is used.
4774 If {regname} is not specified, |v:register| is used.
4775 The returned Dictionary can be passed to |setreg()|.
4776 In |Vim9-script| {regname} must be one character.
4777
4778 Can also be used as a |method|: >
4779 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004780<
4781 Return type: dict<any>
4782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004783
Shougo Matsushita19b71882024-02-28 22:48:12 +01004784getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004785 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004786 buffer.
4787
4788 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004789 See |getpos()| for the format of the list. It's possible
4790 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004791 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004792
4793 The optional argument {opts} is a Dict and supports the
4794 following items:
4795
zeertzjqafc22952024-05-24 19:07:12 +02004796 type Specify the region's selection type.
4797 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004798 except that the width can be omitted
4799 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004800 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004801
zeertzjq87410ab2024-03-02 06:00:23 +08004802 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004803 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004804 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004805
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004806 You can get the last selection type by |visualmode()|.
4807 If Visual mode is active, use |mode()| to get the Visual mode
4808 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004809 This function is useful to get text starting and ending in
4810 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004811
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004812 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004813 Note that:
4814 - Order of {pos1} and {pos2} doesn't matter, it will always
4815 return content from the upper left position to the lower
4816 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004817 - If 'virtualedit' is enabled and the region is past the end
4818 of the lines, resulting lines are padded with spaces.
4819 - If the region is blockwise and it starts or ends in the
4820 middle of a multi-cell character, it is not included but
4821 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004822 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004823 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004824 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004825 - It is evaluated in current window context, which makes a
4826 difference if the buffer is displayed in a window with
4827 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004828
4829 Examples: >
4830 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004831 \ <Cmd>echow getregion(
4832 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004833<
4834 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004835 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004836<
4837 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004838
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004839<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004840getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4841 Same as |getregion()|, but returns a list of positions
4842 describing the buffer text segments bound by {pos1} and
4843 {pos2}.
4844 The segments are a pair of positions for every line: >
4845 [[{start_pos}, {end_pos}], ...]
4846<
4847 The position is a |List| with four numbers:
4848 [bufnum, lnum, col, off]
4849 "bufnum" is the buffer number.
4850 "lnum" and "col" are the position in the buffer. The first
4851 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004852 If the "off" number of a starting position is non-zero, it is
4853 the offset in screen columns from the start of the character.
4854 E.g., a position within a <Tab> or after the last character.
4855 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004856 the offset of the character's first cell not included in the
4857 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004858
zeertzjq2b09de92024-05-24 07:48:51 +02004859 Apart from the options supported by |getregion()|, {opts} also
4860 supports the following:
4861
4862 eol If |TRUE|, indicate positions beyond
4863 the end of a line with "col" values
4864 one more than the length of the line.
4865 If |FALSE|, positions are limited
4866 within their lines, and if a line is
4867 empty or the selection is entirely
4868 beyond the end of a line, a "col"
4869 value of 0 is used for both positions.
4870 (default: |FALSE|)
4871
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004872 Can also be used as a |method|: >
4873 getpos('.')->getregionpos(getpos("'a"))
4874<
zeertzjqd4d12072024-07-16 20:34:16 +02004875 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004876
4877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004878getregtype([{regname}]) *getregtype()*
4879 The result is a String, which is type of register {regname}.
4880 The value will be one of:
4881 "v" for |characterwise| text
4882 "V" for |linewise| text
4883 "<CTRL-V>{width}" for |blockwise-visual| text
4884 "" for an empty or unknown register
4885 <CTRL-V> is one character with value 0x16.
4886 The {regname} argument is a string. If {regname} is "", the
4887 unnamed register '"' is used. If {regname} is not specified,
4888 |v:register| is used.
4889 In |Vim9-script| {regname} must be one character.
4890
4891 Can also be used as a |method|: >
4892 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004893<
4894 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004895
Bram Moolenaar71badf92023-04-22 22:40:14 +01004896getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004897 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004898 scripts in the order they were sourced, like what
4899 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004900
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004901 The optional Dict argument {opts} supports the following
4902 optional items:
4903 name Script name match pattern. If specified,
4904 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004905 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004906 "name" are returned.
4907 sid Script ID |<SID>|. If specified, only
4908 information about the script with ID "sid" is
4909 returned and "name" is ignored.
4910
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004911 Each item in the returned List is a |Dict| with the following
4912 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004913 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004914 `import autoload` but was not actually sourced
4915 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004916 functions List of script-local function names defined in
4917 the script. Present only when a particular
4918 script is specified using the "sid" item in
4919 {opts}.
4920 name Vim script file name.
4921 sid Script ID |<SID>|.
4922 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004923 this script name links to, if any, otherwise
4924 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004925 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004926 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004927 specified using the "sid" item in {opts}.
4928 Note that this is a copy, the value of
4929 script-local variables cannot be changed using
4930 this dictionary.
h_east59858792023-10-25 22:47:05 +09004931 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004932
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004933 Examples: >
4934 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004935 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004936<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004937 Return type: list<dict<any>>
4938
4939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004940gettabinfo([{tabnr}]) *gettabinfo()*
4941 If {tabnr} is not specified, then information about all the
4942 tab pages is returned as a |List|. Each List item is a
4943 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4944 number and information about that one is returned. If the tab
4945 page does not exist an empty List is returned.
4946
4947 Each List item is a |Dictionary| with the following entries:
4948 tabnr tab page number.
4949 variables a reference to the dictionary with
4950 tabpage-local variables
4951 windows List of |window-ID|s in the tab page.
4952
4953 Can also be used as a |method|: >
4954 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004955<
4956 Return type: list<dict<any>>
4957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004958
4959gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4960 Get the value of a tab-local variable {varname} in tab page
4961 {tabnr}. |t:var|
4962 Tabs are numbered starting with one.
4963 The {varname} argument is a string. When {varname} is empty a
4964 dictionary with all tab-local variables is returned.
4965 Note that the name without "t:" must be used.
4966 When the tab or variable doesn't exist {def} or an empty
4967 string is returned, there is no error message.
4968
4969 Can also be used as a |method|: >
4970 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004971<
4972 Return type: any, depending on {varname}
4973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004974
4975gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4976 Get the value of window-local variable {varname} in window
4977 {winnr} in tab page {tabnr}.
4978 The {varname} argument is a string. When {varname} is empty a
4979 dictionary with all window-local variables is returned.
4980 When {varname} is equal to "&" get the values of all
4981 window-local options in a |Dictionary|.
4982 Otherwise, when {varname} starts with "&" get the value of a
4983 window-local option.
4984 Note that {varname} must be the name without "w:".
4985 Tabs are numbered starting with one. For the current tabpage
4986 use |getwinvar()|.
4987 {winnr} can be the window number or the |window-ID|.
4988 When {winnr} is zero the current window is used.
4989 This also works for a global option, buffer-local option and
4990 window-local option, but it doesn't work for a global variable
4991 or buffer-local variable.
4992 When the tab, window or variable doesn't exist {def} or an
4993 empty string is returned, there is no error message.
4994 Examples: >
4995 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004996 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004997<
4998 To obtain all window-local variables use: >
4999 gettabwinvar({tabnr}, {winnr}, '&')
5000
5001< Can also be used as a |method|: >
5002 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005003<
5004 Return type: any, depending on {varname}
5005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005006
5007gettagstack([{winnr}]) *gettagstack()*
5008 The result is a Dict, which is the tag stack of window {winnr}.
5009 {winnr} can be the window number or the |window-ID|.
5010 When {winnr} is not specified, the current window is used.
5011 When window {winnr} doesn't exist, an empty Dict is returned.
5012
5013 The returned dictionary contains the following entries:
5014 curidx Current index in the stack. When at
5015 top of the stack, set to (length + 1).
5016 Index of bottom of the stack is 1.
5017 items List of items in the stack. Each item
5018 is a dictionary containing the
5019 entries described below.
5020 length Number of entries in the stack.
5021
5022 Each item in the stack is a dictionary with the following
5023 entries:
5024 bufnr buffer number of the current jump
5025 from cursor position before the tag jump.
5026 See |getpos()| for the format of the
5027 returned list.
5028 matchnr current matching tag number. Used when
5029 multiple matching tags are found for a
5030 name.
5031 tagname name of the tag
5032
5033 See |tagstack| for more information about the tag stack.
5034
5035 Can also be used as a |method|: >
5036 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005037<
5038 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005039
5040
Christ van Willegence0ef912024-06-20 23:41:59 +02005041gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005042 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005043 This is intended for use in Vim scripts. When generating
5044 message translations the {text} is extracted by `xgettext`,
5045 the translator can add translated messages into the .po file
5046 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005047 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005048 `xgettext` does not support single quoted escaped text.
5049
Christ van Willegence0ef912024-06-20 23:41:59 +02005050 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005051 for that specific package. This is mainly required for
5052 third-party Vim scripts. You need to specify a path to the
5053 translations with the |bindtextdomain()| function before
5054 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005055
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005056 Return type: |String|
5057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005058
5059getwininfo([{winid}]) *getwininfo()*
5060 Returns information about windows as a |List| with Dictionaries.
5061
5062 If {winid} is given Information about the window with that ID
5063 is returned, as a |List| with one item. If the window does not
5064 exist the result is an empty list.
5065
5066 Without {winid} information about all the windows in all the
5067 tab pages is returned.
5068
5069 Each List item is a |Dictionary| with the following entries:
5070 botline last complete displayed buffer line
5071 bufnr number of buffer in the window
5072 height window height (excluding winbar)
5073 loclist 1 if showing a location list
5074 {only with the +quickfix feature}
5075 quickfix 1 if quickfix or location list window
5076 {only with the +quickfix feature}
5077 terminal 1 if a terminal window
5078 {only with the +terminal feature}
5079 tabnr tab page number
5080 topline first displayed buffer line
5081 variables a reference to the dictionary with
5082 window-local variables
5083 width window width
5084 winbar 1 if the window has a toolbar, 0
5085 otherwise
5086 wincol leftmost screen column of the window;
5087 "col" from |win_screenpos()|
5088 textoff number of columns occupied by any
5089 'foldcolumn', 'signcolumn' and line
5090 number in front of the text
5091 winid |window-ID|
5092 winnr window number
5093 winrow topmost screen line of the window;
5094 "row" from |win_screenpos()|
5095
5096 Can also be used as a |method|: >
5097 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005098<
5099 Return type: list<dict<any>>
5100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005101
5102getwinpos([{timeout}]) *getwinpos()*
5103 The result is a |List| with two numbers, the result of
5104 |getwinposx()| and |getwinposy()| combined:
5105 [x-pos, y-pos]
5106 {timeout} can be used to specify how long to wait in msec for
5107 a response from the terminal. When omitted 100 msec is used.
5108 Use a longer time for a remote terminal.
5109 When using a value less than 10 and no response is received
5110 within that time, a previously reported position is returned,
5111 if available. This can be used to poll for the position and
5112 do some work in the meantime: >
5113 while 1
5114 let res = getwinpos(1)
5115 if res[0] >= 0
5116 break
5117 endif
5118 " Do some work here
5119 endwhile
5120<
5121
5122 Can also be used as a |method|: >
5123 GetTimeout()->getwinpos()
5124<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005125 Return type: list<number>
5126
5127
5128getwinposx() *getwinposx()*
5129 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005130 the left hand side of the GUI Vim window. Also works for an
5131 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005132 The result will be -1 if the information is not available
5133 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005134 The value can be used with `:winpos`.
5135
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005136 Return type: |Number|
5137
5138
5139getwinposy() *getwinposy()*
5140 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005141 the top of the GUI Vim window. Also works for an xterm (uses
5142 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005143 The result will be -1 if the information is not available
5144 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005145 The value can be used with `:winpos`.
5146
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005147 Return type: |Number|
5148
5149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005150getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5151 Like |gettabwinvar()| for the current tabpage.
5152 Examples: >
5153 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005154 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005155
5156< Can also be used as a |method|: >
5157 GetWinnr()->getwinvar(varname)
5158<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005159 Return type: any, depending on {varname}
5160
5161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005162glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5163 Expand the file wildcards in {expr}. See |wildcards| for the
5164 use of special characters.
5165
5166 Unless the optional {nosuf} argument is given and is |TRUE|,
5167 the 'suffixes' and 'wildignore' options apply: Names matching
5168 one of the patterns in 'wildignore' will be skipped and
5169 'suffixes' affect the ordering of matches.
5170 'wildignorecase' always applies.
5171
5172 When {list} is present and it is |TRUE| the result is a |List|
5173 with all matching files. The advantage of using a List is,
5174 you also get filenames containing newlines correctly.
5175 Otherwise the result is a String and when there are several
5176 matches, they are separated by <NL> characters.
5177
5178 If the expansion fails, the result is an empty String or List.
5179
5180 You can also use |readdir()| if you need to do complicated
5181 things, such as limiting the number of matches.
5182
5183 A name for a non-existing file is not included. A symbolic
5184 link is only included if it points to an existing file.
5185 However, when the {alllinks} argument is present and it is
5186 |TRUE| then all symbolic links are included.
5187
5188 For most systems backticks can be used to get files names from
5189 any external command. Example: >
5190 :let tagfiles = glob("`find . -name tags -print`")
5191 :let &tags = substitute(tagfiles, "\n", ",", "g")
5192< The result of the program inside the backticks should be one
5193 item per line. Spaces inside an item are allowed.
5194
5195 See |expand()| for expanding special Vim variables. See
5196 |system()| for getting the raw output of an external command.
5197
5198 Can also be used as a |method|: >
5199 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005200<
5201 Return type: |String| or list<string> or list<any> depending
5202 on {list}
5203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005204
5205glob2regpat({string}) *glob2regpat()*
5206 Convert a file pattern, as used by glob(), into a search
5207 pattern. The result can be used to match with a string that
5208 is a file name. E.g. >
5209 if filename =~ glob2regpat('Make*.mak')
5210< This is equivalent to: >
5211 if filename =~ '^Make.*\.mak$'
5212< When {string} is an empty string the result is "^$", match an
5213 empty string.
5214 Note that the result depends on the system. On MS-Windows
5215 a backslash usually means a path separator.
5216
5217 Can also be used as a |method|: >
5218 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005219<
5220 Return type: |String|
5221
5222 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005223globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5224 Perform glob() for String {expr} on all directories in {path}
5225 and concatenate the results. Example: >
5226 :echo globpath(&rtp, "syntax/c.vim")
5227<
5228 {path} is a comma-separated list of directory names. Each
5229 directory name is prepended to {expr} and expanded like with
5230 |glob()|. A path separator is inserted when needed.
5231 To add a comma inside a directory name escape it with a
5232 backslash. Note that on MS-Windows a directory may have a
5233 trailing backslash, remove it if you put a comma after it.
5234 If the expansion fails for one of the directories, there is no
5235 error message.
5236
5237 Unless the optional {nosuf} argument is given and is |TRUE|,
5238 the 'suffixes' and 'wildignore' options apply: Names matching
5239 one of the patterns in 'wildignore' will be skipped and
5240 'suffixes' affect the ordering of matches.
5241
5242 When {list} is present and it is |TRUE| the result is a |List|
5243 with all matching files. The advantage of using a List is, you
5244 also get filenames containing newlines correctly. Otherwise
5245 the result is a String and when there are several matches,
5246 they are separated by <NL> characters. Example: >
5247 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5248<
5249 {alllinks} is used as with |glob()|.
5250
5251 The "**" item can be used to search in a directory tree.
5252 For example, to find all "README.txt" files in the directories
5253 in 'runtimepath' and below: >
5254 :echo globpath(&rtp, "**/README.txt")
5255< Upwards search and limiting the depth of "**" is not
5256 supported, thus using 'path' will not always work properly.
5257
5258 Can also be used as a |method|, the base is passed as the
5259 second argument: >
5260 GetExpr()->globpath(&rtp)
5261<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005262 Return type: |String| or list<string> or list<any> depending
5263 on {list}
5264
5265
5266has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005267 When {check} is omitted or is zero: The result is a Number,
5268 which is 1 if the feature {feature} is supported, zero
5269 otherwise. The {feature} argument is a string, case is
5270 ignored. See |feature-list| below.
5271
5272 When {check} is present and not zero: The result is a Number,
5273 which is 1 if the feature {feature} could ever be supported,
5274 zero otherwise. This is useful to check for a typo in
5275 {feature} and to detect dead code. Keep in mind that an older
5276 Vim version will not know about a feature added later and
5277 features that have been abandoned will not be known by the
5278 current Vim version.
5279
5280 Also see |exists()| and |exists_compiled()|.
5281
5282 Note that to skip code that has a syntax error when the
5283 feature is not available, Vim may skip the rest of the line
5284 and miss a following `endif`. Therefore put the `endif` on a
5285 separate line: >
5286 if has('feature')
5287 let x = this->breaks->without->the->feature
5288 endif
5289< If the `endif` would be moved to the second line as "| endif" it
5290 would not be found.
5291
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005292 Return type: |Number|
5293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005294
5295has_key({dict}, {key}) *has_key()*
5296 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005297 has an entry with key {key}. FALSE otherwise.
5298 The {key} argument is a string. In |Vim9| script a number is
5299 also accepted (and converted to a string) but no other types.
5300 In legacy script the usual automatic conversion to string is
5301 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005302
5303 Can also be used as a |method|: >
5304 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005305<
5306 Return type: |Number|
5307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005308
5309haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5310 The result is a Number:
5311 1 when the window has set a local directory via |:lcd|
5312 2 when the tab-page has set a local directory via |:tcd|
5313 0 otherwise.
5314
5315 Without arguments use the current window.
5316 With {winnr} use this window in the current tab page.
5317 With {winnr} and {tabnr} use the window in the specified tab
5318 page.
5319 {winnr} can be the window number or the |window-ID|.
5320 If {winnr} is -1 it is ignored and only the tabpage is used.
5321 Return 0 if the arguments are invalid.
5322 Examples: >
5323 if haslocaldir() == 1
5324 " window local directory case
5325 elseif haslocaldir() == 2
5326 " tab-local directory case
5327 else
5328 " global directory case
5329 endif
5330
5331 " current window
5332 :echo haslocaldir()
5333 :echo haslocaldir(0)
5334 :echo haslocaldir(0, 0)
5335 " window n in current tab page
5336 :echo haslocaldir(n)
5337 :echo haslocaldir(n, 0)
5338 " window n in tab page m
5339 :echo haslocaldir(n, m)
5340 " tab page m
5341 :echo haslocaldir(-1, m)
5342<
5343 Can also be used as a |method|: >
5344 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005345<
5346 Return type: |Number|
5347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005348
5349hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5350 The result is a Number, which is TRUE if there is a mapping
5351 that contains {what} in somewhere in the rhs (what it is
5352 mapped to) and this mapping exists in one of the modes
5353 indicated by {mode}.
5354 The arguments {what} and {mode} are strings.
5355 When {abbr} is there and it is |TRUE| use abbreviations
5356 instead of mappings. Don't forget to specify Insert and/or
5357 Command-line mode.
5358 Both the global mappings and the mappings local to the current
5359 buffer are checked for a match.
5360 If no matching mapping is found FALSE is returned.
5361 The following characters are recognized in {mode}:
5362 n Normal mode
5363 v Visual and Select mode
5364 x Visual mode
5365 s Select mode
5366 o Operator-pending mode
5367 i Insert mode
5368 l Language-Argument ("r", "f", "t", etc.)
5369 c Command-line mode
5370 When {mode} is omitted, "nvo" is used.
5371
5372 This function is useful to check if a mapping already exists
5373 to a function in a Vim script. Example: >
5374 :if !hasmapto('\ABCdoit')
5375 : map <Leader>d \ABCdoit
5376 :endif
5377< This installs the mapping to "\ABCdoit" only if there isn't
5378 already a mapping to "\ABCdoit".
5379
5380 Can also be used as a |method|: >
5381 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005382<
5383 Return type: |Number|
5384
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005385
5386histadd({history}, {item}) *histadd()*
5387 Add the String {item} to the history {history} which can be
5388 one of: *hist-names*
5389 "cmd" or ":" command line history
5390 "search" or "/" search pattern history
5391 "expr" or "=" typed expression history
5392 "input" or "@" input line history
5393 "debug" or ">" debug command history
5394 empty the current or last used history
5395 The {history} string does not need to be the whole name, one
5396 character is sufficient.
5397 If {item} does already exist in the history, it will be
5398 shifted to become the newest entry.
5399 The result is a Number: TRUE if the operation was successful,
5400 otherwise FALSE is returned.
5401
5402 Example: >
5403 :call histadd("input", strftime("%Y %b %d"))
5404 :let date=input("Enter date: ")
5405< This function is not available in the |sandbox|.
5406
5407 Can also be used as a |method|, the base is passed as the
5408 second argument: >
5409 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005410<
5411 Return type: |Number|
5412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005413
5414histdel({history} [, {item}]) *histdel()*
5415 Clear {history}, i.e. delete all its entries. See |hist-names|
5416 for the possible values of {history}.
5417
5418 If the parameter {item} evaluates to a String, it is used as a
5419 regular expression. All entries matching that expression will
5420 be removed from the history (if there are any).
5421 Upper/lowercase must match, unless "\c" is used |/\c|.
5422 If {item} evaluates to a Number, it will be interpreted as
5423 an index, see |:history-indexing|. The respective entry will
5424 be removed if it exists.
5425
5426 The result is TRUE for a successful operation, otherwise FALSE
5427 is returned.
5428
5429 Examples:
5430 Clear expression register history: >
5431 :call histdel("expr")
5432<
5433 Remove all entries starting with "*" from the search history: >
5434 :call histdel("/", '^\*')
5435<
5436 The following three are equivalent: >
5437 :call histdel("search", histnr("search"))
5438 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005439 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005440<
5441 To delete the last search pattern and use the last-but-one for
5442 the "n" command and 'hlsearch': >
5443 :call histdel("search", -1)
5444 :let @/ = histget("search", -1)
5445<
5446 Can also be used as a |method|: >
5447 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005448<
5449 Return type: |Number|
5450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005451
5452histget({history} [, {index}]) *histget()*
5453 The result is a String, the entry with Number {index} from
5454 {history}. See |hist-names| for the possible values of
5455 {history}, and |:history-indexing| for {index}. If there is
5456 no such entry, an empty String is returned. When {index} is
5457 omitted, the most recent item from the history is used.
5458
5459 Examples:
5460 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005461 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005462
5463< Define an Ex command ":H {num}" that supports re-execution of
5464 the {num}th entry from the output of |:history|. >
5465 :command -nargs=1 H execute histget("cmd", 0+<args>)
5466<
5467 Can also be used as a |method|: >
5468 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005469<
5470 Return type: |String|
5471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005472
5473histnr({history}) *histnr()*
5474 The result is the Number of the current entry in {history}.
5475 See |hist-names| for the possible values of {history}.
5476 If an error occurred, -1 is returned.
5477
5478 Example: >
5479 :let inp_index = histnr("expr")
5480
5481< Can also be used as a |method|: >
5482 GetHistory()->histnr()
5483<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005484 Return type: |Number|
5485
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005486hlexists({name}) *hlexists()*
5487 The result is a Number, which is TRUE if a highlight group
5488 called {name} exists. This is when the group has been
5489 defined in some way. Not necessarily when highlighting has
5490 been defined for it, it may also have been used for a syntax
5491 item.
5492 *highlight_exists()*
5493 Obsolete name: highlight_exists().
5494
5495 Can also be used as a |method|: >
5496 GetName()->hlexists()
5497<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005498 Return type: |Number|
5499
5500
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005501hlget([{name} [, {resolve}]]) *hlget()*
5502 Returns a List of all the highlight group attributes. If the
5503 optional {name} is specified, then returns a List with only
5504 the attributes of the specified highlight group. Returns an
5505 empty List if the highlight group {name} is not present.
5506
5507 If the optional {resolve} argument is set to v:true and the
5508 highlight group {name} is linked to another group, then the
5509 link is resolved recursively and the attributes of the
5510 resolved highlight group are returned.
5511
5512 Each entry in the returned List is a Dictionary with the
5513 following items:
5514 cleared boolean flag, set to v:true if the highlight
5515 group attributes are cleared or not yet
5516 specified. See |highlight-clear|.
5517 cterm cterm attributes. See |highlight-cterm|.
5518 ctermbg cterm background color.
5519 See |highlight-ctermbg|.
5520 ctermfg cterm foreground color.
5521 See |highlight-ctermfg|.
5522 ctermul cterm underline color. See |highlight-ctermul|.
5523 default boolean flag, set to v:true if the highlight
5524 group link is a default link. See
5525 |highlight-default|.
5526 font highlight group font. See |highlight-font|.
5527 gui gui attributes. See |highlight-gui|.
5528 guibg gui background color. See |highlight-guibg|.
5529 guifg gui foreground color. See |highlight-guifg|.
5530 guisp gui special color. See |highlight-guisp|.
5531 id highlight group ID.
5532 linksto linked highlight group name.
5533 See |:highlight-link|.
5534 name highlight group name. See |group-name|.
5535 start start terminal keycode. See |highlight-start|.
5536 stop stop terminal keycode. See |highlight-stop|.
5537 term term attributes. See |highlight-term|.
5538
5539 The 'term', 'cterm' and 'gui' items in the above Dictionary
5540 have a dictionary value with the following optional boolean
5541 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5542 'reverse', 'inverse' and 'strikethrough'.
5543
5544 Example(s): >
5545 :echo hlget()
5546 :echo hlget('ModeMsg')
5547 :echo hlget('Number', v:true)
5548<
5549 Can also be used as a |method|: >
5550 GetName()->hlget()
5551<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005552 Return type: list<dict<any>>
5553
5554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005555hlset({list}) *hlset()*
5556 Creates or modifies the attributes of a List of highlight
5557 groups. Each item in {list} is a dictionary containing the
5558 attributes of a highlight group. See |hlget()| for the list of
5559 supported items in this dictionary.
5560
5561 In addition to the items described in |hlget()|, the following
5562 additional items are supported in the dictionary:
5563
5564 force boolean flag to force the creation of
5565 a link for an existing highlight group
5566 with attributes.
5567
5568 The highlight group is identified using the 'name' item and
5569 the 'id' item (if supplied) is ignored. If a highlight group
5570 with a specified name doesn't exist, then it is created.
5571 Otherwise the attributes of an existing highlight group are
5572 modified.
5573
5574 If an empty dictionary value is used for the 'term' or 'cterm'
5575 or 'gui' entries, then the corresponding attributes are
5576 cleared. If the 'cleared' item is set to v:true, then all the
5577 attributes of the highlight group are cleared.
5578
5579 The 'linksto' item can be used to link a highlight group to
5580 another highlight group. See |:highlight-link|.
5581
5582 Returns zero for success, -1 for failure.
5583
5584 Example(s): >
5585 " add bold attribute to the Visual highlight group
5586 :call hlset([#{name: 'Visual',
5587 \ term: #{reverse: 1 , bold: 1}}])
5588 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5589 :let l = hlget()
5590 :call hlset(l)
5591 " clear the Search highlight group
5592 :call hlset([#{name: 'Search', cleared: v:true}])
5593 " clear the 'term' attributes for a highlight group
5594 :call hlset([#{name: 'Title', term: {}}])
5595 " create the MyHlg group linking it to DiffAdd
5596 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5597 " remove the MyHlg group link
5598 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5599 " clear the attributes and a link
5600 :call hlset([#{name: 'MyHlg', cleared: v:true,
5601 \ linksto: 'NONE'}])
5602<
5603 Can also be used as a |method|: >
5604 GetAttrList()->hlset()
5605<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005606 Return type: |Number|
5607
5608hlID({name}) *hlID()*
5609 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005610 with name {name}. When the highlight group doesn't exist,
5611 zero is returned.
5612 This can be used to retrieve information about the highlight
5613 group. For example, to get the background color of the
5614 "Comment" group: >
5615 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5616< *highlightID()*
5617 Obsolete name: highlightID().
5618
5619 Can also be used as a |method|: >
5620 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005621<
5622 Return type: |Number|
5623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005624
5625hostname() *hostname()*
5626 The result is a String, which is the name of the machine on
5627 which Vim is currently running. Machine names greater than
5628 256 characters long are truncated.
5629
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005630 Return type: |String|
5631
5632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005633iconv({string}, {from}, {to}) *iconv()*
5634 The result is a String, which is the text {string} converted
5635 from encoding {from} to encoding {to}.
5636 When the conversion completely fails an empty string is
5637 returned. When some characters could not be converted they
5638 are replaced with "?".
5639 The encoding names are whatever the iconv() library function
5640 can accept, see ":!man 3 iconv".
5641 Most conversions require Vim to be compiled with the |+iconv|
5642 feature. Otherwise only UTF-8 to latin1 conversion and back
5643 can be done.
5644 This can be used to display messages with special characters,
5645 no matter what 'encoding' is set to. Write the message in
5646 UTF-8 and use: >
5647 echo iconv(utf8_str, "utf-8", &enc)
5648< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5649 from/to UCS-2 is automatically changed to use UTF-8. You
5650 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5651
5652 Can also be used as a |method|: >
5653 GetText()->iconv('latin1', 'utf-8')
5654<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005655 Return type: |String|
5656
5657
Ernie Raelc8e158b2024-07-09 18:39:52 +02005658id({item}) *id()*
5659 The result is a unique String associated with the {item} and
5660 not with the {item}'s contents. It is only valid while the
5661 {item} exists and is referenced. It is valid only in the
5662 instance of vim that produces the result. The whole idea is
5663 that `id({item})` does not change if the contents of {item}
5664 changes. This is useful as a `key` for creating an identity
5665 dictionary, rather than one based on equals.
5666
5667 This operation does not reference {item} and there is no
5668 function to convert the `id` to the {item}. It may be useful to
5669 have a map of `id` to {item}. The following >
5670 var referenceMap: dict<any>
5671 var id = item->id()
5672 referenceMap[id] = item
5673< prevents {item} from being garbage collected and provides a
5674 way to get the {item} from the `id`.
5675
5676 {item} may be a List, Dictionary, Object, Job, Channel or
5677 Blob. If the item is not a permitted type, or it is a null
5678 value, then an empty String is returned.
5679
5680 Can also be used as a |method|: >
5681 GetItem()->id()
5682<
5683 Return type: |String|
5684
5685
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005686indent({lnum}) *indent()*
5687 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005688 current buffer. The indent is counted in spaces, the value
5689 of 'tabstop' is relevant. {lnum} is used just like in
5690 |getline()|.
5691 When {lnum} is invalid -1 is returned. In |Vim9| script an
5692 error is given.
5693
5694 Can also be used as a |method|: >
5695 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005696<
5697 Return type: |Number|
5698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005699
5700index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005701 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005702 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005704 If {object} is a |List| return the lowest index where the item
5705 has a value equal to {expr}. There is no automatic
5706 conversion, so the String "4" is different from the Number 4.
5707 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005708 of 'ignorecase' is not used here, case matters as indicated by
5709 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005710
5711 If {object} is |Blob| return the lowest index where the byte
5712 value is equal to {expr}.
5713
5714 If {start} is given then start looking at the item with index
5715 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005717 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5718 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005719
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005720 -1 is returned when {expr} is not found in {object}.
5721 Example: >
5722 :let idx = index(words, "the")
5723 :if index(numbers, 123) >= 0
5724
5725< Can also be used as a |method|: >
5726 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005727<
5728 Return type: |Number|
5729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005730
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005731indexof({object}, {expr} [, {opts}]) *indexof()*
5732 Returns the index of an item in {object} where {expr} is
5733 v:true. {object} must be a |List| or a |Blob|.
5734
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005735 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005736 List until the expression is v:true and return the index of
5737 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005738
5739 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005740 Blob until the expression is v:true and return the index of
5741 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005742
5743 {expr} must be a |string| or |Funcref|.
5744
5745 If {expr} is a |string|: If {object} is a |List|, inside
5746 {expr} |v:key| has the index of the current List item and
5747 |v:val| has the value of the item. If {object} is a |Blob|,
5748 inside {expr} |v:key| has the index of the current byte and
5749 |v:val| has the byte value.
5750
5751 If {expr} is a |Funcref| it must take two arguments:
5752 1. the key or the index of the current item.
5753 2. the value of the current item.
5754 The function must return |TRUE| if the item is found and the
5755 search should stop.
5756
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005757 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005758 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005759 startidx start evaluating {expr} at the item with this
5760 index; may be negative for an item relative to
5761 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005762 Returns -1 when {expr} evaluates to v:false for all the items.
5763 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005764 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5765 :echo indexof(l, "v:val.n == 20")
5766 :echo indexof(l, {i, v -> v.n == 30})
5767 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005768
5769< Can also be used as a |method|: >
5770 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005771<
5772 Return type: |Number|
5773
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005775input({prompt} [, {text} [, {completion}]]) *input()*
5776 The result is a String, which is whatever the user typed on
5777 the command-line. The {prompt} argument is either a prompt
5778 string, or a blank string (for no prompt). A '\n' can be used
5779 in the prompt to start a new line.
5780 The highlighting set with |:echohl| is used for the prompt.
5781 The input is entered just like a command-line, with the same
5782 editing commands and mappings. There is a separate history
5783 for lines typed for input().
5784 Example: >
5785 :if input("Coffee or beer? ") == "beer"
5786 : echo "Cheers!"
5787 :endif
5788<
5789 If the optional {text} argument is present and not empty, this
5790 is used for the default reply, as if the user typed this.
5791 Example: >
5792 :let color = input("Color? ", "white")
5793
5794< The optional {completion} argument specifies the type of
5795 completion supported for the input. Without it completion is
5796 not performed. The supported completion types are the same as
5797 that can be supplied to a user-defined command using the
5798 "-complete=" argument. Refer to |:command-completion| for
5799 more information. Example: >
5800 let fname = input("File: ", "", "file")
5801<
5802 NOTE: This function must not be used in a startup file, for
5803 the versions that only run in GUI mode (e.g., the Win32 GUI).
5804 Note: When input() is called from within a mapping it will
5805 consume remaining characters from that mapping, because a
5806 mapping is handled like the characters were typed.
5807 Use |inputsave()| before input() and |inputrestore()|
5808 after input() to avoid that. Another solution is to avoid
5809 that further characters follow in the mapping, e.g., by using
5810 |:execute| or |:normal|.
5811
5812 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005813 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005814 :function GetFoo()
5815 : call inputsave()
5816 : let g:Foo = input("enter search pattern: ")
5817 : call inputrestore()
5818 :endfunction
5819
5820< Can also be used as a |method|: >
5821 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005822<
5823 Return type: |String|
5824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005825
5826inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5827 Like |input()|, but when the GUI is running and text dialogs
5828 are supported, a dialog window pops up to input the text.
5829 Example: >
5830 :let n = inputdialog("value for shiftwidth", shiftwidth())
5831 :if n != ""
5832 : let &sw = n
5833 :endif
5834< When the dialog is cancelled {cancelreturn} is returned. When
5835 omitted an empty string is returned.
5836 Hitting <Enter> works like pressing the OK button. Hitting
5837 <Esc> works like pressing the Cancel button.
5838 NOTE: Command-line completion is not supported.
5839
5840 Can also be used as a |method|: >
5841 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005842<
5843 Return type: |String|
5844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005845
5846inputlist({textlist}) *inputlist()*
5847 {textlist} must be a |List| of strings. This |List| is
5848 displayed, one string per line. The user will be prompted to
5849 enter a number, which is returned.
5850 The user can also select an item by clicking on it with the
5851 mouse, if the mouse is enabled in the command line ('mouse' is
5852 "a" or includes "c"). For the first string 0 is returned.
5853 When clicking above the first item a negative number is
5854 returned. When clicking on the prompt one more than the
5855 length of {textlist} is returned.
5856 Make sure {textlist} has less than 'lines' entries, otherwise
5857 it won't work. It's a good idea to put the entry number at
5858 the start of the string. And put a prompt in the first item.
5859 Example: >
5860 let color = inputlist(['Select color:', '1. red',
5861 \ '2. green', '3. blue'])
5862
5863< Can also be used as a |method|: >
5864 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005865<
5866 Return type: |Number|
5867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005868
5869inputrestore() *inputrestore()*
5870 Restore typeahead that was saved with a previous |inputsave()|.
5871 Should be called the same number of times inputsave() is
5872 called. Calling it more often is harmless though.
5873 Returns TRUE when there is nothing to restore, FALSE otherwise.
5874
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005875 Return type: |Number|
5876
5877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005878inputsave() *inputsave()*
5879 Preserve typeahead (also from mappings) and clear it, so that
5880 a following prompt gets input from the user. Should be
5881 followed by a matching inputrestore() after the prompt. Can
5882 be used several times, in which case there must be just as
5883 many inputrestore() calls.
5884 Returns TRUE when out of memory, FALSE otherwise.
5885
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005886 Return type: |Number|
5887
5888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005889inputsecret({prompt} [, {text}]) *inputsecret()*
5890 This function acts much like the |input()| function with but
5891 two exceptions:
5892 a) the user's response will be displayed as a sequence of
5893 asterisks ("*") thereby keeping the entry secret, and
5894 b) the user's response will not be recorded on the input
5895 |history| stack.
5896 The result is a String, which is whatever the user actually
5897 typed on the command-line in response to the issued prompt.
5898 NOTE: Command-line completion is not supported.
5899
5900 Can also be used as a |method|: >
5901 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005902<
5903 Return type: |String|
5904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005905
5906insert({object}, {item} [, {idx}]) *insert()*
5907 When {object} is a |List| or a |Blob| insert {item} at the start
5908 of it.
5909
5910 If {idx} is specified insert {item} before the item with index
5911 {idx}. If {idx} is zero it goes before the first item, just
5912 like omitting {idx}. A negative {idx} is also possible, see
5913 |list-index|. -1 inserts just before the last item.
5914
5915 Returns the resulting |List| or |Blob|. Examples: >
5916 :let mylist = insert([2, 3, 5], 1)
5917 :call insert(mylist, 4, -1)
5918 :call insert(mylist, 6, len(mylist))
5919< The last example can be done simpler with |add()|.
5920 Note that when {item} is a |List| it is inserted as a single
5921 item. Use |extend()| to concatenate |Lists|.
5922
5923 Can also be used as a |method|: >
5924 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005925<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005926 Return type: |Number|
5927
5928
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005929 *instanceof()* *E614* *E616* *E693*
5930instanceof({object}, {class})
5931 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005932 argument is a direct or indirect instance of a |Class|,
5933 |Interface|, or class |:type| alias specified by {class}.
5934 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005935 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005936 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005937 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005938
5939< Can also be used as a |method|: >
5940 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005941<
5942 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005943
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005944interrupt() *interrupt()*
5945 Interrupt script execution. It works more or less like the
5946 user typing CTRL-C, most commands won't execute and control
5947 returns to the user. This is useful to abort execution
5948 from lower down, e.g. in an autocommand. Example: >
5949 :function s:check_typoname(file)
5950 : if fnamemodify(a:file, ':t') == '['
5951 : echomsg 'Maybe typo'
5952 : call interrupt()
5953 : endif
5954 :endfunction
5955 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005956<
5957 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005958
5959invert({expr}) *invert()*
5960 Bitwise invert. The argument is converted to a number. A
5961 List, Dict or Float argument causes an error. Example: >
5962 :let bits = invert(bits)
5963< Can also be used as a |method|: >
5964 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005965<
5966 Return type: |Number|
5967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005968
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005969isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005970 The result is a Number, which is |TRUE| when {path} is an
5971 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005972 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005973 On MS-Windows, it is considered absolute when it starts with an
5974 optional drive prefix and is followed by a '\' or '/'. UNC paths
5975 are always absolute.
5976 Example: >
5977 echo isabsolutepath('/usr/share/') " 1
5978 echo isabsolutepath('./foobar') " 0
5979 echo isabsolutepath('C:\Windows') " 1
5980 echo isabsolutepath('foobar') " 0
5981 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005982<
LemonBoydca1d402022-04-28 15:26:33 +01005983 Can also be used as a |method|: >
5984 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005985<
5986 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005987
5988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005989isdirectory({directory}) *isdirectory()*
5990 The result is a Number, which is |TRUE| when a directory
5991 with the name {directory} exists. If {directory} doesn't
5992 exist, or isn't a directory, the result is |FALSE|. {directory}
5993 is any expression, which is used as a String.
5994
5995 Can also be used as a |method|: >
5996 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005997<
5998 Return type: |Number|
5999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006000
6001isinf({expr}) *isinf()*
6002 Return 1 if {expr} is a positive infinity, or -1 a negative
6003 infinity, otherwise 0. >
6004 :echo isinf(1.0 / 0.0)
6005< 1 >
6006 :echo isinf(-1.0 / 0.0)
6007< -1
6008
6009 Can also be used as a |method|: >
6010 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006011<
6012 Return type: |Number|
6013
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006014
6015islocked({expr}) *islocked()* *E786*
6016 The result is a Number, which is |TRUE| when {expr} is the
6017 name of a locked variable.
6018 The string argument {expr} must be the name of a variable,
6019 |List| item or |Dictionary| entry, not the variable itself!
6020 Example: >
6021 :let alist = [0, ['a', 'b'], 2, 3]
6022 :lockvar 1 alist
6023 :echo islocked('alist') " 1
6024 :echo islocked('alist[1]') " 0
6025
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006026< When {expr} is a variable that does not exist -1 is returned.
6027 If {expr} uses a range, list or dict index that is out of
6028 range or does not exist you get an error message. Use
6029 |exists()| to check for existence.
6030 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006031
6032 Can also be used as a |method|: >
6033 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006034<
6035 Return type: |Number|
6036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006037
6038isnan({expr}) *isnan()*
6039 Return |TRUE| if {expr} is a float with value NaN. >
6040 echo isnan(0.0 / 0.0)
6041< 1
6042
6043 Can also be used as a |method|: >
6044 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006045<
6046 Return type: |Number|
6047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006048
6049items({dict}) *items()*
6050 Return a |List| with all the key-value pairs of {dict}. Each
6051 |List| item is a list with two items: the key of a {dict}
6052 entry and the value of this entry. The |List| is in arbitrary
6053 order. Also see |keys()| and |values()|.
6054 Example: >
6055 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006056 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006057 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006058<
6059 A List or a String argument is also supported. In these
6060 cases, items() returns a List with the index and the value at
6061 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006062
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006063 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006064 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006065<
6066 Return type: list<list<any>> or list<any>
6067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068
6069job_ functions are documented here: |job-functions-details|
6070
6071
6072join({list} [, {sep}]) *join()*
6073 Join the items in {list} together into one String.
6074 When {sep} is specified it is put in between the items. If
6075 {sep} is omitted a single space is used.
6076 Note that {sep} is not added at the end. You might want to
6077 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006078 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006079< String items are used as-is. |Lists| and |Dictionaries| are
6080 converted into a string like with |string()|.
6081 The opposite function is |split()|.
6082
6083 Can also be used as a |method|: >
6084 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006085<
6086 Return type: |String|
6087
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006088
6089js_decode({string}) *js_decode()*
6090 This is similar to |json_decode()| with these differences:
6091 - Object key names do not have to be in quotes.
6092 - Strings can be in single quotes.
6093 - Empty items in an array (between two commas) are allowed and
6094 result in v:none items.
6095
6096 Can also be used as a |method|: >
6097 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006098<
6099 Return type: any, depending on {varname}
6100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006101
6102js_encode({expr}) *js_encode()*
6103 This is similar to |json_encode()| with these differences:
6104 - Object key names are not in quotes.
6105 - v:none items in an array result in an empty item between
6106 commas.
6107 For example, the Vim object:
6108 [1,v:none,{"one":1},v:none] ~
6109 Will be encoded as:
6110 [1,,{one:1},,] ~
6111 While json_encode() would produce:
6112 [1,null,{"one":1},null] ~
6113 This encoding is valid for JavaScript. It is more efficient
6114 than JSON, especially when using an array with optional items.
6115
6116 Can also be used as a |method|: >
6117 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006118<
6119 Return type: |String|
6120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006121
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006122json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006123 This parses a JSON formatted string and returns the equivalent
6124 in Vim values. See |json_encode()| for the relation between
6125 JSON and Vim values.
6126 The decoding is permissive:
6127 - A trailing comma in an array and object is ignored, e.g.
6128 "[1, 2, ]" is the same as "[1, 2]".
6129 - Integer keys are accepted in objects, e.g. {1:2} is the
6130 same as {"1":2}.
6131 - More floating point numbers are recognized, e.g. "1." for
6132 "1.0", or "001.2" for "1.2". Special floating point values
6133 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6134 are accepted.
6135 - Leading zeroes in integer numbers are ignored, e.g. "012"
6136 for "12" or "-012" for "-12".
6137 - Capitalization is ignored in literal names null, true or
6138 false, e.g. "NULL" for "null", "True" for "true".
6139 - Control characters U+0000 through U+001F which are not
6140 escaped in strings are accepted, e.g. " " (tab
6141 character in string) for "\t".
6142 - An empty JSON expression or made of only spaces is accepted
6143 and results in v:none.
6144 - Backslash in an invalid 2-character sequence escape is
6145 ignored, e.g. "\a" is decoded as "a".
6146 - A correct surrogate pair in JSON strings should normally be
6147 a 12 character sequence such as "\uD834\uDD1E", but
6148 json_decode() silently accepts truncated surrogate pairs
6149 such as "\uD834" or "\uD834\u"
6150 *E938*
6151 A duplicate key in an object, valid in rfc7159, is not
6152 accepted by json_decode() as the result must be a valid Vim
6153 type, e.g. this fails: {"a":"b", "a":"c"}
6154
6155 Can also be used as a |method|: >
6156 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006157<
6158 Return type: any, depending on {varname}
6159
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006160
6161json_encode({expr}) *json_encode()*
6162 Encode {expr} as JSON and return this as a string.
6163 The encoding is specified in:
6164 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006165 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006166 |Number| decimal number
6167 |Float| floating point number
6168 Float nan "NaN"
6169 Float inf "Infinity"
6170 Float -inf "-Infinity"
6171 |String| in double quotes (possibly null)
6172 |Funcref| not possible, error
6173 |List| as an array (possibly null); when
6174 used recursively: []
6175 |Dict| as an object (possibly null); when
6176 used recursively: {}
6177 |Blob| as an array of the individual bytes
6178 v:false "false"
6179 v:true "true"
6180 v:none "null"
6181 v:null "null"
6182 Note that NaN and Infinity are passed on as values. This is
6183 missing in the JSON standard, but several implementations do
6184 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006185 If a string contains an illegal character then the replacement
6186 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006187
6188 Can also be used as a |method|: >
6189 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006190<
6191 Return type: |String|
6192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006193
6194keys({dict}) *keys()*
6195 Return a |List| with all the keys of {dict}. The |List| is in
6196 arbitrary order. Also see |items()| and |values()|.
6197
6198 Can also be used as a |method|: >
6199 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006200<
6201 Return type: list<string>
6202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006203
zeertzjqcdc83932022-09-12 13:38:41 +01006204keytrans({string}) *keytrans()*
6205 Turn the internal byte representation of keys into a form that
6206 can be used for |:map|. E.g. >
6207 :let xx = "\<C-Home>"
6208 :echo keytrans(xx)
6209< <C-Home>
6210
6211 Can also be used as a |method|: >
6212 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006213<
6214 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006216
6217len({expr}) *len()* *E701*
6218 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006219 When {expr} is a String or a Number the length in bytes is
6220 used, as with |strlen()|.
6221 When {expr} is a |List| the number of items in the |List| is
6222 returned.
6223 When {expr} is a |Blob| the number of bytes is returned.
6224 When {expr} is a |Dictionary| the number of entries in the
6225 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006226 When {expr} is an |Object|, invokes the len() method in the
6227 object (if present) to get the length (|object-len()|).
6228 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006229
6230 Can also be used as a |method|: >
6231 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006232<
6233 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006234
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006235
6236 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006237libcall({libname}, {funcname}, {argument})
6238 Call function {funcname} in the run-time library {libname}
6239 with single argument {argument}.
6240 This is useful to call functions in a library that you
6241 especially made to be used with Vim. Since only one argument
6242 is possible, calling standard library functions is rather
6243 limited.
6244 The result is the String returned by the function. If the
6245 function returns NULL, this will appear as an empty string ""
6246 to Vim.
6247 If the function returns a number, use libcallnr()!
6248 If {argument} is a number, it is passed to the function as an
6249 int; if {argument} is a string, it is passed as a
6250 null-terminated string.
6251 This function will fail in |restricted-mode|.
6252
6253 libcall() allows you to write your own 'plug-in' extensions to
6254 Vim without having to recompile the program. It is NOT a
6255 means to call system functions! If you try to do so Vim will
6256 very probably crash.
6257
6258 For Win32, the functions you write must be placed in a DLL
6259 and use the normal C calling convention (NOT Pascal which is
6260 used in Windows System DLLs). The function must take exactly
6261 one parameter, either a character pointer or a long integer,
6262 and must return a character pointer or NULL. The character
6263 pointer returned must point to memory that will remain valid
6264 after the function has returned (e.g. in static data in the
6265 DLL). If it points to allocated memory, that memory will
6266 leak away. Using a static buffer in the function should work,
6267 it's then freed when the DLL is unloaded.
6268
6269 WARNING: If the function returns a non-valid pointer, Vim may
6270 crash! This also happens if the function returns a number,
6271 because Vim thinks it's a pointer.
6272 For Win32 systems, {libname} should be the filename of the DLL
6273 without the ".DLL" suffix. A full path is only required if
6274 the DLL is not in the usual places.
6275 For Unix: When compiling your own plugins, remember that the
6276 object code must be compiled as position-independent ('PIC').
6277 {only in Win32 and some Unix versions, when the |+libcall|
6278 feature is present}
6279 Examples: >
6280 :echo libcall("libc.so", "getenv", "HOME")
6281
6282< Can also be used as a |method|, the base is passed as the
6283 third argument: >
6284 GetValue()->libcall("libc.so", "getenv")
6285<
6286 *libcallnr()*
6287libcallnr({libname}, {funcname}, {argument})
6288 Just like |libcall()|, but used for a function that returns an
6289 int instead of a string.
6290 {only in Win32 on some Unix versions, when the |+libcall|
6291 feature is present}
6292 Examples: >
6293 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6294 :call libcallnr("libc.so", "printf", "Hello World!\n")
6295 :call libcallnr("libc.so", "sleep", 10)
6296<
6297 Can also be used as a |method|, the base is passed as the
6298 third argument: >
6299 GetValue()->libcallnr("libc.so", "printf")
6300<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006301 Return type: |String|
6302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006303
6304line({expr} [, {winid}]) *line()*
6305 The result is a Number, which is the line number of the file
6306 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006307 See |getpos()| for accepted positions.
6308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006309 To get the column number use |col()|. To get both use
6310 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006312 With the optional {winid} argument the values are obtained for
6313 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006314
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006315 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006316
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006317 Examples: >
6318 line(".") line number of the cursor
6319 line(".", winid) idem, in window "winid"
6320 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006321 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006322<
6323 To jump to the last known position when opening a file see
6324 |last-position-jump|.
6325
6326 Can also be used as a |method|: >
6327 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006328<
6329 Return type: |Number|
6330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006331
6332line2byte({lnum}) *line2byte()*
6333 Return the byte count from the start of the buffer for line
6334 {lnum}. This includes the end-of-line character, depending on
6335 the 'fileformat' option for the current buffer. The first
6336 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6337 This can also be used to get the byte count for the line just
6338 below the last line: >
6339 line2byte(line("$") + 1)
6340< This is the buffer size plus one. If 'fileencoding' is empty
6341 it is the file size plus one. {lnum} is used like with
6342 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6343 feature has been disabled at compile time, -1 is returned.
6344 Also see |byte2line()|, |go| and |:goto|.
6345
6346 Can also be used as a |method|: >
6347 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006348<
6349 Return type: |Number|
6350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006351
6352lispindent({lnum}) *lispindent()*
6353 Get the amount of indent for line {lnum} according the lisp
6354 indenting rules, as with 'lisp'.
6355 The indent is counted in spaces, the value of 'tabstop' is
6356 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006357 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006358 error is given.
6359
6360 Can also be used as a |method|: >
6361 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006362<
6363 Return type: |Number|
6364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006365
6366list2blob({list}) *list2blob()*
6367 Return a Blob concatenating all the number values in {list}.
6368 Examples: >
6369 list2blob([1, 2, 3, 4]) returns 0z01020304
6370 list2blob([]) returns 0z
6371< Returns an empty Blob on error. If one of the numbers is
6372 negative or more than 255 error *E1239* is given.
6373
6374 |blob2list()| does the opposite.
6375
6376 Can also be used as a |method|: >
6377 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006378<
6379 Return type: |Blob|
6380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006381
6382list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006383 Convert each number in {list} to a character string and
6384 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006385 list2str([32]) returns " "
6386 list2str([65, 66, 67]) returns "ABC"
6387< The same can be done (slowly) with: >
6388 join(map(list, {nr, val -> nr2char(val)}), '')
6389< |str2list()| does the opposite.
6390
6391 When {utf8} is omitted or zero, the current 'encoding' is used.
6392 When {utf8} is TRUE, always return UTF-8 characters.
6393 With UTF-8 composing characters work as expected: >
6394 list2str([97, 769]) returns "á"
6395<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006396 Returns an empty string on error.
6397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006398 Can also be used as a |method|: >
6399 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006400<
6401 Return type: |String|
6402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006403
6404listener_add({callback} [, {buf}]) *listener_add()*
6405 Add a callback function that will be invoked when changes have
6406 been made to buffer {buf}.
6407 {buf} refers to a buffer name or number. For the accepted
6408 values, see |bufname()|. When {buf} is omitted the current
6409 buffer is used.
6410 Returns a unique ID that can be passed to |listener_remove()|.
6411
6412 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006413 bufnr the buffer that was changed
6414 start first changed line number
6415 end first line number below the change
6416 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006417 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006418 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006419
6420 Example: >
6421 func Listener(bufnr, start, end, added, changes)
6422 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6423 endfunc
6424 call listener_add('Listener', bufnr)
6425
Bram Moolenaar944697a2022-02-20 19:48:20 +00006426< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427 dictionary with these entries:
6428 lnum the first line number of the change
6429 end the first line below the change
6430 added number of lines added; negative if lines were
6431 deleted
6432 col first column in "lnum" that was affected by
6433 the change; one if unknown or the whole line
6434 was affected; this is a byte index, first
6435 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006436 When lines are inserted (not when a line is split, e.g. by
6437 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006438 lnum line above which the new line is added
6439 end equal to "lnum"
6440 added number of lines inserted
6441 col 1
6442 When lines are deleted the values are:
6443 lnum the first deleted line
6444 end the line below the first deleted line, before
6445 the deletion was done
6446 added negative, number of lines deleted
6447 col 1
6448 When lines are changed:
6449 lnum the first changed line
6450 end the line below the last changed line
6451 added 0
6452 col first column with a change or 1
6453
6454 The entries are in the order the changes were made, thus the
6455 most recent change is at the end. The line numbers are valid
6456 when the callback is invoked, but later changes may make them
6457 invalid, thus keeping a copy for later might not work.
6458
6459 The {callback} is invoked just before the screen is updated,
6460 when |listener_flush()| is called or when a change is being
6461 made that changes the line count in a way it causes a line
6462 number in the list of changes to become invalid.
6463
6464 The {callback} is invoked with the text locked, see
6465 |textlock|. If you do need to make changes to the buffer, use
6466 a timer to do this later |timer_start()|.
6467
6468 The {callback} is not invoked when the buffer is first loaded.
6469 Use the |BufReadPost| autocmd event to handle the initial text
6470 of a buffer.
6471 The {callback} is also not invoked when the buffer is
6472 unloaded, use the |BufUnload| autocmd event for that.
6473
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006474 Returns zero if {callback} or {buf} is invalid.
6475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476 Can also be used as a |method|, the base is passed as the
6477 second argument: >
6478 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006479<
6480 Return type: |Number|
6481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006482
6483listener_flush([{buf}]) *listener_flush()*
6484 Invoke listener callbacks for buffer {buf}. If there are no
6485 pending changes then no callbacks are invoked.
6486
6487 {buf} refers to a buffer name or number. For the accepted
6488 values, see |bufname()|. When {buf} is omitted the current
6489 buffer is used.
6490
6491 Can also be used as a |method|: >
6492 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006493<
6494 Return type: |Number|
6495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006496
6497listener_remove({id}) *listener_remove()*
6498 Remove a listener previously added with listener_add().
6499 Returns FALSE when {id} could not be found, TRUE when {id} was
6500 removed.
6501
6502 Can also be used as a |method|: >
6503 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006504<
6505 Return type: |Number|
6506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006507
6508localtime() *localtime()*
6509 Return the current time, measured as seconds since 1st Jan
6510 1970. See also |strftime()|, |strptime()| and |getftime()|.
6511
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006512 Return type: |Number|
6513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006514
6515log({expr}) *log()*
6516 Return the natural logarithm (base e) of {expr} as a |Float|.
6517 {expr} must evaluate to a |Float| or a |Number| in the range
6518 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006519 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006520 Examples: >
6521 :echo log(10)
6522< 2.302585 >
6523 :echo log(exp(5))
6524< 5.0
6525
6526 Can also be used as a |method|: >
6527 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006528<
6529 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006530
6531
6532log10({expr}) *log10()*
6533 Return the logarithm of Float {expr} to base 10 as a |Float|.
6534 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006535 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006536 Examples: >
6537 :echo log10(1000)
6538< 3.0 >
6539 :echo log10(0.01)
6540< -2.0
6541
6542 Can also be used as a |method|: >
6543 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006544<
6545 Return type: |Float|
6546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006547
6548luaeval({expr} [, {expr}]) *luaeval()*
6549 Evaluate Lua expression {expr} and return its result converted
6550 to Vim data structures. Second {expr} may hold additional
6551 argument accessible as _A inside first {expr}.
6552 Strings are returned as they are.
6553 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006554 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006555 Dictionaries and lists obtained by vim.eval() are returned
6556 as-is.
6557 Other objects are returned as zero without any errors.
6558 See |lua-luaeval| for more details.
6559 Note that in a `:def` function local variables are not visible
6560 to {expr}.
6561
6562 Can also be used as a |method|: >
6563 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006564<
6565 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006566
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006567 {only available when compiled with the |+lua| feature}
6568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006569
6570map({expr1}, {expr2}) *map()*
6571 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006572 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006573 item in {expr1} with the result of evaluating {expr2}.
6574 For a |Blob| each byte is replaced.
6575 For a |String|, each character, including composing
6576 characters, is replaced.
6577 If the item type changes you may want to use |mapnew()| to
6578 create a new List or Dictionary. This is required when using
6579 Vim9 script.
6580
6581 {expr2} must be a |String| or |Funcref|.
6582
6583 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6584 of the current item. For a |Dictionary| |v:key| has the key
6585 of the current item and for a |List| |v:key| has the index of
6586 the current item. For a |Blob| |v:key| has the index of the
6587 current byte. For a |String| |v:key| has the index of the
6588 current character.
6589 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006590 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006591< This puts "> " before and " <" after each item in "mylist".
6592
6593 Note that {expr2} is the result of an expression and is then
6594 used as an expression again. Often it is good to use a
6595 |literal-string| to avoid having to double backslashes. You
6596 still have to double ' quotes
6597
6598 If {expr2} is a |Funcref| it is called with two arguments:
6599 1. The key or the index of the current item.
6600 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006601 With a legacy script lambda you don't get an error if it only
6602 accepts one argument, but with a Vim9 lambda you get "E1106:
6603 One argument too many", the number of arguments must match.
6604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006605 The function must return the new value of the item. Example
6606 that changes each value by "key-value": >
6607 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006608 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006609 endfunc
6610 call map(myDict, function('KeyValue'))
6611< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006612 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006613< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006614 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006615< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006616 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006617<
6618 The operation is done in-place for a |List| and |Dictionary|.
6619 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006620 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006621
6622< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6623 or a new |Blob| or |String|.
6624 When an error is encountered while evaluating {expr2} no
6625 further items in {expr1} are processed.
6626 When {expr2} is a Funcref errors inside a function are ignored,
6627 unless it was defined with the "abort" flag.
6628
6629 Can also be used as a |method|: >
6630 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006631<
6632 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6633 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006634
6635
6636maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6637 When {dict} is omitted or zero: Return the rhs of mapping
6638 {name} in mode {mode}. The returned String has special
6639 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006640 listing. When {dict} is TRUE a dictionary is returned, see
6641 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006642
6643 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006644 returned if {dict} is FALSE, otherwise returns an empty Dict.
6645 When the mapping for {name} is empty, then "<Nop>" is
6646 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006647
6648 The {name} can have special key names, like in the ":map"
6649 command.
6650
6651 {mode} can be one of these strings:
6652 "n" Normal
6653 "v" Visual (including Select)
6654 "o" Operator-pending
6655 "i" Insert
6656 "c" Cmd-line
6657 "s" Select
6658 "x" Visual
6659 "l" langmap |language-mapping|
6660 "t" Terminal-Job
6661 "" Normal, Visual and Operator-pending
6662 When {mode} is omitted, the modes for "" are used.
6663
6664 When {abbr} is there and it is |TRUE| use abbreviations
6665 instead of mappings.
6666
6667 When {dict} is there and it is |TRUE| return a dictionary
6668 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006669 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006670 "lhs" The {lhs} of the mapping as it would be typed
6671 "lhsraw" The {lhs} of the mapping as raw bytes
6672 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6673 form, only present when it differs from "lhsraw"
6674 "rhs" The {rhs} of the mapping as typed.
6675 "silent" 1 for a |:map-silent| mapping, else 0.
6676 "noremap" 1 if the {rhs} of the mapping is not remappable.
6677 "script" 1 if mapping was defined with <script>.
6678 "expr" 1 for an expression mapping (|:map-<expr>|).
6679 "buffer" 1 for a buffer local mapping (|:map-local|).
6680 "mode" Modes for which the mapping is defined. In
6681 addition to the modes mentioned above, these
6682 characters will be used:
6683 " " Normal, Visual and Operator-pending
6684 "!" Insert and Commandline mode
6685 (|mapmode-ic|)
6686 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006687 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006688 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006689 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006690 "lnum" The line number in "sid", zero if unknown.
6691 "nowait" Do not wait for other, longer mappings.
6692 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006693 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006694 "mode_bits" Vim's internal binary representation of "mode".
6695 |mapset()| ignores this; only "mode" is used.
6696 See |maplist()| for usage examples. The values
6697 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006698
6699 The dictionary can be used to restore a mapping with
6700 |mapset()|.
6701
6702 The mappings local to the current buffer are checked first,
6703 then the global mappings.
6704 This function can be used to map a key even when it's already
6705 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006706 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006707
6708< Can also be used as a |method|: >
6709 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006710<
6711 Return type: |String| or dict<any> depending on {dict}
6712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006713
6714mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6715 Check if there is a mapping that matches with {name} in mode
6716 {mode}. See |maparg()| for {mode} and special names in
6717 {name}.
6718 When {abbr} is there and it is |TRUE| use abbreviations
6719 instead of mappings.
6720 A match happens with a mapping that starts with {name} and
6721 with a mapping which is equal to the start of {name}.
6722
6723 matches mapping "a" "ab" "abc" ~
6724 mapcheck("a") yes yes yes
6725 mapcheck("abc") yes yes yes
6726 mapcheck("ax") yes no no
6727 mapcheck("b") no no no
6728
6729 The difference with maparg() is that mapcheck() finds a
6730 mapping that matches with {name}, while maparg() only finds a
6731 mapping for {name} exactly.
6732 When there is no mapping that starts with {name}, an empty
6733 String is returned. If there is one, the RHS of that mapping
6734 is returned. If there are several mappings that start with
6735 {name}, the RHS of one of them is returned. This will be
6736 "<Nop>" if the RHS is empty.
6737 The mappings local to the current buffer are checked first,
6738 then the global mappings.
6739 This function can be used to check if a mapping can be added
6740 without being ambiguous. Example: >
6741 :if mapcheck("_vv") == ""
6742 : map _vv :set guifont=7x13<CR>
6743 :endif
6744< This avoids adding the "_vv" mapping when there already is a
6745 mapping for "_v" or for "_vvv".
6746
6747 Can also be used as a |method|: >
6748 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006749<
6750 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006751
6752
Ernie Rael09661202022-04-25 14:40:44 +01006753maplist([{abbr}]) *maplist()*
6754 Returns a |List| of all mappings. Each List item is a |Dict|,
6755 the same as what is returned by |maparg()|, see
6756 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6757 abbreviations instead of mappings.
6758
6759 Example to show all mappings with 'MultiMatch' in rhs: >
6760 vim9script
6761 echo maplist()->filter(
6762 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006763< It can be tricky to find mappings for particular |:map-modes|.
6764 |mapping-dict|'s "mode_bits" can simplify this. For example,
6765 the mode_bits for Normal, Insert or Command-line modes are
6766 0x19. To find all the mappings available in those modes you
6767 can do: >
6768 vim9script
6769 var saved_maps = []
6770 for m in maplist()
6771 if and(m.mode_bits, 0x19) != 0
6772 saved_maps->add(m)
6773 endif
6774 endfor
6775 echo saved_maps->mapnew((_, m) => m.lhs)
6776< The values of the mode_bits are defined in Vim's src/vim.h
6777 file and they can be discovered at runtime using
6778 |:map-commands| and "maplist()". Example: >
6779 vim9script
6780 omap xyzzy <Nop>
6781 var op_bit = maplist()->filter(
6782 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6783 ounmap xyzzy
6784 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006785<
6786 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006787
6788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006789mapnew({expr1}, {expr2}) *mapnew()*
6790 Like |map()| but instead of replacing items in {expr1} a new
6791 List or Dictionary is created and returned. {expr1} remains
6792 unchanged. Items can still be changed by {expr2}, if you
6793 don't want that use |deepcopy()| first.
6794
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006795 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6796 depending on {expr1}
6797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006798
6799mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006800mapset({dict})
6801 Restore a mapping from a dictionary, possibly returned by
6802 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6803 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006804 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006805 feature allows copying mappings from one buffer to another.
6806 The dict.mode value may restore a single mapping that covers
6807 more than one mode, like with mode values of '!', ' ', 'nox',
6808 or 'v'. *E1276*
6809
6810 In the first form, {mode} and {abbr} should be the same as
6811 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006812 {mode} is used to define the mode in which the mapping is set,
6813 not the "mode" entry in {dict}.
6814 Example for saving and restoring a mapping: >
6815 let save_map = maparg('K', 'n', 0, 1)
6816 nnoremap K somethingelse
6817 ...
6818 call mapset('n', 0, save_map)
6819< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006820 e.g. with `:map!`, you need to save/restore the mapping for
6821 all of them, when they might differ.
6822
6823 In the second form, with {dict} as the only argument, mode
6824 and abbr are taken from the dict.
6825 Example: >
6826 vim9script
6827 var save_maps = maplist()->filter(
6828 (_, m) => m.lhs == 'K')
6829 nnoremap K somethingelse
6830 cnoremap K somethingelse2
6831 # ...
6832 unmap K
6833 for d in save_maps
6834 mapset(d)
6835 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006836<
6837 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006838
6839
6840match({expr}, {pat} [, {start} [, {count}]]) *match()*
6841 When {expr} is a |List| then this returns the index of the
6842 first item where {pat} matches. Each item is used as a
6843 String, |Lists| and |Dictionaries| are used as echoed.
6844
6845 Otherwise, {expr} is used as a String. The result is a
6846 Number, which gives the index (byte offset) in {expr} where
6847 {pat} matches.
6848
6849 A match at the first character or |List| item returns zero.
6850 If there is no match -1 is returned.
6851
6852 For getting submatches see |matchlist()|.
6853 Example: >
6854 :echo match("testing", "ing") " results in 4
6855 :echo match([1, 'x'], '\a') " results in 1
6856< See |string-match| for how {pat} is used.
6857 *strpbrk()*
6858 Vim doesn't have a strpbrk() function. But you can do: >
6859 :let sepidx = match(line, '[.,;: \t]')
6860< *strcasestr()*
6861 Vim doesn't have a strcasestr() function. But you can add
6862 "\c" to the pattern to ignore case: >
6863 :let idx = match(haystack, '\cneedle')
6864<
6865 If {start} is given, the search starts from byte index
6866 {start} in a String or item {start} in a |List|.
6867 The result, however, is still the index counted from the
6868 first character/item. Example: >
6869 :echo match("testing", "ing", 2)
6870< result is again "4". >
6871 :echo match("testing", "ing", 4)
6872< result is again "4". >
6873 :echo match("testing", "t", 2)
6874< result is "3".
6875 For a String, if {start} > 0 then it is like the string starts
6876 {start} bytes later, thus "^" will match at {start}. Except
6877 when {count} is given, then it's like matches before the
6878 {start} byte are ignored (this is a bit complicated to keep it
6879 backwards compatible).
6880 For a String, if {start} < 0, it will be set to 0. For a list
6881 the index is counted from the end.
6882 If {start} is out of range ({start} > strlen({expr}) for a
6883 String or {start} > len({expr}) for a |List|) -1 is returned.
6884
6885 When {count} is given use the {count}'th match. When a match
6886 is found in a String the search for the next one starts one
6887 character further. Thus this example results in 1: >
6888 echo match("testing", "..", 0, 2)
6889< In a |List| the search continues in the next item.
6890 Note that when {count} is added the way {start} works changes,
6891 see above.
6892
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006893 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006894 See |pattern| for the patterns that are accepted.
6895 The 'ignorecase' option is used to set the ignore-caseness of
6896 the pattern. 'smartcase' is NOT used. The matching is always
6897 done like 'magic' is set and 'cpoptions' is empty.
6898 Note that a match at the start is preferred, thus when the
6899 pattern is using "*" (any number of matches) it tends to find
6900 zero matches at the start instead of a number of matches
6901 further down in the text.
6902
6903 Can also be used as a |method|: >
6904 GetText()->match('word')
6905 GetList()->match('word')
6906<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006907 Return type: |Number|
6908
6909
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006910 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006911matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6912 Defines a pattern to be highlighted in the current window (a
6913 "match"). It will be highlighted with {group}. Returns an
6914 identification number (ID), which can be used to delete the
6915 match using |matchdelete()|. The ID is bound to the window.
6916 Matching is case sensitive and magic, unless case sensitivity
6917 or magicness are explicitly overridden in {pattern}. The
6918 'magic', 'smartcase' and 'ignorecase' options are not used.
6919 The "Conceal" value is special, it causes the match to be
6920 concealed.
6921
6922 The optional {priority} argument assigns a priority to the
6923 match. A match with a high priority will have its
6924 highlighting overrule that of a match with a lower priority.
6925 A priority is specified as an integer (negative numbers are no
6926 exception). If the {priority} argument is not specified, the
6927 default priority is 10. The priority of 'hlsearch' is zero,
6928 hence all matches with a priority greater than zero will
6929 overrule it. Syntax highlighting (see 'syntax') is a separate
6930 mechanism, and regardless of the chosen priority a match will
6931 always overrule syntax highlighting.
6932
6933 The optional {id} argument allows the request for a specific
6934 match ID. If a specified ID is already taken, an error
6935 message will appear and the match will not be added. An ID
6936 is specified as a positive integer (zero excluded). IDs 1, 2
6937 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006938 respectively. 3 is reserved for use by the |matchparen|
6939 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006940 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006941 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006942
6943 The optional {dict} argument allows for further custom
6944 values. Currently this is used to specify a match specific
6945 conceal character that will be shown for |hl-Conceal|
6946 highlighted matches. The dict can have the following members:
6947
6948 conceal Special character to show instead of the
6949 match (only for |hl-Conceal| highlighted
6950 matches, see |:syn-cchar|)
6951 window Instead of the current window use the
6952 window with this number or window ID.
6953
6954 The number of matches is not limited, as it is the case with
6955 the |:match| commands.
6956
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006957 Returns -1 on error.
6958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006959 Example: >
6960 :highlight MyGroup ctermbg=green guibg=green
6961 :let m = matchadd("MyGroup", "TODO")
6962< Deletion of the pattern: >
6963 :call matchdelete(m)
6964
6965< A list of matches defined by |matchadd()| and |:match| are
6966 available from |getmatches()|. All matches can be deleted in
6967 one operation by |clearmatches()|.
6968
6969 Can also be used as a |method|: >
6970 GetGroup()->matchadd('TODO')
6971<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006972 Return type: |Number|
6973
6974
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006975 *matchaddpos()*
6976matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6977 Same as |matchadd()|, but requires a list of positions {pos}
6978 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02006979 because it does not handle regular expressions and it sets
6980 buffer line boundaries to redraw screen. It is supposed to be
6981 used when fast match additions and deletions are required, for
6982 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006983
6984 {pos} is a list of positions. Each position can be one of
6985 these:
6986 - A number. This whole line will be highlighted. The first
6987 line has number 1.
6988 - A list with one number, e.g., [23]. The whole line with this
6989 number will be highlighted.
6990 - A list with two numbers, e.g., [23, 11]. The first number is
6991 the line number, the second one is the column number (first
6992 column is 1, the value must correspond to the byte index as
6993 |col()| would return). The character at this position will
6994 be highlighted.
6995 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6996 the third number gives the length of the highlight in bytes.
6997
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006998 Returns -1 on error.
6999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007000 Example: >
7001 :highlight MyGroup ctermbg=green guibg=green
7002 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7003< Deletion of the pattern: >
7004 :call matchdelete(m)
7005
7006< Matches added by |matchaddpos()| are returned by
7007 |getmatches()|.
7008
7009 Can also be used as a |method|: >
7010 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007011<
7012 Return type: |Number|
7013
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007014
7015matcharg({nr}) *matcharg()*
7016 Selects the {nr} match item, as set with a |:match|,
7017 |:2match| or |:3match| command.
7018 Return a |List| with two elements:
7019 The name of the highlight group used
7020 The pattern used.
7021 When {nr} is not 1, 2 or 3 returns an empty |List|.
7022 When there is no match item set returns ['', ''].
7023 This is useful to save and restore a |:match|.
7024 Highlighting matches using the |:match| commands are limited
7025 to three matches. |matchadd()| does not have this limitation.
7026
7027 Can also be used as a |method|: >
7028 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007029<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007030 Return type: list<string>
7031
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007032 *matchbufline()*
7033matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7034 Returns the |List| of matches in lines from {lnum} to {end} in
7035 buffer {buf} where {pat} matches.
7036
7037 {lnum} and {end} can either be a line number or the string "$"
7038 to refer to the last line in {buf}.
7039
7040 The {dict} argument supports following items:
7041 submatches include submatch information (|/\(|)
7042
7043 For each match, a |Dict| with the following items is returned:
7044 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007045 lnum line number where there is a match
7046 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007047 Note that there can be multiple matches in a single line.
7048
7049 This function works only for loaded buffers. First call
7050 |bufload()| if needed.
7051
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007052 See |match-pattern| for information about the effect of some
7053 option settings on the pattern.
7054
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007055 When {buf} is not a valid buffer, the buffer is not loaded or
7056 {lnum} or {end} is not valid then an error is given and an
7057 empty |List| is returned.
7058
7059 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007060 " Assuming line 3 in buffer 5 contains "a"
7061 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7062 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7063 " Assuming line 4 in buffer 10 contains "tik tok"
7064 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7065 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007066<
7067 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007068 "\1", "\2", etc. are also returned. Example: >
7069 " Assuming line 2 in buffer 2 contains "acd"
7070 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007071 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007072 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007073< The "submatches" List always contains 9 items. If a submatch
7074 is not found, then an empty string is returned for that
7075 submatch.
7076
7077 Can also be used as a |method|: >
7078 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007079<
7080 Return type: list<dict<any>> or list<any>
7081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007082
7083matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
7084 Deletes a match with ID {id} previously defined by |matchadd()|
7085 or one of the |:match| commands. Returns 0 if successful,
7086 otherwise -1. See example for |matchadd()|. All matches can
7087 be deleted in one operation by |clearmatches()|.
7088 If {win} is specified, use the window with this number or
7089 window ID instead of the current window.
7090
7091 Can also be used as a |method|: >
7092 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007093<
7094 Return type: |Number|
7095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007096
7097matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7098 Same as |match()|, but return the index of first character
7099 after the match. Example: >
7100 :echo matchend("testing", "ing")
7101< results in "7".
7102 *strspn()* *strcspn()*
7103 Vim doesn't have a strspn() or strcspn() function, but you can
7104 do it with matchend(): >
7105 :let span = matchend(line, '[a-zA-Z]')
7106 :let span = matchend(line, '[^a-zA-Z]')
7107< Except that -1 is returned when there are no matches.
7108
7109 The {start}, if given, has the same meaning as for |match()|. >
7110 :echo matchend("testing", "ing", 2)
7111< results in "7". >
7112 :echo matchend("testing", "ing", 5)
7113< result is "-1".
7114 When {expr} is a |List| the result is equal to |match()|.
7115
7116 Can also be used as a |method|: >
7117 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007118<
7119 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007120
7121
7122matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7123 If {list} is a list of strings, then returns a |List| with all
7124 the strings in {list} that fuzzy match {str}. The strings in
7125 the returned list are sorted based on the matching score.
7126
7127 The optional {dict} argument always supports the following
7128 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007129 matchseq When this item is present return only matches
7130 that contain the characters in {str} in the
7131 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007132 limit Maximum number of matches in {list} to be
7133 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007134
7135 If {list} is a list of dictionaries, then the optional {dict}
7136 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007137 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007138 {str}. The value of this item should be a
7139 string.
7140 text_cb |Funcref| that will be called for every item
7141 in {list} to get the text for fuzzy matching.
7142 This should accept a dictionary item as the
7143 argument and return the text for that item to
7144 use for fuzzy matching.
7145
7146 {str} is treated as a literal string and regular expression
7147 matching is NOT supported. The maximum supported {str} length
7148 is 256.
7149
7150 When {str} has multiple words each separated by white space,
7151 then the list of strings that have all the words is returned.
7152
7153 If there are no matching strings or there is an error, then an
7154 empty list is returned. If length of {str} is greater than
7155 256, then returns an empty list.
7156
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007157 When {limit} is given, matchfuzzy() will find up to this
7158 number of matches in {list} and return them in sorted order.
7159
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007160 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007161 matching strings.
7162
7163 Example: >
7164 :echo matchfuzzy(["clay", "crow"], "cay")
7165< results in ["clay"]. >
7166 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7167< results in a list of buffer names fuzzy matching "ndl". >
7168 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7169< results in a list of buffer information dicts with buffer
7170 names fuzzy matching "ndl". >
7171 :echo getbufinfo()->matchfuzzy("spl",
7172 \ {'text_cb' : {v -> v.name}})
7173< results in a list of buffer information dicts with buffer
7174 names fuzzy matching "spl". >
7175 :echo v:oldfiles->matchfuzzy("test")
7176< results in a list of file names fuzzy matching "test". >
7177 :let l = readfile("buffer.c")->matchfuzzy("str")
7178< results in a list of lines in "buffer.c" fuzzy matching "str". >
7179 :echo ['one two', 'two one']->matchfuzzy('two one')
7180< results in ['two one', 'one two']. >
7181 :echo ['one two', 'two one']->matchfuzzy('two one',
7182 \ {'matchseq': 1})
7183< results in ['two one'].
7184
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007185 Return type: list<string> or list<any>
7186
7187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007188matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7189 Same as |matchfuzzy()|, but returns the list of matched
7190 strings, the list of character positions where characters
7191 in {str} matches and a list of matching scores. You can
7192 use |byteidx()| to convert a character position to a byte
7193 position.
7194
7195 If {str} matches multiple times in a string, then only the
7196 positions for the best match is returned.
7197
7198 If there are no matching strings or there is an error, then a
7199 list with three empty list items is returned.
7200
7201 Example: >
7202 :echo matchfuzzypos(['testing'], 'tsg')
7203< results in [['testing'], [[0, 2, 6]], [99]] >
7204 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7205< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7206 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7207< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007209 Return type: list<list<any>>
7210
7211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007212matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7213 Same as |match()|, but return a |List|. The first item in the
7214 list is the matched string, same as what matchstr() would
7215 return. Following items are submatches, like "\1", "\2", etc.
7216 in |:substitute|. When an optional submatch didn't match an
7217 empty string is used. Example: >
7218 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7219< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7220 When there is no match an empty list is returned.
7221
7222 You can pass in a List, but that is not very useful.
7223
7224 Can also be used as a |method|: >
7225 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007226<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007227 Return type: list<string> or list<any>
7228
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007229 *matchstrlist()*
7230matchstrlist({list}, {pat} [, {dict}])
7231 Returns the |List| of matches in {list} where {pat} matches.
7232 {list} is a |List| of strings. {pat} is matched against each
7233 string in {list}.
7234
7235 The {dict} argument supports following items:
7236 submatches include submatch information (|/\(|)
7237
7238 For each match, a |Dict| with the following items is returned:
7239 byteidx starting byte index of the match.
7240 idx index in {list} of the match.
7241 text matched string
7242 submatches a List of submatches. Present only if
7243 "submatches" is set to v:true in {dict}.
7244
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007245 See |match-pattern| for information about the effect of some
7246 option settings on the pattern.
7247
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007248 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007249 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7250 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7251 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7252 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007253<
7254 If "submatches" is present and is v:true, then submatches like
7255 "\1", "\2", etc. are also returned. Example: >
7256 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7257 \ #{submatches: v:true})
7258 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7259< The "submatches" List always contains 9 items. If a submatch
7260 is not found, then an empty string is returned for that
7261 submatch.
7262
7263 Can also be used as a |method|: >
7264 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007265<
7266 Return type: list<dict<any>> or list<any>
7267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007268
7269matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7270 Same as |match()|, but return the matched string. Example: >
7271 :echo matchstr("testing", "ing")
7272< results in "ing".
7273 When there is no match "" is returned.
7274 The {start}, if given, has the same meaning as for |match()|. >
7275 :echo matchstr("testing", "ing", 2)
7276< results in "ing". >
7277 :echo matchstr("testing", "ing", 5)
7278< result is "".
7279 When {expr} is a |List| then the matching item is returned.
7280 The type isn't changed, it's not necessarily a String.
7281
7282 Can also be used as a |method|: >
7283 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007284<
7285 Return type: |String|
7286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007287
7288matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7289 Same as |matchstr()|, but return the matched string, the start
7290 position and the end position of the match. Example: >
7291 :echo matchstrpos("testing", "ing")
7292< results in ["ing", 4, 7].
7293 When there is no match ["", -1, -1] is returned.
7294 The {start}, if given, has the same meaning as for |match()|. >
7295 :echo matchstrpos("testing", "ing", 2)
7296< results in ["ing", 4, 7]. >
7297 :echo matchstrpos("testing", "ing", 5)
7298< result is ["", -1, -1].
7299 When {expr} is a |List| then the matching item, the index
7300 of first item where {pat} matches, the start position and the
7301 end position of the match are returned. >
7302 :echo matchstrpos([1, '__x'], '\a')
7303< result is ["x", 1, 2, 3].
7304 The type isn't changed, it's not necessarily a String.
7305
7306 Can also be used as a |method|: >
7307 GetText()->matchstrpos('word')
7308<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007309 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007310
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007311
7312max({expr}) *max()*
7313 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007314 echo max([apples, pears, oranges])
7315
7316< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7317 it returns the maximum of all values in the Dictionary.
7318 If {expr} is neither a List nor a Dictionary, or one of the
7319 items in {expr} cannot be used as a Number this results in
7320 an error. An empty |List| or |Dictionary| results in zero.
7321
7322 Can also be used as a |method|: >
7323 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007324<
7325 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007326
7327
7328menu_info({name} [, {mode}]) *menu_info()*
7329 Return information about the specified menu {name} in
7330 mode {mode}. The menu name should be specified without the
7331 shortcut character ('&'). If {name} is "", then the top-level
7332 menu names are returned.
7333
7334 {mode} can be one of these strings:
7335 "n" Normal
7336 "v" Visual (including Select)
7337 "o" Operator-pending
7338 "i" Insert
7339 "c" Cmd-line
7340 "s" Select
7341 "x" Visual
7342 "t" Terminal-Job
7343 "" Normal, Visual and Operator-pending
7344 "!" Insert and Cmd-line
7345 When {mode} is omitted, the modes for "" are used.
7346
7347 Returns a |Dictionary| containing the following items:
7348 accel menu item accelerator text |menu-text|
7349 display display name (name without '&')
7350 enabled v:true if this menu item is enabled
7351 Refer to |:menu-enable|
7352 icon name of the icon file (for toolbar)
7353 |toolbar-icon|
7354 iconidx index of a built-in icon
7355 modes modes for which the menu is defined. In
7356 addition to the modes mentioned above, these
7357 characters will be used:
7358 " " Normal, Visual and Operator-pending
7359 name menu item name.
7360 noremenu v:true if the {rhs} of the menu item is not
7361 remappable else v:false.
7362 priority menu order priority |menu-priority|
7363 rhs right-hand-side of the menu item. The returned
7364 string has special characters translated like
7365 in the output of the ":menu" command listing.
7366 When the {rhs} of a menu item is empty, then
7367 "<Nop>" is returned.
7368 script v:true if script-local remapping of {rhs} is
7369 allowed else v:false. See |:menu-script|.
7370 shortcut shortcut key (character after '&' in
7371 the menu name) |menu-shortcut|
7372 silent v:true if the menu item is created
7373 with <silent> argument |:menu-silent|
7374 submenus |List| containing the names of
7375 all the submenus. Present only if the menu
7376 item has submenus.
7377
7378 Returns an empty dictionary if the menu item is not found.
7379
7380 Examples: >
7381 :echo menu_info('Edit.Cut')
7382 :echo menu_info('File.Save', 'n')
7383
7384 " Display the entire menu hierarchy in a buffer
7385 func ShowMenu(name, pfx)
7386 let m = menu_info(a:name)
7387 call append(line('$'), a:pfx .. m.display)
7388 for child in m->get('submenus', [])
7389 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7390 \ a:pfx .. ' ')
7391 endfor
7392 endfunc
7393 new
7394 for topmenu in menu_info('').submenus
7395 call ShowMenu(topmenu, '')
7396 endfor
7397<
7398 Can also be used as a |method|: >
7399 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007400<
7401 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007402
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007403min({expr}) *min()*
7404 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007405 echo min([apples, pears, oranges])
7406
7407< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7408 it returns the minimum of all values in the Dictionary.
7409 If {expr} is neither a List nor a Dictionary, or one of the
7410 items in {expr} cannot be used as a Number this results in
7411 an error. An empty |List| or |Dictionary| results in zero.
7412
7413 Can also be used as a |method|: >
7414 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007415<
7416 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007417
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007418
7419mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007420 Create directory {name}.
7421
Bram Moolenaar938ae282023-02-20 20:44:55 +00007422 When {flags} is present it must be a string. An empty string
7423 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007424
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007425 {flags} can contain these character flags:
7426 "p" intermediate directories will be created as necessary
7427 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007428 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007429 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007430 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007431
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007432 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007433 some directories may already exist. Only the first one that
7434 is created and what it contains is scheduled to be deleted.
7435 E.g. when using: >
7436 call mkdir('subdir/tmp/autoload', 'pR')
7437< and "subdir" already exists then "subdir/tmp" will be
7438 scheduled for deletion, like with: >
7439 defer delete('subdir/tmp', 'rf')
7440< Note that if scheduling the defer fails the directory is not
7441 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007442
7443 If {prot} is given it is used to set the protection bits of
7444 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7445 the user, readable for others). Use 0o700 to make it
7446 unreadable for others. This is only used for the last part of
7447 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7448 created with 0o755.
7449 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007450 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007451
7452< This function is not available in the |sandbox|.
7453
7454 There is no error if the directory already exists and the "p"
7455 flag is passed (since patch 8.0.1708). However, without the
7456 "p" option the call will fail.
7457
7458 The function result is a Number, which is TRUE if the call was
7459 successful or FALSE if the directory creation failed or partly
7460 failed.
7461
7462 Not available on all systems. To check use: >
7463 :if exists("*mkdir")
7464
7465< Can also be used as a |method|: >
7466 GetName()->mkdir()
7467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007468 Return type: |Number|
7469
7470
7471mode([{expr}]) *mode()*
7472 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007473 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007474 a non-empty String (|non-zero-arg|), then the full mode is
7475 returned, otherwise only the first letter is returned.
7476 Also see |state()|.
7477
7478 n Normal
7479 no Operator-pending
7480 nov Operator-pending (forced characterwise |o_v|)
7481 noV Operator-pending (forced linewise |o_V|)
7482 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7483 CTRL-V is one character
7484 niI Normal using |i_CTRL-O| in |Insert-mode|
7485 niR Normal using |i_CTRL-O| in |Replace-mode|
7486 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7487 nt Terminal-Normal (insert goes to Terminal-Job mode)
7488 v Visual by character
7489 vs Visual by character using |v_CTRL-O| in Select mode
7490 V Visual by line
7491 Vs Visual by line using |v_CTRL-O| in Select mode
7492 CTRL-V Visual blockwise
7493 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7494 s Select by character
7495 S Select by line
7496 CTRL-S Select blockwise
7497 i Insert
7498 ic Insert mode completion |compl-generic|
7499 ix Insert mode |i_CTRL-X| completion
7500 R Replace |R|
7501 Rc Replace mode completion |compl-generic|
7502 Rx Replace mode |i_CTRL-X| completion
7503 Rv Virtual Replace |gR|
7504 Rvc Virtual Replace mode completion |compl-generic|
7505 Rvx Virtual Replace mode |i_CTRL-X| completion
7506 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007507 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007508 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007509 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007510 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007511 ce Normal Ex mode |Q|
7512 r Hit-enter prompt
7513 rm The -- more -- prompt
7514 r? A |:confirm| query of some sort
7515 ! Shell or external command is executing
7516 t Terminal-Job mode: keys go to the job
7517
7518 This is useful in the 'statusline' option or when used
7519 with |remote_expr()| In most other places it always returns
7520 "c" or "n".
7521 Note that in the future more modes and more specific modes may
7522 be added. It's better not to compare the whole string but only
7523 the leading character(s).
7524 Also see |visualmode()|.
7525
7526 Can also be used as a |method|: >
7527 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007528<
7529 Return type: |String|
7530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007531
7532mzeval({expr}) *mzeval()*
7533 Evaluate MzScheme expression {expr} and return its result
7534 converted to Vim data structures.
7535 Numbers and strings are returned as they are.
7536 Pairs (including lists and improper lists) and vectors are
7537 returned as Vim |Lists|.
7538 Hash tables are represented as Vim |Dictionary| type with keys
7539 converted to strings.
7540 All other types are converted to string with display function.
7541 Examples: >
7542 :mz (define l (list 1 2 3))
7543 :mz (define h (make-hash)) (hash-set! h "list" l)
7544 :echo mzeval("l")
7545 :echo mzeval("h")
7546<
7547 Note that in a `:def` function local variables are not visible
7548 to {expr}.
7549
7550 Can also be used as a |method|: >
7551 GetExpr()->mzeval()
7552<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007553 Return type: any, depending on {expr}
7554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007555 {only available when compiled with the |+mzscheme| feature}
7556
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007558nextnonblank({lnum}) *nextnonblank()*
7559 Return the line number of the first line at or below {lnum}
7560 that is not blank. Example: >
7561 if getline(nextnonblank(1)) =~ "Java"
7562< When {lnum} is invalid or there is no non-blank line at or
7563 below it, zero is returned.
7564 {lnum} is used like with |getline()|.
7565 See also |prevnonblank()|.
7566
7567 Can also be used as a |method|: >
7568 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007569<
7570 Return type: |Number|
7571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007572
7573nr2char({expr} [, {utf8}]) *nr2char()*
7574 Return a string with a single character, which has the number
7575 value {expr}. Examples: >
7576 nr2char(64) returns "@"
7577 nr2char(32) returns " "
7578< When {utf8} is omitted or zero, the current 'encoding' is used.
7579 Example for "utf-8": >
7580 nr2char(300) returns I with bow character
7581< When {utf8} is TRUE, always return UTF-8 characters.
7582 Note that a NUL character in the file is specified with
7583 nr2char(10), because NULs are represented with newline
7584 characters. nr2char(0) is a real NUL and terminates the
7585 string, thus results in an empty string.
7586 To turn a list of character numbers into a string: >
7587 let list = [65, 66, 67]
7588 let str = join(map(list, {_, val -> nr2char(val)}), '')
7589< Result: "ABC"
7590
7591 Can also be used as a |method|: >
7592 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007593<
7594 Return type: |String|
7595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007596
7597or({expr}, {expr}) *or()*
7598 Bitwise OR on the two arguments. The arguments are converted
7599 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007600 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007601 Example: >
7602 :let bits = or(bits, 0x80)
7603< Can also be used as a |method|: >
7604 :let bits = bits->or(0x80)
7605
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007606< Rationale: The reason this is a function and not using the "|"
7607 character like many languages, is that Vi has always used "|"
7608 to separate commands. In many places it would not be clear if
7609 "|" is an operator or a command separator.
7610
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007611 Return type: |Number|
7612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007613
7614pathshorten({path} [, {len}]) *pathshorten()*
7615 Shorten directory names in the path {path} and return the
7616 result. The tail, the file name, is kept as-is. The other
7617 components in the path are reduced to {len} letters in length.
7618 If {len} is omitted or smaller than 1 then 1 is used (single
7619 letters). Leading '~' and '.' characters are kept. Examples: >
7620 :echo pathshorten('~/.vim/autoload/myfile.vim')
7621< ~/.v/a/myfile.vim ~
7622>
7623 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7624< ~/.vi/au/myfile.vim ~
7625 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007626 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007627
7628 Can also be used as a |method|: >
7629 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007630<
7631 Return type: |String|
7632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007633
7634perleval({expr}) *perleval()*
7635 Evaluate Perl expression {expr} in scalar context and return
7636 its result converted to Vim data structures. If value can't be
7637 converted, it is returned as a string Perl representation.
7638 Note: If you want an array or hash, {expr} must return a
7639 reference to it.
7640 Example: >
7641 :echo perleval('[1 .. 4]')
7642< [1, 2, 3, 4]
7643
7644 Note that in a `:def` function local variables are not visible
7645 to {expr}.
7646
7647 Can also be used as a |method|: >
7648 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007649<
7650 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007651
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007652 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007653
7654
7655popup_ functions are documented here: |popup-functions|
7656
7657
7658pow({x}, {y}) *pow()*
7659 Return the power of {x} to the exponent {y} as a |Float|.
7660 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007661 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007662 Examples: >
7663 :echo pow(3, 3)
7664< 27.0 >
7665 :echo pow(2, 16)
7666< 65536.0 >
7667 :echo pow(32, 0.20)
7668< 2.0
7669
7670 Can also be used as a |method|: >
7671 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007672<
7673 Return type: |Number|
7674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007675
7676prevnonblank({lnum}) *prevnonblank()*
7677 Return the line number of the first line at or above {lnum}
7678 that is not blank. Example: >
7679 let ind = indent(prevnonblank(v:lnum - 1))
7680< When {lnum} is invalid or there is no non-blank line at or
7681 above it, zero is returned.
7682 {lnum} is used like with |getline()|.
7683 Also see |nextnonblank()|.
7684
7685 Can also be used as a |method|: >
7686 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007687<
7688 Return type: |Number|
7689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007690
7691printf({fmt}, {expr1} ...) *printf()*
7692 Return a String with {fmt}, where "%" items are replaced by
7693 the formatted form of their respective arguments. Example: >
7694 printf("%4d: E%d %.30s", lnum, errno, msg)
7695< May result in:
7696 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7697
7698 When used as a |method| the base is passed as the second
7699 argument: >
7700 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007701<
7702 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007703
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007704 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007705 %s string
7706 %6S string right-aligned in 6 display cells
7707 %6s string right-aligned in 6 bytes
7708 %.9s string truncated to 9 bytes
7709 %c single byte
7710 %d decimal number
7711 %5d decimal number padded with spaces to 5 characters
7712 %x hex number
7713 %04x hex number padded with zeros to at least 4 characters
7714 %X hex number using upper case letters
7715 %o octal number
7716 %08b binary number padded with zeros to at least 8 chars
7717 %f floating point number as 12.23, inf, -inf or nan
7718 %F floating point number as 12.23, INF, -INF or NAN
7719 %e floating point number as 1.23e3, inf, -inf or nan
7720 %E floating point number as 1.23E3, INF, -INF or NAN
7721 %g floating point number, as %f or %e depending on value
7722 %G floating point number, as %F or %E depending on value
7723 %% the % character itself
7724
7725 Conversion specifications start with '%' and end with the
7726 conversion type. All other characters are copied unchanged to
7727 the result.
7728
7729 The "%" starts a conversion specification. The following
7730 arguments appear in sequence:
7731
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007732 % [pos-argument] [flags] [field-width] [.precision] type
7733
7734 pos-argument
7735 At most one positional argument specifier. These
7736 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007737
7738 flags
7739 Zero or more of the following flags:
7740
7741 # The value should be converted to an "alternate
7742 form". For c, d, and s conversions, this option
7743 has no effect. For o conversions, the precision
7744 of the number is increased to force the first
7745 character of the output string to a zero (except
7746 if a zero value is printed with an explicit
7747 precision of zero).
7748 For b and B conversions, a non-zero result has
7749 the string "0b" (or "0B" for B conversions)
7750 prepended to it.
7751 For x and X conversions, a non-zero result has
7752 the string "0x" (or "0X" for X conversions)
7753 prepended to it.
7754
7755 0 (zero) Zero padding. For all conversions the converted
7756 value is padded on the left with zeros rather
7757 than blanks. If a precision is given with a
7758 numeric conversion (d, b, B, o, x, and X), the 0
7759 flag is ignored.
7760
7761 - A negative field width flag; the converted value
7762 is to be left adjusted on the field boundary.
7763 The converted value is padded on the right with
7764 blanks, rather than on the left with blanks or
7765 zeros. A - overrides a 0 if both are given.
7766
7767 ' ' (space) A blank should be left before a positive
7768 number produced by a signed conversion (d).
7769
7770 + A sign must always be placed before a number
7771 produced by a signed conversion. A + overrides
7772 a space if both are used.
7773
7774 field-width
7775 An optional decimal digit string specifying a minimum
7776 field width. If the converted value has fewer bytes
7777 than the field width, it will be padded with spaces on
7778 the left (or right, if the left-adjustment flag has
7779 been given) to fill out the field width. For the S
7780 conversion the count is in cells.
7781
7782 .precision
7783 An optional precision, in the form of a period '.'
7784 followed by an optional digit string. If the digit
7785 string is omitted, the precision is taken as zero.
7786 This gives the minimum number of digits to appear for
7787 d, o, x, and X conversions, the maximum number of
7788 bytes to be printed from a string for s conversions,
7789 or the maximum number of cells to be printed from a
7790 string for S conversions.
7791 For floating point it is the number of digits after
7792 the decimal point.
7793
7794 type
7795 A character that specifies the type of conversion to
7796 be applied, see below.
7797
7798 A field width or precision, or both, may be indicated by an
7799 asterisk '*' instead of a digit string. In this case, a
7800 Number argument supplies the field width or precision. A
7801 negative field width is treated as a left adjustment flag
7802 followed by a positive field width; a negative precision is
7803 treated as though it were missing. Example: >
7804 :echo printf("%d: %.*s", nr, width, line)
7805< This limits the length of the text used from "line" to
7806 "width" bytes.
7807
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007808 If the argument to be formatted is specified using a
7809 positional argument specifier, and a '*' is used to indicate
7810 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007811 precision, the argument(s) to be used must also be specified
7812 using a {n$} positional argument specifier. See |printf-$|.
7813
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007814 The conversion specifiers and their meanings are:
7815
7816 *printf-d* *printf-b* *printf-B* *printf-o*
7817 *printf-x* *printf-X*
7818 dbBoxX The Number argument is converted to signed decimal
7819 (d), unsigned binary (b and B), unsigned octal (o), or
7820 unsigned hexadecimal (x and X) notation. The letters
7821 "abcdef" are used for x conversions; the letters
7822 "ABCDEF" are used for X conversions.
7823 The precision, if any, gives the minimum number of
7824 digits that must appear; if the converted value
7825 requires fewer digits, it is padded on the left with
7826 zeros.
7827 In no case does a non-existent or small field width
7828 cause truncation of a numeric field; if the result of
7829 a conversion is wider than the field width, the field
7830 is expanded to contain the conversion result.
7831 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007832 The 'l' modifier indicates the argument is a long
7833 integer. The size will be 32 bits or 64 bits
7834 depending on your platform.
7835 The "ll" modifier indicates the argument is 64 bits.
7836 The b and B conversion specifiers never take a width
7837 modifier and always assume their argument is a 64 bit
7838 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007839 Generally, these modifiers are not useful. They are
7840 ignored when type is known from the argument.
7841
7842 i alias for d
7843 D alias for ld
7844 U alias for lu
7845 O alias for lo
7846
7847 *printf-c*
7848 c The Number argument is converted to a byte, and the
7849 resulting character is written.
7850
7851 *printf-s*
7852 s The text of the String argument is used. If a
7853 precision is specified, no more bytes than the number
7854 specified are used.
7855 If the argument is not a String type, it is
7856 automatically converted to text with the same format
7857 as ":echo".
7858 *printf-S*
7859 S The text of the String argument is used. If a
7860 precision is specified, no more display cells than the
7861 number specified are used.
7862
7863 *printf-f* *E807*
7864 f F The Float argument is converted into a string of the
7865 form 123.456. The precision specifies the number of
7866 digits after the decimal point. When the precision is
7867 zero the decimal point is omitted. When the precision
7868 is not specified 6 is used. A really big number
7869 (out of range or dividing by zero) results in "inf"
7870 or "-inf" with %f (INF or -INF with %F).
7871 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7872 Example: >
7873 echo printf("%.2f", 12.115)
7874< 12.12
7875 Note that roundoff depends on the system libraries.
7876 Use |round()| when in doubt.
7877
7878 *printf-e* *printf-E*
7879 e E The Float argument is converted into a string of the
7880 form 1.234e+03 or 1.234E+03 when using 'E'. The
7881 precision specifies the number of digits after the
7882 decimal point, like with 'f'.
7883
7884 *printf-g* *printf-G*
7885 g G The Float argument is converted like with 'f' if the
7886 value is between 0.001 (inclusive) and 10000000.0
7887 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7888 for 'G'. When no precision is specified superfluous
7889 zeroes and '+' signs are removed, except for the zero
7890 immediately after the decimal point. Thus 10000000.0
7891 results in 1.0e7.
7892
7893 *printf-%*
7894 % A '%' is written. No argument is converted. The
7895 complete conversion specification is "%%".
7896
7897 When a Number argument is expected a String argument is also
7898 accepted and automatically converted.
7899 When a Float or String argument is expected a Number argument
7900 is also accepted and automatically converted.
7901 Any other argument type results in an error message.
7902
7903 *E766* *E767*
7904 The number of {exprN} arguments must exactly match the number
7905 of "%" items. If there are not sufficient or too many
7906 arguments an error is given. Up to 18 arguments can be used.
7907
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007908 *printf-$*
7909 In certain languages, error and informative messages are
7910 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007911 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007912 having a different word order, positional arguments may be
7913 used to indicate this. For instance: >
7914
h_east596a9f22023-11-21 21:24:23 +09007915 #, c-format
7916 msgid "%s returning %s"
7917 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007918<
h_east596a9f22023-11-21 21:24:23 +09007919 In this example, the sentence has its 2 string arguments
7920 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007921
h_east596a9f22023-11-21 21:24:23 +09007922 echo printf(
7923 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7924 "Bram", "Moolenaar")
7925< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007926
h_east596a9f22023-11-21 21:24:23 +09007927 echo printf(
7928 "In Belgium, vim's creator's name is: %2$s %1$s",
7929 "Bram", "Moolenaar")
7930< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007931
7932 Width (and precision) can be specified using the '*' specifier.
7933 In this case, you must specify the field width position in the
7934 argument list. >
7935
h_east596a9f22023-11-21 21:24:23 +09007936 echo printf("%1$*2$.*3$d", 1, 2, 3)
7937< 001 >
7938 echo printf("%2$*3$.*1$d", 1, 2, 3)
7939< 2 >
7940 echo printf("%3$*1$.*2$d", 1, 2, 3)
7941< 03 >
7942 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7943< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007944
7945 You can mix specifying the width and/or precision directly
7946 and via positional arguments: >
7947
h_east596a9f22023-11-21 21:24:23 +09007948 echo printf("%1$4.*2$f", 1.4142135, 6)
7949< 1.414214 >
7950 echo printf("%1$*2$.4f", 1.4142135, 6)
7951< 1.4142 >
7952 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7953< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007954
Christ van Willegenc35fc032024-03-14 18:30:41 +01007955 You will get an overflow error |E1510|, when the field-width
7956 or precision will result in a string longer than 6400 chars.
7957
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007958 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007959 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007960 echo printf("%s%1$s", "One", "Two")
7961< E1500: Cannot mix positional and non-positional arguments:
7962 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007963
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007964 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007965 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007966 echo printf("%3$s%1$s", "One", "Two", "Three")
7967< E1501: format argument 2 unused in $-style format:
7968 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007969
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007970 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007971 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007972 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7973< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007974
7975 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007976 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7977< E1502: Positional argument 2 used as field width reused as
7978 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007979
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007980 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007981 When a positional argument is used, but not the correct number
7982 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007983 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7984< E1503: Positional argument 3 out of bounds: %1$d at width
7985 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007986
7987 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007988 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7989< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7990 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007991
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007992 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007993 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007994 echo printf("%1$s %2$s %1$s", "One", "Two")
7995< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007996
7997 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007998 echo printf("%1$s %2$s %1$d", "One", "Two")
7999< E1504: Positional argument 1 type used inconsistently:
8000 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008001
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008002 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008003 Various other errors that lead to a format string being
8004 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008005 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8006< E1505: Invalid format specifier: %1$d at width %2$d is:
8007 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008008
Christ van Willegenea746f92023-10-05 20:48:36 +02008009 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008010 This internal error indicates that the logic to parse a
8011 positional format argument ran into a problem that couldn't be
8012 otherwise reported. Please file a bug against Vim if you run
8013 into this, copying the exact format string and parameters that
8014 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008015
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008016 Return type: |String|
8017
Christ van Willegenea746f92023-10-05 20:48:36 +02008018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019prompt_getprompt({buf}) *prompt_getprompt()*
8020 Returns the effective prompt text for buffer {buf}. {buf} can
8021 be a buffer name or number. See |prompt-buffer|.
8022
8023 If the buffer doesn't exist or isn't a prompt buffer, an empty
8024 string is returned.
8025
8026 Can also be used as a |method|: >
8027 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008028<
8029 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008030
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008031 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008032
8033
8034prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8035 Set prompt callback for buffer {buf} to {expr}. When {expr}
8036 is an empty string the callback is removed. This has only
8037 effect if {buf} has 'buftype' set to "prompt".
8038
8039 The callback is invoked when pressing Enter. The current
8040 buffer will always be the prompt buffer. A new line for a
8041 prompt is added before invoking the callback, thus the prompt
8042 for which the callback was invoked will be in the last but one
8043 line.
8044 If the callback wants to add text to the buffer, it must
8045 insert it above the last line, since that is where the current
8046 prompt is. This can also be done asynchronously.
8047 The callback is invoked with one argument, which is the text
8048 that was entered at the prompt. This can be an empty string
8049 if the user only typed Enter.
8050 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008051 func s:TextEntered(text)
8052 if a:text == 'exit' || a:text == 'quit'
8053 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008054 " Reset 'modified' to allow the buffer to be closed.
8055 " We assume there is nothing useful to be saved.
8056 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008057 close
8058 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008059 " Do something useful with "a:text". In this example
8060 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008061 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008062 endif
8063 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008064 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008065
8066< Can also be used as a |method|: >
8067 GetBuffer()->prompt_setcallback(callback)
8068
8069< {only available when compiled with the |+channel| feature}
8070
8071prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8072 Set a callback for buffer {buf} to {expr}. When {expr} is an
8073 empty string the callback is removed. This has only effect if
8074 {buf} has 'buftype' set to "prompt".
8075
8076 This callback will be invoked when pressing CTRL-C in Insert
8077 mode. Without setting a callback Vim will exit Insert mode,
8078 as in any buffer.
8079
8080 Can also be used as a |method|: >
8081 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008082<
8083 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008084
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008085 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008086
8087prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8088 Set prompt for buffer {buf} to {text}. You most likely want
8089 {text} to end in a space.
8090 The result is only visible if {buf} has 'buftype' set to
8091 "prompt". Example: >
8092 call prompt_setprompt(bufnr(), 'command: ')
8093<
8094 Can also be used as a |method|: >
8095 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008096<
8097 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008098
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008099 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008100
8101prop_ functions are documented here: |text-prop-functions|
8102
8103pum_getpos() *pum_getpos()*
8104 If the popup menu (see |ins-completion-menu|) is not visible,
8105 returns an empty |Dictionary|, otherwise, returns a
8106 |Dictionary| with the following keys:
8107 height nr of items visible
8108 width screen cells
8109 row top screen row (0 first row)
8110 col leftmost screen column (0 first col)
8111 size total nr of items
8112 scrollbar |TRUE| if scrollbar is visible
8113
8114 The values are the same as in |v:event| during
8115 |CompleteChanged|.
8116
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008117 Return type: dict<any>
8118
8119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008120pumvisible() *pumvisible()*
8121 Returns non-zero when the popup menu is visible, zero
8122 otherwise. See |ins-completion-menu|.
8123 This can be used to avoid some things that would remove the
8124 popup menu.
8125
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008126 Return type: |Number|
8127
8128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008129py3eval({expr}) *py3eval()*
8130 Evaluate Python expression {expr} and return its result
8131 converted to Vim data structures.
8132 Numbers and strings are returned as they are (strings are
8133 copied though, Unicode strings are additionally converted to
8134 'encoding').
8135 Lists are represented as Vim |List| type.
8136 Dictionaries are represented as Vim |Dictionary| type with
8137 keys converted to strings.
8138 Note that in a `:def` function local variables are not visible
8139 to {expr}.
8140
8141 Can also be used as a |method|: >
8142 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008143<
8144 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008145
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008146 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008147
8148 *E858* *E859*
8149pyeval({expr}) *pyeval()*
8150 Evaluate Python expression {expr} and return its result
8151 converted to Vim data structures.
8152 Numbers and strings are returned as they are (strings are
8153 copied though).
8154 Lists are represented as Vim |List| type.
8155 Dictionaries are represented as Vim |Dictionary| type,
8156 non-string keys result in error.
8157 Note that in a `:def` function local variables are not visible
8158 to {expr}.
8159
8160 Can also be used as a |method|: >
8161 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008162<
8163 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008164
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008165 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008166
8167pyxeval({expr}) *pyxeval()*
8168 Evaluate Python expression {expr} and return its result
8169 converted to Vim data structures.
8170 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8171 See also: |pyeval()|, |py3eval()|
8172
8173 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008174 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008175<
8176 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008177
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008178 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008179 |+python3| feature}
8180
8181rand([{expr}]) *rand()* *random*
8182 Return a pseudo-random Number generated with an xoshiro128**
8183 algorithm using seed {expr}. The returned number is 32 bits,
8184 also on 64 bits systems, for consistency.
8185 {expr} can be initialized by |srand()| and will be updated by
8186 rand(). If {expr} is omitted, an internal seed value is used
8187 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008188 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008189
8190 Examples: >
8191 :echo rand()
8192 :let seed = srand()
8193 :echo rand(seed)
8194 :echo rand(seed) % 16 " random number 0 - 15
8195<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008196 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008197
8198 *E726* *E727*
8199range({expr} [, {max} [, {stride}]]) *range()*
8200 Returns a |List| with Numbers:
8201 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8202 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8203 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8204 {max}] (increasing {expr} with {stride} each time, not
8205 producing a value past {max}).
8206 When the maximum is one before the start the result is an
8207 empty list. When the maximum is more than one before the
8208 start this is an error.
8209 Examples: >
8210 range(4) " [0, 1, 2, 3]
8211 range(2, 4) " [2, 3, 4]
8212 range(2, 9, 3) " [2, 5, 8]
8213 range(2, -2, -1) " [2, 1, 0, -1, -2]
8214 range(0) " []
8215 range(2, 0) " error!
8216<
8217 Can also be used as a |method|: >
8218 GetExpr()->range()
8219<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008220 Return type: list<number>
8221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008222
K.Takata11df3ae2022-10-19 14:02:40 +01008223readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008224 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008225 If {offset} is specified, read the file from the specified
8226 offset. If it is a negative value, it is used as an offset
8227 from the end of the file. E.g., to read the last 12 bytes: >
8228 readblob('file.bin', -12)
8229< If {size} is specified, only the specified size will be read.
8230 E.g. to read the first 100 bytes of a file: >
8231 readblob('file.bin', 0, 100)
8232< If {size} is -1 or omitted, the whole data starting from
8233 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008234 This can be also used to read the data from a character device
8235 on Unix when {size} is explicitly set. Only if the device
8236 supports seeking {offset} can be used. Otherwise it should be
8237 zero. E.g. to read 10 bytes from a serial console: >
8238 readblob('/dev/ttyS0', 0, 10)
8239< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008240 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008241 When the offset is beyond the end of the file the result is an
8242 empty blob.
8243 When trying to read more bytes than are available the result
8244 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008245 Also see |readfile()| and |writefile()|.
8246
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008247 Return type: |Blob|
8248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008249
8250readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8251 Return a list with file and directory names in {directory}.
8252 You can also use |glob()| if you don't need to do complicated
8253 things, such as limiting the number of matches.
8254 The list will be sorted (case sensitive), see the {dict}
8255 argument below for changing the sort order.
8256
8257 When {expr} is omitted all entries are included.
8258 When {expr} is given, it is evaluated to check what to do:
8259 If {expr} results in -1 then no further entries will
8260 be handled.
8261 If {expr} results in 0 then this entry will not be
8262 added to the list.
8263 If {expr} results in 1 then this entry will be added
8264 to the list.
8265 The entries "." and ".." are always excluded.
8266 Each time {expr} is evaluated |v:val| is set to the entry name.
8267 When {expr} is a function the name is passed as the argument.
8268 For example, to get a list of files ending in ".txt": >
8269 readdir(dirname, {n -> n =~ '.txt$'})
8270< To skip hidden and backup files: >
8271 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008272< *E857*
8273 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008274 values. Currently this is used to specify if and how sorting
8275 should be performed. The dict can have the following members:
8276
8277 sort How to sort the result returned from the system.
8278 Valid values are:
8279 "none" do not sort (fastest method)
8280 "case" sort case sensitive (byte value of
8281 each character, technically, using
8282 strcmp()) (default)
8283 "icase" sort case insensitive (technically
8284 using strcasecmp())
8285 "collate" sort using the collation order
8286 of the "POSIX" or "C" |locale|
8287 (technically using strcoll())
8288 Other values are silently ignored.
8289
8290 For example, to get a list of all files in the current
8291 directory without sorting the individual entries: >
8292 readdir('.', '1', #{sort: 'none'})
8293< If you want to get a directory tree: >
8294 function! s:tree(dir)
8295 return {a:dir : map(readdir(a:dir),
8296 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008297 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008298 endfunction
8299 echo s:tree(".")
8300<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008301 Returns an empty List on error.
8302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008303 Can also be used as a |method|: >
8304 GetDirName()->readdir()
8305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008306 Return type: list<string> or list<any>
8307
8308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008309readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8310 Extended version of |readdir()|.
8311 Return a list of Dictionaries with file and directory
8312 information in {directory}.
8313 This is useful if you want to get the attributes of file and
8314 directory at the same time as getting a list of a directory.
8315 This is much faster than calling |readdir()| then calling
8316 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8317 each file and directory especially on MS-Windows.
8318 The list will by default be sorted by name (case sensitive),
8319 the sorting can be changed by using the optional {dict}
8320 argument, see |readdir()|.
8321
8322 The Dictionary for file and directory information has the
8323 following items:
8324 group Group name of the entry. (Only on Unix)
8325 name Name of the entry.
8326 perm Permissions of the entry. See |getfperm()|.
8327 size Size of the entry. See |getfsize()|.
8328 time Timestamp of the entry. See |getftime()|.
8329 type Type of the entry.
8330 On Unix, almost same as |getftype()| except:
8331 Symlink to a dir "linkd"
8332 Other symlink "link"
8333 On MS-Windows:
8334 Normal file "file"
8335 Directory "dir"
8336 Junction "junction"
8337 Symlink to a dir "linkd"
8338 Other symlink "link"
8339 Other reparse point "reparse"
8340 user User name of the entry's owner. (Only on Unix)
8341 On Unix, if the entry is a symlink, the Dictionary includes
8342 the information of the target (except the "type" item).
8343 On MS-Windows, it includes the information of the symlink
8344 itself because of performance reasons.
8345
8346 When {expr} is omitted all entries are included.
8347 When {expr} is given, it is evaluated to check what to do:
8348 If {expr} results in -1 then no further entries will
8349 be handled.
8350 If {expr} results in 0 then this entry will not be
8351 added to the list.
8352 If {expr} results in 1 then this entry will be added
8353 to the list.
8354 The entries "." and ".." are always excluded.
8355 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8356 of the entry.
8357 When {expr} is a function the entry is passed as the argument.
8358 For example, to get a list of files ending in ".txt": >
8359 readdirex(dirname, {e -> e.name =~ '.txt$'})
8360<
8361 For example, to get a list of all files in the current
8362 directory without sorting the individual entries: >
8363 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008364<
8365 Can also be used as a |method|: >
8366 GetDirName()->readdirex()
8367<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008368 Return type: list<dict<any>> or list<any>
8369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008370
8371 *readfile()*
8372readfile({fname} [, {type} [, {max}]])
8373 Read file {fname} and return a |List|, each line of the file
8374 as an item. Lines are broken at NL characters. Macintosh
8375 files separated with CR will result in a single long line
8376 (unless a NL appears somewhere).
8377 All NUL characters are replaced with a NL character.
8378 When {type} contains "b" binary mode is used:
8379 - When the last line ends in a NL an extra empty list item is
8380 added.
8381 - No CR characters are removed.
8382 Otherwise:
8383 - CR characters that appear before a NL are removed.
8384 - Whether the last line ends in a NL or not does not matter.
8385 - When 'encoding' is Unicode any UTF-8 byte order mark is
8386 removed from the text.
8387 When {max} is given this specifies the maximum number of lines
8388 to be read. Useful if you only want to check the first ten
8389 lines of a file: >
8390 :for line in readfile(fname, '', 10)
8391 : if line =~ 'Date' | echo line | endif
8392 :endfor
8393< When {max} is negative -{max} lines from the end of the file
8394 are returned, or as many as there are.
8395 When {max} is zero the result is an empty list.
8396 Note that without {max} the whole file is read into memory.
8397 Also note that there is no recognition of encoding. Read a
8398 file into a buffer if you need to.
8399 Deprecated (use |readblob()| instead): When {type} contains
8400 "B" a |Blob| is returned with the binary data of the file
8401 unmodified.
8402 When the file can't be opened an error message is given and
8403 the result is an empty list.
8404 Also see |writefile()|.
8405
8406 Can also be used as a |method|: >
8407 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008408<
8409 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008410
8411reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8412 {func} is called for every item in {object}, which can be a
8413 |String|, |List| or a |Blob|. {func} is called with two
8414 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008415 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008416
8417 {initial} is the initial result. When omitted, the first item
8418 in {object} is used and {func} is first called for the second
8419 item. If {initial} is not given and {object} is empty no
8420 result can be computed, an E998 error is given.
8421
8422 Examples: >
8423 echo reduce([1, 3, 5], { acc, val -> acc + val })
8424 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8425 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8426 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8427<
8428 Can also be used as a |method|: >
8429 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008430<
8431 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8432 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008433
8434
8435reg_executing() *reg_executing()*
8436 Returns the single letter name of the register being executed.
8437 Returns an empty string when no register is being executed.
8438 See |@|.
8439
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008440 Return type: |String|
8441
8442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008443reg_recording() *reg_recording()*
8444 Returns the single letter name of the register being recorded.
8445 Returns an empty string when not recording. See |q|.
8446
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008447 Return type: |String|
8448
8449
8450reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008451reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008452reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008453 Return an item that represents a time value. The item is a
8454 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008455 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008456 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008457 string or |reltimefloat()| to convert to a Float. For
8458 example, to see the time spent in function Work(): >
8459 var startTime = reltime()
8460 Work()
8461 echo startTime->reltime()->reltimestr()
8462<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008463 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008464 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008465 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008466 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008467 specified in the argument.
8468 With two arguments it returns the time passed between {start}
8469 and {end}.
8470
8471 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008472 reltime(). If there is an error an empty List is returned in
8473 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008474
8475 Can also be used as a |method|: >
8476 GetStart()->reltime()
8477<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008478 Return type: list<number>
8479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008480 {only available when compiled with the |+reltime| feature}
8481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008483reltimefloat({time}) *reltimefloat()*
8484 Return a Float that represents the time value of {time}.
8485 Example: >
8486 let start = reltime()
8487 call MyFunction()
8488 let seconds = reltimefloat(reltime(start))
8489< See the note of reltimestr() about overhead.
8490 Also see |profiling|.
8491 If there is an error 0.0 is returned in legacy script, in Vim9
8492 script an error is given.
8493
8494 Can also be used as a |method|: >
8495 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008496<
8497 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008498
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008499 {only available when compiled with the |+reltime| feature}
8500
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008501
8502reltimestr({time}) *reltimestr()*
8503 Return a String that represents the time value of {time}.
8504 This is the number of seconds, a dot and the number of
8505 microseconds. Example: >
8506 let start = reltime()
8507 call MyFunction()
8508 echo reltimestr(reltime(start))
8509< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008510 The accuracy depends on the system. Use reltimefloat() for the
8511 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008512 Leading spaces are used to make the string align nicely. You
8513 can use split() to remove it. >
8514 echo split(reltimestr(reltime(start)))[0]
8515< Also see |profiling|.
8516 If there is an error an empty string is returned in legacy
8517 script, in Vim9 script an error is given.
8518
8519 Can also be used as a |method|: >
8520 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008521<
8522 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008523
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008524 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008525
8526 *remote_expr()* *E449*
8527remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008528 Send the {string} to {server}. The {server} argument is a
8529 string, also see |{server}|.
8530
8531 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008532 after evaluation. The result must be a String or a |List|
8533 other types will be converted to String. A |List| is turned
8534 into a String by joining the items with a line break in
8535 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008537 If {idvar} is present and not empty, it is taken as the name
8538 of a variable and a {serverid} for later use with
8539 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008541 If {timeout} is given the read times out after this many
8542 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008544 See also |clientserver| |RemoteReply|.
8545 This function is not available in the |sandbox|.
8546 {only available when compiled with the |+clientserver| feature}
8547 Note: Any errors will cause a local error message to be issued
8548 and the result will be the empty string.
8549
8550 Variables will be evaluated in the global namespace,
8551 independent of a function currently being active. Except
8552 when in debug mode, then local function variables and
8553 arguments can be evaluated.
8554
8555 Examples: >
8556 :echo remote_expr("gvim", "2+2")
8557 :echo remote_expr("gvim1", "b:current_syntax")
8558<
8559 Can also be used as a |method|: >
8560 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008561<
8562 Return type: |String| or list<{type}>
8563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008564
8565remote_foreground({server}) *remote_foreground()*
8566 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008567 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008568 This works like: >
8569 remote_expr({server}, "foreground()")
8570< Except that on Win32 systems the client does the work, to work
8571 around the problem that the OS doesn't always allow the server
8572 to bring itself to the foreground.
8573 Note: This does not restore the window if it was minimized,
8574 like foreground() does.
8575 This function is not available in the |sandbox|.
8576
8577 Can also be used as a |method|: >
8578 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008579<
8580 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008581
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008582 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008583 Win32 console version}
8584
8585
8586remote_peek({serverid} [, {retvar}]) *remote_peek()*
8587 Returns a positive number if there are available strings
8588 from {serverid}. Copies any reply string into the variable
8589 {retvar} if specified. {retvar} must be a string with the
8590 name of a variable.
8591 Returns zero if none are available.
8592 Returns -1 if something is wrong.
8593 See also |clientserver|.
8594 This function is not available in the |sandbox|.
8595 {only available when compiled with the |+clientserver| feature}
8596 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008597 :let repl = ""
8598 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008599
8600< Can also be used as a |method|: >
8601 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008602<
8603 Return type: |Number|
8604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008605
8606remote_read({serverid}, [{timeout}]) *remote_read()*
8607 Return the oldest available reply from {serverid} and consume
8608 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008609 reply is available. Returns an empty string, if a reply is
8610 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611 See also |clientserver|.
8612 This function is not available in the |sandbox|.
8613 {only available when compiled with the |+clientserver| feature}
8614 Example: >
8615 :echo remote_read(id)
8616
8617< Can also be used as a |method|: >
8618 ServerId()->remote_read()
8619<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008620 Return type: |String|
8621
8622
8623remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008624 Send the {string} to {server}. The {server} argument is a
8625 string, also see |{server}|.
8626
8627 The string is sent as input keys and the function returns
8628 immediately. At the Vim server the keys are not mapped
8629 |:map|.
8630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008631 If {idvar} is present, it is taken as the name of a variable
8632 and a {serverid} for later use with remote_read() is stored
8633 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008635 See also |clientserver| |RemoteReply|.
8636 This function is not available in the |sandbox|.
8637 {only available when compiled with the |+clientserver| feature}
8638
8639 Note: Any errors will be reported in the server and may mess
8640 up the display.
8641 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008642 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008643 \ remote_read(serverid)
8644
8645 :autocmd NONE RemoteReply *
8646 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008647 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008648 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8649<
8650 Can also be used as a |method|: >
8651 ServerName()->remote_send(keys)
8652<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008653 Return type: |String|
8654
8655
8656remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008657 Become the server {name}. {name} must be a non-empty string.
8658 This fails if already running as a server, when |v:servername|
8659 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008660
8661 Can also be used as a |method|: >
8662 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008663<
8664 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008666 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008667
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008668
8669remove({list}, {idx}) *remove()*
8670remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008671 Without {end}: Remove the item at {idx} from |List| {list} and
8672 return the item.
8673 With {end}: Remove items from {idx} to {end} (inclusive) and
8674 return a |List| with these items. When {idx} points to the same
8675 item as {end} a list with one item is returned. When {end}
8676 points to an item before {idx} this is an error.
8677 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008678 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008679 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008680 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008681 :call remove(mylist, 0, 9)
8682<
8683 Use |delete()| to remove a file.
8684
8685 Can also be used as a |method|: >
8686 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008687<
8688 Return type: any, depending on {list}
8689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008690
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008691remove({blob}, {idx})
8692remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008693 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8694 return the byte.
8695 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8696 return a |Blob| with these bytes. When {idx} points to the same
8697 byte as {end} a |Blob| with one byte is returned. When {end}
8698 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008699 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008700 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008701 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008702 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008703<
8704 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008705
8706remove({dict}, {key})
8707 Remove the entry from {dict} with key {key} and return it.
8708 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008709 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008710< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008711 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008712
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008713 Return type: any, depending on {dict}
8714
8715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008716rename({from}, {to}) *rename()*
8717 Rename the file by the name {from} to the name {to}. This
8718 should also work to move files across file systems. The
8719 result is a Number, which is 0 if the file was renamed
8720 successfully, and non-zero when the renaming failed.
8721 NOTE: If {to} exists it is overwritten without warning.
8722 This function is not available in the |sandbox|.
8723
8724 Can also be used as a |method|: >
8725 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008726<
8727 Return type: |Number|
8728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008729
8730repeat({expr}, {count}) *repeat()*
8731 Repeat {expr} {count} times and return the concatenated
8732 result. Example: >
8733 :let separator = repeat('-', 80)
8734< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008735 When {expr} is a |List| or a |Blob| the result is {expr}
8736 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008737 :let longlist = repeat(['a', 'b'], 3)
8738< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8739
8740 Can also be used as a |method|: >
8741 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008742<
8743 Return type: |String|, |Blob| or list<{type}> depending on
8744 {expr}
8745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008746
8747resolve({filename}) *resolve()* *E655*
8748 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8749 returns the path the shortcut points to in a simplified form.
8750 When {filename} is a symbolic link or junction point, return
8751 the full path to the target. If the target of junction is
8752 removed, return {filename}.
8753 On Unix, repeat resolving symbolic links in all path
8754 components of {filename} and return the simplified result.
8755 To cope with link cycles, resolving of symbolic links is
8756 stopped after 100 iterations.
8757 On other systems, return the simplified {filename}.
8758 The simplification step is done as by |simplify()|.
8759 resolve() keeps a leading path component specifying the
8760 current directory (provided the result is still a relative
8761 path name) and also keeps a trailing path separator.
8762
8763 Can also be used as a |method|: >
8764 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008765<
8766 Return type: |String|
8767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008768
8769reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008770 Reverse the order of items in {object}. {object} can be a
8771 |List|, a |Blob| or a |String|. For a List and a Blob the
8772 items are reversed in-place and {object} is returned.
8773 For a String a new String is returned.
8774 Returns zero if {object} is not a List, Blob or a String.
8775 If you want a List or Blob to remain unmodified make a copy
8776 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008777 :let revlist = reverse(copy(mylist))
8778< Can also be used as a |method|: >
8779 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008780<
8781 Return type: |String|, |Blob| or list<{type}> depending on
8782 {object}
8783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008784
8785round({expr}) *round()*
8786 Round off {expr} to the nearest integral value and return it
8787 as a |Float|. If {expr} lies halfway between two integral
8788 values, then use the larger one (away from zero).
8789 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008790 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008791 Examples: >
8792 echo round(0.456)
8793< 0.0 >
8794 echo round(4.5)
8795< 5.0 >
8796 echo round(-4.5)
8797< -5.0
8798
8799 Can also be used as a |method|: >
8800 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008801<
8802 Return type: |Float|
8803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008804
8805rubyeval({expr}) *rubyeval()*
8806 Evaluate Ruby expression {expr} and return its result
8807 converted to Vim data structures.
8808 Numbers, floats and strings are returned as they are (strings
8809 are copied though).
8810 Arrays are represented as Vim |List| type.
8811 Hashes are represented as Vim |Dictionary| type.
8812 Other objects are represented as strings resulted from their
8813 "Object#to_s" method.
8814 Note that in a `:def` function local variables are not visible
8815 to {expr}.
8816
8817 Can also be used as a |method|: >
8818 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008819<
8820 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008821
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008822 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008823
8824screenattr({row}, {col}) *screenattr()*
8825 Like |screenchar()|, but return the attribute. This is a rather
8826 arbitrary number that can only be used to compare to the
8827 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008828 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008829
8830 Can also be used as a |method|: >
8831 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008832<
8833 Return type: |Number|
8834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008835
8836screenchar({row}, {col}) *screenchar()*
8837 The result is a Number, which is the character at position
8838 [row, col] on the screen. This works for every possible
8839 screen position, also status lines, window separators and the
8840 command line. The top left position is row one, column one
8841 The character excludes composing characters. For double-byte
8842 encodings it may only be the first byte.
8843 This is mainly to be used for testing.
8844 Returns -1 when row or col is out of range.
8845
8846 Can also be used as a |method|: >
8847 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008848<
8849 Return type: |Number|
8850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008851
8852screenchars({row}, {col}) *screenchars()*
8853 The result is a |List| of Numbers. The first number is the same
8854 as what |screenchar()| returns. Further numbers are
8855 composing characters on top of the base character.
8856 This is mainly to be used for testing.
8857 Returns an empty List when row or col is out of range.
8858
8859 Can also be used as a |method|: >
8860 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008861<
8862 Return type: list<number> or list<any>
8863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008864
8865screencol() *screencol()*
8866 The result is a Number, which is the current screen column of
8867 the cursor. The leftmost column has number 1.
8868 This function is mainly used for testing.
8869
8870 Note: Always returns the current screen column, thus if used
8871 in a command (e.g. ":echo screencol()") it will return the
8872 column inside the command line, which is 1 when the command is
8873 executed. To get the cursor position in the file use one of
8874 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008875 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008876 nnoremap <silent> GG :echom screencol()<CR>
8877 nnoremap GG <Cmd>echom screencol()<CR>
8878<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008879 Return type: |Number|
8880
8881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008882screenpos({winid}, {lnum}, {col}) *screenpos()*
8883 The result is a Dict with the screen position of the text
8884 character in window {winid} at buffer line {lnum} and column
8885 {col}. {col} is a one-based byte index.
8886 The Dict has these members:
8887 row screen row
8888 col first screen column
8889 endcol last screen column
8890 curscol cursor screen column
8891 If the specified position is not visible, all values are zero.
8892 The "endcol" value differs from "col" when the character
8893 occupies more than one screen cell. E.g. for a Tab "col" can
8894 be 1 and "endcol" can be 8.
8895 The "curscol" value is where the cursor would be placed. For
8896 a Tab it would be the same as "endcol", while for a double
8897 width character it would be the same as "col".
8898 The |conceal| feature is ignored here, the column numbers are
8899 as if 'conceallevel' is zero. You can set the cursor to the
8900 right position and use |screencol()| to get the value with
8901 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008902 If the position is in a closed fold the screen position of the
8903 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008904 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008905
8906 Can also be used as a |method|: >
8907 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008908<
8909 Return type: dict<number> or dict<any>
8910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008911
8912screenrow() *screenrow()*
8913 The result is a Number, which is the current screen row of the
8914 cursor. The top line has number one.
8915 This function is mainly used for testing.
8916 Alternatively you can use |winline()|.
8917
8918 Note: Same restrictions as with |screencol()|.
8919
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008920 Return type: |Number|
8921
8922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008923screenstring({row}, {col}) *screenstring()*
8924 The result is a String that contains the base character and
8925 any composing characters at position [row, col] on the screen.
8926 This is like |screenchars()| but returning a String with the
8927 characters.
8928 This is mainly to be used for testing.
8929 Returns an empty String when row or col is out of range.
8930
8931 Can also be used as a |method|: >
8932 GetRow()->screenstring(col)
8933<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008934 Return type: |String|
8935
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008936 *search()*
8937search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8938 Search for regexp pattern {pattern}. The search starts at the
8939 cursor position (you can use |cursor()| to set it).
8940
8941 When a match has been found its line number is returned.
8942 If there is no match a 0 is returned and the cursor doesn't
8943 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008944 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008945
8946 {flags} is a String, which can contain these character flags:
8947 'b' search Backward instead of forward
8948 'c' accept a match at the Cursor position
8949 'e' move to the End of the match
8950 'n' do Not move the cursor
8951 'p' return number of matching sub-Pattern (see below)
8952 's' Set the ' mark at the previous location of the cursor
8953 'w' Wrap around the end of the file
8954 'W' don't Wrap around the end of the file
8955 'z' start searching at the cursor column instead of zero
8956 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8957
8958 If the 's' flag is supplied, the ' mark is set, only if the
8959 cursor is moved. The 's' flag cannot be combined with the 'n'
8960 flag.
8961
8962 'ignorecase', 'smartcase' and 'magic' are used.
8963
8964 When the 'z' flag is not given, forward searching always
8965 starts in column zero and then matches before the cursor are
8966 skipped. When the 'c' flag is present in 'cpo' the next
8967 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008968 search starts one column after the start of the match. This
8969 matters for overlapping matches. See |cpo-c|. You can also
8970 insert "\ze" to change where the match ends, see |/\ze|.
8971
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008972 When searching backwards and the 'z' flag is given then the
8973 search starts in column zero, thus no match in the current
8974 line will be found (unless wrapping around the end of the
8975 file).
8976
8977 When the {stopline} argument is given then the search stops
8978 after searching this line. This is useful to restrict the
8979 search to a range of lines. Examples: >
8980 let match = search('(', 'b', line("w0"))
8981 let end = search('END', '', line("w$"))
8982< When {stopline} is used and it is not zero this also implies
8983 that the search does not wrap around the end of the file.
8984 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008985 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008986 When the {timeout} argument is given the search stops when
8987 more than this many milliseconds have passed. Thus when
8988 {timeout} is 500 the search stops after half a second.
8989 The value must not be negative. A zero value is like not
8990 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02008991
8992 Note: the timeout is only considered when searching, not
8993 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008994 {only available when compiled with the |+reltime| feature}
8995
8996 If the {skip} expression is given it is evaluated with the
8997 cursor positioned on the start of a match. If it evaluates to
8998 non-zero this match is skipped. This can be used, for
8999 example, to skip a match in a comment or a string.
9000 {skip} can be a string, which is evaluated as an expression, a
9001 function reference or a lambda.
9002 When {skip} is omitted or empty, every match is accepted.
9003 When evaluating {skip} causes an error the search is aborted
9004 and -1 returned.
9005 *search()-sub-match*
9006 With the 'p' flag the returned value is one more than the
9007 first sub-match in \(\). One if none of them matched but the
9008 whole pattern did match.
9009 To get the column number too use |searchpos()|.
9010
9011 The cursor will be positioned at the match, unless the 'n'
9012 flag is used.
9013
9014 Example (goes over all files in the argument list): >
9015 :let n = 1
9016 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009017 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009018 : " start at the last char in the file and wrap for the
9019 : " first search to find match at start of file
9020 : normal G$
9021 : let flags = "w"
9022 : while search("foo", flags) > 0
9023 : s/foo/bar/g
9024 : let flags = "W"
9025 : endwhile
9026 : update " write the file if modified
9027 : let n = n + 1
9028 :endwhile
9029<
9030 Example for using some flags: >
9031 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9032< This will search for the keywords "if", "else", and "endif"
9033 under or after the cursor. Because of the 'p' flag, it
9034 returns 1, 2, or 3 depending on which keyword is found, or 0
9035 if the search fails. With the cursor on the first word of the
9036 line:
9037 if (foo == 0) | let foo = foo + 1 | endif ~
9038 the function returns 1. Without the 'c' flag, the function
9039 finds the "endif" and returns 3. The same thing happens
9040 without the 'e' flag if the cursor is on the "f" of "if".
9041 The 'n' flag tells the function not to move the cursor.
9042
9043 Can also be used as a |method|: >
9044 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009045<
9046 Return type: |Number|
9047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009048
9049searchcount([{options}]) *searchcount()*
9050 Get or update the last search count, like what is displayed
9051 without the "S" flag in 'shortmess'. This works even if
9052 'shortmess' does contain the "S" flag.
9053
9054 This returns a |Dictionary|. The dictionary is empty if the
9055 previous pattern was not set and "pattern" was not specified.
9056
9057 key type meaning ~
9058 current |Number| current position of match;
9059 0 if the cursor position is
9060 before the first match
9061 exact_match |Boolean| 1 if "current" is matched on
9062 "pos", otherwise 0
9063 total |Number| total count of matches found
9064 incomplete |Number| 0: search was fully completed
9065 1: recomputing was timed out
9066 2: max count exceeded
9067
9068 For {options} see further down.
9069
9070 To get the last search count when |n| or |N| was pressed, call
9071 this function with `recompute: 0` . This sometimes returns
9072 wrong information because |n| and |N|'s maximum count is 99.
9073 If it exceeded 99 the result must be max count + 1 (100). If
9074 you want to get correct information, specify `recompute: 1`: >
9075
9076 " result == maxcount + 1 (100) when many matches
9077 let result = searchcount(#{recompute: 0})
9078
9079 " Below returns correct result (recompute defaults
9080 " to 1)
9081 let result = searchcount()
9082<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009083 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009084 function! LastSearchCount() abort
9085 let result = searchcount(#{recompute: 0})
9086 if empty(result)
9087 return ''
9088 endif
9089 if result.incomplete ==# 1 " timed out
9090 return printf(' /%s [?/??]', @/)
9091 elseif result.incomplete ==# 2 " max count exceeded
9092 if result.total > result.maxcount &&
9093 \ result.current > result.maxcount
9094 return printf(' /%s [>%d/>%d]', @/,
9095 \ result.current, result.total)
9096 elseif result.total > result.maxcount
9097 return printf(' /%s [%d/>%d]', @/,
9098 \ result.current, result.total)
9099 endif
9100 endif
9101 return printf(' /%s [%d/%d]', @/,
9102 \ result.current, result.total)
9103 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009104 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009105
9106 " Or if you want to show the count only when
9107 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009108 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009109 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9110<
9111 You can also update the search count, which can be useful in a
9112 |CursorMoved| or |CursorMovedI| autocommand: >
9113
9114 autocmd CursorMoved,CursorMovedI *
9115 \ let s:searchcount_timer = timer_start(
9116 \ 200, function('s:update_searchcount'))
9117 function! s:update_searchcount(timer) abort
9118 if a:timer ==# s:searchcount_timer
9119 call searchcount(#{
9120 \ recompute: 1, maxcount: 0, timeout: 100})
9121 redrawstatus
9122 endif
9123 endfunction
9124<
9125 This can also be used to count matched texts with specified
9126 pattern in the current buffer using "pattern": >
9127
9128 " Count '\<foo\>' in this buffer
9129 " (Note that it also updates search count)
9130 let result = searchcount(#{pattern: '\<foo\>'})
9131
9132 " To restore old search count by old pattern,
9133 " search again
9134 call searchcount()
9135<
9136 {options} must be a |Dictionary|. It can contain:
9137 key type meaning ~
9138 recompute |Boolean| if |TRUE|, recompute the count
9139 like |n| or |N| was executed.
9140 otherwise returns the last
9141 computed result (when |n| or
9142 |N| was used when "S" is not
9143 in 'shortmess', or this
9144 function was called).
9145 (default: |TRUE|)
9146 pattern |String| recompute if this was given
9147 and different with |@/|.
9148 this works as same as the
9149 below command is executed
9150 before calling this function >
9151 let @/ = pattern
9152< (default: |@/|)
9153 timeout |Number| 0 or negative number is no
9154 timeout. timeout milliseconds
9155 for recomputing the result
9156 (default: 0)
9157 maxcount |Number| 0 or negative number is no
9158 limit. max count of matched
9159 text while recomputing the
9160 result. if search exceeded
9161 total count, "total" value
9162 becomes `maxcount + 1`
9163 (default: 99)
9164 pos |List| `[lnum, col, off]` value
9165 when recomputing the result.
9166 this changes "current" result
9167 value. see |cursor()|,
9168 |getpos()|
9169 (default: cursor's position)
9170
9171 Can also be used as a |method|: >
9172 GetSearchOpts()->searchcount()
9173<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009174 Return type: dict<number>
9175
9176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009177searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9178 Search for the declaration of {name}.
9179
9180 With a non-zero {global} argument it works like |gD|, find
9181 first match in the file. Otherwise it works like |gd|, find
9182 first match in the function.
9183
9184 With a non-zero {thisblock} argument matches in a {} block
9185 that ends before the cursor position are ignored. Avoids
9186 finding variable declarations only valid in another scope.
9187
9188 Moves the cursor to the found match.
9189 Returns zero for success, non-zero for failure.
9190 Example: >
9191 if searchdecl('myvar') == 0
9192 echo getline('.')
9193 endif
9194<
9195 Can also be used as a |method|: >
9196 GetName()->searchdecl()
9197<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009198 Return type: |Number|
9199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009200 *searchpair()*
9201searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9202 [, {stopline} [, {timeout}]]]])
9203 Search for the match of a nested start-end pair. This can be
9204 used to find the "endif" that matches an "if", while other
9205 if/endif pairs in between are ignored.
9206 The search starts at the cursor. The default is to search
9207 forward, include 'b' in {flags} to search backward.
9208 If a match is found, the cursor is positioned at it and the
9209 line number is returned. If no match is found 0 or -1 is
9210 returned and the cursor doesn't move. No error message is
9211 given.
9212
9213 {start}, {middle} and {end} are patterns, see |pattern|. They
9214 must not contain \( \) pairs. Use of \%( \) is allowed. When
9215 {middle} is not empty, it is found when searching from either
9216 direction, but only when not in a nested start-end pair. A
9217 typical use is: >
9218 searchpair('\<if\>', '\<else\>', '\<endif\>')
9219< By leaving {middle} empty the "else" is skipped.
9220
9221 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9222 |search()|. Additionally:
9223 'r' Repeat until no more matches found; will find the
9224 outer pair. Implies the 'W' flag.
9225 'm' Return number of matches instead of line number with
9226 the match; will be > 1 when 'r' is used.
9227 Note: it's nearly always a good idea to use the 'W' flag, to
9228 avoid wrapping around the end of the file.
9229
9230 When a match for {start}, {middle} or {end} is found, the
9231 {skip} expression is evaluated with the cursor positioned on
9232 the start of the match. It should return non-zero if this
9233 match is to be skipped. E.g., because it is inside a comment
9234 or a string.
9235 When {skip} is omitted or empty, every match is accepted.
9236 When evaluating {skip} causes an error the search is aborted
9237 and -1 returned.
9238 {skip} can be a string, a lambda, a funcref or a partial.
9239 Anything else makes the function fail.
9240 In a `:def` function when the {skip} argument is a string
9241 constant it is compiled into instructions.
9242
9243 For {stopline} and {timeout} see |search()|.
9244
9245 The value of 'ignorecase' is used. 'magic' is ignored, the
9246 patterns are used like it's on.
9247
9248 The search starts exactly at the cursor. A match with
9249 {start}, {middle} or {end} at the next character, in the
9250 direction of searching, is the first one found. Example: >
9251 if 1
9252 if 2
9253 endif 2
9254 endif 1
9255< When starting at the "if 2", with the cursor on the "i", and
9256 searching forwards, the "endif 2" is found. When starting on
9257 the character just before the "if 2", the "endif 1" will be
9258 found. That's because the "if 2" will be found first, and
9259 then this is considered to be a nested if/endif from "if 2" to
9260 "endif 2".
9261 When searching backwards and {end} is more than one character,
9262 it may be useful to put "\zs" at the end of the pattern, so
9263 that when the cursor is inside a match with the end it finds
9264 the matching start.
9265
9266 Example, to find the "endif" command in a Vim script: >
9267
9268 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9269 \ 'getline(".") =~ "^\\s*\""')
9270
9271< The cursor must be at or after the "if" for which a match is
9272 to be found. Note that single-quote strings are used to avoid
9273 having to double the backslashes. The skip expression only
9274 catches comments at the start of a line, not after a command.
9275 Also, a word "en" or "if" halfway a line is considered a
9276 match.
9277 Another example, to search for the matching "{" of a "}": >
9278
9279 :echo searchpair('{', '', '}', 'bW')
9280
9281< This works when the cursor is at or before the "}" for which a
9282 match is to be found. To reject matches that syntax
9283 highlighting recognized as strings: >
9284
9285 :echo searchpair('{', '', '}', 'bW',
9286 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9287<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009288 Return type: |Number|
9289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009290 *searchpairpos()*
9291searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9292 [, {stopline} [, {timeout}]]]])
9293 Same as |searchpair()|, but returns a |List| with the line and
9294 column position of the match. The first element of the |List|
9295 is the line number and the second element is the byte index of
9296 the column position of the match. If no match is found,
9297 returns [0, 0]. >
9298
9299 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9300<
9301 See |match-parens| for a bigger and more useful example.
9302
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009303 Return type: list<number>
9304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009305 *searchpos()*
9306searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9307 Same as |search()|, but returns a |List| with the line and
9308 column position of the match. The first element of the |List|
9309 is the line number and the second element is the byte index of
9310 the column position of the match. If no match is found,
9311 returns [0, 0].
9312 Example: >
9313 :let [lnum, col] = searchpos('mypattern', 'n')
9314
9315< When the 'p' flag is given then there is an extra item with
9316 the sub-pattern match number |search()-sub-match|. Example: >
9317 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9318< In this example "submatch" is 2 when a lowercase letter is
9319 found |/\l|, 3 when an uppercase letter is found |/\u|.
9320
9321 Can also be used as a |method|: >
9322 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009323<
9324 Return type: list<number>
9325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009326
9327server2client({clientid}, {string}) *server2client()*
9328 Send a reply string to {clientid}. The most recent {clientid}
9329 that sent a string can be retrieved with expand("<client>").
9330 {only available when compiled with the |+clientserver| feature}
9331 Returns zero for success, -1 for failure.
9332 Note:
9333 This id has to be stored before the next command can be
9334 received. I.e. before returning from the received command and
9335 before calling any commands that waits for input.
9336 See also |clientserver|.
9337 Example: >
9338 :echo server2client(expand("<client>"), "HELLO")
9339
9340< Can also be used as a |method|: >
9341 GetClientId()->server2client(string)
9342<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009343 Return type: |Number|
9344
9345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009346serverlist() *serverlist()*
9347 Return a list of available server names, one per line.
9348 When there are no servers or the information is not available
9349 an empty string is returned. See also |clientserver|.
9350 {only available when compiled with the |+clientserver| feature}
9351 Example: >
9352 :echo serverlist()
9353<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009354 Return type: |String|
9355
9356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009357setbufline({buf}, {lnum}, {text}) *setbufline()*
9358 Set line {lnum} to {text} in buffer {buf}. This works like
9359 |setline()| for the specified buffer.
9360
9361 This function works only for loaded buffers. First call
9362 |bufload()| if needed.
9363
9364 To insert lines use |appendbufline()|.
9365 Any text properties in {lnum} are cleared.
9366
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009367 {text} can be a string to set one line, or a List of strings
9368 to set multiple lines. If the List extends below the last
9369 line then those lines are added. If the List is empty then
9370 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009371
9372 For the use of {buf}, see |bufname()| above.
9373
9374 {lnum} is used like with |setline()|.
9375 Use "$" to refer to the last line in buffer {buf}.
9376 When {lnum} is just below the last line the {text} will be
9377 added below the last line.
9378
9379 When {buf} is not a valid buffer, the buffer is not loaded or
9380 {lnum} is not valid then 1 is returned. In |Vim9| script an
9381 error is given.
9382 On success 0 is returned.
9383
9384 Can also be used as a |method|, the base is passed as the
9385 third argument: >
9386 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009387<
9388 Return type: |Number|
9389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009390
9391setbufvar({buf}, {varname}, {val}) *setbufvar()*
9392 Set option or local variable {varname} in buffer {buf} to
9393 {val}.
9394 This also works for a global or local window option, but it
9395 doesn't work for a global or local window variable.
9396 For a local window option the global value is unchanged.
9397 For the use of {buf}, see |bufname()| above.
9398 The {varname} argument is a string.
9399 Note that the variable name without "b:" must be used.
9400 Examples: >
9401 :call setbufvar(1, "&mod", 1)
9402 :call setbufvar("todo", "myvar", "foobar")
9403< This function is not available in the |sandbox|.
9404
9405 Can also be used as a |method|, the base is passed as the
9406 third argument: >
9407 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009408<
9409 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009410
9411
9412setcellwidths({list}) *setcellwidths()*
9413 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009414 tells Vim how wide characters are when displayed in the
9415 terminal, counted in screen cells. The values override
9416 'ambiwidth'. Example: >
9417 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009418 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009419 \ [0x2194, 0x2199, 2],
9420 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009421
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009422< The {list} argument is a List of Lists with each three
9423 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9424 {low} and {high} can be the same, in which case this refers to
9425 one character. Otherwise it is the range of characters from
9426 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009427 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009428
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009429 {width} must be either 1 or 2, indicating the character width
9430 in screen cells. *E1112*
9431 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009432 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009434 If the new value causes 'fillchars' or 'listchars' to become
9435 invalid it is rejected and an error is given.
9436
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009437 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009438 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009439
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009440< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009441 the effect for known emoji characters. Move the cursor
9442 through the text to check if the cell widths of your terminal
9443 match with what Vim knows about each emoji. If it doesn't
9444 look right you need to adjust the {list} argument.
9445
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009446 Return type: |Number|
9447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009448
9449setcharpos({expr}, {list}) *setcharpos()*
9450 Same as |setpos()| but uses the specified column number as the
9451 character index instead of the byte index in the line.
9452
9453 Example:
9454 With the text "여보세요" in line 8: >
9455 call setcharpos('.', [0, 8, 4, 0])
9456< positions the cursor on the fourth character '요'. >
9457 call setpos('.', [0, 8, 4, 0])
9458< positions the cursor on the second character '보'.
9459
9460 Can also be used as a |method|: >
9461 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009462<
9463 Return type: |Number|
9464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009465
9466setcharsearch({dict}) *setcharsearch()*
9467 Set the current character search information to {dict},
9468 which contains one or more of the following entries:
9469
9470 char character which will be used for a subsequent
9471 |,| or |;| command; an empty string clears the
9472 character search
9473 forward direction of character search; 1 for forward,
9474 0 for backward
9475 until type of character search; 1 for a |t| or |T|
9476 character search, 0 for an |f| or |F|
9477 character search
9478
9479 This can be useful to save/restore a user's character search
9480 from a script: >
9481 :let prevsearch = getcharsearch()
9482 :" Perform a command which clobbers user's search
9483 :call setcharsearch(prevsearch)
9484< Also see |getcharsearch()|.
9485
9486 Can also be used as a |method|: >
9487 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009488<
9489 Return type: dict<any>
9490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009491
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009492setcmdline({str} [, {pos}]) *setcmdline()*
9493 Set the command line to {str} and set the cursor position to
9494 {pos}.
9495 If {pos} is omitted, the cursor is positioned after the text.
9496 Returns 0 when successful, 1 when not editing the command
9497 line.
9498
9499 Can also be used as a |method|: >
9500 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009501<
9502 Return type: |Number|
9503
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009505setcmdpos({pos}) *setcmdpos()*
9506 Set the cursor position in the command line to byte position
9507 {pos}. The first position is 1.
9508 Use |getcmdpos()| to obtain the current position.
9509 Only works while editing the command line, thus you must use
9510 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9511 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9512 set after the command line is set to the expression. For
9513 |c_CTRL-R_=| it is set after evaluating the expression but
9514 before inserting the resulting text.
9515 When the number is too big the cursor is put at the end of the
9516 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009517 Returns 0 when successful, 1 when not editing the command
9518 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009519
9520 Can also be used as a |method|: >
9521 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009522<
9523 Return type: |Number|
9524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009525
9526setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9527setcursorcharpos({list})
9528 Same as |cursor()| but uses the specified column number as the
9529 character index instead of the byte index in the line.
9530
9531 Example:
9532 With the text "여보세요" in line 4: >
9533 call setcursorcharpos(4, 3)
9534< positions the cursor on the third character '세'. >
9535 call cursor(4, 3)
9536< positions the cursor on the first character '여'.
9537
9538 Can also be used as a |method|: >
9539 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009540<
9541 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009542
9543
9544setenv({name}, {val}) *setenv()*
9545 Set environment variable {name} to {val}. Example: >
9546 call setenv('HOME', '/home/myhome')
9547
9548< When {val} is |v:null| the environment variable is deleted.
9549 See also |expr-env|.
9550
9551 Can also be used as a |method|, the base is passed as the
9552 second argument: >
9553 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009554<
9555 Return type: |Number|
9556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009557
9558setfperm({fname}, {mode}) *setfperm()* *chmod*
9559 Set the file permissions for {fname} to {mode}.
9560 {mode} must be a string with 9 characters. It is of the form
9561 "rwxrwxrwx", where each group of "rwx" flags represent, in
9562 turn, the permissions of the owner of the file, the group the
9563 file belongs to, and other users. A '-' character means the
9564 permission is off, any other character means on. Multi-byte
9565 characters are not supported.
9566
9567 For example "rw-r-----" means read-write for the user,
9568 readable by the group, not accessible by others. "xx-x-----"
9569 would do the same thing.
9570
9571 Returns non-zero for success, zero for failure.
9572
9573 Can also be used as a |method|: >
9574 GetFilename()->setfperm(mode)
9575<
9576 To read permissions see |getfperm()|.
9577
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009578 Return type: |Number|
9579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009580
9581setline({lnum}, {text}) *setline()*
9582 Set line {lnum} of the current buffer to {text}. To insert
9583 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009584 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009585 Any text properties in {lnum} are cleared. See
9586 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009587
9588 {lnum} is used like with |getline()|.
9589 When {lnum} is just below the last line the {text} will be
9590 added below the last line.
9591 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009592 converted to a String. When {text} is an empty List then
9593 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009594
9595 If this succeeds, FALSE is returned. If this fails (most likely
9596 because {lnum} is invalid) TRUE is returned.
9597 In |Vim9| script an error is given if {lnum} is invalid.
9598
9599 Example: >
9600 :call setline(5, strftime("%c"))
9601
9602< When {text} is a |List| then line {lnum} and following lines
9603 will be set to the items in the list. Example: >
9604 :call setline(5, ['aaa', 'bbb', 'ccc'])
9605< This is equivalent to: >
9606 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9607 : call setline(n, l)
9608 :endfor
9609
9610< Note: The '[ and '] marks are not set.
9611
9612 Can also be used as a |method|, the base is passed as the
9613 second argument: >
9614 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009615<
9616 Return type: |Number|
9617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009618
9619setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9620 Create or replace or add to the location list for window {nr}.
9621 {nr} can be the window number or the |window-ID|.
9622 When {nr} is zero the current window is used.
9623
9624 For a location list window, the displayed location list is
9625 modified. For an invalid window number {nr}, -1 is returned.
9626 Otherwise, same as |setqflist()|.
9627 Also see |location-list|.
9628
9629 For {action} see |setqflist-action|.
9630
9631 If the optional {what} dictionary argument is supplied, then
9632 only the items listed in {what} are set. Refer to |setqflist()|
9633 for the list of supported keys in {what}.
9634
9635 Can also be used as a |method|, the base is passed as the
9636 second argument: >
9637 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009638<
9639 Return type: |Number|
9640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009641
9642setmatches({list} [, {win}]) *setmatches()*
9643 Restores a list of matches saved by |getmatches()| for the
9644 current window. Returns 0 if successful, otherwise -1. All
9645 current matches are cleared before the list is restored. See
9646 example for |getmatches()|.
9647 If {win} is specified, use the window with this number or
9648 window ID instead of the current window.
9649
9650 Can also be used as a |method|: >
9651 GetMatches()->setmatches()
9652<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009653 Return type: |Number|
9654
9655
9656setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009657 Set the position for String {expr}. Possible values:
9658 . the cursor
9659 'x mark x
9660
9661 {list} must be a |List| with four or five numbers:
9662 [bufnum, lnum, col, off]
9663 [bufnum, lnum, col, off, curswant]
9664
9665 "bufnum" is the buffer number. Zero can be used for the
9666 current buffer. When setting an uppercase mark "bufnum" is
9667 used for the mark position. For other marks it specifies the
9668 buffer to set the mark in. You can use the |bufnr()| function
9669 to turn a file name into a buffer number.
9670 For setting the cursor and the ' mark "bufnum" is ignored,
9671 since these are associated with a window, not a buffer.
9672 Does not change the jumplist.
9673
9674 "lnum" and "col" are the position in the buffer. The first
9675 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9676 smaller than 1 then 1 is used. To use the character count
9677 instead of the byte count, use |setcharpos()|.
9678
9679 The "off" number is only used when 'virtualedit' is set. Then
9680 it is the offset in screen columns from the start of the
9681 character. E.g., a position within a <Tab> or after the last
9682 character.
9683
9684 The "curswant" number is only used when setting the cursor
9685 position. It sets the preferred column for when moving the
9686 cursor vertically. When the "curswant" number is missing the
9687 preferred column is not set. When it is present and setting a
9688 mark position it is not used.
9689
9690 Note that for '< and '> changing the line number may result in
9691 the marks to be effectively be swapped, so that '< is always
9692 before '>.
9693
9694 Returns 0 when the position could be set, -1 otherwise.
9695 An error message is given if {expr} is invalid.
9696
9697 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9698
9699 This does not restore the preferred column for moving
9700 vertically; if you set the cursor position with this, |j| and
9701 |k| motions will jump to previous columns! Use |cursor()| to
9702 also set the preferred column. Also see the "curswant" key in
9703 |winrestview()|.
9704
9705 Can also be used as a |method|: >
9706 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009707<
9708 Return type: |Number|
9709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009710
9711setqflist({list} [, {action} [, {what}]]) *setqflist()*
9712 Create or replace or add to the quickfix list.
9713
9714 If the optional {what} dictionary argument is supplied, then
9715 only the items listed in {what} are set. The first {list}
9716 argument is ignored. See below for the supported items in
9717 {what}.
9718 *setqflist-what*
9719 When {what} is not present, the items in {list} are used. Each
9720 item must be a dictionary. Non-dictionary items in {list} are
9721 ignored. Each dictionary item can contain the following
9722 entries:
9723
9724 bufnr buffer number; must be the number of a valid
9725 buffer
9726 filename name of a file; only used when "bufnr" is not
9727 present or it is invalid.
9728 module name of a module; if given it will be used in
9729 quickfix error window instead of the filename.
9730 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009731 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009732 pattern search pattern used to locate the error
9733 col column number
9734 vcol when non-zero: "col" is visual column
9735 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009736 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009737 nr error number
9738 text description of the error
9739 type single-character error type, 'E', 'W', etc.
9740 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009741 user_data custom data associated with the item, can be
9742 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009743
9744 The "col", "vcol", "nr", "type" and "text" entries are
9745 optional. Either "lnum" or "pattern" entry can be used to
9746 locate a matching error line.
9747 If the "filename" and "bufnr" entries are not present or
9748 neither the "lnum" or "pattern" entries are present, then the
9749 item will not be handled as an error line.
9750 If both "pattern" and "lnum" are present then "pattern" will
9751 be used.
9752 If the "valid" entry is not supplied, then the valid flag is
9753 set when "bufnr" is a valid buffer or "filename" exists.
9754 If you supply an empty {list}, the quickfix list will be
9755 cleared.
9756 Note that the list is not exactly the same as what
9757 |getqflist()| returns.
9758
9759 {action} values: *setqflist-action* *E927*
9760 'a' The items from {list} are added to the existing
9761 quickfix list. If there is no existing list, then a
9762 new list is created.
9763
9764 'r' The items from the current quickfix list are replaced
9765 with the items from {list}. This can also be used to
9766 clear the list: >
9767 :call setqflist([], 'r')
9768<
9769 'f' All the quickfix lists in the quickfix stack are
9770 freed.
9771
9772 If {action} is not present or is set to ' ', then a new list
9773 is created. The new quickfix list is added after the current
9774 quickfix list in the stack and all the following lists are
9775 freed. To add a new quickfix list at the end of the stack,
9776 set "nr" in {what} to "$".
9777
9778 The following items can be specified in dictionary {what}:
9779 context quickfix list context. See |quickfix-context|
9780 efm errorformat to use when parsing text from
9781 "lines". If this is not present, then the
9782 'errorformat' option value is used.
9783 See |quickfix-parse|
9784 id quickfix list identifier |quickfix-ID|
9785 idx index of the current entry in the quickfix
9786 list specified by 'id' or 'nr'. If set to '$',
9787 then the last entry in the list is set as the
9788 current entry. See |quickfix-index|
9789 items list of quickfix entries. Same as the {list}
9790 argument.
9791 lines use 'errorformat' to parse a list of lines and
9792 add the resulting entries to the quickfix list
9793 {nr} or {id}. Only a |List| value is supported.
9794 See |quickfix-parse|
9795 nr list number in the quickfix stack; zero
9796 means the current quickfix list and "$" means
9797 the last quickfix list.
9798 quickfixtextfunc
9799 function to get the text to display in the
9800 quickfix window. The value can be the name of
9801 a function or a funcref or a lambda. Refer to
9802 |quickfix-window-function| for an explanation
9803 of how to write the function and an example.
9804 title quickfix list title text. See |quickfix-title|
9805 Unsupported keys in {what} are ignored.
9806 If the "nr" item is not present, then the current quickfix list
9807 is modified. When creating a new quickfix list, "nr" can be
9808 set to a value one greater than the quickfix stack size.
9809 When modifying a quickfix list, to guarantee that the correct
9810 list is modified, "id" should be used instead of "nr" to
9811 specify the list.
9812
9813 Examples (See also |setqflist-examples|): >
9814 :call setqflist([], 'r', {'title': 'My search'})
9815 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9816 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9817<
9818 Returns zero for success, -1 for failure.
9819
9820 This function can be used to create a quickfix list
9821 independent of the 'errorformat' setting. Use a command like
9822 `:cc 1` to jump to the first position.
9823
9824 Can also be used as a |method|, the base is passed as the
9825 second argument: >
9826 GetErrorlist()->setqflist()
9827<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009828 Return type: |Number|
9829
9830
9831setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009832 Set the register {regname} to {value}.
9833 If {regname} is "" or "@", the unnamed register '"' is used.
9834 The {regname} argument is a string. In |Vim9-script|
9835 {regname} must be one character.
9836
9837 {value} may be any value returned by |getreg()| or
9838 |getreginfo()|, including a |List| or |Dict|.
9839 If {options} contains "a" or {regname} is upper case,
9840 then the value is appended.
9841
9842 {options} can also contain a register type specification:
9843 "c" or "v" |characterwise| mode
9844 "l" or "V" |linewise| mode
9845 "b" or "<CTRL-V>" |blockwise-visual| mode
9846 If a number immediately follows "b" or "<CTRL-V>" then this is
9847 used as the width of the selection - if it is not specified
9848 then the width of the block is set to the number of characters
9849 in the longest line (counting a <Tab> as 1 character).
9850
9851 If {options} contains no register settings, then the default
9852 is to use character mode unless {value} ends in a <NL> for
9853 string {value} and linewise mode for list {value}. Blockwise
9854 mode is never selected automatically.
9855 Returns zero for success, non-zero for failure.
9856
9857 *E883*
9858 Note: you may not use |List| containing more than one item to
9859 set search and expression registers. Lists containing no
9860 items act like empty strings.
9861
9862 Examples: >
9863 :call setreg(v:register, @*)
9864 :call setreg('*', @%, 'ac')
9865 :call setreg('a', "1\n2\n3", 'b5')
9866 :call setreg('"', { 'points_to': 'a'})
9867
9868< This example shows using the functions to save and restore a
9869 register: >
9870 :let var_a = getreginfo()
9871 :call setreg('a', var_a)
9872< or: >
9873 :let var_a = getreg('a', 1, 1)
9874 :let var_amode = getregtype('a')
9875 ....
9876 :call setreg('a', var_a, var_amode)
9877< Note: you may not reliably restore register value
9878 without using the third argument to |getreg()| as without it
9879 newlines are represented as newlines AND Nul bytes are
9880 represented as newlines as well, see |NL-used-for-Nul|.
9881
9882 You can also change the type of a register by appending
9883 nothing: >
9884 :call setreg('a', '', 'al')
9885
9886< Can also be used as a |method|, the base is passed as the
9887 second argument: >
9888 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009889<
9890 Return type: |Number|
9891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009892
9893settabvar({tabnr}, {varname}, {val}) *settabvar()*
9894 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9895 |t:var|
9896 The {varname} argument is a string.
9897 Note that autocommands are blocked, side effects may not be
9898 triggered, e.g. when setting 'filetype'.
9899 Note that the variable name without "t:" must be used.
9900 Tabs are numbered starting with one.
9901 This function is not available in the |sandbox|.
9902
9903 Can also be used as a |method|, the base is passed as the
9904 third argument: >
9905 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009906<
9907 Return type: |Number|
9908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009909
9910settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9911 Set option or local variable {varname} in window {winnr} to
9912 {val}.
9913 Tabs are numbered starting with one. For the current tabpage
9914 use |setwinvar()|.
9915 {winnr} can be the window number or the |window-ID|.
9916 When {winnr} is zero the current window is used.
9917 Note that autocommands are blocked, side effects may not be
9918 triggered, e.g. when setting 'filetype' or 'syntax'.
9919 This also works for a global or local buffer option, but it
9920 doesn't work for a global or local buffer variable.
9921 For a local buffer option the global value is unchanged.
9922 Note that the variable name without "w:" must be used.
9923 Examples: >
9924 :call settabwinvar(1, 1, "&list", 0)
9925 :call settabwinvar(3, 2, "myvar", "foobar")
9926< This function is not available in the |sandbox|.
9927
9928 Can also be used as a |method|, the base is passed as the
9929 fourth argument: >
9930 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009931<
9932 Return type: |Number|
9933
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009934
9935settagstack({nr}, {dict} [, {action}]) *settagstack()*
9936 Modify the tag stack of the window {nr} using {dict}.
9937 {nr} can be the window number or the |window-ID|.
9938
9939 For a list of supported items in {dict}, refer to
9940 |gettagstack()|. "curidx" takes effect before changing the tag
9941 stack.
9942 *E962*
9943 How the tag stack is modified depends on the {action}
9944 argument:
9945 - If {action} is not present or is set to 'r', then the tag
9946 stack is replaced.
9947 - If {action} is set to 'a', then new entries from {dict} are
9948 pushed (added) onto the tag stack.
9949 - If {action} is set to 't', then all the entries from the
9950 current entry in the tag stack or "curidx" in {dict} are
9951 removed and then new entries are pushed to the stack.
9952
9953 The current index is set to one after the length of the tag
9954 stack after the modification.
9955
9956 Returns zero for success, -1 for failure.
9957
9958 Examples (for more examples see |tagstack-examples|):
9959 Empty the tag stack of window 3: >
9960 call settagstack(3, {'items' : []})
9961
9962< Save and restore the tag stack: >
9963 let stack = gettagstack(1003)
9964 " do something else
9965 call settagstack(1003, stack)
9966 unlet stack
9967<
9968 Can also be used as a |method|, the base is passed as the
9969 second argument: >
9970 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009971<
9972 Return type: |Number|
9973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009974
9975setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9976 Like |settabwinvar()| for the current tab page.
9977 Examples: >
9978 :call setwinvar(1, "&list", 0)
9979 :call setwinvar(2, "myvar", "foobar")
9980
9981< Can also be used as a |method|, the base is passed as the
9982 third argument: >
9983 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009984<
9985 Return type: |Number|
9986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009987
9988sha256({string}) *sha256()*
9989 Returns a String with 64 hex characters, which is the SHA256
9990 checksum of {string}.
9991
9992 Can also be used as a |method|: >
9993 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009994<
9995 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009996
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009997 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009998
9999shellescape({string} [, {special}]) *shellescape()*
10000 Escape {string} for use as a shell command argument.
10001 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010002 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010003 in single quotes and will double up all internal single
10004 quotes.
10005 On MS-Windows, when 'shellslash' is not set, it will enclose
10006 {string} in double quotes and double all double quotes within
10007 {string}.
10008 Otherwise it will enclose {string} in single quotes and
10009 replace all "'" with "'\''".
10010
Enno5faeb602024-05-15 21:54:19 +020010011 The {special} argument adds additional escaping of keywords
10012 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010013 number or a non-empty String (|non-zero-arg|), then special
10014 items such as "!", "%", "#" and "<cword>" (as listed in
10015 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010016 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010017
10018 The "!" character will be escaped (again with a |non-zero-arg|
10019 {special}) when 'shell' contains "csh" in the tail. That is
10020 because for csh and tcsh "!" is used for history replacement
10021 even when inside single quotes.
10022
10023 With a |non-zero-arg| {special} the <NL> character is also
10024 escaped. When 'shell' containing "csh" in the tail it's
10025 escaped a second time.
10026
10027 The "\" character will be escaped when 'shell' contains "fish"
10028 in the tail. That is because for fish "\" is used as an escape
10029 character inside single quotes.
10030
10031 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010032 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010033< This results in a directory listing for the file under the
10034 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010035 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010036< See also |::S|.
10037
10038 Can also be used as a |method|: >
10039 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010040<
10041 Return type: |String|
10042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010043
10044shiftwidth([{col}]) *shiftwidth()*
10045 Returns the effective value of 'shiftwidth'. This is the
10046 'shiftwidth' value unless it is zero, in which case it is the
10047 'tabstop' value. This function was introduced with patch
10048 7.3.694 in 2012, everybody should have it by now (however it
10049 did not allow for the optional {col} argument until 8.1.542).
10050
10051 When there is one argument {col} this is used as column number
10052 for which to return the 'shiftwidth' value. This matters for the
10053 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10054 no {col} argument is given, column 1 will be assumed.
10055
10056 Can also be used as a |method|: >
10057 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010058<
10059 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010060
10061sign_ functions are documented here: |sign-functions-details|
10062
10063
10064simplify({filename}) *simplify()*
10065 Simplify the file name as much as possible without changing
10066 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10067 Unix) are not resolved. If the first path component in
10068 {filename} designates the current directory, this will be
10069 valid for the result as well. A trailing path separator is
10070 not removed either. On Unix "//path" is unchanged, but
10071 "///path" is simplified to "/path" (this follows the Posix
10072 standard).
10073 Example: >
10074 simplify("./dir/.././/file/") == "./file/"
10075< Note: The combination "dir/.." is only removed if "dir" is
10076 a searchable directory or does not exist. On Unix, it is also
10077 removed when "dir" is a symbolic link within the same
10078 directory. In order to resolve all the involved symbolic
10079 links before simplifying the path name, use |resolve()|.
10080
10081 Can also be used as a |method|: >
10082 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010083<
10084 Return type: |String|
10085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010086
10087sin({expr}) *sin()*
10088 Return the sine of {expr}, measured in radians, as a |Float|.
10089 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010090 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010091 Examples: >
10092 :echo sin(100)
10093< -0.506366 >
10094 :echo sin(-4.01)
10095< 0.763301
10096
10097 Can also be used as a |method|: >
10098 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010099<
10100 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010101
10102
10103sinh({expr}) *sinh()*
10104 Return the hyperbolic sine of {expr} as a |Float| in the range
10105 [-inf, inf].
10106 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010107 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010108 Examples: >
10109 :echo sinh(0.5)
10110< 0.521095 >
10111 :echo sinh(-0.9)
10112< -1.026517
10113
10114 Can also be used as a |method|: >
10115 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010116<
10117 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010118
10119
10120slice({expr}, {start} [, {end}]) *slice()*
10121 Similar to using a |slice| "expr[start : end]", but "end" is
10122 used exclusive. And for a string the indexes are used as
10123 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010124 |vim9script|. Also, composing characters are treated as a
10125 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010126 When {end} is omitted the slice continues to the last item.
10127 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010128 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010129
10130 Can also be used as a |method|: >
10131 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010132<
10133 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010134
10135
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010136sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010137 Sort the items in {list} in-place. Returns {list}.
10138
10139 If you want a list to remain unmodified make a copy first: >
10140 :let sortedlist = sort(copy(mylist))
10141
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010142< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010143 string representation of each item to sort on. Numbers sort
10144 after Strings, |Lists| after Numbers. For sorting text in the
10145 current buffer use |:sort|.
10146
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010147 When {how} is given and it is 'i' then case is ignored.
10148 In legacy script, for backwards compatibility, the value one
10149 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010150
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010151 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010152 locale is used for ordering. Implementation details: strcoll()
10153 is used to compare strings. See |:language| check or set the
10154 collation locale. |v:collate| can also be used to check the
10155 current locale. Sorting using the locale typically ignores
10156 case. Example: >
10157 " ö is sorted similarly to o with English locale.
10158 :language collate en_US.UTF8
10159 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10160< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10161>
10162 " ö is sorted after z with Swedish locale.
10163 :language collate sv_SE.UTF8
10164 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10165< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10166 This does not work properly on Mac.
10167
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010168 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010169 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010170 strtod() function to parse numbers. Strings, Lists, Dicts and
10171 Funcrefs will be considered as being 0). Note that this won't
10172 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010173
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010174 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010175 sorted numerical. This is like 'n' but a string containing
10176 digits will be used as the number they represent.
10177
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010178 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010179 sorted numerical. All values must be a Number or a Float.
10180
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010181 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010182 is called to compare items. The function is invoked with two
10183 items as argument and must return zero if they are equal, 1 or
10184 bigger if the first one sorts after the second one, -1 or
10185 smaller if the first one sorts before the second one.
10186
10187 {dict} is for functions with the "dict" attribute. It will be
10188 used to set the local variable "self". |Dictionary-function|
10189
10190 The sort is stable, items which compare equal (as number or as
10191 string) will keep their relative position. E.g., when sorting
10192 on numbers, text strings will sort next to each other, in the
10193 same order as they were originally.
10194
10195 Can also be used as a |method|: >
10196 mylist->sort()
10197
10198< Also see |uniq()|.
10199
10200 Example: >
10201 func MyCompare(i1, i2)
10202 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10203 endfunc
10204 eval mylist->sort("MyCompare")
10205< A shorter compare version for this specific simple case, which
10206 ignores overflow: >
10207 func MyCompare(i1, i2)
10208 return a:i1 - a:i2
10209 endfunc
10210< For a simple expression you can use a lambda: >
10211 eval mylist->sort({i1, i2 -> i1 - i2})
10212<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010213 Return type: list<{type}>
10214
10215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010216sound_clear() *sound_clear()*
10217 Stop playing all sounds.
10218
10219 On some Linux systems you may need the libcanberra-pulse
10220 package, otherwise sound may not stop.
10221
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010222 Return type: |Number|
10223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010224 {only available when compiled with the |+sound| feature}
10225
10226 *sound_playevent()*
10227sound_playevent({name} [, {callback}])
10228 Play a sound identified by {name}. Which event names are
10229 supported depends on the system. Often the XDG sound names
10230 are used. On Ubuntu they may be found in
10231 /usr/share/sounds/freedesktop/stereo. Example: >
10232 call sound_playevent('bell')
10233< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10234 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10235 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010236 On macOS, {name} refers to files located in
10237 /System/Library/Sounds (e.g. "Tink"). It will also work for
10238 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010239
10240 When {callback} is specified it is invoked when the sound is
10241 finished. The first argument is the sound ID, the second
10242 argument is the status:
10243 0 sound was played to the end
10244 1 sound was interrupted
10245 2 error occurred after sound started
10246 Example: >
10247 func Callback(id, status)
10248 echomsg "sound " .. a:id .. " finished with " .. a:status
10249 endfunc
10250 call sound_playevent('bell', 'Callback')
10251
10252< MS-Windows: {callback} doesn't work for this function.
10253
10254 Returns the sound ID, which can be passed to `sound_stop()`.
10255 Returns zero if the sound could not be played.
10256
10257 Can also be used as a |method|: >
10258 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010259<
10260 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010261
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010262 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010263
10264 *sound_playfile()*
10265sound_playfile({path} [, {callback}])
10266 Like `sound_playevent()` but play sound file {path}. {path}
10267 must be a full path. On Ubuntu you may find files to play
10268 with this command: >
10269 :!find /usr/share/sounds -type f | grep -v index.theme
10270
10271< Can also be used as a |method|: >
10272 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010273<
10274 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010275
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010276 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010277
10278
10279sound_stop({id}) *sound_stop()*
10280 Stop playing sound {id}. {id} must be previously returned by
10281 `sound_playevent()` or `sound_playfile()`.
10282
10283 On some Linux systems you may need the libcanberra-pulse
10284 package, otherwise sound may not stop.
10285
10286 On MS-Windows, this does not work for event sound started by
10287 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10288
10289 Can also be used as a |method|: >
10290 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010291<
10292 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010293
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010294 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010295
10296 *soundfold()*
10297soundfold({word})
10298 Return the sound-folded equivalent of {word}. Uses the first
10299 language in 'spelllang' for the current window that supports
10300 soundfolding. 'spell' must be set. When no sound folding is
10301 possible the {word} is returned unmodified.
10302 This can be used for making spelling suggestions. Note that
10303 the method can be quite slow.
10304
10305 Can also be used as a |method|: >
10306 GetWord()->soundfold()
10307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010308 Return type: |String|
10309
10310
10311spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010312 Without argument: The result is the badly spelled word under
10313 or after the cursor. The cursor is moved to the start of the
10314 bad word. When no bad word is found in the cursor line the
10315 result is an empty string and the cursor doesn't move.
10316
10317 With argument: The result is the first word in {sentence} that
10318 is badly spelled. If there are no spelling mistakes the
10319 result is an empty string.
10320
10321 The return value is a list with two items:
10322 - The badly spelled word or an empty string.
10323 - The type of the spelling error:
10324 "bad" spelling mistake
10325 "rare" rare word
10326 "local" word only valid in another region
10327 "caps" word should start with Capital
10328 Example: >
10329 echo spellbadword("the quik brown fox")
10330< ['quik', 'bad'] ~
10331
10332 The spelling information for the current window and the value
10333 of 'spelllang' are used.
10334
10335 Can also be used as a |method|: >
10336 GetText()->spellbadword()
10337<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010338 Return type: list<string>
10339
10340
10341spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010342 Return a |List| with spelling suggestions to replace {word}.
10343 When {max} is given up to this number of suggestions are
10344 returned. Otherwise up to 25 suggestions are returned.
10345
10346 When the {capital} argument is given and it's non-zero only
10347 suggestions with a leading capital will be given. Use this
10348 after a match with 'spellcapcheck'.
10349
10350 {word} can be a badly spelled word followed by other text.
10351 This allows for joining two words that were split. The
10352 suggestions also include the following text, thus you can
10353 replace a line.
10354
10355 {word} may also be a good word. Similar words will then be
10356 returned. {word} itself is not included in the suggestions,
10357 although it may appear capitalized.
10358
10359 The spelling information for the current window is used. The
10360 values of 'spelllang' and 'spellsuggest' are used.
10361
10362 Can also be used as a |method|: >
10363 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010364<
10365 Return type: list<string> or list<any>
10366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010367
10368split({string} [, {pattern} [, {keepempty}]]) *split()*
10369 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010370 empty each white space separated sequence of characters
10371 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010372 Otherwise the string is split where {pattern} matches,
10373 removing the matched characters. 'ignorecase' is not used
10374 here, add \c to ignore case. |/\c|
10375 When the first or last item is empty it is omitted, unless the
10376 {keepempty} argument is given and it's non-zero.
10377 Other empty items are kept when {pattern} matches at least one
10378 character or when {keepempty} is non-zero.
10379 Example: >
10380 :let words = split(getline('.'), '\W\+')
10381< To split a string in individual characters: >
10382 :for c in split(mystring, '\zs')
10383< If you want to keep the separator you can also use '\zs' at
10384 the end of the pattern: >
10385 :echo split('abc:def:ghi', ':\zs')
10386< ['abc:', 'def:', 'ghi'] ~
10387 Splitting a table where the first element can be empty: >
10388 :let items = split(line, ':', 1)
10389< The opposite function is |join()|.
10390
10391 Can also be used as a |method|: >
10392 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010393<
10394 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010395
10396sqrt({expr}) *sqrt()*
10397 Return the non-negative square root of Float {expr} as a
10398 |Float|.
10399 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010400 is negative the result is NaN (Not a Number). Returns 0.0 if
10401 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010402 Examples: >
10403 :echo sqrt(100)
10404< 10.0 >
10405 :echo sqrt(-4.01)
10406< nan
10407 "nan" may be different, it depends on system libraries.
10408
10409 Can also be used as a |method|: >
10410 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010411<
10412 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010413
10414
10415srand([{expr}]) *srand()*
10416 Initialize seed used by |rand()|:
10417 - If {expr} is not given, seed values are initialized by
10418 reading from /dev/urandom, if possible, or using time(NULL)
10419 a.k.a. epoch time otherwise; this only has second accuracy.
10420 - If {expr} is given it must be a Number. It is used to
10421 initialize the seed values. This is useful for testing or
10422 when a predictable sequence is intended.
10423
10424 Examples: >
10425 :let seed = srand()
10426 :let seed = srand(userinput)
10427 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010428<
10429 Return type: list<number>
10430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010431
10432state([{what}]) *state()*
10433 Return a string which contains characters indicating the
10434 current state. Mostly useful in callbacks that want to do
10435 work that may not always be safe. Roughly this works like:
10436 - callback uses state() to check if work is safe to do.
10437 Yes: then do it right away.
10438 No: add to work queue and add a |SafeState| and/or
10439 |SafeStateAgain| autocommand (|SafeState| triggers at
10440 toplevel, |SafeStateAgain| triggers after handling
10441 messages and callbacks).
10442 - When SafeState or SafeStateAgain is triggered and executes
10443 your autocommand, check with `state()` if the work can be
10444 done now, and if yes remove it from the queue and execute.
10445 Remove the autocommand if the queue is now empty.
10446 Also see |mode()|.
10447
10448 When {what} is given only characters in this string will be
10449 added. E.g, this checks if the screen has scrolled: >
10450 if state('s') == ''
10451 " screen has not scrolled
10452<
10453 These characters indicate the state, generally indicating that
10454 something is busy:
10455 m halfway a mapping, :normal command, feedkeys() or
10456 stuffed command
10457 o operator pending, e.g. after |d|
10458 a Insert mode autocomplete active
10459 x executing an autocommand
10460 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10461 ch_readraw() when reading json
10462 S not triggering SafeState or SafeStateAgain, e.g. after
10463 |f| or a count
10464 c callback invoked, including timer (repeats for
10465 recursiveness up to "ccc")
10466 s screen has scrolled for messages
10467
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010468 Return type: |String|
10469
10470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010471str2float({string} [, {quoted}]) *str2float()*
10472 Convert String {string} to a Float. This mostly works the
10473 same as when using a floating point number in an expression,
10474 see |floating-point-format|. But it's a bit more permissive.
10475 E.g., "1e40" is accepted, while in an expression you need to
10476 write "1.0e40". The hexadecimal form "0x123" is also
10477 accepted, but not others, like binary or octal.
10478 When {quoted} is present and non-zero then embedded single
10479 quotes before the dot are ignored, thus "1'000.0" is a
10480 thousand.
10481 Text after the number is silently ignored.
10482 The decimal point is always '.', no matter what the locale is
10483 set to. A comma ends the number: "12,345.67" is converted to
10484 12.0. You can strip out thousands separators with
10485 |substitute()|: >
10486 let f = str2float(substitute(text, ',', '', 'g'))
10487<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010488 Returns 0.0 if the conversion fails.
10489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010490 Can also be used as a |method|: >
10491 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010492<
10493 Return type: |Float|
10494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010495
10496str2list({string} [, {utf8}]) *str2list()*
10497 Return a list containing the number values which represent
10498 each character in String {string}. Examples: >
10499 str2list(" ") returns [32]
10500 str2list("ABC") returns [65, 66, 67]
10501< |list2str()| does the opposite.
10502
10503 When {utf8} is omitted or zero, the current 'encoding' is used.
10504 When {utf8} is TRUE, always treat the String as UTF-8
10505 characters. With UTF-8 composing characters are handled
10506 properly: >
10507 str2list("á") returns [97, 769]
10508
10509< Can also be used as a |method|: >
10510 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010511<
10512 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010513
10514
10515str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10516 Convert string {string} to a number.
10517 {base} is the conversion base, it can be 2, 8, 10 or 16.
10518 When {quoted} is present and non-zero then embedded single
10519 quotes are ignored, thus "1'000'000" is a million.
10520
10521 When {base} is omitted base 10 is used. This also means that
10522 a leading zero doesn't cause octal conversion to be used, as
10523 with the default String to Number conversion. Example: >
10524 let nr = str2nr('0123')
10525<
10526 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10527 different base the result will be zero. Similarly, when
10528 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10529 {base} is 2 a leading "0b" or "0B" is ignored.
10530 Text after the number is silently ignored.
10531
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010532 Returns 0 if {string} is empty or on error.
10533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010534 Can also be used as a |method|: >
10535 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010536<
10537 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010538
10539
10540strcharlen({string}) *strcharlen()*
10541 The result is a Number, which is the number of characters
10542 in String {string}. Composing characters are ignored.
10543 |strchars()| can count the number of characters, counting
10544 composing characters separately.
10545
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010546 Returns 0 if {string} is empty or on error.
10547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010548 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10549
10550 Can also be used as a |method|: >
10551 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010552<
10553 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010554
10555
10556strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10557 Like |strpart()| but using character index and length instead
10558 of byte index and length.
10559 When {skipcc} is omitted or zero, composing characters are
10560 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010561 When {skipcc} set to 1, composing characters are treated as a
10562 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010563 When a character index is used where a character does not
10564 exist it is omitted and counted as one character. For
10565 example: >
10566 strcharpart('abc', -1, 2)
10567< results in 'a'.
10568
Bram Moolenaard592deb2022-06-17 15:42:40 +010010569 Returns an empty string on error.
10570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010571 Can also be used as a |method|: >
10572 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010573<
10574 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010575
10576
10577strchars({string} [, {skipcc}]) *strchars()*
10578 The result is a Number, which is the number of characters
10579 in String {string}.
10580 When {skipcc} is omitted or zero, composing characters are
10581 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010582 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010583 |strcharlen()| always does this.
10584
Bram Moolenaard592deb2022-06-17 15:42:40 +010010585 Returns zero on error.
10586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010587 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10588
10589 {skipcc} is only available after 7.4.755. For backward
10590 compatibility, you can define a wrapper function: >
10591 if has("patch-7.4.755")
10592 function s:strchars(str, skipcc)
10593 return strchars(a:str, a:skipcc)
10594 endfunction
10595 else
10596 function s:strchars(str, skipcc)
10597 if a:skipcc
10598 return strlen(substitute(a:str, ".", "x", "g"))
10599 else
10600 return strchars(a:str)
10601 endif
10602 endfunction
10603 endif
10604<
10605 Can also be used as a |method|: >
10606 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010607<
10608 Return type: |Number|
10609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010610
10611strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10612 The result is a Number, which is the number of display cells
10613 String {string} occupies on the screen when it starts at {col}
10614 (first column is zero). When {col} is omitted zero is used.
10615 Otherwise it is the screen column where to start. This
10616 matters for Tab characters.
10617 The option settings of the current window are used. This
10618 matters for anything that's displayed differently, such as
10619 'tabstop' and 'display'.
10620 When {string} contains characters with East Asian Width Class
10621 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010622 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010623 Also see |strlen()|, |strwidth()| and |strchars()|.
10624
10625 Can also be used as a |method|: >
10626 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010627<
10628 Return type: |Number|
10629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010630
10631strftime({format} [, {time}]) *strftime()*
10632 The result is a String, which is a formatted date and time, as
10633 specified by the {format} string. The given {time} is used,
10634 or the current time if no time is given. The accepted
10635 {format} depends on your system, thus this is not portable!
10636 See the manual page of the C function strftime() for the
10637 format. The maximum length of the result is 80 characters.
10638 See also |localtime()|, |getftime()| and |strptime()|.
10639 The language can be changed with the |:language| command.
10640 Examples: >
10641 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10642 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10643 :echo strftime("%y%m%d %T") 970427 11:53:55
10644 :echo strftime("%H:%M") 11:55
10645 :echo strftime("%c", getftime("file.c"))
10646 Show mod time of file.c.
10647< Not available on all systems. To check use: >
10648 :if exists("*strftime")
10649
10650< Can also be used as a |method|: >
10651 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010652<
10653 Return type: |String|
10654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010655
10656strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010657 Get a Number corresponding to the character at {index} in
10658 {str}. This uses a zero-based character index, not a byte
10659 index. Composing characters are considered separate
10660 characters here. Use |nr2char()| to convert the Number to a
10661 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010662 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010663 Also see |strcharpart()| and |strchars()|.
10664
10665 Can also be used as a |method|: >
10666 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010667<
10668 Return type: |Number|
10669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010670
10671stridx({haystack}, {needle} [, {start}]) *stridx()*
10672 The result is a Number, which gives the byte index in
10673 {haystack} of the first occurrence of the String {needle}.
10674 If {start} is specified, the search starts at index {start}.
10675 This can be used to find a second match: >
10676 :let colon1 = stridx(line, ":")
10677 :let colon2 = stridx(line, ":", colon1 + 1)
10678< The search is done case-sensitive.
10679 For pattern searches use |match()|.
10680 -1 is returned if the {needle} does not occur in {haystack}.
10681 See also |strridx()|.
10682 Examples: >
10683 :echo stridx("An Example", "Example") 3
10684 :echo stridx("Starting point", "Start") 0
10685 :echo stridx("Starting point", "start") -1
10686< *strstr()* *strchr()*
10687 stridx() works similar to the C function strstr(). When used
10688 with a single character it works similar to strchr().
10689
10690 Can also be used as a |method|: >
10691 GetHaystack()->stridx(needle)
10692<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010693 Return type: |Number|
10694
10695
10696string({expr}) *string()*
10697 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010698 Float, String, Blob or a composition of them, then the result
10699 can be parsed back with |eval()|.
10700 {expr} type result ~
10701 String 'string' (single quotes are doubled)
10702 Number 123
10703 Float 123.123456 or 1.123456e8
10704 Funcref function('name')
10705 Blob 0z00112233.44556677.8899
10706 List [item, item]
10707 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010708 Class class SomeName
10709 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010710 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010711 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010712
10713 When a |List| or |Dictionary| has a recursive reference it is
10714 replaced by "[...]" or "{...}". Using eval() on the result
10715 will then fail.
10716
mityu7f0bba22024-03-29 10:14:41 +010010717 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010718 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010719 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010721 Can also be used as a |method|: >
10722 mylist->string()
10723
10724< Also see |strtrans()|.
10725
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010726 Return type: |String|
10727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010728
10729strlen({string}) *strlen()*
10730 The result is a Number, which is the length of the String
10731 {string} in bytes.
10732 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010733 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010734 If you want to count the number of multibyte characters use
10735 |strchars()|.
10736 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10737
10738 Can also be used as a |method|: >
10739 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010740<
10741 Return type: |Number|
10742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010743
10744strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10745 The result is a String, which is part of {src}, starting from
10746 byte {start}, with the byte length {len}.
10747 When {chars} is present and TRUE then {len} is the number of
10748 characters positions (composing characters are not counted
10749 separately, thus "1" means one base character and any
10750 following composing characters).
10751 To count {start} as characters instead of bytes use
10752 |strcharpart()|.
10753
10754 When bytes are selected which do not exist, this doesn't
10755 result in an error, the bytes are simply omitted.
10756 If {len} is missing, the copy continues from {start} till the
10757 end of the {src}. >
10758 strpart("abcdefg", 3, 2) == "de"
10759 strpart("abcdefg", -2, 4) == "ab"
10760 strpart("abcdefg", 5, 4) == "fg"
10761 strpart("abcdefg", 3) == "defg"
10762
10763< Note: To get the first character, {start} must be 0. For
10764 example, to get the character under the cursor: >
10765 strpart(getline("."), col(".") - 1, 1, v:true)
10766<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010767 Returns an empty string on error.
10768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010769 Can also be used as a |method|: >
10770 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010771<
10772 Return type: |String|
10773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010774
10775strptime({format}, {timestring}) *strptime()*
10776 The result is a Number, which is a unix timestamp representing
10777 the date and time in {timestring}, which is expected to match
10778 the format specified in {format}.
10779
10780 The accepted {format} depends on your system, thus this is not
10781 portable! See the manual page of the C function strptime()
10782 for the format. Especially avoid "%c". The value of $TZ also
10783 matters.
10784
10785 If the {timestring} cannot be parsed with {format} zero is
10786 returned. If you do not know the format of {timestring} you
10787 can try different {format} values until you get a non-zero
10788 result.
10789
10790 See also |strftime()|.
10791 Examples: >
10792 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10793< 862156163 >
10794 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10795< Sun Apr 27 11:53:55 1997 >
10796 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10797< Sun Apr 27 12:53:55 1997
10798
10799 Can also be used as a |method|: >
10800 GetFormat()->strptime(timestring)
10801<
10802 Not available on all systems. To check use: >
10803 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010804<
10805 Return type: |Number|
10806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010807
10808strridx({haystack}, {needle} [, {start}]) *strridx()*
10809 The result is a Number, which gives the byte index in
10810 {haystack} of the last occurrence of the String {needle}.
10811 When {start} is specified, matches beyond this index are
10812 ignored. This can be used to find a match before a previous
10813 match: >
10814 :let lastcomma = strridx(line, ",")
10815 :let comma2 = strridx(line, ",", lastcomma - 1)
10816< The search is done case-sensitive.
10817 For pattern searches use |match()|.
10818 -1 is returned if the {needle} does not occur in {haystack}.
10819 If the {needle} is empty the length of {haystack} is returned.
10820 See also |stridx()|. Examples: >
10821 :echo strridx("an angry armadillo", "an") 3
10822< *strrchr()*
10823 When used with a single character it works similar to the C
10824 function strrchr().
10825
10826 Can also be used as a |method|: >
10827 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010828<
10829 Return type: |Number|
10830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010831
10832strtrans({string}) *strtrans()*
10833 The result is a String, which is {string} with all unprintable
10834 characters translated into printable characters |'isprint'|.
10835 Like they are shown in a window. Example: >
10836 echo strtrans(@a)
10837< This displays a newline in register a as "^@" instead of
10838 starting a new line.
10839
Bram Moolenaard592deb2022-06-17 15:42:40 +010010840 Returns an empty string on error.
10841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010842 Can also be used as a |method|: >
10843 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010844<
10845 Return type: |String|
10846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010847
Christian Brabandt67672ef2023-04-24 21:09:54 +010010848strutf16len({string} [, {countcc}]) *strutf16len()*
10849 The result is a Number, which is the number of UTF-16 code
10850 units in String {string} (after converting it to UTF-16).
10851
10852 When {countcc} is TRUE, composing characters are counted
10853 separately.
10854 When {countcc} is omitted or FALSE, composing characters are
10855 ignored.
10856
10857 Returns zero on error.
10858
10859 Also see |strlen()| and |strcharlen()|.
10860 Examples: >
10861 echo strutf16len('a') returns 1
10862 echo strutf16len('©') returns 1
10863 echo strutf16len('😊') returns 2
10864 echo strutf16len('ą́') returns 1
10865 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010866<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010867 Can also be used as a |method|: >
10868 GetText()->strutf16len()
10869<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010870 Return type: |Number|
10871
10872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010873strwidth({string}) *strwidth()*
10874 The result is a Number, which is the number of display cells
10875 String {string} occupies. A Tab character is counted as one
10876 cell, alternatively use |strdisplaywidth()|.
10877 When {string} contains characters with East Asian Width Class
10878 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010879 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010880 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10881
10882 Can also be used as a |method|: >
10883 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010884<
10885 Return type: |Number|
10886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010887
10888submatch({nr} [, {list}]) *submatch()* *E935*
10889 Only for an expression in a |:substitute| command or
10890 substitute() function.
10891 Returns the {nr}'th submatch of the matched text. When {nr}
10892 is 0 the whole matched text is returned.
10893 Note that a NL in the string can stand for a line break of a
10894 multi-line match or a NUL character in the text.
10895 Also see |sub-replace-expression|.
10896
10897 If {list} is present and non-zero then submatch() returns
10898 a list of strings, similar to |getline()| with two arguments.
10899 NL characters in the text represent NUL characters in the
10900 text.
10901 Only returns more than one item for |:substitute|, inside
10902 |substitute()| this list will always contain one or zero
10903 items, since there are no real line breaks.
10904
10905 When substitute() is used recursively only the submatches in
10906 the current (deepest) call can be obtained.
10907
Bram Moolenaard592deb2022-06-17 15:42:40 +010010908 Returns an empty string or list on error.
10909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010910 Examples: >
10911 :s/\d\+/\=submatch(0) + 1/
10912 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10913< This finds the first number in the line and adds one to it.
10914 A line break is included as a newline character.
10915
10916 Can also be used as a |method|: >
10917 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010918<
10919 Return type: |String| or list<string> depending on {list}
10920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010921
10922substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10923 The result is a String, which is a copy of {string}, in which
10924 the first match of {pat} is replaced with {sub}.
10925 When {flags} is "g", all matches of {pat} in {string} are
10926 replaced. Otherwise {flags} should be "".
10927
10928 This works like the ":substitute" command (without any flags).
10929 But the matching with {pat} is always done like the 'magic'
10930 option is set and 'cpoptions' is empty (to make scripts
10931 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10932 if you want to ignore or match case and ignore 'ignorecase'.
10933 'smartcase' is not used. See |string-match| for how {pat} is
10934 used.
10935
10936 A "~" in {sub} is not replaced with the previous {sub}.
10937 Note that some codes in {sub} have a special meaning
10938 |sub-replace-special|. For example, to replace something with
10939 "\n" (two characters), use "\\\\n" or '\\n'.
10940
10941 When {pat} does not match in {string}, {string} is returned
10942 unmodified.
10943
10944 Example: >
10945 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10946< This removes the last component of the 'path' option. >
10947 :echo substitute("testing", ".*", "\\U\\0", "")
10948< results in "TESTING".
10949
10950 When {sub} starts with "\=", the remainder is interpreted as
10951 an expression. See |sub-replace-expression|. Example: >
10952 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010953 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010954
10955< When {sub} is a Funcref that function is called, with one
10956 optional argument. Example: >
10957 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10958< The optional argument is a list which contains the whole
10959 matched string and up to nine submatches, like what
10960 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010961 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010962
Bram Moolenaard592deb2022-06-17 15:42:40 +010010963< Returns an empty string on error.
10964
10965 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010966 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010967<
10968 Return type: |String|
10969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010970
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010971swapfilelist() *swapfilelist()*
10972 Returns a list of swap file names, like what "vim -r" shows.
10973 See the |-r| command argument. The 'directory' option is used
10974 for the directories to inspect. If you only want to get a
10975 list of swap files in the current directory then temporarily
10976 set 'directory' to a dot: >
10977 let save_dir = &directory
10978 let &directory = '.'
10979 let swapfiles = swapfilelist()
10980 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010981<
10982 Return type: list<string>
10983
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010985swapinfo({fname}) *swapinfo()*
10986 The result is a dictionary, which holds information about the
10987 swapfile {fname}. The available fields are:
10988 version Vim version
10989 user user name
10990 host host name
10991 fname original file name
10992 pid PID of the Vim process that created the swap
10993 file
10994 mtime last modification time in seconds
10995 inode Optional: INODE number of the file
10996 dirty 1 if file was modified, 0 if not
10997 Note that "user" and "host" are truncated to at most 39 bytes.
10998 In case of failure an "error" item is added with the reason:
10999 Cannot open file: file not found or in accessible
11000 Cannot read file: cannot read first block
11001 Not a swap file: does not contain correct block ID
11002 Magic number mismatch: Info in first block is invalid
11003
11004 Can also be used as a |method|: >
11005 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011006<
11007 Return type: dict<any> or dict<string>
11008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011009
11010swapname({buf}) *swapname()*
11011 The result is the swap file path of the buffer {expr}.
11012 For the use of {buf}, see |bufname()| above.
11013 If buffer {buf} is the current buffer, the result is equal to
11014 |:swapname| (unless there is no swap file).
11015 If buffer {buf} has no swap file, returns an empty string.
11016
11017 Can also be used as a |method|: >
11018 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011019<
11020 Return type: |String|
11021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011022
11023synID({lnum}, {col}, {trans}) *synID()*
11024 The result is a Number, which is the syntax ID at the position
11025 {lnum} and {col} in the current window.
11026 The syntax ID can be used with |synIDattr()| and
11027 |synIDtrans()| to obtain syntax information about text.
11028
11029 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11030 line. 'synmaxcol' applies, in a longer line zero is returned.
11031 Note that when the position is after the last character,
11032 that's where the cursor can be in Insert mode, synID() returns
11033 zero. {lnum} is used like with |getline()|.
11034
11035 When {trans} is |TRUE|, transparent items are reduced to the
11036 item that they reveal. This is useful when wanting to know
11037 the effective color. When {trans} is |FALSE|, the transparent
11038 item is returned. This is useful when wanting to know which
11039 syntax item is effective (e.g. inside parens).
11040 Warning: This function can be very slow. Best speed is
11041 obtained by going through the file in forward direction.
11042
Bram Moolenaard592deb2022-06-17 15:42:40 +010011043 Returns zero on error.
11044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011045 Example (echoes the name of the syntax item under the cursor): >
11046 :echo synIDattr(synID(line("."), col("."), 1), "name")
11047<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011048 Return type: |Number|
11049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011050
11051synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11052 The result is a String, which is the {what} attribute of
11053 syntax ID {synID}. This can be used to obtain information
11054 about a syntax item.
11055 {mode} can be "gui", "cterm" or "term", to get the attributes
11056 for that mode. When {mode} is omitted, or an invalid value is
11057 used, the attributes for the currently active highlighting are
11058 used (GUI, cterm or term).
11059 Use synIDtrans() to follow linked highlight groups.
11060 {what} result
11061 "name" the name of the syntax item
11062 "fg" foreground color (GUI: color name used to set
11063 the color, cterm: color number as a string,
11064 term: empty string)
11065 "bg" background color (as with "fg")
11066 "font" font name (only available in the GUI)
11067 |highlight-font|
11068 "sp" special color for the GUI (as with "fg")
11069 |highlight-guisp|
11070 "ul" underline color for cterm: number as a string
11071 "fg#" like "fg", but for the GUI and the GUI is
11072 running the name in "#RRGGBB" form
11073 "bg#" like "fg#" for "bg"
11074 "sp#" like "fg#" for "sp"
11075 "bold" "1" if bold
11076 "italic" "1" if italic
11077 "reverse" "1" if reverse
11078 "inverse" "1" if inverse (= reverse)
11079 "standout" "1" if standout
11080 "underline" "1" if underlined
11081 "undercurl" "1" if undercurled
11082 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011083 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011084
Bram Moolenaard592deb2022-06-17 15:42:40 +010011085 Returns an empty string on error.
11086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011087 Example (echoes the color of the syntax item under the
11088 cursor): >
11089 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11090<
11091 Can also be used as a |method|: >
11092 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011093<
11094 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011095
11096
11097synIDtrans({synID}) *synIDtrans()*
11098 The result is a Number, which is the translated syntax ID of
11099 {synID}. This is the syntax group ID of what is being used to
11100 highlight the character. Highlight links given with
11101 ":highlight link" are followed.
11102
Bram Moolenaard592deb2022-06-17 15:42:40 +010011103 Returns zero on error.
11104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011105 Can also be used as a |method|: >
11106 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011107<
11108 Return type: |Number|
11109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011110
11111synconcealed({lnum}, {col}) *synconcealed()*
11112 The result is a |List| with currently three items:
11113 1. The first item in the list is 0 if the character at the
11114 position {lnum} and {col} is not part of a concealable
11115 region, 1 if it is. {lnum} is used like with |getline()|.
11116 2. The second item in the list is a string. If the first item
11117 is 1, the second item contains the text which will be
11118 displayed in place of the concealed text, depending on the
11119 current setting of 'conceallevel' and 'listchars'.
11120 3. The third and final item in the list is a number
11121 representing the specific syntax region matched in the
11122 line. When the character is not concealed the value is
11123 zero. This allows detection of the beginning of a new
11124 concealable region if there are two consecutive regions
11125 with the same replacement character. For an example, if
11126 the text is "123456" and both "23" and "45" are concealed
11127 and replaced by the character "X", then:
11128 call returns ~
11129 synconcealed(lnum, 1) [0, '', 0]
11130 synconcealed(lnum, 2) [1, 'X', 1]
11131 synconcealed(lnum, 3) [1, 'X', 1]
11132 synconcealed(lnum, 4) [1, 'X', 2]
11133 synconcealed(lnum, 5) [1, 'X', 2]
11134 synconcealed(lnum, 6) [0, '', 0]
11135
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011136 Note: Doesn't consider |matchadd()| highlighting items,
11137 since syntax and matching highlighting are two different
11138 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011139
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011140 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011142
11143synstack({lnum}, {col}) *synstack()*
11144 Return a |List|, which is the stack of syntax items at the
11145 position {lnum} and {col} in the current window. {lnum} is
11146 used like with |getline()|. Each item in the List is an ID
11147 like what |synID()| returns.
11148 The first item in the List is the outer region, following are
11149 items contained in that one. The last one is what |synID()|
11150 returns, unless not the whole item is highlighted or it is a
11151 transparent item.
11152 This function is useful for debugging a syntax file.
11153 Example that shows the syntax stack under the cursor: >
11154 for id in synstack(line("."), col("."))
11155 echo synIDattr(id, "name")
11156 endfor
11157< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011158 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011159 character in a line and the first column in an empty line are
11160 valid positions.
11161
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011162 Return type: list<number> or list<any>
11163
11164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011165system({expr} [, {input}]) *system()* *E677*
11166 Get the output of the shell command {expr} as a |String|. See
11167 |systemlist()| to get the output as a |List|.
11168
11169 When {input} is given and is a |String| this string is written
11170 to a file and passed as stdin to the command. The string is
11171 written as-is, you need to take care of using the correct line
11172 separators yourself.
11173 If {input} is given and is a |List| it is written to the file
11174 in a way |writefile()| does with {binary} set to "b" (i.e.
11175 with a newline between each list item with newlines inside
11176 list items converted to NULs).
11177 When {input} is given and is a number that is a valid id for
11178 an existing buffer then the content of the buffer is written
11179 to the file line by line, each line terminated by a NL and
11180 NULs characters where the text has a NL.
11181
11182 Pipes are not used, the 'shelltemp' option is not used.
11183
11184 When prepended by |:silent| the terminal will not be set to
11185 cooked mode. This is meant to be used for commands that do
11186 not need the user to type. It avoids stray characters showing
11187 up on the screen which require |CTRL-L| to remove. >
11188 :silent let f = system('ls *.vim')
11189<
11190 Note: Use |shellescape()| or |::S| with |expand()| or
11191 |fnamemodify()| to escape special characters in a command
11192 argument. Newlines in {expr} may cause the command to fail.
11193 The characters in 'shellquote' and 'shellxquote' may also
11194 cause trouble.
11195 This is not to be used for interactive commands.
11196
11197 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011198 :let files = system('ls ' .. shellescape(expand('%:h')))
11199 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011200
11201< To make the result more system-independent, the shell output
11202 is filtered to replace <CR> with <NL> for Macintosh, and
11203 <CR><NL> with <NL> for DOS-like systems.
11204 To avoid the string being truncated at a NUL, all NUL
11205 characters are replaced with SOH (0x01).
11206
11207 The command executed is constructed using several options:
11208 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11209 ({tmp} is an automatically generated file name).
11210 For Unix, braces are put around {expr} to allow for
11211 concatenated commands.
11212
11213 The command will be executed in "cooked" mode, so that a
11214 CTRL-C will interrupt the command (on Unix at least).
11215
11216 The resulting error code can be found in |v:shell_error|.
11217 This function will fail in |restricted-mode|.
11218
11219 Note that any wrong value in the options mentioned above may
11220 make the function fail. It has also been reported to fail
11221 when using a security agent application.
11222 Unlike ":!cmd" there is no automatic check for changed files.
11223 Use |:checktime| to force a check.
11224
11225 Can also be used as a |method|: >
11226 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011227<
11228 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011229
11230
11231systemlist({expr} [, {input}]) *systemlist()*
11232 Same as |system()|, but returns a |List| with lines (parts of
11233 output separated by NL) with NULs transformed into NLs. Output
11234 is the same as |readfile()| will output with {binary} argument
11235 set to "b", except that there is no extra empty item when the
11236 result ends in a NL.
11237 Note that on MS-Windows you may get trailing CR characters.
11238
11239 To see the difference between "echo hello" and "echo -n hello"
11240 use |system()| and |split()|: >
11241 echo system('echo hello')->split('\n', 1)
11242<
11243 Returns an empty string on error.
11244
11245 Can also be used as a |method|: >
11246 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011247<
11248 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011249
11250
11251tabpagebuflist([{arg}]) *tabpagebuflist()*
11252 The result is a |List|, where each item is the number of the
11253 buffer associated with each window in the current tab page.
11254 {arg} specifies the number of the tab page to be used. When
11255 omitted the current tab page is used.
11256 When {arg} is invalid the number zero is returned.
11257 To get a list of all buffers in all tabs use this: >
11258 let buflist = []
11259 for i in range(tabpagenr('$'))
11260 call extend(buflist, tabpagebuflist(i + 1))
11261 endfor
11262< Note that a buffer may appear in more than one window.
11263
11264 Can also be used as a |method|: >
11265 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011266<
11267 Return type: list<number>
11268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011269
11270tabpagenr([{arg}]) *tabpagenr()*
11271 The result is a Number, which is the number of the current
11272 tab page. The first tab page has number 1.
11273
11274 The optional argument {arg} supports the following values:
11275 $ the number of the last tab page (the tab page
11276 count).
11277 # the number of the last accessed tab page
11278 (where |g<Tab>| goes to). if there is no
11279 previous tab page 0 is returned.
11280 The number can be used with the |:tab| command.
11281
Bram Moolenaard592deb2022-06-17 15:42:40 +010011282 Returns zero on error.
11283
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011284 Return type: |Number|
11285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011286
11287tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11288 Like |winnr()| but for tab page {tabarg}.
11289 {tabarg} specifies the number of tab page to be used.
11290 {arg} is used like with |winnr()|:
11291 - When omitted the current window number is returned. This is
11292 the window which will be used when going to this tab page.
11293 - When "$" the number of windows is returned.
11294 - When "#" the previous window nr is returned.
11295 Useful examples: >
11296 tabpagewinnr(1) " current window of tab page 1
11297 tabpagewinnr(4, '$') " number of windows in tab page 4
11298< When {tabarg} is invalid zero is returned.
11299
11300 Can also be used as a |method|: >
11301 GetTabpage()->tabpagewinnr()
11302<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011303 Return type: |Number|
11304
11305
11306tagfiles() *tagfiles()*
11307 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011308 for the current buffer. This is the 'tags' option expanded.
11309
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011310 Return type: list<string> or list<any>
11311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011312
11313taglist({expr} [, {filename}]) *taglist()*
11314 Returns a |List| of tags matching the regular expression {expr}.
11315
11316 If {filename} is passed it is used to prioritize the results
11317 in the same way that |:tselect| does. See |tag-priority|.
11318 {filename} should be the full path of the file.
11319
11320 Each list item is a dictionary with at least the following
11321 entries:
11322 name Name of the tag.
11323 filename Name of the file where the tag is
11324 defined. It is either relative to the
11325 current directory or a full path.
11326 cmd Ex command used to locate the tag in
11327 the file.
11328 kind Type of the tag. The value for this
11329 entry depends on the language specific
11330 kind values. Only available when
11331 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011332 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011333 static A file specific tag. Refer to
11334 |static-tag| for more information.
11335 More entries may be present, depending on the content of the
11336 tags file: access, implementation, inherits and signature.
11337 Refer to the ctags documentation for information about these
11338 fields. For C code the fields "struct", "class" and "enum"
11339 may appear, they give the name of the entity the tag is
11340 contained in.
11341
11342 The ex-command "cmd" can be either an ex search pattern, a
11343 line number or a line number followed by a byte number.
11344
11345 If there are no matching tags, then an empty list is returned.
11346
11347 To get an exact tag match, the anchors '^' and '$' should be
11348 used in {expr}. This also make the function work faster.
11349 Refer to |tag-regexp| for more information about the tag
11350 search regular expression pattern.
11351
11352 Refer to |'tags'| for information about how the tags file is
11353 located by Vim. Refer to |tags-file-format| for the format of
11354 the tags file generated by the different ctags tools.
11355
11356 Can also be used as a |method|: >
11357 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011358<
11359 Return type: list<dict<any>> or list<any>
11360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011361
11362tan({expr}) *tan()*
11363 Return the tangent of {expr}, measured in radians, as a |Float|
11364 in the range [-inf, inf].
11365 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011366 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011367 Examples: >
11368 :echo tan(10)
11369< 0.648361 >
11370 :echo tan(-4.01)
11371< -1.181502
11372
11373 Can also be used as a |method|: >
11374 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011375<
11376 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011377
11378
11379tanh({expr}) *tanh()*
11380 Return the hyperbolic tangent of {expr} as a |Float| in the
11381 range [-1, 1].
11382 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011383 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011384 Examples: >
11385 :echo tanh(0.5)
11386< 0.462117 >
11387 :echo tanh(-1)
11388< -0.761594
11389
11390 Can also be used as a |method|: >
11391 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011392<
11393 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011394
11395
11396tempname() *tempname()* *temp-file-name*
11397 The result is a String, which is the name of a file that
11398 doesn't exist. It can be used for a temporary file. The name
11399 is different for at least 26 consecutive calls. Example: >
11400 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011401 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011402< For Unix, the file will be in a private directory |tempfile|
11403 that is recursively deleted when Vim exits, on other systems
11404 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011405 For MS-Windows forward slashes are used when the 'shellslash'
11406 option is set, or when 'shellcmdflag' starts with '-' and
11407 'shell' does not contain powershell or pwsh.
11408
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011409 Return type: |String|
11410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011411
11412term_ functions are documented here: |terminal-function-details|
11413
11414
11415terminalprops() *terminalprops()*
11416 Returns a |Dictionary| with properties of the terminal that Vim
11417 detected from the response to |t_RV| request. See
11418 |v:termresponse| for the response itself. If |v:termresponse|
11419 is empty most values here will be 'u' for unknown.
11420 cursor_style whether sending |t_RS| works **
11421 cursor_blink_mode whether sending |t_RC| works **
11422 underline_rgb whether |t_8u| works **
11423 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011424 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011425
11426 ** value 'u' for unknown, 'y' for yes, 'n' for no
11427
11428 If the |+termresponse| feature is missing then the result is
11429 an empty dictionary.
11430
11431 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11432 current cursor style.
11433 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11434 request the cursor blink status.
11435 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11436 is not empty, Vim will detect the working of sending |t_RS|
11437 and |t_RC| on startup.
11438
11439 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11440 This avoids sending it to xterm, which would clear the colors.
11441
11442 For "mouse" the value 'u' is unknown
11443
11444 Also see:
11445 - 'ambiwidth' - detected by using |t_u7|.
11446 - |v:termstyleresp| and |v:termblinkresp| for the response to
11447 |t_RS| and |t_RC|.
11448
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011449 Return type: dict<string>
11450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011451
11452test_ functions are documented here: |test-functions-details|
11453
11454
11455 *timer_info()*
11456timer_info([{id}])
11457 Return a list with information about timers.
11458 When {id} is given only information about this timer is
11459 returned. When timer {id} does not exist an empty list is
11460 returned.
11461 When {id} is omitted information about all timers is returned.
11462
11463 For each timer the information is stored in a |Dictionary| with
11464 these items:
11465 "id" the timer ID
11466 "time" time the timer was started with
11467 "remaining" time until the timer fires
11468 "repeat" number of times the timer will still fire;
11469 -1 means forever
11470 "callback" the callback
11471 "paused" 1 if the timer is paused, 0 otherwise
11472
11473 Can also be used as a |method|: >
11474 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011475<
11476 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011477
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011478 {only available when compiled with the |+timers| feature}
11479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011480
11481timer_pause({timer}, {paused}) *timer_pause()*
11482 Pause or unpause a timer. A paused timer does not invoke its
11483 callback when its time expires. Unpausing a timer may cause
11484 the callback to be invoked almost immediately if enough time
11485 has passed.
11486
11487 Pausing a timer is useful to avoid the callback to be called
11488 for a short time.
11489
11490 If {paused} evaluates to a non-zero Number or a non-empty
11491 String, then the timer is paused, otherwise it is unpaused.
11492 See |non-zero-arg|.
11493
11494 Can also be used as a |method|: >
11495 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011496<
11497 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011498
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011499 {only available when compiled with the |+timers| feature}
11500
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011501
11502 *timer_start()* *timer* *timers*
11503timer_start({time}, {callback} [, {options}])
11504 Create a timer and return the timer ID.
11505
11506 {time} is the waiting time in milliseconds. This is the
11507 minimum time before invoking the callback. When the system is
11508 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011509 Zero can be used to execute the callback when Vim is back in
11510 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011511
11512 {callback} is the function to call. It can be the name of a
11513 function or a |Funcref|. It is called with one argument, which
11514 is the timer ID. The callback is only invoked when Vim is
11515 waiting for input.
11516 If you want to show a message look at |popup_notification()|
11517 to avoid interfering with what the user is doing.
11518
11519 {options} is a dictionary. Supported entries:
11520 "repeat" Number of times to repeat calling the
11521 callback. -1 means forever. When not present
11522 the callback will be called once.
11523 If the timer causes an error three times in a
11524 row the repeat is cancelled. This avoids that
11525 Vim becomes unusable because of all the error
11526 messages.
11527
Bram Moolenaard592deb2022-06-17 15:42:40 +010011528 Returns -1 on error.
11529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011530 Example: >
11531 func MyHandler(timer)
11532 echo 'Handler called'
11533 endfunc
11534 let timer = timer_start(500, 'MyHandler',
11535 \ {'repeat': 3})
11536< This will invoke MyHandler() three times at 500 msec
11537 intervals.
11538
11539 Can also be used as a |method|: >
11540 GetMsec()->timer_start(callback)
11541
11542< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011543
11544 Return type: |Number|
11545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011546 {only available when compiled with the |+timers| feature}
11547
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011549timer_stop({timer}) *timer_stop()*
11550 Stop a timer. The timer callback will no longer be invoked.
11551 {timer} is an ID returned by timer_start(), thus it must be a
11552 Number. If {timer} does not exist there is no error.
11553
11554 Can also be used as a |method|: >
11555 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011556<
11557 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011558
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011559 {only available when compiled with the |+timers| feature}
11560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011561
11562timer_stopall() *timer_stopall()*
11563 Stop all timers. The timer callbacks will no longer be
11564 invoked. Useful if a timer is misbehaving. If there are no
11565 timers there is no error.
11566
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011567 Return type: |Number|
11568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011569 {only available when compiled with the |+timers| feature}
11570
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011572tolower({expr}) *tolower()*
11573 The result is a copy of the String given, with all uppercase
11574 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011575 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011576
11577 Can also be used as a |method|: >
11578 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011579<
11580 Return type: |String|
11581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011582
11583toupper({expr}) *toupper()*
11584 The result is a copy of the String given, with all lowercase
11585 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011586 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011587
11588 Can also be used as a |method|: >
11589 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011590<
11591 Return type: |String|
11592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011593
11594tr({src}, {fromstr}, {tostr}) *tr()*
11595 The result is a copy of the {src} string with all characters
11596 which appear in {fromstr} replaced by the character in that
11597 position in the {tostr} string. Thus the first character in
11598 {fromstr} is translated into the first character in {tostr}
11599 and so on. Exactly like the unix "tr" command.
11600 This code also deals with multibyte characters properly.
11601
Bram Moolenaard592deb2022-06-17 15:42:40 +010011602 Returns an empty string on error.
11603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011604 Examples: >
11605 echo tr("hello there", "ht", "HT")
11606< returns "Hello THere" >
11607 echo tr("<blob>", "<>", "{}")
11608< returns "{blob}"
11609
11610 Can also be used as a |method|: >
11611 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011612<
11613 Return type: |String|
11614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011615
11616trim({text} [, {mask} [, {dir}]]) *trim()*
11617 Return {text} as a String where any character in {mask} is
11618 removed from the beginning and/or end of {text}.
11619
Illia Bobyr80799172023-10-17 18:00:50 +020011620 If {mask} is not given, or is an empty string, {mask} is all
11621 characters up to 0x20, which includes Tab, space, NL and CR,
11622 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011623
11624 The optional {dir} argument specifies where to remove the
11625 characters:
11626 0 remove from the beginning and end of {text}
11627 1 remove only at the beginning of {text}
11628 2 remove only at the end of {text}
11629 When omitted both ends are trimmed.
11630
11631 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011632 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011633
11634 Examples: >
11635 echo trim(" some text ")
11636< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011637 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011638< returns "RESERVE_TAIL" >
11639 echo trim("rm<Xrm<>X>rrm", "rm<>")
11640< returns "Xrm<>X" (characters in the middle are not removed) >
11641 echo trim(" vim ", " ", 2)
11642< returns " vim"
11643
11644 Can also be used as a |method|: >
11645 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011646<
11647 Return type: |String|
11648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011649
11650trunc({expr}) *trunc()*
11651 Return the largest integral value with magnitude less than or
11652 equal to {expr} as a |Float| (truncate towards zero).
11653 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011654 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011655 Examples: >
11656 echo trunc(1.456)
11657< 1.0 >
11658 echo trunc(-5.456)
11659< -5.0 >
11660 echo trunc(4.0)
11661< 4.0
11662
11663 Can also be used as a |method|: >
11664 Compute()->trunc()
11665<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011666 Return type: |Float|
11667
11668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011669 *type()*
11670type({expr}) The result is a Number representing the type of {expr}.
11671 Instead of using the number directly, it is better to use the
11672 v:t_ variable that has the value:
11673 Number: 0 |v:t_number|
11674 String: 1 |v:t_string|
11675 Funcref: 2 |v:t_func|
11676 List: 3 |v:t_list|
11677 Dictionary: 4 |v:t_dict|
11678 Float: 5 |v:t_float|
11679 Boolean: 6 |v:t_bool| (v:false and v:true)
11680 None: 7 |v:t_none| (v:null and v:none)
11681 Job: 8 |v:t_job|
11682 Channel: 9 |v:t_channel|
11683 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011684 Class: 12 |v:t_class|
11685 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011686 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011687 Enum: 15 |v:t_enum|
11688 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011689 For backward compatibility, this method can be used: >
11690 :if type(myvar) == type(0)
11691 :if type(myvar) == type("")
11692 :if type(myvar) == type(function("tr"))
11693 :if type(myvar) == type([])
11694 :if type(myvar) == type({})
11695 :if type(myvar) == type(0.0)
11696 :if type(myvar) == type(v:false)
11697 :if type(myvar) == type(v:none)
11698< To check if the v:t_ variables exist use this: >
11699 :if exists('v:t_number')
11700
11701< Can also be used as a |method|: >
11702 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011703<
11704 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011705
11706
11707typename({expr}) *typename()*
11708 Return a string representation of the type of {expr}.
11709 Example: >
11710 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011711< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011712
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011713 Return type: |String|
11714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011715
11716undofile({name}) *undofile()*
11717 Return the name of the undo file that would be used for a file
11718 with name {name} when writing. This uses the 'undodir'
11719 option, finding directories that exist. It does not check if
11720 the undo file exists.
11721 {name} is always expanded to the full path, since that is what
11722 is used internally.
11723 If {name} is empty undofile() returns an empty string, since a
11724 buffer without a file name will not write an undo file.
11725 Useful in combination with |:wundo| and |:rundo|.
11726 When compiled without the |+persistent_undo| option this always
11727 returns an empty string.
11728
11729 Can also be used as a |method|: >
11730 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011731<
11732 Return type: |String|
11733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011734
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011735undotree([{buf}]) *undotree()*
11736 Return the current state of the undo tree for the current
11737 buffer, or for a specific buffer if {buf} is given. The
11738 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011739 "seq_last" The highest undo sequence number used.
11740 "seq_cur" The sequence number of the current position in
11741 the undo tree. This differs from "seq_last"
11742 when some changes were undone.
11743 "time_cur" Time last used for |:earlier| and related
11744 commands. Use |strftime()| to convert to
11745 something readable.
11746 "save_last" Number of the last file write. Zero when no
11747 write yet.
11748 "save_cur" Number of the current position in the undo
11749 tree.
11750 "synced" Non-zero when the last undo block was synced.
11751 This happens when waiting from input from the
11752 user. See |undo-blocks|.
11753 "entries" A list of dictionaries with information about
11754 undo blocks.
11755
11756 The first item in the "entries" list is the oldest undo item.
11757 Each List item is a |Dictionary| with these items:
11758 "seq" Undo sequence number. Same as what appears in
11759 |:undolist|.
11760 "time" Timestamp when the change happened. Use
11761 |strftime()| to convert to something readable.
11762 "newhead" Only appears in the item that is the last one
11763 that was added. This marks the last change
11764 and where further changes will be added.
11765 "curhead" Only appears in the item that is the last one
11766 that was undone. This marks the current
11767 position in the undo tree, the block that will
11768 be used by a redo command. When nothing was
11769 undone after the last change this item will
11770 not appear anywhere.
11771 "save" Only appears on the last block before a file
11772 write. The number is the write count. The
11773 first write has number 1, the last one the
11774 "save_last" mentioned above.
11775 "alt" Alternate entry. This is again a List of undo
11776 blocks. Each item may again have an "alt"
11777 item.
11778
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011779 Return type: dict<any>
11780
11781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011782uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11783 Remove second and succeeding copies of repeated adjacent
11784 {list} items in-place. Returns {list}. If you want a list
11785 to remain unmodified make a copy first: >
11786 :let newlist = uniq(copy(mylist))
11787< The default compare function uses the string representation of
11788 each item. For the use of {func} and {dict} see |sort()|.
11789
Bram Moolenaard592deb2022-06-17 15:42:40 +010011790 Returns zero if {list} is not a |List|.
11791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011792 Can also be used as a |method|: >
11793 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011794<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011795 Return type: list<{type}>
11796
11797
Christian Brabandt67672ef2023-04-24 21:09:54 +010011798 *utf16idx()*
11799utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011800 Same as |charidx()| but returns the UTF-16 code unit index of
11801 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011802
11803 When {charidx} is present and TRUE, {idx} is used as the
11804 character index in the String {string} instead of as the byte
11805 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011806 An {idx} in the middle of a UTF-8 sequence is rounded
11807 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011808
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011809 Returns -1 if the arguments are invalid or if there are less
11810 than {idx} bytes in {string}. If there are exactly {idx} bytes
11811 the length of the string in UTF-16 code units is returned.
11812
Christian Brabandt67672ef2023-04-24 21:09:54 +010011813 See |byteidx()| and |byteidxcomp()| for getting the byte index
11814 from the UTF-16 index and |charidx()| for getting the
11815 character index from the UTF-16 index.
11816 Refer to |string-offset-encoding| for more information.
11817 Examples: >
11818 echo utf16idx('a😊😊', 3) returns 2
11819 echo utf16idx('a😊😊', 7) returns 4
11820 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11821 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11822 echo utf16idx('aą́c', 6) returns 2
11823 echo utf16idx('aą́c', 6, 1) returns 4
11824 echo utf16idx('a😊😊', 9) returns -1
11825<
11826 Can also be used as a |method|: >
11827 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011828<
11829 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011831
11832values({dict}) *values()*
11833 Return a |List| with all the values of {dict}. The |List| is
11834 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011835 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011836
11837 Can also be used as a |method|: >
11838 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011839<
11840 Return type: list<any>
11841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011842
zeertzjq825cf812023-08-17 22:55:25 +020011843virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011844 The result is a Number, which is the screen column of the file
11845 position given with {expr}. That is, the last screen position
11846 occupied by the character at that position, when the screen
11847 would be of unlimited width. When there is a <Tab> at the
11848 position, the returned Number will be the column at the end of
11849 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11850 set to 8, it returns 8. |conceal| is ignored.
11851 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011852
zeertzjq02f3eba2024-06-12 20:45:24 +020011853 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011854 When {expr} is "$", it means the end of the cursor line, so
11855 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011856
11857 When 'virtualedit' is used {expr} can be [lnum, col, off],
11858 where "off" is the offset in screen columns from the start of
11859 the character. E.g., a position within a <Tab> or after the
11860 last character. When "off" is omitted zero is used. When
11861 Virtual editing is active in the current mode, a position
11862 beyond the end of the line can be returned. Also see
11863 |'virtualedit'|
11864
zeertzjq825cf812023-08-17 22:55:25 +020011865 If {list} is present and non-zero then virtcol() returns a
11866 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011867 character.
11868
zeertzjq825cf812023-08-17 22:55:25 +020011869 With the optional {winid} argument the values are obtained for
11870 that window instead of the current window.
11871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011872 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011874 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011875 " With text "foo^Lbar" and cursor on the "^L":
11876
11877 virtcol(".") " returns 5
11878 virtcol(".", 1) " returns [4, 5]
11879 virtcol("$") " returns 9
11880
11881 " With text " there", with 't at 'h':
11882
11883 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011884<
11885 The first column is 1. 0 or [0, 0] is returned for an error.
11886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011887 A more advanced example that echoes the maximum length of
11888 all lines: >
11889 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11890
11891< Can also be used as a |method|: >
11892 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011893<
11894 Return type: |Number|
11895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011896
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011897virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11898 The result is a Number, which is the byte index of the
11899 character in window {winid} at buffer line {lnum} and virtual
11900 column {col}.
11901
zeertzjqb583eda2023-10-14 11:32:28 +020011902 If buffer line {lnum} is an empty line, 0 is returned.
11903
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011904 If {col} is greater than the last virtual column in line
11905 {lnum}, then the byte index of the character at the last
11906 virtual column is returned.
11907
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011908 For a multi-byte character, the column number of the first
11909 byte in the character is returned.
11910
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011911 The {winid} argument can be the window number or the
11912 |window-ID|. If this is zero, then the current window is used.
11913
11914 Returns -1 if the window {winid} doesn't exist or the buffer
11915 line {lnum} or virtual column {col} is invalid.
11916
11917 See also |screenpos()|, |virtcol()| and |col()|.
11918
11919 Can also be used as a |method|: >
11920 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011921<
11922 Return type: |Number|
11923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011924
11925visualmode([{expr}]) *visualmode()*
11926 The result is a String, which describes the last Visual mode
11927 used in the current buffer. Initially it returns an empty
11928 string, but once Visual mode has been used, it returns "v",
11929 "V", or "<CTRL-V>" (a single CTRL-V character) for
11930 character-wise, line-wise, or block-wise Visual mode
11931 respectively.
11932 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011933 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011934< This enters the same Visual mode as before. It is also useful
11935 in scripts if you wish to act differently depending on the
11936 Visual mode that was used.
11937 If Visual mode is active, use |mode()| to get the Visual mode
11938 (e.g., in a |:vmap|).
11939 If {expr} is supplied and it evaluates to a non-zero Number or
11940 a non-empty String, then the Visual mode will be cleared and
11941 the old value is returned. See |non-zero-arg|.
11942
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011943 Return type: |String|
11944
11945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011946wildmenumode() *wildmenumode()*
11947 Returns |TRUE| when the wildmenu is active and |FALSE|
11948 otherwise. See 'wildmenu' and 'wildmode'.
11949 This can be used in mappings to handle the 'wildcharm' option
11950 gracefully. (Makes only sense with |mapmode-c| mappings).
11951
11952 For example to make <c-j> work like <down> in wildmode, use: >
11953 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11954<
11955 (Note, this needs the 'wildcharm' option set appropriately).
11956
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011957 Return type: |Number|
11958
11959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011960win_execute({id}, {command} [, {silent}]) *win_execute()*
11961 Like `execute()` but in the context of window {id}.
11962 The window will temporarily be made the current window,
11963 without triggering autocommands or changing directory. When
11964 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011965 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011966 Example: >
11967 call win_execute(winid, 'set syntax=python')
11968< Doing the same with `setwinvar()` would not trigger
11969 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011970 *E994*
11971 Not all commands are allowed in popup windows.
11972 When window {id} does not exist then no error is given and
11973 an empty string is returned.
11974
11975 Can also be used as a |method|, the base is passed as the
11976 second argument: >
11977 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011978<
11979 Return type: |String|
11980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011981
11982win_findbuf({bufnr}) *win_findbuf()*
11983 Returns a |List| with |window-ID|s for windows that contain
11984 buffer {bufnr}. When there is none the list is empty.
11985
11986 Can also be used as a |method|: >
11987 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011988<
11989 Return type: list<number> or list<any>
11990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011991
11992win_getid([{win} [, {tab}]]) *win_getid()*
11993 Get the |window-ID| for the specified window.
11994 When {win} is missing use the current window.
11995 With {win} this is the window number. The top window has
11996 number 1.
11997 Without {tab} use the current tab, otherwise the tab with
11998 number {tab}. The first tab has number one.
11999 Return zero if the window cannot be found.
12000
12001 Can also be used as a |method|: >
12002 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012003<
12004 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012005
12006
12007win_gettype([{nr}]) *win_gettype()*
12008 Return the type of the window:
12009 "autocmd" autocommand window. Temporary window
12010 used to execute autocommands.
12011 "command" command-line window |cmdwin|
12012 (empty) normal window
12013 "loclist" |location-list-window|
12014 "popup" popup window |popup|
12015 "preview" preview window |preview-window|
12016 "quickfix" |quickfix-window|
12017 "unknown" window {nr} not found
12018
12019 When {nr} is omitted return the type of the current window.
12020 When {nr} is given return the type of this window by number or
12021 |window-ID|.
12022
12023 Also see the 'buftype' option. When running a terminal in a
12024 popup window then 'buftype' is "terminal" and win_gettype()
12025 returns "popup".
12026
12027 Can also be used as a |method|: >
12028 GetWinid()->win_gettype()
12029<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012030 Return type: |String|
12031
12032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012033win_gotoid({expr}) *win_gotoid()*
12034 Go to window with ID {expr}. This may also change the current
12035 tabpage.
12036 Return TRUE if successful, FALSE if the window cannot be found.
12037
12038 Can also be used as a |method|: >
12039 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012040<
12041 Return type: |Number|
12042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012043
12044win_id2tabwin({expr}) *win_id2tabwin()*
12045 Return a list with the tab number and window number of window
12046 with ID {expr}: [tabnr, winnr].
12047 Return [0, 0] if the window cannot be found.
12048
12049 Can also be used as a |method|: >
12050 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012051<
12052 Return type: list<number>
12053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012054
12055win_id2win({expr}) *win_id2win()*
12056 Return the window number of window with ID {expr}.
12057 Return 0 if the window cannot be found in the current tabpage.
12058
12059 Can also be used as a |method|: >
12060 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012061<
12062 Return type: |Number|
12063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012064
Daniel Steinbergee630312022-01-10 13:36:34 +000012065win_move_separator({nr}, {offset}) *win_move_separator()*
12066 Move window {nr}'s vertical separator (i.e., the right border)
12067 by {offset} columns, as if being dragged by the mouse. {nr}
12068 can be a window number or |window-ID|. A positive {offset}
12069 moves right and a negative {offset} moves left. Moving a
12070 window's vertical separator will change the width of the
12071 window and the width of other windows adjacent to the vertical
12072 separator. The magnitude of movement may be smaller than
12073 specified (e.g., as a consequence of maintaining
12074 'winminwidth'). Returns TRUE if the window can be found and
12075 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012076 This will fail for the rightmost window and a full-width
12077 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012078 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012079
12080 Can also be used as a |method|: >
12081 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012082<
12083 Return type: |Number|
12084
Daniel Steinbergee630312022-01-10 13:36:34 +000012085
12086win_move_statusline({nr}, {offset}) *win_move_statusline()*
12087 Move window {nr}'s status line (i.e., the bottom border) by
12088 {offset} rows, as if being dragged by the mouse. {nr} can be a
12089 window number or |window-ID|. A positive {offset} moves down
12090 and a negative {offset} moves up. Moving a window's status
12091 line will change the height of the window and the height of
12092 other windows adjacent to the status line. The magnitude of
12093 movement may be smaller than specified (e.g., as a consequence
12094 of maintaining 'winminheight'). Returns TRUE if the window can
12095 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012096 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012097
12098 Can also be used as a |method|: >
12099 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012100<
12101 Return type: |Number|
12102
Daniel Steinbergee630312022-01-10 13:36:34 +000012103
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012104win_screenpos({nr}) *win_screenpos()*
12105 Return the screen position of window {nr} as a list with two
12106 numbers: [row, col]. The first window always has position
12107 [1, 1], unless there is a tabline, then it is [2, 1].
12108 {nr} can be the window number or the |window-ID|. Use zero
12109 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012110 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012111
12112 Can also be used as a |method|: >
12113 GetWinid()->win_screenpos()
12114<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012115 Return type: list<number>
12116
12117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012118win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012119 Temporarily switch to window {target}, then move window {nr}
12120 to a new split adjacent to {target}.
12121 Unlike commands such as |:split|, no new windows are created
12122 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012123
12124 Both {nr} and {target} can be window numbers or |window-ID|s.
12125 Both must be in the current tab page.
12126
12127 Returns zero for success, non-zero for failure.
12128
12129 {options} is a |Dictionary| with the following optional entries:
12130 "vertical" When TRUE, the split is created vertically,
12131 like with |:vsplit|.
12132 "rightbelow" When TRUE, the split is made below or to the
12133 right (if vertical). When FALSE, it is done
12134 above or to the left (if vertical). When not
12135 present, the values of 'splitbelow' and
12136 'splitright' are used.
12137
12138 Can also be used as a |method|: >
12139 GetWinid()->win_splitmove(target)
12140<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012141 Return type: |Number|
12142
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012143
12144 *winbufnr()*
12145winbufnr({nr}) The result is a Number, which is the number of the buffer
12146 associated with window {nr}. {nr} can be the window number or
12147 the |window-ID|.
12148 When {nr} is zero, the number of the buffer in the current
12149 window is returned.
12150 When window {nr} doesn't exist, -1 is returned.
12151 Example: >
12152 :echo "The file in the current window is " . bufname(winbufnr(0))
12153<
12154 Can also be used as a |method|: >
12155 FindWindow()->winbufnr()->bufname()
12156<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012157 Return type: |Number|
12158
12159
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012160 *wincol()*
12161wincol() The result is a Number, which is the virtual column of the
12162 cursor in the window. This is counting screen cells from the
12163 left side of the window. The leftmost column is one.
12164
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012165 Return type: |Number|
12166
12167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012168 *windowsversion()*
12169windowsversion()
12170 The result is a String. For MS-Windows it indicates the OS
12171 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12172 Windows XP is "5.1". For non-MS-Windows systems the result is
12173 an empty string.
12174
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012175 Return type: |String|
12176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012177winheight({nr}) *winheight()*
12178 The result is a Number, which is the height of window {nr}.
12179 {nr} can be the window number or the |window-ID|.
12180 When {nr} is zero, the height of the current window is
12181 returned. When window {nr} doesn't exist, -1 is returned.
12182 An existing window always has a height of zero or more.
12183 This excludes any window toolbar line.
12184 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012185 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012186
12187< Can also be used as a |method|: >
12188 GetWinid()->winheight()
12189<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012190 Return type: |Number|
12191
12192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012193winlayout([{tabnr}]) *winlayout()*
12194 The result is a nested List containing the layout of windows
12195 in a tabpage.
12196
12197 Without {tabnr} use the current tabpage, otherwise the tabpage
12198 with number {tabnr}. If the tabpage {tabnr} is not found,
12199 returns an empty list.
12200
12201 For a leaf window, it returns:
12202 ['leaf', {winid}]
12203 For horizontally split windows, which form a column, it
12204 returns:
12205 ['col', [{nested list of windows}]]
12206 For vertically split windows, which form a row, it returns:
12207 ['row', [{nested list of windows}]]
12208
12209 Example: >
12210 " Only one window in the tab page
12211 :echo winlayout()
12212 ['leaf', 1000]
12213 " Two horizontally split windows
12214 :echo winlayout()
12215 ['col', [['leaf', 1000], ['leaf', 1001]]]
12216 " The second tab page, with three horizontally split
12217 " windows, with two vertically split windows in the
12218 " middle window
12219 :echo winlayout(2)
12220 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12221 ['leaf', 1001]]], ['leaf', 1000]]]
12222<
12223 Can also be used as a |method|: >
12224 GetTabnr()->winlayout()
12225<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012226 Return type: list<any>
12227
12228
12229winline() *winline()*
12230 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012231 in the window. This is counting screen lines from the top of
12232 the window. The first line is one.
12233 If the cursor was moved the view on the file will be updated
12234 first, this may cause a scroll.
12235
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012236 Return type: |Number|
12237
12238
12239winnr([{arg}]) *winnr()*
12240 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012241 window. The top window has number 1.
12242 Returns zero for a popup window.
12243
12244 The optional argument {arg} supports the following values:
12245 $ the number of the last window (the window
12246 count).
12247 # the number of the last accessed window (where
12248 |CTRL-W_p| goes to). If there is no previous
12249 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012250 returned. May refer to the current window in
12251 some cases (e.g. when evaluating 'statusline'
12252 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012253 {N}j the number of the Nth window below the
12254 current window (where |CTRL-W_j| goes to).
12255 {N}k the number of the Nth window above the current
12256 window (where |CTRL-W_k| goes to).
12257 {N}h the number of the Nth window left of the
12258 current window (where |CTRL-W_h| goes to).
12259 {N}l the number of the Nth window right of the
12260 current window (where |CTRL-W_l| goes to).
12261 The number can be used with |CTRL-W_w| and ":wincmd w"
12262 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012263 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012264 Also see |tabpagewinnr()| and |win_getid()|.
12265 Examples: >
12266 let window_count = winnr('$')
12267 let prev_window = winnr('#')
12268 let wnum = winnr('3k')
12269
12270< Can also be used as a |method|: >
12271 GetWinval()->winnr()
12272<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012273 Return type: |Number|
12274
12275
12276winrestcmd() *winrestcmd()*
12277 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012278 the current window sizes. Only works properly when no windows
12279 are opened or closed and the current window and tab page is
12280 unchanged.
12281 Example: >
12282 :let cmd = winrestcmd()
12283 :call MessWithWindowSizes()
12284 :exe cmd
12285<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012286 Return type: |String|
12287
12288
12289winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012290 Uses the |Dictionary| returned by |winsaveview()| to restore
12291 the view of the current window.
12292 Note: The {dict} does not have to contain all values, that are
12293 returned by |winsaveview()|. If values are missing, those
12294 settings won't be restored. So you can use: >
12295 :call winrestview({'curswant': 4})
12296<
12297 This will only set the curswant value (the column the cursor
12298 wants to move on vertical movements) of the cursor to column 5
12299 (yes, that is 5), while all other settings will remain the
12300 same. This is useful, if you set the cursor position manually.
12301
12302 If you have changed the values the result is unpredictable.
12303 If the window size changed the result won't be the same.
12304
12305 Can also be used as a |method|: >
12306 GetView()->winrestview()
12307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012308 Return type: |Number|
12309
12310
12311winsaveview() *winsaveview()*
12312 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012313 the view of the current window. Use |winrestview()| to
12314 restore the view.
12315 This is useful if you have a mapping that jumps around in the
12316 buffer and you want to go back to the original view.
12317 This does not save fold information. Use the 'foldenable'
12318 option to temporarily switch off folding, so that folds are
12319 not opened when moving around. This may have side effects.
12320 The return value includes:
12321 lnum cursor line number
12322 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012323 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012324 returns)
12325 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012326 curswant column for vertical movement (Note:
12327 the first column is zero, as opposed
12328 to what |getcurpos()| returns). After
12329 |$| command it will be a very large
12330 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012331 topline first line in the window
12332 topfill filler lines, only in diff mode
12333 leftcol first column displayed; only used when
12334 'wrap' is off
12335 skipcol columns skipped
12336 Note that no option values are saved.
12337
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012338 Return type: dict<number>
12339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012340
12341winwidth({nr}) *winwidth()*
12342 The result is a Number, which is the width of window {nr}.
12343 {nr} can be the window number or the |window-ID|.
12344 When {nr} is zero, the width of the current window is
12345 returned. When window {nr} doesn't exist, -1 is returned.
12346 An existing window always has a width of zero or more.
12347 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012348 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012349 :if winwidth(0) <= 50
12350 : 50 wincmd |
12351 :endif
12352< For getting the terminal or screen size, see the 'columns'
12353 option.
12354
12355 Can also be used as a |method|: >
12356 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012357<
12358 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012359
12360
12361wordcount() *wordcount()*
12362 The result is a dictionary of byte/chars/word statistics for
12363 the current buffer. This is the same info as provided by
12364 |g_CTRL-G|
12365 The return value includes:
12366 bytes Number of bytes in the buffer
12367 chars Number of chars in the buffer
12368 words Number of words in the buffer
12369 cursor_bytes Number of bytes before cursor position
12370 (not in Visual mode)
12371 cursor_chars Number of chars before cursor position
12372 (not in Visual mode)
12373 cursor_words Number of words before cursor position
12374 (not in Visual mode)
12375 visual_bytes Number of bytes visually selected
12376 (only in Visual mode)
12377 visual_chars Number of chars visually selected
12378 (only in Visual mode)
12379 visual_words Number of words visually selected
12380 (only in Visual mode)
12381
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012382 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012383
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012384
12385writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012386 When {object} is a |List| write it to file {fname}. Each list
12387 item is separated with a NL. Each list item must be a String
12388 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012389 All NL characters are replaced with a NUL character.
12390 Inserting CR characters needs to be done before passing {list}
12391 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012392
12393 When {object} is a |Blob| write the bytes to file {fname}
12394 unmodified, also when binary mode is not specified.
12395
12396 {flags} must be a String. These characters are recognized:
12397
12398 'b' Binary mode is used: There will not be a NL after the
12399 last list item. An empty item at the end does cause the
12400 last line in the file to end in a NL.
12401
12402 'a' Append mode is used, lines are appended to the file: >
12403 :call writefile(["foo"], "event.log", "a")
12404 :call writefile(["bar"], "event.log", "a")
12405<
12406 'D' Delete the file when the current function ends. This
12407 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012408 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012409< Fails when not in a function. Also see |:defer|.
12410
12411 's' fsync() is called after writing the file. This flushes
12412 the file to disk, if possible. This takes more time but
12413 avoids losing the file if the system crashes.
12414
12415 'S' fsync() is not called, even when 'fsync' is set.
12416
12417 When {flags} does not contain "S" or "s" then fsync() is
12418 called if the 'fsync' option is set.
12419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012420 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012422 When the write fails -1 is returned, otherwise 0. There is an
12423 error message if the file can't be created or when writing
12424 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012426 Also see |readfile()|.
12427 To copy a file byte for byte: >
12428 :let fl = readfile("foo", "b")
12429 :call writefile(fl, "foocopy", "b")
12430
12431< Can also be used as a |method|: >
12432 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012433<
12434 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012435
12436
12437xor({expr}, {expr}) *xor()*
12438 Bitwise XOR on the two arguments. The arguments are converted
12439 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012440 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012441 Example: >
12442 :let bits = xor(bits, 0x80)
12443<
12444 Can also be used as a |method|: >
12445 :let bits = bits->xor(0x80)
12446<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012447 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012448
12449==============================================================================
124503. Feature list *feature-list*
12451
12452There are three types of features:
124531. Features that are only supported when they have been enabled when Vim
12454 was compiled |+feature-list|. Example: >
12455 :if has("cindent")
12456< *gui_running*
124572. Features that are only supported when certain conditions have been met.
12458 Example: >
12459 :if has("gui_running")
12460< *has-patch*
124613. Beyond a certain version or at a certain version and including a specific
12462 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12463 later, or it is version 7.4 and patch 248 was included. Example: >
12464 :if has("patch-7.4.248")
12465< Note that it's possible for patch 248 to be omitted even though 249 is
12466 included. Only happens when cherry-picking patches.
12467 Note that this form only works for patch 7.4.237 and later, before that
12468 you need to check for the patch and the v:version. Example (checking
12469 version 6.2.148 or later): >
12470 :if v:version > 602 || (v:version == 602 && has("patch148"))
12471
12472Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12473use: `if exists('+shellslash')`
12474
12475
12476acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012477all_builtin_terms Compiled with all builtin terminals enabled. (always
12478 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012479amiga Amiga version of Vim.
12480arabic Compiled with Arabic support |Arabic|.
12481arp Compiled with ARP support (Amiga).
12482autocmd Compiled with autocommand support. (always true)
12483autochdir Compiled with support for 'autochdir'
12484autoservername Automatically enable |clientserver|
12485balloon_eval Compiled with |balloon-eval| support.
12486balloon_multiline GUI supports multiline balloons.
12487beos BeOS version of Vim.
12488browse Compiled with |:browse| support, and browse() will
12489 work.
12490browsefilter Compiled with support for |browsefilter|.
12491bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012492builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012493byte_offset Compiled with support for 'o' in 'statusline'
12494channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012495cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012496clientserver Compiled with remote invocation support |clientserver|.
12497clipboard Compiled with 'clipboard' support.
12498clipboard_working Compiled with 'clipboard' support and it can be used.
12499cmdline_compl Compiled with |cmdline-completion| support.
12500cmdline_hist Compiled with |cmdline-history| support.
12501cmdline_info Compiled with 'showcmd' and 'ruler' support.
12502comments Compiled with |'comments'| support.
12503compatible Compiled to be very Vi compatible.
12504conpty Platform where |ConPTY| can be used.
12505cryptv Compiled with encryption support |encryption|.
12506cscope Compiled with |cscope| support.
12507cursorbind Compiled with |'cursorbind'| (always true)
12508debug Compiled with "DEBUG" defined.
12509dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012510dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012511dialog_gui Compiled with GUI dialog support.
12512diff Compiled with |vimdiff| and 'diff' support.
12513digraphs Compiled with support for digraphs.
12514directx Compiled with support for DirectX and 'renderoptions'.
12515dnd Compiled with support for the "~ register |quote_~|.
12516drop_file Compiled with |drop_file| support.
12517ebcdic Compiled on a machine with ebcdic character set.
12518emacs_tags Compiled with support for Emacs tags.
12519eval Compiled with expression evaluation support. Always
12520 true, of course!
12521ex_extra |+ex_extra| (always true)
12522extra_search Compiled with support for |'incsearch'| and
12523 |'hlsearch'|
12524farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012525file_in_path Compiled with support for |gf| and |<cfile>| (always
12526 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012527filterpipe When 'shelltemp' is off pipes are used for shell
12528 read/write/filter commands
12529find_in_path Compiled with support for include file searches
12530 |+find_in_path|.
12531float Compiled with support for |Float|.
12532fname_case Case in file names matters (for Amiga and MS-Windows
12533 this is not present).
12534folding Compiled with |folding| support.
12535footer Compiled with GUI footer support. |gui-footer|
12536fork Compiled to use fork()/exec() instead of system().
12537gettext Compiled with message translation |multi-lang|
12538gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012539gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012540gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12541gui_gtk Compiled with GTK+ GUI (any version).
12542gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12543gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12544gui_haiku Compiled with Haiku GUI.
12545gui_mac Compiled with Macintosh GUI.
12546gui_motif Compiled with Motif GUI.
12547gui_photon Compiled with Photon GUI.
12548gui_running Vim is running in the GUI, or it will start soon.
12549gui_win32 Compiled with MS-Windows Win32 GUI.
12550gui_win32s idem, and Win32s system being used (Windows 3.1)
12551haiku Haiku version of Vim.
12552hangul_input Compiled with Hangul input support. |hangul|
12553hpux HP-UX version of Vim.
12554iconv Can use iconv() for conversion.
12555insert_expand Compiled with support for CTRL-X expansion commands in
12556 Insert mode. (always true)
12557job Compiled with support for |channel| and |job|
12558ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012559jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012560keymap Compiled with 'keymap' support.
12561lambda Compiled with |lambda| support.
12562langmap Compiled with 'langmap' support.
12563libcall Compiled with |libcall()| support.
12564linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12565 'breakindent' support.
12566linux Linux version of Vim.
12567lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012568 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012569listcmds Compiled with commands for the buffer list |:files|
12570 and the argument list |arglist|.
12571localmap Compiled with local mappings and abbr. |:map-local|
12572lua Compiled with Lua interface |Lua|.
12573mac Any Macintosh version of Vim cf. osx
12574macunix Synonym for osxdarwin
12575menu Compiled with support for |:menu|.
12576mksession Compiled with support for |:mksession|.
12577modify_fname Compiled with file name modifiers. |filename-modifiers|
12578 (always true)
12579mouse Compiled with support for mouse.
12580mouse_dec Compiled with support for Dec terminal mouse.
12581mouse_gpm Compiled with support for gpm (Linux console mouse)
12582mouse_gpm_enabled GPM mouse is working
12583mouse_netterm Compiled with support for netterm mouse.
12584mouse_pterm Compiled with support for qnx pterm mouse.
12585mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12586mouse_sgr Compiled with support for sgr mouse.
12587mouse_urxvt Compiled with support for urxvt mouse.
12588mouse_xterm Compiled with support for xterm mouse.
12589mouseshape Compiled with support for 'mouseshape'.
12590multi_byte Compiled with support for 'encoding' (always true)
12591multi_byte_encoding 'encoding' is set to a multibyte encoding.
12592multi_byte_ime Compiled with support for IME input method.
12593multi_lang Compiled with support for multiple languages.
12594mzscheme Compiled with MzScheme interface |mzscheme|.
12595nanotime Compiled with sub-second time stamp checks.
12596netbeans_enabled Compiled with support for |netbeans| and connected.
12597netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012598num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012599ole Compiled with OLE automation support for Win32.
12600osx Compiled for macOS cf. mac
12601osxdarwin Compiled for macOS, with |mac-darwin-feature|
12602packages Compiled with |packages| support.
12603path_extra Compiled with up/downwards search in 'path' and 'tags'
12604perl Compiled with Perl interface.
12605persistent_undo Compiled with support for persistent undo history.
12606postscript Compiled with PostScript file printing.
12607printer Compiled with |:hardcopy| support.
12608profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012609prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012610python Python 2.x interface available. |has-python|
12611python_compiled Compiled with Python 2.x interface. |has-python|
12612python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12613python3 Python 3.x interface available. |has-python|
12614python3_compiled Compiled with Python 3.x interface. |has-python|
12615python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012616python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012617pythonx Python 2.x and/or 3.x interface available. |python_x|
12618qnx QNX version of Vim.
12619quickfix Compiled with |quickfix| support.
12620reltime Compiled with |reltime()| support.
12621rightleft Compiled with 'rightleft' support.
12622ruby Compiled with Ruby interface |ruby|.
12623scrollbind Compiled with 'scrollbind' support. (always true)
12624showcmd Compiled with 'showcmd' support.
12625signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012626smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012627sodium Compiled with libsodium for better crypt support
12628sound Compiled with sound support, e.g. `sound_playevent()`
12629spell Compiled with spell checking support |spell|.
12630startuptime Compiled with |--startuptime| support.
12631statusline Compiled with support for 'statusline', 'rulerformat'
12632 and special formats of 'titlestring' and 'iconstring'.
12633sun SunOS version of Vim.
12634sun_workshop Support for Sun |workshop| has been removed.
12635syntax Compiled with syntax highlighting support |syntax|.
12636syntax_items There are active syntax highlighting items for the
12637 current buffer.
12638system Compiled to use system() instead of fork()/exec().
12639tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012640 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012641tag_old_static Support for old static tags was removed, see
12642 |tag-old-static|.
12643tcl Compiled with Tcl interface.
12644termguicolors Compiled with true color in terminal support.
12645terminal Compiled with |terminal| support.
12646terminfo Compiled with terminfo instead of termcap.
12647termresponse Compiled with support for |t_RV| and |v:termresponse|.
12648textobjects Compiled with support for |text-objects|.
12649textprop Compiled with support for |text-properties|.
12650tgetent Compiled with tgetent support, able to use a termcap
12651 or terminfo file.
12652timers Compiled with |timer_start()| support.
12653title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012654 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012655toolbar Compiled with support for |gui-toolbar|.
12656ttyin input is a terminal (tty)
12657ttyout output is a terminal (tty)
12658unix Unix version of Vim. *+unix*
12659unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12660user_commands User-defined commands. (always true)
12661vartabs Compiled with variable tabstop support |'vartabstop'|.
12662vcon Win32: Virtual console support is working, can use
12663 'termguicolors'. Also see |+vtp|.
12664vertsplit Compiled with vertically split windows |:vsplit|.
12665 (always true)
12666vim_starting True while initial source'ing takes place. |startup|
12667 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012668vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012669viminfo Compiled with viminfo support.
12670vimscript-1 Compiled Vim script version 1 support
12671vimscript-2 Compiled Vim script version 2 support
12672vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012673vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012674virtualedit Compiled with 'virtualedit' option. (always true)
12675visual Compiled with Visual mode. (always true)
12676visualextra Compiled with extra Visual mode commands. (always
12677 true) |blockwise-operators|.
12678vms VMS version of Vim.
12679vreplace Compiled with |gR| and |gr| commands. (always true)
12680vtp Compiled for vcon support |+vtp| (check vcon to find
12681 out if it works in the current console).
12682wildignore Compiled with 'wildignore' option.
12683wildmenu Compiled with 'wildmenu' option.
12684win16 old version for MS-Windows 3.1 (always false)
12685win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12686 64 bits)
12687win32unix Win32 version of Vim, using Unix files (Cygwin)
12688win64 Win64 version of Vim (MS-Windows 64 bit).
12689win95 Win32 version for MS-Windows 95/98/ME (always false)
12690winaltkeys Compiled with 'winaltkeys' option.
12691windows Compiled with support for more than one window.
12692 (always true)
12693writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012694xattr Compiled with extended attributes support |xattr|
12695 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012696xfontset Compiled with X fontset support |xfontset|.
12697xim Compiled with X input method support |xim|.
12698xpm Compiled with pixmap support.
12699xpm_w32 Compiled with pixmap support for Win32. (Only for
12700 backward compatibility. Use "xpm" instead.)
12701xsmp Compiled with X session management support.
12702xsmp_interact Compiled with interactive X session management support.
12703xterm_clipboard Compiled with support for xterm clipboard.
12704xterm_save Compiled with support for saving and restoring the
12705 xterm screen.
12706x11 Compiled with X11 support.
12707
12708
12709==============================================================================
127104. Matching a pattern in a String *string-match*
12711
12712This is common between several functions. A regexp pattern as explained at
12713|pattern| is normally used to find a match in the buffer lines. When a
12714pattern is used to find a match in a String, almost everything works in the
12715same way. The difference is that a String is handled like it is one line.
12716When it contains a "\n" character, this is not seen as a line break for the
12717pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12718>
12719 :let a = "aaaa\nxxxx"
12720 :echo matchstr(a, "..\n..")
12721 aa
12722 xx
12723 :echo matchstr(a, "a.x")
12724 a
12725 x
12726
12727Don't forget that "^" will only match at the first character of the String and
12728"$" at the last character of the string. They don't match after or before a
12729"\n".
12730
12731 vim:tw=78:ts=8:noet:ft=help:norl: